]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавил таблицы по суммам и возвратам
authorvladfo <fvv2011@gmail.com>
Mon, 14 Oct 2024 10:01:52 +0000 (13:01 +0300)
committervladfo <fvv2011@gmail.com>
Mon, 14 Oct 2024 10:01:52 +0000 (13:01 +0300)
erp24/actions/motivation/TestSelfCostAction.php
erp24/services/MotivationService.php
erp24/views/motivation/test-self-cost.php

index 09cd8c1d5d5b70b5d3eb5af98ecea18ba0119119..e610eb6a1124ba3b1ddfcbd0b014674372c45af4 100644 (file)
@@ -44,6 +44,11 @@ class TestSelfCostAction extends Action
         $uniqueProductsData = [];
 
         if ($startDate && $endDate && $storeId) {
+
+            // Получаем продажи и возвраты
+            $salesAndReturns = MotivationService::getSalesAndReturns($startDate, $endDate, $storeId);
+            $salesRecords = $salesAndReturns['salesRecords'];
+            $returnedSales = $salesAndReturns['returnedSales'];
             $totalSum = MotivationService::getSelfCostSumByStore($startDate, $endDate, $storeId);
 
             // Получаем данные о продуктах и себестоимости
@@ -66,6 +71,9 @@ class TestSelfCostAction extends Action
                         'price' => $item['price'],
                         'm_price' => $item['m_price'],
                         'quantity' => $item['quantity'],
+                        'summ' => $item['summ'],
+                        'discount' => $item['discount'],
+
                     ];
                 } else {
                     $groupedProducts[$productId]['quantity'] += $item['quantity'];
@@ -91,6 +99,8 @@ class TestSelfCostAction extends Action
             'uniqueProductsData' => $uniqueProductsData,
             'totalSum' => $totalSum,
             'totalProductsSum' => $totalProductsSum,
+            'salesRecords' => $salesRecords ?? [],
+            'returnedSales' => $returnedSales ?? [],
         ]);
     }
 }
\ No newline at end of file
index f6d48702e722aa592a8581d88a3b1341a7deaccc..6680b398ad8a5abf24fe8df459dd18e479229ae6 100644 (file)
@@ -1870,6 +1870,7 @@ class MotivationService
         $salesProducts = SalesProducts::find()
             ->select(['check_id', 'product_id', 'quantity'])
             ->where(['check_id' => $salesIds])
+            ->andWhere(['type_id' => 1])
             ->asArray()
             ->all();
 
@@ -1960,7 +1961,7 @@ class MotivationService
 
         // Находим товары, проданные в выбранных продажах
         $salesProducts = SalesProducts::find()
-            ->select(['check_id', 'product_id', 'quantity', 'price'])
+            ->select(['check_id', 'product_id', 'quantity', 'price', 'summ', 'discount'])
             ->where(['check_id' => $salesIds])
             ->andWhere(['type_id' => 1])
             //    ->andWhere(['>', 'price',  '0'  ])
@@ -2007,6 +2008,8 @@ class MotivationService
                 'quantity' => $quantity,
                 'check_id' => $product['check_id'],
                 'm_price' => $product['price'],
+                'summ' => $product['summ'],
+                'discount' => $product['discount'],
             ];
         }
 
@@ -2014,6 +2017,39 @@ class MotivationService
     }
 
 
