Compare commits
3 Commits
ba9e85a4e9
...
1ebada1787
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ebada1787 | ||
|
|
d107f1be18 | ||
|
|
9ce3b34f75 |
@@ -154,17 +154,22 @@ class ProductionPlanResource extends Resource
|
||||
// $currentPath = url()->current();
|
||||
// $currentPath = $_SERVER['REQUEST_URI'];
|
||||
// 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('line_id', $get('line_id'))
|
||||
->whereDate('created_at', today())
|
||||
->exists();
|
||||
|
||||
if ($exists)
|
||||
{
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Production plan already updated.');
|
||||
return;
|
||||
if ($exists)
|
||||
{
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Production plan already updated.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$set('ppLineError', null);
|
||||
}
|
||||
@@ -203,6 +208,9 @@ class ProductionPlanResource extends Resource
|
||||
->label('Production Quantity')
|
||||
->readOnly()
|
||||
->default(0),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
|
||||
@@ -41,7 +41,6 @@ class ShiftResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('block_id', null);
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$plantId) {
|
||||
$set('sPlantError', 'Please select a plant first.');
|
||||
return;
|
||||
@@ -79,7 +78,6 @@ class ShiftResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$blockId = $get('block_id');
|
||||
$set('name', null);
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$blockId) {
|
||||
$set('sBlockError', 'Please select a block first.');
|
||||
return;
|
||||
@@ -101,7 +99,6 @@ class ShiftResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$nameId = $get('name');
|
||||
$set('start_time', null);
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
$set('sNameError', 'Scan the valid name.');
|
||||
return;
|
||||
@@ -128,7 +125,6 @@ class ShiftResource extends Resource
|
||||
$nameId = $get('start_time');
|
||||
// $set('duration', null);
|
||||
$set('end_time', self::calculateEndTime($state, $get('duration')));
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
$set('sStartTimeError', 'Choose the valid start time.');
|
||||
return;
|
||||
@@ -158,7 +154,6 @@ class ShiftResource extends Resource
|
||||
$duration = $get('duration');
|
||||
// $set('end_time', null);
|
||||
$set('end_time', self::calculateEndTime($get('start_time'), $state));
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$duration) {
|
||||
$set('sDurationError', 'Scan the valid duration.');
|
||||
return;
|
||||
@@ -182,7 +177,6 @@ class ShiftResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$endTime = $get('end_time');
|
||||
$set('end_time', self::calculateEndTime($get('start_time'), $state));
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$endTime) {
|
||||
$set('sEndTimeError', 'Choose the valid start time & duration.');
|
||||
return;
|
||||
@@ -282,34 +276,32 @@ class ShiftResource extends Resource
|
||||
}
|
||||
|
||||
protected static function calculateEndTime(?string $startTime, ?string $duration): ?string
|
||||
{
|
||||
if (!$startTime || !$duration) {
|
||||
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
|
||||
{
|
||||
if (!$startTime || !$duration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Extract hours and minutes correctly
|
||||
[$hours, $decimalMinutes] = explode('.', $duration) + [0, 0]; // Ensure two parts
|
||||
$hours = (int) $hours; // Convert to integer hours
|
||||
$minutes = (int) $decimalMinutes; // Directly use decimal part as minutes
|
||||
try {
|
||||
// Convert start_time to Carbon instance
|
||||
$startTimeCarbon = Carbon::createFromFormat('H:i:s', $startTime);
|
||||
|
||||
// Calculate end time
|
||||
$endTimeCarbon = $startTimeCarbon->addHours($hours)->addMinutes($minutes);
|
||||
// Ensure duration is in a valid numeric format
|
||||
$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
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
// Extract hours and minutes correctly
|
||||
[$hours, $decimalMinutes] = explode('.', $duration) + [0, 0]; // Ensure two parts
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user