領収証発行サービス
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.

84 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. foreach ($list as $row) {
  44. $csv->addLine($row->toArray());
  45. }
  46. return $csv->download($this->getDownloadFileName());
  47. }
  48. private function getHeaderLabel(): array
  49. {
  50. $headers = [
  51. '集計ID',
  52. '集計年月',
  53. '顧客コード',
  54. '顧客名',
  55. '駐車場管理コード',
  56. '駐車場名',
  57. '領収証発行依頼件数',
  58. '郵送依頼件数',
  59. 'SMS送信件数',
  60. ];
  61. return $headers;
  62. }
  63. private function getDownloadFileName()
  64. {
  65. return sprintf("利用実績_%s.csv", $this->param->summaryYyyymm);
  66. }
  67. }