]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-389 ERP-391 Реализовать зависимость от наличия прогноза ОС МБ origin/feature_zozirova_erp-389_change_percent
authormarina <m.zozirova@gmail.com>
Wed, 26 Mar 2025 06:42:38 +0000 (09:42 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 26 Mar 2025 06:42:38 +0000 (09:42 +0300)
erp24/controllers/BouquetController.php
erp24/records/BouquetCompositionProducts.php
erp24/views/bouquet/_product_list.php
erp24/web/js/bouquet/bouquet.js

index a3c31f76054ce516e1d225591c72452f07f258ff..ef192fbdf156e4bd0cb1ff6ad8b5273d9f7280db 100644 (file)
@@ -207,4 +207,28 @@ class BouquetController extends Controller
 
         return $this->redirect(Yii::$app->request->referrer);
     }
+
+    public function actionGetProductListData()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        $request = Yii::$app->request;
+
+        $bouquet_id = (int) $request->get('id');
+        $month = (int) $request->get('month');
+        $year = (int) $request->get('year');
+
+        $products = BouquetCompositionProducts::find()->where(['bouquet_id' => $bouquet_id])->all();
+
+        $data = [];
+
+        foreach ($products as $product) {
+            $data[] = [
+                'product_guid' => $product->product_guid,
+                'buildPercentage' => $product->getBuildPercentage($year, $month),
+                'averageNumberOfPieces' => $product->getAverageNumberOfPieces($year, $month),
+            ];
+        }
+
+        return $data;
+    }
 }
\ No newline at end of file
index 17a280e8b73d562f98f10acb38240fcddf34b2f7..25f2dc06464083da983b2619106d662d0c66b6cd 100644 (file)
@@ -228,24 +228,44 @@ class BouquetCompositionProducts extends ActiveRecord
         return round($medianProfitability, 2);
     }
 
-    public function getBuildPercentage(): float
+    public function getBuildPercentage(int $year = null, int $month = null): float
     {
-        $totalAssemblies = BouquetCompositionProducts::find()->count();
+        $year = $year ?? date('Y');
+        $month = $month ?? date('m');
+        $periodBouquets = BouquetForecast::find()
+            ->andWhere(['year' => $year, 'month' => $month])
+            ->select('bouquet_id')
+            ->distinct()
+            ->column();
+
+        $totalAssemblies = BouquetCompositionProducts::find()
+            ->count();
+
         $assembliesWithProduct = BouquetCompositionProducts::find()
-            ->where(['product_guid' => $this->product_guid])
+            ->andWhere(['product_guid' => $this->product_guid])
+            ->andWhere(['bouquet_id' => $periodBouquets])
             ->count();
 
         return $totalAssemblies ? round(($assembliesWithProduct / $totalAssemblies) * 100, 2) : 0;
     }
 
-    public function getAverageNumberOfPieces(): float
+    public function getAverageNumberOfPieces(int $year = null, int $month = null): float
     {
+        $year = $year ?? date('Y');
+        $month = $month ?? date('m');
+        $periodBouquets = BouquetForecast::find()
+            ->andWhere(['year' => $year, 'month' => $month])
+            ->select('bouquet_id')
+            ->distinct()
+            ->column();
+
         $totalCount = BouquetCompositionProducts::find()
             ->where(['product_guid' => $this->product_guid])
             ->sum('count');
 
         $assembliesWithProduct = BouquetCompositionProducts::find()
-            ->where(['product_guid' => $this->product_guid])
+            ->andWhere(['product_guid' => $this->product_guid])
+            ->andWhere(['bouquet_id' => $periodBouquets])
             ->count();
 
         return $assembliesWithProduct ? round($totalCount / $assembliesWithProduct, 2) : 0;
index d044e165be523401a6c414b2b6d4f42bea3e18b8..5a7bcb864d71800439027d295e1f16c969707210 100644 (file)
@@ -7,7 +7,7 @@
     <div class="col-md-2 text-center font-weight-bold">ср.шт. в сборке</div>
 </div>
 
-<div class="bg-white border rounded shadow-sm" style="height: 400px; overflow-y: auto; overflow-x: hidden;">
+<div class="products-list bg-white border rounded shadow-sm" style="height: 400px; overflow-y: auto; overflow-x: hidden;">
     <?php
     use yii\helpers\Html;
     use yii\helpers\Url;
     use yii_app\records\WriteOffsErp;
 
     foreach ($bouquetCompositionProducts as $product) { ?>
-        <div class="d-flex border-bottom ms-1 py-2" style="gap: 0;">
+        <div class="d-flex border-bottom ms-1 py-2" style="gap: 0;" data-product-guid="<?= Html::encode($product->product_guid) ?>">
             <div class="text-center" style="width: 33.33%;"><?= Html::encode($product->product->name) ?></div>
             <div class="text-center" style="width: 16.66%;"><?= Html::encode($product->count) ?></div>
             <div class="text-center" style="width:  8.33%;"><?= Html::encode($product->getWriteOffPercentage()) ?></div>
             <div class="text-center" style="width: 16.66%;"><?= Html::encode($product->getProfitability())?> </div>
-            <div class="text-center" style="width: 16.66%;"><?= Html::encode($product->getBuildPercentage()) ?>%</div>
-            <div class="text-center" style="width: 8.33%;"><?= Html::encode($product->getAverageNumberOfPieces()) ?></div>
+            <div class="text-center build-percentage" style="width: 16.66%;"><?= Html::encode($product->getBuildPercentage()) ?>%</div>
+            <div class="text-center average-pieces" style="width: 8.33%;"><?= Html::encode($product->getAverageNumberOfPieces()) ?></div>
         </div>
     <?php } ?>
 </div>
index 4d74d0ac6d16584e4dad978505a0052105cec48d..b1dec1d3617244f63e318ff9bb82833ea9d53b55 100644 (file)
@@ -51,6 +51,29 @@ $(document).ready(function () {
                     console.error("Ошибка загрузки данных:", status, error);
                 }
             });
+
+            $.ajax({
+                url: '/bouquet/get-product-list-data',
+                type: 'GET',
+                data: { year: year, month: month, id: id },
+                dataType: 'json',
+                success: function (response) {
+                    if (response) {
+                        console.log(response);
+
+                        response.forEach(item => {
+                            let row = $(`.d-flex[data-product-guid="${item.product_guid}"]`);
+                            if (row.length) {
+                                row.find('.build-percentage').text(item.buildPercentage + '%');
+                                row.find('.average-pieces').text(item.averageNumberOfPieces);
+                            }
+                        });
+                    }
+                },
+                error: function (xhr, status, error) {
+                    console.error("Ошибка загрузки данных:", status, error);
+                }
+            });
         });
     }
 });