Compare commits
2 Commits
eaefffd51b
...
650314a435
| Author | SHA1 | Date | |
|---|---|---|---|
| 650314a435 | |||
|
|
dd0d429b3a |
@@ -5,6 +5,7 @@ namespace App\Filament\Resources;
|
|||||||
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||||
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
||||||
use App\Models\AlertMailRule;
|
use App\Models\AlertMailRule;
|
||||||
|
use App\Models\InvoiceMaster;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Dotenv\Exception\ValidationException;
|
use Dotenv\Exception\ValidationException;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
@@ -17,6 +18,10 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
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 Illuminate\Validation\ValidationException as ValidationValidationException;
|
||||||
|
|
||||||
class AlertMailRuleResource extends Resource
|
class AlertMailRuleResource extends Resource
|
||||||
@@ -51,6 +56,7 @@ class AlertMailRuleResource extends Resource
|
|||||||
'InvoiceDataReport' => 'InvoiceDataReport',
|
'InvoiceDataReport' => 'InvoiceDataReport',
|
||||||
'ProductionQuantities' => 'ProductionQuantities',
|
'ProductionQuantities' => 'ProductionQuantities',
|
||||||
'QualityValidation' => 'QualityValidation',
|
'QualityValidation' => 'QualityValidation',
|
||||||
|
'InvoiceTransit' => 'InvoiceTransit',
|
||||||
]),
|
]),
|
||||||
Forms\Components\Select::make('rule_name')
|
Forms\Components\Select::make('rule_name')
|
||||||
->label('Rule Name')
|
->label('Rule Name')
|
||||||
@@ -61,6 +67,7 @@ class AlertMailRuleResource extends Resource
|
|||||||
'ProductionMail' => 'Production Mail',
|
'ProductionMail' => 'Production Mail',
|
||||||
'InvoiceDataMail' => 'Invoice Data Mail',
|
'InvoiceDataMail' => 'Invoice Data Mail',
|
||||||
'QualityMail' => 'Quality Mail',
|
'QualityMail' => 'Quality Mail',
|
||||||
|
'InvoiceTransitMail' => 'Invoice Transit Mail',
|
||||||
])
|
])
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\TextInput::make('email')
|
Forms\Components\TextInput::make('email')
|
||||||
@@ -75,29 +82,76 @@ class AlertMailRuleResource extends Resource
|
|||||||
'Hourly' => 'Hourly',
|
'Hourly' => 'Hourly',
|
||||||
'Daily' => 'Daily',
|
'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')
|
Checkbox::make('is_active')
|
||||||
->label('All Plants Reports')
|
->label('All Plants Reports')
|
||||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
|
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
|
||||||
->reactive(),
|
->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')
|
Forms\Components\Hidden::make('created_by')
|
||||||
->default(fn () => Filament::auth()->user()?->name),
|
->default(fn () => Filament::auth()->user()?->name),
|
||||||
Forms\Components\Hidden::make('updated_by')
|
Forms\Components\Hidden::make('updated_by')
|
||||||
->default(fn () => Filament::auth()->user()?->name),
|
->default(fn () => Filament::auth()->user()?->name),
|
||||||
])
|
])
|
||||||
->columns(6),
|
->columns(2),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally, also override for update/editing
|
|
||||||
// public static function mutateFormDataBeforeSave(array $data): array
|
|
||||||
// {
|
|
||||||
// dd('test');
|
|
||||||
// if ($data['is_active']) {
|
|
||||||
// $data['plant'] = 'All Plants';
|
|
||||||
// }
|
|
||||||
// return $data;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
@@ -132,6 +186,16 @@ class AlertMailRuleResource extends Resource
|
|||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('invoiceMaster.receiving_plant_name')
|
||||||
|
->label('Receiving Plant')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('invoiceMaster.transport_name')
|
||||||
|
->label('Transporter')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('email')
|
Tables\Columns\TextColumn::make('email')
|
||||||
->label('TO Emails')
|
->label('TO Emails')
|
||||||
->searchable()
|
->searchable()
|
||||||
|
|||||||
Reference in New Issue
Block a user