Merge pull request 'Added receiving plant name and transport name in alert mail resource page' (#140) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #140
This commit was merged in pull request #140.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Filament\Resources;
|
||||
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;
|
||||
@@ -17,6 +18,10 @@ 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;
|
||||
|
||||
class AlertMailRuleResource extends Resource
|
||||
@@ -51,6 +56,7 @@ class AlertMailRuleResource extends Resource
|
||||
'InvoiceDataReport' => 'InvoiceDataReport',
|
||||
'ProductionQuantities' => 'ProductionQuantities',
|
||||
'QualityValidation' => 'QualityValidation',
|
||||
'InvoiceTransit' => 'InvoiceTransit',
|
||||
]),
|
||||
Forms\Components\Select::make('rule_name')
|
||||
->label('Rule Name')
|
||||
@@ -61,6 +67,7 @@ class AlertMailRuleResource extends Resource
|
||||
'ProductionMail' => 'Production Mail',
|
||||
'InvoiceDataMail' => 'Invoice Data Mail',
|
||||
'QualityMail' => 'Quality Mail',
|
||||
'InvoiceTransitMail' => 'Invoice Transit Mail',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
@@ -75,29 +82,76 @@ class AlertMailRuleResource extends Resource
|
||||
'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(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
|
||||
{
|
||||
return $table
|
||||
@@ -132,6 +186,16 @@ class AlertMailRuleResource extends Resource
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->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')
|
||||
->label('TO Emails')
|
||||
->searchable()
|
||||
|
||||
Reference in New Issue
Block a user