選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DocumentPreview.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Closure;
  7. use Filament\Infolists\Components\Grid;
  8. class DocumentPreview extends Grid
  9. {
  10. protected string $view = 'filament.infolists.components.document-preview';
  11. protected DocumentType $documentType = DocumentType::Invoice;
  12. protected bool | Closure $isPreview = false;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->columnSpan(3);
  17. }
  18. public function type(DocumentType | string $type): static
  19. {
  20. if (is_string($type)) {
  21. $type = DocumentType::from($type);
  22. }
  23. $this->documentType = $type;
  24. return $this;
  25. }
  26. public function preview(bool | Closure $condition = true): static
  27. {
  28. $this->isPreview = $condition;
  29. return $this;
  30. }
  31. public function getType(): DocumentType
  32. {
  33. return $this->documentType;
  34. }
  35. public function isPreview(): bool
  36. {
  37. return (bool) $this->evaluate($this->isPreview);
  38. }
  39. public function getTemplate(): Template
  40. {
  41. if ($this->documentType === DocumentType::RecurringInvoice) {
  42. $lookupType = DocumentType::Invoice;
  43. } else {
  44. $lookupType = $this->documentType;
  45. }
  46. $defaults = DocumentDefault::query()
  47. ->type($lookupType)
  48. ->first();
  49. return $defaults?->template ?? Template::Default;
  50. }
  51. }