From 07100c8f12e3cd735d231d12c4b8c5496a85008c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Thu, 9 Oct 2025 15:16:52 +0200 Subject: [PATCH] production: update sorting --- .../productionSchedule/productionSchedule.js | 124 ++++++++++++------ .../productionSchedule/productionSchedule.php | 3 +- 2 files changed, 84 insertions(+), 43 deletions(-) diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js index be8f4e1e..e80084cf 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js @@ -8,7 +8,10 @@ $(document).ready(function () { return false; }, format: function (s, table, cell) { - return $(cell).find("input[id^=production-date]").val() + " " + $(cell).find("input[id^=production-time]").val() || "2222-01-01"; + if ($(cell).find("input[id^=production-date]").val() === '') { + return "2222-01-01"; + } + return $(cell).find("input[id^=production-date]").val() + " " + $(cell).find("input[id^=production-time]").val(); }, parsed: false, type: "text" @@ -60,7 +63,7 @@ $(document).ready(function () { } }, headers: { - 3: { sorter: "production_date" }, + 3: {sorter: "production_date"}, }, }); $("#allTable").bind('filterEnd', function () { @@ -73,7 +76,8 @@ $(document).ready(function () { try { localStorage.setItem('productionSchedule_sort', $("#allTable")[0].config.sortList[0][0] + "|" + $("#allTable")[0].config.sortList[0][1]); - } catch (e) {} + } catch (e) { + } updateTimeSummary(); }); setTimeout(() => { @@ -87,12 +91,13 @@ $(document).ready(function () { var tmp = sort.split("|"); $("#allTable")[0].config.sortList = [[parseInt(tmp[0]), parseInt(tmp[1])]]; $.tablesorter.sortOn($("#allTable")[0].config, [[parseInt(tmp[0]), parseInt(tmp[1])]]); - } catch (e) { } + } catch (e) { + } } }, 500); $("#selectAll").click(function () { if (this.checked) { - $(".allCheck").each(function() { + $(".allCheck").each(function () { if ($(this).closest('tr').is(':visible')) { $(this).prop('checked', true); } @@ -103,20 +108,35 @@ $(document).ready(function () { updateTimeSummary(); }); $("#duplicateBtn").click(() => duplicatePositions()); - $("#deleteBtn").click(() => { removePositions(); }); - $("#excelBtn").click(() => { exportExcel(); }); - $("#pdfBtn").click(() => { exportPDF(); }); - $("#changeDateBtn").click(() => { changeDate(); }); - $("#rawMaterialsExcelBtn").click(() => { exportRawMaterialsExcel(); }); - $("#productionBtn").click(() => { window.alert("In progress."); }); + $("#deleteBtn").click(() => { + removePositions(); + }); + $("#excelBtn").click(() => { + exportExcel(); + }); + $("#pdfBtn").click(() => { + exportPDF(); + }); + $("#changeDateBtn").click(() => { + changeDate(); + }); + $("#rawMaterialsExcelBtn").click(() => { + exportRawMaterialsExcel(); + }); + $("#productionBtn").click(() => { + window.alert("In progress."); + }); $("#createInsideOrder").click(createInsideOrder); - $(document).on('change', '.allCheck', function() { + $(document).on('change', '.allCheck', function () { updateTimeSummary(); }); }); + function SetTab(tab_name) { - if (TabsMainBlock) { return; } + if (TabsMainBlock) { + return; + } var TabMenu = document.getElementById("groupTabsPanels"); var tabs = TabMenu.getElementsByTagName("li"); for (var i = 0; i < tabs.length; i++) { @@ -142,6 +162,7 @@ function SetTab(tab_name) { if (SelectedTab === "1") { } } + function getRawMaterials() { var ids = []; $("input.allCheck:checkbox:checked").each(function () { @@ -177,6 +198,7 @@ function getRawMaterials() { } }); } + function drawRawMaterials(data) { $("#rawMaterialsTableContainer").html(rawMaterialsTablePrototype()); // TODO: tutraj czasami się wiesza @@ -190,7 +212,7 @@ function drawRawMaterials(data) { } code += ">" + el.code + ""; tr.append(code); - tr.append("" + el.name + ""); + tr.append("" + el.name + ""); tr.append("" + el.quantity + ""); tr.append("" + el.unit + ""); tr.append("" + el.stockState + ""); @@ -218,7 +240,7 @@ function drawRawMaterials(data) { $("#selectAllRawMaterials").attr('checked', false); $("#selectAllRawMaterials").click(function () { if (this.checked) { - $(".rawMaterialCheck").each(function() { + $(".rawMaterialCheck").each(function () { if ($(this).closest('tr').is(':visible')) { $(this).prop('checked', true); } @@ -229,9 +251,11 @@ function drawRawMaterials(data) { }); updateRawMaterialsPositions(); } + function rawMaterialsTablePrototype() { return '
PozycjaIndeksNazwaIlośćJM.StanAdres magazynowy
'; } + function updateRawMaterialsPositions() { var i = 0; $("#rawMaterialsTable").find("tr").each(function (index) { @@ -241,6 +265,7 @@ function updateRawMaterialsPositions() { } }); } + function editQty(id) { $("#edit-" + id).css("display", "none"); $("#qty-" + id).css("display", "none"); @@ -248,6 +273,7 @@ function editQty(id) { $("#qtyInput-" + id).select(); $("#save-" + id).css("display", "inline-block"); } + function saveQty(id) { showLoader("Trwa aktualizacja..."); $("#edit-" + id).css("display", "inline-block"); @@ -263,6 +289,7 @@ function saveQty(id) { }, }); } + function duplicatePositions() { var ids = []; $("input.allCheck:checkbox:checked").each(function () { @@ -273,7 +300,9 @@ function duplicatePositions() { return; } var userResponse = window.confirm("Zduplikować pozycje?"); - if (!userResponse) { return; } + if (!userResponse) { + return; + } showLoader("Duplikowanie..."); $.ajax({ method: "get", @@ -283,6 +312,7 @@ function duplicatePositions() { }, }); } + function removePositions() { var ids = []; $("input.allCheck:checkbox:checked").each(function () { @@ -293,17 +323,19 @@ function removePositions() { return; } var userResponse = window.confirm("Usunąć pozycje?"); - if (!userResponse) { return; } + if (!userResponse) { + return; + } showLoader("Usuwanie..."); $.ajax({ method: "get", url: $(location).attr("href") + "&to_pdf=1&ajaxAction=removePositions&ids=" + ids.join("|"), - success: function () - { + success: function () { window.location.reload(); }, }); } + function saveProductionDate(id) { let date = $("#production-date-" + id).val(); let time = $("#production-time-" + id).val(); @@ -322,7 +354,7 @@ function saveProductionDate(id) { 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"; } @@ -336,7 +368,7 @@ function saveProductionDate(id) { 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"; } @@ -352,6 +384,7 @@ function saveProductionDate(id) { url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveProductionDate&id=" + id + "&date=" + encodeURIComponent(date) + "&time=" + encodeURIComponent(time), }); } + function editDescription(id) { $("#edit-description-" + id).css("display", "none"); $("#description-" + id).css("display", "none"); @@ -359,6 +392,7 @@ function editDescription(id) { $("#descriptionInput-" + id).select(); $("#save-description-" + id).css("display", "inline-block"); } + function saveDescription(id) { $("#edit-description-" + id).css("display", "inline-block"); $("#description-" + id).css("display", "inline"); @@ -372,6 +406,7 @@ function saveDescription(id) { }, }); } + function showLoader(msg = "Pobieranie danych") { $.blockUI({ css: { @@ -388,9 +423,11 @@ function showLoader(msg = "Pobieranie danych") { message: msg }); } + function hideLoader() { $.unblockUI(); } + function exportExcel() { // Check if any rows are selected var checkedRows = $("input.allCheck:checkbox:checked").closest('tr:visible'); @@ -404,7 +441,7 @@ function exportExcel() { // Get headers (skip first checkbox column) var headers = []; - $("#allTable thead tr th").each(function(index) { + $("#allTable thead tr th").each(function (index) { if (index > 0) { headers.push($(this).text().trim()); } @@ -412,11 +449,11 @@ function exportExcel() { tableData.push(headers); // Get data from checked and visible rows - checkedRows.each(function() { + checkedRows.each(function () { var rowData = []; var $row = $(this); - $row.find('td').each(function(index) { + $row.find('td').each(function (index) { if (index > 0) { // Skip first checkbox column var $cell = $(this); var cellValue = ''; @@ -456,12 +493,13 @@ function exportExcel() { downloadFile(result.fileContent, result.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); hideLoader(); }, - error: function() { + error: function () { window.alert("Błąd podczas generowania pliku"); hideLoader(); } }); } + function exportPDF() { var ids = []; $("input.allCheck:checkbox:checked").each(function () { @@ -476,13 +514,13 @@ function exportPDF() { $.ajax({ method: "get", url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportPDF&ids=" + ids.join("|"), - success: function (response) - { + success: function (response) { downloadFile(response.fileContent, response.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); hideLoader(); }, }); } + function exportRawMaterialsExcel() { // Check if raw materials table exists if ($("#rawMaterialsTable").length === 0) { @@ -506,7 +544,7 @@ function exportRawMaterialsExcel() { // Get headers (skip first checkbox column) var headers = []; - $("#rawMaterialsTable thead tr th").each(function(index) { + $("#rawMaterialsTable thead tr th").each(function (index) { if (index > 0) { headers.push($(this).text().trim()); } @@ -514,11 +552,11 @@ function exportRawMaterialsExcel() { tableData.push(headers); // Get data from selected/visible rows - checkedRows.each(function() { + checkedRows.each(function () { var rowData = []; var $row = $(this); - $row.find('td').each(function(index) { + $row.find('td').each(function (index) { if (index > 0) { // Skip first checkbox column var $cell = $(this); var cellValue = ''; @@ -552,30 +590,32 @@ function exportRawMaterialsExcel() { downloadFile(result.fileContent, result.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); hideLoader(); }, - error: function() { + error: function () { window.alert("Błąd podczas generowania pliku"); hideLoader(); } }); } + function createInsideOrder() { var ids = []; $('input.allCheck:checkbox:checked').each(function () { - ids.push($(this).val()); + ids.push($(this).val()); }); if (ids.length === 0) { - alert('Wybierz pozycje.'); - return; + alert('Wybierz pozycje.'); + return; } var products = []; ids.forEach(el => { - const qty = parseFloat($("#qtyInput-" + el).val().trim()); - const id = $("#productId-" + el).val(); - products.push(id + "|" + qty); + const qty = parseFloat($("#qtyInput-" + el).val().trim()); + const id = $("#productId-" + el).val(); + products.push(id + "|" + qty); }); $("#insideOrderProducts").val(products.join('*')); $("#createInsideOrderForm").submit(); - } +} + function downloadFile(base64Data, fileName, mimeType) { // Stwórz blob z danych base64 const byteCharacters = atob(base64Data); @@ -605,11 +645,12 @@ function downloadFile(base64Data, fileName, mimeType) { link.click(); // Usuń link z dokumentu - setTimeout(function() { + setTimeout(function () { document.body.removeChild(link); window.URL.revokeObjectURL(link.href); }, 100); } + function updateTimeSummary() { var totalMinutes = 0; var rows; @@ -622,7 +663,7 @@ function updateTimeSummary() { rows = $('#allTable tbody tr:visible'); } - rows.each(function() { + rows.each(function () { var actionTimeCell = $(this).find('td').eq(17); var timeText = actionTimeCell.text().trim(); @@ -645,6 +686,7 @@ function updateTimeSummary() { return formattedTime; } + function changeDate() { var ids = []; $('input.allCheck:checkbox:checked').each(function () { @@ -678,7 +720,7 @@ function changeDate() { success: function () { window.location.reload(); }, - error: function() { + error: function () { window.alert("Aktualizacja nie powiodła się."); window.location.reload(); } diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php index 34ba3161..92b0767e 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.php @@ -106,7 +106,7 @@ WHERE ps.deleted = 0 "; if ($dateFrom != null && $dateTo != null) { $query .= " AND ( (DATE(ps.production_date) >= '$dateFrom' AND DATE(ps.production_date) <= '$dateTo') - OR ps.production_date IS NULL OR DATE(ps.production_date) = '0000-00-00')"; + OR ps.production_date IS NULL OR DATE(ps.production_date) = '0000-00-00 06:00:00')"; } if ($ids != null) { @@ -115,7 +115,6 @@ WHERE ps.deleted = 0 "; $query .= "GROUP BY ps.id, s.id, si.id, p.id, ps_main.id, p_main.id "; - $rows = $db->query($query); $data = array(); $i = 0;