belongsTo(Currency::class, 'currency_code', 'code'); } public function lineItems(): MorphMany { return $this->morphMany(DocumentLineItem::class, 'documentable'); } public function hasLineItems(): bool { return $this->lineItems()->exists(); } public function hasInactiveAdjustments(): bool { return $this->lineItems->contains(function (DocumentLineItem $lineItem) { return $lineItem->adjustments->contains(function (Adjustment $adjustment) { return $adjustment->isInactive(); }); }); } public static function getPrintDocumentAction(string $action = Action::class): MountableAction { return $action::make('printPdf') ->label('Print') ->icon('heroicon-m-printer') ->action(function (self $record, Component $livewire) { $url = route('documents.print', [ 'documentType' => $record::documentType(), 'id' => $record->id, ]); $livewire->js("window.printPdf('{$url}')"); }); } abstract public static function documentType(): DocumentType; abstract public function documentNumber(): ?string; abstract public function documentDate(): ?string; abstract public function dueDate(): ?string; abstract public function referenceNumber(): ?string; abstract public function amountDue(): ?string; }