|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
-
-
-
- namespace common\models;
-
- use common\helpers\GlobalParam;
- use common\helpers\Price;
- use Yii;
- use common\components\ActiveRecordCommon;
-
-
- class ProductOrder extends ActiveRecordCommon
- {
-
-
-
- public static function tableName()
- {
- return 'product_order';
- }
-
-
-
-
- public function getProduct()
- {
- return $this->hasOne(Product::className(), ['id' => 'id_product']);
- }
-
- public function getTaxRate()
- {
- return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']);
- }
-
-
-
- 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']
- ];
- }
-
-
-
- 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é',
- ];
- }
-
-
-
- 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 ;
- }
-
-
-
- public function getPriceWithTax()
- {
- return Price::getPriceWithTax($this->price, $this->taxRate->value);
- }
-
- }
|