service = app('OwnerStoreOutFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); } public function index(Request $request) { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $work_name_fee_total, $fee_total) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $owner = Owner::query()->selectRaw("name,id")->find($owner_id); $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get(); $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE); $request = $this->buildRequest($request, $counting_month, $owner_id); $work_name_fee_total = collect($this->buildWorkNameFeeTotal($reports, $work_name_fee_total)); return view('finance.settlementBills.storeOutFee.report.index', compact('owners', 'owner', 'isArchived', 'request', 'work_name_fee_total', 'fee_total')); } public function export(Request $request) { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $work_name_fee_total, $fee_total) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $json = []; $work_name_fee_total = collect($this->buildWorkNameFeeTotal($reports, $work_name_fee_total)); foreach ($work_name_fee_total as $work_name_fee_total_item) { foreach ($work_name_fee_total_item['data'] as $data_item) { $json[] = [ $work_name_fee_total_item['work_name'], $data_item['step'], $data_item['unit_price'] . '/' . $data_item['unit']['name'] ?? '', $data_item['amount'], $work_name_fee_total_item['fee'], ]; } } $row = ['作业名称', '阶梯', '单价', '数量', '合计',]; return Export::make($row, $json, "出库费合计"); } private function buildWorkNameFeeTotal($reports, $work_name_fee_total): array { $result = []; $reports_grouped = $reports->groupBy('work_name'); foreach ($work_name_fee_total as $work_name_fee_total_item) { $work_name_fee_total_item['data'] = $reports_grouped[$work_name_fee_total_item['work_name']] ?? []; $result[] = $work_name_fee_total_item; } return $result; } }