Added part validation mail trigger logic and image uploading

This commit is contained in:
dhanabalan
2025-11-24 09:12:56 +05:30
parent be5b7751a1
commit d5738a381d

View File

@@ -6,6 +6,8 @@ use App\Filament\Exports\QualityValidationExporter;
use App\Filament\Imports\QualityValidationImporter; use App\Filament\Imports\QualityValidationImporter;
use App\Filament\Resources\QualityValidationResource\Pages; use App\Filament\Resources\QualityValidationResource\Pages;
use App\Filament\Resources\QualityValidationResource\RelationManagers; use App\Filament\Resources\QualityValidationResource\RelationManagers;
use App\Mail\InvalidQualityMail;
use App\Models\AlertMailRule;
use App\Models\Item; use App\Models\Item;
use App\Models\Line; use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
@@ -32,7 +34,9 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Notification; use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Mail;
use Storage;
class QualityValidationResource extends Resource class QualityValidationResource extends Resource
{ {
@@ -42,10 +46,12 @@ class QualityValidationResource extends Resource
protected static ?string $navigationGroup = 'Display'; protected static ?string $navigationGroup = 'Display';
public $isSubmitted = false; public $isSubmitted = false;
public $data = [];
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
return $form return $form
->statePath('data')
->schema(components: [ ->schema(components: [
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->relationship('plant', 'name') ->relationship('plant', 'name')
@@ -59,12 +65,18 @@ class QualityValidationResource extends Resource
$set('line_id', null); $set('line_id', null);
$set('production_order', null); $set('production_order', null);
$set('part_validation_type_options', []);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('validation1_image_url', null);
$set('plant', $state); $set('plant', $state);
$pId = $get('plant_id'); $pId = $get('plant_id');
if (!$pId) { if (!$pId) {
$set('pqPlantError', 'Please select a plant first.'); $set('pqPlantError', 'Please select a plant first.');
} else { }
else {
$set('pqPlantError', null); $set('pqPlantError', null);
} }
@@ -172,6 +184,28 @@ class QualityValidationResource extends Resource
Forms\Components\Hidden::make('sap_msg_description') Forms\Components\Hidden::make('sap_msg_description')
->default(null), ->default(null),
// Forms\Components\TextInput::make('name')
// ->required()
// ->autofocus()
// ->live(debounce: 600)
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('email', $state . '@cripumps.com');
// })
// ->maxLength(255),
// Forms\Components\TextInput::make('email')
// // ->email()
// ->unique(ignoreRecord: true)
// ->required()
// ->readOnly()
// // ->rule(function (callable $get) {
// // return Rule::unique('users', 'email')
// // ->ignore($get('id')); // Ignore current record during updates
// // })
// // ->dehydrated()
// //->prefix(fn ($get) => $get('name') ?? null)
// // ->suffix('@cripumps.com')
// ->maxLength(255),
Forms\Components\TextInput::make('item_id') Forms\Components\TextInput::make('item_id')
->label('Item Code') ->label('Item Code')
->placeholder('Scan the valid QR code') ->placeholder('Scan the valid QR code')
@@ -182,6 +216,10 @@ class QualityValidationResource extends Resource
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$pId = $get('line_id'); $pId = $get('line_id');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('validation1_image_url', null);
if (!$pId) { if (!$pId) {
$set('pqLineError', 'Please select a line.'); $set('pqLineError', 'Please select a line.');
} else { } else {
@@ -193,6 +231,9 @@ class QualityValidationResource extends Resource
{ {
$set('prodOrdError', "Production Order can't be empty."); $set('prodOrdError', "Production Order can't be empty.");
$set('production_order', null); $set('production_order', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('validation1_image_url', null);
} }
else else
{ {
@@ -230,6 +271,10 @@ class QualityValidationResource extends Resource
// // Check if QR format contains '|' // // Check if QR format contains '|'
if (strpos($state, '|') == false) { if (strpos($state, '|') == false) {
$set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number)'); $set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number)');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
@@ -249,18 +294,34 @@ class QualityValidationResource extends Resource
if (!ctype_alnum($iCode)) { if (!ctype_alnum($iCode)) {
$set('validationError', 'Item code must contain alpha-numeric values.'); $set('validationError', 'Item code must contain alpha-numeric values.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if (strlen($iCode) < 6) { else if (strlen($iCode) < 6) {
$set('validationError', 'Item code must be at least 6 digits.'); $set('validationError', 'Item code must be at least 6 digits.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if (!ctype_alnum($sNumber)) { else if (!ctype_alnum($sNumber)) {
$set('validationError', 'Serial Number must contain alpha-numeric values.'); $set('validationError', 'Serial Number must contain alpha-numeric values.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if (strlen($sNumber) < 9) { else if (strlen($sNumber) < 9) {
$set('validationError', 'Serial Number must be at least 9 digits.'); $set('validationError', 'Serial Number must be at least 9 digits.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
// } // }
@@ -284,11 +345,19 @@ class QualityValidationResource extends Resource
if (strlen($itemCode) < 6) { if (strlen($itemCode) < 6) {
$set('validationError', 'Item code must be at least 6 digits.'); $set('validationError', 'Item code must be at least 6 digits.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if (!ctype_alnum($itemCode)) { else if (!ctype_alnum($itemCode)) {
$set('validationError', 'Item Code should contain alpha-numeric values.'); $set('validationError', 'Item Code should contain alpha-numeric values.');
$set('item_id', null); $set('item_id', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if ($serialNumber == '') { else if ($serialNumber == '') {
@@ -297,11 +366,19 @@ class QualityValidationResource extends Resource
} }
else if (strlen($serialNumber) < 9) { else if (strlen($serialNumber) < 9) {
$set('validationError', 'Serial Number must be at least 9 digits.'); $set('validationError', 'Serial Number must be at least 9 digits.');
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else if (!ctype_alnum($serialNumber)) { else if (!ctype_alnum($serialNumber)) {
$set('validationError', 'Serial Number should contain alpha-numeric values.'); $set('validationError', 'Serial Number should contain alpha-numeric values.');
$set('item_id', null); $set('item_id', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else else
@@ -314,6 +391,10 @@ class QualityValidationResource extends Resource
if (!$plantId) { if (!$plantId) {
$set('validationError', 'Please select a plant first.'); $set('validationError', 'Please select a plant first.');
$set('item_id', null); $set('item_id', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
// Check if the item exists for the selected plant // Check if the item exists for the selected plant
@@ -327,6 +408,10 @@ class QualityValidationResource extends Resource
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('uom', null); $set('uom', null);
$set('serial_number', null); $set('serial_number', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
else else
@@ -336,6 +421,9 @@ class QualityValidationResource extends Resource
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('uom', null); $set('uom', null);
$set('serial_number', null); $set('serial_number', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('validation1_image_url', null);
return; return;
} }
else if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) else if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
@@ -345,6 +433,10 @@ class QualityValidationResource extends Resource
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('uom', null); $set('uom', null);
$set('serial_number', null); $set('serial_number', null);
$set('part_validation_type', null);
$set('show_validation_image', false);
$set('part_validation_type_options', []);
$set('validation1_image_url', null);
return; return;
} }
@@ -442,18 +534,260 @@ class QualityValidationResource extends Resource
} }
$set('serial_number', $serialNumber); $set('serial_number', $serialNumber);
}) // Find item based on scanned code
$item = Item::where('code', $itemCode)
->where('plant_id', $plantId)->first();
if (!$item) {
$set('part_validation_type_options', []);
return;
}
// Find sticker master
$sticker = StickerMaster::where('plant_id', $plantId)
->where('item_id', $item->id)
->first();
if (!$sticker) {
$set('part_validation_type_options', []);
return;
}
// Build dynamic options
$options = [];
if (!empty($sticker->part_validation1)) {
$options['part_validation1'] = 'Part Validation 1';
}
if (!empty($sticker->part_validation2)) {
$options['part_validation2'] = 'Part Validation 2';
}
if (!empty($sticker->part_validation3)) {
$options['part_validation3'] = 'Part Validation 3';
}
if (!empty($sticker->part_validation4)) {
$options['part_validation4'] = 'Part Validation 4';
}
// Save options in hidden field
$set('part_validation_type_options', $options);
})
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('validationError') ? 'border-red-500' : '', 'class' => $get('validationError') ? 'border-red-500' : '',
]) ])
->extraAttributes([ ->extraAttributes([
'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); return false; }", 'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); return false; }",
]) ])
->hint(fn ($get) => $get('validationError') ? $get('validationError') : null) ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
->hintColor('danger'), ->hintColor('danger'),
// Forms\Components\Select::make('part_validation_type')
// ->reactive()
// ->label('Select Validation')
// ->options(function (callable $get) {
// $plantId = $get('plant_id');
// $itemId = $get('item_id');
// if (!$plantId || !$itemId) {
// return [];
// }
// $sticker = StickerMaster::where('plant_id', $plantId)
// ->where('item_id', $itemId)
// ->first();
// if (!$sticker) {
// return [];
// }
// $options = [];
// if (!empty($sticker->part_validation1)) {
// $options['part_validation1'] = 'Part Validation 1';
// }
// if (!empty($sticker->part_validation2)) {
// $options['part_validation2'] = 'Part Validation 2';
// }
// if (!empty($sticker->part_validation3)) {
// $options['part_validation3'] = 'Part Validation 3';
// }
// if (!empty($sticker->part_validation4)) {
// $options['part_validation4'] = 'Part Validation 4';
// }
// // if (!empty($sticker->part_validation5)) {
// // $options['part_validation5'] = 'Part Validation 5';
// // }
// return $options;
// })
// ->reactive()
// ->required(),
Forms\Components\Hidden::make('part_validation_type_options')
->default([])
->reactive()
->dehydrated(false),
Forms\Components\Hidden::make('show_validation_image')
->reactive()
->default(false),
// Forms\Components\Select::make('part_validation_type')
// ->label('Select Validation')
// ->reactive()
// ->options(fn (callable $get) => $get('part_validation_type_options') ?? [])
// ->required()
// ->visible(fn ($get) => !empty($get('part_validation_type_options')))
// ->afterStateUpdated(function ($state, callable $set) {
// // when user selects something new, hide the image
// $set('show_validation_image', false);
// $set('validation1_image_url', null);
// }),
Forms\Components\Select::make('part_validation_type')
->label('Select Validation')
->reactive()
->options(fn (callable $get) => $get('part_validation_type_options') ?? [])
->required()
->afterStateUpdated(function ($state, callable $set) {
// when user selects something new, hide the image
$set('show_validation_image', false);
$set('validation1_image_url', null);
})
->visible(fn ($get) => !empty($get('part_validation_type_options')))
->suffixAction(
Forms\Components\Actions\Action::make('toggleValidationImage')
->icon(fn (callable $get) => $get('show_validation_image') ? 'heroicon-o-eye-slash' : 'heroicon-o-eye')
->tooltip('View Validation Image')
->action(function (callable $get, $set) {
$currentState = $get('show_validation_image');
$set('show_validation_image', !$currentState);
if ($currentState == true) {
$set('validation1_image_url', null);
return;
}
$partvalidationType = $get('part_validation_type');
$plantId1 = $get('plant_id');
$plantCode1 = Plant::where('id', $plantId1)->value('code');
$itemState = $get('item_id');
$parts = explode('|', $itemState);
$itemCode = trim($parts[0]);
$itemId1 = Item::where('code', $itemCode)
->where('plant_id', $plantId1)
->first();
$itemId2 = $itemId1?->id;
$sticker = StickerMaster::where('plant_id', $plantId1)
->where('item_id', $itemId2)
->first();
if (!$sticker) {
Notification::make()
->title('Sticker Master Missing')
->body('No Sticker Master found for selected Plant & Item.')
->danger()
->send();
return;
}
$value = $sticker->{$partvalidationType};
$fileName = "{$value}.png";
$imageUrl = route('part.validation.image', [
'plant' => $plantCode1,
'filename' => $fileName
]);
$set('validation1_image_url', $imageUrl);
})
),
// Forms\Components\Actions::make([
// Forms\Components\Actions\Action::make('openValidation')
// ->label('Open/Close')
// ->button()
// ->color('primary')
// ->action(function (callable $get, $set) {
// $currentState = $get('show_validation_image');
// $set('show_validation_image', !$currentState);
// if ($currentState == true) {
// $set('validation1_image_url', null);
// return;
// }
// $partvalidationType = $get('part_validation_type');
// $plantId1 = $get('plant_id');
// $plantCode1 = Plant::where('id', $plantId1)->value('code');
// $itemState = $get('item_id');
// $parts = explode('|', $itemState);
// $itemCode = trim($parts[0]);
// $itemId1 = Item::where('code', $itemCode)
// ->where('plant_id', $plantId1)->first();
// $itemId2 = $itemId1?->id;
// $sticker = StickerMaster::where('plant_id', $plantId1)
// ->where('item_id', $itemId2)
// ->first();
// if (!$sticker) {
// Notification::make()
// ->title('Sticker Master Missing')
// ->body('No Sticker Master found for selected Plant & Item.')
// ->danger()
// ->send();
// return;
// }
// $value = $sticker->{$partvalidationType};
// $fileName = "{$value}.png";
// // Check existence
// $fullPath = storage_path("app/private/uploads/PartValidation/{$plantCode1}/{$fileName}");
// // Generate URL through custom route
// $imageUrl = route('part.validation.image', [
// 'plant' => $plantCode1,
// 'filename' => $fileName
// ]);
// // Pass to state (for modal/view)
// $set('validation1_image_url', $imageUrl);
// }),
// ])
// ->visible(fn ($get) => !empty($get('part_validation_type_options'))),
Forms\Components\Hidden::make('validation1_image_url')
->reactive(),
Forms\Components\View::make('components.part-validation-error-icon')
->statePath('validation1_image_url') // bind state directly
->visible(fn ($get) => $get('show_validation_image') == true)
->reactive(),
Forms\Components\Hidden::make('serial_number') Forms\Components\Hidden::make('serial_number')
->required(), ->required(),
@@ -1388,7 +1722,6 @@ class QualityValidationResource extends Resource
Forms\Components\Hidden::make('tube_sticker_motor'), Forms\Components\Hidden::make('tube_sticker_motor'),
Forms\Components\TextInput::make('tube_sticker_motor_qr') Forms\Components\TextInput::make('tube_sticker_motor_qr')
->label('Tube Sticker Motor') ->label('Tube Sticker Motor')
->hidden(fn (callable $get) => !$get('tube_sticker_motor_qr_visible')) ->hidden(fn (callable $get) => !$get('tube_sticker_motor_qr_visible'))
@@ -1913,6 +2246,13 @@ class QualityValidationResource extends Resource
->required() ->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$mPorder = $get('production_order');
$mPlantId = $get('plant_id');
$plant = Plant::find($mPlantId);
$plantCodePart1 = $plant?->code;
$stickerMasterId = $get('sticker_master_id'); $stickerMasterId = $get('sticker_master_id');
if (!$stickerMasterId) { if (!$stickerMasterId) {
return; return;
@@ -1937,7 +2277,37 @@ class QualityValidationResource extends Resource
else else
{ {
$set('part_validation1_error', "Invalid input for part validation 1."); $set('part_validation1_error', "Invalid input for part validation 1.");
//.Mail
$mailData = \App\Filament\Resources\QualityValidationResource::getMailData($mPlantId);
$mPlantName = $mailData['plant_name'];
$emails = $mailData['emails'];
if (!empty($emails))
{
//Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
Mail::to($emails)->send(
new InvalidQualityMail($state, $mPorder, $mPlantName, 'InvalidPartNumber')
);
}
else
{
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
}
$set('part_validation1', null); $set('part_validation1', null);
$fileName = $expectedValue . ".png"; // or .jpg based on your file
$fullPath = storage_path("app/private/uploads/PartValidation/{$plantCodePart1}/{$fileName}");
// Generate URL through custom route
$imageUrl = route('part.validation.image', [
'plant' => $plantCodePart1,
'filename' => $fileName
]);
$set('part_validation1_error_image', $imageUrl);
return; return;
} }
}) })
@@ -1947,6 +2317,15 @@ class QualityValidationResource extends Resource
->hint(fn ($get) => $get('part_validation1_error')) ->hint(fn ($get) => $get('part_validation1_error'))
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\Hidden::make('part_validation1_error_image')
->default(null)
->dehydrated(false),
Forms\Components\View::make('components.part-validation1-error-icon')
->visible(fn ($get) => $get('part_validation1_error') != null)
->statePath('part_validation1_error_image')
->reactive(),
Forms\Components\TextInput::make('part_validation2') Forms\Components\TextInput::make('part_validation2')
->hidden(fn (callable $get) => !$get('part_validation2_visible')) ->hidden(fn (callable $get) => !$get('part_validation2_visible'))
->default('') ->default('')
@@ -1954,6 +2333,12 @@ class QualityValidationResource extends Resource
->reactive() ->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$mPorder = $get('production_order');
$mPlantId = $get('plant_id');
$plant = Plant::find($mPlantId);
$plantCodePart2 = $plant?->code;
$stickerMasterId = $get('sticker_master_id'); $stickerMasterId = $get('sticker_master_id');
if (!$stickerMasterId) { if (!$stickerMasterId) {
return; return;
@@ -1978,17 +2363,61 @@ class QualityValidationResource extends Resource
else else
{ {
$set('part_validation2_error', "Invalid input for part validation 2."); $set('part_validation2_error', "Invalid input for part validation 2.");
$mailData = \App\Filament\Resources\QualityValidationResource::getMailData($mPlantId);
$mPlantName = $mailData['plant_name'];
$emails = $mailData['emails'];
if (!empty($emails))
{
//Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
Mail::to($emails)->send(
new InvalidQualityMail($state, $mPorder, $mPlantName, 'InvalidPartNumber2')
);
}
else
{
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
}
$set('part_validation2', null); $set('part_validation2', null);
$fileName = $expectedValue . ".png"; // or .jpg based on your file
$fullPath = storage_path("app/private/uploads/PartValidation/{$plantCodePart2}/{$fileName}");
// if (!file_exists($fullPath)) {
// Notification::make()
// ->title('Image Not Found')
// ->body($fileName)
// ->danger()
// ->send();
// return;
// }
// Generate URL through custom route
$imageUrl = route('part.validation.image', [
'plant' => $plantCodePart2,
'filename' => $fileName
]);
$set('part_validation2_error_image', $imageUrl);
return; return;
} }
}) })
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('part_validation2_error') ? 'border-red-500' : '', 'class' => $get('part_validation2_error') ? 'border-red-500' : '',
]) ])
->hint(fn ($get) => $get('part_validation2_error')) ->hint(fn ($get) => $get('part_validation2_error'))
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\Hidden::make('part_validation2_error_image')
->default(null)
->dehydrated(false),
Forms\Components\View::make('components.part-validation1-error-icon')
->visible(fn ($get) => $get('part_validation2_error') != null)
->statePath('part_validation2_error_image')
->reactive(),
Forms\Components\TextInput::make('part_validation3') Forms\Components\TextInput::make('part_validation3')
->hidden(fn (callable $get) => !$get('part_validation3_visible')) ->hidden(fn (callable $get) => !$get('part_validation3_visible'))
->default('') ->default('')
@@ -1996,12 +2425,20 @@ class QualityValidationResource extends Resource
->reactive() ->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$stickerMasterId = $get('sticker_master_id'); $stickerMasterId = $get('sticker_master_id');
$mPorder = $get('production_order');
$mPlantId = $get('plant_id');
$plant = Plant::find($mPlantId);
$plantCodePart3 = $plant?->code;
if (!$stickerMasterId) { if (!$stickerMasterId) {
return; return;
} }
$stickerMaster = StickerMaster::find($stickerMasterId); $stickerMaster = StickerMaster::find($stickerMasterId);
if (!$stickerMaster) { if (!$stickerMaster)
{
return; return;
} }
@@ -2019,17 +2456,60 @@ class QualityValidationResource extends Resource
else else
{ {
$set('part_validation3_error', "Invalid input for part validation 3."); $set('part_validation3_error', "Invalid input for part validation 3.");
$mailData = \App\Filament\Resources\QualityValidationResource::getMailData($mPlantId);
$mPlantName = $mailData['plant_name'];
$emails = $mailData['emails'];
if (!empty($emails))
{
//Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
Mail::to($emails)->send(
new InvalidQualityMail($state, $mPorder, $mPlantName, 'InvalidPartNumber3')
);
}
else
{
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
}
$set('part_validation3', null); $set('part_validation3', null);
$fileName = $expectedValue . ".png"; // or .jpg based on your file
//$fullPath = storage_path("app/private/uploads/PartValidation/{$plantCodePart3}/{$fileName}");
// if (!file_exists($fullPath)) {
// Notification::make()
// ->title('Image Not Found')
// ->body($fileName)
// ->danger()
// ->send();
// return;
// }
// Generate URL through custom route
$imageUrl = route('part.validation.image', [
'plant' => $plantCodePart3,
'filename' => $fileName
]);
$set('part_validation2_error_image', $imageUrl);
return; return;
} }
}) })
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('part_validation3_error') ? 'border-red-500' : '', 'class' => $get('part_validation3_error') ? 'border-red-500' : '',
]) ])
->hint(fn ($get) => $get('part_validation3_error')) ->hint(fn ($get) => $get('part_validation3_error'))
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\Hidden::make('part_validation3_error_image')
->default(null)
->dehydrated(false),
Forms\Components\View::make('components.part-validation1-error-icon')
->visible(fn ($get) => $get('part_validation3_error') != null)
->statePath('part_validation3_error_image')
->reactive(),
Forms\Components\TextInput::make('part_validation4') Forms\Components\TextInput::make('part_validation4')
->hidden(fn (callable $get) => !$get('part_validation4_visible')) ->hidden(fn (callable $get) => !$get('part_validation4_visible'))
->default('') ->default('')
@@ -2037,6 +2517,12 @@ class QualityValidationResource extends Resource
->reactive() ->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$stickerMasterId = $get('sticker_master_id'); $stickerMasterId = $get('sticker_master_id');
$mPorder = $get('production_order');
$mPlantId = $get('plant_id');
$plant = Plant::find($mPlantId);
$plantCodePart4 = $plant?->code;
if (!$stickerMasterId) { if (!$stickerMasterId) {
return; return;
} }
@@ -2061,18 +2547,52 @@ class QualityValidationResource extends Resource
else else
{ {
$set('part_validation4_error', "Invalid input for part validation 4."); $set('part_validation4_error', "Invalid input for part validation 4.");
$mailData = \App\Filament\Resources\QualityValidationResource::getMailData($mPlantId);
$mPlantName = $mailData['plant_name'];
$emails = $mailData['emails'];
if (!empty($emails))
{
//Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
Mail::to($emails)->send(
new InvalidQualityMail($state, $mPorder, $mPlantName, 'InvalidPartNumber4')
);
}
else
{
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
}
$set('part_validation4', null); $set('part_validation4', null);
$fileName = $expectedValue . ".png"; // or .jpg based on your file
$fullPath = storage_path("app/private/uploads/PartValidation/{$plantCodePart4}/{$fileName}");
// Generate URL through custom route
$imageUrl = route('part.validation.image', [
'plant' => $plantCodePart4,
'filename' => $fileName
]);
$set('part_validation2_error_image', $imageUrl);
return; return;
} }
}) })
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('part_validation4_error') ? 'border-red-500' : '', 'class' => $get('part_validation4_error') ? 'border-red-500' : '',
]) ])
->hint(fn ($get) => $get('part_validation4_error')) ->hint(fn ($get) => $get('part_validation4_error'))
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\Hidden::make('part_validation4_error_image')
->default(null)
->dehydrated(false),
Forms\Components\View::make('components.part-validation1-error-icon')
->visible(fn ($get) => $get('part_validation4_error') != null)
->statePath('part_validation4_error_image')
->reactive(),
Forms\Components\TextInput::make('part_validation5') Forms\Components\TextInput::make('part_validation5')
->hidden(fn (callable $get) => !$get('part_validation5_visible')) ->hidden(fn (callable $get) => !$get('part_validation5_visible'))
->default('') ->default('')
@@ -2080,6 +2600,10 @@ class QualityValidationResource extends Resource
->reactive() ->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$stickerMasterId = $get('sticker_master_id'); $stickerMasterId = $get('sticker_master_id');
$mPorder = $get('production_order');
$mPlantId = $get('plant_id');
if (!$stickerMasterId) { if (!$stickerMasterId) {
return; return;
} }
@@ -2146,12 +2670,27 @@ class QualityValidationResource extends Resource
else else
{ {
$set('part_validation5_error', "Invalid input for part validation 5."); $set('part_validation5_error', "Invalid input for part validation 5.");
$mailData = \App\Filament\Resources\QualityValidationResource::getMailData($mPlantId);
$mPlantName = $mailData['plant_name'];
$emails = $mailData['emails'];
if (!empty($emails))
{
//Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
Mail::to($emails)->send(
new InvalidQualityMail($state, $mPorder, $mPlantName, 'InvalidPartNumber5')
);
}
else
{
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
}
$set('part_validation5', null); $set('part_validation5', null);
return; return;
} }
}) })
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('part_validation5_error') ? 'border-red-500' : '', 'class' => $get('part_validation5_error') ? 'border-red-500' : '',
]) ])
@@ -2164,6 +2703,53 @@ class QualityValidationResource extends Resource
]); ]);
} }
public static function getMailData($plantId)
{
$mPlantName = Plant::where('id', $plantId)->value('name');
$emails = AlertMailRule::where('plant', $plantId)
->where('module', 'InvoiceValidation')
->where('rule_name', 'InvoiceMail')
->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', ''))
->pluck('email')
->toArray();
return [
'plant_id' => $plantId,
'plant_name' => $mPlantName,
'emails' => $emails,
];
}
// public function getMail(){
// //$plantId = $this->form->getState()['plant_id'];
// $plantId = $this->data['plant_id'] ?? null;
// //$this->plantId = $plantId;
// dd($plantId);
// $mInvoiceType = 'Serial';
// $mPlantName = Plant::where('id', $plantId)->value('name');
// $emails = AlertMailRule::where('plant', $plantId)
// //->where('plant', $plantName)
// ->where('module', 'InvoiceValidation')
// ->where('rule_name', 'InvoiceMail')
// ->where(function ($query) {
// $query->whereNull('schedule_type')
// ->orWhere('schedule_type', '');
// })
// ->pluck('email')
// ->toArray();
// return [
// 'plant_id' => $plantId,
// 'plant_name' => $mPlantName,
// 'invoice_type' => $mInvoiceType,
// 'emails' => $emails,
// ];
// }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table