From 4374f2cd65438b4bf4f7ab5a1fc89e518599dc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Tue, 7 Oct 2025 17:54:59 +0200 Subject: [PATCH] production: time in production date --- .../productionSchedule/productionSchedule.js | 62 ++++++++- .../productionSchedule/productionSchedule.php | 119 +++++++++++++++++- .../productionSchedule/productionSchedule.tpl | 1 + 3 files changed, 176 insertions(+), 6 deletions(-) diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js index 30d66dab..be8f4e1e 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js @@ -106,6 +106,7 @@ $(document).ready(function () { $("#deleteBtn").click(() => { removePositions(); }); $("#excelBtn").click(() => { exportExcel(); }); $("#pdfBtn").click(() => { exportPDF(); }); + $("#changeDateBtn").click(() => { changeDate(); }); $("#rawMaterialsExcelBtn").click(() => { exportRawMaterialsExcel(); }); $("#productionBtn").click(() => { window.alert("In progress."); }); $("#createInsideOrder").click(createInsideOrder); @@ -314,17 +315,31 @@ function saveProductionDate(id) { time = ''; } else { if (time.length === 5) { - // Sprawdź format HH:mm - const timeRegex = /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/; + const timeRegex = /^([0-5]?[0-9]|1[0-3]):[0-5][0-9]$|^14:[0-2][0-9]$|^14:30$/; if (!timeRegex.test(time)) { time = "06:00"; + } else { + const timeParts = time.split(':'); + const hours = parseInt(timeParts[0], 10); + const minutes = parseInt(timeParts[1], 10); + + if (hours < 6 || (hours === 14 && minutes > 30) || hours > 14) { + time = "06:00"; + } } } else if (time.length === 4) { - // Wstaw : pomiędzy i sprawdź format time = time.substring(0, 2) + ":" + time.substring(2); - const timeRegex = /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/; + const timeRegex = /^([0-5]?[0-9]|1[0-3]):[0-5][0-9]$|^14:[0-2][0-9]$|^14:30$/; if (!timeRegex.test(time)) { time = "06:00"; + } else { + const timeParts = time.split(':'); + const hours = parseInt(timeParts[0], 10); + const minutes = parseInt(timeParts[1], 10); + + if (hours < 6 || (hours === 14 && minutes > 30) || hours > 14) { + time = "06:00"; + } } } else { time = "06:00"; @@ -630,3 +645,42 @@ function updateTimeSummary() { return formattedTime; } +function changeDate() { + var ids = []; + $('input.allCheck:checkbox:checked').each(function () { + ids.push($(this).val()); + }); + if (ids.length === 0) { + alert('Wybierz pozycje.'); + return; + } + let hours = prompt("Podaj ilość godzin:"); + if (hours === null) { + return null; // no response + } + hours = parseFloat(hours); + if (hours === "") { + window.alert("Niepoprawna wartość (-100 : 100)"); + return null; + } + const hoursNum = parseFloat(hours); + if (isNaN(hoursNum)) { + window.alert("Niepoprawna wartość (-100 : 100)"); + return null; + } + if (hoursNum < -100 || hoursNum > 100) { + window.alert("Niepoprawna wartość (-100 : 100)"); + return null; + } + $.ajax({ + method: "get", + url: $(location).attr("href") + "&to_pdf=1&ajaxAction=updateProductionDate&ids=" + ids.join("|") + "&hours=" + hoursNum, + success: function () { + window.location.reload(); + }, + error: function() { + window.alert("Aktualizacja nie powiodła się."); + window.location.reload(); + } + }); +} \ No newline at end of file diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php index 9aa589ef..77b3012d 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php @@ -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' )); -} \ No newline at end of file +} +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; +} + diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.tpl b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.tpl index dff21ebc..f7d11fa7 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.tpl +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.tpl @@ -133,6 +133,7 @@ +