OwnerSundryFeeDetailSettlementBillController.php 4.0 KB

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