]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-381] правки
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Mar 2025 12:23:07 +0000 (15:23 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Mar 2025 12:23:07 +0000 (15:23 +0300)
erp24/controllers/BouquetController.php
erp24/records/BouquetComposition.php
erp24/views/bouquet/_product_edit.php
erp24/views/bouquet/_product_list.php
erp24/views/bouquet/index.php
erp24/views/bouquet/update.php
erp24/web/js/bouquet/bouquet.js

index ac1eb2eadacd76886d4dbf2f0ae455a4688788f1..fb8b94cfc397fa49c57f8daa6779c6c86cf86010 100644 (file)
@@ -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),
+            ]
         ];
     }
 
index 32953abba2412294f9d19b48fa8b0450b6cd5005..f99890eb224b691bb48d063cfb5c56fe43fbebd5 100644 (file)
@@ -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;
     }
 
 //    /**
index ad6bceef9b2dfcc0460f961fcd8331eb26bd2657..6134b8bddd04934516a9df189ab4224a7e3d3d29 100644 (file)
@@ -22,32 +22,49 @@ $this->registerCSS('.cost-value {max-width: 75px}');
 
 <div class="row">
     <div class="col-md-6 position-relative">
+        <h4>Нижегородская обл.</h4>
         <div class="pt-2 position-relative content-wrapper">
             <div class="loader-overlay d-none">
                 <div class="spinner-border text-primary" role="status"></div>
             </div>
             <p class="mb-1"><strong>Себестоимость:</strong> <span class="selfcost-value"><?= round($selfCost ?? 0) ?></span> ₽</p>
             <p class="mb-1"><strong>Наценка:</strong> +30% / +<span class="markup-value"><?= round(0.3 * ($selfCost ?? 0)) ?></span>₽</p>
-            <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value" class="cost-value" value="<?= round($cost) ?>"
-                                                          min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value"><?= round($markUp, 2) ?></span>%</p>
+            <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value[52]" class="cost-value region52" value="<?= round($cost[52]) ?>"
+                                                          min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value region52"><?= round($markUp[52], 2) ?></span>%</p>
         </div>
     </div>
 
-    <div class="col-md-2"></div>
+</div>
+
+<div class="row mt-5">
+    <div class="col-md-6 position-relative">
+        <h4>Московская обл.</h4>
+        <div class="pt-2 position-relative content-wrapper">
+            <div class="loader-overlay d-none">
+                <div class="spinner-border text-primary" role="status"></div>
+            </div>
+            <p class="mb-1"><strong>Себестоимость:</strong> <span class="selfcost-value"><?= round($selfCost ?? 0) ?></span> ₽</p>
+            <p class="mb-1"><strong>Наценка:</strong> +30% / +<span class="markup-value"><?= round(0.3 * ($selfCost ?? 0)) ?></span>₽</p>
+            <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value[77]" class="cost-value region77" value="<?= round($cost[77]) ?>"
+                                                          min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value region77"><?= round($markUp[77], 2) ?></span>%</p>
+        </div>
+    </div>
 
     <?php if (!$isCreate) {?>
         <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
             <?= Html::button('Рассчитать', ['class' => 'btn btn-warning calculate-btn w-100']) ?>
         </div>
-    <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
-        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?>
-    </div>
+        <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
+            <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?>
+        </div>
     <?php } else { ?>
         <div class="col-md-4 d-flex justify-content-end align-items-end px-3 w-100">
             <?= Html::button('Рассчитать', ['class' => 'btn btn-warning calculate-btn w-100']) ?>
         </div>
     <?php }  ?>
+
 </div>
