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 $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, ]; } }