From: Alexander Smirnov Date: Mon, 31 Mar 2025 18:59:52 +0000 (+0300) Subject: [ERP-381] fix price X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f7e847946707097b0c3060dd07b735a08ad0897c;p=erp24_rep%2Fyii-erp24%2F.git [ERP-381] fix price --- diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 1d73c585..a38552a4 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -150,17 +150,13 @@ class BouquetController extends Controller $data = json_decode(Yii::$app->request->getRawBody(), true); $model = BouquetComposition::findOne($data['bouquetId']); - $cost = []; - $markup = []; + $costModels = []; foreach (BouquetComposition::getRegions() as $region_id) { - $cost[$region_id] = round($model->getBouquetCost($region_id, $data, true)); - $markup[$region_id] = round($model->getBouquetCostMarkup($region_id, $data, true), 2); + $costModels[$region_id] = $model->getCostModel($region_id, $data['data']); } return [ - 'selfcost' => round($model->getSelfCost($data), 2), - 'cost' => $cost, - 'markup' => $markup, + 'costModels' => $costModels, ]; } diff --git a/erp24/migrations/m250331_125814_create_Table_bouquet_composition_price.php b/erp24/migrations/m250331_125814_create_Table_bouquet_composition_price.php new file mode 100755 index 00000000..1f092d2f --- /dev/null +++ b/erp24/migrations/m250331_125814_create_Table_bouquet_composition_price.php @@ -0,0 +1,46 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'bouquet_id' => $this->integer()->notNull()->comment('ID букета'), + 'region_id' => $this->integer()->notNull()->comment('52 - Нижний Новгород, 77 - Москва'), + 'selfcost' => $this->float()->notNull()->comment('Себестоимость'), + 'selfcost_markup' => $this->float()->notNull()->defaultValue(30.0) + ->comment('Наценка над себестоимостью. По умолчанию 30%'), + 'selfcost_markup_price' => $this->float()->notNull() + ->comment('Наценка над себестоимостью в рублёвом эквиваленте'), + 'price' => $this->float()->notNull()->comment('Цена + наценка ~= selfcost * 130% * 115%'), + 'price_markup' => $this->float()->notNull()->defaultValue(15.0) + ->comment('Наценка над базовой ценой = себестоимостью * 130%. По умолчанию 15%'), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } +} diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 34f367af..23cd7b72 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -40,13 +40,12 @@ use yii_app\services\FileService; class BouquetComposition extends ActiveRecord { const REGION_NN = 52; - const REGIONO_MSK = 77; - const PROCENT_30 = 0.3; + const REGION_MSK = 77; public static function getRegions() { return [ self::REGION_NN, - self::REGIONO_MSK + self::REGION_MSK ]; } @@ -412,6 +411,48 @@ class BouquetComposition extends ActiveRecord $newPriceDynamic->price = round($cost); $newPriceDynamic->region_id = $region_id; $newPriceDynamic->save(); + + $pricesRegion = PricesRegion::find() + ->where(['product_id' => $this->guid, 'region_id' => $region_id]) + ->one(); + /* @var $pricesRegion PricesRegion */ + if (!$pricesRegion) { + $pricesRegion = new PricesRegion; + $pricesRegion->product_id = $this->guid; + $pricesRegion->region_id = $region_id; + } + $pricesRegion->price = $newPriceDynamic->price; + $pricesRegion->save(); + + $costModel = BouquetCompositionPrice::find()->where(['bouquet_id' => $this->id, 'region_id' => $region_id])->one(); + /* @var $costModel BouquetCompositionPrice */ + if (!$costModel) { + $costModel = new BouquetCompositionPrice; + $costModel->bouquet_id = $this->id; + $costModel->region_id = $region_id; + $costModel->selfcost = $this->getSelfCost(); + $costModel->selfcost_markup = 30; + $costModel->selfcost_markup_price = 0.3 * $costModel->selfcost; + } + $costModel->price = round($cost); + $costModel->price_markup = $costModel->selfcost > 0 ? 100 * $costModel->price / ($costModel->selfcost_markup_price + $costModel->selfcost) : 0; + $costModel->save(); + } + + public function getCostModel($region_id, $data = null, $force = false) { + $costModel = BouquetCompositionPrice::find()->where(['bouquet_id' => $this->id, 'region_id' => $region_id])->one(); + if (!$costModel || $force) { + $costModel = new BouquetCompositionPrice; + $costModel->bouquet_id = $this->id; + $costModel->region_id = $region_id; + $costModel->selfcost = $this->getSelfCost($data); + $costModel->selfcost_markup = 30; + $costModel->selfcost_markup_price = 0.3 * $costModel->selfcost; + $costModel->price = round(1.15 * ($costModel->selfcost_markup_price + $costModel->selfcost)); + $costModel->price_markup = $costModel->selfcost > 0 ? 100 * $costModel->price / ($costModel->selfcost_markup_price + $costModel->selfcost) : 0; + $costModel->save(); + } + return $costModel; } public function getBouquetCost($region_id, $data = null, $forceDefault = false) { @@ -535,4 +576,4 @@ class BouquetComposition extends ActiveRecord } return (int)date('d') > 10; } -} \ No newline at end of file +} diff --git a/erp24/records/BouquetCompositionPrice.php b/erp24/records/BouquetCompositionPrice.php new file mode 100644 index 00000000..03588cb0 --- /dev/null +++ b/erp24/records/BouquetCompositionPrice.php @@ -0,0 +1,58 @@ + null], + [['bouquet_id', 'region_id'], 'integer'], + [['selfcost', 'selfcost_markup', 'selfcost_markup_price', 'price', 'price_markup'], 'number'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'bouquet_id' => 'Bouquet ID', + 'region_id' => 'Region ID', + 'selfcost' => 'Selfcost', + 'selfcost_markup' => 'Selfcost Markup', + 'selfcost_markup_price' => 'Selfcost Markup Price', + 'price' => 'Price', + 'price_markup' => 'Price Markup', + ]; + } +} diff --git a/erp24/views/bouquet/_product_edit.php b/erp24/views/bouquet/_product_edit.php index 7bb4460d..3f59eb2f 100644 --- a/erp24/views/bouquet/_product_edit.php +++ b/erp24/views/bouquet/_product_edit.php @@ -1,9 +1,14 @@ -registerCSS('.cost-value {max-width: 75px}'); +/* @var $costModelsByRegionId array */ + ?> 'products', @@ -27,10 +32,13 @@ $this->registerCSS('.cost-value {max-width: 75px}');
Нижегородская обл.
-

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

