ranjith-dev #418

Merged
jothi merged 3 commits from ranjith-dev into master 2026-02-26 19:44:27 +00:00
4 changed files with 136 additions and 113 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Exports;
use App\Models\CharacteristicValue;
use App\Models\ProductCharacteristicsMaster;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
@@ -28,6 +29,8 @@ class CharacteristicValueExporter extends Exporter
->label('LINE NAME'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
ExportColumn::make('item.description')
->label('DESCRIPTION'),
ExportColumn::make('machine.work_center')
->label('WORK CENTER'),
ExportColumn::make('process_order')
@@ -36,6 +39,18 @@ class CharacteristicValueExporter extends Exporter
->label('COIL NUMBER'),
ExportColumn::make('status')
->label('STATUS'),
ExportColumn::make('spec_value')
->label('Spec. Value')
->formatStateUsing(function ($record) {
$specVal = ProductCharacteristicsMaster::where('plant_id', $record->plant_id)
->where('item_id', $record->item_id)
->where('line_id', $record->line_id)
->where('machine_id', $record->machine_id)
->first();
return $specVal?->lower . ' - ' . $specVal?->upper;
}),
ExportColumn::make('observed_value')
->label('OBSERVED VALUE'),
ExportColumn::make('created_at')

View File

@@ -24,13 +24,13 @@ class ProcessOrderImporter extends Importer
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('PLANT CODE')
->example('1000')
->example('1200')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('line')
->exampleHeader('LINE NAME')
->example(' Polywrapped line')
->example(' Poly Wrapped Wire SFG')
->label('LINE NAME')
->relationship(resolveUsing: 'name'),
ImportColumn::make('item')
@@ -43,54 +43,54 @@ class ProcessOrderImporter extends Importer
ImportColumn::make('process_order')
->requiredMapping()
->exampleHeader('PROCESS ORDER')
->example('202500123456')
->example('2025002123456')
->label('PROCESS ORDER')
->rules(['required']),
ImportColumn::make('coil_number')
->exampleHeader('COIL NUMBER')
->example('01')
->label('COIL NUMBER'),
ImportColumn::make('order_quantity')
->requiredMapping()
->exampleHeader('ORDER QUANTITY')
->example('100')
->example('1000')
->label('ORDER QUANTITY')
->rules(['required']),
ImportColumn::make('coil_number')
->exampleHeader('COIL NUMBER')
// ->example('01')
->label('COIL NUMBER'),
ImportColumn::make('received_quantity')
->exampleHeader('RECEIVED QUANTITY')
->example('01')
// ->example('01')
->label('RECEIVED QUANTITY'),
ImportColumn::make('sfg_number')
->exampleHeader('SFG NUMBER')
->example('200000220613-72')
// ->example('200000220613-72')
->label('SFG NUMBER'),
ImportColumn::make('machine_name')
->exampleHeader('MACHINE NAME')
->example('WMIWRM13 - 2-L2')
// ->example('WMIWRM13 - 2-L2')
->label('MACHINE NAME'),
ImportColumn::make('scrap_quantity')
->exampleHeader('SCRAP QUANTITY')
->example('0')
// ->example('0')
->label('SCRAP QUANTITY'),
ImportColumn::make('rework_status')
->exampleHeader('REWORK STATUS')
->example('0')
// ->example('0')
->label('REWORK STATUS'),
ImportColumn::make('created_at')
->exampleHeader('CREATED AT')
->example('2026-02-20 13:00:00')
// ->example('2026-02-20 13:00:00')
->label('CREATED AT'),
ImportColumn::make('updated_at')
->exampleHeader('UPDATED AT')
->example('2026-02-20 13:00:00')
// ->example('2026-02-20 13:00:00')
->label('UPDATED AT'),
ImportColumn::make('created_by')
->exampleHeader('CREATED BY')
->example('RAW01234')
// ->example('RAW01234')
->label('CREATED BY'),
ImportColumn::make('updated_by')
->exampleHeader('UPDATED BY')
->example('RAW01234')
// ->example('RAW01234')
->label('UPDATED BY'),
];
}
@@ -98,12 +98,13 @@ class ProcessOrderImporter extends Importer
public function resolveRecord(): ?ProcessOrder
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
$plantCod = trim($this->data['plant']) ?? '';
$plantId = null;
$item = null;
$iCode = trim($this->data['item']) ?? '';
$itemId = null;
$iCode = trim($this->data['item']);
$lineName = trim($this->data['line']);
$lineNam = trim($this->data['line']) ?? '';
$processOrder = trim($this->data['process_order'] ?? '');
$coilNo = trim($this->data['coil_number'] ?? '');
$sfgNo = trim($this->data['sfg_number'] ?? '');
@@ -120,18 +121,27 @@ class ProcessOrderImporter extends Importer
// $operatorName = $user->name;
if ($plantCod == null || $plantCod == '') {
$warnMsg[] = 'Plant code cannot be empty';
$warnMsg[] = "Plant code can't be empty!";
} elseif (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
}
if ($iCode == null || $iCode == '') {
$warnMsg[] = 'Item code cannot be empty';
$warnMsg[] = "Item code can't be empty!";
} elseif (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
}
if ($processOrder == null || $processOrder == '') {
$warnMsg[] = 'Process order cannot be empty';
$warnMsg[] = "Process order can't be empty!";
}
if ($lineNam == null || $lineNam == '') {
$warnMsg[] = "Line name can't be empty!";
}
if ($orderQuan == null || $orderQuan == '') {
$warnMsg[] = 'Order quantity cannot be empty';
$warnMsg[] = "Order quantity can't be empty!";
} elseif ($orderQuan == 0 || $orderQuan == '0') {
$warnMsg[] = 'Order quantity cannot be zero';
$warnMsg[] = "Order quantity can't be zero!";
} elseif (Str::length($orderQuan) >= 1 && ! is_numeric($orderQuan)) {
$warnMsg[] = 'Invalid order quantity found!';
}
if ($coilNo == null || $coilNo == '') {
$coilNo = '0';
@@ -150,37 +160,46 @@ class ProcessOrderImporter extends Importer
$warnMsg[] = 'Invalid rework status found';
}
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plantId = $plant->id;
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found!';
} else {
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$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;
}
$plantId = $plant->id;
}
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$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 ($plant && $itemCode && $processOrder != '') {
$lineExists = Line::where('name', $lineNam)->first();
if (! $lineExists) {
$warnMsg[] = 'Line name not found!';
} else {
if ($plantId) {
$lineAgainstPlant = Line::where('name', $lineNam)->where('plant_id', $plantId)->first();
if (! $lineAgainstPlant) {
$warnMsg[] = 'Line name not found for the given plant!';
} else {
$lineId = $lineAgainstPlant->id;
}
}
}
if ($plantId && $itemCode && $lineId && $processOrder != '') {
$existingOrder = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->first();
@@ -190,27 +209,9 @@ class ProcessOrderImporter extends Importer
}
}
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;
}
// $user = User::where('name', $this->data['created_by'])->first();
// if (! $user) {
// $warnMsg[] = 'User not found';
// $warnMsg[] = 'User not found!';
// }
if (! $createdBy) {
@@ -224,7 +225,7 @@ class ProcessOrderImporter extends Importer
throw new RowImportFailedException(implode(', ', $warnMsg));
}
if ($lineName != null && $lineName != '') {
if ($coilNo != null && $coilNo != '' && $scrapQuan && $reworkStatus && $recQuan && $createdAt && $createdBy && $updatedAt && $updatedBy && Filament::auth()->user()->hasRole('Super Admin')) {
$existingCoil = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineId)
@@ -267,11 +268,11 @@ class ProcessOrderImporter extends Importer
'updated_at' => $updatedAt,
]);
}
} elseif ($lineName == null || $lineName == '') {
} else {
$coilNo = '0';
$existing = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('coil_number', $coilNo)
// ->where('coil_number', $coilNo)
->first();
if (! $existing && ($coilNo == '0' || $coilNo == 0)) {
@@ -308,23 +309,25 @@ class ProcessOrderImporter extends Importer
]
);
} else {// $coilNo = '0'
if ($existing->rework_status == 1 && $reworkStatus == 0) {
if ($existing->process_order == $processOrder) {
throw new RowImportFailedException('Process order already exist for the given plant!');
} elseif ($existing->rework_status == 1 && $reworkStatus == 0) {
throw new RowImportFailedException('Rework coil number already exist for the given Plant and Process Order!');
} else {
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,
]);
}
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,
]);
}
}

