* @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');
$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')
namespace app\controllers;
+use Yii;
use yii\web\Controller;
+use yii_app\records\CityStore;
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