feat: updates
This commit is contained in:
@@ -6,7 +6,6 @@ use App\Commands\Transmittal\GenerateTransmittalSeries;
|
||||
use App\Commands\Transmittal\StoreTransmittalCommand;
|
||||
use App\Exports\TransmittalsExport;
|
||||
use App\Filament\Resources\TransmittalResource\Pages;
|
||||
use App\Filament\Resources\TransmittalResource\RelationManagers;
|
||||
use App\Jobs\ExportCompleteJob;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Client;
|
||||
@@ -23,31 +22,23 @@ use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Arr;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;
|
||||
|
||||
use YOS\FilamentExcel\Actions\Import;
|
||||
|
||||
class TransmittalResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Transmittal::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return $form
|
||||
->schema(static::getFormSchema());
|
||||
return parent::getEloquentQuery()->orderBy('id', 'desc');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -93,19 +84,74 @@ class TransmittalResource extends Resource
|
||||
Tables\Actions\BulkAction::make('Bulk Export')->action(function ($records) {
|
||||
|
||||
static::exportTransmittal(Arr::flatten($records->pluck('id')));
|
||||
})
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
public static function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
Tables\Actions\Action::make('Export')->action(fn ($record) => static::exportTransmittal([$record->id])),
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\Action::make('Update Status')
|
||||
->fillForm(function ($record) {
|
||||
return [
|
||||
'user_id' => $record->user_id,
|
||||
'date_dispatch' => $record->date_dispatch,
|
||||
'date_received' => $record->date_received,
|
||||
'received_by' => $record->received_by,
|
||||
];
|
||||
})
|
||||
->form([
|
||||
Select::make('user_id')->label('Dispatch By')
|
||||
->relationship('user', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
Datepicker::make('date_dispatch')->label('Dispatch Date')
|
||||
->native(false)->default(now()),
|
||||
TextInput::make('received_by')->label('Received By'),
|
||||
Datepicker::make('date_received')->label('Date Received')->native(false),
|
||||
])
|
||||
->action(function ($data, $record) {
|
||||
$data['id'] = $record->id;
|
||||
(new StoreTransmittalCommand)->execute($data);
|
||||
})
|
||||
->icon('heroicon-o-pencil-square')
|
||||
->slideOver()
|
||||
->hidden(! auth()->user()->can('update_transmittal')),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getFormSchema() : array
|
||||
public static function exportTransmittal(array $id): void
|
||||
{
|
||||
$recipient = auth()->user();
|
||||
|
||||
static::generateExportNotification();
|
||||
|
||||
(new TransmittalsExport([$id]))->store('public/transmittal-export.xlsx')->chain([
|
||||
app(ExportCompleteJob::class, ['user' => $recipient]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function generateExportNotification(): Notification
|
||||
{
|
||||
|
||||
return Notification::make()
|
||||
->title('Your export will be ready. check your notification for file download link.')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema(static::getFormSchema());
|
||||
}
|
||||
|
||||
public static function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Forms\Components\Select::make('client_id')
|
||||
@@ -143,65 +189,17 @@ class TransmittalResource extends Resource
|
||||
]),
|
||||
])
|
||||
->columns(3)
|
||||
->columnSpan(3)
|
||||
->columnSpan(3),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getTableActions () : array
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
Tables\Actions\Action::make('Export')->action(fn ($record) => static::exportTransmittal([$record->id])),
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\Action::make('Update Status')
|
||||
->fillForm(function($record) {
|
||||
return [
|
||||
'user_id' => $record->user_id,
|
||||
'date_dispatch' => $record->date_dispatch,
|
||||
'date_received' => $record->date_received,
|
||||
'received_by' => $record->received_by,
|
||||
];
|
||||
})
|
||||
->form([
|
||||
Select::make('user_id')->label('Dispatch By')
|
||||
->relationship('user', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
Datepicker::make('date_dispatch')->label('Dispatch Date')
|
||||
->native(false)->default(now()),
|
||||
TextInput::make('received_by')->label('Received By'),
|
||||
Datepicker::make('date_received')->label('Date Received')->native(false),
|
||||
])
|
||||
->action(function ($data, $record) {
|
||||
$data['id'] = $record->id;
|
||||
(new StoreTransmittalCommand())->execute($data);
|
||||
})
|
||||
->icon('heroicon-o-pencil-square')
|
||||
->slideOver()
|
||||
->hidden(!auth()->user()->can('update_transmittal')),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function generateExportNotification() : Notification {
|
||||
|
||||
|
||||
return Notification::make()
|
||||
->title('Your export will be ready. check your notification for file download link.')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
public static function exportTransmittal(array $id) : void {
|
||||
$recipient = auth()->user();
|
||||
|
||||
static::generateExportNotification();
|
||||
|
||||
(new TransmittalsExport([$id]))->store('public/transmittal-export.xlsx')->chain([
|
||||
app(ExportCompleteJob::class, [ 'user' => $recipient])
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user