OwnerStoreOutFeeReportController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Interfaces\SettlementBillControllerInterface;
  4. use App\Owner;
  5. use App\OwnerBillReport;
  6. use App\OwnerBillReportArchive;
  7. use App\OwnerStoreOutFeeReport;
  8. use App\Services\OwnerBillReportArchiveService;
  9. use App\Services\OwnerStoreOutFeeReportService;
  10. use App\Traits\SettlementBillTrait;
  11. use Illuminate\Http\RedirectResponse;
  12. use Illuminate\Http\Request;
  13. use Oursdreams\Export\Export;
  14. class OwnerStoreOutFeeReportController extends Controller implements SettlementBillControllerInterface
  15. {
  16. use SettlementBillTrait;
  17. //TODO 缺少总计费用
  18. /* @var OwnerStoreOutFeeReportService $service */
  19. private $service;
  20. /** @var $archiveService OwnerBillReportArchiveService */
  21. private $archiveService;
  22. /**
  23. * OwnerStoreOutFeeReportController constructor.
  24. */
  25. public function __construct()
  26. {
  27. $this->service = app('OwnerStoreOutFeeReportService');
  28. $this->archiveService = app('OwnerBillReportArchiveService');
  29. }
  30. public function index(Request $request)
  31. {
  32. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  33. list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
  34. 'owner_id' => $owner_id,
  35. 'counting_month' => $counting_month,
  36. 'type' => $this->service::TYPE,
  37. ]);
  38. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  39. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  40. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  41. $request = $this->buildRequest($request, $counting_month);
  42. return view('finance.settlementBills.storeOutFee.report.index',
  43. compact('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', 'work_name_fee_total', 'fee_total'));
  44. }
  45. public function confirmBill(Request $request): RedirectResponse
  46. {
  47. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  48. $billReport = OwnerBillReport::query()
  49. ->select('storage_fee', 'id')
  50. ->where('owner_id', $owner_id)
  51. ->where('counting_month', $counting_month)
  52. ->firstOr(function () {
  53. return new OwnerBillReport();
  54. });
  55. list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
  56. 'owner_id' => $owner_id,
  57. 'counting_month' => $counting_month,
  58. 'type' => $this->service::TYPE,
  59. ]);
  60. OwnerBillReportArchive::query()->create([
  61. 'owner_bill_report_id' => $billReport->id ?? null,
  62. 'owner_id' => $owner_id,
  63. 'counting_month' => $counting_month,
  64. 'type' => $this->service::TYPE,
  65. 'archiver_id' => auth()->id(),
  66. 'archived_at' => now(),
  67. 'information' => [
  68. 'reports' => $reports,
  69. 'work_name_fee_total' => $work_name_fee_total,
  70. 'fee_total' => $fee_total,
  71. ],
  72. ]);
  73. return back()->with('success', '确认成功');
  74. }
  75. public function export(Request $request)
  76. {
  77. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  78. list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
  79. 'owner_id' => $owner_id,
  80. 'counting_month' => $counting_month,
  81. 'type' => $this->service::TYPE,
  82. ]);
  83. $json = [];
  84. foreach ($reports as $report) {
  85. $fee = '';
  86. foreach ($work_name_fee_total as $item) {
  87. if ($item['work_name'] == $report['work_name']) {
  88. $fee = $item['fee'];
  89. continue;
  90. }
  91. }
  92. $json[] = [
  93. $report['work_name'],
  94. $report['step'],
  95. $report['unit_price'] . '元/' . $report['unit']['name'] ?? '',
  96. $report['amount'],
  97. $fee,
  98. ];
  99. }
  100. $row = ['作业名称', '阶梯', '单价', '数量', '合计',];
  101. return Export::make($row, $json, "出库费合计");
  102. }
  103. }