Added part validation mail trigger logic and image uploading
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Filament\Exports\QualityValidationExporter;
|
||||
use App\Filament\Imports\QualityValidationImporter;
|
||||
use App\Filament\Resources\QualityValidationResource\Pages;
|
||||
use App\Filament\Resources\QualityValidationResource\RelationManagers;
|
||||
use App\Mail\InvalidQualityMail;
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
@@ -32,7 +34,9 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Notification;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Storage;
|
||||
|
||||
class QualityValidationResource extends Resource
|
||||
{
|
||||
@@ -42,10 +46,12 @@ class QualityValidationResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Display';
|
||||
public $isSubmitted = false;
|
||||
public $data = [];
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('data')
|
||||
->schema(components: [
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
@@ -59,12 +65,18 @@ class QualityValidationResource extends Resource
|
||||
$set('line_id', 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);
|
||||
|
||||
$pId = $get('plant_id');
|
||||
if (!$pId) {
|
||||
$set('pqPlantError', 'Please select a plant first.');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$set('pqPlantError', null);
|
||||
}
|
||||
|
||||
@@ -172,6 +184,28 @@ class QualityValidationResource extends Resource
|
||||
Forms\Components\Hidden::make('sap_msg_description')
|
||||
->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')
|
||||
->label('Item Code')
|
||||
->placeholder('Scan the valid QR code')
|
||||
@@ -182,6 +216,10 @@ class QualityValidationResource extends Resource
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
|
||||
$pId = $get('line_id');
|
||||
$set('part_validation_type', null);
|
||||
$set('show_validation_image', false);
|
||||
$set('validation1_image_url', null);
|
||||
|
||||
if (!$pId) {
|
||||
$set('pqLineError', 'Please select a line.');
|
||||
} else {
|
||||
@@ -193,6 +231,9 @@ class QualityValidationResource extends Resource
|
||||
{
|
||||
$set('prodOrdError', "Production Order can't be empty.");
|
||||
$set('production_order', null);
|
||||
$set('part_validation_type', null);
|
||||
$set('show_validation_image', false);
|
||||
$set('validation1_image_url', null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -230,6 +271,10 @@ class QualityValidationResource extends Resource
|
||||
// // Check if QR format contains '|'
|
||||
if (strpos($state, '|') == false) {
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -249,18 +294,34 @@ class QualityValidationResource extends Resource
|
||||
|
||||
if (!ctype_alnum($iCode)) {
|
||||
$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;
|
||||
}
|
||||
else if (strlen($iCode) < 6) {
|
||||
$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;
|
||||
}
|
||||
else if (!ctype_alnum($sNumber)) {
|
||||
$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;
|
||||
}
|
||||
else if (strlen($sNumber) < 9) {
|
||||
$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;
|
||||
}
|
||||
// }
|
||||
@@ -284,11 +345,19 @@ class QualityValidationResource extends Resource
|
||||
|
||||
if (strlen($itemCode) < 6) {
|
||||
$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;
|
||||
}
|
||||
else if (!ctype_alnum($itemCode)) {
|
||||
$set('validationError', 'Item Code should contain alpha-numeric values.');
|
||||
$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;
|
||||
}
|
||||
else if ($serialNumber == '') {
|
||||
@@ -297,11 +366,19 @@ class QualityValidationResource extends Resource
|
||||
}
|
||||
else if (strlen($serialNumber) < 9) {
|
||||
$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;
|
||||
}
|
||||
else if (!ctype_alnum($serialNumber)) {
|
||||
$set('validationError', 'Serial Number should contain alpha-numeric values.');
|
||||
$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;
|
||||
}
|
||||
else
|
||||
@@ -314,6 +391,10 @@ class QualityValidationResource extends Resource
|
||||
if (!$plantId) {
|
||||
$set('validationError', 'Please select a plant first.');
|
||||
$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;
|
||||
}
|
||||
// Check if the item exists for the selected plant
|
||||
@@ -327,6 +408,10 @@ class QualityValidationResource extends Resource
|
||||
$set('sticker_master_id', null);
|
||||
$set('uom', 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;
|
||||
}
|
||||
else
|
||||
@@ -336,6 +421,9 @@ class QualityValidationResource extends Resource
|
||||
$set('sticker_master_id', null);
|
||||
$set('uom', null);
|
||||
$set('serial_number', null);
|
||||
$set('part_validation_type', null);
|
||||
$set('show_validation_image', false);
|
||||
$set('validation1_image_url', null);
|
||||
return;
|
||||
}
|
||||
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('uom', 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;
|
||||
}
|
||||
|
||||
@@ -442,18 +534,260 @@ class QualityValidationResource extends Resource
|
||||
}
|
||||
$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) => [
|
||||
'class' => $get('validationError') ? 'border-red-500' : '',
|
||||
])
|
||||
->extraAttributes([
|
||||
'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); return false; }",
|
||||
])
|
||||
|
||||
->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
|
||||
->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')
|
||||
->required(),
|
||||
|
||||
@@ -1388,7 +1722,6 @@ class QualityValidationResource extends Resource
|
||||
|
||||
Forms\Components\Hidden::make('tube_sticker_motor'),
|
||||
|
||||
|
||||
Forms\Components\TextInput::make('tube_sticker_motor_qr')
|
||||
->label('Tube Sticker Motor')
|
||||
->hidden(fn (callable $get) => !$get('tube_sticker_motor_qr_visible'))
|
||||
@@ -1913,6 +2246,13 @@ class QualityValidationResource extends Resource
|
||||
->required()
|
||||
->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');
|
||||
if (!$stickerMasterId) {
|
||||
return;
|
||||
@@ -1937,7 +2277,37 @@ class QualityValidationResource extends Resource
|
||||
else
|
||||
{
|
||||
$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);
|
||||
|
||||
$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;
|
||||
}
|
||||
})
|
||||
@@ -1947,6 +2317,15 @@ class QualityValidationResource extends Resource
|
||||
->hint(fn ($get) => $get('part_validation1_error'))
|
||||
->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')
|
||||
->hidden(fn (callable $get) => !$get('part_validation2_visible'))
|
||||
->default('')
|
||||
@@ -1954,6 +2333,12 @@ class QualityValidationResource extends Resource
|
||||
->reactive()
|
||||
->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');
|
||||
if (!$stickerMasterId) {
|
||||
return;
|
||||
@@ -1978,17 +2363,61 @@ class QualityValidationResource extends Resource
|
||||
else
|
||||
{
|
||||
$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);
|
||||
|
||||
$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;
|
||||
}
|
||||
})
|
||||
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('part_validation2_error') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('part_validation2_error'))
|
||||
->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')
|
||||
->hidden(fn (callable $get) => !$get('part_validation3_visible'))
|
||||
->default('')
|
||||
@@ -1996,12 +2425,20 @@ class QualityValidationResource extends Resource
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$stickerMasterId = $get('sticker_master_id');
|
||||
|
||||
$mPorder = $get('production_order');
|
||||
|
||||
$mPlantId = $get('plant_id');
|
||||
$plant = Plant::find($mPlantId);
|
||||
$plantCodePart3 = $plant?->code;
|
||||
|
||||
if (!$stickerMasterId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stickerMaster = StickerMaster::find($stickerMasterId);
|
||||
if (!$stickerMaster) {
|
||||
if (!$stickerMaster)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2019,17 +2456,60 @@ class QualityValidationResource extends Resource
|
||||
else
|
||||
{
|
||||
$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);
|
||||
$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;
|
||||
}
|
||||
})
|
||||
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('part_validation3_error') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('part_validation3_error'))
|
||||
->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')
|
||||
->hidden(fn (callable $get) => !$get('part_validation4_visible'))
|
||||
->default('')
|
||||
@@ -2037,6 +2517,12 @@ class QualityValidationResource extends Resource
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$stickerMasterId = $get('sticker_master_id');
|
||||
$mPorder = $get('production_order');
|
||||
|
||||
$mPlantId = $get('plant_id');
|
||||
$plant = Plant::find($mPlantId);
|
||||
$plantCodePart4 = $plant?->code;
|
||||
|
||||
if (!$stickerMasterId) {
|
||||
return;
|
||||
}
|
||||
@@ -2061,18 +2547,52 @@ class QualityValidationResource extends Resource
|
||||
else
|
||||
{
|
||||
$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);
|
||||
$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;
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('part_validation4_error') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('part_validation4_error'))
|
||||
->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')
|
||||
->hidden(fn (callable $get) => !$get('part_validation5_visible'))
|
||||
->default('')
|
||||
@@ -2080,6 +2600,10 @@ class QualityValidationResource extends Resource
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$stickerMasterId = $get('sticker_master_id');
|
||||
|
||||
$mPorder = $get('production_order');
|
||||
$mPlantId = $get('plant_id');
|
||||
|
||||
if (!$stickerMasterId) {
|
||||
return;
|
||||
}
|
||||
@@ -2146,12 +2670,27 @@ class QualityValidationResource extends Resource
|
||||
else
|
||||
{
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
->extraAttributes(fn ($get) => [
|
||||
'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
|
||||
{
|
||||
return $table
|
||||
|
||||
Reference in New Issue
Block a user