SettlementBillStorageFeeController.php 4.5 KB

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