]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Вычисление доли недели для вида товара по списаниям
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 5 May 2025 13:15:31 +0000 (16:15 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 5 May 2025 13:15:31 +0000 (16:15 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/views/auto-plannogramma/control-species.php

index 4b95f02a918bcff6718a6443ff632319314f2aea..bf1d674abb437c3a62e10d941eca3040f4f29f32 100644 (file)
@@ -233,8 +233,10 @@ class AutoPlannogrammaController extends BaseController
             $monthsList[$key] = $key;
         }
 
-        $result = [];
+        $monthResult = [];
         $totals = [];
+        $weeksData = [];
+        $weeksShareResult = [];
 
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $filters = [];
@@ -244,8 +246,8 @@ class AutoPlannogrammaController extends BaseController
 
 
             list($m, $y) = explode('-', $model->month);
-            $dateFrom = sprintf('%04d-%02d-01', $y, $m);
-            $dateTo   = date('Y-m-t', strtotime($dateFrom));
+            $dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $y, $m)));
+            $dateTo   = date("Y-m-t 23:59:59", strtotime($dateFrom));
 
             $service = new AutoPlannogrammaService();
 
@@ -259,18 +261,68 @@ class AutoPlannogrammaController extends BaseController
                 );
             }
 
-            $result = $service->getMonthSpeciesShareOrWriteOffDate(
+            $monthResult = $service->getMonthSpeciesShareOrWriteOffDate(
                 $dateFrom,
                 $dateTo,
                 $filters,
                 null,
                 $model->type
             );
+            $speciesMonthTotals = [];
+            foreach ($monthResult as $monthRow) {
+                $speciesMonthTotals[$monthRow['store_id']]
+                [$monthRow['category']]
+                [$monthRow['subcategory']]
+                [$monthRow['species']] = $monthRow['total_sum'] ;
+            }
+
+
+            foreach (range(1, 5) as $ind) {
+                $weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($dateFrom)));
+                $weekEnd = date("Y-m-d 23:59:59", strtotime("+" . ($ind * 7 - 1) . ' days', strtotime($dateFrom)));
+                if ($weekEnd > $dateTo) {
+                    $weekEnd = $dateTo;
+                }
+                if ($weekStart > $dateTo) {
+                    continue;
+                }
+                 $weekResult = $service->getMonthSpeciesShareOrWriteOffDate(
+                    $weekStart,
+                    $weekEnd,
+                    $filters,
+                    null,
+                    $model->type
+                );
+                $weeksData[$ind] = $weekResult;
+                if (!$weekResult) {
+                    continue;
+                }
+                $weeksShareResult[$ind] = [];
+                foreach ($weekResult as $weekRow) {
+                    $monthSum = $speciesMonthTotals
+                    [$weekRow['store_id']]
+                    [$weekRow['category']]
+                    [$weekRow['subcategory']]
+                    [$weekRow['species']] ?? null;
+
+                    if ($monthSum) {
+                        $weeksShareResult[$ind]
+                        [$weekRow['category']]
+                        [$weekRow['subcategory']]
+                        [$weekRow['species']] = $weekRow['total_sum'] / $monthSum;
+                    }
+
+                }
+
+            }
+
         }
 
         return $this->render('control-species', [
             'model'           => $model,
-            'result'          => $result,
+            'result'          => $monthResult,
+            'weeksData'       => $weeksData,
+            'weeksShareResult' => $weeksShareResult,
             'totals'          => $totals,
             'storeList'       => $storeList,
             'monthsList'      => $monthsList,
index 7df8a61a46562fedb69be1735f9d6f74e529204c..f3c2b4ddef2cb798641bc0c8222e2e8183258f51 100644 (file)
@@ -13,6 +13,8 @@ use yii_app\records\Products1c;
 /* @var $monthsList array */
 /* @var $result array */
 /* @var $totals array */
+/* @var $weeksData array */
+/* @var $weeksShareResult array */
 
 ?>
 
@@ -88,6 +90,43 @@ use yii_app\records\Products1c;
         </tbody>
     </table>
     <?php endif; ?>
-
-
+    <?php if (!empty($weeksData)): ?>
+        <h2>Результаты по неделям</h2>
+        <?php foreach ($weeksData as $weekNum => $weekRows): ?>
+            <h3>Неделя <?= $weekNum ?></h3>
+            <?php if (empty($weekRows)): ?>
+                <p>Нет данных за эту неделю.</p>
+            <?php else: ?>
+                <table class="table table-striped table-bordered">
+                    <thead>
+                    <tr>
+                        <th>Категория</th>
+                        <th>Подкатегория</th>
+                        <th>Вид товара</th>
+                        <th>Сумма</th>
+                        <th>Доля недели</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php foreach ($weekRows as $row): ?>
+                        <tr>
+                            <td><?= Html::encode($row['category']) ?></td>
+                            <td><?= Html::encode($row['subcategory']) ?></td>
+                            <td><?= Html::encode($row['species']) ?></td>
+                            <td><?= Yii::$app->formatter->asDecimal($row['total_sum'], 2) ?></td>
+                            <td>
+                                <?= isset($weeksShareResult[$weekNum])
+                                    ? Yii::$app->formatter->asPercent(
+                                            $weeksShareResult[$weekNum][$row['category']][$row['subcategory']][$row['species']],
+                                            2
+                                    )
+                                    : '-' ?>
+                            </td>
+                        </tr>
+                    <?php endforeach; ?>
+                    </tbody>
+                </table>
+            <?php endif; ?>
+        <?php endforeach; ?>
+    <?php endif; ?>
 </div>