production: time in production date
This commit is contained in:
@@ -53,6 +53,9 @@ if (!isset($_GET['ajaxAction'])) {
|
||||
case 'getRawMaterials':
|
||||
getRawMaterials($_POST['ids']);
|
||||
break;
|
||||
case 'updateProductionDate':
|
||||
updateProductionDate($_GET['ids'], $_GET['hours']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
function loadSchedulers($dateFrom = null, $dateTo = null, $ids = null)
|
||||
@@ -293,7 +296,7 @@ function saveProductionDate($id, $date, $time)
|
||||
if ($parsedDate == '1970-01-01') {
|
||||
$db->query("UPDATE productionScheduler SET production_date=NULL WHERE id='$id'");
|
||||
} else {
|
||||
$parsetDateTime = date("Y-m-d H:i", strtotime($date. ' ' . $time));
|
||||
$parsetDateTime = date("Y-m-d H:i", strtotime($date . ' ' . $time));
|
||||
$db->query("UPDATE productionScheduler SET production_date='$parsetDateTime' WHERE id='$id'");
|
||||
}
|
||||
}
|
||||
@@ -472,6 +475,7 @@ function generateUuidV4()
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||
}
|
||||
|
||||
function exportExcelWYSIWYG($tableDataJson)
|
||||
{
|
||||
if (function_exists('from_html')) {
|
||||
@@ -506,4 +510,115 @@ function exportExcelWYSIWYG($tableDataJson)
|
||||
'fileContent' => base64_encode($xlsx_content),
|
||||
'fileName' => 'harmonogram_produkcji.xlsx'
|
||||
));
|
||||
}
|
||||
}
|
||||
function updateProductionDate($ids, $hours) {
|
||||
$db = $GLOBALS['db'];
|
||||
$ids = explode("|", $ids);
|
||||
foreach ($ids as $id) {
|
||||
$res = $db->fetchByAssoc($db->query("SELECT production_date FROM productionScheduler WHERE id ='$id'"));
|
||||
|
||||
if ($res['production_date'] && $res['production_date'] != '0000-00-00 00:00:00') {
|
||||
$newDate = calculateProductionDate($res['production_date'], $hours);
|
||||
$db->query("UPDATE productionScheduler SET production_date='$newDate:00' WHERE id='$id'");
|
||||
}
|
||||
}
|
||||
}
|
||||
function calculateProductionDate($currentDateTime, $hoursToAdd) {
|
||||
$WORK_START = 6 * 60;
|
||||
$WORK_END = 14 * 60 + 30;
|
||||
|
||||
$date = new DateTime($currentDateTime);
|
||||
$totalMinutesToAdd = $hoursToAdd * 60;
|
||||
|
||||
if ($totalMinutesToAdd > 0) {
|
||||
while ($totalMinutesToAdd > 0) {
|
||||
$dayOfWeek = $date->format('w');
|
||||
if ($dayOfWeek == 0 || $dayOfWeek == 6) {
|
||||
$date = getNextWorkDay($date);
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentMinutes = $date->format('H') * 60 + $date->format('i');
|
||||
|
||||
if ($currentMinutes < $WORK_START) {
|
||||
$date->setTime(6, 0, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($currentMinutes >= $WORK_END) {
|
||||
$date = getNextWorkDay($date);
|
||||
continue;
|
||||
}
|
||||
|
||||
$remainingMinutesToday = $WORK_END - $currentMinutes;
|
||||
|
||||
if ($totalMinutesToAdd <= $remainingMinutesToday) {
|
||||
$date->modify('+' . $totalMinutesToAdd . ' minutes');
|
||||
$totalMinutesToAdd = 0;
|
||||
} else {
|
||||
$totalMinutesToAdd -= $remainingMinutesToday;
|
||||
$date = getNextWorkDay($date);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($totalMinutesToAdd < 0) {
|
||||
$totalMinutesToAdd = abs($totalMinutesToAdd);
|
||||
|
||||
while ($totalMinutesToAdd > 0) {
|
||||
$dayOfWeek = $date->format('w');
|
||||
if ($dayOfWeek == 0 || $dayOfWeek == 6) {
|
||||
$date = getPreviousWorkDay($date);
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentMinutes = $date->format('H') * 60 + $date->format('i');
|
||||
|
||||
if ($currentMinutes > $WORK_END) {
|
||||
$date->setTime(14, 30, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($currentMinutes <= $WORK_START) {
|
||||
$date = getPreviousWorkDay($date);
|
||||
continue;
|
||||
}
|
||||
|
||||
$minutesFromStart = $currentMinutes - $WORK_START;
|
||||
|
||||
if ($totalMinutesToAdd <= $minutesFromStart) {
|
||||
$date->modify('-' . $totalMinutesToAdd . ' minutes');
|
||||
$totalMinutesToAdd = 0;
|
||||
} else {
|
||||
$totalMinutesToAdd -= $minutesFromStart;
|
||||
$date = getPreviousWorkDay($date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $date->format('Y-m-d H:i');
|
||||
}
|
||||
|
||||
function getNextWorkDay($date) {
|
||||
$nextDay = clone $date;
|
||||
$nextDay->modify('+1 day');
|
||||
$nextDay->setTime(6, 0, 0);
|
||||
|
||||
while ($nextDay->format('w') == 0 || $nextDay->format('w') == 6) {
|
||||
$nextDay->modify('+1 day');
|
||||
}
|
||||
|
||||
return $nextDay;
|
||||
}
|
||||
|
||||
function getPreviousWorkDay($date) {
|
||||
$prevDay = clone $date;
|
||||
$prevDay->modify('-1 day');
|
||||
$prevDay->setTime(14, 30, 0);
|
||||
|
||||
while ($prevDay->format('w') == 0 || $prevDay->format('w') == 6) {
|
||||
$prevDay->modify('-1 day');
|
||||
}
|
||||
|
||||
return $prevDay;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user