| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?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;
- /**
- * SettlementBillStoreFeeReportController constructor.
- */
- public function __construct()
- {
- $this->service = app('OwnerStoreFeeReportService');
- $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, $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, $owner_id);
- return view('finance.settlementBills.storeFee.report.index',
- compact('owners', 'owner', 'isArchived', 'request', 'totalAmount', 'totalFee', 'owner_price_operation_fees'));
- }
- public function export(Request $request)
- {
- $this->service = app('OwnerStoreFeeReportService');
- $this->archiveService = app('OwnerBillReportArchiveService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->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('work_name', $report['work_name']);
- $json[] = [
- $report['work_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('work_name');
- foreach ($owner_price_operation_fees as $price_operation) {
- $price_operation['data'] = $reports[$price_operation['work_name']];
- $result[] = $price_operation;
- }
- return collect($result);
- }
- }
|