AuxiliaryAccountService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. namespace App\Service;
  3. use App\Model\AuxiliaryAccount;
  4. use App\Model\AuxiliaryAccountDetails;
  5. use App\Model\Employee;
  6. use App\Model\ExpenseClaims;
  7. use App\Model\ExpenseClaimsDetails;
  8. use App\Model\Fee;
  9. use App\Model\MonthlyDdOrder;
  10. use App\Model\MonthlyDdOrderDetails;
  11. use App\Model\MonthlyPsOrder;
  12. use App\Model\MonthlyPsOrderDetails;
  13. use Carbon\Carbon;
  14. use Illuminate\Support\Facades\DB;
  15. class AuxiliaryAccountService extends Service
  16. {
  17. public function auxiliaryAccountList($data,$user){
  18. $model = $this->setCommon($data, $user);
  19. $list = $this->limit($model,'',$data);
  20. $list = $this->fillData($list, $user);
  21. return [true, $list];
  22. }
  23. public function setCommon($data,$user, $field = []){
  24. if(empty($field)) $field = AuxiliaryAccount::$field;
  25. $model = AuxiliaryAccount::Clear($user,$data);
  26. $model = $model->where('del_time',0)
  27. ->select($field)
  28. ->orderby('month', 'desc');
  29. if(! empty($data['month'])) $model->where('month', $data['month']);
  30. if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
  31. if(! empty($data['time'][0]) && ! empty($data['time'][1])) {
  32. $return = $this->changeDateToTimeStampAboutRange($data['time']);
  33. $model->where('month','>=',$return[0]);
  34. $model->where('month','<=',$return[1]);
  35. }
  36. return $model;
  37. }
  38. public function fillData($data, $user){
  39. if(empty($data['data'])) return $data;
  40. $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
  41. $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
  42. foreach ($data['data'] as $key => $value){
  43. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  44. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  45. $data['data'][$key]['month'] = $value['month'] ? date('Y-m',$value['month']) : '';
  46. $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
  47. }
  48. return $data;
  49. }
  50. public function auxiliaryAccountSummary($data,$user){
  51. //传参月份
  52. if(!isset($data['month'])) return [201,'月份必传'];
  53. $month = $data['month'];
  54. $monthStart = strtotime($month);
  55. $monthEnd = strtotime("$month +1 month") - 1;
  56. //获取员工汇总月份工资
  57. list($status,$employee_month_amount) = $this->employeeMonthAmount($data,$user,$monthStart,$monthEnd);
  58. if (!$status) return [$status,$employee_month_amount];
  59. //获取设备折旧费用
  60. list($status,$device_month_amount) = $this->deviceMonthAmount($data,$user,$monthStart,$monthEnd);
  61. if (!$status) return [$status,$device_month_amount];
  62. //获取费用汇总的费用数据
  63. list($status,$fee_month_amount) = $this->feeMonthAmount($data,$user,$monthStart,$monthEnd);
  64. if (!$status) return [$status,$fee_month_amount];
  65. return [true,[
  66. "employee_month_amount" => $employee_month_amount,
  67. "device_month_amount" => $device_month_amount,
  68. "fee_month_amount" => $fee_month_amount,
  69. ]];
  70. }
  71. private function employeeMonthAmount($month,$user,$monthStart,$monthEnd){
  72. $data['top_depart_id'] = $user['top_depart_id'];
  73. $month_ps_order = MonthlyPsOrder::Clear($user,$data);
  74. $month_ps_order_id = $month_ps_order->where('del_time',0)->where("month",$monthStart)->first();
  75. if(empty($month_ps_order_id)){
  76. return [false,"请补充对应月份人员月度工资信息"];
  77. }else{
  78. $month_ps_order_id = $month_ps_order_id->id;
  79. }
  80. $model = MonthlyPsOrderDetails::Clear($user,$data);
  81. $totals = $model->where('main_id', $month_ps_order_id)
  82. ->where('del_time', 0)
  83. ->selectRaw('
  84. employee_id,
  85. SUM(
  86. IFNULL(base_salary, 0) +
  87. IFNULL(other, 0) +
  88. IFNULL(performance_salary, 0) +
  89. IFNULL(bonus, 0)
  90. ) as total
  91. ')
  92. ->groupBy('employee_id')
  93. ->pluck('total' , 'employee_id')
  94. ->toArray();
  95. $entrust_type_map = Employee::whereIn('id', array_keys($totals))
  96. ->pluck('entrust_type', 'id')
  97. ->toArray();
  98. $total_amount = $entrust_in_amount = $entrust_out_amount = 0;
  99. foreach ($totals as $employee_id => $amount){
  100. $total_amount = bcadd($amount, $total_amount, 2);
  101. if(! empty($entrust_type_map[$employee_id])){
  102. $tmp = $entrust_type_map[$employee_id];
  103. if($tmp == Employee::WT_TYPE_ONE){
  104. $entrust_in_amount = bcadd($amount, $entrust_in_amount, 2);
  105. }elseif($tmp == Employee::WT_TYPE_TWO){
  106. $entrust_out_amount = bcadd($amount, $entrust_out_amount, 2);
  107. }
  108. }
  109. }
  110. return [true,[
  111. "total_amount" => $total_amount,
  112. "entrust_in_amount" => $entrust_in_amount,
  113. "entrust_out_amount" => $entrust_out_amount,
  114. ]];
  115. }
  116. private function employeeMonthAmount1($month,$user,$monthStart,$monthEnd){
  117. $data['top_depart_id'] = $user['top_depart_id'];
  118. $month_ps_order = MonthlyPsOrder::Clear($user,$data);
  119. $month_ps_order_id = $month_ps_order->where('del_time',0)->where("month",$monthStart)->first();
  120. if(empty($month_ps_order_id)){
  121. return [false,"请补充对应月份人员月度工资信息"];
  122. }else{
  123. $month_ps_order_id = $month_ps_order_id->id;
  124. }
  125. $model = MonthlyPsOrderDetails::Clear($user,$data);
  126. //总金额
  127. $total_amount = $model->where('main_id',$month_ps_order_id)->where('del_time',0)->sum("salary");
  128. //委内
  129. $entrust_in_amount = $model->where('main_id',$month_ps_order_id)->where("entrust_type",1)->sum("salary");
  130. //委外
  131. $entrust_out_amount = $model->where('main_id',$month_ps_order_id)->where("entrust_type",2)->sum("salary");
  132. return [true,[
  133. "total_amount" => $total_amount,
  134. "entrust_in_amount" => $entrust_in_amount,
  135. "entrust_out_amount" => $entrust_out_amount,
  136. ]];
  137. }
  138. private function deviceMonthAmount($month,$user,$monthStart,$monthEnd){
  139. $data['top_depart_id'] = $user['top_depart_id'];
  140. $month_ps_order = MonthlyDdOrder::Clear($user,$data);
  141. $month_ps_order_id = $month_ps_order->where('del_time',0)->where("month",$monthStart)->first();
  142. if(empty($month_ps_order_id)){
  143. return [false,"请补充对应月份设备月度折旧信息"];
  144. }else{
  145. $month_ps_order_id = $month_ps_order_id->id;
  146. }
  147. $model = MonthlyDdOrderDetails::Clear($user,$data);
  148. //总金额
  149. $total_amount = $model->where('main_id',$month_ps_order_id)->sum("depreciation_amount");
  150. return [true,[
  151. "total_amount" => $total_amount,
  152. ]];
  153. }
  154. private function feeMonthAmount($month,$user,$monthStart,$monthEnd){
  155. $data['top_depart_id'] = $user['top_depart_id'];
  156. $month_ps_order = ExpenseClaims::Clear($user,$data);
  157. $month_ps_order_id = $month_ps_order->where('del_time',0)->where("month",$monthStart)->first();
  158. if(empty($month_ps_order_id)){
  159. return [false,"请补充对应月份费用信息"];
  160. }else{
  161. $month_ps_order_id = $month_ps_order_id->id;
  162. }
  163. $model = new ExpenseClaimsDetails();
  164. //总金额
  165. $list = $model->where('expense_claims_id',$month_ps_order_id)->where('del_time',0)->select("fee_id","amount as total_amount","remark","entrust_type","item_id")->get()->toArray();
  166. foreach ($list as &$v){
  167. $v['entrust1_amount'] = $v['entrust_type'] == 1 ? $v['total_amount'] : 0;
  168. $v['entrust2_amount'] = $v['entrust_type'] == 2 ? $v['total_amount'] : 0;
  169. }
  170. ///分组
  171. $fee_type_list = Fee::TopClear($user,$data)->where('del_time',0)->select("title","id","parent_id")->get()->toArray();
  172. return [true,$this->groupListByRoot($list,$fee_type_list)];
  173. }
  174. /**
  175. * 将报销明细按照一级费用分类进行分组
  176. * * @param array $list 报销明细列表 (含 fee_id, amount 等)
  177. * @param array $fee_type_list 费用类型树 (含 id, parent_id, title)
  178. * @return array
  179. */
  180. public function groupListByRoot(array $list, array $fee_type_list)
  181. {
  182. // 1. 建立 ID 索引,方便快速查找
  183. $idMap = array_column($fee_type_list, null, 'id');
  184. // 2. 预处理映射表:让所有子 ID 直接指向它的最顶层“祖宗” ID
  185. $childToRoot = [];
  186. $grouped = [];
  187. foreach ($fee_type_list as $type) {
  188. $current = $type;
  189. // 向上追溯直到 parent_id 为 0,即找到一级分类
  190. while ($current['parent_id'] != 0) {
  191. $current = $idMap[$current['parent_id']];
  192. }
  193. $childToRoot[$type['id']] = [
  194. 'id' => $current['id'],
  195. 'title' => $current['title']
  196. ];
  197. // if (!isset($grouped[$current['id']])) {
  198. // $grouped[$current['id']] = [
  199. // 'first_level_id' => $current['id'],
  200. // 'first_level_title' => $current['title'],
  201. // 'details' => []
  202. // ];
  203. // }
  204. }
  205. $map = Fee::whereIn('id', array_unique(array_column($list,'fee_id')))
  206. ->pluck('title','id')
  207. ->all();
  208. // 3. 遍历明细数据进行分组
  209. foreach ($list as $item) {
  210. $feeId = $item['fee_id'];
  211. $item['fee_title'] = $map[$item['fee_id']] ?? "";
  212. // 获取该费用对应的一级分类信息
  213. $rootInfo = $childToRoot[$feeId] ?? ['id' => 0, 'title' => '其他费用'];
  214. $rootId = $rootInfo['id'];
  215. if (!isset($grouped[$rootId])) {
  216. $grouped[$rootId] = [
  217. 'first_level_id' => $rootId,
  218. 'first_level_title' => $rootInfo['title'],
  219. 'details' => []
  220. ];
  221. }
  222. $grouped[$rootId]['details'][] = $item;
  223. }
  224. // 4. 重置数组索引并返回
  225. return array_values($grouped);
  226. }
  227. public function auxiliaryAccountAdd($data,$user){
  228. list($status,$msg) = $this->auxiliaryAccountRule($data, $user);
  229. if(!$status) return [$status,$msg];
  230. try {
  231. DB::beginTransaction();
  232. $model = new AuxiliaryAccount();
  233. $model->code = $this->generateBillNo([
  234. 'top_depart_id' => $user['top_depart_id'],
  235. 'type' => ExpenseClaims::Order_type,
  236. 'period' => date("Ym", $data['month'])
  237. ]);
  238. $model->month = $data['month'];
  239. $model->crt_id = $user['id'];
  240. $model->top_depart_id = $data['top_depart_id'];
  241. $model->save();
  242. $this->saveDetail($model->id, time(), $data,$user['id'],$user);
  243. DB::commit();
  244. }catch (\Exception $exception){
  245. DB::rollBack();
  246. return [false,$exception->getLine().':'.$exception->getMessage()];
  247. }
  248. return [true, ''];
  249. }
  250. private function saveDetail($id, $time, $data,$crt_id,$user){
  251. if(! empty($data['details'])){
  252. $unit = [];
  253. foreach ($data['details'] as $value){
  254. $unit[] = [
  255. 'auxiliary_account_id' => $id,
  256. 'voucher_date' => strtotime($value['voucher_date']),
  257. 'voucher_type' => $value['voucher_type'],
  258. 'voucher_no' => $value['voucher_no'],
  259. 'voucher_remark' => $value['voucher_remark'],
  260. 'voucher_amount' => $value['voucher_amount'],
  261. 'entrust_type' => $value['entrust_type']??"",
  262. 'type' => $value['type'],
  263. 'fee_id' => $value['fee_id']??0,
  264. 'remark' => $value['remark']??"",
  265. 'entrust1_amount' => $value['entrust1_amount']??0,
  266. 'entrust2_amount' => $value['entrust2_amount']??0,
  267. 'aggregation_amount' => $value['aggregation_amount']??00,
  268. 'total_amount' => $value['total_amount'],
  269. 'top_depart_id' => $user['top_depart_id'],
  270. 'item_id' => $value['item_id'],
  271. 'crt_time' => $time,
  272. 'crt_id' => $crt_id,
  273. 'r_id' => $value['r_id']??0,
  274. ];
  275. }
  276. if(!empty($unit)) AuxiliaryAccountDetails::insert($unit);
  277. }
  278. }
  279. private function auxiliaryAccountRule(&$data, $user, $is_add = true){
  280. $data['top_depart_id'] = $user['top_depart_id'];
  281. if (empty($data['month'])) return [false, '月份不能为空'];
  282. $data['month'] = $this->changeDateToDate($data['month']);
  283. //归档
  284. list($status, $msg) = ArchiveService::isArchive($data['month'], $user);
  285. if(! $status) return [false, $msg];
  286. $monthStart = $data['month'];
  287. $monthEnd = strtotime('+1 month', $monthStart) - 1;
  288. if(empty($data['details'])) return [false, '研发支出辅助账单明细不能为空'];
  289. // 初始化各类型的计数器
  290. $typeCounters = [];
  291. $fee_map = Fee::where('top_depart_id', $data['top_depart_id'])
  292. ->whereIn('id', array_unique(array_column($data['details'], 'fee_id')))
  293. ->pluck('title', 'id')
  294. ->all();
  295. foreach ($data['details'] as $item) {
  296. if(empty($item['type']) || ! isset(AuxiliaryAccountDetails::Type[$item['type']])) return [false, 'type类型不能为空或错误'];
  297. $type = $item['type'];
  298. $tabName = AuxiliaryAccountDetails::Type[$item['type']];
  299. // 针对当前 type 的行数进行累加
  300. if($type == AuxiliaryAccountDetails::TYPE_ONE || $type == AuxiliaryAccountDetails::TYPE_TWO|| $type == AuxiliaryAccountDetails::TYPE_THREE){
  301. if (!isset($typeCounters[$type])) {
  302. $typeCounters[$type] = 1;
  303. } else {
  304. $typeCounters[$type]++;
  305. }
  306. }else{
  307. if(empty($item['fee_id'])) return [false, '费用类型id不能为空'];
  308. $fee_t = $fee_map[$item['fee_id']] ?? "";
  309. if(empty($fee_t)) return [false, '费用类型不存在'];
  310. $tabName = $fee_t;
  311. $new_key = $type . $item['fee_id'];
  312. if (!isset($typeCounters[$new_key])) {
  313. $typeCounters[$new_key] = 1;
  314. } else {
  315. $typeCounters[$new_key]++;
  316. }
  317. }
  318. $errorPrefix = "【{$tabName}】第 " . $typeCounters[$type] . " 行:";
  319. if (!isset($item['voucher_date'])) {
  320. return [false, $errorPrefix . "凭证日期缺失"];
  321. }
  322. // 将报销日期转换为时间戳
  323. $claimTime = strtotime($item['voucher_date']);
  324. // 判断:voucher_date 必须早于 month
  325. // 如果 voucher_date 是 2026-02-28,而 month 是 2026-03-01,则校验通过
  326. if ($claimTime < $monthStart || $claimTime > $monthEnd) return [false, $errorPrefix . "凭证日期必须早于当前结算月份(" . date("Y-m", $data['month']) . ")"];
  327. if (!isset($item['voucher_type'])) {
  328. return [false, $errorPrefix . "凭证种类缺失"];
  329. }
  330. if (!isset($item['voucher_no'])) {
  331. return [false, $errorPrefix . "凭证号数缺失"];
  332. }
  333. if (!isset($item['voucher_remark'])) {
  334. return [false, $errorPrefix . "凭证摘要缺失"];
  335. }
  336. if (!isset($item['voucher_amount'])) {
  337. return [false, $errorPrefix . "会计凭证记载金额缺失"];
  338. }
  339. $res = $this->checkNumber($item['voucher_amount'], 2, 'non-negative');
  340. if (! $res['valid']) return [false, $errorPrefix . "会计凭证记载金额" . $res['error']];
  341. if (!isset($item['aggregation_amount'])) {
  342. return [false, $errorPrefix . "税法规定的归集金额缺失"];
  343. }
  344. $res = $this->checkNumber($item['aggregation_amount'], 2, 'non-negative');
  345. if (! $res['valid']) return [false, $errorPrefix . "税法规定的归集金额" . $res['error']];
  346. }
  347. $query = AuxiliaryAccount::where('top_depart_id', $user['top_depart_id'])
  348. ->where('month', $monthStart)
  349. ->where('del_time', 0);
  350. if (!$is_add) {
  351. if (empty($data['id'])) return [false, 'ID不能为空'];
  352. $query->where('id', '<>', $data['id']);
  353. }
  354. if ($query->exists()) return [false, date("Y-m", $monthStart) . '已存在研发支出辅助账单'];
  355. return [true, ''];
  356. }
  357. public function auxiliaryAccountEdit($data,$user){
  358. list($status,$msg) = $this->auxiliaryAccountRule($data, $user, false);
  359. if(!$status) return [$status,$msg];
  360. try {
  361. DB::beginTransaction();
  362. $model = AuxiliaryAccount::where('id',$data['id'])->first();
  363. // $model->save();
  364. $time = time();
  365. AuxiliaryAccountDetails::where('del_time',0)
  366. ->where('auxiliary_account_id', $model->id)
  367. ->update(['del_time' => $time]);
  368. $this->saveDetail($model->id, $time, $data,$user['id']);
  369. DB::commit();
  370. }catch (\Exception $exception){
  371. DB::rollBack();
  372. return [false,$exception->getMessage()];
  373. }
  374. return [true, ''];
  375. }
  376. public function auxiliaryAccountDel($data, $user){
  377. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  378. try {
  379. DB::beginTransaction();
  380. $time = time();
  381. $month = AuxiliaryAccount::where('del_time',0)
  382. ->whereIn('id',$data['id'])
  383. ->pluck('month')
  384. ->toArray();
  385. //归档
  386. list($status, $msg) = ArchiveService::isArchive($month, $user);
  387. if(! $status) return [false, $msg];
  388. AuxiliaryAccount::where('del_time',0)
  389. ->whereIn('id',$data['id'])
  390. ->update(['del_time' => $time]);
  391. AuxiliaryAccountDetails::where('del_time',0)
  392. ->whereIn('auxiliary_account_id', $data['id'])
  393. ->update(['del_time' => $time]);
  394. DB::commit();
  395. }catch (\Exception $exception){
  396. DB::rollBack();
  397. return [false,$exception->getMessage()];
  398. }
  399. return [true, ''];
  400. }
  401. public function auxiliaryAccountDetail($data, $user){
  402. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  403. $customer = AuxiliaryAccount::where('del_time',0)
  404. ->where('id',$data['id'])
  405. ->first();
  406. if(empty($customer)) return [false,'单据不存在或已被删除'];
  407. $customer = $customer->toArray();
  408. $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
  409. $customer['crt_time'] =$this->utcTime($customer['crt_time']);
  410. $map = ArchiveService::fillIsArchive($customer['month'], $user);
  411. $customer['is_archive'] = $map[$customer['month']] ?? false;
  412. $customer['month'] =$this->utcTime($customer['month']);
  413. $details = $this->getDetail($data['id']);
  414. $customer["details"] = $details;
  415. return [true, $customer];
  416. }
  417. private function getDetail($id){
  418. $data = AuxiliaryAccountDetails::where('del_time',0)
  419. ->where('auxiliary_account_id', $id)
  420. ->get()->toArray();
  421. $map = Fee::whereIn('id', array_unique(array_column($data,'fee_id')))
  422. ->pluck('title','id')
  423. ->all();
  424. foreach ($data as &$v){
  425. $v['voucher_date'] = $this->utcTime($v['voucher_date']);
  426. $v['fee_title'] = $map[$v['fee_id']] ?? "";
  427. }
  428. return $data;
  429. }
  430. private function utcTime($time){
  431. return Carbon::createFromTimestamp($time, 'UTC')
  432. ->toIso8601ZuluString();
  433. }
  434. public function fillDataForExport($data, $column, &$return)
  435. {
  436. if (empty($data)) return;
  437. $mainIds = array_column($data, 'id');
  438. // 获取详情映射 [expense_claims_id => [details...]]
  439. $detailsMap = $this->getDetailsMap($mainIds);
  440. // 默认空行模板
  441. $defaultRow = array_fill_keys($column, '');
  442. foreach ($data as $main) {
  443. $mainId = $main['id'];
  444. $details = $detailsMap[$mainId] ?? [];
  445. // 提取主表信息
  446. $mainInfo = [
  447. 'code' => $main['code'],
  448. 'month' => $main['month'] ? date('Y-m', $main['month']) : '',
  449. ];
  450. if (empty($details)) {
  451. // 如果没有详情,至少导出一行主表信息
  452. $return[] = array_merge($defaultRow, $mainInfo);
  453. } else {
  454. // 遍历明细,每一行明细都带上主表的 code 和 month
  455. foreach ($details as $sub) {
  456. // 合并主表字段 + 详情字段
  457. $fullRow = array_merge($mainInfo, $sub);
  458. // 仅保留 column 配置中要求的列
  459. $return[] = array_merge($defaultRow, array_intersect_key($fullRow, $defaultRow));
  460. }
  461. }
  462. }
  463. }
  464. public function getDetailsMap($main_ids)
  465. {
  466. // 1. 获取详情
  467. $details = AuxiliaryAccountDetails::where('del_time', 0)
  468. ->whereIn('auxiliary_account_id', $main_ids)
  469. ->get();
  470. if ($details->isEmpty()) return [];
  471. // 2. 批量提取所有关联 ID 用于预加载
  472. $feeIds = $details->pluck('fee_id')->unique();
  473. // 3. 建立档案映射 Map
  474. $feeMap = Fee::whereIn('id', $feeIds)->get()->keyBy('id');
  475. $res = [];
  476. foreach ($details as $item) {
  477. $tmpFee = $feeMap[$item->fee_id] ?? null;
  478. $t = $tmpFee ? $tmpFee->title : '';
  479. if($item->type == AuxiliaryAccountDetails::TYPE_ONE || $item->type == AuxiliaryAccountDetails::TYPE_TWO){
  480. $type_title = AuxiliaryAccountDetails::Type[$item->type] ?? "";
  481. }else{
  482. $type_title = $t;
  483. }
  484. // 4. 组装明细行字段 (key 要与模板配置中的 export 对应)
  485. $res[$item->auxiliary_account_id][] = [
  486. 'type_title' => $type_title,
  487. 'voucher_date' => $item->voucher_date ? date('Y-m-d', $item->voucher_date) : '',
  488. 'voucher_type' => $item->voucher_type,
  489. 'voucher_no' => $item->voucher_no,
  490. 'voucher_remark' => $item->voucher_remark,
  491. 'voucher_amount' => $item->voucher_amount,
  492. 'aggregation_amount' => $item->aggregation_amount,
  493. 'total_amount' => $item->total_amount,
  494. 'entrust1_amount' => $item->entrust1_amount,
  495. 'entrust2_amount' => $item->entrust2_amount,
  496. 'remark' => $item->remark,
  497. 'fee_title' => $t,
  498. ];
  499. }
  500. return $res;
  501. }
  502. }