OwnerSundryFeeDetailSettlementBillController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\OwnerSundryFeeDetailService;
  9. use App\Traits\SettlementBillTrait;
  10. use Illuminate\Http\RedirectResponse;
  11. use Illuminate\Http\Request;
  12. use Oursdreams\Export\Export;
  13. class OwnerSundryFeeDetailSettlementBillController extends Controller implements SettlementBillControllerInterface
  14. {
  15. use SettlementBillTrait;
  16. /** @var OwnerBillReportArchiveService $archiveService */
  17. private $archiveService;
  18. /** @var OwnerSundryFeeDetailService $service */
  19. private $service;
  20. /**
  21. * OwnerSundryFeeDetailSettlementBillController constructor.
  22. */
  23. public function __construct()
  24. {
  25. $this->archiveService = app('OwnerBillReportArchiveService');
  26. $this->service = app('OwnerSundryFeeDetailService');
  27. $this->middleware('auth');
  28. }
  29. public function index(Request $request)
  30. {
  31. $paginateParams = $request->input();
  32. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  33. $owner_sundry_fee_details = $this->service->get([
  34. 'counting_month' => $counting_month,
  35. 'owner_id' => $owner_id,
  36. 'paginateParams' => $paginateParams,
  37. ]);
  38. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  39. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  40. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  41. $request = $this->buildRequest($request, $counting_month);
  42. return view('finance.settlementBills.ownerSundryFee.index', compact('owner_sundry_fee_details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  43. }
  44. /**
  45. * @param Request $request
  46. * @return RedirectResponse
  47. */
  48. public function confirmBill(Request $request): RedirectResponse
  49. {
  50. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  51. $billReport = OwnerBillReport::query()
  52. ->select('id')
  53. ->where('owner_id', $owner_id)
  54. ->where('counting_month', $counting_month)
  55. ->firstOr(function () {
  56. return new OwnerBillReport();
  57. });
  58. OwnerBillReportArchive::query()->create([
  59. 'owner_bill_report_id' => $billReport->id ?? null,
  60. 'owner_id' => $owner_id,
  61. 'counting_month' => $counting_month,
  62. 'type' => $this->service::TYPE,
  63. 'archiver_id' => auth()->id(),
  64. 'archived_at' => now(),
  65. 'information' => [],
  66. ]);
  67. return back()->with('success', '确认成功');
  68. }
  69. public function export(Request $request)
  70. {
  71. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  72. $query = $this->service->getSql($owner_id, $counting_month);
  73. if (!$request->exists('checkAllSign')) {
  74. $query->whereIn('id', explode(',', $request['data']));
  75. }
  76. $details = $query->get();
  77. $row = ['货主', '日期', '作业类型', '费用描述', '快递单号', '承运商', '数量', '单价', '收费金额', '备注'];
  78. $json = [];
  79. foreach ($details as $detail) {
  80. $json[] = [
  81. $detail->owner->name ?? '',
  82. $detail->created_at ?? '',
  83. $detail->type ?? '',
  84. $detail->fee_explain ?? '',
  85. $detail->logistic_name ?? '',
  86. $detail->logistic->name ?? '',
  87. $detail->amount ?? '',
  88. $detail->price ?? '',
  89. $detail->fee ?? '',
  90. $detail->remark ?? '',
  91. ];
  92. }
  93. return Export::make($row, $json, "杂项费");
  94. }
  95. }