Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

gogs 2 месяцев назад
Родитель
Сommit
fb900ea0d9

+ 3 - 5
app/Exports/ManActivityTimeCardMultipleSheetExport.php

@@ -7,7 +7,6 @@ use Maatwebsite\Excel\Concerns\WithMultipleSheets;
 class ManActivityTimeCardMultipleSheetExport implements WithMultipleSheets
 {
     protected $projectsData;
-    protected $year;
 
     /**
      * @param array $projectsData 格式为:[
@@ -16,10 +15,9 @@ class ManActivityTimeCardMultipleSheetExport implements WithMultipleSheets
      * ]
      * @param string $year
      */
-    public function __construct(array $projectsData, string $year = '2024')
+    public function __construct(array $projectsData)
     {
         $this->projectsData = $projectsData;
-        $this->year = $year;
     }
 
     /**
@@ -29,9 +27,9 @@ class ManActivityTimeCardMultipleSheetExport implements WithMultipleSheets
     {
         $sheets = [];
 
-        foreach ($this->projectsData as $projectName => $data) {
+        foreach ($this->projectsData as $key => $data) {
             // 每一项都实例化之前写的那个 ProjectAnnualSalaryExport
-            $sheets[] = new ManActivityTimeCardSheetExport($projectName, $data, $this->year);
+            $sheets[] = new ManActivityTimeCardSheetExport($data['project'], $data['data'], $data['year']);
         }
 
         return $sheets;

+ 1 - 1
app/Service/CalendarService.php

@@ -136,7 +136,7 @@ class CalendarService extends Service
         if(empty($customer)) return [false,'日历设置不存在或已被删除'];
         $customer = $customer->toArray();
         $customer['time']  = ! empty($customer['time']) ? date("Y-m", $customer['time']) : "";
-        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
+        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
 
         $details = $this->getDetail($data['id']);

+ 18 - 23
app/Service/ExpenseClaimsService.php

@@ -2,16 +2,11 @@
 
 namespace App\Service;
 
-use App\Model\CalendarDetails;
-use App\Model\Device;
 use App\Model\Employee;
 use App\Model\ExpenseClaims;
 use App\Model\ExpenseClaimsDetails;
 use App\Model\Fee;
 use App\Model\Item;
-use App\Model\ItemDetails;
-use App\Model\RuleSet;
-use App\Model\RuleSetDetails;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
@@ -27,16 +22,17 @@ class ExpenseClaimsService extends Service
 
     private function expenseClaimsSetCommon($data,$user, $field = []){
         if(empty($field)) $field = ExpenseClaims::$field;
-        $data['top_depart_id'] = $user['top_depart_id'];
+
         $model = ExpenseClaims::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select($field)
             ->orderby('month', 'desc');
         if(! empty($data['month'])) $model->where('month', $data['month']);
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        return $model;
 
+        return $model;
     }
+
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
@@ -47,13 +43,14 @@ class ExpenseClaimsService extends Service
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['month'] =  $value['month'] ? date('Y-m',$value['month']) : '';
         }
+
         return $data;
     }
 
     public function expenseClaimsAdd($data,$user){
         list($status,$msg) = $this->expenseClaimsRule($data, $user);
-        if(!$status) return [$status,$msg];
-        //费用报销结构
+        if(! $status) return [$status, $msg];
+
         try {
             DB::beginTransaction();
             $month = strtotime(date("Ymd", strtotime($data['month'])));
@@ -63,22 +60,23 @@ class ExpenseClaimsService extends Service
                 'type' => ExpenseClaims::Order_type,
                 'period' => $month
             ]);
-            $model->month =  $month;
+            $model->month = $month;
             $model->crt_id = $user['id'];
-            $model->top_depart_id = $user['top_depart_id'];
+            $model->top_depart_id = $data['top_depart_id'];
             $model->save();
-            $data['top_depart_id'] = $user['top_depart_id'];
-            $this->saveDetail($model->id, time(), $data,$user['id']);
+
+            $this->saveDetail($model->id, time(), $data, $user);
 
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
-            return [false,$exception->getLine()."_".$exception->getMessage()];
+            return [false, $exception->getLine()."_".$exception->getMessage()];
         }
 
         return [true, ''];
     }
-    private function saveDetail($id, $time, $data,$crt_id){
+
+    private function saveDetail($id, $time, $data, $user){
         if(! empty($data['details'])){
             $unit = [];
             foreach ($data['details'] as $value){
@@ -98,14 +96,15 @@ class ExpenseClaimsService extends Service
                     'file_name' => $value['file_name']??"",
                     'top_depart_id' => $data['top_depart_id'],
                     'crt_time' => $time,
-                    'crt_id' => $crt_id,
+                    'crt_id' => $user['id'],
                 ];
             }
             if(!empty($unit)) ExpenseClaimsDetails::insert($unit);
         }
     }
 
-    private function expenseClaimsRule($data,$user){
+    private function expenseClaimsRule(&$data, $user){
+        $data['top_depart_id'] = $user['top_depart_id'];
         if(!isset($data['month'])) return [false,"月份必传"];
         $monthStr = $data['month']; // 假设是 "2026-03"
         $monthStart = strtotime($monthStr); // 2026-03-01 00:00:00
@@ -142,8 +141,8 @@ class ExpenseClaimsService extends Service
             ExpenseClaimsDetails::where('del_time',0)
                 ->where('expense_claims_id', $model->id)
                 ->update(['del_time' => $time]);
-            $data['top_depart_id'] = $user['top_depart_id'];
-            $this->saveDetail($model->id, $time, $data, $user['id']);
+
+            $this->saveDetail($model->id, $time, $data, $user);
 
             DB::commit();
         }catch (\Exception $exception){
@@ -197,7 +196,6 @@ class ExpenseClaimsService extends Service
     private function getDetail($data,$user){
         $data = ExpenseClaimsDetails::where('del_time',0)
             ->where('expense_claims_id', $data['id'])
-            ->select('*')
             ->get()->toArray();
         $item_ids = collect($data)->pluck('item_id')->unique()->values()->all();
         $employee_ids = collect($data)->pluck('employee_id')->unique()->values()->all();
@@ -229,7 +227,4 @@ class ExpenseClaimsService extends Service
         return  Carbon::createFromTimestamp($time, 'UTC')
             ->toIso8601ZuluString();
     }
-
-
-
 }

+ 104 - 0
app/Service/ExportFileService.php

@@ -805,6 +805,110 @@ class ExportFileService extends Service
         return [true, $filename];
     }
 
+    // 人员活动考勤占比
+    public function exportActivityTimeCard(array $data, $user)
+    {
+        $service = new StatisticService();
+        // 1. 获取统计数据
+        list($status, $result) = $service->itemEmployeeSalaryStatistic($data, $user);
+        if (!$status) return [false, $result];
+
+        $rawList = collect($result ?? []);
+
+        // 2. 按 项目名称 和 年度 联合分组
+        $groupedData = $rawList->groupBy(function ($item) {
+            $year = substr($item['month'] ?? date('Y'), 0, 4);
+            return $year . "-" . $item['item_title'];
+        });
+
+        $allProjectsData = [];
+
+        foreach ($groupedData as $groupKey => $records) {
+            list($year, $projectTitle) = explode('-', $groupKey);
+
+            $projectRows = [];
+            $groupedByMonth = $records->groupBy('month');
+
+            foreach ($groupedByMonth as $monthStr => $monthRecords) {
+                $monthNum = substr($monthStr, 5, 2);
+                $monthSubTotal = array_fill(3, 15, 0); // 索引3-17的累加器
+
+                foreach ($monthRecords as $v) {
+                    $radioVal = (float)($v['radio'] ?? 0);
+                    $row = [
+                        (int)$monthNum . '月',         // 0. 月份
+                        '技术人员',            // 1. 类别
+                        $v['employee_title'] ?? '',   // 2. 姓名
+                        (float)$v['total_min'],       // 3. 应出勤
+                        (float)$v['work_minutes'],    // 4. 研发出勤
+                        ($radioVal * 100) . '%',      // 5. 占比 (字符串)
+                        (float)$v['salary'],          // 6. 归集工资
+                        (float)$v['social_insurance'],// 7. 归集社保
+                        (float)$v['public_housing_fund'], // 8. 归集公积金
+                        (float)$v['work_salary'],     // 9. 确定工资
+                        (float)$v['work_social_insurance'], // 10. 确定社保
+                        (float)$v['work_public_housing_fund'], // 11. 确定公积金
+                        (float)$v['work_salary'],     // 12. 研发确定总工资
+                        (float)$v['work_social_insurance'], // 13. 研发确定总社保
+                        (float)$v['work_public_housing_fund'], // 14. 研发确定总公积金
+                        0, 0, 0                       // 15, 16, 17. 调整金额
+                    ];
+                    $projectRows[] = $row;
+
+                    // 累加月份小计 (跳过索引5的百分比字符串)
+                    for ($i = 3; $i <= 14; $i++) {
+                        if ($i == 5) continue;
+                        $monthSubTotal[$i] += (float)$row[$i];
+                    }
+                }
+
+                // 构造月份小计行 (重新计算占比)
+                $mRadio = $monthSubTotal[3] > 0 ? round($monthSubTotal[4] / $monthSubTotal[3] * 100, 2) . '%' : '0%';
+                $projectRows[] = [
+                    '小计:', '', '', $monthSubTotal[3], $monthSubTotal[4], $mRadio,
+                    $monthSubTotal[6], $monthSubTotal[7], $monthSubTotal[8],
+                    $monthSubTotal[9], $monthSubTotal[10], $monthSubTotal[11],
+                    $monthSubTotal[12], $monthSubTotal[13], $monthSubTotal[14],
+                    0, 0, 0
+                ];
+            }
+
+            // 计算整年合计 (避开小计行,避开非数字)
+            $yearTotal = array_fill(3, 15, 0);
+            foreach ($projectRows as $row) {
+                if ($row[0] !== '小计:' && $row[0] !== '合计') {
+                    for ($i = 3; $i <= 14; $i++) {
+                        if ($i == 5) continue;
+                        $yearTotal[$i] += (float)$row[$i];
+                    }
+                }
+            }
+
+            $yRadio = $yearTotal[3] > 0 ? round($yearTotal[4] / $yearTotal[3] * 100, 2) . '%' : '0%';
+            $projectRows[] = [
+                '合计', '', '', $yearTotal[3], $yearTotal[4], $yRadio,
+                $yearTotal[6], $yearTotal[7], $yearTotal[8],
+                $yearTotal[9], $yearTotal[10], $yearTotal[11],
+                $yearTotal[12], $yearTotal[13], $yearTotal[14],
+                0, 0, 0
+            ];
+
+            $allProjectsData[$groupKey] = [
+                'project' => $projectTitle,
+                'year'    => $year,
+                'data'    => $projectRows
+            ];
+        }
+
+        $filename = "人员活动考勤占比统计表_" . date("YmdHis") . '.xlsx';
+        \Maatwebsite\Excel\Facades\Excel::store(
+            new \App\Exports\ManActivityTimeCardMultipleSheetExport($allProjectsData),
+            "public/export/{$filename}"
+        );
+
+        return [true, $filename];
+    }
+
     public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
         if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
         $filename =  $file_name . '.' . 'xlsx';