|
|
@@ -195,17 +195,28 @@ class Distribution extends ActiveRecordCommon |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 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() |
|
|
|
->where('date > ' . date('Y-m-d')) |
|
|
|
->andWhere(['id_producer' => Producer::getId()]) |
|
|
|
->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) { |
|
|
|
$distribution->linkProduct($product) ; |
|
|
|
} |
|
|
@@ -216,7 +227,6 @@ class Distribution extends ActiveRecordCommon |
|
|
|
* |
|
|
|
* @param Product $product |
|
|
|
*/ |
|
|
|
|
|
|
|
public function linkProduct($product) |
|
|
|
{ |
|
|
|
$productDistribution = ProductDistribution::searchOne([ |
|
|
@@ -233,7 +243,6 @@ class Distribution extends ActiveRecordCommon |
|
|
|
$productDistribution->quantity_max = $product->quantity_max; |
|
|
|
|
|
|
|
$dayDistribution = date('N', strtotime($this->date)); |
|
|
|
|
|
|
|
$daysArray = [ |
|
|
|
1 => 'monday', |
|
|
|
2 => 'tuesday', |
|
|
@@ -252,5 +261,55 @@ class Distribution extends ActiveRecordCommon |
|
|
|
|
|
|
|
$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() ; |
|
|
|
} |
|
|
|
|
|
|
|
} |