SettlementBillOwnerAreaFeeController.php 4.5 KB

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