hasOne(Product::className(), ['id' => 'id_product']); } public function getTaxRate() { return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); } /** * @inheritdoc */ public function rules() { return [ [['id_order', 'id_product', 'quantity'], 'required'], [['id_order', 'id_product', 'id_tax_rate'], 'integer'], [['unit'], 'string', 'max' => 255], [['quantity'], 'number', 'min' => 0], [['price', 'invoice_price'], 'double'], [['description'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'id_order' => 'Commande', 'id_product' => 'Product', 'quantity' => 'Quantité', 'unit' => 'Unité', 'id_tax_rate' => 'Taxe', 'description' => 'Description', 'price' => 'Prix', 'invoice_price' => 'Prix facturé', ]; } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => ['taxRate'], 'join_with' => [], 'orderby' => '', 'attribute_id_producer' => '' ]; } public function afterFind() { if ($this->taxRate == null) { $this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); } parent::afterFind(); } public function getPrice() { return $this->price ; } public function getInvoicePrice() { return $this->invoice_price ; } /** * Retourne le prix du produit avec taxe */ public function getPriceWithTax() { return Price::getPriceWithTax($this->price, $this->taxRate->value); } public function getPriceByTypeTotal($typeTotal = Order::AMOUNT_TOTAL) { if($typeTotal == Order::INVOICE_AMOUNT_TOTAL && $this->invoice_price) { return $this->invoice_price; } return $this->price; } }