View File

@@ -12,6 +12,7 @@ use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
@@ -45,6 +46,7 @@ class GrMasterResource extends Resource
->reactive()
->searchable()
->relationship('plant', 'name')
->disabled(fn (Get $get) => ! empty($get('id')))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
@@ -56,6 +58,7 @@ class GrMasterResource extends Resource
// ->relationship('item', 'id')
->reactive()
->searchable()
->disabled(fn (Get $get) => ! empty($get('id')))
->options(function (callable $get) {
$plantId = $get('plant_id');
if (empty($plantId)) {

View File

@@ -2279,42 +2279,44 @@ class CharacteristicsController extends Controller
$charMasters = ProductCharacteristicsMaster::with('workGroupMaster')->where('plant_id', $plantId)->where('item_id', $ItemId)->where('line_id', $lineId)->where('machine_id', $machineId)->get(); // ->select(['name', 'characteristics_type', 'inspection_type', 'lower', 'middle', 'upper', 'work_group_master_id'])
if (! $charMasters) {
if ($charMasters->count() <= 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Characteristics not found in product master table for the plant : '$plant->name'!",
], 404);
} else {
$output = $charMasters->map(function ($charMast) {
$charMaster = [
'work_group_master' => optional($charMast->workGroupMaster)->name ?? '',
'name' => $charMast?->name ?? '',
'characteristics_type' => $charMast?->characteristics_type ?? '',
'inspection_type' => $charMast?->inspection_type ?? '',
'lower' => (string) $charMast?->lower ?? '',
'middle' => (string) $charMast?->middle ?? '',
'upper' => (string) $charMast?->upper ?? '',
if ($charMasters->count() == 1) {
$charMasters = ProductCharacteristicsMaster::with('workGroupMaster')->where('plant_id', $plantId)->where('item_id', $ItemId)->where('line_id', $lineId)->where('machine_id', $machineId)->first();
// $workGroup = WorkGroupMaster::find($charMasters->work_group_master_id);
// $workGroupName = $workGroup?->name ?? '';
$output = [
'work_group_master' => $charMasters?->workGroupMaster->name ?? '', // $workGroupName ?? '',
'name' => $charMasters?->name ?? '',
'characteristics_type' => $charMasters?->characteristics_type ?? '',
'inspection_type' => $charMasters?->inspection_type ?? '',
'lower' => (string) $charMasters?->lower ?? '',
'middle' => (string) $charMasters?->middle ?? '',
'upper' => (string) $charMasters?->upper ?? '',
];
} else {
$output = $charMasters->map(function ($charMast) {
$charMaster = [
'work_group_master' => $charMast?->workGroupMaster->name ?? '', // optional($charMast->workGroupMaster)->name ?? '',
'name' => $charMast?->name ?? '',
'characteristics_type' => $charMast?->characteristics_type ?? '',
'inspection_type' => $charMast?->inspection_type ?? '',
'lower' => (string) $charMast?->lower ?? '',
'middle' => (string) $charMast?->middle ?? '',
'upper' => (string) $charMast?->upper ?? '',
];
return $charMaster;
});
return $charMaster;
});
}
}
// $charMasters = ProductCharacteristicsMaster::with('workGroupMaster')->where('plant_id', $plantId)->where('item_id', $ItemId)->where('line_id', $lineId)->where('machine_id', $machineId)->first();
// // $workGroup = WorkGroupMaster::find($charMasters->work_group_master_id);
// // $workGroupName = $workGroup?->name ?? '';
// $output = [
// 'work_group_master' => $charMasters?->workGroupMaster->name ?? '', // $workGroupName ?? '',
// 'name' => $charMasters?->name ?? '',
// 'characteristics_type' => $charMasters?->characteristics_type ?? '',
// 'inspection_type' => $charMasters?->inspection_type ?? '',
// 'lower' => (string) $charMasters?->lower ?? '',
// 'middle' => (string) $charMasters?->middle ?? '',
// 'upper' => (string) $charMasters?->upper ?? '',
// ];
return response()->json($output, 200);
}