SettlementBillStorageFeeController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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,$owner_id);
  44. return view('finance.settlementBills.storageFee.index', compact('owner', 'owners', 'areaReports', 'billReport', 'request', 'isArchived'));
  45. }
  46. public function export(Request $request)
  47. {
  48. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  49. list($areaReports, $billReport) = $this->service->get([
  50. 'owner_id' => $owner_id,
  51. 'counting_month' => $counting_month,
  52. 'type' => $this->service::TYPE,
  53. ]);
  54. $json = [];
  55. foreach ($areaReports as $areaReport) {
  56. $json[] = [
  57. $areaReport['owner_storage_price_model']['using_type'] ?? $areaReport['ownerStoragePriceModel']['using_type'],
  58. '平面区',
  59. $areaReport['area_on_flat'],
  60. $areaReport['accounting_area'],
  61. $areaReport['owner_storage_price_model']['price'],
  62. $billReport['storage_fee'],
  63. ];
  64. $json[] = [
  65. $areaReport['owner_storage_price_model']['using_type'] ?? $areaReport['ownerStoragePriceModel']['using_type'],
  66. '整托存储',
  67. $areaReport['area_on_tray'],
  68. $areaReport['accounting_area'],
  69. $areaReport['owner_storage_price_model']['price'],
  70. $billReport['storage_fee'],
  71. ];
  72. $json[] = [
  73. $areaReport['owner_storage_price_model']['using_type'] ?? $areaReport['ownerStoragePriceModel']['using_type'],
  74. '半托存储',
  75. $areaReport['area_on_half_tray'],
  76. $areaReport['accounting_area'],
  77. $areaReport['owner_storage_price_model']['price'],
  78. $billReport['storage_fee'],
  79. ];
  80. }
  81. $row = ['仓库类型', '使用区域', '数量', '合计面积', '单价', '金额',];
  82. return Export::make($row, $json, "仓储费");
  83. }
  84. }