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

71 lines
1.9KB

  1. <?php
  2. namespace App\Logic\ReceiptIssuingOrder;
  3. use App\Codes\PrefCode;
  4. use App\Events\ReceiptIssuingOrder\DownloadedEvent;
  5. use App\Exceptions\AppCommonException;
  6. use App\Models\ReceiptIssuingOrder;
  7. use App\Util\DateUtil;
  8. use PDF;
  9. class PDFDownLoadManager extends ReceiptIssuingOrderManager
  10. {
  11. public function __construct(
  12. protected ReceiptIssuingOrder $order,
  13. ) {
  14. parent::__construct($order);
  15. }
  16. public function downlaodA4()
  17. {
  18. $order = $this->order;
  19. $data = $this->getPDFData();
  20. $pdf = PDF::loadView('pdf/receipt_a4', $data);
  21. // はがきサイズを指定
  22. $ret = $pdf->setPaper('A4')
  23. ->setOption('encoding', 'utf-8')
  24. ->inline();
  25. if ($order->status_receipt_download_datetime === null) {
  26. $order->status_receipt_download_datetime = DateUtil::now();
  27. // イベント登録
  28. DownloadedEvent::dispatch($this->order);
  29. }
  30. $this->save();
  31. return $ret;
  32. }
  33. public function downlaodLetter()
  34. {
  35. $data = $this->getPDFData();
  36. $pdf = PDF::loadView('pdf/receipt_letter', $data);
  37. // はがきサイズを指定
  38. $ret = $pdf->setOption('page-height', 148)
  39. ->setOption('page-width', 100)
  40. ->setOption('encoding', 'utf-8')
  41. ->inline();
  42. return $ret;
  43. }
  44. protected function getPDFData()
  45. {
  46. $o = $this->order;
  47. return [
  48. ...$this->order->toArray(),
  49. ReceiptIssuingOrder::COL_NAME_STATUS_RECEIPT_CONFIRM_DATETIME => $o->status_receipt_confirm_datetime->format('Y/m/d'),
  50. ReceiptIssuingOrder::COL_NAME_RECEIPT_USE_DATE => $o->receipt_use_date->format('Y/m/d'),
  51. ReceiptIssuingOrder::COL_NAME_RECEIPT_AMOUNT => number_format($o->receipt_amount),
  52. 'pref_name' => PrefCode::getName($o->mail_pref_code),
  53. ];
  54. }
  55. }