|
@@ -6,6 +6,7 @@ use App\Exports\ExportOrder;
|
|
|
use App\Exports\ItemSalaryFTMultipleSheetExport;
|
|
use App\Exports\ItemSalaryFTMultipleSheetExport;
|
|
|
use App\Exports\ItemSalarySheetExport;
|
|
use App\Exports\ItemSalarySheetExport;
|
|
|
use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
|
|
use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
|
|
|
|
|
+use App\Exports\MonthlyPsMatrixExport;
|
|
|
use App\Exports\MultiSheetExport;
|
|
use App\Exports\MultiSheetExport;
|
|
|
use App\Exports\ProjectDepreciationMultipleSheetExport;
|
|
use App\Exports\ProjectDepreciationMultipleSheetExport;
|
|
|
use App\Exports\ProjectStaffExport;
|
|
use App\Exports\ProjectStaffExport;
|
|
@@ -238,7 +239,7 @@ class ExportFileService extends Service
|
|
|
return [true, $this->saveExportData($return,$header)];
|
|
return [true, $this->saveExportData($return,$header)];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function monthPsOrder($ergs,$user){
|
|
|
|
|
|
|
+ public function monthPsOrder1($ergs,$user){
|
|
|
// 导出数据
|
|
// 导出数据
|
|
|
$return = [];
|
|
$return = [];
|
|
|
$header_default = $user['e_header_default'];
|
|
$header_default = $user['e_header_default'];
|
|
@@ -256,6 +257,63 @@ class ExportFileService extends Service
|
|
|
return [true, $this->saveExportData($return,$header)];
|
|
return [true, $this->saveExportData($return,$header)];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function monthPsOrder($ergs, $user)
|
|
|
|
|
+ {
|
|
|
|
|
+ $service = new PersonSalaryService();
|
|
|
|
|
+ // 1. 获取主表查询模型
|
|
|
|
|
+ $model = $service->monthlyPsOrderCommon($ergs, $user);
|
|
|
|
|
+
|
|
|
|
|
+ $yearlyData = []; // 用于存放归类后的数据:[年份][员工Key][月份] = 薪资数据
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 分批捞取主表数据并按年、人、月进行归类
|
|
|
|
|
+ $model->chunk(500, function ($mainOrders) use (&$yearlyData, $service) {
|
|
|
|
|
+ $mainIds = $mainOrders->pluck('id')->toArray();
|
|
|
|
|
+ // 获取详情映射 [main_id => [details...]]
|
|
|
|
|
+ $detailsMap = $service->getDetailsMap($mainIds);
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($mainOrders as $main) {
|
|
|
|
|
+ // 解析年份和月份
|
|
|
|
|
+ if (empty($main['month'])) continue;
|
|
|
|
|
+ $year = date('Y', $main['month']); // 例如: "2025"
|
|
|
|
|
+ $month = (int)date('m', $main['month']); // 例如: 5 (直接转成数字 1-12)
|
|
|
|
|
+
|
|
|
|
|
+ $details = $detailsMap[$main['id']] ?? [];
|
|
|
|
|
+ foreach ($details as $sub) {
|
|
|
|
|
+ // 构造员工在表格左侧的唯一标识(工号 + 姓名)
|
|
|
|
|
+ $empKey = $sub['employee_number'] . '_' . $sub['employee_title'];
|
|
|
|
|
+
|
|
|
|
|
+ // 计算当前月份该员工的总薪资 = 基本 + 绩效 + 奖金 + 其他
|
|
|
|
|
+ $totalSalary = (float)$sub['base_salary']
|
|
|
|
|
+ + (float)$sub['performance_salary']
|
|
|
|
|
+ + (float)$sub['bonus']
|
|
|
|
|
+ + (float)$sub['other'];
|
|
|
|
|
+
|
|
|
|
|
+ // 归入矩阵:如果该年该人该月已经有值,做累加(防止单月重复发薪单)
|
|
|
|
|
+ if (!isset($yearlyData[$year][$empKey][$month])) {
|
|
|
|
|
+ $yearlyData[$year][$empKey][$month] = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $yearlyData[$year][$empKey][$month] += $totalSalary;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($yearlyData)) {
|
|
|
|
|
+ return [false, '没有可导出的数据'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 排序:年份按从小到大,员工按工号排序
|
|
|
|
|
+ ksort($yearlyData);
|
|
|
|
|
+ foreach ($yearlyData as $year => &$emps) {
|
|
|
|
|
+ ksort($emps); // 员工按工号等 Key 排序
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $file_name = "人员月工资单统计表_" . date("Y-m-d") . "_". rand(1000,9999);
|
|
|
|
|
+ $filename = $file_name . '.' . 'xlsx';
|
|
|
|
|
+
|
|
|
|
|
+ $bool = Excel::store(new MonthlyPsMatrixExport($yearlyData), "/public/export/{$filename}", null, 'Xlsx', []);
|
|
|
|
|
+ return [true, $filename];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function monthDdOrder($ergs,$user){
|
|
public function monthDdOrder($ergs,$user){
|
|
|
// 导出数据
|
|
// 导出数据
|
|
|
$return = [];
|
|
$return = [];
|