3 Commits

Author SHA1 Message Date
dhanabalan
1ebada1787 ID column added to run update func in Production Plan Resource 2025-03-31 21:25:04 +05:30
dhanabalan
d107f1be18 Removed commented text in shift resource 2025-03-31 21:23:21 +05:30
dhanabalan
9ce3b34f75 Unwanted white space in shift resource 2025-03-31 21:18:01 +05:30
2 changed files with 37 additions and 37 deletions

View File

@@ -154,17 +154,22 @@ class ProductionPlanResource extends Resource
// $currentPath = url()->current(); // $currentPath = url()->current();
// $currentPath = $_SERVER['REQUEST_URI']; // $currentPath = $_SERVER['REQUEST_URI'];
// dd($currentPath); // dd($currentPath);
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
$isUpdate = !empty($get('id'));
if (!$isUpdate)
{
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id')) ->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id')) ->where('line_id', $get('line_id'))
->whereDate('created_at', today()) ->whereDate('created_at', today())
->exists(); ->exists();
if ($exists) if ($exists)
{ {
$set('line_id', null); $set('line_id', null);
$set('ppLineError', 'Production plan already updated.'); $set('ppLineError', 'Production plan already updated.');
return; return;
}
} }
$set('ppLineError', null); $set('ppLineError', null);
} }
@@ -203,6 +208,9 @@ class ProductionPlanResource extends Resource
->label('Production Quantity') ->label('Production Quantity')
->readOnly() ->readOnly()
->default(0), ->default(0),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]) ])
->columns(2), ->columns(2),
]); ]);

View File

@@ -41,7 +41,6 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$set('block_id', null); $set('block_id', null);
// Ensure `linestop_id` is not cleared
if (!$plantId) { if (!$plantId) {
$set('sPlantError', 'Please select a plant first.'); $set('sPlantError', 'Please select a plant first.');
return; return;
@@ -79,7 +78,6 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$blockId = $get('block_id'); $blockId = $get('block_id');
$set('name', null); $set('name', null);
// Ensure `linestop_id` is not cleared
if (!$blockId) { if (!$blockId) {
$set('sBlockError', 'Please select a block first.'); $set('sBlockError', 'Please select a block first.');
return; return;
@@ -101,7 +99,6 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name'); $nameId = $get('name');
$set('start_time', null); $set('start_time', null);
// Ensure `linestop_id` is not cleared
if (!$nameId) { if (!$nameId) {
$set('sNameError', 'Scan the valid name.'); $set('sNameError', 'Scan the valid name.');
return; return;
@@ -128,7 +125,6 @@ class ShiftResource extends Resource
$nameId = $get('start_time'); $nameId = $get('start_time');
// $set('duration', null); // $set('duration', null);
$set('end_time', self::calculateEndTime($state, $get('duration'))); $set('end_time', self::calculateEndTime($state, $get('duration')));
// Ensure `linestop_id` is not cleared
if (!$nameId) { if (!$nameId) {
$set('sStartTimeError', 'Choose the valid start time.'); $set('sStartTimeError', 'Choose the valid start time.');
return; return;
@@ -158,7 +154,6 @@ class ShiftResource extends Resource
$duration = $get('duration'); $duration = $get('duration');
// $set('end_time', null); // $set('end_time', null);
$set('end_time', self::calculateEndTime($get('start_time'), $state)); $set('end_time', self::calculateEndTime($get('start_time'), $state));
// Ensure `linestop_id` is not cleared
if (!$duration) { if (!$duration) {
$set('sDurationError', 'Scan the valid duration.'); $set('sDurationError', 'Scan the valid duration.');
return; return;
@@ -182,7 +177,6 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$endTime = $get('end_time'); $endTime = $get('end_time');
$set('end_time', self::calculateEndTime($get('start_time'), $state)); $set('end_time', self::calculateEndTime($get('start_time'), $state));
// Ensure `linestop_id` is not cleared
if (!$endTime) { if (!$endTime) {
$set('sEndTimeError', 'Choose the valid start time & duration.'); $set('sEndTimeError', 'Choose the valid start time & duration.');
return; return;
@@ -282,34 +276,32 @@ class ShiftResource extends Resource
} }
protected static function calculateEndTime(?string $startTime, ?string $duration): ?string protected static function calculateEndTime(?string $startTime, ?string $duration): ?string
{ {
if (!$startTime || !$duration) { if (!$startTime || !$duration) {
return null; return null;
}
try {
// Convert start_time to Carbon instance
$startTimeCarbon = Carbon::createFromFormat('H:i:s', $startTime);
// Ensure duration is in a valid numeric format
$duration = str_replace(',', '.', $duration); // Handle decimal formats
if (!is_numeric($duration)) {
return null; // Invalid duration format
} }
// Extract hours and minutes correctly try {
[$hours, $decimalMinutes] = explode('.', $duration) + [0, 0]; // Ensure two parts // Convert start_time to Carbon instance
$hours = (int) $hours; // Convert to integer hours $startTimeCarbon = Carbon::createFromFormat('H:i:s', $startTime);
$minutes = (int) $decimalMinutes; // Directly use decimal part as minutes
// Calculate end time // Ensure duration is in a valid numeric format
$endTimeCarbon = $startTimeCarbon->addHours($hours)->addMinutes($minutes); $duration = str_replace(',', '.', $duration); // Handle decimal formats
if (!is_numeric($duration)) {
return null; // Invalid duration format
}
return $endTimeCarbon->format('H:i:s'); // Return formatted end time // Extract hours and minutes correctly
} catch (\Exception $e) { [$hours, $decimalMinutes] = explode('.', $duration) + [0, 0]; // Ensure two parts
return null; $hours = (int) $hours; // Convert to integer hours
$minutes = (int) $decimalMinutes; // Directly use decimal part as minutes
// Calculate end time
$endTimeCarbon = $startTimeCarbon->addHours($hours)->addMinutes($minutes);
return $endTimeCarbon->format('H:i:s'); // Return formatted end time
} catch (\Exception $e) {
return null;
}
} }
} }
}