ranjith-dev #940
@@ -28,6 +28,8 @@ use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use App\Filament\Exports\PanelBoxValidationExporter;
|
||||
use App\Filament\Imports\PanelBoxValidationImporter;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
|
||||
class PanelBoxValidationResource extends Resource
|
||||
{
|
||||
@@ -41,7 +43,7 @@ class PanelBoxValidationResource extends Resource
|
||||
|
||||
public $data = [];
|
||||
|
||||
// public bool $showChecklist = false;
|
||||
public bool $showChecklist = false;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
@@ -239,10 +241,6 @@ class PanelBoxValidationResource extends Resource
|
||||
$set('pqLineError', null);
|
||||
}
|
||||
|
||||
// if(!$state){
|
||||
// $set('serial_exists', false);
|
||||
// }
|
||||
|
||||
$pOrder = $get('production_order');
|
||||
if (! $pOrder) {
|
||||
$set('prodOrdError', "Production Order can't be empty.");
|
||||
@@ -278,11 +276,12 @@ class PanelBoxValidationResource extends Resource
|
||||
|
||||
// Proceed with validation logic for new scanned QR code
|
||||
if (! $state || trim($state) == '') {
|
||||
$set('serial_exists', false);
|
||||
$set('validationError', null);
|
||||
return;
|
||||
}
|
||||
|
||||
// // Check if QR format contains '|'
|
||||
// Check if QR format contains '|'
|
||||
|
||||
if ($state && str_contains($state, '|'))
|
||||
{
|
||||
@@ -566,11 +565,10 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
// $set('serial_exists', false);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$supplier = $parts[0];
|
||||
$panelBoxCode = $parts[1];
|
||||
$panelBoxSerialNo = implode('/', array_slice($parts, 2));
|
||||
@@ -587,6 +585,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -599,6 +598,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -611,6 +611,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){
|
||||
@@ -620,6 +621,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
else if($existInMaster->supplier_number != $supplier){
|
||||
@@ -629,6 +631,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
else if($existInMaster->inspection_lot_number != $inspecLotNo){
|
||||
@@ -638,6 +641,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
else if($existInMaster->quantity == '' || $existInMaster->quantity == null){
|
||||
@@ -647,6 +651,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){
|
||||
@@ -656,6 +661,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -668,6 +674,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -680,6 +687,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -695,6 +703,7 @@ class PanelBoxValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
$set('validationError', null);
|
||||
return;
|
||||
}
|
||||
@@ -702,6 +711,7 @@ class PanelBoxValidationResource extends Resource
|
||||
if (strlen($itemCode) < 6) {
|
||||
$set('validationError', 'Item code must be at least 6 digits.');
|
||||
$set('part_validation_type', null);
|
||||
$set('serial_exists', false);
|
||||
$set('show_validation_image', false);
|
||||
$set('part_validation_type_options', []);
|
||||
$set('validation1_image_url', null);
|
||||
@@ -710,6 +720,7 @@ class PanelBoxValidationResource extends Resource
|
||||
} elseif (! ctype_alnum($itemCode)) {
|
||||
$set('validationError', 'Item Code should contain alpha-numeric values.');
|
||||
$set('item_id', null);
|
||||
$set('serial_exists', false);
|
||||
$set('part_validation_type', null);
|
||||
$set('show_validation_image', false);
|
||||
$set('part_validation_type_options', []);
|
||||
@@ -745,6 +756,7 @@ class PanelBoxValidationResource extends Resource
|
||||
$set('show_validation_image', false);
|
||||
$set('part_validation_type_options', []);
|
||||
$set('validation1_image_url', null);
|
||||
$set('serial_exists', false);
|
||||
|
||||
return;
|
||||
} else {
|
||||
@@ -756,6 +768,7 @@ class PanelBoxValidationResource extends Resource
|
||||
$set('part_validation_type', null);
|
||||
$set('show_validation_image', false);
|
||||
$set('validation1_image_url', null);
|
||||
$set('serial_exists', false);
|
||||
|
||||
return;
|
||||
} elseif (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) {
|
||||
@@ -768,6 +781,7 @@ class PanelBoxValidationResource extends Resource
|
||||
$set('show_validation_image', false);
|
||||
$set('part_validation_type_options', []);
|
||||
$set('validation1_image_url', null);
|
||||
$set('serial_exists', false);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -793,23 +807,23 @@ class PanelBoxValidationResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
$serialExists = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->first();
|
||||
$serialExists = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->latest()->first();
|
||||
|
||||
// if ($serialExists) {
|
||||
// $set('serial_exists', true);
|
||||
// } else {
|
||||
// $set('serial_exists', false);
|
||||
// }
|
||||
|
||||
if ($serialExists && ! $get('id')) {
|
||||
$set('validationError', 'Serial number already exists in panel box validation.');
|
||||
$set('sticker_master_id', null);
|
||||
$set('uom', null);
|
||||
$set('serial_number', null);
|
||||
|
||||
return;
|
||||
if ($serialExists) {
|
||||
$set('serial_exists', true);
|
||||
} else {
|
||||
$set('serial_exists', false);
|
||||
}
|
||||
|
||||
// if ($serialExists && ! $get('id')) {
|
||||
// $set('validationError', 'Serial number already exists in panel box validation.');
|
||||
// $set('sticker_master_id', null);
|
||||
// $set('uom', null);
|
||||
// $set('serial_number', null);
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
$set('validationError', null);
|
||||
|
||||
foreach ($serialFields as $column) {
|
||||
@@ -923,12 +937,6 @@ class PanelBoxValidationResource extends Resource
|
||||
$set('part_validation_type_options', $options);
|
||||
|
||||
})
|
||||
// ->extraAttributes(fn ($get) => [
|
||||
// 'class' => $get('validationError') ? 'border-red-500' : '',
|
||||
// 'id' => 'item_id',
|
||||
// 'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); return false; }",
|
||||
// ])
|
||||
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('validationError') ? 'border-red-500' : '',
|
||||
'id' => 'item_id',
|
||||
@@ -960,6 +968,78 @@ class PanelBoxValidationResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Hidden::make('serial_exists')
|
||||
->default(false),
|
||||
|
||||
Forms\Components\Actions::make([
|
||||
Action::make('rework')
|
||||
->label('Yes, Rework')
|
||||
->color('warning')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Confirm Rework')
|
||||
->modalDescription('Have you reworked this serial number?')
|
||||
->modalSubmitActionLabel('Yes, Continue')
|
||||
->visible(fn ($get) => $get('serial_exists') == true)
|
||||
->action(function ($get, $livewire) {
|
||||
|
||||
$serialNumber = $get('serial_number');
|
||||
$plantId = $get('plant_id');
|
||||
$pOrder = $get('production_order');
|
||||
$inspecLotNo = $get('inspection_lot_number');
|
||||
|
||||
// $serialRecords = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->get();
|
||||
|
||||
// if ($serialRecords->isNotEmpty()) {
|
||||
|
||||
// $alreadyExists = $serialRecords->contains(function ($record) use ($pOrder, $inspecLotNo) {
|
||||
// return $record->production_order == $pOrder
|
||||
// && $record->inspection_lot_number == $inspecLotNo;
|
||||
// });
|
||||
|
||||
// if ($alreadyExists) {
|
||||
// Notification::make()
|
||||
// ->title('Invalid Rework')
|
||||
// ->body(
|
||||
// 'This document number and inspection lot number have already been used for this serial number. Please provide a new document number and inspection lot number.'
|
||||
// )
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
$alreadyExists = PanelBoxValidation::where('serial_number', $serialNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->where('production_order', $pOrder)
|
||||
->where('inspection_lot_number', $inspecLotNo)
|
||||
->first();
|
||||
|
||||
if ($alreadyExists) {
|
||||
Notification::make()
|
||||
->title('Invalid Rework')
|
||||
->body(
|
||||
'This document number and inspection lot number have already been used for this serial number. Please provide a new document number and inspection lot number.'
|
||||
)
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// $livewire->showChecklist = true;
|
||||
$data = $livewire->data;
|
||||
|
||||
if ($livewire->checkIfHasCharacteristics($data)) {
|
||||
|
||||
$livewire->showChecklist = true;
|
||||
$livewire->dispatch('close-modal');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}),
|
||||
]),
|
||||
Forms\Components\Hidden::make('part_validation_type_options')
|
||||
->default([])
|
||||
->reactive()
|
||||
@@ -1767,6 +1847,11 @@ class PanelBoxValidationResource extends Resource
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('rework_count')
|
||||
->label('Rework Count')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\ProductCharacteristicsMaster;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Filament\Actions\Action;
|
||||
|
||||
class CreatePanelBoxValidation extends CreateRecord {
|
||||
|
||||
@@ -37,6 +38,17 @@ class CreatePanelBoxValidation extends CreateRecord {
|
||||
{
|
||||
$this->create();
|
||||
}
|
||||
public function getCreateFormAction(): Action
|
||||
{
|
||||
return parent::getCreateFormAction()
|
||||
->visible(fn () => $this->data['serial_exists'] != true);
|
||||
}
|
||||
|
||||
protected function getCreateAnotherFormAction(): Action
|
||||
{
|
||||
return parent::getCreateAnotherFormAction()
|
||||
->visible(fn () => ($this->data['serial_exists'] ?? false) != true);
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
@@ -75,7 +87,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkIfHasCharacteristics(array $data)
|
||||
public function checkIfHasCharacteristics(array $data)
|
||||
{
|
||||
$plantId = $data['plant_id'] ?? null;
|
||||
$itemCode = $data['item_id'] ?? null;
|
||||
|
||||
@@ -113,14 +113,14 @@ public $records = [];
|
||||
|
||||
$plan = Plant::find($this->data['plant_id']);
|
||||
|
||||
if ($exists) {
|
||||
Notification::make()
|
||||
->title('Duplicate Serial Number')
|
||||
->body("serial number {$this->data['serial_number']} already exists for the selected plant $plan->code.")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
// if ($exists) {
|
||||
// Notification::make()
|
||||
// ->title('Duplicate Serial Number')
|
||||
// ->body("serial number {$this->data['serial_number']} already exists for the selected plant $plan->code.")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(!$this->selectForNotOk){
|
||||
|
||||
@@ -177,29 +177,59 @@ public $records = [];
|
||||
}
|
||||
}
|
||||
|
||||
$qualityValidation = PanelBoxValidation::create([
|
||||
'plant_id' => $this->data['plant_id'] ?? null,
|
||||
'line_id' => $this->data['line_id'] ?? null,
|
||||
'sticker_master_id' => $this->data['sticker_master_id'] ?? null,
|
||||
'production_order' => $this->data['production_order'] ?? null,
|
||||
'serial_number' => $this->data['serial_number'] ?? null,
|
||||
'serial_number_panel' => $this->data['serial_number_panel'] ?? null,
|
||||
'pack_slip_panel' => $this->data['pack_slip_panel'] ?? null,
|
||||
'name_plate_panel' => $this->data['name_plate_panel'] ?? null,
|
||||
'tube_sticker_panel' => $this->data['tube_sticker_panel'] ?? null,
|
||||
'warranty_card_panel' => $this->data['warranty_card_panel'] ?? null,
|
||||
'part_validation1' => $this->data['part_validation1'] ?? null,
|
||||
'part_validation2' => $this->data['part_validation2'] ?? null,
|
||||
'part_validation3' => $this->data['part_validation3'] ?? null,
|
||||
'part_validation4' => $this->data['part_validation4'] ?? null,
|
||||
'part_validation5' => $this->data['part_validation5'] ?? null,
|
||||
'panel_box_supplier' => $this->data['panel_box_supplier'] ?? null,
|
||||
'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null,
|
||||
'panel_box_code' => $this->data['panel_box_code'] ?? null,
|
||||
'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null,
|
||||
'created_by' => $this->data['created_by'] ?? null,
|
||||
'updated_by' => $this->data['updated_by'] ?? null,
|
||||
]);
|
||||
$latestReworkRecord = PanelBoxValidation::where('plant_id', $this->data['plant_id'] ?? null)->where('serial_number', $this->data['serial_number'] ?? null)->latest()->first();
|
||||
|
||||
if($latestReworkRecord){
|
||||
$qualityValidation = PanelBoxValidation::create([
|
||||
'plant_id' => $this->data['plant_id'] ?? null,
|
||||
'line_id' => $this->data['line_id'] ?? null,
|
||||
'sticker_master_id' => $this->data['sticker_master_id'] ?? null,
|
||||
'production_order' => $this->data['production_order'] ?? null,
|
||||
'serial_number' => $this->data['serial_number'] ?? null,
|
||||
'serial_number_panel' => $this->data['serial_number_panel'] ?? null,
|
||||
'pack_slip_panel' => $this->data['pack_slip_panel'] ?? null,
|
||||
'name_plate_panel' => $this->data['name_plate_panel'] ?? null,
|
||||
'tube_sticker_panel' => $this->data['tube_sticker_panel'] ?? null,
|
||||
'warranty_card_panel' => $this->data['warranty_card_panel'] ?? null,
|
||||
'part_validation1' => $this->data['part_validation1'] ?? null,
|
||||
'part_validation2' => $this->data['part_validation2'] ?? null,
|
||||
'part_validation3' => $this->data['part_validation3'] ?? null,
|
||||
'part_validation4' => $this->data['part_validation4'] ?? null,
|
||||
'part_validation5' => $this->data['part_validation5'] ?? null,
|
||||
'panel_box_supplier' => $this->data['panel_box_supplier'] ?? null,
|
||||
'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null,
|
||||
'panel_box_code' => $this->data['panel_box_code'] ?? null,
|
||||
'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null,
|
||||
'rework_count' => $latestReworkRecord ? ((int) $latestReworkRecord->rework_count + 1) : 0,
|
||||
'created_by' => $this->data['created_by'] ?? null,
|
||||
'updated_by' => $this->data['updated_by'] ?? null,
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$qualityValidation = PanelBoxValidation::create([
|
||||
'plant_id' => $this->data['plant_id'] ?? null,
|
||||
'line_id' => $this->data['line_id'] ?? null,
|
||||
'sticker_master_id' => $this->data['sticker_master_id'] ?? null,
|
||||
'production_order' => $this->data['production_order'] ?? null,
|
||||
'serial_number' => $this->data['serial_number'] ?? null,
|
||||
'serial_number_panel' => $this->data['serial_number_panel'] ?? null,
|
||||
'pack_slip_panel' => $this->data['pack_slip_panel'] ?? null,
|
||||
'name_plate_panel' => $this->data['name_plate_panel'] ?? null,
|
||||
'tube_sticker_panel' => $this->data['tube_sticker_panel'] ?? null,
|
||||
'warranty_card_panel' => $this->data['warranty_card_panel'] ?? null,
|
||||
'part_validation1' => $this->data['part_validation1'] ?? null,
|
||||
'part_validation2' => $this->data['part_validation2'] ?? null,
|
||||
'part_validation3' => $this->data['part_validation3'] ?? null,
|
||||
'part_validation4' => $this->data['part_validation4'] ?? null,
|
||||
'part_validation5' => $this->data['part_validation5'] ?? null,
|
||||
'panel_box_supplier' => $this->data['panel_box_supplier'] ?? null,
|
||||
'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null,
|
||||
'panel_box_code' => $this->data['panel_box_code'] ?? null,
|
||||
'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null,
|
||||
'created_by' => $this->data['created_by'] ?? null,
|
||||
'updated_by' => $this->data['updated_by'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $qualityValidation || ! $qualityValidation->exists) {
|
||||
Notification::make()
|
||||
|
||||
@@ -30,6 +30,7 @@ class PanelBoxValidation extends Model
|
||||
'panel_box_serial_number',
|
||||
'panel_box_code',
|
||||
'inspection_lot_number',
|
||||
'rework_count',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE panel_box_validations
|
||||
DROP CONSTRAINT panel_box_validations_plant_id_serial_number_key
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('panel_box_validations', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE panel_box_validations
|
||||
ADD COLUMN rework_count TEXT DEFAULT '0'
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('panel_box_validations', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user