Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProductionPointVente.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use common\models\PointVente;
  5. use common\models\Production;
  6. /**
  7. * This is the model class for table "production_point_vente".
  8. *
  9. * @property integer $id_production
  10. * @property integer $id_point_vente
  11. * @property integer $livraison
  12. */
  13. class ProductionPointVente extends \yii\db\ActiveRecord {
  14. var $productions_point_vente;
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName() {
  19. return 'production_point_vente';
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public function rules() {
  25. return [
  26. [['id_production', 'id_point_vente'], 'required'],
  27. [['id_production', 'id_point_vente', 'livraison'], 'integer'],
  28. ];
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function attributeLabels() {
  34. return [
  35. 'id_production' => 'Id Production',
  36. 'id_point_vente' => 'Id Point Vente',
  37. 'livraison' => 'Livraison',
  38. ];
  39. }
  40. public function getProduction() {
  41. return $this->hasOne(Production::className(), ['id' => 'id_production']);
  42. }
  43. public function getPointVente() {
  44. return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']);
  45. }
  46. public static function setAll($id_production, $bool_livraison) {
  47. $count_productions_point_vente = self::find()->
  48. where([
  49. 'id_production' => $id_production
  50. ])
  51. ->count();
  52. if (!$count_productions_point_vente) {
  53. $points_vente = PointVente::find()
  54. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  55. ->all();
  56. foreach ($points_vente as $pv) {
  57. $production_pv = new ProductionPointVente();
  58. $production_pv->id_production = $id_production;
  59. $production_pv->id_point_vente = $pv->id;
  60. $production_pv->save();
  61. }
  62. }
  63. $production = Production::findOne($id_production);
  64. if ($production) {
  65. $jour = date('N', strtotime($production->date));
  66. $productions_point_vente = self::find()
  67. ->with(['production', 'pointVente'])
  68. ->where([
  69. 'id_production' => $id_production
  70. ])
  71. ->all();
  72. foreach ($productions_point_vente as $production_pv) {
  73. if ($bool_livraison &&
  74. ( ($jour == 1 && $production_pv->pointVente->livraison_lundi) ||
  75. ($jour == 2 && $production_pv->pointVente->livraison_mardi) ||
  76. ($jour == 3 && $production_pv->pointVente->livraison_mercredi) ||
  77. ($jour == 4 && $production_pv->pointVente->livraison_jeudi) ||
  78. ($jour == 5 && $production_pv->pointVente->livraison_vendredi) ||
  79. ($jour == 6 && $production_pv->pointVente->livraison_samedi) ||
  80. ($jour == 7 && $production_pv->pointVente->livraison_dimanche) ||
  81. $production_pv->pointVente->point_fabrication
  82. )) {
  83. $production_pv->livraison = 1;
  84. } else {
  85. $production_pv->livraison = 0;
  86. }
  87. $production_pv->save();
  88. }
  89. }
  90. }
  91. }