示例#1
0
 protected function updatePrice($params)
 {
     $categories = PriceCategory::find()->all();
     foreach ($categories as $category) {
         $price = Price::findOne(['id_product' => $params['id_product'], 'id_price_category' => $category->id_price_category]);
         if (!$price) {
             $price = new Price();
             $price->setAttributes(['id_product' => $params['id_product'], 'id_price_category' => $category->id_price_category, 'id_uom' => $params['id_uom'], 'price' => 0]);
         }
         if ($price->canSetProperty('logParams')) {
             $logParams = [];
             foreach (['app', 'id_ref'] as $key) {
                 if (isset($params[$key]) || array_key_exists($key, $params)) {
                     $logParams[$key] = $params[$key];
                 }
             }
             $price->logParams = $logParams;
         }
         $price->price = $this->executePriceFormula($category->formula, $params['price']);
         if (!$price->save()) {
             throw new UserException(implode(",\n", $price->firstErrors));
         }
     }
     return true;
 }
示例#2
0
 public function search($params)
 {
     $query = PriceModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_product' => $this->id_product, 'id_price_category' => $this->id_price_category, 'id_uom' => $this->id_uom, 'create_by' => $this->create_by, 'update_by' => $this->update_by]);
     $query->andFilterWhere(['like', 'price', $this->price])->andFilterWhere(['like', 'create_date', $this->create_date])->andFilterWhere(['like', 'update_date', $this->update_date]);
     return $dataProvider;
 }
示例#3
0
 public static function updatePrice($params, $logs = [])
 {
     $categories = PriceCategory::find()->all();
     foreach ($categories as $category) {
         $price = Price::findOne(['id_product' => $params['id_product'], 'id_price_category' => $category->id_price_category]);
         if (!$price) {
             $price = new Price();
             $price->setAttributes(['id_product' => $params['id_product'], 'id_price_category' => $category->id_price_category, 'id_uom' => $params['id_uom'], 'price' => 0]);
         }
         if (!empty($logs) && $price->canSetProperty('logParams')) {
             $price->logParams = $logs;
         }
         $price->price = self::executePriceFormula($category->formula, $params['price']);
         if (!$price->save()) {
             throw new UserException(implode(",\n", $price->firstErrors));
         }
     }
     return true;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPrices()
 {
     return $this->hasMany(Price::className(), ['id_price_category' => 'id_price_category']);
 }
 /**
  * Finds the Price model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id_product
  * @param integer $id_price_category
  * @return Price the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id_product, $id_price_category)
 {
     if (($model = Price::findOne(['id_product' => $id_product, 'id_price_category' => $id_price_category])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPrices()
 {
     return $this->hasMany(Price::className(), ['id_uom' => 'id_uom']);
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPrice()
 {
     return $this->hasOne(Price::className(), ['id_product' => 'id_product']);
 }