| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Http\Controllers;
- use App\Interfaces\SettlementBillControllerInterface;
- use App\Owner;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerStoreOutFeeReportService;
- use App\Traits\SettlementBillTrait;
- use Illuminate\Http\Request;
- use Oursdreams\Export\Export;
- class SettlementBillStoreOutFeeReportController extends Controller implements SettlementBillControllerInterface
- {
- use SettlementBillTrait;
- /* @var OwnerStoreOutFeeReportService $service */
- private $service;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- /**
- * OwnerStoreOutFeeReportController constructor.
- */
- public function __construct()
- {
- $this->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;
- }
- }
|