| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Http\Controllers;
- use App\Interfaces\SettlementBillControllerInterface;
- use App\Owner;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use App\OwnerStoreOutFeeReport;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerStoreOutFeeReportService;
- use App\Traits\SettlementBillTrait;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Oursdreams\Export\Export;
- class OwnerStoreOutFeeReportController extends Controller implements SettlementBillControllerInterface
- {
- use SettlementBillTrait;
- //TODO 缺少总计费用
- /* @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);
- return view('finance.settlementBills.storeOutFee.report.index',
- compact('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', '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 = [];
- foreach ($reports as $report) {
- $fee = '';
- foreach ($work_name_fee_total as $item) {
- if ($item['work_name'] == $report['work_name']) {
- $fee = $item['fee'];
- continue;
- }
- }
- $json[] = [
- $report['work_name'],
- $report['step'],
- $report['unit_price'] . '元/' . $report['unit']['name'] ?? '',
- $report['amount'],
- $fee,
- ];
- }
- $row = ['作业名称', '阶梯', '单价', '数量', '合计',];
- return Export::make($row, $json, "出库费合计");
- }
- }
|