ExportFileService.php 47 KB

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