SettlementBillPackingMaterialFeeController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Services\OwnerBillReportArchiveService;
  8. use App\Services\OwnerProcurementSettlementBillService;
  9. use App\Traits\SettlementBillTrait;
  10. use Illuminate\Http\RedirectResponse;
  11. use Illuminate\Http\Request;
  12. use Oursdreams\Export\Export;
  13. class SettlementBillPackingMaterialFeeController extends Controller implements SettlementBillControllerInterface
  14. {
  15. use SettlementBillTrait;
  16. /**php
  17. * @var $archiveService OwnerBillReportArchiveService
  18. */
  19. private $archiveService;
  20. /**
  21. * @var $service OwnerProcurementSettlementBillService
  22. */
  23. private $service;
  24. public function __construct()
  25. {
  26. $this->archiveService = app('OwnerBillReportArchiveService');
  27. $this->service = app('OwnerProcurementSettlementBillService');
  28. }
  29. public function index(Request $request)
  30. {
  31. $paginateParams = $request->input();
  32. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  33. list($details, $total_fee) = $this->service->get([
  34. 'counting_month' => $counting_month,
  35. 'owner_id' => $owner_id,
  36. 'type' => $this->service::TYPE,
  37. ]);
  38. $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
  39. $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
  40. $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
  41. $request = $this->buildRequest($request, $counting_month);
  42. return view('finance.settlementBills.packingMaterialFee.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived', 'total_fee'));
  43. }
  44. /**
  45. * @param Request $request
  46. * @return RedirectResponse
  47. */
  48. public function confirmBill(Request $request): RedirectResponse
  49. {
  50. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  51. $billReport = OwnerBillReport::query()
  52. ->select('storage_fee', 'id')
  53. ->where('owner_id', $owner_id)
  54. ->where('counting_month', $counting_month)
  55. ->firstOr(function () {
  56. return new OwnerBillReport();
  57. });
  58. list($details, $total_fee) = $this->service->get([
  59. 'owner_id' => $owner_id,
  60. 'counting_month' => $counting_month,
  61. 'type' => $this->service::TYPE,
  62. ]);
  63. OwnerBillReportArchive::query()->create([
  64. 'owner_bill_report_id' => $billReport->id ?? null,
  65. 'owner_id' => $owner_id,
  66. 'counting_month' => $counting_month,
  67. 'type' => $this->service::TYPE,
  68. 'archiver_id' => auth()->id(),
  69. 'archived_at' => now(),
  70. 'information' => [
  71. 'details' => $details,
  72. 'total_fee' => $total_fee,
  73. ],
  74. ]);
  75. return back()->with('success', '确认成功');
  76. }
  77. public function export(Request $request)
  78. {
  79. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  80. $query = $this->service->getSql($owner_id, $counting_month);
  81. if (!$request->exists('checkAllSign')) {
  82. $query->whereIn('id', explode(',', $request['data']));
  83. }
  84. $details = $query->get();
  85. $json = $this->service->buildExport($details);
  86. $row = ['采购日期', '材料名称', '材料类型', '规格', '购买数量', '单价', '总计'];
  87. return Export::make($row, $json, "包材费");
  88. }
  89. }