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

InvoiceResource.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Filament\Resources;
  3. use App\Filament\Resources\InvoiceResource\Pages;
  4. use App\Filament\Resources\InvoiceResource\RelationManagers;
  5. use App\Models\Setting\Currency;
  6. use Wallo\FilamentSelectify\Components\ButtonGroup;
  7. use App\Models\Document\Document;
  8. use Filament\Forms;
  9. use Filament\Resources\Form;
  10. use Filament\Resources\Resource;
  11. use Filament\Resources\Table;
  12. use Filament\Tables;
  13. use Illuminate\Database\Eloquent\Builder;
  14. use Illuminate\Database\Eloquent\SoftDeletingScope;
  15. use Illuminate\Support\Facades\Auth;
  16. class InvoiceResource extends Resource
  17. {
  18. protected static ?string $model = Document::class;
  19. protected static ?string $navigationIcon = 'heroicon-o-document-text';
  20. protected static ?string $navigationGroup = 'Sales';
  21. protected static ?string $navigationLabel = 'Invoices';
  22. protected static ?string $modelLabel = 'invoice';
  23. public static function getEloquentQuery(): Builder
  24. {
  25. return parent::getEloquentQuery()
  26. ->where('type', 'invoice');
  27. }
  28. public static function form(Form $form): Form
  29. {
  30. return $form
  31. ->schema([
  32. Forms\Components\Section::make('Billing')
  33. ->schema([
  34. Forms\Components\Grid::make(3)
  35. ->schema([
  36. Forms\Components\Select::make('contact_id')
  37. ->label('Customer')
  38. ->preload()
  39. ->placeholder('Select a customer')
  40. ->relationship('contact', 'name', static fn (Builder $query) => $query->where('type', 'customer'))
  41. ->searchable()
  42. ->required()
  43. ->createOptionForm([
  44. ButtonGroup::make('contact.entity')
  45. ->label('Entity')
  46. ->options([
  47. 'company' => 'Company',
  48. 'individual' => 'Individual',
  49. ])
  50. ->default('company')
  51. ->required(),
  52. Forms\Components\TextInput::make('contact.name')
  53. ->label('Name')
  54. ->maxLength(100)
  55. ->required(),
  56. Forms\Components\TextInput::make('contact.email')
  57. ->label('Email')
  58. ->email()
  59. ->nullable(),
  60. Forms\Components\TextInput::make('contact.phone')
  61. ->label('Phone')
  62. ->tel()
  63. ->maxLength(20),
  64. Forms\Components\Select::make('contact.currency_code')
  65. ->label('Currency')
  66. ->relationship('currency', 'name')
  67. ->preload()
  68. ->default(Currency::getDefaultCurrency())
  69. ->searchable()
  70. ->reactive()
  71. ->required(),
  72. ])->columnSpan(1),
  73. Forms\Components\Grid::make(2)
  74. ->schema([
  75. Forms\Components\DatePicker::make('document_date')
  76. ->label('Invoice Date')
  77. ->default(now())
  78. ->format('Y-m-d')
  79. ->required(),
  80. Forms\Components\DatePicker::make('due_date')
  81. ->label('Due Date')
  82. ->default(now())
  83. ->format('Y-m-d')
  84. ->required(),
  85. Forms\Components\TextInput::make('document_number')
  86. ->label('Invoice Number')
  87. ->required(),
  88. Forms\Components\TextInput::make('order_number')
  89. ->label('Order Number')
  90. ->nullable(),
  91. ])->columnSpan(2),
  92. ])->columns(3),
  93. ])->columns(3),
  94. ]);
  95. }
  96. public static function table(Table $table): Table
  97. {
  98. return $table
  99. ->columns([
  100. //
  101. ])
  102. ->filters([
  103. //
  104. ])
  105. ->actions([
  106. Tables\Actions\EditAction::make(),
  107. ])
  108. ->bulkActions([
  109. Tables\Actions\DeleteBulkAction::make(),
  110. ]);
  111. }
  112. public static function getRelations(): array
  113. {
  114. return [
  115. RelationManagers\DocumentItemsRelationManager::class,
  116. ];
  117. }
  118. public static function getPages(): array
  119. {
  120. return [
  121. 'index' => Pages\ListInvoices::route('/'),
  122. 'create' => Pages\CreateInvoice::route('/create'),
  123. 'edit' => Pages\EditInvoice::route('/{record}/edit'),
  124. ];
  125. }
  126. }