OwnerStoreFeeReportController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  20. * OwnerStoreFeeReportController constructor.
  21. */
  22. public function __construct()
  23. {
  24. $this->middleware('auth');
  25. }
  26. public function index(Request $request)
  27. {
  28. $this->service = app('OwnerStoreFeeReportService');
  29. $this->archiveService = app('OwnerBillReportArchiveService');
  30. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  31. list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([
  32. 'owner_id' => $owner_id,
  33. 'counting_month' => $counting_month,
  34. 'type' => $this->service::TYPE,
  35. ]);
  36. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  37. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  38. $this->archiveService = app('OwnerBillReportArchiveService');
  39. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  40. $request = $this->buildRequest($request, $counting_month);
  41. return view('finance.settlementBills.storeFee.report.index',
  42. compact('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', 'totalAmount', 'totalFee', 'newFee', 'backFee'));
  43. }
  44. public function confirmBill(Request $request)
  45. {
  46. $this->service = app('OwnerStoreFeeReportService');
  47. $this->archiveService = app('OwnerBillReportArchiveService');
  48. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  49. $billReport = OwnerBillReport::query()
  50. ->select('storage_fee', 'id')
  51. ->where('owner_id', $owner_id)
  52. ->where('counting_month', $counting_month)
  53. ->firstOr(function () {
  54. return new OwnerBillReport();
  55. });
  56. list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([
  57. 'owner_id' => $owner_id,
  58. 'counting_month' => $counting_month,
  59. 'type' => $this->service::TYPE,
  60. ]);
  61. OwnerBillReportArchive::query()->create([
  62. 'owner_bill_report_id' => $billReport->id ?? null,
  63. 'owner_id' => $owner_id,
  64. 'counting_month' => $counting_month,
  65. 'type' => $this->service::TYPE,
  66. 'archiver_id' => auth()->id(),
  67. 'archived_at' => now(),
  68. 'information' => [
  69. 'reports' => $reports,
  70. 'totalAmount' => $totalAmount,
  71. 'totalFee' => $totalFee,
  72. 'newFee' => $newFee,
  73. 'backFee' => $backFee,
  74. ],
  75. ]);
  76. return back()->with('success', '确认成功');
  77. }
  78. public function export(Request $request)
  79. {
  80. $this->service = app('OwnerStoreFeeReportService');
  81. $this->archiveService = app('OwnerBillReportArchiveService');
  82. list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id);
  83. list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([
  84. 'owner_id' => $owner_id,
  85. 'counting_month' => $counting_month,
  86. 'type' => $this->service::TYPE,
  87. ]);
  88. $json = [];
  89. foreach ($reports as $report) {
  90. $json[] = [
  91. $report['type'],
  92. $report['unit_price'],
  93. $report['amount'],
  94. $report['type'] == '新品入库' ? $newFee : $backFee,
  95. ];
  96. }
  97. $row = ['名称', '单价', '数量', '合计'];
  98. return Export::make($row, $json, "入库费合计");
  99. }
  100. }