| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Http\Controllers;
- use App\Owner;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerStoreFeeReportService;
- use App\Traits\SettlementBillTrait;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Oursdreams\Export\Export;
- use Tightenco\Collect\Support\Collection;
- class SettlementBillStoreFeeReportController extends Controller
- {
- use SettlementBillTrait;
- /* @var OwnerStoreFeeReportService $service */
- private $service;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- public function index(Request $request)
- {
- $this->service = app('OwnerStoreFeeReportService');
- $this->archiveService = app('OwnerBillReportArchiveService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
- list($reports, $totalAmount, $totalFee, $owner_price_operation_fees) = $this->service->get([
- 'owner_id' => $owner_id,
- 'counting_month' => $counting_month,
- 'type' => $this->service::TYPE,
- ]);
- $owner_price_operation_fees = $this->buildOwnerPriceOperationFees($reports, $owner_price_operation_fees);
- $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
- $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
- $this->archiveService = app('OwnerBillReportArchiveService');
- $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
- $request = $this->buildRequest($request, $counting_month);
- return view('finance.settlementBills.storeFee.report.index',
- compact('owners', 'owner', 'isArchived', 'request', 'reports', 'totalAmount', 'totalFee', 'owner_price_operation_fees'));
- }
- public function confirmBill(Request $request): RedirectResponse
- {
- $this->service = app('OwnerStoreFeeReportService');
- $this->archiveService = app('OwnerBillReportArchiveService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->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, $totalAmount, $totalFee, $owner_price_operation_fees) = $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,
- 'totalAmount' => $totalAmount,
- 'totalFee' => $totalFee,
- 'owner_price_operation_fees' => $owner_price_operation_fees
- ],
- ]);
- return back()->with('success', '确认成功');
- }
- public function export(Request $request)
- {
- $this->service = app('OwnerStoreFeeReportService');
- $this->archiveService = app('OwnerBillReportArchiveService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
- list($reports, $totalAmount, $totalFee, $owner_price_operation_fees) = $this->service->get([
- 'owner_id' => $owner_id,
- 'counting_month' => $counting_month,
- 'type' => $this->service::TYPE,
- ]);
- $json = [];
- foreach ($reports as $report) {
- $operation = $owner_price_operation_fees->firstWhere('owner_price_operation_id',$report['owner_price_operation_id']);
- $json[] = [
- $operation['owner_price_operation']['name']??$operation['ownerPriceOperation']['name'],
- $report['unit_price'],
- $report['amount'],
- $operation['fee'],
- ];
- }
- $row = ['名称', '单价', '数量', '合计'];
- return Export::make($row, $json, "入库费合计");
- }
- /**
- * @param $reports
- * @param $owner_price_operation_fees
- * @return \Illuminate\Support\Collection|Collection
- */
- private function buildOwnerPriceOperationFees($reports, $owner_price_operation_fees)
- {
- $result = [];
- $reports = $reports->groupBy('owner_price_operation_id');
- foreach ($owner_price_operation_fees as $price_operation) {
- $price_operation['data'] = $reports[$price_operation['owner_price_operation_id']];
- $result[] = $price_operation;
- }
- return collect($result);
- }
- }
|