From 5dd789053e960eb4d3e8c8276745288379f276cc Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 28 Mar 2025 15:23:07 +0300 Subject: [PATCH] =?utf8?q?[ERP-381]=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/BouquetController.php | 16 ++++++++++---- erp24/records/BouquetComposition.php | 13 ++++++----- erp24/views/bouquet/_product_edit.php | 29 ++++++++++++++++++++----- erp24/views/bouquet/_product_list.php | 15 +++++++++++-- erp24/views/bouquet/index.php | 9 +++++++- erp24/views/bouquet/update.php | 4 ++-- erp24/web/js/bouquet/bouquet.js | 19 +++++++++++----- 7 files changed, 78 insertions(+), 27 deletions(-) diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index ac1eb2ea..fb8b94cf 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -65,8 +65,10 @@ class BouquetController extends Controller $model = BouquetComposition::findModel($id); if (Yii::$app->request->isPost && $products = Yii::$app->request->post('products_quantity')) { - $cost = Yii::$app->request->post('cost-value'); - $model->setCost($cost); + $cost = Yii::$app->request->post("cost-value"); + foreach ($cost as $region_id => $price) { + $model->setCost($region_id, $price); + } BouquetCompositionProducts::updateProducts($model->id, $products); return $this->redirect(['view', 'id' => $id]); } @@ -150,8 +152,14 @@ class BouquetController extends Controller return [ 'selfcost' => round($model->getSelfCost($data), 2), - 'cost' => round($model->getBouquetCost($data, true)), - 'markup' => round($model->getBouquetCostMarkup($data, true), 2), + 'cost' => [ + 52 => round($model->getBouquetCost(52, $data, true)), + 77 => round($model->getBouquetCost(77, $data, true)), + ], + 'markup' => [ + 52 => round($model->getBouquetCostMarkup(52, $data, true), 2), + 77 => round($model->getBouquetCostMarkup(77, $data, true), 2), + ] ]; } diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 32953abb..f99890eb 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -382,9 +382,9 @@ class BouquetComposition extends ActiveRecord // return $cost; // } - public function setCost($cost) { + public function setCost($region_id, $cost) { $priceModel = PricesDynamic::find() - ->where(['product_id' => $this->guid]) + ->where(['product_id' => $this->guid, 'region_id' => $region_id]) ->andWhere(['=', 'active', PricesDynamic::ACTIVE]) ->one(); /* @var PricesDynamic $priceModel */ @@ -399,21 +399,22 @@ class BouquetComposition extends ActiveRecord $newPriceDynamic->date_from = date('Y-m-d H:i:s'); $newPriceDynamic->date_to = date('2100-01-01 00:00:00'); $newPriceDynamic->price = round($cost); + $newPriceDynamic->region_id = $region_id; $newPriceDynamic->save(); } - public function getBouquetCost($data = null, $forceDefault = false) { + public function getBouquetCost($region_id, $data = null, $forceDefault = false) { $priceModel = PricesDynamic::find() - ->where(['product_id' => $this->guid]) + ->where(['product_id' => $this->guid, 'region_id' => $region_id]) ->andWhere(['=', 'active', PricesDynamic::ACTIVE]) ->one(); /* @var PricesDynamic $priceModel */ return $priceModel && !$forceDefault ? $priceModel->price : $this->getSelfCost($data) * 1.3 * 1.15; } - public function getBouquetCostMarkup($data = null, $forceDefault = false) { + public function getBouquetCostMarkup($region_id, $data = null, $forceDefault = false) { $selfCost = $this->getSelfCost($data); - return $selfCost > 0 ? ($this->getBouquetCost($data, $forceDefault) / (1.3 * $selfCost) - 1) * 100 : 0; + return $selfCost > 0 ? ($this->getBouquetCost($region_id, $data, $forceDefault) / (1.3 * $selfCost) - 1) * 100 : 0; } // /** diff --git a/erp24/views/bouquet/_product_edit.php b/erp24/views/bouquet/_product_edit.php index ad6bceef..6134b8bd 100644 --- a/erp24/views/bouquet/_product_edit.php +++ b/erp24/views/bouquet/_product_edit.php @@ -22,32 +22,49 @@ $this->registerCSS('.cost-value {max-width: 75px}');
+

Нижегородская обл.

Себестоимость: ₽

Наценка: +30% / +₽

-

Цена: ₽. +%

+

Цена: ₽. +%

-
+
+ +
+
+

Московская обл.

+
+
+
+
+

Себестоимость: ₽

+

Наценка: +30% / +₽

+

Цена: ₽. +%

+
+
'btn btn-warning calculate-btn w-100']) ?>
-
- 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?> -
+
+ 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?> +
'btn btn-warning calculate-btn w-100']) ?>
+
+