OwnerStoreFeeReportController.php 4.2 KB

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