Просмотр исходного кода

Mise à jour des distributions (PointSaleDistribution) lors de l'ajout/modification de points de vente

dev
Guillaume Bourgeois 5 лет назад
Родитель
Сommit
80897e4c27
2 измененных файлов: 67 добавлений и 6 удалений
  1. +2
    -0
      backend/controllers/PointSaleController.php
  2. +65
    -6
      common/models/Distribution.php

+ 2
- 0
backend/controllers/PointSaleController.php Просмотреть файл

@@ -105,6 +105,7 @@ class PointSaleController extends BackendController
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->processPointProduction();
$model->processRestrictedAccess();
Distribution::linkPointSaleIncomingDistributions($model) ;
return $this->redirect(['index']);
} else {
return $this->render('create', array_merge($this->initForm(), [
@@ -134,6 +135,7 @@ class PointSaleController extends BackendController
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->processPointProduction();
$model->processRestrictedAccess();
Distribution::linkPointSaleIncomingDistributions($model) ;
return $this->redirect(['index']);
} else {
return $this->render('update', array_merge($this->initForm($id), [

+ 65
- 6
common/models/Distribution.php Просмотреть файл

@@ -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() ;
}

}

Загрузка…
Отмена
Сохранить