SettlementBillSundryFeeController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 SettlementBillSundryFeeController 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,$owner_id);
  41. return view('finance.settlementBills.sundryFee.index', compact('owner_sundry_fee_details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived'));
  42. }
  43. public function export(Request $request)
  44. {
  45. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  46. $query = $this->service->getSql($owner_id, $counting_month);
  47. if (!$request->exists('checkAllSign')) {
  48. $query->whereIn('id', explode(',', $request['data']));
  49. }
  50. $details = $query->get();
  51. $row = ['货主', '日期', '作业类型', '费用描述', '快递单号', '承运商', '数量', '单价', '收费金额', '备注'];
  52. $json = [];
  53. foreach ($details as $detail) {
  54. $json[] = [
  55. $detail->owner->name ?? '',
  56. $detail->created_at ?? '',
  57. $detail->type ?? '',
  58. $detail->fee_explain ?? '',
  59. $detail->logistic_name ?? '',
  60. $detail->logistic->name ?? '',
  61. $detail->amount ?? '',
  62. $detail->price ?? '',
  63. $detail->fee ?? '',
  64. $detail->remark ?? '',
  65. ];
  66. }
  67. return Export::make($row, $json, "杂项费");
  68. }
  69. }