]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Выводл списаний за месяц
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 5 May 2025 08:51:08 +0000 (11:51 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 5 May 2025 08:51:08 +0000 (11:51 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/views/auto-plannogramma/control-species.php

index 3dc54ee8e23f51796008f452a78f12d8718badc6..4b95f02a918bcff6718a6443ff632319314f2aea 100644 (file)
@@ -212,92 +212,72 @@ class AutoPlannogrammaController extends BaseController
 
     public function actionControlSpecies()
     {
-
         $model = new DynamicModel([
-            'storeId','monthFrom','monthTo','type',
-            'category','subcategory','species'
+            'storeId', 'month', 'type',
+
         ]);
-        $model->addRule(['monthFrom','monthTo','type'], 'required')
-            ->addRule('storeId', 'integer')
-            ->addRule(['category','subcategory','species'], 'string');
+        $model->addRule(['month', 'type'], 'required')
+            ->addRule('storeId', 'integer');
 
         $storeList = CityStore::find()
             ->select(['name','id'])
+            ->where(['visible' => CityStore::IS_VISIBLE])
             ->indexBy('id')
             ->column();
 
         $monthsList = [];
         for ($i = 0; $i < 12; $i++) {
-            $m = (new \DateTime("first day of -{$i} month"))->format('Y-m');
-            $monthsList[$m] = (new \DateTime("first day of -{$i} month"))
-                ->format('F Y');
-        }
-
-
-        $categoryList = Products1cNomenclature::find()
-            ->select('category')
-            ->distinct()
-            ->indexBy('category')
-            ->column();
-
-        $subcategoryList = [];
-        if ($model->category) {
-            $subcategoryList = Products1cNomenclature::find()
-                ->where(['category' => $model->category])
-                ->select('subcategory')
-                ->distinct()
-                ->indexBy('subcategory')
-                ->column();
-        }
-
-        $speciesList = [];
-        if ($model->category && $model->subcategory) {
-            $speciesList = Products1cNomenclature::find()
-                ->where([
-                    'category'    => $model->category,
-                    'subcategory' => $model->subcategory
-                ])
-                ->select('species')
-                ->distinct()
-                ->indexBy('species')
-                ->column();
+            // получаем метку вида "03-2025"
+            $ts = strtotime("first day of -{$i} month");
+            $key = date('m-Y', $ts);
+            $monthsList[$key] = $key;
         }
 
         $result = [];
+        $totals = [];
 
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
-            // формируем фильтры
             $filters = [];
-            if ($model->storeId)    $filters['store_id']   = $model->storeId;
-            if ($model->category)   $filters['category']   = $model->category;
-            if ($model->subcategory)$filters['subcategory']= $model->subcategory;
-            if ($model->species)    $filters['species']    = $model->species;
-            //var_dump($model->type); die();
-            $dateFrom = $model->monthFrom . '-01';
+            if ($model->storeId) {
+                $filters['store_id'] = $model->storeId;
+            }
+
+
+            list($m, $y) = explode('-', $model->month);
+            $dateFrom = sprintf('%04d-%02d-01', $y, $m);
             $dateTo   = date('Y-m-t', strtotime($dateFrom));
-            $service =  new AutoPlannogrammaService();
-            $totals =  $service->getStoreTotals([1,2,4], '2025-03-01', null, 'writeOffs');
-           // var_dump($totals);die();
-            $result = $service
-                ->getMonthSpeciesShareOrWriteOffDate(
-                    '2025-03-01',
-                    '2025-03-31',
+
+            $service = new AutoPlannogrammaService();
+
+            if ($model->storeId) {
+                $totals = $service->getStoreTotals(
+                    [$model->storeId],
+                    $dateFrom,
                     null,
-                    null,               // productFilter
-                    'writeOffs'
+                    $model->type,
+                    $dateTo
                 );
+            }
+
+            $result = $service->getMonthSpeciesShareOrWriteOffDate(
+                $dateFrom,
+                $dateTo,
+                $filters,
+                null,
+                $model->type
+            );
         }
 
         return $this->render('control-species', [
             'model'           => $model,
             'result'          => $result,
+            'totals'          => $totals,
             'storeList'       => $storeList,
             'monthsList'      => $monthsList,
-            'categoryList'    => $categoryList,
-            'subcategoryList' => $subcategoryList,
-            'speciesList'     => $speciesList,
+
         ]);
     }
+
     /**
      * Возвращает список подкатегорий для выбранной категории.
      * @param string $category
index 4f89144ad2aae67502ad950e3cc2e5cb38dca6e8..79c5de6b7cff7f14e1ec87e9cff5ae2343bab733 100644 (file)
@@ -417,7 +417,7 @@ class AutoPlannogrammaService
             $storeIds = array_intersect($storeIds, [(int)$filters['store_id']]);
         }
 
-        $totals = $this->getStoreTotals($storeIds, '2025-03-01', null, 'writeOffs', '2025-03-31');
+        $totals = $this->getStoreTotals($storeIds, $dateFrom, null, $type, $dateTo);
         if (empty($totals)) {
             return [];
         }
@@ -488,7 +488,7 @@ class AutoPlannogrammaService
                 'subcategory'     => $row['subcategory'],
                 'species'         => $row['species'],
                 'total_sum'       => (float)$row['total_sum'],
-                'percent_of_month'=> round((float)$row['total_sum'] / $total, 4),
+                'percent_of_month'=> round(((float)$row['total_sum'] / $total) , 4),
             ];
         }
 
index f331340bf1feec490cabfa3eb064715734b158a5..7df8a61a46562fedb69be1735f9d6f74e529204c 100644 (file)
@@ -8,34 +8,26 @@ use yii_app\records\PricesDynamic;
 use yii_app\records\Products1c;
 
 /* @var $this yii\web\View */
-/* @var $result array|null */
 /* @var $model DynamicModel */
 /* @var $storeList array */
 /* @var $monthsList array */
-/* @var $categoryList array */
-/* @var $subcategoryList array */
-/* @var $speciesList array */
+/* @var $result array */
+/* @var $totals array */
 
 ?>
 
-<div class="show-history-data p-4">
-    <h1>Ð\9fÑ\80овеÑ\80ка Ð´Ð°Ð½Ð½Ñ\8bÑ\85 по видам</h1>
+<div class="control-species p-4">
+    <h1>Ð\9fÑ\80овеÑ\80ка Ð¿Ñ\80одаж/Ñ\81пиÑ\81аний по видам</h1>
 
-    <?php $form = ActiveForm::begin([
-    'method' => 'post',
-    ]); ?>
+    <?php $form = ActiveForm::begin(['method' => 'post']); ?>
 
     <?= $form->field($model, 'storeId')
     ->dropDownList($storeList, ['prompt' => 'Выберите магазин'])
     ->label('Магазин') ?>
 
-    <?= $form->field($model, 'monthFrom')
-    ->dropDownList($monthsList, ['prompt' => 'Начало периода'])
-    ->label('Дата с') ?>
-
-    <?= $form->field($model, 'monthTo')
-    ->dropDownList($monthsList, ['prompt' => 'Конец периода'])
-    ->label('Дата по') ?>
+    <?= $form->field($model, 'month')
+    ->dropDownList($monthsList, ['prompt' => 'Выберите месяц'])
+    ->label('Месяц') ?>
 
     <?= $form->field($model, 'type')
     ->radioList([
@@ -44,17 +36,6 @@ use yii_app\records\Products1c;
     ])
     ->label('Тип данных') ?>
 
-    <?= $form->field($model, 'category')
-    ->dropDownList($categoryList, ['prompt' => 'Выберите категорию'])
-    ->label('Категория') ?>
-
-    <?= $form->field($model, 'subcategory')
-    ->dropDownList($subcategoryList, ['prompt' => 'Выберите подкатегорию'])
-    ->label('Подкатегория') ?>
-
-    <?= $form->field($model, 'species')
-    ->dropDownList($speciesList, ['prompt' => 'Выберите вид товара'])
-    ->label('Вид товара') ?>
 
     <div class="form-group">
         <?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
@@ -62,12 +43,31 @@ use yii_app\records\Products1c;
 
     <?php ActiveForm::end(); ?>
 
+    <?php if (!empty($totals)): ?>
+    <h2>Итоги по магазину</h2>
+    <table class="table table-bordered">
+        <thead>
+        <tr>
+            <th>Магазин</th>
+            <th>Итого сумма</th>
+        </tr>
+        </thead>
+        <tbody>
+        <?php foreach ($totals as $storeId => $sum): ?>
+        <tr>
+            <td><?= Html::encode($storeList[$storeId] ?? $storeId) ?></td>
+            <td><?= Yii::$app->formatter->asDecimal($sum, 2) ?></td>
+        </tr>
+        <?php endforeach; ?>
+        </tbody>
+    </table>
+    <?php endif; ?>
+
     <?php if (!empty($result)): ?>
-    <h2>РезÑ\83лÑ\8cÑ\82аÑ\82Ñ\8b</h2>
+    <h2>Ð\94еÑ\82ализаÑ\86иÑ\8f Ð¿Ð¾ Ð²Ð¸Ð´Ð°Ð¼</h2>
     <table class="table table-striped table-bordered">
         <thead>
         <tr>
-            <th>Магазин</th>
             <th>Категория</th>
             <th>Подкатегория</th>
             <th>Вид товара</th>
@@ -78,7 +78,6 @@ use yii_app\records\Products1c;
         <tbody>
         <?php foreach ($result as $row): ?>
         <tr>
-            <td><?= Html::encode($storeList[$row['store_id']] ?? $row['store_id']) ?></td>
             <td><?= Html::encode($row['category']) ?></td>
             <td><?= Html::encode($row['subcategory']) ?></td>
             <td><?= Html::encode($row['species']) ?></td>
@@ -90,9 +89,5 @@ use yii_app\records\Products1c;
     </table>
     <?php endif; ?>
 
-    <?php
-    $this->registerJsFile('/js/category-plan/show-history-data.js', [
-    'position' => \yii\web\View::POS_END
-    ]);
-    ?>
+
 </div>