production: time in production date
This commit is contained in:
@@ -106,6 +106,7 @@ $(document).ready(function () {
|
|||||||
$("#deleteBtn").click(() => { removePositions(); });
|
$("#deleteBtn").click(() => { removePositions(); });
|
||||||
$("#excelBtn").click(() => { exportExcel(); });
|
$("#excelBtn").click(() => { exportExcel(); });
|
||||||
$("#pdfBtn").click(() => { exportPDF(); });
|
$("#pdfBtn").click(() => { exportPDF(); });
|
||||||
|
$("#changeDateBtn").click(() => { changeDate(); });
|
||||||
$("#rawMaterialsExcelBtn").click(() => { exportRawMaterialsExcel(); });
|
$("#rawMaterialsExcelBtn").click(() => { exportRawMaterialsExcel(); });
|
||||||
$("#productionBtn").click(() => { window.alert("In progress."); });
|
$("#productionBtn").click(() => { window.alert("In progress."); });
|
||||||
$("#createInsideOrder").click(createInsideOrder);
|
$("#createInsideOrder").click(createInsideOrder);
|
||||||
@@ -314,17 +315,31 @@ function saveProductionDate(id) {
|
|||||||
time = '';
|
time = '';
|
||||||
} else {
|
} else {
|
||||||
if (time.length === 5) {
|
if (time.length === 5) {
|
||||||
// Sprawdź format HH:mm
|
const timeRegex = /^([0-5]?[0-9]|1[0-3]):[0-5][0-9]$|^14:[0-2][0-9]$|^14:30$/;
|
||||||
const timeRegex = /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/;
|
|
||||||
if (!timeRegex.test(time)) {
|
if (!timeRegex.test(time)) {
|
||||||
time = "06:00";
|
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) {
|
} else if (time.length === 4) {
|
||||||
// Wstaw : pomiędzy i sprawdź format
|
|
||||||
time = time.substring(0, 2) + ":" + time.substring(2);
|
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)) {
|
if (!timeRegex.test(time)) {
|
||||||
time = "06:00";
|
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 {
|
} else {
|
||||||
time = "06:00";
|
time = "06:00";
|
||||||
@@ -630,3 +645,42 @@ function updateTimeSummary() {
|
|||||||
|
|
||||||
return formattedTime;
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -53,6 +53,9 @@ if (!isset($_GET['ajaxAction'])) {
|
|||||||
case 'getRawMaterials':
|
case 'getRawMaterials':
|
||||||
getRawMaterials($_POST['ids']);
|
getRawMaterials($_POST['ids']);
|
||||||
break;
|
break;
|
||||||
|
case 'updateProductionDate':
|
||||||
|
updateProductionDate($_GET['ids'], $_GET['hours']);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function loadSchedulers($dateFrom = null, $dateTo = null, $ids = null)
|
function loadSchedulers($dateFrom = null, $dateTo = null, $ids = null)
|
||||||
@@ -472,6 +475,7 @@ function generateUuidV4()
|
|||||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportExcelWYSIWYG($tableDataJson)
|
function exportExcelWYSIWYG($tableDataJson)
|
||||||
{
|
{
|
||||||
if (function_exists('from_html')) {
|
if (function_exists('from_html')) {
|
||||||
@@ -507,3 +511,114 @@ function exportExcelWYSIWYG($tableDataJson)
|
|||||||
'fileName' => 'harmonogram_produkcji.xlsx'
|
'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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@
|
|||||||
<input class="button" id="excelBtn" value="Excel" type="button">
|
<input class="button" id="excelBtn" value="Excel" type="button">
|
||||||
<input class="button" id="pdfBtn" value="PDF" type="button">
|
<input class="button" id="pdfBtn" value="PDF" type="button">
|
||||||
<input class="button" value="Utwórz przyjęcie produkcyjne" type="button" id="createInsideOrder"/>
|
<input class="button" value="Utwórz przyjęcie produkcyjne" type="button" id="createInsideOrder"/>
|
||||||
|
<input class="button" id="changeDateBtn" value="Aktualizuj datę produkcji" type="button">
|
||||||
<table id="allTable">
|
<table id="allTable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user