You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductionProduit.php 2.2KB

8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace common\models;
  3. use yii\base\Object;
  4. use Yii;
  5. /**
  6. * This is the model class for table "production_produit".
  7. *
  8. * @property integer $id
  9. * @property integer $id_production
  10. * @property integer $id_produit
  11. * @property integer $actif
  12. */
  13. class ProductionProduit extends \yii\db\ActiveRecord
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName()
  19. {
  20. return 'production_produit';
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['id_production', 'id_produit', 'actif','quantite_max'], 'integer']
  29. ];
  30. }
  31. public function getProduit()
  32. {
  33. return $this->hasOne(Produit::className(), ['id'=>'id_produit']) ;
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'id_production' => 'Id Production',
  43. 'id_produit' => 'Id Produit',
  44. 'actif' => 'Actif',
  45. 'quantite_max' => 'Quantité max',
  46. ];
  47. }
  48. public static function findProduits($id_production) {
  49. $production_produits = ProductionProduit::find()
  50. ->with('produit')
  51. ->where(['id_production'=>$id_production])
  52. ->all() ;
  53. $arr_production_produits = [] ;
  54. $commandes = Commande::find()
  55. ->with('commandeProduits','user')
  56. ->joinWith('production')
  57. ->where(['production.id'=>$id_production])
  58. ->orderBy('date ASC')
  59. ->all() ;
  60. foreach($production_produits as $pp)
  61. {
  62. if(isset($pp->produit))
  63. {
  64. $arr_production_produits[$pp->id_produit] = [
  65. 'actif'=> (int) $pp->actif,
  66. 'epuise' => (int) $pp->produit->epuise,
  67. 'vrac' => (int) $pp->produit->vrac,
  68. 'quantite_max' => $pp->quantite_max,
  69. 'quantite_commandee' => Commande::getQuantiteProduit($pp->id_produit, $commandes),
  70. 'quantite_restante' => $pp->quantite_max - Commande::getQuantiteProduit($pp->id_produit, $commandes)
  71. ] ;
  72. }
  73. }
  74. return $arr_production_produits ;
  75. }
  76. }