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.

DocumentPreview.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. $defaults = DocumentDefault::query()
  31. ->type($this->documentType)
  32. ->first();
  33. return $defaults?->template ?? Template::Default;
  34. }
  35. }