production: update sorting

This commit is contained in:
Michał Zieliński
2025-10-09 15:16:52 +02:00
parent c02009ad63
commit 07100c8f12
2 changed files with 84 additions and 43 deletions

View File

@@ -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"
@@ -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,7 +91,8 @@ $(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 () {
@@ -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 () {
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
@@ -229,9 +251,11 @@ function drawRawMaterials(data) {
});
updateRawMaterialsPositions();
}
function rawMaterialsTablePrototype() {
return '<table id="rawMaterialsTable"><thead><tr><th class="filter-false"><input type="checkbox" id="selectAllRawMaterials" /></th><th>Pozycja</th><th>Indeks</th><th>Nazwa</th><th>Ilość</th><th>JM.</th><th>Stan</th><th>Adres magazynowy</th></tr></thead><tbody aria-live="polite" aria-relevant="all"></tbody></table>';
}
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();
@@ -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');
@@ -462,6 +499,7 @@ function exportExcel() {
}
});
}
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) {
@@ -558,6 +596,7 @@ function exportRawMaterialsExcel() {
}
});
}
function createInsideOrder() {
var ids = [];
$('input.allCheck:checkbox:checked').each(function () {
@@ -576,6 +615,7 @@ function createInsideOrder() {
$("#insideOrderProducts").val(products.join('*'));
$("#createInsideOrderForm").submit();
}
function downloadFile(base64Data, fileName, mimeType) {
// Stwórz blob z danych base64
const byteCharacters = atob(base64Data);
@@ -610,6 +650,7 @@ function downloadFile(base64Data, fileName, mimeType) {
window.URL.revokeObjectURL(link.href);
}, 100);
}
function updateTimeSummary() {
var totalMinutes = 0;
var rows;
@@ -645,6 +686,7 @@ function updateTimeSummary() {
return formattedTime;
}
function changeDate() {
var ids = [];
$('input.allCheck:checkbox:checked').each(function () {

View File

@@ -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;