OwnerStoreFeeDetailController.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Interfaces\SettlementBillControllerInterface;
  4. use App\Owner;
  5. use App\OwnerBillReport;
  6. use App\OwnerBillReportArchive;
  7. use App\Services\OwnerBillReportArchiveService;
  8. use App\Services\OwnerStoreFeeDetailService;
  9. use App\Traits\SettlementBillTrait;
  10. use Illuminate\Http\RedirectResponse;
  11. use Illuminate\Http\Request;
  12. use Oursdreams\Export\Export;
  13. class OwnerStoreFeeDetailController extends Controller implements SettlementBillControllerInterface
  14. {
  15. use SettlementBillTrait;
  16. /** @var $service OwnerStoreFeeDetailService */
  17. private $service;
  18. /** @var $archiveService OwnerBillReportArchiveService */
  19. private $archiveService;
  20. public function __construct()
  21. {
  22. $this->middleware('auth');
  23. }
  24. /**
  25. * Display a listing of the resource.
  26. *
  27. */
  28. public function index(Request $request)
  29. {
  30. $this->archiveService = app('OwnerBillReportArchiveService');
  31. $this->service = app('OwnerStoreFeeDetailService');
  32. $paginateParams = $request->input();
  33. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  34. $details = $this->service->get([
  35. 'counting_month' => $counting_month,
  36. 'owner_id' => $owner_id,
  37. 'type' => $this->service::TYPE,
  38. 'paginateParams' => $paginateParams,
  39. ]);
  40. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  41. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  42. $this->archiveService = app('OwnerBillReportArchiveService');
  43. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  44. $request = $this->buildRequest($request, $counting_month);
  45. return view('finance.settlementBills.storeFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  46. }
  47. public function export(Request $request)
  48. {
  49. $this->service = app('OwnerStoreFeeDetailService');
  50. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  51. $query = $this->service->getSql($counting_month, $owner_id);
  52. if (!$request->exists('checkAllSign')) {
  53. $query->whereIn('id', explode(',', $request['data']));
  54. }
  55. $details = $query->get();
  56. $json = $this->service->buildExport($details);
  57. $row = ['作业日期', '作业名称', '入库单号', '商品条码', '商品名称', '数量', '单价', '入库费'];
  58. return Export::make($row, $json, "入库费明细");
  59. }
  60. /**
  61. * 确认账单
  62. * @param Request $request
  63. * @return RedirectResponse
  64. */
  65. public function confirmBill(Request $request): RedirectResponse
  66. {
  67. $this->service = app('OwnerStoreFeeDetailService');
  68. $this->archiveService = app('OwnerBillReportArchiveService');
  69. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  70. $billReport = OwnerBillReport::query()
  71. ->select( 'id')
  72. ->where('owner_id', $owner_id)
  73. ->where('counting_month', $counting_month)
  74. ->firstOr(function () {
  75. return new OwnerBillReport();
  76. });
  77. OwnerBillReportArchive::query()->create([
  78. 'owner_bill_report_id' => $billReport->id ?? null,
  79. 'owner_id' => $owner_id,
  80. 'counting_month' => $counting_month,
  81. 'type' => $this->service::TYPE,
  82. 'archiver_id' => auth()->id(),
  83. 'archived_at' => now(),
  84. 'information' => [],
  85. ]);
  86. return back()->with('success', '确认成功');
  87. }
  88. }