Jelajahi Sumber

最后一张报表

cqp 1 bulan lalu
induk
melakukan
ac24a49475

+ 103 - 0
app/Exports/CompanyRdActivityExport.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace App\Exports;
+
+use Maatwebsite\Excel\Concerns\WithEvents;
+use Maatwebsite\Excel\Concerns\WithTitle;
+use Maatwebsite\Excel\Events\AfterSheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Border;
+
+class CompanyRdActivityExport implements WithEvents, WithTitle
+{
+    protected $data; // 存放传入的列表数据
+
+    public function __construct(array $data) {
+        $this->data = $data;
+    }
+
+    public function title(): string {
+        return '研发活动汇总';
+    }
+
+    public function registerEvents(): array {
+        return [
+            AfterSheet::class => function (AfterSheet $event) {
+                $sheet = $event->sheet->getDelegate();
+                $lastCol = 'H';
+                $dataCount = count($this->data);
+                $lastRow = 3 + $dataCount; // 数据从第4行开始填充
+
+                // --- 1. 第一行:主标题 ---
+                $sheet->mergeCells('A1:H1');
+                $sheet->setCellValue('A1', "企业研究开发活动汇总表");
+
+                // --- 2. 第二行:单位说明 ---
+                $sheet->mergeCells('A2:H2');
+                $sheet->setCellValue('A2', "单位:元  "); // 末尾加空格防止贴边
+
+                // --- 3. 第三行:表头标题 ---
+                $headers = [
+                    'A'=>'序号','B'=>'研发活动名称','C'=>'起止时间',
+                    'D'=>'技术来源','E'=>'研发预算','F'=>'实际支出',
+                    'G'=>'技术领域','H'=>'备注'
+                ];
+                foreach ($headers as $col => $title) {
+                    $sheet->setCellValue("{$col}3", $title);
+                }
+
+                // --- 4. 填充数据 (从第4行开始) ---
+                $currentRow = 4;
+                foreach ($this->data as $index => $row) {
+                    $sheet->fromArray([
+                        $index + 1,                 // A 序号
+                        $row['activity_name']??'',  // B 研发活动名称
+                        $row['time_range']??'',     // C 起止时间
+                        '自有技术',                  // D 技术来源
+                        $row['budget']??0,          // E 研发预算
+                        $row['actual_spending']??0, // F 实际支出
+                        $row['tech_area']??'',      // G 技术领域
+                        $row['remark']??'',         // H 备注
+                    ], null, "A{$currentRow}");
+                    $currentRow++;
+                }
+
+                // --- 5. 样式全局精修 ---
+                $fullRange = "A1:{$lastCol}{$lastRow}";
+
+                // 统一设置:垂直居中、水平居中、自动换行
+                $sheet->getStyle($fullRange)->getAlignment()->applyFromArray([
+                    'vertical' => Alignment::VERTICAL_CENTER,
+                    'horizontal' => Alignment::HORIZONTAL_CENTER,
+                    'wrapText' => true,
+                ]);
+
+                // --- 【关键修正】第二行:单位说明 强制右对齐 ---
+                // 必须在全局居中设置之后执行,否则会被覆盖
+                $sheet->getStyle('A2:H2')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
+
+                // 表头 (第1行和第3行) 字体加粗
+                $sheet->getStyle('A1:H1')->getFont()->setBold(true)->setSize(14);
+                $sheet->getStyle('A3:H3')->getFont()->setBold(true);
+
+                // --- 6. 调整行高与列宽 ---
+                $sheet->getRowDimension(1)->setRowHeight(35); // 主标题行
+                $sheet->getRowDimension(2)->setRowHeight(20); // 单位行
+                $sheet->getRowDimension(3)->setRowHeight(25); // 表头行
+
+                // 设置列宽
+                $sheet->getColumnDimension('A')->setWidth(8);
+                $sheet->getColumnDimension('B')->setWidth(30);
+                $sheet->getColumnDimension('C')->setWidth(18);
+                $sheet->getColumnDimension('D')->setWidth(15);
+                $sheet->getColumnDimension('E')->setWidth(13);
+                $sheet->getColumnDimension('F')->setWidth(13);
+                $sheet->getColumnDimension('G')->setWidth(15);
+                $sheet->getColumnDimension('H')->setWidth(25);
+
+                // --- 7. 全表加细边框 ---
+                $sheet->getStyle("A3:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
+            },
+        ];
+    }
+}

+ 101 - 0
app/Exports/ProjectStaffExport.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace App\Exports;
+
+use Maatwebsite\Excel\Concerns\WithEvents;
+use Maatwebsite\Excel\Concerns\WithTitle;
+use Maatwebsite\Excel\Events\AfterSheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Border;
+use PhpOffice\PhpSpreadsheet\Style\Color;
+
+class ProjectStaffExport implements WithEvents, WithTitle
+{
+    protected $data;
+
+    public function __construct(array $data)
+    {
+        $this->data = $data;
+    }
+
+    public function title(): string
+    {
+        return '项目研发人员情况';
+    }
+
+    public function registerEvents(): array
+    {
+        return [
+            AfterSheet::class => function (AfterSheet $event) {
+                $sheet = $event->sheet->getDelegate();
+                $lastCol = 'I';
+                $dataCount = count($this->data);
+                $lastRow = 2 + $dataCount;
+
+                // --- 1. 第一行:主标题(包含红色提示文字) ---
+                $sheet->mergeCells('A1:I1');
+                $sheet->setCellValue('A1', "项目研发活动人员情况表    (这个主要针对项目中体现的人员情况)");
+                $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
+
+                // --- 2. 第二行:表头设置 ---
+                $headers = [
+                    'A' => '序号',
+                    'B' => '姓名',
+                    'C' => '学历',
+                    'D' => '专业',
+                    'E' => '职称',
+                    'F' => "项目角色(不同\n行业不同定义)", // 提示列
+                    'G' => '项目角色',
+                    'H' => '部门',
+                    'I' => '承担职责'
+                ];
+                foreach ($headers as $col => $title) {
+                    $sheet->setCellValue("{$col}2", $title);
+                }
+
+                // 设置表头中 F2 单元格“项目角色”下方文字为红色
+                $sheet->getStyle('F2')->getFont()->getColor()->setARGB(Color::COLOR_RED);
+                $sheet->getStyle('A2:I2')->getFont()->setBold(true);
+
+                // --- 3. 填充数据 ---
+                $currentRow = 3;
+                foreach ($this->data as $index => $row) {
+                    $sheet->fromArray([
+                        $index + 1,
+                        $row['name'] ?? '',
+                        $row['education'] ?? '',
+                        $row['major'] ?? '',
+                        $row['title'] ?? '',
+                        $row['role_desc'] ?? '', // 此列通常显示:项目负责人/技术负责人等
+                        $row['role_name'] ?? '',
+                        $row['dept'] ?? '',
+                        $row['duty'] ?? '',
+                    ], null, "A{$currentRow}");
+                    $currentRow++;
+                }
+
+                // --- 4. 全局样式 ---
+                $fullRange = "A1:{$lastCol}{$lastRow}";
+                $sheet->getStyle($fullRange)->getAlignment()->applyFromArray([
+                    'vertical' => Alignment::VERTICAL_CENTER,
+                    'horizontal' => Alignment::HORIZONTAL_CENTER,
+                    'wrapText' => true,
+                ]);
+
+                // --- 5. 行高与列宽 ---
+                $sheet->getRowDimension(1)->setRowHeight(35);
+                $sheet->getRowDimension(2)->setRowHeight(45); // 表头双行文字
+
+                $sheet->getColumnDimension('A')->setWidth(8);
+                $sheet->getColumnDimension('B')->setWidth(12);
+                $sheet->getColumnDimension('F')->setWidth(20); // 角色定义列
+                $sheet->getColumnDimension('G')->setWidth(15);
+                $sheet->getColumnDimension('H')->setWidth(15);
+                $sheet->getColumnDimension('I')->setWidth(25); // 职责列
+
+                // --- 6. 边框 ---
+                $sheet->getStyle("A2:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
+            },
+        ];
+    }
+}

+ 98 - 0
app/Exports/TechnicalStaffExport.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace App\Exports;
+
+use Maatwebsite\Excel\Concerns\WithEvents;
+use Maatwebsite\Excel\Concerns\WithTitle;
+use Maatwebsite\Excel\Events\AfterSheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Border;
+
+class TechnicalStaffExport implements WithEvents, WithTitle
+{
+    protected $data;
+
+    public function __construct(array $data)
+    {
+        $this->data = $data;
+    }
+
+    public function title(): string
+    {
+        return '科技人员情况表';
+    }
+
+    public function registerEvents(): array
+    {
+        return [
+            AfterSheet::class => function (AfterSheet $event) {
+                $sheet = $event->sheet->getDelegate();
+                $lastCol = 'I'; // A 到 I 共9列
+                $dataCount = count($this->data);
+                $lastRow = 2 + $dataCount; // 标题1行 + 表头1行 + 数据行
+
+                // --- 1. 第一行:主标题 ---
+                $sheet->mergeCells('A1:I1');
+                $sheet->setCellValue('A1', "企业研究开发科技人员情况表");
+                $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
+
+                // --- 2. 第二行:表头 ---
+                $headers = [
+                    'A' => '序号',
+                    'B' => '姓名',
+                    'C' => '身份证号码',
+                    'D' => '学历',
+                    'E' => '专业',
+                    'F' => '职称/职业资格',
+                    'G' => '部门/岗位',
+                    'H' => '在职、临聘、兼职',
+                ];
+                foreach ($headers as $col => $title) {
+                    $sheet->setCellValue("{$col}2", $title);
+                }
+                $sheet->getStyle('A2:I2')->getFont()->setBold(true);
+
+                // --- 3. 填充数据 (从第3行开始) ---
+                $currentRow = 3;
+                foreach ($this->data as $index => $row) {
+                    $sheet->fromArray([
+                        $index + 1,                   // 序号
+                        $row['name'] ?? '',           // 姓名
+                        $row['id_card'] ?? '',        // 身份证号
+                        $row['education'] ?? '',      // 学历
+                        $row['major'] ?? '',          // 专业
+                        $row['title_level'] ?? '',    // 职称/职业资格
+                        $row['department_job'] ?? '', // 部门/岗位
+                        $row['employment_type'] ?? '',// 聘用类型
+                    ], null, "A{$currentRow}");
+                    $currentRow++;
+                }
+
+                // --- 4. 样式全局精修 ---
+                $fullRange = "A1:{$lastCol}{$lastRow}";
+                $sheet->getStyle($fullRange)->getAlignment()->applyFromArray([
+                    'vertical' => Alignment::VERTICAL_CENTER,
+                    'horizontal' => Alignment::HORIZONTAL_CENTER,
+                    'wrapText' => true,
+                ]);
+
+                // --- 5. 设置行高与列宽 ---
+                $sheet->getRowDimension(1)->setRowHeight(40); // 主标题
+                $sheet->getRowDimension(2)->setRowHeight(30); // 表头
+
+                // 根据图片内容调整列宽
+                $sheet->getColumnDimension('A')->setWidth(8);  // 序号
+                $sheet->getColumnDimension('B')->setWidth(12); // 姓名
+                $sheet->getColumnDimension('C')->setWidth(25); // 身份证
+                $sheet->getColumnDimension('D')->setWidth(12); // 学历
+                $sheet->getColumnDimension('E')->setWidth(15); // 专业
+                $sheet->getColumnDimension('F')->setWidth(25); // 职称
+                $sheet->getColumnDimension('G')->setWidth(25); // 部门
+                $sheet->getColumnDimension('H')->setWidth(18); // 类型
+
+                // --- 6. 全表加细边框 ---
+                $sheet->getStyle("A1:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
+            },
+        ];
+    }
+}

+ 134 - 1
app/Http/Controllers/Api/TestController.php

@@ -2,14 +2,17 @@
 
 namespace App\Http\Controllers\Api;
 
+use App\Exports\CompanyRdActivityExport;
 use App\Exports\ItemSalaryFTMultipleSheetExport;
 use App\Exports\ItemSalarySheetExport;
 use App\Exports\ManActivityTimeCardMultipleSheetExport;
 use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
 use App\Exports\ProjectDepreciationMultipleSheetExport;
+use App\Exports\ProjectStaffExport;
 use App\Exports\ResearchExpenseMultipleSheetExport;
 use App\Exports\ResearchExpenseSummaryMultipleSheetExport;
 use App\Exports\ResearchProjectDetailMultiExport;
+use App\Exports\TechnicalStaffExport;
 use Maatwebsite\Excel\Facades\Excel;
 use PhpMqtt\Client\MqttClient;
 // --- 必须引入以下两个 MQTT 相关的类 ---
@@ -18,7 +21,7 @@ use PhpMqtt\Client\ConnectionSettings;
 class TestController extends BaseController
 {
     public function aa(){
-         return $this->rdB();
+         return $this->testExport();
         $mqtt = new MqttClient('47.111.77.194', 1883, 'web_publisher');
         $mqtt->connect((new ConnectionSettings)->setUsername('yonglidev1')->setPassword('tZjUw0kQ'));
         $mqtt->publish('/wy/119/RealtimeData/DT5/yonglidev1', json_encode(['cmd' => 'reset']), 0);
@@ -328,6 +331,7 @@ class TestController extends BaseController
         return $filename;
     }
 
+    //最长的报表
     public function rdB(){
         // 示例数据准备 (通常从数据库查询得出)
         $year = 2026;
@@ -378,4 +382,133 @@ class TestController extends BaseController
 
         return $filename;
     }
+
+    //企业研究开发活动汇总表
+    public function exportRdSummary() {
+
+        // 模拟从数据库获取的研发活动列表数据
+        $rdData = [
+            [
+                'activity_name' => '智能AI图像识别算法研发项目',
+                'time_range' => '2025.01-2025.12',
+                'budget' => 500000.00,
+                'actual_spending' => 485000.50,
+                'tech_area' => '人工智能',
+                'remark' => '核心算法已申请软著',
+            ],
+            [
+                'activity_name' => '高并发云原生架构优化',
+                'time_range' => '2025.03-2025.10',
+                'budget' => 300000.00,
+                'actual_spending' => 310000.00,
+                'tech_area' => '云计算',
+                'remark' => '超出预算部分已通过审批',
+            ],
+        ];
+
+        $file_name = "企业研发活动汇总表_" . date("YmdHis");
+        $filename =  $file_name . '.xlsx';
+
+        // 触发导出
+         Excel::store(
+            new CompanyRdActivityExport($rdData),
+             "public/export/{$filename}"
+        );
+
+         return $filename;
+    }
+
+    // 企业研究开发科技人员情况表
+    public function exportTechnicalStaff()
+    {
+        // 模拟测试数据,对应图片中的示例内容
+        $testData = [
+            [
+                'name' => '张三',
+                'id_card' => '33010119900101XXXX',
+                'education' => '本科',
+                'major' => '计算机科学',
+                'title_level' => '高级工程师',
+                'department_job' => "技术部/\n系统集成工程师",
+                'employment_type' => '在职',
+            ],
+            [
+                'name' => '李四',
+                'id_card' => '33010119920202XXXX',
+                'education' => '硕士',
+                'major' => '机械工程',
+                'title_level' => "工程师/\n注册电气工程师",
+                'department_job' => "生产部/\n模具制作师",
+                'employment_type' => '在职',
+            ],
+            [
+                'name' => '王五',
+                'id_card' => '33010119950505XXXX',
+                'education' => '大专',
+                'major' => '自动化',
+                'title_level' => '助理工程师',
+                'department_job' => "生产部/\n产品试制研发辅助员",
+                'employment_type' => '临聘',
+            ],
+            [
+                'name' => '赵六',
+                'id_card' => '33010119800808XXXX',
+                'education' => '博士',
+                'major' => '电子工程',
+                'title_level' => '教授/电工证',
+                'department_job' => '研发部/技术顾问',
+                'employment_type' => '兼职',
+            ]
+        ];
+
+        $filename = '企业研究开发科技人员情况表_' . date('Ymd') . '.xlsx';
+
+         Excel::store(new TechnicalStaffExport($testData), "public/export/{$filename}");
+
+         return $filename;
+    }
+
+    //项目研发活动人员情况表
+    public function testExport()
+    {
+        // 模拟数据:对应图片中的角色定义示例
+        $data = [
+            [
+                'name' => '张技术',
+                'education' => '本科',
+                'major' => '机械设计',
+                'title' => '高级工程师',
+                'role_desc' => '项目负责人',
+                'role_name' => '总指挥',
+                'dept' => '研发部',
+                'duty' => '负责项目整体进度把控与技术架构设计',
+            ],
+            [
+                'name' => '李研发',
+                'education' => '硕士',
+                'major' => '自动化',
+                'title' => '工程师',
+                'role_desc' => '技术负责人',
+                'role_name' => '核心研发',
+                'dept' => '技术部',
+                'duty' => '负责核心算法编写与系统集成',
+            ],
+            [
+                'name' => '王测试',
+                'education' => '大专',
+                'major' => '电子信息',
+                'title' => '助工',
+                'role_desc' => '测试工程师',
+                'role_name' => '质量检测',
+                'dept' => '质检部',
+                'duty' => '负责产品试制阶段的可靠性测试',
+            ]
+        ];
+
+        $filename = '项目研发活动人员情况表' . date('Ymd') . '.xlsx';
+
+        Excel::store(new ProjectStaffExport($data), "public/export/{$filename}");
+
+        return $filename;
+    }
 }

+ 2 - 1
app/Service/ExpenseClaimsService.php

@@ -101,7 +101,8 @@ class ExpenseClaimsService extends Service
                     'employee_id' => $value['employee_id'] ?? "",
                     'fee_id' => $value['fee_id'] ?? 0,
                     'amount' => $value['amount'] ?? 0,
-                    'entrust_amount' => $value['entrust_amount'] ?? 0,
+                    'entrust1_amount' => $value['entrust1_amount'] ?? 0,
+                    'entrust2_amount' => $value['entrust2_amount'] ?? 0,
                     'remark' => $value['remark'] ?? "",
                     'claim_date' => strtotime($value['claim_date']),
                     'entrust_type' => $value['entrust_type'] ?? 0,