Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

84 Zeilen
2.2KB

  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. * @inheritdoc
  16. */
  17. public static function tableName() {
  18. return 'production_produit';
  19. }
  20. /**
  21. * @inheritdoc
  22. */
  23. public function rules() {
  24. return [
  25. [['id_production', 'id_produit', 'actif', 'quantite_max'], 'integer']
  26. ];
  27. }
  28. public function getProduit() {
  29. return $this->hasOne(Produit::className(), ['id' => 'id_produit']);
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function attributeLabels() {
  35. return [
  36. 'id' => 'ID',
  37. 'id_production' => 'Id Production',
  38. 'id_produit' => 'Id Produit',
  39. 'actif' => 'Actif',
  40. 'quantite_max' => 'Quantité max',
  41. ];
  42. }
  43. public static function findProduits($id_production) {
  44. $production_produits = ProductionProduit::find()
  45. ->with('produit')
  46. ->where(['id_production' => $id_production])
  47. ->all();
  48. $arr_production_produits = [];
  49. $commandes = Commande::find()
  50. ->with('commandeProduits', 'user')
  51. ->joinWith('production')
  52. ->where(['production.id' => $id_production])
  53. ->orderBy('date ASC')
  54. ->all();
  55. foreach ($production_produits as $pp) {
  56. if (isset($pp->produit)) {
  57. $arr_production_produits[$pp->id_produit] = [
  58. 'actif' => (int) $pp->actif,
  59. 'epuise' => (int) $pp->produit->epuise,
  60. 'vrac' => (int) $pp->produit->vrac,
  61. 'quantite_max' => $pp->quantite_max,
  62. 'quantite_commandee' => Commande::getQuantiteProduit($pp->id_produit, $commandes),
  63. 'quantite_restante' => $pp->quantite_max - Commande::getQuantiteProduit($pp->id_produit, $commandes)
  64. ];
  65. }
  66. }
  67. return $arr_production_produits;
  68. }
  69. }