SettlementBillPackingMaterialFeeController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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,$owner_id);
  42. return view('finance.settlementBills.packingMaterialFee.index', compact('details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived', 'total_fee'));
  43. }
  44. public function export(Request $request)
  45. {
  46. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  47. $query = $this->service->getSql($owner_id, $counting_month);
  48. if (!$request->exists('checkAllSign')) {
  49. $query->whereIn('id', explode(',', $request['data']));
  50. }
  51. $details = $query->get();
  52. $json = $this->service->buildExport($details);
  53. $row = ['采购日期', '材料名称', '材料类型', '规格', '购买数量', '单价', '总计'];
  54. return Export::make($row, $json, "包材费");
  55. }
  56. }