SettlementBillOwnerAreaFeeController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Owner;
  4. use App\OwnerBillReportArchive;
  5. use App\Services\OwnerBillReportArchiveService;
  6. use App\Services\SettlementBillsAreaFeeService;
  7. use Carbon\Carbon;
  8. use Illuminate\Http\RedirectResponse;
  9. use Illuminate\Http\Request;
  10. use Oursdreams\Export\Export;
  11. use Tightenco\Collect\Support\Collection;
  12. /**
  13. * 结算管理-结算账单-仓储费
  14. * Class SettlementBillOwnerAreaFeeController
  15. * @package App\Http\Controllers
  16. */
  17. class SettlementBillOwnerAreaFeeController extends Controller
  18. {
  19. /* @var $service SettlementBillsAreaFeeService */
  20. private $service;
  21. /** @var $archiveService OwnerBillReportArchiveService */
  22. private $archiveService;
  23. public function index(Request $request)
  24. {
  25. $this->service = app('SettlementBillsAreaFeeService');
  26. $this->archiveService = app('OwnerBillReportArchiveService');
  27. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  28. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, OwnerBillReportArchive::$enums['type']['仓储费']);
  29. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  30. $owners = Owner::query()->find($permittingOwnerIds);
  31. $owner = Owner::query()->find($owner_id);
  32. $request = $this->buildRequest($request, $counting_month);
  33. return view('finance.settlementBills.areaFee.index', compact('owner', 'owners', 'areaReports', 'billReport', 'price', 'request', 'isArchived'));
  34. }
  35. /**
  36. * 确认账单
  37. * @param Request $request
  38. * @return RedirectResponse
  39. */
  40. public function confirmBill(Request $request)
  41. {
  42. $this->service = app('SettlementBillsAreaFeeService');
  43. $this->archiveService = app('OwnerBillReportArchiveService');
  44. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  45. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  46. OwnerBillReportArchive::query()->create([
  47. 'owner_bill_report_id' => $billReport->id ?? null,
  48. 'owner_id' => $owner_id,
  49. 'counting_month' => $counting_month,
  50. 'type' => $this->service::TYPE,
  51. 'archiver_id' => auth()->id(),
  52. 'archived_at' => now(),
  53. 'information' => [
  54. 'areaReports' => $areaReports,
  55. 'billReport' => $billReport,
  56. 'price' => $price,
  57. ],
  58. ]);
  59. return back()->with('success', '确认成功');
  60. }
  61. public function export(Request $request)
  62. {
  63. $this->service = app('SettlementBillsAreaFeeService');
  64. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  65. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  66. $json = [];
  67. foreach ($areaReports as $areaReport) {
  68. $json[] = [
  69. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  70. '平面区',
  71. $areaReport['area_on_flat'],
  72. $areaReport['accounting_area'],
  73. $price,
  74. $billReport['storage_fee'],
  75. ];
  76. $json[] = [
  77. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  78. '整托存储',
  79. $areaReport['area_on_tray'],
  80. $areaReport['accounting_area'],
  81. $price,
  82. $billReport['storage_fee'],
  83. ];
  84. $json[] = [
  85. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  86. '半托存储',
  87. $areaReport['area_on_half_tray'],
  88. $areaReport['accounting_area'],
  89. $price,
  90. $billReport['storage_fee'],
  91. ];
  92. }
  93. $row = ['仓库类型', '使用区域', '数量', '合计面积', '单价', '金额',];
  94. return Export::make($row, $json, "仓储费");
  95. }
  96. /**
  97. * @param Request $request
  98. * @param $counting_month
  99. * @return \Illuminate\Support\Collection|Collection
  100. */
  101. private function buildRequest(Request $request, $counting_month)
  102. {
  103. $request = $request->all();
  104. $request['year'] = Carbon::parse($counting_month)->year;
  105. $request['month'] = Carbon::parse($counting_month)->month;
  106. return collect($request);
  107. }
  108. }