| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?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\Request;
- use Oursdreams\Export\Export;
- class OwnerStoreFeeReportController extends Controller
- {
- use SettlementBillTrait;
- //TODO 缺少总计费用
- /* @var OwnerStoreFeeReportService $service */
- private $service;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- /**
- * OwnerStoreFeeReportController constructor.
- */
- public function __construct()
- {
- $this->middleware('auth');
- }
- 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, $newFee, $backFee) = $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();
- $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('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', 'totalAmount', 'totalFee', 'newFee', 'backFee'));
- }
- public function confirmBill(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);
- $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, $newFee, $backFee) = $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,
- 'newFee' => $newFee,
- 'backFee' => $backFee,
- ],
- ]);
- 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, $newFee, $backFee) = $this->service->get([
- 'owner_id' => $owner_id,
- 'counting_month' => $counting_month,
- 'type' => $this->service::TYPE,
- ]);
- $json = [];
- foreach ($reports as $report) {
- $json[] = [
- $report['type'],
- $report['unit_price'],
- $report['amount'],
- $report['type'] == '新品入库' ? $newFee : $backFee,
- ];
- }
- $row = ['名称', '单价', '数量', '合计'];
- return Export::make($row, $json, "入库费合计");
- }
- }
|