+
 <style>
     .content-wrapper {
         position: relative;
index 41446e475044c1d389845619f2d731d6978d0adb..8dde69c42bc8be66bcd02e5c197cc75eaf71e63e 100644 (file)
 
 <div class="row pt-3">
     <div class="col-md-8">
-        <strong>Нижегородская область</strong>
+        <strong>Нижегородская обл.</strong>
         <div class='self-cost pt-3' style='display: flex; gap: 10px;'>
             Себестоимость: <?= round($model->getSelfCost()) ?>₽<br>
             Наценка: +30% / +<?= round(0.3 * $model->getSelfCost()) ?>₽<br>
-            Цена: <?= round($model->getBouquetCost()) ?>₽. +<?= round($model->getBouquetCostMarkup(), 2) ?>%<br>
+            Цена: <?= round($model->getBouquetCost(52)) ?>₽. +<?= round($model->getBouquetCostMarkup(52), 2) ?>%<br>
+        </div>
+    </div>
+</div>
+
+<div class="row pt-3">
+    <div class="col-md-8">
+        <strong>Московская обл.</strong>
+        <div class='self-cost pt-3' style='display: flex; gap: 10px;'>
+            Себестоимость: <?= round($model->getSelfCost()) ?>₽<br>
+            Наценка: +30% / +<?= round(0.3 * $model->getSelfCost()) ?>₽<br>
+            Цена: <?= round($model->getBouquetCost(77)) ?>₽. +<?= round($model->getBouquetCostMarkup(77), 2) ?>%<br>
         </div>
     </div>
     <div class="col-md-4">
index 133e6269b633276f29ad0f28f4572f06d3aaeab5..79d634d1bdceb1759dc181469964999e8561b48f 100644 (file)
@@ -109,10 +109,17 @@ $this->title = 'Содержание матрицы';
                                      style='height: 160px; padding: 10px; overflow-y: auto; overflow-x: hidden; max-width: 100%; word-wrap: break-word;'>
                                     {$compositionHtml}
                                 </div>
+                                <strong>Нижегородская обл.</strong>
+                                <div class='self-cost pt-3 mb-2' style='display: flex; gap: 10px;'>
+                                    Себестоимость: " . round($model->getSelfCost()) . "₽<br>
+                                    Наценка: +30% / +" . round(0.3 * $model->getSelfCost()) . "₽<br>
+                                    Цена: " . round($model->getBouquetCost(52)) . "₽. +" . round($model->getBouquetCostMarkup(52), 2) . "%<br>
+                                </div>
+                                <strong>Московская обл.</strong>
                                 <div class='self-cost pt-3' style='display: flex; gap: 10px;'>
                                     Себестоимость: " . round($model->getSelfCost()) . "₽<br>
                                     Наценка: +30% / +" . round(0.3 * $model->getSelfCost()) . "₽<br>
-                                    Цена: " . round($model->getBouquetCost()) . "₽. +" . round($model->getBouquetCostMarkup(), 2) . "%<br>
+                                    Цена: " . round($model->getBouquetCost(77)) . "₽. +" . round($model->getBouquetCostMarkup(77), 2) . "%<br>
                                 </div>
                             </div>
 
index 0e404d7b444e38f098454a845d50fa325c1d457b..4e721ed0e1aa5d6f5d3a2306e5c5c1ce980b9e2a 100644 (file)
@@ -61,8 +61,8 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
                 'isCreate' => false,
                 'listContainerSize' => [],
                 'selfCost' => $model->getSelfCost(),
-                'cost' => $model->getBouquetCost(),
-                'markUp' => $model->getBouquetCostMarkup(),
+                'cost' => [ 52 => $model->getBouquetCost(52), 77 => $model->getBouquetCost(77)],
+                'markUp' => [ 52 => $model->getBouquetCostMarkup(52), 77 => $model->getBouquetCostMarkup(77)],
             ]); ?>
             <?php ActiveForm::end(); ?>
         </div>
\ No newline at end of file
index fe267311a99641a53fb0dfa102cb39c5e79165ef..e38a3fca7569352bf831a3c933ca4360476b0c5f 100644 (file)
@@ -126,8 +126,9 @@ $(document).on('input change', '.quantity-input', function () {
 
 
 $('.cost-value').on('change', function () {
-    const selfCost = $('.selfcost-value');
-    $('.markup-cost-value').text(+selfCost.text() > 0 ? Math.round((this.value / (1.3 * (+selfCost.text())) - 1)*10000) / 100 : 0);
+    const root = $(this).parent().parent();
+    const selfCost = root.find('.selfcost-value');
+    root.find('.markup-cost-value').text(+selfCost.text() > 0 ? Math.round((this.value / (1.3 * (+selfCost.text())) - 1)*10000) / 100 : 0);
 });
 
 $('.calculate-btn').on('click', function () {
@@ -157,16 +158,22 @@ $('.calculate-btn').on('click', function () {
         dataType: 'json',
         success: function (response) {
             if (response) {
-                if (response.cost !== undefined) {
-                    $('.cost-value').val(+response.cost);
+                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 !== undefined) {
-                    $('.markup-cost-value').text(Math.round(+response.markup));
+                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]));
                 }
             }
         },