StatisticsService.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <?php
  2. namespace App\Service;
  3. use App\Model\EmployeeIndex;
  4. use App\Model\FreightFee;
  5. use App\Model\GiveOut;
  6. use App\Model\ItemReport;
  7. use App\Model\ItemReportRoad;
  8. use App\Model\RevenueCost;
  9. use App\Model\RevenueCostTotal;
  10. use App\Model\SalaryEmployee;
  11. use Illuminate\Support\Facades\DB;
  12. class StatisticsService extends Service
  13. {
  14. public function statisticsRevenueCostCommon($data,$user, $field = []){
  15. if(empty($field)) $field = RevenueCostTotal::$field;
  16. $model = RevenueCostTotal::Clear($user,$data);
  17. $model = $model->where('del_time',0)
  18. ->select($field)
  19. ->orderby('id', 'desc');
  20. if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
  21. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
  22. list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
  23. if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
  24. $model->where('order_time', '>=', $start_time)
  25. ->where('order_time', '<', $end_time);
  26. }
  27. if(! empty($data['order_type'])) $model->where('order_type',$data['order_type']);
  28. if(! empty($data['id'])) $model->whereIn('id',$data['id']);
  29. return [true, $model];
  30. }
  31. public function statisticsRevenueCost($data,$user){
  32. list($status, $model) = $this->statisticsRevenueCostCommon($data, $user);
  33. if(! $status) return [false, $model];
  34. $list = $this->limit($model,'',$data);
  35. $list = $this->statisticsRevenueCostFillData($list);
  36. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  37. return [true, $list];
  38. }
  39. public function statisticsRevenueCostFillData($data){
  40. if(empty($data['data'])) return $data;
  41. foreach ($data['data'] as $key => $value){
  42. $time = date("Y-m", $value['order_time']);
  43. $data['data'][$key]['order_time'] = $time;
  44. $data['data'][$key]['order_type_title'] = RevenueCost::$order_type[$value['order_type']] ?? "";
  45. $data['data'][$key]['profit_rate'] = bcmul($value['profit_rate'], 100,2);
  46. }
  47. return $data;
  48. }
  49. public function statisticsRevenueCostOneAndTwoCommon($data,$user, $field = []){
  50. if(empty($data['order_type']) || ! isset(RevenueCost::$order_type[$data['order_type']])) return [false, '单据类型不存在或错误'];
  51. if(empty($field)) {
  52. if($data['order_type'] == 1){
  53. $field = RevenueCost::$field_xhd;
  54. }else{
  55. $field = RevenueCost::$field_xsfp;
  56. }
  57. }
  58. $model = RevenueCost::Clear($user,$data);
  59. $model = $model->where('del_time',0)
  60. ->where('order_type',$data['order_type'])
  61. ->select($field)
  62. ->orderby('id', 'desc');
  63. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
  64. list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
  65. if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
  66. $model->where('order_time', '>=', $start_time)
  67. ->where('order_time', '<=', $end_time);
  68. }
  69. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  70. if(! empty($data['customer_title'])) $model->where('customer_title', 'LIKE', '%'.$data['customer_title'].'%');
  71. if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
  72. if(! empty($data['id'])) $model->whereIn('id',$data['id']);
  73. return [true, $model];
  74. }
  75. public function statisticsRevenueCostOneAndTwo($data,$user){
  76. list($status, $model) = $this->statisticsRevenueCostOneAndTwoCommon($data, $user);
  77. if(! $status) return [false, $model];
  78. $list = $this->limit($model,'',$data);
  79. $list = $this->statisticsRevenueCostOneAndTwoFillData($list);
  80. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  81. return [true, $list];
  82. }
  83. public function statisticsRevenueCostOneAndTwoFillData($data){
  84. if(empty($data['data'])) return $data;
  85. foreach ($data['data'] as $key => $value){
  86. $data['data'][$key]['profit_rate'] = bcmul($value['profit_rate'], 100,2);
  87. $data['data'][$key]['order_time'] = $value['order_time'] ? date("Y-m-d", $value['order_time']) : "";
  88. }
  89. return $data;
  90. }
  91. public function statisticsRevenueCostThreeCommon($data,$user, $field = []){
  92. if(empty($field)) {
  93. $field = RevenueCost::$field_hkd_salary_main;
  94. $field[] = DB::raw('sum(payment_amount) as payment_amount');
  95. $field[] = DB::raw('sum(price_4_total) as price_4_total');
  96. $field[] = DB::raw('sum(profit) as profit');
  97. $field[] = DB::raw('max(employee_id_2) as employee_id_2');
  98. $field[] = DB::raw("MAX(COALESCE(employee_id_2_title, '')) as employee_id_2_title");
  99. }
  100. $model = RevenueCost::Clear($user,$data);
  101. $model = $model->where('del_time',0)
  102. ->where('order_type',RevenueCost::ORDER_THREE)
  103. ->select($field)
  104. ->groupby('order_id')
  105. ->orderby('id', 'desc');
  106. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
  107. list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
  108. if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
  109. $model->where('order_time', '>=', $start_time)
  110. ->where('order_time', '<=', $end_time);
  111. }
  112. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  113. if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
  114. if(! empty($data['employee_id_1'])) $model->where('employee_id_1', 'LIKE', $data['employee_id_1']);
  115. if(! empty($data['employee_id_2'])) $model->where('employee_id_2', 'LIKE', $data['employee_id_2']);
  116. if(! empty($data['employee_id_2_title'])) $model->where('employee_id_2_title', 'LIKE', '%'.$data['employee_id_2_title'].'%');
  117. if(! empty($data['channel_finance_array'])) {
  118. $array = explode("\n", str_replace(["\r\n", "\r"], "\n", $data['channel_finance_array']));
  119. $model->whereIn('channel_finance', $array);
  120. }
  121. if(! empty($data['id'])) $model->whereIn('order_id',$data['id']);
  122. return [true, $model];
  123. }
  124. public function statisticsRevenueCostThree($data,$user){
  125. list($status, $model) = $this->statisticsRevenueCostThreeCommon($data, $user);
  126. if(! $status) return [false, $model];
  127. $list = $this->limit($model,'',$data);
  128. $list = $this->statisticsRevenueCostThreeFillData($list);
  129. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  130. return [true, $list];
  131. }
  132. public function statisticsRevenueCostThreeFillData($data){
  133. if(empty($data['data'])) return $data;
  134. foreach ($data['data'] as $key => $value){
  135. $profit_rate = $value['payment_amount'] > 0 ? bcdiv($value['profit'], $value['payment_amount'],8) : 0;
  136. $data['data'][$key]['profit_rate'] = bcmul($profit_rate, 100,2);
  137. $data['data'][$key]['order_time'] = $value['order_time'] ? date("Y-m-d", $value['order_time']) : "";
  138. }
  139. return $data;
  140. }
  141. public function statisticsRevenueCostThreeDetail($data,$user){
  142. if(empty($data['order_number'])) return [false, '回款单号不能为空'];
  143. $result = RevenueCost::where('del_time',0)
  144. ->where('order_type',RevenueCost::ORDER_THREE)
  145. ->where('order_number',$data['order_number'])
  146. ->select(RevenueCost::$field_hkd_detail)
  147. ->get()->toArray();
  148. if(empty($result)) return [false, "回款单不存在或已被删除"];
  149. $detail = [];
  150. foreach ($result as $value){
  151. $detail[] = [
  152. 'order_number' => $value['order_number_upstream'],
  153. 'customer_code' => $value['customer_code'],
  154. 'customer_title' => $value['customer_title'],
  155. 'channel_finance' => $value['channel_finance'],
  156. 'product_code' => $value['product_code'],
  157. 'product_title' => $value['product_title'],
  158. 'product_size' => $value['product_size'],
  159. 'unit' => $value['unit'],
  160. 'quantity' => $value['quantity'],
  161. 'payment_amount' => $value['payment_amount'],
  162. 'price_1' => $value['price_1'],
  163. 'price_1_total' => $value['price_1_total'],
  164. 'price_4' => $value['price_4'],
  165. 'price_4_total' => $value['price_4_total'],
  166. 'profit' => $value['profit'],
  167. 'profit_rate' => bcmul($value['profit_rate'],100,2) . '%',
  168. 'customer_profit_rate' => bcmul($value['customer_profit_rate'],100,2) . '%',
  169. 'voucher_type_title' => RevenueCost::$voucher_type[$value['voucher_type']] ?? "",
  170. ];
  171. }
  172. $footer = $this->countTotal($result, $user['header_default']);
  173. $footer['profit_rate'] = $footer['profit_rate'] . "%";
  174. $footer = array_merge( [
  175. 'order_number' => '',
  176. 'customer_code' => '',
  177. 'customer_title' => '',
  178. 'channel_finance' => '',
  179. 'product_code' => '',
  180. 'product_title' => '',
  181. 'product_size' => '',
  182. 'unit' => '',
  183. 'quantity' => '',
  184. 'payment_amount' => '',
  185. 'price_1' => '',
  186. 'price_1_total' => '',
  187. 'price_4' => '',
  188. 'price_4_total' => '',
  189. 'profit' => '',
  190. 'profit_rate' => '',
  191. 'customer_profit_rate'=> '',
  192. 'voucher_type_title' => '',
  193. ], $footer);
  194. $detail[] = $footer;
  195. $first = $result[0];
  196. $order = [
  197. 'order_number' => $data['order_number'],
  198. 'order_time' => date("Y-m-d",$first['order_time']),
  199. 'employee_id_1_title' => $first['employee_id_1_title'],
  200. 'detail' => $detail
  201. ];
  202. return [true, $order];
  203. }
  204. public function statisticsProfitCommon($data,$user, $field = []){
  205. if(empty($field)) {
  206. $field = RevenueCost::$field_hkd_profit_main;
  207. $field[] = DB::raw('COALESCE(SUM(rc.payment_amount), 0) AS payment_amount');
  208. }
  209. $type = RevenueCost::ORDER_THREE;
  210. $model = EmployeeIndex::Clear($user, $data)
  211. ->where('employee_index.del_time', 0)
  212. ->where('employee_index.type', EmployeeIndex::TYPE_THREE)
  213. ->leftJoin(DB::raw('revenue_cost as rc'), function ($join) use ($type) {
  214. $join->on('rc.employee_id_2', '=', 'employee_index.employee_id')
  215. ->where('rc.del_time', 0)
  216. ->where('rc.order_type', $type)
  217. ->whereNotNull('rc.employee_id_2')
  218. ->where('rc.employee_id_2', '<>', '')
  219. ->whereRaw('rc.order_time >= employee_index.start_time')
  220. ->whereRaw('rc.order_time <= employee_index.end_time');
  221. })
  222. ->select($field)
  223. ->groupBy('employee_index.employee_id', 'employee_index.start_time', 'employee_index.end_time')
  224. ->orderBy('employee_index.end_time', 'desc');
  225. // $type = RevenueCost::ORDER_THREE;
  226. // $model = EmployeeIndex::where('employee_index.del_time',0)
  227. // ->where('employee_index.type',EmployeeIndex::TYPE_THREE)
  228. // ->leftJoin(DB::raw('revenue_cost as rc'), function ($join) use ($type) {
  229. // $join->on('rc.employee_id_2', '=', 'employee_index.employee_id')
  230. // ->where('rc.del_time', 0)
  231. // ->where('rc.order_type', $type)
  232. // ->whereRaw('rc.order_time >= employee_index.start_time')
  233. // ->whereRaw('rc.order_time <= employee_index.end_time');
  234. // })
  235. // ->select($field)
  236. // ->groupBy('employee_index.employee_id', 'employee_index.start_time', 'employee_index.end_time')
  237. // ->orderBy('employee_index.end_time','desc');
  238. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){;
  239. list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
  240. if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
  241. $model->where('employee_index.start_time', '<=', $end_time)
  242. ->where('employee_index.end_time', '>=', $start_time);
  243. }
  244. if(! empty($data['employee_id_2_title'])) $model->where('rc.employee_id_2_title', 'LIKE', '%'.$data['employee_id_2_title'].'%');
  245. if(! empty($data['id'])) $model->whereIn('employee_index.id', $data['id']);
  246. return [true, $model];
  247. }
  248. public function statisticsProfit($data,$user){
  249. list($status, $model) = $this->statisticsProfitCommon($data, $user);
  250. if(! $status) return [false, $model];
  251. $list = $this->limit($model,'',$data);
  252. $list = $this->statisticsProfitFillData($list);
  253. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  254. return [true, $list];
  255. }
  256. public function statisticsProfitFillData($data){
  257. if(empty($data['data'])) return $data;
  258. //获取应发放金额需要的指标
  259. $indexes = $this->getEmployeeIndex($data['data']);
  260. //已发
  261. $indexes_give = $this->getEmployeeGiveOut($data['data']);
  262. foreach ($data['data'] as $key => $value){
  263. $start = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
  264. $end = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
  265. $string = "";
  266. if(! empty($start) && ! empty($end)) $string = $start . "-" . $end;
  267. $value['check_time'] = $string;
  268. $value['index_' . EmployeeIndex::TYPE_ONE] = 0;
  269. $value['index_' . EmployeeIndex::TYPE_FIVE] = 0;
  270. //指标
  271. $this->makeIndex($indexes, $value, $data['data'][$key]);
  272. //应付
  273. $this->makeShouldPay($value,$data['data'][$key]);
  274. //已付
  275. $this->makePayed($indexes_give, $value,$data['data'][$key]);
  276. //未付
  277. $not_pay = bcsub($data['data'][$key]['should_pay'], $data['data'][$key]['payed'],2);
  278. $data['data'][$key]['not_pay'] = $not_pay;
  279. }
  280. return $data;
  281. }
  282. private function getEmployeeIndex($existingData)
  283. {
  284. if (empty($existingData)) {
  285. return collect();
  286. }
  287. // 取出所有涉及的 employee_id 和时间区间
  288. $employeeIds = array_column($existingData, 'employee_id_2');
  289. $start_time = array_column($existingData, 'start_time');
  290. $minStart = ! empty($start_time) ? min($start_time) : 0;
  291. $end_time = array_column($existingData, 'end_time');
  292. $maxEnd = ! empty($end_time) ? max($end_time) : 0;
  293. // 一次性查出这些员工在最大区间范围内的所有指标
  294. $results = EmployeeIndex::where('del_time', 0)
  295. ->whereIn('type', [EmployeeIndex::TYPE_ONE, EmployeeIndex::TYPE_FIVE])
  296. ->whereIn('employee_id', $employeeIds)
  297. ->where('start_time', '<=', $maxEnd)
  298. ->where('end_time', '>=', $minStart)
  299. ->select('start_time','end_time','employee_id','index','type')
  300. ->get();
  301. return $results;
  302. }
  303. private function getEmployeeGiveOut($existingData)
  304. {
  305. if (empty($existingData)) {
  306. return collect();
  307. }
  308. // 取出所有涉及的 employee_id 和时间区间
  309. $employeeIds = array_column($existingData, 'employee_id_2');
  310. $start_time = array_column($existingData, 'start_time');
  311. $minStart = ! empty($start_time) ? min($start_time) : 0;
  312. $end_time = array_column($existingData, 'end_time');
  313. $maxEnd = ! empty($end_time) ? max($end_time) : 0;
  314. // 一次性查出这些员工在最大区间范围内的所有指标
  315. $results = GiveOut::where('del_time', 0)
  316. ->whereIn('employee_id_1', $employeeIds)
  317. ->where('start_time', '<=', $maxEnd)
  318. ->where('end_time', '>=', $minStart)
  319. ->select('start_time','end_time','employee_id_1 as employee_id','give_out_amount')
  320. ->get();
  321. return $results;
  322. }
  323. private function makeIndex($indexes, $value, &$data){
  324. // 找到所有符合条件的 index(可能多个 type)
  325. $matchedIndexes = $indexes->filter(function ($item) use ($value) {
  326. return $item['employee_id'] == $value['employee_id_2']
  327. && $item['start_time'] <= $value['end_time']
  328. && $item['end_time'] >= $value['start_time'];
  329. });
  330. // 按 type 去重,只保留第一次出现的
  331. $uniqueByType = [];
  332. foreach ($matchedIndexes as $item) {
  333. $index = "index_" . $item['type'];
  334. if (! isset($uniqueByType[$index])) {
  335. $uniqueByType[$index] = $item['index'];
  336. }
  337. }
  338. $data = array_merge($value, $uniqueByType);
  339. }
  340. private function makeShouldPay($value, &$data){
  341. $index_1 = bcdiv($data['index_1'],100,2);
  342. $index_5 = bcdiv($data['index_5'],100,2);
  343. // 分红比例/2
  344. $a = bcdiv($index_5,2,2);
  345. // 季度预支分红比例/2
  346. $b = bcdiv($index_1,2,2);
  347. //(分红比例/2-季度预支分红比例/2)
  348. $c = bcsub($a, $b,2);
  349. $data['part_left'] = $c;
  350. if($value['payment_amount'] < $value['index']){
  351. //回款金额*(分红比例/2-季度预支分红比例/2);
  352. $shouldPay = bcmul($value['payment_amount'], $c,2);
  353. }else{
  354. //回款金额-季度指标金额
  355. $d = bcsub($value['payment_amount'], $value['index'],2);
  356. //(回款金额-季度指标金额)*15%
  357. $e = bcmul($d, 0.15,2);
  358. //(回款金额-季度指标金额)*15%/2
  359. $e = bcdiv($e,2,2);
  360. //(分红比例/2-季度预支分红比例/2+(回款金额-季度指标金额)*15%/2)
  361. $rate = bcadd($c, $e,2);
  362. // $data['data'][$key]['rate'] = $rate;
  363. //回款金额*(分红比例/2-回款金额*季度预支分红比例/2+(回款金额-季度指标金额)*15%/2)
  364. $shouldPay = bcmul($value['payment_amount'], $rate,2);
  365. }
  366. $data['should_pay'] = $shouldPay;
  367. }
  368. private function makePayed($indexes, $value, &$data){
  369. $matchedIndexes_give = $indexes->filter(function ($item) use ($value) {
  370. return $item['employee_id'] == $value['employee_id_2']
  371. && $item['start_time'] <= $value['end_time']
  372. && $item['end_time'] >= $value['start_time'];
  373. });
  374. $give_out = 0;
  375. foreach ($matchedIndexes_give as $item) {
  376. $give_out = bcadd($item['give_out_amount'], $give_out,2);
  377. }
  378. $data['payed'] = $give_out;
  379. }
  380. public function statisticsEmployeeSalaryCommon($data,$user, $field = []){
  381. if(empty($field)) {
  382. $field = SalaryEmployee::$field;
  383. }
  384. $model = SalaryEmployee::Clear($user,$data);
  385. $model = $model->where('del_time',0)
  386. ->where('order_type',RevenueCost::ORDER_THREE)
  387. ->select($field)
  388. ->orderby('order_time', 'desc');
  389. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
  390. $start_time = strtotime($data['order_time'][0] . "-01");
  391. $end_time = strtotime($data['order_time'][1] . "-01");
  392. $model->where('order_time', '>=', $start_time)
  393. ->where('order_time', '<=', $end_time);
  394. }
  395. if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
  396. if(! empty($data['id'])) $model->whereIn('id', $data['id']);
  397. return [true, $model];
  398. }
  399. public function statisticsEmployeeSalary($data,$user){
  400. list($status, $model) = $this->statisticsEmployeeSalaryCommon($data, $user);
  401. if(! $status) return [false, $model];
  402. $list = $this->limit($model,'',$data);
  403. $list = $this->statisticsEmployeeSalaryFillData($list);
  404. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  405. return [true, $list];
  406. }
  407. public function statisticsEmployeeSalaryFillData($data){
  408. if(empty($data['data'])) return $data;
  409. foreach ($data['data'] as $key => $value){
  410. $order_time = $value['order_time'] ? date('Y-m',$value['order_time']) : '';
  411. $data['data'][$key]['order_time'] = $order_time;
  412. }
  413. return $data;
  414. }
  415. public function statisticsFreightFeeCommon($data,$user, $field = []){
  416. if(empty($field)) {
  417. $field = FreightFee::$field;
  418. }
  419. $model = FreightFee::Clear($user,$data);
  420. $model = $model->where('del_time',0)
  421. ->select($field)
  422. ->groupby('order_time')
  423. ->orderby('order_time', 'desc');
  424. if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
  425. list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
  426. if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
  427. $model->where('order_time', '>=', $start_time)
  428. ->where('order_time', '<=', $end_time);
  429. }
  430. if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
  431. if(! empty($data['id'])) $model->whereIn('order_time', $data['id']);
  432. return [true, $model];
  433. }
  434. public function statisticsFreightFee($data,$user){
  435. list($status, $model) = $this->statisticsFreightFeeCommon($data, $user);
  436. if(! $status) return [false, $model];
  437. $list = $this->limit($model,'',$data);
  438. $list = $this->statisticsFreightFeeFillData($list, $user,$data);
  439. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  440. return [true, $list];
  441. }
  442. public function statisticsFreightFeeFillData($data, $user, $ergs){
  443. if(empty($data['data'])) return $data;
  444. $order_time = array_column($data['data'], 'order_time');
  445. $model = FreightFee::Clear($user,$ergs);
  446. $allFees = $model->where('del_time', 0)
  447. ->whereIn('order_time', $order_time)
  448. ->get()
  449. ->toArray();
  450. $feesByDay = [];
  451. foreach ($allFees as $f) {
  452. $feesByDay[$f['order_time']][] = $f;
  453. }
  454. foreach ($data['data'] as $key => $value) {
  455. $fees = $feesByDay[$value['order_time']] ?? [];
  456. if (empty($fees)) {
  457. $data['data'][$key]['total_amount'] = 0;
  458. continue;
  459. }
  460. // 准备 time_amount(和详情逻辑一致)
  461. $time_amount = [];
  462. foreach ($fees as $f) {
  463. if ($f['business_type_id'] == FreightFee::businessTypeNormal) {
  464. $k = $f['order_time'] . $f['area_hs'];
  465. $time_amount[$k]['amount'] = isset($time_amount[$k]['amount'])
  466. ? bcadd($f['freight_amount'], $time_amount[$k]['amount'], 4)
  467. : $f['freight_amount'];
  468. $time_amount[$k]['is_use'] = $time_amount[$k]['is_use'] ?? 0;
  469. }
  470. }
  471. // 逐条算金额
  472. $valueTotal = 0;
  473. foreach ($fees as $f) {
  474. $f = $this->calculateFreightFeeRow($f, $time_amount);
  475. $valueTotal = bcadd($valueTotal, $f['total_amount'], 4);
  476. }
  477. $data['data'][$key]['total_amount'] = $valueTotal;
  478. $order_time = $value['order_time'] ? date('Y-m-d',$value['order_time']) : '';
  479. $data['data'][$key]['order_time_show'] = $order_time;
  480. $data['data'][$key]['id'] = $value['order_time'];
  481. }
  482. return $data;
  483. }
  484. public function statisticsFreightFeeDetail($data, $user)
  485. {
  486. if (empty($data['order_time'])) {
  487. return [false, '单据日期不能为空'];
  488. }
  489. $model = FreightFee::Clear($user,$data);
  490. $fee = $model->where('del_time', 0)
  491. ->where('order_time', $data['order_time'])
  492. ->get()
  493. ->toArray();
  494. if (empty($fee)) {
  495. return [false, '单据日期下暂无数据'];
  496. }
  497. // 按时间+地区聚合同一天、同地区的非退货配送费
  498. $time_amount = [];
  499. foreach ($fee as $value) {
  500. if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
  501. $key = $value['order_time'] . $value['area_hs'];
  502. $time_amount[$key]['amount'] = isset($time_amount[$key]['amount'])
  503. ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 4)
  504. : $value['freight_amount'];
  505. $time_amount[$key]['is_use'] = $time_amount[$key]['is_use'] ?? 0;
  506. }
  507. }
  508. $return = [];
  509. foreach ($fee as $value) {
  510. $value = $this->calculateFreightFeeRow($value, $time_amount);
  511. $key = $value['order_time'] . '|' . $value['area_hs'];
  512. $return[$value['business_type_id']][$key][] = $value;
  513. }
  514. $result = [];
  515. // 需要合计的字段
  516. $sumFields = ['xs', 'weight', 'freight_amount', 'js_amount', 'customer_store_zx_fee', 'jj_fee', 'dh_fee', 'total_amount'];
  517. $sumFields_map = ['weight' => 4,'freight_amount' => 4, 'js_amount' => 4,'customer_store_zx_fee' => 4, 'jj_fee' => 4, 'dh_fee' => 4, 'total_amount' => 4];
  518. // 业务类型 日期 地区 算一张表算运费
  519. foreach ($return as $g => $group) {
  520. $g_title = FreightFee::$business[$g] ?? "";
  521. foreach ($group as $key => $val) {
  522. $tmp_key = explode('|', $key);
  523. $title = $tmp_key[1] . "(" . $g_title . ")";
  524. // 计算合计
  525. $sumRow = [];
  526. foreach ($val as $key => $row) {
  527. $order_time = $row['order_time'] ? date('Y-m-d',$row['order_time']) : '';
  528. $val[$key]['order_time_show'] = $order_time;
  529. $val[$key]['is_present_show'] = $row['is_present'] ? '是' : '否';
  530. $delivery_mode_show = FreightFee::$delivery[$row['delivery_mode']] ?? "";
  531. $val[$key]['delivery_mode_show'] = $delivery_mode_show;
  532. $val[$key]['area_range_show'] = $row['area_range'] == 1 ? '1~5吨' : '5吨以上';
  533. foreach ($sumFields as $field) {
  534. $decimals = $sumFields_map[$field] ?? 2;
  535. $sumRow[$field] = isset($sumRow[$field])
  536. ? bcadd($sumRow[$field], $row[$field], $decimals)
  537. : $row[$field];
  538. }
  539. }
  540. // 末行合计行(非合计字段设为空字符串)
  541. $footer = [];
  542. foreach ($val[0] as $field => $v) {
  543. $footer[$field] = in_array($field, $sumFields) ? $sumRow[$field] : '';
  544. }
  545. $val[] = $footer;
  546. $result[] = [
  547. 'key' => $title,
  548. 'list' => $val
  549. ];
  550. }
  551. }
  552. return [true, $result];
  553. }
  554. public function statisticsFreightFeeDetailsForExport($data, $user)
  555. {
  556. if (empty($data['order_time'])) return [];
  557. $model = FreightFee::Clear($user, $data);
  558. $orderTimes = is_array($data['order_time']) ? $data['order_time'] : [$data['order_time']];
  559. $fee = $model->where('del_time', 0)
  560. ->whereIn('order_time', $orderTimes)
  561. ->get()
  562. ->toArray();
  563. // 表头定义(所有 sheet 通用)
  564. $header = [
  565. "仓库", "销货单备注", "业务类型", "销货单号", "销货日期", "客户",
  566. "客户门店装车费单价", "业务员", "送货地址", "地区华商", "存货编码", "存货名称", "箱规",
  567. "华商重量", "门店卸货费单价(华商)", "门店卸货费单价(华商)", "赠品", "货类(华商)", "运输方式",
  568. "数量", "含税单价", "含税金额", "箱数", "总重量", "运价区间", "配送费单价", "配送费金额", "结算金额",
  569. "门店卸货费", "上楼费", "加急费", "到货装卸费", "总金额"
  570. ];
  571. if (empty($fee)) {
  572. // 返回每个请求的日期都带表头(只有表头),以便导出时每个 sheet 至少有表头
  573. $resultEmpty = [];
  574. foreach ($orderTimes as $ot) {
  575. $dateKey = date('Y-m-d', $ot);
  576. $resultEmpty[$dateKey] = [
  577. 0 => $header
  578. ];
  579. }
  580. return $resultEmpty;
  581. }
  582. // 按时间+地区聚合同一天、同地区的非退货配送费(用于 calculate 逻辑)
  583. $time_amount = [];
  584. foreach ($fee as $value) {
  585. if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
  586. $key = $value['order_time'] . $value['area_hs'];
  587. $time_amount[$key]['amount'] = isset($time_amount[$key]['amount'])
  588. ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 4)
  589. : $value['freight_amount'];
  590. $time_amount[$key]['is_use'] = $time_amount[$key]['is_use'] ?? 0;
  591. }
  592. }
  593. // 先按 order_time -> business_type_id -> (order_time|area_hs) 分组收集数据行
  594. $grouped = [];
  595. foreach ($fee as $value) {
  596. $value = $this->calculateFreightFeeRow($value, $time_amount);
  597. $key = $value['order_time'] . '|' . $value['area_hs'];
  598. $grouped[$value['order_time']][$value['business_type_id']][$key][] = $value;
  599. }
  600. // 构造返回:每个日期一个 sheet(键为 YYYY-MM-DD),值为数值下标数组,0 为表头
  601. $result = [];
  602. // 需要合计的字段及小数位
  603. $sumFields = ['xs','weight', 'freight_amount', 'js_amount', 'customer_store_zx_fee', 'jj_fee', 'dh_fee', 'total_amount'];
  604. $sumFields_map = ['xs' => 0,'weight' => 4, 'freight_amount' => 4, 'js_amount' => 4, 'customer_store_zx_fee' => 4, 'jj_fee' => 4, 'dh_fee' => 4, 'total_amount' => 4];
  605. // 初始化每个传入日期,确保即使某个日期无数据也有表头
  606. foreach ($orderTimes as $ot) {
  607. $dateKey = date('Y-m-d', $ot);
  608. $result[$dateKey] = [];
  609. $result[$dateKey][] = $header; // index 0 为表头
  610. }
  611. // 填充数据
  612. foreach ($grouped as $order_time => $types) {
  613. $dateKey = date('Y-m-d', $order_time);
  614. // 若该日期未初始化(理论上不会),先初始化表头
  615. if (!isset($result[$dateKey])) {
  616. $result[$dateKey] = [];
  617. $result[$dateKey][] = $header;
  618. }
  619. foreach ($types as $business_type_id => $group) {
  620. $businessTitle = FreightFee::$business[$business_type_id] ?? '';
  621. foreach ($group as $key => $rows) {
  622. // 每个 key 对应一组明细(按 area_hs 分组)
  623. $sumRow = []; // 用于该分组的合计
  624. foreach ($rows as $row) {
  625. $date_show = $row['order_time'] ? date('Y-m-d', $row['order_time']) : "";
  626. $is_present_show = !empty($row['is_present']) ? '是' : '否';
  627. $delivery_mode_show = FreightFee::$delivery[$row['delivery_mode']] ?? "";
  628. $area_range_show = isset($row['area_range']) && $row['area_range'] == 1 ? '1~5吨' : '5吨以上';
  629. // 单行数据(按你指定的字段顺序)
  630. $line = [
  631. $row['warehouse_name'] ?? '', // 仓库
  632. $row['mark'] ?? '', // 销货单备注
  633. $row['business_type_title'] ?? '', // 业务类型
  634. $row['order_number'] ?? '', // 销货单号
  635. $date_show, // 销货日期
  636. $row['customer_title'] ?? '', // 客户
  637. $row['customer_store_price'] ?? 0, // 客户门店装车费单价
  638. $row['employee_id_1_title'] ?? '', // 业务员
  639. $row['address'] ?? '', // 送货地址
  640. $row['area_hs'] ?? '', // 地区华商
  641. $row['product_code'] ?? '', // 存货编码
  642. $row['product_title'] ?? '', // 存货名称
  643. $row['product_box_size'] ?? '', // 箱规
  644. $row['product_weight'] ?? 0, // 华商重量
  645. $row['product_store_price'] ?? 0, // 门店卸货费单价(华商)
  646. $row['product_store_price2'] ?? 0, // 到货装卸费单价(华商)
  647. $is_present_show, // 赠品
  648. $row['product_category'] ?? '', // 货类(华商)
  649. $delivery_mode_show, // 运输方式
  650. $row['quantity'] ?? 0, // 数量
  651. $row['price_3'] ?? 0, // 含税单价
  652. $row['price_3_total'] ?? 0, // 含税金额
  653. number_format($row['xs'] ?? 0), // 箱数
  654. $row['weight'] ?? 0, // 总重量
  655. $area_range_show, // 运价区间
  656. $row['freight_unit_price'] ?? 0, // 配送费单价
  657. $row['freight_amount'] ?? 0, // 配送费金额
  658. $row['js_amount'] ?? 0, // 结算金额
  659. $row['customer_store_zx_fee'] ?? 0, // 门店卸货费
  660. $row['sl_fee'] ?? 0, // 上楼费
  661. number_format($row['jj_fee'] ?? 0, 2), // 加急费
  662. $row['dh_fee'] ?? 0, // 到货装卸费
  663. $row['total_amount'] ?? 0, // 总金额
  664. ];
  665. $result[$dateKey][] = $line;
  666. // 累加合计
  667. foreach ($sumFields as $field) {
  668. $decimals = $sumFields_map[$field] ?? 2;
  669. $sumRow[$field] = isset($sumRow[$field])
  670. ? bcadd($sumRow[$field], $row[$field], $decimals)
  671. : ($row[$field] ?? 0);
  672. }
  673. }
  674. // 添加本分组合计行(合计位置与表头列对齐,其它非合计字段留空)
  675. $totalLine = [
  676. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  677. $sumRow['xs'] ?? 0,
  678. $sumRow['weight'] ?? 0,
  679. '', '',
  680. $sumRow['freight_amount'] ?? 0, // 配送费金额合计
  681. $sumRow['js_amount'] ?? 0, // 结算金额合计
  682. $sumRow['customer_store_zx_fee'] ?? 0, // 门店卸货费合计
  683. $sumRow['sl_fee'] ?? 0, // 上楼费合计
  684. $sumRow['jj_fee'] ?? 0, // 加急费合计
  685. $sumRow['dh_fee'] ?? 0, // 到货装卸费合计
  686. $sumRow['total_amount'] ?? 0, // 总金额合计
  687. ];
  688. $result[$dateKey][] = $totalLine;
  689. }
  690. }
  691. }
  692. // 确保每个日期的数组是从 0 开始的连续下标(虽然我们已经按顺序 push,但为了保险)
  693. return $result;
  694. }
  695. protected function calculateFreightFeeRow(array $value, array &$time_amount)
  696. {
  697. $key = $value['order_time'] . $value['area_hs'];
  698. $js_amount = 0;
  699. if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
  700. $tmp_total_arr = $time_amount[$key];
  701. // 判断是否使用最低运费
  702. if ($tmp_total_arr['amount'] < $value['min_freight_amount']) {
  703. if (!$time_amount[$key]['is_use']) {
  704. $js_amount = $value['min_freight_amount'];
  705. $time_amount[$key]['is_use'] = 1;
  706. }
  707. } else {
  708. $js_amount = $value['js_single_amount'];
  709. }
  710. } else {
  711. $js_amount = $value['js_single_amount'];
  712. }
  713. $value['js_amount'] = $js_amount;
  714. // 加急费
  715. $jj_fee = 0;
  716. if ($value['delivery_mode'] == FreightFee::deliveryModeRightNow) {
  717. $jj_fee = bcmul($js_amount, 0.5, 4);
  718. }
  719. $value['jj_fee'] = $jj_fee;
  720. // 总金额
  721. $total_amount = bcadd($js_amount, $value['customer_store_zx_fee'], 4);
  722. $total_amount = bcadd($total_amount, $value['sl_fee'], 4);
  723. $total_amount = bcadd($total_amount, $jj_fee, 4);
  724. $total_amount = bcadd($total_amount, $value['dh_fee'], 4);
  725. $value['total_amount'] = $total_amount;
  726. return $value;
  727. }
  728. public function statisticsItem($data, $user)
  729. {
  730. $model = $this->statisticsItemCommon($data, $user);
  731. $list = $this->limit($model,'',$data);
  732. $list = $this->statisticsItemFillData($list, $user,$data);
  733. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  734. return [true, $list];
  735. }
  736. public function statisticsItemCommon($data,$user, $field = []){
  737. $model = ItemReport::select('*')
  738. ->orderby('id', 'desc');
  739. if(! empty($data['order_time'])){
  740. $time = strtotime($data['order_time'] . "-01");
  741. $model->where('time', $time);
  742. }
  743. return $model;
  744. }
  745. public function statisticsItemFillData($data, $user, $ergs){
  746. if(empty($data['data'])) return $data;
  747. foreach ($data['data'] as $key => $value) {
  748. $time = $value['time'] ? date('Y-m',$value['time']) : '';
  749. $data['data'][$key]['time'] = $time;
  750. }
  751. return $data;
  752. }
  753. public function statisticsRoad($data, $user)
  754. {
  755. $model = $this->statisticsRoadCommon($data, $user);
  756. $list = $this->limit($model,'',$data);
  757. $list = $this->statisticsRoadFillData($list, $user,$data);
  758. $list['count'] = $this->countTotal($list['data'], $user['header_default']);
  759. return [true, $list];
  760. }
  761. public function statisticsRoadCommon($data,$user, $field = []){
  762. $model = ItemReportRoad::select('*')
  763. ->orderby('id', 'desc');
  764. if(! empty($data['order_time'])){
  765. $time = strtotime($data['order_time'] . "-01");
  766. $model->where('time', $time);
  767. }
  768. return $model;
  769. }
  770. public function statisticsRoadFillData($data, $user, $ergs){
  771. if(empty($data['data'])) return $data;
  772. foreach ($data['data'] as $key => $value) {
  773. $time = $value['time'] ? date('Y-m',$value['time']) : '';
  774. $data['data'][$key]['time'] = $time;
  775. $data['data'][$key]['type_title'] = ItemReportRoad::$order_type[$value['type']] ?? '';
  776. }
  777. return $data;
  778. }
  779. public function getChannelReport($data)
  780. {
  781. if(empty($data['order_time'])) return [false, '年月不能为空'];
  782. $yearMonth = $data['order_time'];
  783. // 1. 解析输入
  784. [$year, $month] = explode('-', $yearMonth);
  785. $year = (int)$year;
  786. $month = (int)$month;
  787. $currentMonthTs = mktime(0, 0, 0, $month, 1, $year);
  788. $yearStartTs = mktime(0, 0, 0, 1, 1, $year);
  789. // 2. 获取所有相关数据
  790. $records = DB::table('item_report')
  791. ->whereBetween('time', [$yearStartTs, $currentMonthTs])
  792. ->whereNotNull('channel_details') // 可选:排除空渠道
  793. ->get();
  794. // 3. 初始化结果容器
  795. $channels = [];
  796. foreach ($records as $record) {
  797. $channel = $record->channel_details;
  798. if (!isset($channels[$channel])) {
  799. // 初始化当月和累计
  800. $channels[$channel] = [
  801. 'monthly' => array_fill_keys($this->getAmountFieldNames(), 0),
  802. 'cumulative' => array_fill_keys($this->getAmountFieldNames(), 0),
  803. ];
  804. }
  805. // 判断是否是当月
  806. $isCurrentMonth = ($record->time == $currentMonthTs);
  807. // 累加所有字段(包括 NULL 处理)
  808. foreach ($this->getAmountFieldNames() as $field) {
  809. $value = $record->$field ?? 0;
  810. $channels[$channel]['cumulative'][$field] += $value;
  811. if ($isCurrentMonth) {
  812. $channels[$channel]['monthly'][$field] += $value;
  813. }
  814. }
  815. }
  816. // 4. 插入 amount1 和 amount2,并格式化输出
  817. $finalResult = [];
  818. foreach ($channels as $channel => $data) {
  819. $finalResult[] = [
  820. 'channel' => $channel,
  821. 'monthly' => $this->injectAmount1And2($data['monthly']),
  822. 'cumulative' => $this->injectAmount1And2($data['cumulative']),
  823. ];
  824. }
  825. return $finalResult;
  826. }
  827. private function getAmountFieldNames()
  828. {
  829. return [
  830. 'receipt_amount',
  831. 'cost',
  832. 'profit',
  833. 'settle_amount',
  834. 'gl_amount',
  835. 'wl_amount',
  836. 'ht_amount',
  837. 'zk_amount',
  838. 'cx_amount',
  839. 'tg_amount',
  840. 'cl_amount',
  841. 'kq_amount',
  842. 'zp_amount',
  843. 'gg_amount',
  844. 'kd_amount',
  845. 'xsqt_amount',
  846. 'ry_amount',
  847. 'sb_amount',
  848. 'sj_amount', // 注意:包含 sj_amount
  849. ];
  850. }
  851. private function injectAmount1And2($data)
  852. {
  853. $result = [];
  854. $expenseFields = [
  855. 'settle_amount',
  856. 'gl_amount',
  857. 'wl_amount',
  858. 'ht_amount',
  859. 'zk_amount',
  860. 'cx_amount',
  861. 'tg_amount',
  862. 'cl_amount',
  863. 'kq_amount',
  864. 'zp_amount',
  865. 'gg_amount',
  866. 'kd_amount',
  867. 'xsqt_amount',
  868. 'ry_amount',
  869. 'sb_amount',
  870. 'sj_amount', // 注意:sj_amount 要包含
  871. ];
  872. // 第一步:按顺序构建带 amount1/2 的数组
  873. foreach ($data as $key => $value) {
  874. if ($key === 'sj_amount') {
  875. $result['amount1'] = '0.00';
  876. $result['sj_amount'] = number_format($value, 2, '.', '');
  877. $result['amount2'] = '0.00';
  878. } else {
  879. $result[$key] = number_format($value, 2, '.', '');
  880. }
  881. }
  882. // 第二步:计算 total(仅 expenseFields 中的字段,从 $data 原始值取,避免字符串运算)
  883. $total = 0;
  884. foreach ($expenseFields as $field) {
  885. $val = $data[$field] ?? 0;
  886. $total += is_numeric($val) ? (float)$val : 0;
  887. }
  888. $result['total'] = number_format($total, 2, '.', '');
  889. return $result;
  890. }
  891. public function getChannelReportRoad($data)
  892. {
  893. if(empty($data['order_time'])) return [false, '年月不能为空'];
  894. $yearMonth = $data['order_time'];
  895. // 1. 解析输入
  896. [$year, $month] = explode('-', $yearMonth);
  897. $year = (int)$year;
  898. $month = (int)$month;
  899. $currentMonthTs = mktime(0, 0, 0, $month, 1, $year);
  900. $yearStartTs = mktime(0, 0, 0, 1, 1, $year);
  901. // 2. 获取所有相关数据
  902. $records = DB::table('item_report_road')
  903. ->whereBetween('time', [$yearStartTs, $currentMonthTs])
  904. ->whereNotNull('employee_title_type') //
  905. ->get();
  906. // 3. 初始化结果容器
  907. $channels = [];
  908. foreach ($records as $record) {
  909. $channel = $record->employee_title_type;
  910. if (!isset($channels[$channel])) {
  911. // 初始化当月和累计
  912. $channels[$channel] = [
  913. 'monthly' => array_fill_keys($this->getAmountFieldNames(), 0),
  914. 'cumulative' => array_fill_keys($this->getAmountFieldNames(), 0),
  915. ];
  916. }
  917. // 判断是否是当月
  918. $isCurrentMonth = ($record->time == $currentMonthTs);
  919. // 累加所有字段(包括 NULL 处理)
  920. foreach ($this->getAmountFieldNames() as $field) {
  921. $value = $record->$field ?? 0;
  922. $channels[$channel]['cumulative'][$field] += $value;
  923. if ($isCurrentMonth) {
  924. $channels[$channel]['monthly'][$field] += $value;
  925. }
  926. }
  927. }
  928. // 4. 插入 amount1 和 amount2,并格式化输出
  929. $finalResult = [];
  930. foreach ($channels as $channel => $data) {
  931. $finalResult[] = [
  932. 'channel' => $channel,
  933. 'monthly' => $this->injectAmount1And2($data['monthly']),
  934. 'cumulative' => $this->injectAmount1And2($data['cumulative']),
  935. ];
  936. }
  937. return $finalResult;
  938. }
  939. }