Added operator_id field to ProductionQuantity and QualityValidation in report filter

This commit is contained in:
dhanabalan
2025-07-30 12:32:17 +05:30
parent 0b9d0f9995
commit d1f9a3176f
2 changed files with 86 additions and 5 deletions

View File

@@ -1035,6 +1035,7 @@ class ProductionQuantityResource extends Resource
$set('Shift', null); $set('Shift', null);
$set('Item', null); $set('Item', null);
$set('sap_msg_status', null); $set('sap_msg_status', null);
$set('operator_id', null);
}), }),
//line //line
@@ -1050,7 +1051,10 @@ class ProductionQuantityResource extends Resource
return Line::where('plant_id', $plantId) return Line::where('plant_id', $plantId)
->pluck('name', 'id'); ->pluck('name', 'id');
}) })
->reactive(), ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('operator_id', null);
}),
//block //block
Select::make('Block') Select::make('Block')
@@ -1067,6 +1071,7 @@ class ProductionQuantityResource extends Resource
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Shift', null); $set('Shift', null);
$set('operator_id', null);
}), }),
//shift //shift
@@ -1085,7 +1090,10 @@ class ProductionQuantityResource extends Resource
->where('block_id', $blockId) ->where('block_id', $blockId)
->pluck('name', 'id'); ->pluck('name', 'id');
}) })
->reactive(), ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('operator_id', null);
}),
TextInput::make('production_order') TextInput::make('production_order')
->label('Production Order') ->label('Production Order')
@@ -1133,6 +1141,37 @@ class ProductionQuantityResource extends Resource
// ->options(QualityValidation::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status')) // ->options(QualityValidation::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'))
->reactive(), ->reactive(),
Select::make('operator_id')
->label('Created By')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
$lineId = $get('Line');
$shiftId = $get('Shift');
if (!$plantId && !$lineId && !$shiftId)
{
return ProductionQuantity::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && !$lineId && !$shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && $lineId && !$shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && !$lineId && $shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else// if ($plantId && $lineId && $shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
})
->searchable()
->reactive(),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
->placeholder(placeholder: 'Select From DateTime') ->placeholder(placeholder: 'Select From DateTime')
@@ -1146,7 +1185,7 @@ class ProductionQuantityResource extends Resource
->native(false), ->native(false),
]) ])
->query(function ($query, array $data) { ->query(function ($query, array $data) {
if (empty($data['Plant']) && empty($data['Shift']) && empty($data['Line']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['Item']) && empty($data['sap_msg_status']) && empty($data['created_from']) && empty($data['created_to'])) { if (empty($data['Plant']) && empty($data['Shift']) && empty($data['Line']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['Item']) && empty($data['operator_id']) && empty($data['sap_msg_status']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
@@ -1185,6 +1224,11 @@ class ProductionQuantityResource extends Resource
if ($to = $data['created_to'] ?? null) { if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to); $query->where('created_at', '<=', $to);
} }
if (!empty($data['operator_id'])) {
$query->where('operator_id', $data['operator_id']);
}
// return $query; // return $query;
}) })
->indicateUsing(function (array $data) { ->indicateUsing(function (array $data) {
@@ -1226,6 +1270,10 @@ class ProductionQuantityResource extends Resource
$indicators[] = 'To: ' . $data['created_to']; $indicators[] = 'To: ' . $data['created_to'];
} }
if (!empty($data['operator_id'])) {
$indicators[] = 'Created By: ' . $data['operator_id'];
}
return $indicators; return $indicators;
}) })
]) ])

View File

@@ -2133,6 +2133,8 @@ class QualityValidationResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('sap_msg_status', null); $set('sap_msg_status', null);
$set('Line', null);
$set('operator_id', null);
}), }),
Select::make('Line') Select::make('Line')
->label('Select Line') ->label('Select Line')
@@ -2153,6 +2155,7 @@ class QualityValidationResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('sap_msg_status', null); $set('sap_msg_status', null);
$set('operator_id', null);
}), }),
TextInput::make('production_order') TextInput::make('production_order')
->label('Production Order') ->label('Production Order')
@@ -2189,6 +2192,27 @@ class QualityValidationResource extends Resource
}) })
// ->options(QualityValidation::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status')) // ->options(QualityValidation::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'))
->reactive(), ->reactive(),
Select::make('operator_id')
->label('Created By')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
$lineId = $get('Line');
if (!$plantId && !$lineId)
{
return QualityValidation::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && !$lineId)
{
return QualityValidation::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else// if ($plantId && $lineId)
{
return QualityValidation::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
})
->searchable()
->reactive(),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
->placeholder(placeholder: 'Select From DateTime') ->placeholder(placeholder: 'Select From DateTime')
@@ -2199,10 +2223,11 @@ class QualityValidationResource extends Resource
->placeholder(placeholder: 'Select To DateTime') ->placeholder(placeholder: 'Select To DateTime')
->reactive() ->reactive()
->native(false), ->native(false),
]) ])
->query(function ($query, array $data) { ->query(function ($query, array $data) {
// Hide all records initially if no filters are applied // Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['sap_msg_status']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) { if (empty($data['Plant']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['sap_msg_status']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['operator_id']) && empty($data['sticker_master_id'])) {
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
@@ -2219,7 +2244,7 @@ class QualityValidationResource extends Resource
} }
if (!empty($data['serial_number'])) { if (!empty($data['serial_number'])) {
$query->where('serial_number',$data['serial_number']); $query->where('serial_number', $data['serial_number']);
} }
if (!empty($data['sap_msg_status'])) { if (!empty($data['sap_msg_status'])) {
@@ -2234,6 +2259,10 @@ class QualityValidationResource extends Resource
$query->where('created_at', '<=', $data['created_to']); $query->where('created_at', '<=', $data['created_to']);
} }
if (!empty($data['operator_id'])) {
$query->where('operator_id', $data['operator_id']);
}
if (!empty($data['sticker_master_id'])) { if (!empty($data['sticker_master_id'])) {
$stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id']) $stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id'])
->pluck('id') ->pluck('id')
@@ -2275,6 +2304,10 @@ class QualityValidationResource extends Resource
$indicators[] = 'To: ' . $data['created_to']; $indicators[] = 'To: ' . $data['created_to'];
} }
if (!empty($data['operator_id'])) {
$indicators[] = 'Created By: ' . $data['operator_id'];
}
if (!empty($data['sticker_master_id'])) { if (!empty($data['sticker_master_id'])) {
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown'; $itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: ' . $itemCode; $indicators[] = 'Item Codes: ' . $itemCode;