+    public static function getSalesAndReturns($startDate, $endDate, $storeId)
+    {
+        $storeId = (int)$storeId;
+        $startDate = date('Y-m-d', strtotime($startDate));
+        $endDate = date('Y-m-d 23:59:59', strtotime($endDate));
+
+        // Находим все продажи за указанный период
+        $salesRecords = Sales::find()
+           // ->select(['id', 'date'])
+            ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_SALE])
+            ->andWhere(['>=', 'date', $startDate])
+            ->andWhere(['<=', 'date', $endDate])
+            ->asArray()
+            ->all();
+
+        $endDatePlusThreeWeeks = date('Y-m-d 23:59:59', strtotime($endDate . ' +3 weeks'));
+
+        // Находим возвраты за указанный период + 3 недели
+        $returnedSales = Sales::find()
+          //  ->select(['id', 'date', 'sales_check'])
+            ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_RETURN])
+            ->andWhere(['>=', 'date', $startDate])
+            ->andWhere(['<=', 'date', $endDatePlusThreeWeeks])
+            ->andWhere(['is not', 'sales_check', null])
+            ->asArray()
+            ->all();
+
+        return [
+            'salesRecords' => $salesRecords,
+            'returnedSales' => $returnedSales,
+        ];
+    }
+
     public static function getCostConsumablesSalesSupportByStore($startDate, $endDate, $storeId) {
         $exportImportTable = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $storeId, 'export_id' => 1])->one();
 
index bc17c5daa0ecda36b94f7e270e61fe8debfa226d..200dc18690ccb2a7100799f37403d7068f0a11e7 100644 (file)
@@ -11,6 +11,8 @@ use yii\grid\GridView;
 /* @var $uniqueProductsData array */
 /* @var $totalSum float */
 /* @var $totalProductsSum float */
+/* @var $salesRecords array */
+/* @var $returnedSales array */
 
 $this->title = 'Себестоимость товаров по магазинам';
 ?>
@@ -53,6 +55,8 @@ $this->title = 'Себестоимость товаров по магазина
                 ['attribute' => 'check_id', 'label' => 'ID чека'],
                 ['attribute' => 'product_name', 'label' => 'Название'],
                 ['attribute' => 'm_price', 'label' => 'Цена'],
+                ['attribute' => 'summ', 'label' => 'Сумма', 'footer' => array_sum(array_column($data, 'summ')),],
+                ['attribute' => 'discount', 'label' => 'Скидка', 'footer' => array_sum(array_column($data, 'discount')),],
                 ['attribute' => 'price', 'label' => 'Себестоимость ед'],
                 [
                     'attribute' => 'quantity',
@@ -113,4 +117,44 @@ $this->title = 'Себестоимость товаров по магазина
             ],
         ]); ?>
     <?php endif; ?>
+
+    <?php if (!empty($salesRecords)): ?>
+        <h2>Продажи за период</h2>
+        <?= GridView::widget([
+            'dataProvider' => new \yii\data\ArrayDataProvider([
+                'allModels' => $salesRecords,
+                'pagination' => false,
+            ]),
+            'showFooter' => true, // Показываем подвал таблицы
+            'columns' => [
+                ['attribute' => 'id', 'label' => 'ID продажи'],
+                ['attribute' => 'operation', 'label' => 'Операция'],
+                ['attribute' => 'status', 'label' => 'Статус'],
+                [
+                    'attribute' => 'summ',
+                    'label' => 'Сумма',
+                    'footer' => array_sum(array_column($salesRecords, 'summ')), // Сумма всех значений столбца "Сумма"
+                ],
+                ['attribute' => 'sales_check', 'label' => 'Чек возврата'],
+                ['attribute' => 'date', 'label' => 'Дата'],
+            ],
+        ]); ?>
+    <?php endif; ?>
+
+    <?php if (!empty($returnedSales)): ?>
+        <h2>Возвраты за период</h2>
+        <?= GridView::widget([
+            'dataProvider' => new \yii\data\ArrayDataProvider([
+                'allModels' => $returnedSales,
+                'pagination' => false,
+            ]),
+            'columns' => [
+                ['attribute' => 'id', 'label' => 'ID возврата'],
+                ['attribute' => 'date', 'label' => 'Дата'],
+                ['attribute' => 'sales_check', 'label' => 'ID продажи'],
+            ],
+        ]); ?>
+    <?php endif; ?>
+
+
 </div>
\ No newline at end of file