|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
-
-
-
- namespace common\models;
-
- use Yii;
- use common\components\ActiveRecordCommon ;
- use common\models\PointVente;
- use common\models\Production;
-
-
- class PointSaleDistribution extends ActiveRecordCommon
- {
-
- var $points_sale_distribution;
-
-
-
- public static function tableName()
- {
- return 'point_sale_distribution';
- }
-
-
-
- public function rules()
- {
- return [
- [['id_distribution', 'id_point_sale'], 'required'],
- [['id_distribution', 'id_point_sale', 'delivery'], 'integer'],
- ];
- }
-
-
-
- public function attributeLabels()
- {
- return [
- 'id_distribution' => 'Distribution',
- 'id_point_sale' => 'Point de vente',
- 'delivery' => 'Livraison',
- ];
- }
-
-
-
-
- public function getDistribution()
- {
- return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']);
- }
-
- public function getPointSale()
- {
- return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']);
- }
-
-
-
- public static function defaultOptionsSearch() {
- return [
- 'with' => ['distribution', 'pointSale'],
- 'join_with' => [],
- 'orderby' => '',
- 'attribute_id_producer' => ''
- ] ;
- }
-
-
-
- public static function setAll($idDistribution, $boolDelivery)
- {
-
- $arrPointsSale = PointSale::find()
- ->with(['pointSaleDistribution' => function($q) use ($idDistribution) {
- $q->where(['id_distribution' => $idDistribution]);
- }])
- ->where([
- 'id_producer' => Producer::getId(),
- ])
- ->all();
-
- foreach ($arrPointsSale as $pointSale) {
- if(!$pointSale->pointSaleDistribution) {
- $pointSaleDistribution = new PointSaleDistribution();
- $pointSaleDistribution->id_distribution = $idDistribution;
- $pointSaleDistribution->id_point_sale = $pointSale->id;
- $pointSaleDistribution->save();
- }
- }
-
- $distribution = Distribution::findOne($idDistribution);
-
- if ($distribution) {
- $day = date('N', strtotime($distribution->date));
-
- $arrPointsSaleDistribution = self::searchAll([
- 'id_distribution' => $idDistribution
- ]) ;
-
- foreach ($arrPointsSaleDistribution as $pointSaleDistribution) {
- if ($boolDelivery &&
- (($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) ||
- ($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) ||
- ($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) ||
- ($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) ||
- ($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) ||
- ($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) ||
- ($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday)
- )) {
- $pointSaleDistribution->delivery = 1;
- } else {
- $pointSaleDistribution->delivery = 0;
- }
-
- $pointSaleDistribution->save();
- }
- }
- }
-
- }
|