Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DocumentPreview.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Filament\Infolists\Components;
  3. use App\Enums\Accounting\DocumentType;
  4. use App\Enums\Setting\Template;
  5. use App\Models\Setting\DocumentDefault;
  6. use Filament\Infolists\Components\Grid;
  7. class DocumentPreview extends Grid
  8. {
  9. protected string $view = 'filament.infolists.components.document-preview';
  10. protected DocumentType $documentType = DocumentType::Invoice;
  11. protected function setUp(): void
  12. {
  13. parent::setUp();
  14. $this->columnSpan(3);
  15. }
  16. public function type(DocumentType | string $type): static
  17. {
  18. if (is_string($type)) {
  19. $type = DocumentType::from($type);
  20. }
  21. $this->documentType = $type;
  22. return $this;
  23. }
  24. public function getType(): DocumentType
  25. {
  26. return $this->documentType;
  27. }
  28. public function getTemplate(): Template
  29. {
  30. if ($this->documentType === DocumentType::RecurringInvoice) {
  31. $lookupType = DocumentType::Invoice;
  32. } else {
  33. $lookupType = $this->documentType;
  34. }
  35. $defaults = DocumentDefault::query()
  36. ->type($lookupType)
  37. ->first();
  38. return $defaults?->template ?? Template::Default;
  39. }
  40. }