|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
|
|
|
|
use App\Filament\Resources\InvoiceResource\Pages;
|
|
|
|
use App\Filament\Resources\InvoiceResource\RelationManagers\OrdersRelationManager;
|
|
|
|
use App\Filament\Resources\InvoiceResource\RelationManagers\ProductServicesRelationManager;
|
|
|
|
use App\Models\Customer;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use Filament\Forms\Components\DatePicker;
|
|
|
|
use Filament\Forms\Components\Grid;
|
|
|
|
use Filament\Forms\Components\Section;
|
|
|
|
use Filament\Forms\Components\Select;
|
|
|
|
use Filament\Forms\Components\Split;
|
|
|
|
use Filament\Forms\Components\ToggleButtons;
|
|
|
|
use Filament\Forms\Form;
|
|
|
|
use Filament\Resources\Resource;
|
|
|
|
use Filament\Tables;
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
|
|
|
class InvoiceResource extends Resource
|
|
|
|
{
|
|
|
|
protected static ?string $model = Invoice::class;
|
|
|
|
|
|
|
|
protected static ?string $navigationIcon = 'lucide-receipt-text';
|
|
|
|
|
|
|
|
protected static ?string $navigationGroup = 'Production';
|
|
|
|
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
|
|
|
|
public static function form(Form $form): Form
|
|
|
|
{
|
|
|
|
return $form
|
|
|
|
->schema([
|
|
|
|
Section::make([
|
|
|
|
Grid::make(2)
|
|
|
|
->schema([
|
|
|
|
Select::make('customer_id')
|
|
|
|
->required()
|
|
|
|
->label('Customer')
|
|
|
|
->options(Customer::all()->pluck('company_name', 'id'))
|
|
|
|
->reactive()
|
|
|
|
->searchable()
|
|
|
|
->columnSpan(2),
|
|
|
|
|
|
|
|
Split::make([
|
|
|
|
DatePicker::make('date')
|
|
|
|
->required()
|
|
|
|
->default(today()),
|
|
|
|
DatePicker::make('due_date'),
|
|
|
|
])
|
|
|
|
->columnSpan(2),
|
|
|
|
])->columnSpan(2),
|
|
|
|
|
|
|
|
Grid::make(1)
|
|
|
|
->schema([
|
|
|
|
ToggleButtons::make('gst')
|
|
|
|
->boolean()
|
|
|
|
->default(true)
|
|
|
|
->inline()
|
|
|
|
->colors([
|
|
|
|
'true' => 'info',
|
|
|
|
'false' => 'info',
|
|
|
|
]),
|
|
|
|
|
|
|
|
ToggleButtons::make('pst')
|
|
|
|
->boolean()
|
|
|
|
->default(false)
|
|
|
|
->inline()
|
|
|
|
->colors([
|
|
|
|
'true' => 'info',
|
|
|
|
'false' => 'info',
|
|
|
|
]),
|
|
|
|
])->columnSpan(1),
|
|
|
|
])
|
|
|
|
->columns(3)
|
|
|
|
->columnSpan(3),
|
|
|
|
])->columns(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function table(Table $table): Table
|
|
|
|
{
|
|
|
|
return $table
|
|
|
|
->columns([
|
|
|
|
Tables\Columns\TextColumn::make('internal_id')
|
|
|
|
->label('ID')
|
|
|
|
->color('primary'),
|
|
|
|
Tables\Columns\TextColumn::make('customer.company_name'),
|
|
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
|
|
->date(),
|
|
|
|
Tables\Columns\TextColumn::make('gst_amount')
|
|
|
|
->label('GST')
|
|
|
|
->prefix('$'),
|
|
|
|
Tables\Columns\TextColumn::make('pst_amount')
|
|
|
|
->label('PST')
|
|
|
|
->prefix('$'),
|
|
|
|
Tables\Columns\TextColumn::make('subtotal')
|
|
|
|
->prefix('$'),
|
|
|
|
Tables\Columns\TextColumn::make('total')
|
|
|
|
->prefix('$'),
|
|
|
|
])
|
|
|
|
->filters([
|
|
|
|
//
|
|
|
|
])
|
|
|
|
->defaultSort('created_at', 'desc')
|
|
|
|
->actions([
|
|
|
|
Tables\Actions\EditAction::make(),
|
|
|
|
])
|
|
|
|
->bulkActions([
|
|
|
|
Tables\Actions\BulkActionGroup::make([
|
|
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getRelations(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
OrdersRelationManager::class,
|
|
|
|
ProductServicesRelationManager::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'index' => Pages\ListInvoices::route('/'),
|
|
|
|
'create' => Pages\CreateInvoice::route('/create'),
|
|
|
|
'edit' => Pages\EditInvoice::route('/{record}/edit'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|