| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace App\Http\Controllers;
- use App\Interfaces\SettlementBillControllerInterface;
- use App\Owner;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerStoreFeeDetailService;
- use App\Traits\SettlementBillTrait;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Oursdreams\Export\Export;
- class OwnerStoreFeeDetailController extends Controller implements SettlementBillControllerInterface
- {
- use SettlementBillTrait;
- /** @var $service OwnerStoreFeeDetailService */
- private $service;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- public function __construct()
- {
- $this->middleware('auth');
- }
- /**
- * Display a listing of the resource.
- *
- */
- public function index(Request $request)
- {
- $this->archiveService = app('OwnerBillReportArchiveService');
- $this->service = app('OwnerStoreFeeDetailService');
- $paginateParams = $request->input();
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
- $details = $this->service->get([
- 'counting_month' => $counting_month,
- 'owner_id' => $owner_id,
- 'type' => $this->service::TYPE,
- 'paginateParams' => $paginateParams,
- ]);
- $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
- $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
- $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.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
- }
- public function export(Request $request)
- {
- $this->service = app('OwnerStoreFeeDetailService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
- $query = $this->service->getSql($counting_month, $owner_id);
- if (!$request->exists('checkAllSign')) {
- $query->whereIn('id', explode(',', $request['data']));
- }
- $details = $query->get();
- $json = $this->service->buildExport($details);
- $row = ['作业日期', '作业名称', '入库单号', '商品条码', '商品名称', '数量', '单价', '入库费'];
- return Export::make($row, $json, "入库费明细");
- }
- /**
- * 确认账单
- * @param Request $request
- * @return RedirectResponse
- */
- public function confirmBill(Request $request): RedirectResponse
- {
- $this->service = app('OwnerStoreFeeDetailService');
- $this->archiveService = app('OwnerBillReportArchiveService');
- list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
- $billReport = OwnerBillReport::query()
- ->select( 'id')
- ->where('owner_id', $owner_id)
- ->where('counting_month', $counting_month)
- ->firstOr(function () {
- return new OwnerBillReport();
- });
- 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' => [],
- ]);
- return back()->with('success', '确认成功');
- }
- }
|