ExportFileService.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. <?php
  2. namespace App\Service;
  3. use App\Exports\ExportOrder;
  4. use App\Exports\ItemSalaryFTMultipleSheetExport;
  5. use App\Exports\ItemSalarySheetExport;
  6. use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
  7. use App\Exports\MonthlyPsMatrixExport;
  8. use App\Exports\MultiSheetExport;
  9. use App\Exports\ProjectDepreciationMultipleSheetExport;
  10. use App\Exports\ProjectStaffExport;
  11. use App\Exports\ResearchExpenseMultipleSheetExport;
  12. use App\Model\Depart;
  13. use App\Model\Employee;
  14. use App\Model\Fee;
  15. use App\Model\PLeaveOverOrder;
  16. use Illuminate\Support\Carbon;
  17. use Maatwebsite\Excel\Facades\Excel;
  18. class ExportFileService extends Service
  19. {
  20. public static $filename = "";
  21. //导出的方式 0 选择导出的数据 1 查询后 导出指定的数据(最多每次一千条)
  22. public static $export_type = [
  23. 0,
  24. 1
  25. ];
  26. public function exportAll($data,$user){
  27. if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];
  28. if(empty($data['type'])) return [false, 'type不能为空'];
  29. $function = $data['type'];
  30. $name = $this->fillE($data['type'], $user);
  31. if (! method_exists(self::class, $function)) return [false, "导出方法不存在,请联系开发"];
  32. self::$filename = $name;
  33. $export_type = $data['export_type'] ?? 0;
  34. if(! isset(self::$export_type[$export_type])) return [false,'导出文件方式错误或者不存在'];
  35. if(empty($export_type)){
  36. if(empty($data['id'])) return [false,'请选择导出数据'];
  37. $search = $data;
  38. }else{
  39. if(empty($data['order_search'])) return [false,'搜索条件不能为空'];
  40. $search = $data['order_search'];
  41. if(empty($search['page_index'])) return [false,'请选择导出数据的开始页码'];
  42. if(empty($search['page_size'])) return [false,'请选择导出数据的条数'];
  43. if($search['page_size'] > 5000) return [false,'请选择导出数据的条数每次最多5000条'];
  44. $data['order_search']['menu_id'] = $data['menu_id'];
  45. $search = $data['order_search'];
  46. }
  47. list($status, $return) = $this->$function($search,$user);
  48. if(! $status) return [false, $return];
  49. return [true, $return];
  50. }
  51. public function fillE($type, &$user){
  52. $header = config("excel." . $type) ?? [];
  53. $funcName = $header['name'] ?? "";
  54. // $header_f = "extra_" . $menu_id;
  55. // $service = new TableHeadService();
  56. // if(method_exists($service,$header_f)) $service->$header_f($header_default);
  57. $user['e_header_default'] = $header['array'] ?? [];
  58. return $funcName;
  59. }
  60. private function fillData($data, $column, &$return)
  61. {
  62. // 预先创建包含默认值的键数组
  63. $default = array_fill_keys($column, '');
  64. foreach ($data as $value) {
  65. // 提取交集,并用默认值补充缺失的键
  66. $return[] = array_merge($default, array_intersect_key($value, $default));
  67. }
  68. }
  69. private function fillTotalData($data, $column, &$return){
  70. $tmp = [];
  71. foreach ($column as $value){
  72. $key = $value['key'];
  73. if(! empty($value['sum']) && isset($data[$value['key']])){
  74. $decimals = $col['decimals'] ?? 2;
  75. // $tmp[$value['key']] = $data[$value['key']];
  76. // 用 number_format 格式化输出(保持字符串形式,避免科学计数)
  77. $tmp[$key] = number_format((float)$data[$key], $decimals, '.', '');
  78. }else{
  79. $tmp[$value['key']] = "";
  80. }
  81. }
  82. $return[] = $tmp;
  83. }
  84. public function employee($ergs,$user){
  85. // 导出数据
  86. $return = [];
  87. $header_default = $user['e_header_default'];
  88. $column = array_column($header_default,'export');
  89. $header = array_column($header_default,'value');
  90. $service = new EmployeeService();
  91. $model = $service->employeeCommon($ergs, $user);
  92. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  93. $service->fillDataForExport($data, $column, $user, $return);
  94. });
  95. return [true, $this->saveExportData($return,$header)];
  96. }
  97. public function depart($ergs,$user){
  98. // 导出数据
  99. $return = [];
  100. $header_default = $user['e_header_default'];
  101. $column = array_column($header_default,'export');
  102. $header = array_column($header_default,'value');
  103. $service = new EmployeeService();
  104. $model = $service->departCommon($ergs, $user);
  105. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  106. $data = $data->toArray();
  107. $list['data'] = $data;
  108. //订单数据
  109. $list = $service->fillDepartList($list, $user, true);
  110. //返回数据
  111. $this->fillData($list, $column, $return);
  112. });
  113. return [true, $this->saveExportData($return,$header)];
  114. }
  115. public function device($ergs,$user){
  116. // 导出数据
  117. $return = [];
  118. $header_default = $user['e_header_default'];
  119. $column = array_column($header_default,'export');
  120. $header = array_column($header_default,'value');
  121. $service = new DeviceService();
  122. $model = $service->deviceCommon($ergs, $user);
  123. $model->chunk(500,function ($data) use(&$return, $service, $column,$ergs, $user){
  124. $data = $data->toArray();
  125. $list['data'] = $data;
  126. //订单数据
  127. $list = $service->fillData($list, $ergs, $user);
  128. //返回数据
  129. $this->fillData($list['data'], $column, $return);
  130. });
  131. return [true, $this->saveExportData($return,$header)];
  132. }
  133. public function item($ergs,$user){
  134. // 导出数据
  135. $return = [];
  136. $header_default = $user['e_header_default'];
  137. $column = array_column($header_default,'export');
  138. $header = array_column($header_default,'value');
  139. $service = new ItemService();
  140. $model = $service->itemCommon($ergs, $user);
  141. $model->chunk(500,function ($data) use(&$return,$column,$service, $user){
  142. // 调用 Service 层的填充方法
  143. $service->fillDataForExport($data, $column, $user, $return);
  144. });
  145. return [true, $this->saveExportData($return,$header)];
  146. }
  147. public function fee($ergs,$user){
  148. // 导出数据
  149. $return = [];
  150. $header_default = $user['e_header_default'];
  151. $column = array_column($header_default,'export');
  152. $header = array_column($header_default,'value');
  153. $service = new FeeService();
  154. $model = $service->feeCommon($ergs, $user);
  155. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  156. $data = $data->toArray();
  157. $list['data'] = $data;
  158. //订单数据
  159. $list = $service->fillFeeList($list, $user, true);
  160. //返回数据
  161. $this->fillData($list['data'], $column, $return);
  162. });
  163. return [true, $this->saveExportData($return,$header)];
  164. }
  165. public function monthPwOrder($ergs,$user){
  166. // 导出数据
  167. $return = [];
  168. $header_default = $user['e_header_default'];
  169. $column = array_column($header_default,'export');
  170. $header = array_column($header_default,'value');
  171. $service = new PersonWorkService();
  172. $model = $service->monthlyPwOrderCommon($ergs, $user);
  173. $model->chunk(500,function ($data) use(&$return, $service, $column){
  174. // 直接处理这一批主表数据,将其与详情合并平铺
  175. $service->fillDataForExport($data->toArray(), $column, $return);
  176. });
  177. return [true, $this->saveExportData($return,$header)];
  178. }
  179. public function monthDwOrder($ergs,$user){
  180. // 导出数据
  181. $return = [];
  182. $header_default = $user['e_header_default'];
  183. $column = array_column($header_default,'export');
  184. $header = array_column($header_default,'value');
  185. $service = new DeviceWorkService();
  186. $model = $service->monthlyDwOrderCommon($ergs, $user);
  187. $model->chunk(500,function ($data) use(&$return, $service, $column){
  188. // 直接处理这一批主表数据,将其与详情合并平铺
  189. $service->fillDataForExport($data->toArray(), $column, $return);
  190. });
  191. return [true, $this->saveExportData($return,$header)];
  192. }
  193. public function monthPsOrder1($ergs,$user){
  194. // 导出数据
  195. $return = [];
  196. $header_default = $user['e_header_default'];
  197. $column = array_column($header_default,'export');
  198. $header = array_column($header_default,'value');
  199. $service = new PersonSalaryService();
  200. $model = $service->monthlyPsOrderCommon($ergs, $user);
  201. $model->chunk(500,function ($data) use(&$return, $service, $column){
  202. // 直接处理这一批主表数据,将其与详情合并平铺
  203. $service->fillDataForExport($data->toArray(), $column, $return);
  204. });
  205. return [true, $this->saveExportData($return,$header)];
  206. }
  207. public function monthPsOrder($ergs, $user)
  208. {
  209. $service = new PersonSalaryService();
  210. // 1. 获取主表查询模型
  211. $model = $service->monthlyPsOrderCommon($ergs, $user);
  212. $yearlyData = []; // 用于存放归类后的数据:[年份][员工Key][月份] = 薪资数据
  213. // 2. 分批捞取主表数据并按年、人、月进行归类
  214. $model->chunk(500, function ($mainOrders) use (&$yearlyData, $service) {
  215. $mainIds = $mainOrders->pluck('id')->toArray();
  216. // 获取详情映射 [main_id => [details...]]
  217. $detailsMap = $service->getDetailsMap($mainIds);
  218. foreach ($mainOrders as $main) {
  219. // 解析年份和月份
  220. if (empty($main['month'])) continue;
  221. $year = date('Y', $main['month']); // 例如: "2025"
  222. $month = (int)date('m', $main['month']); // 例如: 5 (直接转成数字 1-12)
  223. $details = $detailsMap[$main['id']] ?? [];
  224. foreach ($details as $sub) {
  225. // 构造员工在表格左侧的唯一标识(工号 + 姓名)
  226. $empKey = $sub['employee_number'] . '_' . $sub['employee_title'];
  227. // 计算当前月份该员工的总薪资 = 基本 + 绩效 + 奖金 + 其他
  228. $totalSalary = (float)$sub['base_salary']
  229. + (float)$sub['performance_salary']
  230. + (float)$sub['bonus']
  231. + (float)$sub['other'];
  232. // 归入矩阵:如果该年该人该月已经有值,做累加(防止单月重复发薪单)
  233. if (!isset($yearlyData[$year][$empKey][$month])) {
  234. $yearlyData[$year][$empKey][$month] = 0;
  235. }
  236. $yearlyData[$year][$empKey][$month] += $totalSalary;
  237. }
  238. }
  239. });
  240. if (empty($yearlyData)) {
  241. return [false, '没有可导出的数据'];
  242. }
  243. // 3. 排序:年份按从小到大,员工按工号排序
  244. ksort($yearlyData);
  245. foreach ($yearlyData as $year => &$emps) {
  246. ksort($emps); // 员工按工号等 Key 排序
  247. }
  248. $file_name = "人员月工资单统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  249. $filename = $file_name . '.' . 'xlsx';
  250. $bool = Excel::store(new MonthlyPsMatrixExport($yearlyData), "/public/export/{$filename}", null, 'Xlsx', []);
  251. return [true, $filename];
  252. }
  253. public function monthDdOrder($ergs,$user){
  254. // 导出数据
  255. $return = [];
  256. $header_default = $user['e_header_default'];
  257. $column = array_column($header_default,'export');
  258. $header = array_column($header_default,'value');
  259. $service = new DeviceDepreciationService();
  260. $model = $service->monthlyDdOrderCommon($ergs, $user);
  261. $model->chunk(500,function ($data) use(&$return, $service, $column){
  262. // 直接处理这一批主表数据,将其与详情合并平铺
  263. $service->fillDataForExport($data->toArray(), $column, $return);
  264. });
  265. return [true, $this->saveExportData($return,$header)];
  266. }
  267. public function ruleSet($ergs,$user){
  268. // 导出数据
  269. $return = [];
  270. $header_default = $user['e_header_default'];
  271. $column = array_column($header_default,'export');
  272. $header = array_column($header_default,'value');
  273. $service = new RuleSetService();
  274. $model = $service->ruleSetCommon($ergs, $user);
  275. $model->chunk(500,function ($data) use(&$return, $service, $column){
  276. // 直接处理这一批主表数据,将其与详情合并平铺
  277. $service->fillDataForExport($data->toArray(), $column, $return);
  278. });
  279. return [true, $this->saveExportData($return,$header)];
  280. }
  281. public function dailyPwOrder($ergs,$user){
  282. // 导出数据
  283. $return = [];
  284. $header_default = $user['e_header_default'];
  285. $column = array_column($header_default,'export');
  286. $header = array_column($header_default,'value');
  287. $service = new PersonWorkService();
  288. $model = $service->dailyPwOrderCommon($ergs, $user);
  289. $model->chunk(500,function ($data) use(&$return, $service, $column){
  290. // 直接处理这一批主表数据,将其与详情合并平铺
  291. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  292. });
  293. return [true, $this->saveExportData($return,$header)];
  294. }
  295. public function dailyDwOrder($ergs,$user){
  296. // 导出数据
  297. $return = [];
  298. $header_default = $user['e_header_default'];
  299. $column = array_column($header_default,'export');
  300. $header = array_column($header_default,'value');
  301. $service = new DeviceWorkService();
  302. $model = $service->dailyDwOrderCommon($ergs, $user);
  303. $model->chunk(500,function ($data) use(&$return, $service, $column){
  304. // 直接处理这一批主表数据,将其与详情合并平铺
  305. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  306. });
  307. return [true, $this->saveExportData($return,$header)];
  308. }
  309. public function leaveOrder($ergs,$user){
  310. // 导出数据
  311. $return = [];
  312. $header_default = $user['e_header_default'];
  313. $column = array_column($header_default,'export');
  314. $header = array_column($header_default,'value');
  315. $service = new PLeaveOverService();
  316. $ergs['type'] = PLeaveOverOrder::TYPE_ONE;
  317. $model = $service->pLeaveOverCommon($ergs, $user);
  318. $model->chunk(500,function ($data) use(&$return, $service, $column){
  319. // 直接处理这一批主表数据,将其与详情合并平铺
  320. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  321. });
  322. return [true, $this->saveExportData($return,$header)];
  323. }
  324. public function overtimeOrder($ergs,$user){
  325. // 导出数据
  326. $return = [];
  327. $header_default = $user['e_header_default'];
  328. $column = array_column($header_default,'export');
  329. $header = array_column($header_default,'value');
  330. $service = new PLeaveOverService();
  331. $ergs['type'] = PLeaveOverOrder::TYPE_TWO;
  332. $model = $service->pLeaveOverCommon($ergs, $user);
  333. $model->chunk(500,function ($data) use(&$return, $service, $column){
  334. // 直接处理这一批主表数据,将其与详情合并平铺
  335. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  336. });
  337. return [true, $this->saveExportData($return,$header)];
  338. }
  339. public function feeOrder($ergs, $user)
  340. {
  341. // 导出配置
  342. $return = [];
  343. $header_default = $user['e_header_default']; // 假设前端已下发报销单的模板配置
  344. $column = array_column($header_default, 'export');
  345. $header = array_column($header_default, 'value');
  346. $service = new ExpenseClaimsService();
  347. // 使用你提到的 common 方法获取 Query Builder
  348. $model = $service->expenseClaimsSetCommon($ergs, $user);
  349. $model->chunk(500, function ($data) use (&$return, $service, $column) {
  350. // 直接处理这一批主表数据,将其与详情合并平铺
  351. $service->fillDataForExport($data->toArray(), $column, $return);
  352. });
  353. return [true, $this->saveExportData($return, $header)];
  354. }
  355. public function RDOrder($ergs, $user)
  356. {
  357. // 导出配置
  358. $return = [];
  359. $header_default = $user['e_header_default'];
  360. $column = array_column($header_default, 'export');
  361. $header = array_column($header_default, 'value');
  362. $service = new AuxiliaryAccountService();
  363. $model = $service->setCommon($ergs, $user);
  364. $model->chunk(500, function ($data) use (&$return, $service, $column) {
  365. // 直接处理这一批主表数据,将其与详情合并平铺
  366. $service->fillDataForExport($data->toArray(), $column, $return);
  367. });
  368. return [true, $this->saveExportData($return, $header)];
  369. }
  370. //标签管理
  371. public function tag($ergs, $user)
  372. {
  373. // 导出配置
  374. $return = [];
  375. $header_default = $user['e_header_default'];
  376. $column = array_column($header_default, 'export');
  377. $header = array_column($header_default, 'value');
  378. $service = new TagService();
  379. $model = $service->tagCommon($ergs, $user);
  380. $model->chunk(500, function ($data) use (&$return, $service, $column, $user) {
  381. $data = $data->toArray();
  382. $list['data'] = $data;
  383. //订单数据
  384. $list = $service->fillPriorityList($list, $user, true);
  385. //返回数据
  386. $this->fillData($list['data'], $column, $return);
  387. });
  388. return [true, $this->saveExportData($return, $header)];
  389. }
  390. // 项目工资统计表
  391. public function exportEmployeeSalary($data, $user)
  392. {
  393. $service = new StatisticService();
  394. // 1. 调用你现有的查询方法获取基础数据
  395. list($status, $itemMonthList) = $service->employeeMonthSalaryStatistic($data, $user);
  396. if (!$status) return $itemMonthList; // 返回错误信息
  397. // 2. 提取所有涉及到的唯一项目 (按 Code 排序,保证列顺序固定)
  398. $projects = collect($itemMonthList)->pluck('item_code')->unique()->sort()->values()->toArray();
  399. // 3. 按月份对数据进行分组
  400. $groupedByMonth = collect($itemMonthList)->groupBy('month')->sortKeys();
  401. $exportData = [];
  402. $columnTotals = array_fill(0, count($projects) * 2, 0); // 用于存储每列的合计
  403. $grandTotalSalary = 0; // 总计金额
  404. // 4. 循环每个月,构造行数据
  405. foreach ($groupedByMonth as $month => $items) {
  406. $row = [$month]; // A列:月份
  407. $monthTotalSalary = 0;
  408. // 创建该月项目的映射,方便快速查找
  409. $monthItemsMap = $items->keyBy('item_code');
  410. foreach ($projects as $index => $code) {
  411. $itemDetail = $monthItemsMap->get($code);
  412. $days = $itemDetail['days'] ?? 0;
  413. $salary = $itemDetail['allocated_salary'] ?? 0;
  414. $row[] = $days > 0 ? $days : ''; // 天数列
  415. $row[] = $salary > 0 ? $salary : ''; // 工资列
  416. // 累加合计行(列合计)
  417. $columnTotals[$index * 2] += $days;
  418. $columnTotals[$index * 2 + 1] += $salary;
  419. $monthTotalSalary += $salary;
  420. }
  421. $row[] = $monthTotalSalary; // 最后一列:该月合计工资
  422. $grandTotalSalary += $monthTotalSalary;
  423. $exportData[] = $row;
  424. }
  425. // 5. 构造最后的“合计”行
  426. $totalRow = ['合计'];
  427. foreach ($columnTotals as $val) {
  428. $totalRow[] = $val > 0 ? $val : 0;
  429. }
  430. $totalRow[] = $grandTotalSalary;
  431. $exportData[] = $totalRow;
  432. //获取公司基本信息
  433. $company = EmployeeService::getCompanyDetail($user);
  434. $file_name = "项目工资统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  435. $filename = $file_name . '.' . 'xlsx';
  436. $bool = Excel::store(new ItemSalarySheetExport($projects, $exportData, $company['title'] ?? ''),"/public/export/{$filename}", null, 'Xlsx', []);
  437. return [true, $filename];
  438. }
  439. // 人员月工时统计表
  440. public function exportManMonthlyWorkHour($data, $user)
  441. {
  442. // 1. 获取报表基础数据
  443. $service = new StatisticService();
  444. list($status, $result) = $service->employeeDayHourStatistic($data, $user);
  445. if (!$status) return $result;
  446. $sourceData = collect($result);
  447. // 2. 按月份分组,准备多 Sheet 数据
  448. // 结构:[ '2024-04' => [ 'days' => 30, 'data' => [...] ], ... ]
  449. $monthsData = [];
  450. // 按月分组数据
  451. $groupedByMonth = $sourceData->groupBy(function ($item) {
  452. return date('Y年m月', strtotime($item['order_date']));
  453. });
  454. //获取公司基本信息
  455. $company = EmployeeService::getCompanyDetail($user);
  456. foreach ($groupedByMonth as $monthName => $monthItems) {
  457. // A. 计算该月总天数
  458. // 转换 '2024年04月' 为 '2024-04' 获取天数
  459. $formatMonth = str_replace(['年', '月'], ['-', ''], $monthName);
  460. $daysInMonth = date('t', strtotime($formatMonth . '-01'));
  461. // B. 进一步按 项目+人员 分组,因为一行显示一个项目一个人的全月工时
  462. $groupedByUserItem = $monthItems->groupBy(function ($item) {
  463. return $item['item_code'] . '_' . $item['employee_id'];
  464. });
  465. $sheetRows = [];
  466. foreach ($groupedByUserItem as $key => $records) {
  467. $first = $records->first();
  468. // 初始化行:前两列是 项目名称 和 姓名
  469. $row = [
  470. $first['item_title'],
  471. $first['employee_name']
  472. ];
  473. // C. 循环 1 号到该月最后一天,填充工时
  474. // 将该员工该项目在这个月的记录转为 日期 => 工时 的映射
  475. $dayMap = $records->keyBy(function($r){
  476. return (int)date('d', strtotime($r['order_date']));
  477. });
  478. for ($d = 1; $d <= $daysInMonth; $d++) {
  479. $workHour = $dayMap->get($d)['total_work_hours'] ?? '';
  480. // 如果工时为 0 或空,按你要求的格式传空字符串
  481. $row[] = ($workHour > 0) ?(float) $workHour : '';
  482. }
  483. $sheetRows[] = $row;
  484. }
  485. $monthsData[$monthName] = [
  486. 'days' => (int)$daysInMonth,
  487. 'data' => $sheetRows,
  488. 'company_name' => $company['title'] ?? '',
  489. ];
  490. }
  491. $file_name = "人员月工时统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  492. $filename = $file_name . '.' . 'xlsx';
  493. $bool = Excel::store(new ManMonthlyWorkHourMultipleSheetExport($monthsData), "/public/export/{$filename}", null, 'Xlsx', []);
  494. return [true, $filename];
  495. }
  496. // 项目设备折旧
  497. public function exportDeviceZj(array $data, $user)
  498. {
  499. $service = new StatisticService();
  500. list($status, $result) = $service->itemDeviceMonthStatistic($data, $user);
  501. if (!$status) return $result;
  502. // 2. 将数据按 [项目编号][月份] 进行分组
  503. // 预期结构:$monthsData['RD01']['months']['2025-01'] = [设备1, 设备2...]
  504. $groupedData = collect($result)->groupBy('item_code');
  505. $finalExportData = [];
  506. foreach ($groupedData as $itemCode => $itemRecords) {
  507. $firstRecord = $itemRecords->first();
  508. $projectName = $firstRecord['item_title'];
  509. $firstMonth = $firstRecord['month'];
  510. $year = substr($firstMonth, 0, 4);
  511. // 3. 构造新的 Key:年-项目 (例如: 2026-53code)
  512. $newSheetKey = $year . '年度项目' . $itemCode;
  513. // 按月份进一步分组
  514. $monthGroups = $itemRecords->groupBy('month');
  515. $monthsPayload = [];
  516. foreach ($monthGroups as $month => $devices) {
  517. $monthData = [];
  518. foreach ($devices as $dev) {
  519. $monthData[] = [
  520. 'device_name' => $dev['device_title'],
  521. 'original_value' => $dev['device_original'], // 设备原值
  522. 'total_depreciation' => $dev['total_depreciatio'], // 当月总折旧
  523. 'project_hours' => $dev['hours'], // 本项目工时
  524. 'total_hours' => $dev['total_hours'], // 当月总工时
  525. 'ratio' => bcmul($dev['ratio'], 100,2), // 研发工时占比
  526. 'allocated_depreciation' => $dev['allocated_depreciatio'], // 本项目分摊折旧
  527. ];
  528. }
  529. $monthsPayload[$month] = $monthData;
  530. }
  531. // 构造 Sheet 所需结构
  532. $finalExportData[$newSheetKey] = [
  533. 'project_name' => $projectName,
  534. 'months' => $monthsPayload
  535. ];
  536. }
  537. $file_name = "项目设备折旧费用统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  538. $filename = $file_name . '.' . 'xlsx';
  539. $bool = Excel::store(new ProjectDepreciationMultipleSheetExport($finalExportData), "/public/export/{$filename}", null, 'Xlsx', []);
  540. return [true, $filename];
  541. }
  542. // 项目工资分摊
  543. public function exportItemSalaryFT(array $data, $user)
  544. {
  545. $service = new StatisticService();
  546. list($status, $result) = $service->itemDaySalaryStatistic($data, $user);
  547. if (!$status) return $result;
  548. $sourceData = collect($result);
  549. $groupedByMonth = $sourceData->groupBy('month');
  550. $monthsData = [];
  551. foreach ($groupedByMonth as $month => $monthRecords) {
  552. // A. 获取本月参与的所有唯一项目编码
  553. $monthProjects = $monthRecords->pluck('item_code')->unique()->sort()->values()->all();
  554. // B. 按人员分组组织数据
  555. $groupedByEmployee = $monthRecords->groupBy('employee_id');
  556. $sheetRows = [];
  557. $index = 1;
  558. // 初始化列合计
  559. $colTotals = [
  560. 'total_salary' => 0,
  561. 'total_min_hours' => 0, // 月总工时合计
  562. 'project_days' => array_fill_keys($monthProjects, 0),
  563. 'project_salary' => array_fill_keys($monthProjects, 0),
  564. 'total_attendance_days' => 0, // 合计工时列的合计
  565. ];
  566. foreach ($groupedByEmployee as $employeeId => $records) {
  567. $first = $records->first();
  568. $empMonthSalary = (float)$first['total_salary'];
  569. $empTotalHours = $first['total_hours'];
  570. // 1-4列:序号、姓名、工资、月总工时
  571. $row = [$index++, $first['employee_title'], $empMonthSalary, $empTotalHours];
  572. // 5. 动态项目工时列
  573. $empMap = $records->keyBy('item_code');
  574. $rowProjectDaysSum = 0;
  575. foreach ($monthProjects as $code) {
  576. if ($empMap->has($code)) {
  577. $record = $empMap->get($code);
  578. $days = (float)($record['work_hours'] ?? 0);
  579. } else {
  580. $days = 0;
  581. }
  582. $row[] = $days > 0 ? $days : '';
  583. $rowProjectDaysSum += $days;
  584. $colTotals['project_days'][$code] += $days;
  585. }
  586. // 6. 合计工时列
  587. $row[] = $rowProjectDaysSum;
  588. $colTotals['total_attendance_days'] += $rowProjectDaysSum;
  589. // 7. 动态项目金额列
  590. foreach ($monthProjects as $code) {
  591. $salary = $empMap->has($code) ? (float)$empMap->get($code)['allocated_salary'] : 0;
  592. $row[] = $salary > 0 ? $salary : '';
  593. $colTotals['project_salary'][$code] += $salary;
  594. }
  595. // 8. 总计工资列
  596. $row[] = $empMonthSalary;
  597. // 累加合计
  598. $colTotals['total_salary'] += $empMonthSalary;
  599. $colTotals['total_min_hours'] += $empTotalHours;
  600. $sheetRows[] = $row;
  601. }
  602. // C. 构造合计行
  603. $totalRow = ['合计', '', $colTotals['total_salary'], $colTotals['total_min_hours']];
  604. foreach ($monthProjects as $code) { $totalRow[] = $colTotals['project_days'][$code]; }
  605. $totalRow[] = $colTotals['total_attendance_days'];
  606. foreach ($monthProjects as $code) { $totalRow[] = $colTotals['project_salary'][$code]; }
  607. $totalRow[] = $colTotals['total_salary'];
  608. $sheetRows[] = $totalRow;
  609. $monthsData[$month] = [
  610. 'projects' => $monthProjects,
  611. 'data' => $sheetRows
  612. ];
  613. }
  614. //获取公司基本信息
  615. $company = EmployeeService::getCompanyDetail($user);
  616. $file_name = "项目工资分摊统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  617. $filename = $file_name . '.xlsx';
  618. Excel::store(
  619. new ItemSalaryFTMultipleSheetExport($monthsData, $company['title'] ?? ''),
  620. "/public/export/{$filename}"
  621. );
  622. return [true, $filename];
  623. }
  624. // 年度研发支出辅助账汇总表
  625. public function exportResearchExpense(array $data, $user)
  626. {
  627. $service = new StatisticService();
  628. list($status, $result) = $service->auxiliaryStatistic($data, $user);
  629. if (!$status) return [false, $result];
  630. $fee_type_list = $result['fee_type_list'];
  631. $raw_list = $result['list'];
  632. if(empty($raw_list)) return [false, '暂无导出数据'];
  633. // 预读年份和动态表头长度
  634. $year = date("Y", strtotime($raw_list[0]['voucher_date']));
  635. $company = Depart::where('id', $user['top_depart_id'])->value('title');
  636. $dynamicHeaderTitles = array_column($fee_type_list, 'title');
  637. $dynamicCount = count($dynamicHeaderTitles);
  638. $totalColCount = 8 + $dynamicCount + 2; // 基础6 + 固定2 + 动态N + 委托2
  639. $groupedData = [];
  640. foreach ($raw_list as $row) {
  641. $sheetKey = $year . $row['code'];
  642. if (!isset($groupedData[$sheetKey])) {
  643. $groupedData[$sheetKey] = [
  644. 'project' => [
  645. 'code' => $row['code'],
  646. 'name' => $row['title'],
  647. ],
  648. 'dynamic_headers' => $dynamicHeaderTitles,
  649. 'data' => [],
  650. 'year' => $company . $year,
  651. 'totals' => array_fill(0, $totalColCount, 0)
  652. ];
  653. $groupedData[$sheetKey]['totals'][0] = '合计'; // 第一列标识
  654. }
  655. // 组织明细行数据 (逻辑不变)
  656. $excelRow = [
  657. $row['voucher_date'], $row['voucher_type'], $row['voucher_no'], $row['voucher_remark'],
  658. (float)$row['voucher_amount'],
  659. (float)$row['aggregation_amount'],
  660. ($row['type'] == 1 ? (float)$row['total_amount'] : 0), // 人员
  661. ($row['type'] == 2 ? (float)$row['total_amount'] : 0) // 折旧
  662. ];
  663. // 动态列填充
  664. foreach ($fee_type_list as $feeId => $feeItem) {
  665. $excelRow[] = ($row['type'] == 3 && $row['fee_id'] == $feeId) ? (float)$row['total_amount'] : 0;
  666. }
  667. // 委托列
  668. $excelRow[] = (float)($row['entrust1_amount'] ?? 0);
  669. $excelRow[] = (float)($row['entrust2_amount'] ?? 0);
  670. // 【性能优化】:同步累加金额 (从索引 4 开始是金额列)
  671. for ($i = 4; $i < $totalColCount; $i++) {
  672. $groupedData[$sheetKey]['totals'][$i] += $excelRow[$i];
  673. }
  674. $groupedData[$sheetKey]['data'][] = $excelRow;
  675. }
  676. foreach ($groupedData as &$group) {
  677. $group['data'][] = $group['totals'];
  678. unset($group['totals']); // 释放内存
  679. }
  680. // 8. 导出逻辑保持不变
  681. $file_name = "年度研发支出辅助账汇总统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  682. $filename = $file_name . '.xlsx';
  683. Excel::store(
  684. new ResearchExpenseMultipleSheetExport($groupedData),
  685. "public/export/{$filename}"
  686. );
  687. return [true, $filename];
  688. }
  689. // 研发支出辅助帐汇总表
  690. public function exportFormalSummary(array $data, $user)
  691. {
  692. $service = new StatisticService();
  693. // 1. 调用业务逻辑获取原始数据
  694. list($status, $result) = $service->employeeAttendanceMonthStatistic($data, $user);
  695. if (!$status) return [false, $result];
  696. $rawList = $result['list'] ?? [];
  697. $feeTypes = $result['fee_type_list'] ?? [];
  698. // 2. 构造动态表头名称
  699. $dynamicHeaderTitles = array_column($feeTypes, 'title');
  700. $dynamicHeaders = array_merge(['人员人工费用', '折旧费用'], $dynamicHeaderTitles);
  701. $items = [];
  702. foreach ($rawList as $v) {
  703. $rowValues = [];
  704. // A. 填充基础固定两项:人工和折旧
  705. $rowValues[] = (float)($v['employee_salary'] ?? 0);
  706. $rowValues[] = (float)($v['device_depreciation'] ?? 0);
  707. // B. 初始化累加变量
  708. $val7_1 = 0; // 其他相关费用合计 (所有 total_amount 之和)
  709. $val8_1 = 0; // 委托境内合计 (所有 entrust1_amount 之和)
  710. $val8_3 = 0; // 委托境外合计 (所有 entrust2_amount 之和)
  711. // 将当前项目的 fee_list 转为集合以便按 ID 快速查找
  712. $currentProjectFees = collect($v['fee_list'] ?? [])->keyBy('id');
  713. // 遍历所有可能的费用类型,确保 values 数组长度与表头一致
  714. foreach ($feeTypes as $type) {
  715. $feeData = $currentProjectFees->get($type['id']);
  716. $amount = (float)($feeData['total_amount'] ?? 0);
  717. // 填充到动态科目列
  718. $rowValues[] = $amount;
  719. // 1. 累加其他相关费用合计 (7.1)
  720. if(! empty($feeData['is_other']) && $feeData['is_other'] == Fee::IS_OTHER_ONE) $val7_1 += $amount;
  721. // 2. 累加委托费用 (8.1 和 8.3)
  722. $val8_1 += (float)($feeData['entrust1_amount'] ?? 0);
  723. $val8_3 += (float)($feeData['entrust2_amount'] ?? 0);
  724. }
  725. $items[] = [
  726. 'no' => $v['code'] ?? '',
  727. 'name' => $v['title'] ?? '',
  728. 'status' => (($v['state'] ?? '') == "完结" ? 3 : 2),
  729. 'type' => $v['expense_type'] ?? '费用化支出',
  730. 'values' => $rowValues,
  731. 'val7_1' => $val7_1,
  732. 'val8_1' => $val8_1,
  733. 'val8_3' => $val8_3,
  734. ];
  735. }
  736. // 年份获取逻辑
  737. $year = Carbon::parse($data['year'])
  738. ->setTimezone(config('app.timezone')) // 转换为 Laravel 配置的时区
  739. ->format('Y');
  740. //获取公司基本信息
  741. $company = EmployeeService::getCompanyDetail($user);
  742. // 3. 组织多 Sheet 格式数据
  743. $monthsData = [
  744. $year => [
  745. 'tax_id' => $company['code'] ?? '',
  746. 'company_name' => $company['title'] ?? '',
  747. 'items' => $items,
  748. 'dynamic_headers' => $dynamicHeaders
  749. ]
  750. ];
  751. // 4. 执行 Excel 存储
  752. $file_name = "研发支出辅助账汇总表_" . date("YmdHis") . "_" . rand(1000, 9999);
  753. $filename = $file_name . '.xlsx';
  754. Excel::store(
  755. new \App\Exports\ResearchExpenseSummaryMultipleSheetExport($monthsData),
  756. "public/export/{$filename}"
  757. );
  758. return [true, $filename];
  759. }
  760. // 人员活动考勤占比
  761. public function exportActivityTimeCard(array $data, $user)
  762. {
  763. $service = new StatisticService();
  764. // 1. 获取统计数据
  765. list($status, $result) = $service->itemEmployeeSalaryStatistic($data, $user);
  766. if (!$status) return [false, $result];
  767. $rawList = collect($result ?? []);
  768. // 2. 按 项目名称 和 年度 联合分组
  769. $groupedData = $rawList->groupBy(function ($item) {
  770. $year = substr($item['month'] ?? date('Y'), 0, 4);
  771. return $year . "-" . $item['item_title'];
  772. });
  773. $allProjectsData = [];
  774. foreach ($groupedData as $groupKey => $records) {
  775. list($year, $projectTitle) = explode('-', $groupKey);
  776. $projectRows = [];
  777. $groupedByMonth = $records->groupBy('month');
  778. foreach ($groupedByMonth as $monthStr => $monthRecords) {
  779. $monthNum = substr($monthStr, 5, 2);
  780. $monthSubTotal = array_fill(3, 15, 0); // 索引3-17的累加器
  781. foreach ($monthRecords as $v) {
  782. $radioVal = (float)($v['radio'] ?? 0);
  783. $row = [
  784. (int)$monthNum . '月', // 0. 月份
  785. '技术人员', // 1. 类别
  786. $v['employee_title'] ?? '', // 2. 姓名
  787. (float)$v['total_min'], // 3. 应出勤
  788. (float)$v['work_minutes'], // 4. 研发出勤
  789. ($radioVal * 100) . '%', // 5. 占比 (字符串)
  790. (float)$v['salary'], // 6. 归集工资
  791. (float)$v['social_insurance'],// 7. 归集社保
  792. (float)$v['public_housing_fund'], // 8. 归集公积金
  793. (float)$v['work_salary'], // 9. 确定工资
  794. (float)$v['work_social_insurance'], // 10. 确定社保
  795. (float)$v['work_public_housing_fund'], // 11. 确定公积金
  796. (float)$v['work_salary'], // 12. 研发确定总工资
  797. (float)$v['work_social_insurance'], // 13. 研发确定总社保
  798. (float)$v['work_public_housing_fund'], // 14. 研发确定总公积金
  799. 0, 0, 0 // 15, 16, 17. 调整金额
  800. ];
  801. $projectRows[] = $row;
  802. // 累加月份小计 (跳过索引5的百分比字符串)
  803. for ($i = 3; $i <= 14; $i++) {
  804. if ($i == 5) continue;
  805. $monthSubTotal[$i] += (float)$row[$i];
  806. }
  807. }
  808. // 构造月份小计行 (重新计算占比)
  809. $mRadio = $monthSubTotal[3] > 0 ? round($monthSubTotal[4] / $monthSubTotal[3] * 100, 2) . '%' : '0%';
  810. $projectRows[] = [
  811. '小计:', '', '', $monthSubTotal[3], $monthSubTotal[4], $mRadio,
  812. $monthSubTotal[6], $monthSubTotal[7], $monthSubTotal[8],
  813. $monthSubTotal[9], $monthSubTotal[10], $monthSubTotal[11],
  814. $monthSubTotal[12], $monthSubTotal[13], $monthSubTotal[14],
  815. 0, 0, 0
  816. ];
  817. }
  818. // 计算整年合计 (避开小计行,避开非数字)
  819. $yearTotal = array_fill(3, 15, 0);
  820. foreach ($projectRows as $row) {
  821. if ($row[0] !== '小计:' && $row[0] !== '合计') {
  822. for ($i = 3; $i <= 14; $i++) {
  823. if ($i == 5) continue;
  824. $yearTotal[$i] += (float)$row[$i];
  825. }
  826. }
  827. }
  828. $yRadio = $yearTotal[3] > 0 ? round($yearTotal[4] / $yearTotal[3] * 100, 2) . '%' : '0%';
  829. $projectRows[] = [
  830. '合计', '', '', $yearTotal[3], $yearTotal[4], $yRadio,
  831. $yearTotal[6], $yearTotal[7], $yearTotal[8],
  832. $yearTotal[9], $yearTotal[10], $yearTotal[11],
  833. $yearTotal[12], $yearTotal[13], $yearTotal[14],
  834. 0, 0, 0
  835. ];
  836. $allProjectsData[$groupKey] = [
  837. 'project' => $projectTitle,
  838. 'year' => $year,
  839. 'data' => $projectRows
  840. ];
  841. }
  842. $filename = "人员活动考勤占比统计表_" . date("YmdHis") . '.xlsx';
  843. \Maatwebsite\Excel\Facades\Excel::store(
  844. new \App\Exports\ManActivityTimeCardMultipleSheetExport($allProjectsData),
  845. "public/export/{$filename}"
  846. );
  847. return [true, $filename];
  848. }
  849. //业研究开发活动汇总表
  850. public function exportEnterpriseRdStatistic(array $data, $user)
  851. {
  852. $service = new StatisticService();
  853. list($status, $result) = $service->enterpriseRdStatistic($data, $user);
  854. if (!$status) return [false, '获取统计数据失败'];
  855. $exportData = [];
  856. $totalBudget = 0; // 预算总计累加器
  857. $totalActual = 0; // 支出总计累加器
  858. foreach ($result as $row) {
  859. $budget = (float)($row['budget'] ?? 0);
  860. $actual = (float)($row['actual_expenditure'] ?? 0);
  861. $totalBudget = bcadd($totalBudget, $budget, 2);
  862. $totalActual = bcadd($totalActual, $actual, 2);
  863. $exportData[] = [
  864. 'activity_name' => $row['title'] ?? '', // 研发活动名称
  865. 'time_range' => $row['time_range'] ?? '', // 起止时间
  866. 'from' => $row['from'] ?? '自有技术', // 起止时间
  867. 'budget' => $budget, // 研发预算
  868. 'actual_spending' => $actual, // 实际支出
  869. 'tech_area' => $row['field'] ?? '', // 技术领域
  870. 'remark' => $row['mark'] ?? '', // 备注
  871. ];
  872. }
  873. $exportData[] = [
  874. 'activity_name' => '',
  875. 'time_range' => '',
  876. 'from' => '',
  877. 'budget' => $totalBudget,
  878. 'actual_spending' => $totalActual,
  879. 'tech_area' => '',
  880. 'remark' => '',
  881. ];
  882. $file_name = "企业研究开发活动汇总表_" . date("YmdHis");
  883. $filename = $file_name . '.xlsx';
  884. $relative_path = "public/export/{$filename}";
  885. \Maatwebsite\Excel\Facades\Excel::store(
  886. new \App\Exports\CompanyRdActivityExport($exportData),
  887. $relative_path
  888. );
  889. return [true, $filename];
  890. }
  891. //企业研究开发科技人员情况表
  892. public function exportEnterpriseRdManStatistic(array $data, $user)
  893. {
  894. $service = new StatisticService();
  895. list($status, $result) = $service->enterpriseRdManStatistic($data, $user);
  896. if (!$status) return [false, '获取人员统计数据失败'];
  897. // 2. 映射数据到导出类需要的字段格式
  898. $exportData = [];
  899. foreach ($result as $row) {
  900. $exportData[] = [
  901. 'name' => $row['title'] ?? '', // 姓名 (对应模型里的 title 字段)
  902. 'id_card' => $row['id_card'] ?? '', // 身份证号码
  903. 'education' => Employee::Education[$row['education']] ?? "", // 学历
  904. 'major' => $row['major'] ?? '', // 专业
  905. 'title_level' => $row['p_title'] ?? '', // 职称/职业资格
  906. 'department_job' => $row['position_new'] ?? '', // 部门/岗位
  907. 'employment_type' => $row['employee_type_title'] ?? "", // 聘用类型
  908. ];
  909. }
  910. // 3. 定义文件名和路径
  911. $file_name = "企业研究开发科技人员情况表_" . date("YmdHis");
  912. $filename = $file_name . '.xlsx';
  913. $relative_path = "public/export/{$filename}";
  914. \Maatwebsite\Excel\Facades\Excel::store(
  915. new \App\Exports\TechnicalStaffExport($exportData),
  916. $relative_path
  917. );
  918. return [true, $filename];
  919. }
  920. //项目研发活动人员情况表
  921. public function exportEnterpriseRdItemStatistic(array $data, $user)
  922. {
  923. $service = new StatisticService();
  924. list($status, $result) = $service->enterpriseRdItemStatistic($data, $user);
  925. if (!$status) return [false, '获取统计数据失败'];
  926. // 2. 映射数据到导出类需要的字段格式
  927. $exportData = [];
  928. foreach ($result as $row) {
  929. $exportData[] = [
  930. 'title' => $row['title'] ?? '', // 姓名 (对应模型里的 title 字段)
  931. 'education' => Employee::Education[$row['education']] ?? "", // 学历
  932. 'major' => $row['major'] ?? '', // 专业
  933. 'p_title' => $row['p_title'] ?? '', // 职称/职业资格
  934. 'item_title' => $row['item_title'] ?? '', // 项目
  935. 'item_role' => $row['item_role'] ?? '', // 项目角色
  936. 'depart_title' => $row['depart_title'] ?? '', // 部门
  937. 'duty' => $row['duty'] ?? "", // 职责
  938. ];
  939. }
  940. // 3. 定义文件名和路径
  941. $file_name = "项目研发活动人员情况表_" . date("YmdHis");
  942. $filename = $file_name . '.xlsx';
  943. $relative_path = "public/export/{$filename}";
  944. \Maatwebsite\Excel\Facades\Excel::store(
  945. new \App\Exports\ProjectStaffExport($exportData),
  946. $relative_path
  947. );
  948. return [true, $filename];
  949. }
  950. public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
  951. if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
  952. $filename = $file_name . '.' . 'xlsx';
  953. $bool = Excel::store(new ExportOrder($data,$type,$headers),"/public/export/{$filename}", null, 'Xlsx', []);
  954. return $filename;
  955. }
  956. public function saveExportData2($data,$type = 1,$column,$timeRow, $file_name = ''){
  957. if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
  958. $filename = $file_name . '.' . 'xlsx';
  959. \Maatwebsite\Excel\Facades\Excel::store(new MultiSheetExport($data, $type,$column,$timeRow),"/public/export/{$filename}", null, 'Xlsx', []);
  960. return $filename;
  961. }
  962. }