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); $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 confirmBill(Request $request): RedirectResponse { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); $billReport = OwnerBillReport::query() ->select('storage_fee', 'id') ->where('owner_id', $owner_id) ->where('counting_month', $counting_month) ->firstOr(function () { return new OwnerBillReport(); }); list($reports, $work_name_fee_total, $fee_total) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); OwnerBillReportArchive::query()->create([ 'owner_bill_report_id' => $billReport->id ?? null, 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, 'archiver_id' => auth()->id(), 'archived_at' => now(), 'information' => [ 'reports' => $reports, 'work_name_fee_total' => $work_name_fee_total, 'fee_total' => $fee_total, ], ]); return back()->with('success', '确认成功'); } 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['name'], $data_item['step'], $data_item['unit_price'], $data_item['amount'], $work_name_fee_total_item['fee'], ]; } } $row = ['作业名称', '阶梯', '单价', '数量', '合计',]; return Export::make($row, $json, "出库费合计"); } private function buildWorkNameFeeTotal($reports, $work_name_fee_total) { $result = []; $reports_grouped = $reports->groupBy('owner_price_operation_id'); foreach ($work_name_fee_total as $work_name_fee_total_item) { $work_name_fee_total_item['data'] = $reports_grouped[$work_name_fee_total_item['id']]; $result[] = $work_name_fee_total_item; } return $result; } }