SettlementBillOwnerAreaFeeController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  24. * SettlementBillOwnerAreaFeeController constructor.
  25. */
  26. public function __construct()
  27. {
  28. $this->middleware('auth');
  29. }
  30. public function index(Request $request)
  31. {
  32. $this->service = app('SettlementBillsAreaFeeService');
  33. $this->archiveService = app('OwnerBillReportArchiveService');
  34. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  35. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, OwnerBillReportArchive::$enums['type']['仓储费']);
  36. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  37. $owners = Owner::query()->find($permittingOwnerIds);
  38. $owner = Owner::query()->find($owner_id);
  39. $request = $this->buildRequest($request, $counting_month);
  40. return view('finance.settlementBills.areaFee.index', compact('owner', 'owners', 'areaReports', 'billReport', 'price', 'request', 'isArchived'));
  41. }
  42. /**
  43. * 确认账单
  44. * @param Request $request
  45. * @return RedirectResponse
  46. */
  47. public function confirmBill(Request $request)
  48. {
  49. $this->service = app('SettlementBillsAreaFeeService');
  50. $this->archiveService = app('OwnerBillReportArchiveService');
  51. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  52. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  53. OwnerBillReportArchive::query()->create([
  54. 'owner_bill_report_id' => $billReport->id ?? null,
  55. 'owner_id' => $owner_id,
  56. 'counting_month' => $counting_month,
  57. 'type' => $this->service::TYPE,
  58. 'archiver_id' => auth()->id(),
  59. 'archived_at' => now(),
  60. 'information' => [
  61. 'areaReports' => $areaReports,
  62. 'billReport' => $billReport,
  63. 'price' => $price,
  64. ],
  65. ]);
  66. return back()->with('success', '确认成功');
  67. }
  68. public function export(Request $request)
  69. {
  70. $this->service = app('SettlementBillsAreaFeeService');
  71. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  72. list($areaReports, $billReport, $price) = $this->service->get($owner_id, $counting_month);
  73. $json = [];
  74. foreach ($areaReports as $areaReport) {
  75. $json[] = [
  76. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  77. '平面区',
  78. $areaReport['area_on_flat'],
  79. $areaReport['accounting_area'],
  80. $price,
  81. $billReport['storage_fee'],
  82. ];
  83. $json[] = [
  84. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  85. '整托存储',
  86. $areaReport['area_on_tray'],
  87. $areaReport['accounting_area'],
  88. $price,
  89. $billReport['storage_fee'],
  90. ];
  91. $json[] = [
  92. $areaReport['owner_storage_price_model']['using_type']??$areaReport['ownerStoragePriceModel']['using_type'],
  93. '半托存储',
  94. $areaReport['area_on_half_tray'],
  95. $areaReport['accounting_area'],
  96. $price,
  97. $billReport['storage_fee'],
  98. ];
  99. }
  100. $row = ['仓库类型', '使用区域', '数量', '合计面积', '单价', '金额',];
  101. return Export::make($row, $json, "仓储费");
  102. }
  103. /**
  104. * @param Request $request
  105. * @param $counting_month
  106. * @return \Illuminate\Support\Collection|Collection
  107. */
  108. private function buildRequest(Request $request, $counting_month)
  109. {
  110. $request = $request->all();
  111. $request['year'] = Carbon::parse($counting_month)->year;
  112. $request['month'] = Carbon::parse($counting_month)->month;
  113. return collect($request);
  114. }
  115. }