領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.1KB

  1. <?php
  2. namespace App\Http\Controllers\Web\Custom\HelloTechno;
  3. use App\Codes\UserRole;
  4. use App\Features\LoginUser;
  5. use App\Files\CsvFile;
  6. use App\Http\Controllers\Web\IParam;
  7. use App\Repositories\Custom\HelloTechno\UseSummaryRepository as Repository;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  11. class UseSummaryCSVController extends HelloTechnoController
  12. {
  13. use LoginUser;
  14. public function name(): string
  15. {
  16. return "[HelloTechno専用]利用実績一覧CSV取得";
  17. }
  18. public function description(): string
  19. {
  20. return "[HelloTechno専用]利用実績の一覧CSVを取得する";
  21. }
  22. public function __construct(
  23. protected UseSummaryCSVParam $param,
  24. private Repository $repository
  25. ) {
  26. parent::__construct();
  27. $this->roleAllow(UserRole::NORMAL_ADMIN);
  28. }
  29. protected function getParam(): IParam
  30. {
  31. return $this->param;
  32. }
  33. protected function run(Request $request): BinaryFileResponse
  34. {
  35. $param = $this->param;
  36. $condition = [
  37. ...$param->toArray(),
  38. Repository::CONDITION_CONTRACT_ID => $this->loginUser()->getCurrentContractId(),
  39. Repository::CONDITION_SORT_TARGET => 'customer_code',
  40. ];
  41. $list = $this->repository->forCsv()->get($condition);
  42. // $csv = new CsvFile($this->getHeaderLabel(), CsvFile::ENCODE_SJIS);
  43. $csv = new CsvFile($this->getHeaderLabel());
  44. foreach ($list as $row) {
  45. $csv->addLine($row->toArray());
  46. }
  47. return $csv->download($this->getDownloadFileName());
  48. }
  49. private function getHeaderLabel(): array
  50. {
  51. $headers = [
  52. '集計ID',
  53. '集計年月',
  54. '顧客コード',
  55. '顧客名',
  56. '駐車場管理コード',
  57. '領収証発行依頼回数',
  58. 'SMS送信件数',
  59. ];
  60. return $headers;
  61. }
  62. private function getDownloadFileName()
  63. {
  64. return sprintf("利用実績_%s.csv", $this->param->summaryYyyymm);
  65. }
  66. }