];
}
- // Подсчет должностей на смене для этого дня
+ // Подсчет должностей на смене для этого дня (используется для информации по дню)
$employeePositionsOnShift = $this->countEmployeesByPosition($timetables, $positionMap);
-
- // Суммируем для общего отчета
- foreach ($employeePositionsOnShift as $positionName => $count) {
- if (!isset($totalEmployeePositionsOnShift[$positionName])) {
- $totalEmployeePositionsOnShift[$positionName] = 0;
- }
- $totalEmployeePositionsOnShift[$positionName] += $count;
- }
$adminPayrollDaysMonth = AdminPayrollDays::find()->select(["FLOOR(SUM(day_payroll)) as total", "store_id"])
->where(['>=', 'date', date("Y-m-01", strtotime($currentDate))])
$totalEmployeeSkillsScore = round(array_sum($totalEmployeeSkillsScores) / count($totalEmployeeSkillsScores), 1);
}
+ // Агрегируем сотрудников по магазинам без дедупликации
+ $totalEmployeePositionsOnShift = [];
+ $totalEmployeeCountOnShift = 0;
+ foreach ($report["stores"] as $storeData) {
+ $totalEmployeeCountOnShift += $storeData["employee_count_on_shift"];
+ foreach ($storeData["employee_positions_on_shift"] as $positionName => $count) {
+ $totalEmployeePositionsOnShift[$positionName] = ($totalEmployeePositionsOnShift[$positionName] ?? 0) + $count;
+ }
+ }
+
$report['total'] = [
"sale_total" => $storeSaleTotalTotal,
"sale_quantity" => $storeSaleQuantityTotal,
"total_wrap_per_day" => $totalWrapPerDayTotal,
"total_services_per_day" => $totalServicePerDayTotal,
"total_potted_per_day" => $totalPottedPerDayTotal,
- "employee_positions_on_shift" => $employeePositionsOnShift,
+ "employee_positions_on_shift" => $totalEmployeePositionsOnShift,
"employee_skills_score" => $totalEmployeeSkillsScore,
- "employee_count_on_shift" => count($timetables),
+ "employee_count_on_shift" => $totalEmployeeCountOnShift,
];
// Создаем итоговый массив для дня с правильным порядком полей
$total["total_services_per_day"] = ($total["total_services_per_day"] ?? 0) + ($totalServicePerDayTotal[$store_id] ?? 0);
$total["total_potted_per_day"] = ($total["total_potted_per_day"] ?? 0) + ($totalPottedPerDayTotal[$store_id] ?? 0);
}
+
+ // Суммы по всем магазинам без дедупликации сотрудников
+ $totalEmployeePositionsOnShift = [];
+ foreach ($stores as $storeData) {
+ foreach ($storeData['data']['employee_positions_on_shift'] as $position => $count) {
+ $totalEmployeePositionsOnShift[$position] = ($totalEmployeePositionsOnShift[$position] ?? 0) + $count;
+ }
+ }
+ $totalEmployeeCountOnShift = array_sum($employeeCount);
+
$total["sale_avg"] = $total["sale_quantity"] > 0 ? floor($total["sale_total"] / $total["sale_quantity"]) : 0;
$total["total_write_offs_per_date_percent"] = $total["sale_total"] > 0 ? floor($total["total_write_offs_per_date"] / $total["sale_total"] * 100) : 0;
$total["total_write_offs_per_month_percent"] = $total["sale_month_total"] > 0 ? floor($total["total_write_offs_per_month"] / $total["sale_month_total"] * 100) : 0;
$total["employee_sale_avg"] = $employeeCountTotal > 0 ? floor($total["sale_total"] / $employeeCountTotal) : 0;
$total["conversion"] = $total["visitors_quantity"] > 0 ? floor($total["sale_quantity"] / $total["visitors_quantity"] * 100) : 0;;
$total["bonus_user_per_sale_percent"] = $total["sale_quantity"] > 0 ? floor($total["bonus_user_count"] / $total["sale_quantity"] * 100) : 0;
- $total["employee_positions_on_shift"] = $employeePositionsOnShift;
- $total["employee_count_on_shift"] = count($weekEmployees);
+ $total["employee_positions_on_shift"] = $totalEmployeePositionsOnShift;
+ $total["employee_count_on_shift"] = $totalEmployeeCountOnShift;
$report = [
"date_from" => $dateStartEnd[0],