|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Lie un produit aux jours de distribution futurs. |
|
|
|
|
|
|
|
|
* Retourne les distributions futures. |
|
|
* |
|
|
* |
|
|
* @param Product $product |
|
|
|
|
|
|
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public static function linkProductIncomingDistributions($product) |
|
|
|
|
|
|
|
|
public static function getIncomingDistributions() |
|
|
{ |
|
|
{ |
|
|
$distributionsArray = Distribution::find() |
|
|
$distributionsArray = Distribution::find() |
|
|
->where('date > ' . date('Y-m-d')) |
|
|
->where('date > ' . date('Y-m-d')) |
|
|
->andWhere(['id_producer' => Producer::getId()]) |
|
|
->andWhere(['id_producer' => Producer::getId()]) |
|
|
->all(); |
|
|
->all(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $distributionsArray ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Lie un produit aux jours de distribution futurs. |
|
|
|
|
|
* |
|
|
|
|
|
* @param Product $product |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function linkProductIncomingDistributions($product) |
|
|
|
|
|
{ |
|
|
|
|
|
$distributionsArray = self::getIncomingDistributions() ; |
|
|
foreach ($distributionsArray as $distribution) { |
|
|
foreach ($distributionsArray as $distribution) { |
|
|
$distribution->linkProduct($product) ; |
|
|
$distribution->linkProduct($product) ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
* |
|
|
* |
|
|
* @param Product $product |
|
|
* @param Product $product |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
public function linkProduct($product) |
|
|
public function linkProduct($product) |
|
|
{ |
|
|
{ |
|
|
$productDistribution = ProductDistribution::searchOne([ |
|
|
$productDistribution = ProductDistribution::searchOne([ |
|
|
|
|
|
|
|
|
$productDistribution->quantity_max = $product->quantity_max; |
|
|
$productDistribution->quantity_max = $product->quantity_max; |
|
|
|
|
|
|
|
|
$dayDistribution = date('N', strtotime($this->date)); |
|
|
$dayDistribution = date('N', strtotime($this->date)); |
|
|
|
|
|
|
|
|
$daysArray = [ |
|
|
$daysArray = [ |
|
|
1 => 'monday', |
|
|
1 => 'monday', |
|
|
2 => 'tuesday', |
|
|
2 => 'tuesday', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$productDistribution->save(); |
|
|
$productDistribution->save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Lie un point de vente aux jours de distribution futurs. |
|
|
|
|
|
* |
|
|
|
|
|
* @param PointSale $pointSale |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function linkPointSaleIncomingDistributions($pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
$distributionsArray = self::getIncomingDistributions() ; |
|
|
|
|
|
foreach ($distributionsArray as $distribution) { |
|
|
|
|
|
$distribution->linkPointSale($pointSale) ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param type $pointSale |
|
|
|
|
|
*/ |
|
|
|
|
|
public function linkPointSale($pointSale) |
|
|
|
|
|
{ |
|
|
|
|
|
$pointSaleDistribution = PointSaleDistribution::searchOne([ |
|
|
|
|
|
'id_distribution' => $this->id, |
|
|
|
|
|
'id_point_sale' => $pointSale->id |
|
|
|
|
|
]) ; |
|
|
|
|
|
|
|
|
|
|
|
if(!$pointSaleDistribution) { |
|
|
|
|
|
$pointSaleDistribution = new PointSaleDistribution(); |
|
|
|
|
|
$pointSaleDistribution->id_distribution = $this->id; |
|
|
|
|
|
$pointSaleDistribution->id_point_sale = $pointSale->id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$dayDistribution = date('N', strtotime($this->date)); |
|
|
|
|
|
$daysArray = [ |
|
|
|
|
|
1 => 'monday', |
|
|
|
|
|
2 => 'tuesday', |
|
|
|
|
|
3 => 'wednesday', |
|
|
|
|
|
4 => 'thursday', |
|
|
|
|
|
5 => 'friday', |
|
|
|
|
|
6 => 'saturday', |
|
|
|
|
|
7 => 'sunday', |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
|
|
|
$pointSaleDistribution->delivery = 0 ; |
|
|
|
|
|
$deliveryDay = 'delivery_'.$daysArray[$dayDistribution] ; |
|
|
|
|
|
if($pointSale->$deliveryDay) { |
|
|
|
|
|
$pointSaleDistribution->delivery = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$pointSaleDistribution->save() ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |