您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProductionPointVente.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. {
  15. var $productions_point_vente ;
  16. /**
  17. * @inheritdoc
  18. */
  19. public static function tableName()
  20. {
  21. return 'production_point_vente';
  22. }
  23. /**
  24. * @inheritdoc
  25. */
  26. public function rules()
  27. {
  28. return [
  29. [['id_production', 'id_point_vente'], 'required'],
  30. [['id_production', 'id_point_vente', 'livraison'], 'integer'],
  31. ];
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function attributeLabels()
  37. {
  38. return [
  39. 'id_production' => 'Id Production',
  40. 'id_point_vente' => 'Id Point Vente',
  41. 'livraison' => 'Livraison',
  42. ];
  43. }
  44. public function getProduction()
  45. {
  46. return $this->hasOne(Production::className(), ['id' => 'id_production']) ;
  47. }
  48. public function getPointVente()
  49. {
  50. return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']) ;
  51. }
  52. public static function setAll($id_production, $bool_livraison)
  53. {
  54. $count_productions_point_vente = self::find()->
  55. where([
  56. 'id_production' => $id_production
  57. ])
  58. ->count() ;
  59. if(!$count_productions_point_vente)
  60. {
  61. $points_vente = PointVente::find()
  62. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  63. ->all();
  64. foreach($points_vente as $pv)
  65. {
  66. $production_pv = new ProductionPointVente() ;
  67. $production_pv->id_production = $id_production ;
  68. $production_pv->id_point_vente = $pv->id ;
  69. $production_pv->save() ;
  70. }
  71. }
  72. $production = Production::findOne($id_production) ;
  73. if($production)
  74. {
  75. $jour = date('N', strtotime($production->date)) ;
  76. $productions_point_vente = self::find()
  77. ->with(['production','pointVente'])
  78. ->where([
  79. 'id_production' => $id_production
  80. ])
  81. ->all() ;
  82. foreach($productions_point_vente as $production_pv)
  83. {
  84. if($bool_livraison &&
  85. ( ($jour == 1 && $production_pv->pointVente->livraison_lundi) ||
  86. ($jour == 2 && $production_pv->pointVente->livraison_mardi) ||
  87. ($jour == 3 && $production_pv->pointVente->livraison_mercredi) ||
  88. ($jour == 4 && $production_pv->pointVente->livraison_jeudi) ||
  89. ($jour == 5 && $production_pv->pointVente->livraison_vendredi) ||
  90. ($jour == 6 && $production_pv->pointVente->livraison_samedi) ||
  91. ($jour == 7 && $production_pv->pointVente->livraison_dimanche) ||
  92. $production_pv->pointVente->point_fabrication
  93. ))
  94. {
  95. $production_pv->livraison = 1 ;
  96. }
  97. else {
  98. $production_pv->livraison = 0 ;
  99. }
  100. $production_pv->save() ;
  101. }
  102. }
  103. }
  104. }