Compare commits
28 Commits
4acb66c464
...
renovate/a
| Author | SHA1 | Date | |
|---|---|---|---|
| e501e91673 | |||
| 8a0e7d6878 | |||
|
|
81d2f4bd2c | ||
| d1031d8a6e | |||
|
|
c3d4a97277 | ||
| fa06c2c6cb | |||
|
|
d243f53f2f | ||
| e06a458fc0 | |||
|
|
878e12eff5 | ||
| 36dd07817b | |||
|
|
cddc8a1b70 | ||
| 51a20219db | |||
|
|
95217ce722 | ||
| dc564f9c28 | |||
|
|
9ba54dabf1 | ||
|
|
3c4a4bf136 | ||
|
|
0e651e8bcc | ||
| bab5b879e6 | |||
|
|
c3a4985f45 | ||
| a09264a053 | |||
|
|
95c27d6821 | ||
| 82f776ef41 | |||
|
|
8fedc01efd | ||
| 952b9a01a5 | |||
|
|
4abdd1b81e | ||
| 2b8a3a2838 | |||
|
|
10c2abb881 | ||
|
|
934447d0b2 |
@@ -36,12 +36,14 @@ class CharacteristicValueExporter extends Exporter
|
|||||||
->label('COIL NUMBER'),
|
->label('COIL NUMBER'),
|
||||||
ExportColumn::make('status')
|
ExportColumn::make('status')
|
||||||
->label('STATUS'),
|
->label('STATUS'),
|
||||||
|
ExportColumn::make('observed_value')
|
||||||
|
->label('OBSERVED VALUE'),
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
->label('CREATED AT'),
|
->label('CREATED AT'),
|
||||||
ExportColumn::make('updated_at')
|
|
||||||
->label('UPDATED AT'),
|
|
||||||
ExportColumn::make('created_by')
|
ExportColumn::make('created_by')
|
||||||
->label('CREATED BY'),
|
->label('CREATED BY'),
|
||||||
|
ExportColumn::make('updated_at')
|
||||||
|
->label('UPDATED AT'),
|
||||||
ExportColumn::make('updated_by')
|
ExportColumn::make('updated_by')
|
||||||
->label('UPDATED BY'),
|
->label('UPDATED BY'),
|
||||||
ExportColumn::make('deleted_at')
|
ExportColumn::make('deleted_at')
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class ProcessOrderExporter extends Exporter
|
|||||||
}),
|
}),
|
||||||
ExportColumn::make('plant.code')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT CODE'),
|
->label('PLANT CODE'),
|
||||||
|
ExportColumn::make('line.name')
|
||||||
|
->label('LINE NAME'),
|
||||||
ExportColumn::make('item.code')
|
ExportColumn::make('item.code')
|
||||||
->label('ITEM CODE'),
|
->label('ITEM CODE'),
|
||||||
ExportColumn::make('process_order')
|
ExportColumn::make('process_order')
|
||||||
@@ -37,13 +39,17 @@ class ProcessOrderExporter extends Exporter
|
|||||||
ExportColumn::make('sfg_number')
|
ExportColumn::make('sfg_number')
|
||||||
->label('SFG NUMBER'),
|
->label('SFG NUMBER'),
|
||||||
ExportColumn::make('machine_name')
|
ExportColumn::make('machine_name')
|
||||||
->label('MACHINE ID'),
|
->label('MACHINE NAME'),
|
||||||
|
ExportColumn::make('scrap_quantity')
|
||||||
|
->label('SCRAP QUANTITY'),
|
||||||
|
ExportColumn::make('rework_status')
|
||||||
|
->label('REWORK STATUS'),
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
->label('CREATED AT'),
|
->label('CREATED AT'),
|
||||||
ExportColumn::make('updated_at')
|
|
||||||
->label('UPDATED AT'),
|
|
||||||
ExportColumn::make('created_by')
|
ExportColumn::make('created_by')
|
||||||
->label('CREATED BY'),
|
->label('CREATED BY'),
|
||||||
|
ExportColumn::make('updated_at')
|
||||||
|
->label('UPDATED AT'),
|
||||||
ExportColumn::make('updated_by')
|
ExportColumn::make('updated_by')
|
||||||
->label('UPDATED BY'),
|
->label('UPDATED BY'),
|
||||||
ExportColumn::make('deleted_at')
|
ExportColumn::make('deleted_at')
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
|||||||
ExportColumn::make('line.name')
|
ExportColumn::make('line.name')
|
||||||
->label('LINE NAME'), // machine.workGroupMaster.name
|
->label('LINE NAME'), // machine.workGroupMaster.name
|
||||||
ExportColumn::make('machine.workGroupMaster.name')
|
ExportColumn::make('machine.workGroupMaster.name')
|
||||||
->label('WORK GROUP MASTER'),
|
->label('GROUP WORK CENTER'),
|
||||||
ExportColumn::make('machine.work_center')
|
ExportColumn::make('machine.work_center')
|
||||||
->label('WORK CENTER'),
|
->label('WORK CENTER'),
|
||||||
ExportColumn::make('characteristics_type')
|
ExportColumn::make('characteristics_type')
|
||||||
|
|||||||
@@ -8,10 +8,14 @@ use App\Models\Line;
|
|||||||
use App\Models\Machine;
|
use App\Models\Machine;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProcessOrder;
|
use App\Models\ProcessOrder;
|
||||||
|
use App\Models\ProductCharacteristicsMaster;
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class CharacteristicValueImporter extends Importer
|
class CharacteristicValueImporter extends Importer
|
||||||
@@ -64,11 +68,28 @@ class CharacteristicValueImporter extends Importer
|
|||||||
->exampleHeader('Status')
|
->exampleHeader('Status')
|
||||||
->example('Ok')
|
->example('Ok')
|
||||||
->label('Status'),
|
->label('Status'),
|
||||||
|
ImportColumn::make('observed_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Observed Value')
|
||||||
|
->example('RAW01234')
|
||||||
|
->label('Observed Value'),
|
||||||
ImportColumn::make('created_by')
|
ImportColumn::make('created_by')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Created By')
|
->exampleHeader('Created By')
|
||||||
->example('RAW01234')
|
->example('RAW01234')
|
||||||
->label('Created By'),
|
->label('Created By'),
|
||||||
|
ImportColumn::make('created_at')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Created DateTime')
|
||||||
|
->example('01-01-2025 08:00:00')
|
||||||
|
->label('Created DateTime')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('updated_at')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Updated DateTime')
|
||||||
|
->example('01-01-2025 08:00:00')
|
||||||
|
->label('Updated DateTime')
|
||||||
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,30 +103,39 @@ class CharacteristicValueImporter extends Importer
|
|||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantId = null;
|
$plantId = null;
|
||||||
$itemId = null;
|
$itemId = null;
|
||||||
$LineId = null;
|
$lineId = null;
|
||||||
$machineId = null;
|
$machineId = null;
|
||||||
$itemAgainstPlant = null;
|
// $itemAgainstPlant = null;
|
||||||
|
|
||||||
$plantCode = $this->data['plant'];
|
$plantCode = $this->data['plant'];
|
||||||
$processOrder = trim($this->data['process_order'] ?? '');
|
$processOrder = trim($this->data['process_order'] ?? '');
|
||||||
$iCode = trim($this->data['item']);
|
$iCode = trim($this->data['item']);
|
||||||
$workCenter = trim($this->data['machine']);
|
$workCenter = trim($this->data['machine']);
|
||||||
$lineName = trim($this->data['line']);
|
$lineName = trim($this->data['line']);
|
||||||
|
$coilNo = trim($this->data['coil_number']);
|
||||||
|
$obserVal = trim($this->data['observed_value']);
|
||||||
$status = trim($this->data['status']);
|
$status = trim($this->data['status']);
|
||||||
$createdBy = trim($this->data['created_by']);
|
$createdBy = trim($this->data['created_by']);
|
||||||
$coilNo = trim($this->data['coil_number']);
|
|
||||||
|
|
||||||
if ($plantCode == null || $plantCode == '') {
|
if ($plantCode == null || $plantCode == '') {
|
||||||
$warnMsg[] = 'Plant code cannot be empty';
|
$warnMsg[] = 'Plant code cannot be empty';
|
||||||
} elseif ($iCode == null || $iCode == '') {
|
} elseif ($iCode == null || $iCode == '') {// process_order
|
||||||
|
$warnMsg[] = 'Item code cannot be empty';
|
||||||
|
} elseif ($processOrder == null || $processOrder == '') {//
|
||||||
$warnMsg[] = 'Process Order cannot be empty';
|
$warnMsg[] = 'Process Order cannot be empty';
|
||||||
} elseif ($workCenter == null || $workCenter == '') {
|
} elseif ($workCenter == null || $workCenter == '') {
|
||||||
$warnMsg[] = 'Work center cannot be empty';
|
$warnMsg[] = 'Work center cannot be empty';
|
||||||
} elseif ($lineName == null || $lineName == '') {
|
} elseif ($lineName == null || $lineName == '') {
|
||||||
$warnMsg[] = 'Line cannot be empty';
|
$warnMsg[] = 'Line name cannot be empty';
|
||||||
|
} elseif ($coilNo == null || $coilNo == '') {
|
||||||
|
$warnMsg[] = 'Coil number cannot be empty';
|
||||||
|
} elseif ($obserVal == null || $obserVal == '') {
|
||||||
|
$warnMsg[] = 'Observed value cannot be empty';
|
||||||
|
} elseif ($status == null || $status == '') {
|
||||||
|
$warnMsg[] = 'Status cannot be empty';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
|
if (Str::length($plantCode) > 0 && (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode))) {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
} else {
|
} else {
|
||||||
$plant = Plant::where('code', $plantCode)->first();
|
$plant = Plant::where('code', $plantCode)->first();
|
||||||
@@ -116,7 +146,7 @@ class CharacteristicValueImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
if (Str::length($iCode) > 0 && (Str::length($iCode) < 6 || ! ctype_alnum($iCode))) {
|
||||||
$warnMsg[] = 'Invalid item code found';
|
$warnMsg[] = 'Invalid item code found';
|
||||||
} else {
|
} else {
|
||||||
$itemCode = Item::where('code', $iCode)->first();
|
$itemCode = Item::where('code', $iCode)->first();
|
||||||
@@ -124,11 +154,11 @@ class CharacteristicValueImporter extends Importer
|
|||||||
$warnMsg[] = 'Item code not found';
|
$warnMsg[] = 'Item code not found';
|
||||||
} else {
|
} else {
|
||||||
if ($plantId) {
|
if ($plantId) {
|
||||||
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||||
if (! $itemAgainstPlant) {
|
if (! $itemCode) {
|
||||||
$warnMsg[] = 'Item code not found for the given plant';
|
$warnMsg[] = 'Item code not found for the given plant';
|
||||||
} else {
|
} else {
|
||||||
$itemId = $itemAgainstPlant->id;
|
$itemId = $itemCode->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +173,7 @@ class CharacteristicValueImporter extends Importer
|
|||||||
if (! $lineAgainstPlant) {
|
if (! $lineAgainstPlant) {
|
||||||
$warnMsg[] = 'Line name not found for the given plant';
|
$warnMsg[] = 'Line name not found for the given plant';
|
||||||
} else {
|
} else {
|
||||||
$LineId = $lineAgainstPlant->id;
|
$lineId = $lineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,9 +193,9 @@ class CharacteristicValueImporter extends Importer
|
|||||||
// $MachineId = $workCenterAgainstPlant->id;
|
// $MachineId = $workCenterAgainstPlant->id;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if ($plantId != null && $LineId != null) {
|
if ($plantId != null && $lineId != null) {
|
||||||
$machineAgaPlantLine = Machine::where('plant_id', $plantId)
|
$machineAgaPlantLine = Machine::where('plant_id', $plantId)
|
||||||
->where('line_id', $LineId)
|
->where('line_id', $lineId)
|
||||||
->where('work_center', $workCenter)
|
->where('work_center', $workCenter)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -176,34 +206,66 @@ class CharacteristicValueImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($processOrder == null || $processOrder == '') {
|
if (Str::length($coilNo) > 0 && ! is_numeric($coilNo)) {
|
||||||
$warnMsg[] = 'Process Order cannot be empty';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($coilNo == null || $coilNo == '') {
|
|
||||||
$warnMsg[] = 'Coil No cannot be empty';
|
|
||||||
} elseif (! is_numeric($coilNo)) {
|
|
||||||
$warnMsg[] = 'Coil number should contain only numeric values!';
|
$warnMsg[] = 'Coil number should contain only numeric values!';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($status == null || $status == '' || ! $status) {
|
if (Str::length($obserVal) > 0 && ! is_numeric($obserVal)) {
|
||||||
$warnMsg[] = 'Status cannot be empty';
|
$warnMsg[] = 'Observed value should contain only numeric values!';
|
||||||
} elseif (! in_array($status, ['Ok', 'NotOk'], true)) {
|
}
|
||||||
|
|
||||||
|
if (Str::length($status) > 0 && ! in_array($status, ['Ok', 'NotOk'], true)) {
|
||||||
$warnMsg[] = "Status must be either 'Ok' or 'NotOk'!";
|
$warnMsg[] = "Status must be either 'Ok' or 'NotOk'!";
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// if (Str::length($status) <= 0 || ! is_numeric($status) || ! preg_match('/^\d+(\.\d+)?$/', $status)
|
||||||
|
// ) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// } else {
|
||||||
|
// $specVal = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('item_id', $itemId)->where('line_id', $lineId)->where('machine_id', $machineId)->first();
|
||||||
|
// if (! $specVal) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $lowLimit = $specVal?->lower ?? 0;
|
||||||
|
// $uppLimit = $specVal?->upper ?? 0;
|
||||||
|
|
||||||
|
// if (Str::length($lowLimit) <= 0 || ! is_numeric($lowLimit) || ! preg_match('/^\d+(\.\d+)?$/', $lowLimit)
|
||||||
|
// ) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// } elseif (Str::length($uppLimit) <= 0 || ! is_numeric($uppLimit) || ! preg_match('/^\d+(\.\d+)?$/', $uppLimit)
|
||||||
|
// ) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (($lowLimit == 0 && $uppLimit == 0) || ($uppLimit == 0)) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if ($lowLimit > $obserVal || $uppLimit < $obserVal) {
|
||||||
|
// $status = 'NotOk';
|
||||||
|
// }
|
||||||
|
// $status = 'Ok';
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if ($createdBy == null || $createdBy == '' || ! $createdBy) {
|
if ($createdBy == null || $createdBy == '' || ! $createdBy) {
|
||||||
$warnMsg[] = 'Created By cannot be empty';
|
$warnMsg[] = 'Created By cannot be empty';
|
||||||
}
|
}
|
||||||
|
|
||||||
// $existing = CharacteristicValue::where('plant_id', $plantId)
|
if ($plantId) {
|
||||||
// ->where('process_order', $processOrder)
|
$user = User::where('name', $createdBy)->first();
|
||||||
// ->where('coil_number', $coilNo)
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// if ($existing) {
|
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
|
||||||
// $warnMsg[] = "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!";
|
|
||||||
// }
|
if (! $user) {
|
||||||
|
$warnMsg[] = 'Created By user name not found!';
|
||||||
|
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||||
|
$warnMsg[] = "Created By user '{$createdBy}' not found for Plant '{$plantCode}'!";
|
||||||
|
} elseif (! $user->hasRole(['Super Admin', 'Process Quality Manager', 'Process Manager', 'Process Supervisor', 'Process Employee'])) {
|
||||||
|
$warnMsg[] = 'Created By user does not have rights!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($plantId && $processOrder) {
|
if ($plantId && $processOrder) {
|
||||||
$existing = CharacteristicValue::where('plant_id', $plantId)
|
$existing = CharacteristicValue::where('plant_id', $plantId)
|
||||||
@@ -216,31 +278,81 @@ class CharacteristicValueImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($plant && $itemCode && $processOrder != '') {
|
if ($plant && $itemCode && $processOrder != '' && $processOrder != null) {
|
||||||
|
|
||||||
$existingOrder = ProcessOrder::where('plant_id', $plant->id)
|
$existingOrder = ProcessOrder::where('plant_id', $plantId)
|
||||||
->where('process_order', $processOrder)
|
->where('process_order', $processOrder)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($existingOrder && $existingOrder->item_id !== ($itemCode->id ?? null)) {
|
if ($existingOrder && $existingOrder->item_id !== ($itemId ?? null)) {
|
||||||
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||||
|
if (! $updatedBy) {
|
||||||
|
$warnMsg[] = 'Invalid updated by user name found';
|
||||||
|
}
|
||||||
|
|
||||||
|
$fromDate = $this->data['created_at'];
|
||||||
|
$toDate = $this->data['updated_at'];
|
||||||
|
|
||||||
|
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
|
|
||||||
|
$fdateTime = null;
|
||||||
|
$tdateTime = null;
|
||||||
|
// Try parsing with multiple formats
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
try {
|
||||||
|
$fdateTime = Carbon::createFromFormat($format, $fromDate);
|
||||||
|
break;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
try {
|
||||||
|
$tdateTime = Carbon::createFromFormat($format, $toDate);
|
||||||
|
break;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($fdateTime)) {
|
||||||
|
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
|
}
|
||||||
|
if (! isset($tdateTime)) {
|
||||||
|
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($fdateTime) && isset($tdateTime)) {
|
||||||
|
if ($fdateTime->greaterThan($tdateTime)) {
|
||||||
|
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CharacteristicValue::create([
|
return CharacteristicValue::updateOrCreate([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'item_id' => $itemId,
|
'process_order' => $processOrder,
|
||||||
'line_id' => $LineId,
|
'coil_number' => $coilNo,
|
||||||
'machine_id' => $machineId,
|
],
|
||||||
'process_order' => trim($this->data['process_order']),
|
[
|
||||||
'coil_number' => trim($this->data['coil_number']),
|
'item_id' => $itemId,
|
||||||
'status' => trim($this->data['status']),
|
'line_id' => $lineId,
|
||||||
'created_by' => trim($this->data['created_by']),
|
'machine_id' => $machineId,
|
||||||
]);
|
'status' => $status,
|
||||||
|
'observed_value' => $obserVal,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
'created_at' => $fdateTime->format('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
|
||||||
// return null;
|
// return null;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Imports;
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProcessOrder;
|
use App\Models\ProcessOrder;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -27,6 +28,11 @@ class ProcessOrderImporter extends Importer
|
|||||||
->label('PLANT CODE')
|
->label('PLANT CODE')
|
||||||
->relationship(resolveUsing: 'code')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
|
ImportColumn::make('line')
|
||||||
|
->exampleHeader('LINE NAME')
|
||||||
|
->example(' Polywrapped line')
|
||||||
|
->label('LINE NAME')
|
||||||
|
->relationship(resolveUsing: 'name'),
|
||||||
ImportColumn::make('item')
|
ImportColumn::make('item')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('ITEM CODE')
|
->exampleHeader('ITEM CODE')
|
||||||
@@ -35,20 +41,57 @@ class ProcessOrderImporter extends Importer
|
|||||||
->relationship(resolveUsing: 'code')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('process_order')
|
ImportColumn::make('process_order')
|
||||||
|
->requiredMapping()
|
||||||
->exampleHeader('PROCESS ORDER')
|
->exampleHeader('PROCESS ORDER')
|
||||||
->example('202500123456')
|
->example('202500123456')
|
||||||
->label('PROCESS ORDER')
|
->label('PROCESS ORDER')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
|
ImportColumn::make('coil_number')
|
||||||
|
->exampleHeader('COIL NUMBER')
|
||||||
|
->example('01')
|
||||||
|
->label('COIL NUMBER'),
|
||||||
ImportColumn::make('order_quantity')
|
ImportColumn::make('order_quantity')
|
||||||
|
->requiredMapping()
|
||||||
->exampleHeader('ORDER QUANTITY')
|
->exampleHeader('ORDER QUANTITY')
|
||||||
->example('100')
|
->example('100')
|
||||||
->label('ORDER QUANTITY')
|
->label('ORDER QUANTITY')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
// ImportColumn::make('created_by')
|
ImportColumn::make('received_quantity')
|
||||||
// ->exampleHeader('CREATED BY')
|
->exampleHeader('RECEIVED QUANTITY')
|
||||||
// ->example('RAW01234')
|
->example('01')
|
||||||
// ->label('CREATED BY')
|
->label('RECEIVED QUANTITY'),
|
||||||
// ->rules(['required']),
|
ImportColumn::make('sfg_number')
|
||||||
|
->exampleHeader('SFG NUMBER')
|
||||||
|
->example('200000220613-72')
|
||||||
|
->label('SFG NUMBER'),
|
||||||
|
ImportColumn::make('machine_name')
|
||||||
|
->exampleHeader('MACHINE NAME')
|
||||||
|
->example('WMIWRM13 - 2-L2')
|
||||||
|
->label('MACHINE NAME'),
|
||||||
|
ImportColumn::make('scrap_quantity')
|
||||||
|
->exampleHeader('SCRAP QUANTITY')
|
||||||
|
->example('0')
|
||||||
|
->label('SCRAP QUANTITY'),
|
||||||
|
ImportColumn::make('rework_status')
|
||||||
|
->exampleHeader('REWORK STATUS')
|
||||||
|
->example('0')
|
||||||
|
->label('REWORK STATUS'),
|
||||||
|
ImportColumn::make('created_at')
|
||||||
|
->exampleHeader('CREATED AT')
|
||||||
|
->example('2026-02-20 13:00:00')
|
||||||
|
->label('CREATED AT'),
|
||||||
|
ImportColumn::make('updated_at')
|
||||||
|
->exampleHeader('UPDATED AT')
|
||||||
|
->example('2026-02-20 13:00:00')
|
||||||
|
->label('UPDATED AT'),
|
||||||
|
ImportColumn::make('created_by')
|
||||||
|
->exampleHeader('CREATED BY')
|
||||||
|
->example('RAW01234')
|
||||||
|
->label('CREATED BY'),
|
||||||
|
ImportColumn::make('updated_by')
|
||||||
|
->exampleHeader('UPDATED BY')
|
||||||
|
->example('RAW01234')
|
||||||
|
->label('UPDATED BY'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,10 +100,56 @@ class ProcessOrderImporter extends Importer
|
|||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantCod = $this->data['plant'];
|
$plantCod = $this->data['plant'];
|
||||||
$plant = null;
|
$plant = null;
|
||||||
|
$plantId = null;
|
||||||
|
$itemId = null;
|
||||||
$iCode = trim($this->data['item']);
|
$iCode = trim($this->data['item']);
|
||||||
|
$lineName = trim($this->data['line']);
|
||||||
$processOrder = trim($this->data['process_order'] ?? '');
|
$processOrder = trim($this->data['process_order'] ?? '');
|
||||||
$user = Filament::auth()->user();
|
$coilNo = trim($this->data['coil_number'] ?? '');
|
||||||
$operatorName = $user->name;
|
$sfgNo = trim($this->data['sfg_number'] ?? '');
|
||||||
|
$machineName = trim($this->data['machine_name'] ?? '');
|
||||||
|
$orderQuan = trim($this->data['order_quantity'] ?? '');
|
||||||
|
$scrapQuan = trim($this->data['scrap_quantity'] ?? '');
|
||||||
|
$reworkStatus = trim($this->data['rework_status'] ?? '');
|
||||||
|
$recQuan = trim($this->data['received_quantity'] ?? '');
|
||||||
|
$createdAt = trim($this->data['created_at'] ?? '');
|
||||||
|
$createdBy = trim($this->data['created_by'] ?? '');
|
||||||
|
$updatedAt = trim($this->data['updated_at'] ?? '');
|
||||||
|
$updatedBy = trim($this->data['updated_by'] ?? '');
|
||||||
|
// $user = Filament::auth()->user();
|
||||||
|
// $operatorName = $user->name;
|
||||||
|
|
||||||
|
if ($plantCod == null || $plantCod == '') {
|
||||||
|
$warnMsg[] = 'Plant code cannot be empty';
|
||||||
|
}
|
||||||
|
if ($iCode == null || $iCode == '') {
|
||||||
|
$warnMsg[] = 'Item code cannot be empty';
|
||||||
|
}
|
||||||
|
if ($processOrder == null || $processOrder == '') {
|
||||||
|
$warnMsg[] = 'Process order cannot be empty';
|
||||||
|
}
|
||||||
|
if ($orderQuan == null || $orderQuan == '') {
|
||||||
|
$warnMsg[] = 'Order quantity cannot be empty';
|
||||||
|
} elseif ($orderQuan == 0 || $orderQuan == '0') {
|
||||||
|
$warnMsg[] = 'Order quantity cannot be zero';
|
||||||
|
}
|
||||||
|
if ($coilNo == null || $coilNo == '') {
|
||||||
|
$coilNo = '0';
|
||||||
|
}
|
||||||
|
if ($scrapQuan == null || $scrapQuan == '') {
|
||||||
|
$scrapQuan = 0;
|
||||||
|
}
|
||||||
|
if ($recQuan == null || $recQuan == '') {
|
||||||
|
$recQuan = 0;
|
||||||
|
}
|
||||||
|
if ($reworkStatus == null || $reworkStatus = '') {
|
||||||
|
$reworkStatus = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($createdBy == null || $createdBy == '') {
|
||||||
|
$createdBy = Filament::auth()->user()?->name;
|
||||||
|
$updatedBy = $createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
@@ -68,6 +157,8 @@ class ProcessOrderImporter extends Importer
|
|||||||
$plant = Plant::where('code', $plantCod)->first();
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
if (! $plant) {
|
if (! $plant) {
|
||||||
$warnMsg[] = 'Plant not found';
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
|
$plantId = $plant->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,43 +167,169 @@ class ProcessOrderImporter extends Importer
|
|||||||
} else {
|
} else {
|
||||||
$itemCode = Item::where('code', $iCode)->first();
|
$itemCode = Item::where('code', $iCode)->first();
|
||||||
if (! $itemCode) {
|
if (! $itemCode) {
|
||||||
$warnMsg[] = 'Item Code not found';
|
$warnMsg[] = 'Item code not found';
|
||||||
|
} else {
|
||||||
|
if ($plantId) {
|
||||||
|
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||||
|
if (! $itemCode) {
|
||||||
|
$warnMsg[] = 'Item code not found for the given plant';
|
||||||
|
} else {
|
||||||
|
$itemId = $itemCode->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($processOrder == '') {
|
|
||||||
$warnMsg[] = 'Process Order cannot be empty';
|
|
||||||
}
|
|
||||||
|
|
||||||
// $user = User::where('name', $this->data['created_by'])->first();
|
|
||||||
// if (! $user) {
|
|
||||||
// $warnMsg[] = 'User not found';
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ($plant && $itemCode && $processOrder != '') {
|
if ($plant && $itemCode && $processOrder != '') {
|
||||||
|
|
||||||
$existingOrder = ProcessOrder::where('plant_id', $plant->id)
|
$existingOrder = ProcessOrder::where('plant_id', $plantId)
|
||||||
->where('process_order', $processOrder)
|
->where('process_order', $processOrder)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($existingOrder && $existingOrder->item_id !== ($itemCode->id ?? null)) {
|
if ($existingOrder && $existingOrder->item_id !== ($itemId ?? null)) {
|
||||||
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($lineName != null && $lineName != '') {
|
||||||
|
$lineExists = Line::where('name', $lineName)->first();
|
||||||
|
if (! $lineExists) {
|
||||||
|
$warnMsg[] = 'Line name not found';
|
||||||
|
} else {
|
||||||
|
if ($plantId) {
|
||||||
|
$lineAgainstPlant = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
|
||||||
|
if (! $lineAgainstPlant) {
|
||||||
|
$warnMsg[] = 'Line name not found for the given plant';
|
||||||
|
} else {
|
||||||
|
$lineId = $lineAgainstPlant->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$lineId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($createdBy != null && $createdBy != '') {
|
||||||
|
if ($plantId) {
|
||||||
|
$user = User::where('name', $createdBy)->first();
|
||||||
|
|
||||||
|
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
|
||||||
|
|
||||||
|
if (! $user) {
|
||||||
|
$warnMsg[] = 'Created By user name not found!';
|
||||||
|
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||||
|
$warnMsg[] = "Created By user '{$createdBy}' not found for Plant '{$plantCod}'!";
|
||||||
|
} elseif (! $user->hasRole(['Super Admin', 'Process Quality Manager', 'Process Manager', 'Process Supervisor', 'Process Employee'])) {
|
||||||
|
$warnMsg[] = 'Created By user does not have rights!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$updatedBy = Filament::auth()->user()?->name;
|
||||||
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProcessOrder::create([
|
if ($lineName != null && $lineName != '') {
|
||||||
'plant_id' => $plant->id,
|
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||||
'item_id' => $itemCode->id,
|
->where('process_order', $processOrder)
|
||||||
'process_order' => trim($this->data['process_order']),
|
->where('line_id', $lineId)
|
||||||
'coil_number' => '0',
|
->where('coil_number', $coilNo)
|
||||||
'order_quantity' => 0,
|
->first();
|
||||||
'received_quantity' => 0,
|
|
||||||
'created_by' => $operatorName,
|
if (! $existingCoil) {
|
||||||
]);
|
ProcessOrder::Create(
|
||||||
|
[
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'line_id' => $lineId,
|
||||||
|
'process_order' => $processOrder,
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'coil_number' => $coilNo,
|
||||||
|
'order_quantity' => $orderQuan,
|
||||||
|
'received_quantity' => $recQuan,
|
||||||
|
'scrap_quantity' => $scrapQuan,
|
||||||
|
'sfg_number' => $sfgNo,
|
||||||
|
'machine_name' => $machineName,
|
||||||
|
'rework_status' => $reworkStatus,
|
||||||
|
'created_at' => $createdAt,
|
||||||
|
'updated_at' => $updatedAt,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->where('coil_number', $coilNo)
|
||||||
|
->update([
|
||||||
|
// 'order_quantity' => $orderQty,
|
||||||
|
'received_quantity' => $recQuan,
|
||||||
|
'scrap_quantity' => $scrapQuan,
|
||||||
|
// 'sfg_number' => $sfgNo,
|
||||||
|
// 'machine_name' => $machineId,
|
||||||
|
'rework_status' => $reworkStatus,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
'updated_at' => $updatedAt,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($lineName == null || $lineName == '') {
|
||||||
|
$existing = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('coil_number', $coilNo)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $existing && $coilNo == '0' || $coilNo == 0) {
|
||||||
|
ProcessOrder::create([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'process_order' => $processOrder,
|
||||||
|
'coil_number' => '0',
|
||||||
|
'order_quantity' => $orderQuan,
|
||||||
|
'received_quantity' => 0,
|
||||||
|
'scrap_quantity' => 0,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
]);
|
||||||
|
} elseif (! $existing) {
|
||||||
|
ProcessOrder::Create(
|
||||||
|
[
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'line_id' => $lineId,
|
||||||
|
'process_order' => $processOrder,
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'coil_number' => $coilNo,
|
||||||
|
'order_quantity' => $orderQuan,
|
||||||
|
'received_quantity' => $recQuan,
|
||||||
|
'scrap_quantity' => $scrapQuan ?? 0,
|
||||||
|
'sfg_number' => $sfgNo,
|
||||||
|
'machine_name' => $machineName,
|
||||||
|
'rework_status' => $reworkStatus,
|
||||||
|
'created_at' => $createdAt,
|
||||||
|
'updated_at' => $updatedAt,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {// $coilNo = '0'
|
||||||
|
ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('coil_number', $coilNo)
|
||||||
|
->update([
|
||||||
|
// 'order_quantity' => $orderQty,
|
||||||
|
'received_quantity' => $recQuan,
|
||||||
|
'scrap_quantity' => $scrapQuan,
|
||||||
|
// 'sfg_number' => $sfgNo,
|
||||||
|
// 'machine_name' => $machineId,
|
||||||
|
'rework_status' => $reworkStatus,
|
||||||
|
'updated_by' => $updatedBy,
|
||||||
|
'updated_at' => $updatedAt,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
// return new ProcessOrder();
|
// return new ProcessOrder();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
|||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Filament\Facades\Filament;
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class ProductCharacteristicsMasterImporter extends Importer
|
class ProductCharacteristicsMasterImporter extends Importer
|
||||||
@@ -75,7 +75,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('lower')
|
ImportColumn::make('lower')
|
||||||
->exampleHeader('Lower')
|
->exampleHeader('Lower')
|
||||||
->example('-0.2')
|
->example('0')
|
||||||
->label('Lower')
|
->label('Lower')
|
||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('middle')
|
ImportColumn::make('middle')
|
||||||
@@ -86,7 +86,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('upper')
|
ImportColumn::make('upper')
|
||||||
->exampleHeader('Upper')
|
->exampleHeader('Upper')
|
||||||
->example('0.2')
|
->example('2')
|
||||||
->label('Upper')
|
->label('Upper')
|
||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('created_by')
|
ImportColumn::make('created_by')
|
||||||
@@ -103,7 +103,12 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
|
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantCod = $this->data['plant'];
|
$plantCod = $this->data['plant'];
|
||||||
$plant = null;
|
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||||
|
$lower = null;
|
||||||
|
$middle = null;
|
||||||
|
$upper = null;
|
||||||
|
$plantId = null;
|
||||||
|
$name = trim($this->data['name']);
|
||||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
} else {
|
} else {
|
||||||
@@ -111,13 +116,14 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
if (! $plant) {
|
if (! $plant) {
|
||||||
$warnMsg[] = 'Plant not found';
|
$warnMsg[] = 'Plant not found';
|
||||||
} else {
|
} else {
|
||||||
|
$plantId = $plant->id;
|
||||||
$itemExists = Item::where('code', $this->data['item'])->first();
|
$itemExists = Item::where('code', $this->data['item'])->first();
|
||||||
if (! $itemExists) {
|
if (! $itemExists) {
|
||||||
$warnMsg[] = 'Item not found';
|
$warnMsg[] = 'Item not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
if (! $itemAgainstPlant) {
|
if (! $itemAgainstPlant) {
|
||||||
$warnMsg[] = 'Item code not found for the given plant';
|
$warnMsg[] = 'Item code not found for the given plant';
|
||||||
@@ -131,7 +137,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $lineAgainstPlant) {
|
if (! $lineAgainstPlant) {
|
||||||
@@ -140,7 +146,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$LineId = $lineAgainstPlant->id;
|
$LineId = $lineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plant->id)->first();
|
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plantId)->first();
|
||||||
if (! $WorkgroupMaster) {
|
if (! $WorkgroupMaster) {
|
||||||
$warnMsg[] = 'Work Group Master value not found';
|
$warnMsg[] = 'Work Group Master value not found';
|
||||||
} else {
|
} else {
|
||||||
@@ -148,7 +154,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$workGroupMasterId = $WorkgroupMaster->id;
|
$workGroupMasterId = $WorkgroupMaster->id;
|
||||||
|
|
||||||
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
|
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
|
||||||
$existsInLine = Line::where('plant_id', $plant->id)
|
$existsInLine = Line::where('plant_id', $plantId)
|
||||||
->where(function ($q) use ($workGroupMasterId) {
|
->where(function ($q) use ($workGroupMasterId) {
|
||||||
for ($i = 1; $i <= 10; $i++) {
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
|
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
|
||||||
@@ -171,7 +177,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$machineAgainstPlant = Machine::where('work_center', $this->data['machine'])
|
$machineAgainstPlant = Machine::where('work_center', $this->data['machine'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $machineAgainstPlant) {
|
if (! $machineAgainstPlant) {
|
||||||
@@ -180,15 +186,24 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$machineId = $machineAgainstPlant->id;
|
$machineId = $machineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($name == null || $name == '') {
|
||||||
|
$warnMsg[] = "Name can't be empty";
|
||||||
|
}
|
||||||
|
|
||||||
$user = User::where('name', $this->data['created_by'])->first();
|
$user = User::where('name', $this->data['created_by'])->first();
|
||||||
if (! $user) {
|
if (! $user) {
|
||||||
$warnMsg[] = 'Operator ID not found';
|
$warnMsg[] = 'Operator ID not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||||
|
if (! $updatedBy) {
|
||||||
|
$warnMsg[] = 'Invalid updated by user name found';
|
||||||
|
}
|
||||||
|
|
||||||
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
||||||
$upper = $this->data['upper'] ?? null;
|
|
||||||
$lower = $this->data['lower'] ?? null;
|
$lower = $this->data['lower'] ?? null;
|
||||||
$middle = $this->data['middle'] ?? null;
|
$middle = $this->data['middle'] ?? null;
|
||||||
|
$upper = $this->data['upper'] ?? null;
|
||||||
|
|
||||||
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
||||||
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
||||||
@@ -203,64 +218,55 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
} else {
|
}
|
||||||
$record = ProductCharacteristicsMaster::firstOrNew([
|
|
||||||
'plant_id' => $plant->id,
|
// $record = ProductCharacteristicsMaster::firstOrNew([
|
||||||
|
// 'plant_id' => $plantId,
|
||||||
|
// 'item_id' => $itemId,
|
||||||
|
// 'line_id' => $LineId,
|
||||||
|
// 'work_group_master_id' => $workGroupMasterId,
|
||||||
|
// 'machine_id' => $machineId,
|
||||||
|
// ]);
|
||||||
|
// // If record is new, fill all fields
|
||||||
|
// if (! $record->exists) {
|
||||||
|
// $record->name = $name;
|
||||||
|
// $record->characteristics_type = $this->data['characteristics_type'];
|
||||||
|
// $record->inspection_type = $this->data['inspection_type'];
|
||||||
|
// $record->lower = $this->data['lower'] ?? null;
|
||||||
|
// $record->upper = $this->data['upper'] ?? null;
|
||||||
|
// $record->middle = $this->data['middle'] ?? null;
|
||||||
|
// $record->created_by = $this->data['created_by'] ?? null;
|
||||||
|
// $record->updated_by = $updatedBy ?? null;
|
||||||
|
// } else {
|
||||||
|
// // Record exists → update only updated_by and updated_at
|
||||||
|
// $record->updated_by = $updatedBy ?? null;
|
||||||
|
// $record->touch();
|
||||||
|
// }
|
||||||
|
// $record->save();
|
||||||
|
|
||||||
|
ProductCharacteristicsMaster::updateOrCreate(
|
||||||
|
[
|
||||||
|
'plant_id' => $plantId,
|
||||||
'item_id' => $itemId,
|
'item_id' => $itemId,
|
||||||
'line_id' => $LineId,
|
'line_id' => $LineId,
|
||||||
'work_group_master_id' => $workGroupMasterId,
|
'work_group_master_id' => $workGroupMasterId,
|
||||||
'machine_id' => $machineId,
|
'machine_id' => $machineId,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $name,
|
||||||
|
'characteristics_type' => $this->data['characteristics_type'],
|
||||||
|
'inspection_type' => $this->data['inspection_type'],
|
||||||
|
'lower' => $lower,
|
||||||
|
'middle' => $middle,
|
||||||
|
'upper' => $upper,
|
||||||
|
// 'created_by' => user ?? $this->data['created_by'],
|
||||||
|
'created_by' => $this->data['created_by'] ?? null,
|
||||||
|
'updated_by' => $updatedBy ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$currentUser = Auth::check() ? Auth::user()->name : ($this->data['created_by'] ?? 'System');
|
return null;
|
||||||
|
|
||||||
// If record is new, fill all fields
|
|
||||||
if (! $record->exists) {
|
|
||||||
$record->name = $this->data['name'];
|
|
||||||
$record->characteristics_type = $this->data['characteristics_type'];
|
|
||||||
$record->inspection_type = $this->data['inspection_type'];
|
|
||||||
$record->upper = $this->data['upper'] ?? null;
|
|
||||||
$record->lower = $this->data['lower'] ?? null;
|
|
||||||
$record->middle = $this->data['middle'] ?? null;
|
|
||||||
$record->created_by = $currentUser;
|
|
||||||
} else {
|
|
||||||
// Record exists → update only updated_by and updated_at
|
|
||||||
$record->updated_by = $currentUser;
|
|
||||||
$record->touch();
|
|
||||||
}
|
|
||||||
|
|
||||||
$record->save();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// ProductCharacteristicsMaster::updateOrCreate(
|
|
||||||
// [
|
|
||||||
// 'plant_id' => $plant->id,
|
|
||||||
// 'item_id' => $itemId,
|
|
||||||
// 'line_id' => $LineId,
|
|
||||||
// 'work_group_master_id' => $workGroupMasterId,
|
|
||||||
// 'machine_id'=> $machineId,
|
|
||||||
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'name' => $this->data['name'],
|
|
||||||
// 'characteristics_type' => $this->data['characteristics_type'],
|
|
||||||
// 'inspection_type' => $this->data['inspection_type'],
|
|
||||||
// 'upper' => $this->data['upper'] ?? null,
|
|
||||||
// 'lower' => $this->data['lower'] ?? null,
|
|
||||||
// 'middle' => $this->data['middle'] ?? null,
|
|
||||||
// //'created_by' => user ?? $this->data['created_by'],
|
|
||||||
// 'created_by' => Auth::check() ? Auth::user()->name :($this->data['created_by'] ?? null)
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return new WorkGroupMaster();
|
// return new WorkGroupMaster();
|
||||||
|
|
||||||
// return new ProductCharacteristicsMaster();
|
// return new ProductCharacteristicsMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ class StickerMasterImporter extends Importer
|
|||||||
} else {
|
} else {
|
||||||
$itemId = $item->id;
|
$itemId = $item->id;
|
||||||
|
|
||||||
if (! $laserPart1) {
|
if (! $laserPart1 && ! (Str::length($laserPart2) == 1 && is_numeric($laserPart2))) {
|
||||||
$laserPart1 = $laserPart2;
|
$laserPart1 = $laserPart2;
|
||||||
$laserPart2 = null;
|
$laserPart2 = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ class CharacteristicValueResource extends Resource
|
|||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
|
->default(function () {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(CharacteristicValue::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
@@ -412,7 +417,6 @@ class CharacteristicValueResource extends Resource
|
|||||||
// Tables\Filters\TrashedFilter::make(),
|
// Tables\Filters\TrashedFilter::make(),
|
||||||
// ])
|
// ])
|
||||||
->filters([
|
->filters([
|
||||||
|
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
Filter::make('advanced_filters')
|
Filter::make('advanced_filters')
|
||||||
->label('Advanced Filters')
|
->label('Advanced Filters')
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Models\Item;
|
|||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProcessOrder;
|
use App\Models\ProcessOrder;
|
||||||
|
use Closure;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
@@ -27,6 +28,7 @@ use Filament\Tables\Filters\Filter;
|
|||||||
use Filament\Tables\Table;
|
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 Illuminate\Validation\Rule;
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
use Smalot\PdfParser\Parser;
|
use Smalot\PdfParser\Parser;
|
||||||
use Storage;
|
use Storage;
|
||||||
@@ -56,16 +58,31 @@ class ProcessOrderResource extends Resource
|
|||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
|
->default(function () {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProcessOrder::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$set('coil_number', null);
|
$set('item_id', null);
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('item_description', null);
|
||||||
|
$set('item_uom', null);
|
||||||
|
$set('process_order', null);
|
||||||
|
$set('coil_number', '0');
|
||||||
|
$set('order_quantity', '0');
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
$set('sfg_number', null);
|
$set('sfg_number', null);
|
||||||
$set('machine_name', null);
|
$set('machine_name', null);
|
||||||
if (! $plantId) {
|
if (! $plantId) {
|
||||||
$set('poPlantError', 'Please select a plant first.');
|
$set('poPlantError', 'Please select a plant first.');
|
||||||
$set('coilNumberError', null);
|
$set('coilNumberError', null);
|
||||||
$set('sfgNumberError', null);
|
$set('sfgNumberError', null);
|
||||||
|
} else {
|
||||||
|
$set('poPlantError', null);
|
||||||
}
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
@@ -92,8 +109,10 @@ class ProcessOrderResource extends Resource
|
|||||||
$set('item_description', null);
|
$set('item_description', null);
|
||||||
$set('item_uom', null);
|
$set('item_uom', null);
|
||||||
$set('process_order', null);
|
$set('process_order', null);
|
||||||
$set('order_quantity', null);
|
$set('coil_number', '0');
|
||||||
$set('received_quantity', null);
|
$set('order_quantity', '0');
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
$set('sfg_number', null);
|
$set('sfg_number', null);
|
||||||
$set('machine_name', null);
|
$set('machine_name', null);
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
@@ -116,7 +135,13 @@ class ProcessOrderResource extends Resource
|
|||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$itemId = $get('item_id');
|
$itemId = $get('item_id');
|
||||||
// dd($plantId);
|
$set('process_order', null);
|
||||||
|
$set('coil_number', '0');
|
||||||
|
$set('order_quantity', '0');
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
|
$set('sfg_number', null);
|
||||||
|
$set('machine_name', null);
|
||||||
|
|
||||||
if ($plantId && $itemId) {
|
if ($plantId && $itemId) {
|
||||||
// Get the item code using item_id
|
// Get the item code using item_id
|
||||||
@@ -144,6 +169,7 @@ class ProcessOrderResource extends Resource
|
|||||||
|
|
||||||
Forms\Components\TextInput::make('item_description')
|
Forms\Components\TextInput::make('item_description')
|
||||||
->label('Description')
|
->label('Description')
|
||||||
|
->readOnly()
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
|
->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
|
||||||
@@ -184,21 +210,42 @@ class ProcessOrderResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->numeric()
|
->numeric()
|
||||||
->length(12)
|
->length(12)
|
||||||
|
->readOnly(fn ($get) => ($get('plant_id') == null || $get('item_id') == null || $get('line_id') == null))
|
||||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$set('coil_number', null);
|
$set('coil_number', '0');
|
||||||
|
$set('order_quantity', '0');
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
$set('sfg_number', null);
|
$set('sfg_number', null);
|
||||||
$set('machine_name', null);
|
$set('machine_name', null);
|
||||||
if (! $plantId) {
|
// if (! $plantId) {
|
||||||
$set('poPlantError', 'Please select a plant first.');
|
// $set('poPlantError', 'Please select a plant first.');
|
||||||
$set('process_order', null);
|
// $set('process_order', null);
|
||||||
$set('coilNumberError', null);
|
// $set('coilNumberError', null);
|
||||||
$set('sfgNumberError', null);
|
// $set('sfgNumberError', null);
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
$itemId = $get('item_id');
|
||||||
|
$processOrder = trim($get('process_order'));
|
||||||
|
if (! $itemId || ! $processOrder) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderExist = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('item_id', $itemId)->latest()->first();
|
||||||
|
// ->value('order_quantity') ?? 0;
|
||||||
|
|
||||||
|
if ($orderExist) {
|
||||||
|
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||||
}
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
->rule(function (callable $get) {
|
->rule(function (callable $get) {
|
||||||
return function (string $attribute, $value, \Closure $fail) use ($get) {
|
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||||
|
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$itemId = $get('item_id');
|
$itemId = $get('item_id');
|
||||||
@@ -229,54 +276,99 @@ class ProcessOrderResource extends Resource
|
|||||||
Forms\Components\TextInput::make('coil_number')
|
Forms\Components\TextInput::make('coil_number')
|
||||||
->label('Coil Number')
|
->label('Coil Number')
|
||||||
->default('0')
|
->default('0')
|
||||||
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->numeric()
|
||||||
|
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$processOrder = $get('process_order');
|
$processOrder = $get('process_order');
|
||||||
$coilNo = $get('coil_number');
|
// $coilNo = $get('coil_number');
|
||||||
if (! $plantId) {
|
if (! $plantId) {
|
||||||
$set('poPlantError', 'Please select a plant first.');
|
$set('poPlantError', 'Please select a plant first.');
|
||||||
$set('coil_number', null);
|
$set('coil_number', '0');
|
||||||
$set('sfg_number', null);
|
|
||||||
$set('machine_name', null);
|
|
||||||
$set('coilNumberError', null);
|
|
||||||
$set('sfgNumberError', null);
|
|
||||||
} elseif (! $processOrder) {
|
} elseif (! $processOrder) {
|
||||||
$set('coil_number', null);
|
|
||||||
$set('sfg_number', null);
|
|
||||||
$set('machine_name', null);
|
|
||||||
$set('poPlantError', null);
|
$set('poPlantError', null);
|
||||||
$set('coilNumberError', null);
|
$set('coil_number', '0');
|
||||||
$set('sfgNumberError', null);
|
|
||||||
} elseif ($coilNo || $coilNo == '0') {
|
|
||||||
$existing = ProcessOrder::where('plant_id', $plantId)
|
|
||||||
->where('process_order', $processOrder)
|
|
||||||
->where('coil_number', $coilNo)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($existing) {
|
|
||||||
$set('poPlantError', null);
|
|
||||||
$set('coil_number', null);
|
|
||||||
$set('coilNumberError', "Duplicate Coil : '{$coilNo}' found!");
|
|
||||||
} else {
|
|
||||||
$set('poPlantError', null);
|
|
||||||
$set('coilNumberError', null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
|
$set('sfg_number', null);
|
||||||
|
$set('machine_name', null);
|
||||||
|
$set('coilNumberError', null);
|
||||||
|
$set('sfgNumberError', null);
|
||||||
|
// elseif ($coilNo || $coilNo == 0) {
|
||||||
|
// $existing = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
// ->where('process_order', $processOrder)
|
||||||
|
// ->where('coil_number', $coilNo)
|
||||||
|
// ->first();
|
||||||
|
|
||||||
|
// if ($existing) {
|
||||||
|
// $set('poPlantError', null);
|
||||||
|
// $set('coil_number', '0');
|
||||||
|
// $set('coilNumberError', "Duplicate Coil : '{$coilNo}' found!");
|
||||||
|
// } else {
|
||||||
|
// $set('poPlantError', null);
|
||||||
|
// $set('coilNumberError', null);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
|
->rules([
|
||||||
|
function (callable $get) {
|
||||||
|
return Rule::unique('process_orders', 'coil_number')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->where('process_order', $get('process_order'))
|
||||||
|
->ignore($get('id'));
|
||||||
|
},
|
||||||
|
function (callable $get): Closure {
|
||||||
|
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||||
|
$rework = $get('rework_status');
|
||||||
|
if ($value && Str::contains($value, '.') && $rework == 0) {
|
||||||
|
$fail("Rework status should be 'Yes' for rework coil number '{$value}'!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
])
|
||||||
|
// ->rule(function (callable $get) {
|
||||||
|
// return Rule::unique('process_orders', 'coil_number')
|
||||||
|
// ->where('plant_id', $get('plant_id'))
|
||||||
|
// ->where('process_order', $get('process_order'))
|
||||||
|
// ->ignore($get('id'));
|
||||||
|
// })
|
||||||
->extraAttributes(fn ($get) => [
|
->extraAttributes(fn ($get) => [
|
||||||
'class' => $get('coilNumberError') ? 'border-red-500' : '',
|
'class' => $get('coilNumberError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('coilNumberError') ? $get('coilNumberError') : null)
|
->hint(fn ($get) => $get('coilNumberError') ? $get('coilNumberError') : null)
|
||||||
->hintColor('danger')
|
->hintColor('danger'),
|
||||||
->required(),
|
|
||||||
Forms\Components\TextInput::make('order_quantity')
|
Forms\Components\TextInput::make('order_quantity')
|
||||||
->label('Order Quantity')
|
->label('Order Quantity')
|
||||||
->default('1.000')
|
->default('1.000')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->numeric()
|
||||||
|
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
$itemId = $get('item_id');
|
||||||
|
$processOrder = trim($get('process_order'));
|
||||||
|
$set('received_quantity', '0');
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
|
if (! $plantId || ! $itemId || ! $processOrder) {
|
||||||
|
$set('order_quantity', '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('item_id', $itemId);
|
||||||
|
|
||||||
|
$orderExist = $query->latest()->first(); // Latest record (reuse base query)
|
||||||
|
|
||||||
|
if ($query->count() == 1 && $orderExist && ! $get('id')) {
|
||||||
|
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||||
|
} elseif ($query->count() > 1 && $orderExist) {
|
||||||
|
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||||
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('received_quantity')
|
Forms\Components\TextInput::make('received_quantity')
|
||||||
@@ -284,19 +376,44 @@ class ProcessOrderResource extends Resource
|
|||||||
->default('0.000')
|
->default('0.000')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->numeric()
|
||||||
|
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('scrap_quantity')
|
Forms\Components\TextInput::make('scrap_quantity')
|
||||||
->label('Scrap Quantity')
|
->label('Scrap Quantity')
|
||||||
->default('0.000')
|
->default('0.000')
|
||||||
|
->required()
|
||||||
|
->readOnly(fn ($get) => ($get('rework_status') == 0 || $get('process_order') == null))
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->numeric()
|
||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
|
$rework = $get('rework_status');
|
||||||
|
if ($rework == 0) {
|
||||||
|
$set('scrap_quantity', '0');
|
||||||
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||||
|
|
||||||
|
$rework = $get('rework_status');
|
||||||
|
$scrapQty = $value;
|
||||||
|
// $currentId = $get('id'); // current editing record id
|
||||||
|
|
||||||
|
if ($rework == 0 && $scrapQty != 0) {
|
||||||
|
$fail("Scrap Quanity value should be '0'!");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('sfg_number')
|
Forms\Components\TextInput::make('sfg_number')
|
||||||
->label('SFG Number')
|
->label('SFG Number')
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$sfgNo = $get('sfg_number');
|
$sfgNo = $get('sfg_number');
|
||||||
@@ -330,6 +447,7 @@ class ProcessOrderResource extends Resource
|
|||||||
Forms\Components\TextInput::make('machine_name')
|
Forms\Components\TextInput::make('machine_name')
|
||||||
->label('Machine ID')
|
->label('Machine ID')
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
@@ -340,11 +458,55 @@ class ProcessOrderResource extends Resource
|
|||||||
->options([0 => 'No', 1 => 'Yes'])
|
->options([0 => 'No', 1 => 'Yes'])
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
// if ($get('id') && $get('rework_status') == 1) {
|
if ($state == 0) {
|
||||||
// $set('rework_status', 1);
|
$set('scrap_quantity', '0');
|
||||||
// }
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
|
->rule(function (callable $get, callable $set) {
|
||||||
|
return function (string $attribute, $value, Closure $fail) use ($get, $set) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
$lineId = $get('line_id');
|
||||||
|
$processOrder = trim($get('process_order'));
|
||||||
|
$coilNo = trim($get('coil_number'));
|
||||||
|
$status = $value;
|
||||||
|
// $currentId = $get('id'); // current editing record id
|
||||||
|
|
||||||
|
if (! $plantId || ! $lineId || ! $processOrder || Str::length($coilNo) <= 0) {
|
||||||
|
$set('rework_status', 0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif ($status == 0) {
|
||||||
|
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('coil_number', $coilNo)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existingCoil && $existingCoil->rework_status == 1 && $get('id')) {
|
||||||
|
$fail("Rework coil number '{$coilNo}' exist against plant and process order!");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Str::length($coilNo) > 0 && ($status == 1 || Str::contains($coilNo, '.'))) {
|
||||||
|
$coilMain = explode('.', $coilNo)[0]; // 333
|
||||||
|
|
||||||
|
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('coil_number', $coilMain)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $existingCoil) {
|
||||||
|
$fail("Coil number '{$coilMain}' not exist against plant and process order!");
|
||||||
|
} elseif ($existingCoil->rework_status == 0 && ! $get('id')) {
|
||||||
|
$fail("Rework coil number '{$coilMain}' not exist against plant and process order!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
->visible(function () {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->hasRole('Super Admin'); // || Filament::auth()->user()->can('update process order rework status')
|
return Filament::auth()->user()->hasRole('Super Admin'); // || Filament::auth()->user()->can('update process order rework status')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
|
->default(function () {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProductCharacteristicsMaster::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ class StickerMasterResource extends Resource
|
|||||||
->label('Laser Part Validation 2')
|
->label('Laser Part Validation 2')
|
||||||
->nullable()
|
->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
->readOnly(fn (callable $get) => empty($get('laser_part_validation1')))
|
// ->readOnly(fn (callable $get) => empty($get('laser_part_validation1')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
@@ -625,11 +625,13 @@ class StickerMasterResource extends Resource
|
|||||||
Tables\Columns\TextColumn::make('laser_part_validation1')
|
Tables\Columns\TextColumn::make('laser_part_validation1')
|
||||||
->label('Laser Part Validation 1')
|
->label('Laser Part Validation 1')
|
||||||
->default('-')
|
->default('-')
|
||||||
->alignCenter(),
|
->alignCenter()
|
||||||
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('laser_part_validation2')
|
Tables\Columns\TextColumn::make('laser_part_validation2')
|
||||||
->label('Laser Part Validation 2')
|
->label('Laser Part Validation 2')
|
||||||
->default('-')
|
->default('-')
|
||||||
->alignCenter(),
|
->alignCenter()
|
||||||
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('panel_box_code')
|
Tables\Columns\TextColumn::make('panel_box_code')
|
||||||
->label('Panel Box Code')
|
->label('Panel Box Code')
|
||||||
->default('-')
|
->default('-')
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
"alperenersoy/filament-export": "^3.0",
|
"alperenersoy/filament-export": "^3.0",
|
||||||
"althinect/filament-spatie-roles-permissions": "^2.3",
|
"althinect/filament-spatie-roles-permissions": "^3.0",
|
||||||
"erag/laravel-pwa": "^1.9",
|
"erag/laravel-pwa": "^1.9",
|
||||||
"filament/filament": "^3.3",
|
"filament/filament": "^3.3",
|
||||||
"intervention/image": "^3.11",
|
"intervention/image": "^3.11",
|
||||||
|
|||||||
Reference in New Issue
Block a user