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

104 lines
2.7KB

  1. <?php
  2. namespace App\Logic\ReceiptIssuingOrder\Custom\HelloTechno;;
  3. use App\Logic\ReceiptIssuingOrder\PDFDownLoadManager;
  4. use App\Models\ReceiptIssuingHTParkingCustomOrder;
  5. use App\Models\ReceiptIssuingOrder;
  6. use App\Util\DateUtil;
  7. use Illuminate\Database\Eloquent\Collection;
  8. use LogicException;
  9. use PDF;
  10. class PDFDownLoadManagerHelloTechno extends PDFDownLoadManager
  11. {
  12. public function __construct(
  13. protected ReceiptIssuingOrder $order,
  14. protected ReceiptIssuingHTParkingCustomOrder $customOrder,
  15. ) {
  16. parent::__construct($order);
  17. }
  18. public function initForDownloadLetters()
  19. {
  20. $this->initialized = true;
  21. return $this;
  22. }
  23. public function initByToken(string $token)
  24. {
  25. parent::initByToken($token);
  26. $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
  27. return $this;
  28. }
  29. public function initById(string $id)
  30. {
  31. parent::initById($id);
  32. $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
  33. return $this;
  34. }
  35. /**
  36. * @override
  37. */
  38. public function downlaodLetter()
  39. {
  40. if ($this->initialized === false) {
  41. throw new LogicException("初期化不良");
  42. }
  43. $data = new Collection([$this->order]);
  44. return $this->downlaodLetters($data);
  45. }
  46. /**
  47. * @param Collection<int, ReceiptIssuingOrder> $list
  48. */
  49. public function downlaodLetters(Collection $list)
  50. {
  51. $data = [];
  52. foreach ($list as $ele) {
  53. $data[] = $this->getPDFData($ele);
  54. }
  55. $pdf = PDF::loadView('pdf/receipt_letters', [
  56. 'orders' => $data
  57. ]);
  58. $filename = $list->count() === 1 ? $this->getFileNameLetter() : sprintf(
  59. "領収証はがき一括_%s.pdf",
  60. DateUtil::now()->format('YmdHis')
  61. );
  62. // はがきサイズを指定
  63. $ret = $pdf->setOption('page-height', 148)
  64. ->setOption('page-width', 100)
  65. ->setOption('encoding', 'utf-8')
  66. ->inline()
  67. ->header("Content-Disposition", sprintf('inline; filename=%s', $filename));
  68. return $ret;
  69. }
  70. protected function getPDFData(?ReceiptIssuingOrder $order = null)
  71. {
  72. $p = parent::getPDFData($order);
  73. if ($order !== null) {
  74. $c = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($order->id)->firstOrFail()->toArray();
  75. } else {
  76. $c = $this->customOrder->toArray();
  77. }
  78. return [
  79. ...$p,
  80. ...$c,
  81. ];
  82. }
  83. }