您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DocumentTotals.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use App\Enums\Accounting\AdjustmentComputation;
  4. use App\Enums\Accounting\DocumentType;
  5. use Filament\Forms\Components\Grid;
  6. use Filament\Forms\Components\Select;
  7. use Filament\Forms\Components\TextInput;
  8. use Filament\Forms\Get;
  9. class DocumentTotals extends Grid
  10. {
  11. protected string $view = 'filament.forms.components.document-totals';
  12. protected DocumentType $documentType = DocumentType::Invoice;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->schema([
  17. TextInput::make('discount_rate')
  18. ->label('Discount Rate')
  19. ->hiddenLabel()
  20. ->live()
  21. ->rate(computation: static fn (Get $get) => $get('discount_computation'), showAffix: false),
  22. Select::make('discount_computation')
  23. ->label('Discount Computation')
  24. ->hiddenLabel()
  25. ->options([
  26. 'percentage' => '%',
  27. 'fixed' => '$',
  28. ])
  29. ->default(AdjustmentComputation::Percentage)
  30. ->selectablePlaceholder(false)
  31. ->live(),
  32. ]);
  33. }
  34. public function type(DocumentType | string $type): static
  35. {
  36. if (is_string($type)) {
  37. $type = DocumentType::from($type);
  38. }
  39. $this->documentType = $type;
  40. return $this;
  41. }
  42. public function getType(): DocumentType
  43. {
  44. return $this->documentType;
  45. }
  46. }