Updated alignments and added orderby query while load plant
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-10 12:45:54 +05:30
parent 6c9408663b
commit aaa9c17e66
36 changed files with 1592 additions and 1574 deletions

View File

@@ -5,155 +5,152 @@ namespace App\Filament\Resources;
use App\Filament\Exports\AlertMailRuleExporter;
use App\Filament\Imports\AlertMailRuleImporter;
use App\Filament\Resources\AlertMailRuleResource\Pages;
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
use App\Models\AlertMailRule;
use App\Models\InvoiceMaster;
use App\Models\Plant;
use Dotenv\Exception\ValidationException;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException as ValidationValidationException;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class AlertMailRuleResource extends Resource
{
protected static ?string $model = AlertMailRule::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-m-bell-alert';
protected static ?string $navigationGroup = 'Alert Mail';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant')
->label('Plant')
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->required(fn ($get) => ! $get('is_active'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
Forms\Components\Select::make('module')
->label('Module')
->required()
->options([
'InvoiceValidation' => 'InvoiceValidation',
'InvoiceDataReport' => 'InvoiceDataReport',
'ProductionQuantities' => 'ProductionQuantities',
'QualityValidation' => 'QualityValidation',
'InvoiceTransit' => 'InvoiceTransit',
]),
Forms\Components\Select::make('rule_name')
->label('Rule Name')
->options([
'InvoiceMail' => 'Invoice Mail',
'SerialInvoiceMail' => 'Serial Invoice Mail',
'MaterialInvoiceMail' => 'Material Invoice Mail',
'ProductionMail' => 'Production Mail',
'InvoiceDataMail' => 'Invoice Data Mail',
'QualityMail' => 'Quality Mail',
'InvoiceTransitMail' => 'Invoice Transit Mail',
Section::make('')
->schema([
Forms\Components\Select::make('plant')
->label('Plant')
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(fn ($get) => ! $get('is_active'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
Forms\Components\Select::make('module')
->label('Module')
->required()
->options([
'InvoiceValidation' => 'InvoiceValidation',
'InvoiceDataReport' => 'InvoiceDataReport',
'ProductionQuantities' => 'ProductionQuantities',
'QualityValidation' => 'QualityValidation',
'InvoiceTransit' => 'InvoiceTransit',
]),
Forms\Components\Select::make('rule_name')
->label('Rule Name')
->options([
'InvoiceMail' => 'Invoice Mail',
'SerialInvoiceMail' => 'Serial Invoice Mail',
'MaterialInvoiceMail' => 'Material Invoice Mail',
'ProductionMail' => 'Production Mail',
'InvoiceDataMail' => 'Invoice Data Mail',
'QualityMail' => 'Quality Mail',
'InvoiceTransitMail' => 'Invoice Transit Mail',
])
->required(),
Forms\Components\TextInput::make('email')
->label('Email')
->required(),
Forms\Components\Textarea::make('cc_emails')
->label('CC Emails'),
Forms\Components\Select::make('schedule_type')
->label('Schedule Type')
->options([
'Live' => 'Live',
'Hourly' => 'Hourly',
'Daily' => 'Daily',
]),
Forms\Components\Select::make('receiving_plant_name')
->label('Receiving Plant')
->options(
InvoiceMaster::query()
->whereNotNull('receiving_plant_name')
->select('receiving_plant_name')
->distinct()
->pluck('receiving_plant_name', 'receiving_plant_name')
)
->searchable()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('invoice_master_id', null);
}),
Forms\Components\Select::make('invoice_master_id')
->label('Transporter Name')
->options(function (callable $get) {
$recPlant = $get('receiving_plant_name');
if (! $recPlant) {
return [];
}
return InvoiceMaster::query()
->where('receiving_plant_name', $recPlant)
->whereNotNull('transport_name')
->where('transport_name', '!=', '')
->orderBy('transport_name')
->pluck('transport_name', 'id')
->toArray();
})
->searchable(),
Checkbox::make('is_active')
->label('All Plants Reports')
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
->reactive(),
// Forms\Components\Actions::make([
// Action::make('sendInvoiceData')
// ->label('Invoice Data Report')
// ->action(function ($get) {
// $plantIds = AlertMailRule::where('module', 'InvoiceDataReport')
// ->orderBy('plant')
// ->pluck('plant')
// ->toArray();
// foreach ($plantIds as $plantId) {
// Artisan::call('send:invoice-data-report', [
// 'schedule_type' => 'Daily',
// 'plant' => $plantId,
// ]);
// }
// // Notify user in Filament
// Notification::make()
// ->title('Invoice data report sent successfully!')
// ->success()
// ->send();
// }),
// ]),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->default(fn () => Filament::auth()->user()?->name),
])
->required(),
Forms\Components\TextInput::make('email')
->label('Email')
->required(),
Forms\Components\Textarea::make('cc_emails')
->label('CC Emails'),
Forms\Components\Select::make('schedule_type')
->label('Schedule Type')
->options([
'Live' => 'Live',
'Hourly' => 'Hourly',
'Daily' => 'Daily',
]),
Forms\Components\Select::make('receiving_plant_name')
->label('Receiving Plant')
->options(
InvoiceMaster::query()
->whereNotNull('receiving_plant_name')
->select('receiving_plant_name')
->distinct()
->pluck('receiving_plant_name', 'receiving_plant_name')
)
->searchable()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('invoice_master_id', null);
}),
Forms\Components\Select::make('invoice_master_id')
->label('Transporter Name')
->options(function (callable $get) {
$recPlant = $get('receiving_plant_name');
if (! $recPlant) {
return [];
}
return InvoiceMaster::query()
->where('receiving_plant_name', $recPlant)
->whereNotNull('transport_name')
->where('transport_name', '!=', '')
->orderBy('transport_name')
->pluck('transport_name', 'id')
->toArray();
})
->searchable(),
Checkbox::make('is_active')
->label('All Plants Reports')
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
->reactive(),
// Forms\Components\Actions::make([
// Action::make('sendInvoiceData')
// ->label('Invoice Data Report')
// ->action(function ($get) {
// $plantIds = AlertMailRule::where('module', 'InvoiceDataReport')
// ->orderBy('plant')
// ->pluck('plant')
// ->toArray();
// foreach ($plantIds as $plantId) {
// Artisan::call('send:invoice-data-report', [
// 'schedule_type' => 'Daily',
// 'plant' => $plantId,
// ]);
// }
// // Notify user in Filament
// Notification::make()
// ->title('Invoice data report sent successfully!')
// ->success()
// ->send();
// }),
// ]),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->default(fn () => Filament::auth()->user()?->name),
])
->columns(2),
]);
->columns(2),
]);
}
public static function table(Table $table): Table
@@ -166,6 +163,7 @@ class AlertMailRuleResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant')
@@ -178,6 +176,7 @@ class AlertMailRuleResource extends Resource
if (! $plants) {
$plants = Plant::pluck('name', 'id')->toArray();
}
return $plants[$state] ?? 'All Plants';
}),
Tables\Columns\TextColumn::make('module')
@@ -260,14 +259,14 @@ class AlertMailRuleResource extends Resource
->label('Import Alert Mail Rule')
->color('warning')
->importer(AlertMailRuleImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import alert mail rule');
}),
ExportAction::make()
->label('Export Alert Mail Rule')
->color('warning')
->exporter(AlertMailRuleExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export alert mail rule');
}),
]);