領収証発行サービス
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

86 行
2.1KB

  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 PDF;
  9. class PDFDownLoadManagerHelloTechno extends PDFDownLoadManager
  10. {
  11. public function __construct(
  12. protected ReceiptIssuingOrder $order,
  13. protected ReceiptIssuingHTParkingCustomOrder $customOrder,
  14. ) {
  15. parent::__construct($order);
  16. }
  17. public function initForDownloadLetters()
  18. {
  19. $this->initialized = true;
  20. return $this;
  21. }
  22. public function initByToken(string $token)
  23. {
  24. parent::initByToken($token);
  25. $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
  26. return $this;
  27. }
  28. public function initById(string $id)
  29. {
  30. parent::initById($id);
  31. $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
  32. return $this;
  33. }
  34. /**
  35. * @param Collection<int, ReceiptIssuingOrder> $list
  36. */
  37. public function downlaodLetters(Collection $list)
  38. {
  39. $data = [];
  40. foreach ($list as $ele) {
  41. $data[] = $this->getPDFData($ele);
  42. }
  43. $pdf = PDF::loadView('pdf/receipt_letters', [
  44. 'orders' => $data
  45. ]);
  46. // はがきサイズを指定
  47. $ret = $pdf->setOption('page-height', 148)
  48. ->setOption('page-width', 100)
  49. ->setOption('encoding', 'utf-8')
  50. ->inline();
  51. return $ret;
  52. }
  53. protected function getPDFData(?ReceiptIssuingOrder $order = null)
  54. {
  55. $p = parent::getPDFData($order);
  56. if ($order !== null) {
  57. $c = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($order->id)->firstOrFail()->toArray();
  58. } else {
  59. $c = $this->customOrder->toArray();
  60. }
  61. return [
  62. ...$p,
  63. ...$c,
  64. ];
  65. }
  66. }