From: fomichev Date: Thu, 23 Jan 2025 07:27:29 +0000 (+0300) Subject: По дате X-Git-Tag: 1.7~40^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=00d4e8e91cacf930dd52c403430b158d901fcf75;p=erp24_rep%2Fyii-erp24%2F.git По дате --- diff --git a/erp24/api3/core/services/ReportService.php b/erp24/api3/core/services/ReportService.php index 14d97e0a..0d83a866 100644 --- a/erp24/api3/core/services/ReportService.php +++ b/erp24/api3/core/services/ReportService.php @@ -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') diff --git a/erp24/api3/modules/v1/controllers/ReportController.php b/erp24/api3/modules/v1/controllers/ReportController.php index 000b48ce..dc5f38c2 100644 --- a/erp24/api3/modules/v1/controllers/ReportController.php +++ b/erp24/api3/modules/v1/controllers/ReportController.php @@ -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(); diff --git a/erp24/api3/modules/v1/requests/report/ReportDaysInput.php b/erp24/api3/modules/v1/requests/report/ReportDaysInput.php index 7d3bc666..4e61fb87 100644 --- a/erp24/api3/modules/v1/requests/report/ReportDaysInput.php +++ b/erp24/api3/modules/v1/requests/report/ReportDaysInput.php @@ -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]] diff --git a/erp24/controllers/ReportController.php b/erp24/controllers/ReportController.php index 7df4852c..11fc2189 100644 --- a/erp24/controllers/ReportController.php +++ b/erp24/controllers/ReportController.php @@ -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