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