|
- <?php
-
- namespace common\models;
-
- use Yii;
- use common\models\PointVente;
- use common\models\Production;
-
- /**
- * This is the model class for table "production_point_vente".
- *
- * @property integer $id_production
- * @property integer $id_point_vente
- * @property integer $livraison
- */
- class ProductionPointVente extends \yii\db\ActiveRecord {
-
- var $productions_point_vente;
-
- /**
- * @inheritdoc
- */
- public static function tableName() {
- return 'production_point_vente';
- }
-
- /**
- * @inheritdoc
- */
- public function rules() {
- return [
- [['id_production', 'id_point_vente'], 'required'],
- [['id_production', 'id_point_vente', 'livraison'], 'integer'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels() {
- return [
- 'id_production' => 'Id Production',
- 'id_point_vente' => 'Id Point Vente',
- 'livraison' => 'Livraison',
- ];
- }
-
- public function getProduction() {
- return $this->hasOne(Production::className(), ['id' => 'id_production']);
- }
-
- public function getPointVente() {
- return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']);
- }
-
- public static function setAll($id_production, $bool_livraison) {
- $count_productions_point_vente = self::find()->
- where([
- 'id_production' => $id_production
- ])
- ->count();
-
- if (!$count_productions_point_vente) {
- $points_vente = PointVente::find()
- ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
- ->all();
-
- foreach ($points_vente as $pv) {
- $production_pv = new ProductionPointVente();
- $production_pv->id_production = $id_production;
- $production_pv->id_point_vente = $pv->id;
- $production_pv->save();
- }
- }
-
- $production = Production::findOne($id_production);
-
- if ($production) {
- $jour = date('N', strtotime($production->date));
-
- $productions_point_vente = self::find()
- ->with(['production', 'pointVente'])
- ->where([
- 'id_production' => $id_production
- ])
- ->all();
-
- foreach ($productions_point_vente as $production_pv) {
- if ($bool_livraison &&
- ( ($jour == 1 && $production_pv->pointVente->livraison_lundi) ||
- ($jour == 2 && $production_pv->pointVente->livraison_mardi) ||
- ($jour == 3 && $production_pv->pointVente->livraison_mercredi) ||
- ($jour == 4 && $production_pv->pointVente->livraison_jeudi) ||
- ($jour == 5 && $production_pv->pointVente->livraison_vendredi) ||
- ($jour == 6 && $production_pv->pointVente->livraison_samedi) ||
- ($jour == 7 && $production_pv->pointVente->livraison_dimanche) ||
- $production_pv->pointVente->point_fabrication
- )) {
- $production_pv->livraison = 1;
- } else {
- $production_pv->livraison = 0;
- }
-
- $production_pv->save();
- }
- }
- }
-
- }
|