|
- <?php
-
- namespace App\Logic\ReceiptIssuingOrder\Custom\HelloTechno;;
-
- use App\Logic\ReceiptIssuingOrder\PDFDownLoadManager;
- use App\Models\ReceiptIssuingHTParkingCustomOrder;
- use App\Models\ReceiptIssuingOrder;
- use App\Util\DateUtil;
- use Illuminate\Database\Eloquent\Collection;
- use LogicException;
- use PDF;
-
- class PDFDownLoadManagerHelloTechno extends PDFDownLoadManager
- {
-
- public function __construct(
- protected ReceiptIssuingOrder $order,
- protected ReceiptIssuingHTParkingCustomOrder $customOrder,
- ) {
- parent::__construct($order);
- }
-
- public function initForDownloadLetters()
- {
- $this->initialized = true;
- return $this;
- }
-
- public function initByToken(string $token)
- {
- parent::initByToken($token);
-
- $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
- return $this;
- }
-
- public function initById(string $id)
- {
- parent::initById($id);
-
- $this->customOrder = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($this->order->id)->firstOrFail();
- return $this;
- }
-
- /**
- * @override
- */
- public function downlaodLetter()
- {
- if ($this->initialized === false) {
- throw new LogicException("初期化不良");
- }
-
- $data = new Collection([$this->order]);
-
- return $this->downlaodLetters($data);
- }
-
- /**
- * @param Collection<int, ReceiptIssuingOrder> $list
- */
- public function downlaodLetters(Collection $list)
- {
-
- $data = [];
- foreach ($list as $ele) {
- $data[] = $this->getPDFData($ele);
- }
-
- $pdf = PDF::loadView('pdf/receipt_letters', [
- 'orders' => $data
- ]);
-
-
- $filename = $list->count() === 1 ? $this->getFileNameLetter() : sprintf(
- "領収証はがき一括_%s.pdf",
- DateUtil::now()->format('YmdHis')
- );
- // はがきサイズを指定
- $ret = $pdf->setOption('page-height', 148)
- ->setOption('page-width', 100)
- ->setOption('margin-right', 3)
- ->setOption('encoding', 'utf-8')
- ->inline()
- ->header("Content-Disposition", sprintf('inline; filename=%s', $filename));
- return $ret;
- }
-
- protected function getPDFData(?ReceiptIssuingOrder $order = null)
- {
-
- $p = parent::getPDFData($order);
- if ($order !== null) {
- $c = ReceiptIssuingHTParkingCustomOrder::whereReceiptIssuingOrderId($order->id)->firstOrFail()->toArray();
- } else {
- $c = $this->customOrder->toArray();
- }
-
- return [
- ...$p,
- ...$c,
- ];
- }
- }
|