SettlementBillStorageFeeController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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) = $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. ],
  70. ]);
  71. return back()->with('success', '确认成功');
  72. }
  73. public function export(Request $request)
  74. {
  75. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  76. list($areaReports, $billReport) = $this->service->get([
  77. 'owner_id' => $owner_id,
  78. 'counting_month' => $counting_month,
  79. 'type' => $this->service::TYPE,
  80. ]);
  81. $json = [];
  82. foreach ($areaReports as $areaReport) {
  83. $json[] = [
  84. $areaReport['owner_storage_price_model']['using_type'] ?? $areaReport['ownerStoragePriceModel']['using_type'],
  85. '平面区',
  86. $areaReport['area_on_flat'],
  87. $areaReport['accounting_area'],
  88. $areaReport['owner_storage_price_model']['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_tray'],
  95. $areaReport['accounting_area'],
  96. $areaReport['owner_storage_price_model']['price'],
  97. $billReport['storage_fee'],
  98. ];
  99. $json[] = [
  100. $areaReport['owner_storage_price_model']['using_type'] ?? $areaReport['ownerStoragePriceModel']['using_type'],
  101. '半托存储',
  102. $areaReport['area_on_half_tray'],
  103. $areaReport['accounting_area'],
  104. $areaReport['owner_storage_price_model']['price'],
  105. $billReport['storage_fee'],
  106. ];
  107. }
  108. $row = ['仓库类型', '使用区域', '数量', '合计面积', '单价', '金额',];
  109. return Export::make($row, $json, "仓储费");
  110. }
  111. }