OwnerStoreFeeDetailController.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /**
  21. * Display a listing of the resource.
  22. *
  23. */
  24. public function index(Request $request)
  25. {
  26. $this->archiveService = app('OwnerBillReportArchiveService');
  27. $this->service = app('OwnerStoreFeeDetailService');
  28. $paginateParams = $request->input();
  29. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  30. $details = $this->service->get([
  31. 'counting_month' => $counting_month,
  32. 'owner_id' => $owner_id,
  33. 'type' => $this->service::TYPE,
  34. 'paginateParams' => $paginateParams,
  35. ]);
  36. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  37. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  38. $this->archiveService = app('OwnerBillReportArchiveService');
  39. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  40. $request = $this->buildRequest($request, $counting_month);
  41. return view('finance.settlementBills.storeFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  42. }
  43. public function export(Request $request)
  44. {
  45. $this->service = app('OwnerStoreFeeDetailService');
  46. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  47. $query = $this->service->getSql($counting_month, $owner_id);
  48. if (!$request->exists('checkAllSign')) {
  49. $query->whereIn('id', explode(',', $request['data']));
  50. }
  51. $details = $query->get();
  52. $json = $this->service->buildExport($details);
  53. $row = ['作业日期', '作业名称', '入库单号', '商品条码', '商品名称', '数量', '单价', '入库费'];
  54. return Export::make($row, $json, "入库费明细");
  55. }
  56. /**
  57. * 确认账单
  58. * @param Request $request
  59. * @return RedirectResponse
  60. */
  61. public function confirmBill(Request $request): RedirectResponse
  62. {
  63. $this->service = app('OwnerStoreFeeDetailService');
  64. $this->archiveService = app('OwnerBillReportArchiveService');
  65. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  66. $billReport = OwnerBillReport::query()
  67. ->select( 'id')
  68. ->where('owner_id', $owner_id)
  69. ->where('counting_month', $counting_month)
  70. ->firstOr(function () {
  71. return new OwnerBillReport();
  72. });
  73. OwnerBillReportArchive::query()->create([
  74. 'owner_bill_report_id' => $billReport->id ?? null,
  75. 'owner_id' => $owner_id,
  76. 'counting_month' => $counting_month,
  77. 'type' => $this->service::TYPE,
  78. 'archiver_id' => auth()->id(),
  79. 'archived_at' => now(),
  80. 'information' => [],
  81. ]);
  82. return back()->with('success', '确认成功');
  83. }
  84. }