]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
По дате
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 23 Jan 2025 07:27:29 +0000 (10:27 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 23 Jan 2025 07:27:29 +0000 (10:27 +0300)
erp24/api3/core/services/ReportService.php
erp24/api3/modules/v1/controllers/ReportController.php
erp24/api3/modules/v1/requests/report/ReportDaysInput.php
erp24/controllers/ReportController.php

index 14d97e0a4010f1a672bc4676daba0fdaa2f06385..0d83a8661c4a1ef50c3ba0b2f93c6ff2ccc4b644 100644 (file)
@@ -806,25 +806,23 @@ class ReportService
      * @throws \yii\base\Exception
      * @throws Exception
      */
-    public function showDays($data) {
+    public function showDays($data)
+    {
         set_time_limit(600);
+
         $days = [];
-        if (!empty($data->month)) {
-            $startDate = date("Y-m-01", strtotime($data->month));
-            $endDate = date("Y-m-t", strtotime($data->month));
+
+        if (!empty($data->date)) {
+            $startDate = date("Y-m-01", strtotime($data->date));
+            $endDate = date("Y-m-d", strtotime($data->date));
 
             $currentDate = $startDate;
             while ($currentDate <= $endDate) {
                 $days[] = $currentDate;
                 $currentDate = date("Y-m-d", strtotime($currentDate . " +1 day"));
             }
-        } else {
-            if (!empty($data->date)) {
-                foreach ($data->date as $day) {
-                    $days[] = date("Y-m-d", strtotime($day));
-                }
-            }
         }
+
         $reports = [];
 
         $cityStoreNames = ArrayHelper::map(CityStore::find()->where(['visible' => '1'])->all(), 'id', 'name');
@@ -886,8 +884,8 @@ class ReportService
             $adminPayrollDaysMonth = AdminPayrollDays::find()->select(["FLOOR(SUM(day_payroll)) as total", 'store_id'])
                 ->where([
                     'between', 'date',
-                    date("Y-m-01 00:00:00", strtotime($day)),
-                    date("Y-m-d 23:59:59", strtotime($day))])
+                    date("Y-m-01", strtotime($day)),
+                    date("Y-m-d", strtotime($day))])
                 ->andWhere(['store_id' => $data->stores])
                 ->groupBy(['store_id'])
                 ->indexBy('store_id')
index 000b48cebbd57211d9e886cae29d9a4e440e8af9..dc5f38c2112b265e9e0ecf5bb2bf521932cdbe7b 100644 (file)
@@ -89,10 +89,9 @@ class ReportController extends \yii_app\api3\controllers\NoActiveController
         // localhost:8888/v1/report/show-days
         // {
         //   "stores": [1,2,3],
-        //   "date" : [
-        //       "2024-02-08", "2024-02-14"
-        //   ],
-        //   "month" : "2024-12",
+        //   "date" :  "2024-12-08",
+        //
+        //
         //   "shift_type": 1 // 1 - дневная, 2 - ночная, 0 - дневная и ночная смена вместе
         // }
         $params = \Yii::$app->request->post();
index 7d3bc666c0ed30aa79a3b46c31013487aeb28828..4e61fb871299e4baf8ca297cde4e1d3b74de1d3a 100644 (file)
@@ -7,15 +7,14 @@ use yii\base\Model;
 class ReportDaysInput extends Model
 {
     public $stores;
-    public $month;
+
     public $date;
     public $shift_type;
 
     public function rules(): array
     {
         return [
-            [['stores',   'shift_type'], 'required'],
-            [['month', 'date'], 'safe'],
+            [['stores', 'date',  'shift_type'], 'required'],
             ['stores', 'each', 'rule' => ['integer']],
             //[['date_start', 'date_end'], 'datetime', 'format' => 'yyyy-M-d'],
             ['shift_type', 'in', 'range' => [0, 1, 2]]
index 7df4852ccc50a61901b20024232f81be4ac17cb5..11fc21891d40079eab98788421900dafa34d6466 100644 (file)
@@ -2,7 +2,9 @@
 
 namespace app\controllers;
 
+use Yii;
 use yii\web\Controller;
+use yii_app\records\CityStore;
 
 class ReportController extends Controller {
 
@@ -363,4 +365,102 @@ class ReportController extends Controller {
         }
         return $names;
     }
+
+    public function actionDailyReport()
+    {
+
+        if (Yii::$app->request->isGet) {
+            $stores = CityStore::find()
+                ->select(['id', 'name'])
+                ->where(['visible' => 1])
+                ->asArray()
+                ->all();
+
+            return $this->render('daily-report', [
+                'stores' => $stores,
+            ]);
+        }
+
+
+        if (Yii::$app->request->isPost) {
+            $requestData = Yii::$app->request->post();
+
+            $storeId = $requestData['store_id'] ?? null;
+            $month = $requestData['month'] ?? null;
+
+            if (!$storeId || !$month) {
+                return $this->asJson(['success' => false, 'message' => 'Invalid parameters']);
+            }
+
+
+            $filePath = Yii::getAlias('@runtime/result.json');
+           // var_dump($filePath);die();
+            if (!file_exists($filePath)) {
+                return $this->asJson(['success' => false, 'message' => 'Result file not found']);
+            }
+
+            // Чтение данных из файла
+            $fileContents = file_get_contents($filePath);
+            $data = json_decode($fileContents, true);
+
+            if ($data === null) {
+                return $this->asJson(['success' => false, 'message' => 'Failed to parse JSON']);
+            }
+
+            // Фильтрация данных для указанного ID магазина
+            $filteredData = array_filter($data['response'], function ($item) use ($storeId) {
+                return array_search($storeId, array_column($item['stores'], 'id')) !== false;
+            });
+
+            if (empty($filteredData)) {
+                return $this->asJson(['success' => false, 'message' => 'No data found for the selected store']);
+            }
+            $filteredData = array_slice($filteredData, 0, 10);
+            // Преобразуем данные для таблицы
+            $dates = array_column($filteredData, 'date');
+            $indicators = [
+                'Сумма продаж с начала месяца' => 'sale_month_total',
+                'Сумма продаж' => 'sale_total',
+                'Чеков' => 'sale_quantity',
+                'Средний чек' => 'sale_avg',
+                'Сумма списания' => 'total_write_offs_per_date',
+                '% списания' => 'total_write_offs_per_date_percent',
+                'Списания с начала месяца' => 'total_write_offs_per_month',
+                '% списания с начала месяца' => 'total_write_offs_per_month_percent',
+                'ФОТ за день' => 'total_payroll_days',
+                '% ФОТ за день' => 'total_payroll_days_percent',
+                'ФОТ с начала месяца' => 'total_payroll_month',
+                '% ФОТ с начала месяца' => 'total_payroll_month_percent',
+                'Средняя сумма сотрудника' => 'employee_sale_avg',
+                'Посетителей' => 'visitors_quantity',
+                'Конверсия' => 'conversion',
+                'Всего бонусных клиентов' => 'bonus_user_count',
+                '% БК от числа чеков' => 'bonus_user_per_sale_percent',
+                'Новые клиенты БК' => 'bonus_new_user_count',
+                'Старые клиенты БК' => 'bonus_repeat_user_count',
+                'Кол-во возвратов' => 'sale_return_quantity',
+                'Сумма возвратов' => 'sale_return_total',
+                'Сумма букетов матрицы' => 'total_matrix_per_day',
+                '% матрицы' => 'total_matrix_per_day_percent',
+                'Сумма продаж упаковки' => 'total_wrap_per_day',
+                'Сумма продаж услуги' => 'total_services_per_day',
+                'Сумма продаж горшечки' => 'total_potted_per_day',
+            ];
+
+            $tableData = [];
+            foreach ($indicators as $label => $key) {
+                $row = ['label' => $label];
+                foreach ($filteredData as $dayData) {
+                    $store = current(array_filter($dayData['stores'], fn($s) => $s['id'] == $storeId));
+                    $row[$dayData['date']] = $store['data'][$key] ?? 0;
+                }
+                $tableData[] = $row;
+            }
+
+            return $this->asJson(['success' => true, 'data' => $tableData, 'dates' => $dates]);
+        }
+
+        throw new \yii\web\BadRequestHttpException('Invalid request method');
+    }
+
 }
\ No newline at end of file