-

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

-

Цена: ₽. +%

+ +

Себестоимость: selfcost) ?> ₽

+

Наценка: +selfcost_markup ?>% / +selfcost_markup_price) ?>₽

+

Цена: price), [ + "type" => "number", "class" => "cost-value region" . BouquetComposition::REGION_NN, + "min" => round($costModelNN->selfcost_markup_price + $costModelNN->selfcost), + "step" => 1]) ?>₽. +price_markup, 2) ?>%

@@ -43,10 +51,13 @@ $this->registerCSS('.cost-value {max-width: 75px}');
Московская обл.
-

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

-

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

-

Цена: ₽. +%

+ +

Себестоимость: selfcost) ?> ₽

+

Наценка: +selfcost_markup ?>% / +selfcost_markup_price) ?>₽

+

Цена: price), [ + "type" => "number", "class" => "cost-value region" . BouquetComposition::REGION_MSK, + "min" => round($costModelMsk->selfcost_markup_price + $costModelMsk->selfcost), + "step" => 1]) ?>₽. +price_markup, 2) ?>%

diff --git a/erp24/views/bouquet/_product_list.php b/erp24/views/bouquet/_product_list.php index 8d898638..d9b99bd7 100644 --- a/erp24/views/bouquet/_product_list.php +++ b/erp24/views/bouquet/_product_list.php @@ -1,3 +1,9 @@ + +
Название
Кол-во
@@ -31,9 +37,10 @@
Нижегородская обл.
- Себестоимость: getSelfCost()) ?>₽
- Наценка: +30% / +getSelfCost()) ?>₽
- Цена: getBouquetCost(BouquetComposition::REGION_NN)) ?>₽. +getBouquetCostMarkup(BouquetComposition::REGION_NN), 2) ?>%
+ getCostModel(BouquetComposition::REGION_NN); ?> + Себестоимость: selfcost) ?>₽
+ Наценка: +selfcost_markup) ?>% / +selfcost_markup_price) ?>₽
+ Цена: price) ?>₽. +price_markup, 2) ?>%
@@ -42,9 +49,10 @@
Московская обл.
- Себестоимость: getSelfCost()) ?>₽
- Наценка: +30% / +getSelfCost()) ?>₽
- Цена: getBouquetCost(BouquetComposition::REGIONO_MSK)) ?>₽. +getBouquetCostMarkup(BouquetComposition::REGIONO_MSK), 2) ?>%
+ getCostModel(BouquetComposition::REGION_MSK); ?> + Себестоимость: selfcost) ?>₽
+ Наценка: +selfcost_markup) ?>% / +selfcost_markup_price) ?>₽
+ Цена: price) ?>₽. +price_markup, 2) ?>%
diff --git a/erp24/views/bouquet/index.php b/erp24/views/bouquet/index.php index 587401ae..54ff5662 100644 --- a/erp24/views/bouquet/index.php +++ b/erp24/views/bouquet/index.php @@ -10,6 +10,7 @@ use yii_app\records\Files; use yii_app\records\MatrixType; use yii_app\records\Products1c; use yii_app\records\WriteOffsErp; +use yii_app\records\BouquetCompositionPrice; /** @var yii\web\View $this */ $this->title = 'Содержание матрицы'; @@ -101,6 +102,10 @@ $this->title = 'Содержание матрицы'; $imageUrls += array_fill(0, 3 - count($imageUrls), null); $compositionHtml .= "
"; + $cmNN = $model->getCostModel(BouquetComposition::REGION_NN); + $cmMsk = $model->getCostModel(BouquetComposition::REGION_MSK); + /* @var $cmNN BouquetCompositionPrice */ + /* @var $cmMsk BouquetCompositionPrice */ return "
@@ -113,17 +118,17 @@ $this->title = 'Содержание матрицы';
Нижегородская обл.
- Себестоимость: " . round($model->getSelfCost()) . "₽
- Наценка: +30% / +" . round(BouquetComposition::PROCENT_30 * $model->getSelfCost()) . "₽
- Цена: " . round($model->getBouquetCost(BouquetComposition::REGION_NN)) . "₽. +" . round($model->getBouquetCostMarkup(BouquetComposition::REGION_NN), 2) . "%
+ Себестоимость: " . round($cmNN->selfcost) . "₽
+ Наценка: +". round($cmNN->selfcost_markup) ."% / +" . round($cmNN->selfcost_markup_price) . "₽
+ Цена: " . round($cmNN->price) . "₽. +" . round($cmNN->price_markup, 2) . "%
Московская обл.
- Себестоимость: " . round($model->getSelfCost()) . "₽
- Наценка: +30% / +" . round(BouquetComposition::PROCENT_30 * $model->getSelfCost()) . "₽
- Цена: " . round($model->getBouquetCost(BouquetComposition::REGIONO_MSK)) . "₽. +" . round($model->getBouquetCostMarkup(BouquetComposition::REGIONO_MSK), 2) . "%
+ Себестоимость: " . round($cmMsk->selfcost) . "₽
+ Наценка: +". round($cmMsk->selfcost_markup) ."% / +" . round($cmMsk->selfcost_markup_price) . "₽
+ Цена: " . round($cmMsk->price) . "₽. +" . round($cmMsk->price_markup, 2) . "%
diff --git a/erp24/views/bouquet/update.php b/erp24/views/bouquet/update.php index a185d669..4961e29b 100644 --- a/erp24/views/bouquet/update.php +++ b/erp24/views/bouquet/update.php @@ -57,11 +57,9 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO 'dual-list-form']); ?>
getBouquetCost($region_id); - $markup[$region_id] = $model->getBouquetCostMarkup($region_id); + $costModels[$region_id] = $model->getCostModel($region_id); } ?> render('_product_edit', [ @@ -69,9 +67,7 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO 'selectedItems' => $selectedItems, 'isCreate' => false, 'listContainerSize' => [], - 'selfCost' => $model->getSelfCost(), - 'cost' => $cost, - 'markUp' => $markup, + 'costModelsByRegionId' => $costModels, ]); ?> \ No newline at end of file diff --git a/erp24/web/js/bouquet/bouquet.js b/erp24/web/js/bouquet/bouquet.js index 56cbcb27..3f469c22 100644 --- a/erp24/web/js/bouquet/bouquet.js +++ b/erp24/web/js/bouquet/bouquet.js @@ -167,23 +167,12 @@ $('.calculate-btn').on('click', function () { dataType: 'json', success: function (response) { if (response) { - if (response.cost[52] !== undefined) { - $('.cost-value.region52').val(+response.cost[52]); - } - if (response.cost[77] !== undefined) { - $('.cost-value.region77').val(+response.cost[77]); - } - if (response.selfcost !== undefined) { - $('.selfcost-value').text(Math.round(response.selfcost)); - $('.markup-value').text(Math.round(0.3 * (+response.selfcost))); - $('.cost-value').attr('min', Math.round(1.3 * (+response.selfcost))); - } - if (response.markup[52] !== undefined) { - $('.markup-cost-value.region52').text(Math.round(+response.markup[52])); - } - if (response.markup[77] !== undefined) { - $('.markup-cost-value.region77').text(Math.round(+response.markup[77])); - } + $.each(response.costModels, function (regionId, costModel) { + $('.cost-value.region' + regionId).val(+costModel.price).attr('min', Math.round(costModel.selfcost + costModel.selfcost_markup_price)); + $('.selfcost-value.region' + regionId).text(Math.round(costModel.selfcost)); + $('.markup-value.region' + regionId).text(Math.round(costModel.selfcost_markup)); + $('.markup-cost-value.region' + regionId).text(Math.round(costModel.price_markup)); + }) } }, error: function (xhr, status, error) {