production: excel export fix
This commit is contained in:
@@ -106,6 +106,7 @@ $(document).ready(function () {
|
||||
$("#deleteBtn").click(() => { removePositions(); });
|
||||
$("#excelBtn").click(() => { exportExcel(); });
|
||||
$("#pdfBtn").click(() => { exportPDF(); });
|
||||
$("#rawMaterialsExcelBtn").click(() => { exportRawMaterialsExcel(); });
|
||||
$("#productionBtn").click(() => { window.alert("In progress."); });
|
||||
$("#createInsideOrder").click(createInsideOrder);
|
||||
$(document).on('change', '.allCheck', function() {
|
||||
@@ -348,24 +349,74 @@ function hideLoader() {
|
||||
$.unblockUI();
|
||||
}
|
||||
function exportExcel() {
|
||||
var ids = [];
|
||||
$("input.allCheck:checkbox:checked").each(function () {
|
||||
ids.push($(this).val());
|
||||
});
|
||||
if (ids.length === 0) {
|
||||
$("input.allCheck:checkbox").each(function () {
|
||||
ids.push($(this).val());
|
||||
});
|
||||
// Check if any rows are selected
|
||||
var checkedRows = $("input.allCheck:checkbox:checked").closest('tr:visible');
|
||||
if (checkedRows.length === 0) {
|
||||
window.alert("Wybierz pozycje do eksportu");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get table data from selected rows only
|
||||
var tableData = [];
|
||||
|
||||
// Get headers (skip first checkbox column)
|
||||
var headers = [];
|
||||
$("#allTable thead tr th").each(function(index) {
|
||||
if (index > 0) {
|
||||
headers.push($(this).text().trim());
|
||||
}
|
||||
});
|
||||
tableData.push(headers);
|
||||
|
||||
// Get data from checked and visible rows
|
||||
checkedRows.each(function() {
|
||||
var rowData = [];
|
||||
var $row = $(this);
|
||||
|
||||
$row.find('td').each(function(index) {
|
||||
if (index > 0) { // Skip first checkbox column
|
||||
var $cell = $(this);
|
||||
var cellValue = '';
|
||||
|
||||
// Check for input fields (like production date)
|
||||
var $input = $cell.find('input[type="text"], input[type="number"]');
|
||||
if ($input.length > 0) {
|
||||
cellValue = $input.val() || '';
|
||||
} else {
|
||||
// Check for editable divs (like qty, description)
|
||||
var $editableDiv = $cell.find('div[id^="qty-"], div[id^="description-"]');
|
||||
if ($editableDiv.length > 0) {
|
||||
cellValue = $editableDiv.text().trim();
|
||||
} else {
|
||||
// Regular cell text
|
||||
cellValue = $cell.text().trim();
|
||||
}
|
||||
}
|
||||
|
||||
rowData.push(cellValue);
|
||||
}
|
||||
});
|
||||
|
||||
if (rowData.length > 0) {
|
||||
tableData.push(rowData);
|
||||
}
|
||||
});
|
||||
|
||||
showLoader("Generowanie pliku...");
|
||||
$.ajax({
|
||||
method: "get",
|
||||
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportExcel&ids=" + ids.join("|"),
|
||||
success: function (response)
|
||||
{
|
||||
downloadFile(response.fileContent, response.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
method: "post",
|
||||
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportExcelWYSIWYG",
|
||||
data: {
|
||||
tableData: JSON.stringify(tableData)
|
||||
},
|
||||
success: function (result) {
|
||||
downloadFile(result.fileContent, result.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
hideLoader();
|
||||
},
|
||||
error: function() {
|
||||
window.alert("Błąd podczas generowania pliku");
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
function exportPDF() {
|
||||
@@ -389,6 +440,81 @@ function exportPDF() {
|
||||
},
|
||||
});
|
||||
}
|
||||
function exportRawMaterialsExcel() {
|
||||
// Check if raw materials table exists
|
||||
if ($("#rawMaterialsTable").length === 0) {
|
||||
window.alert("Brak tabeli surowców do eksportu");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if any rows are selected
|
||||
var checkedRows = $("input.rawMaterialCheck:checkbox:checked").closest('tr:visible');
|
||||
if (checkedRows.length === 0) {
|
||||
// If no rows selected, export all visible rows
|
||||
checkedRows = $("#rawMaterialsTable tbody tr:visible");
|
||||
if (checkedRows.length === 0) {
|
||||
window.alert("Brak danych do eksportu");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Get table data from selected rows
|
||||
var tableData = [];
|
||||
|
||||
// Get headers (skip first checkbox column)
|
||||
var headers = [];
|
||||
$("#rawMaterialsTable thead tr th").each(function(index) {
|
||||
if (index > 0) {
|
||||
headers.push($(this).text().trim());
|
||||
}
|
||||
});
|
||||
tableData.push(headers);
|
||||
|
||||
// Get data from selected/visible rows
|
||||
checkedRows.each(function() {
|
||||
var rowData = [];
|
||||
var $row = $(this);
|
||||
|
||||
$row.find('td').each(function(index) {
|
||||
if (index > 0) { // Skip first checkbox column
|
||||
var $cell = $(this);
|
||||
var cellValue = '';
|
||||
|
||||
// Check for links (product codes)
|
||||
var $link = $cell.find('a');
|
||||
if ($link.length > 0) {
|
||||
cellValue = $link.text().trim();
|
||||
} else {
|
||||
// Regular cell text
|
||||
cellValue = $cell.text().trim();
|
||||
}
|
||||
|
||||
rowData.push(cellValue);
|
||||
}
|
||||
});
|
||||
|
||||
if (rowData.length > 0) {
|
||||
tableData.push(rowData);
|
||||
}
|
||||
});
|
||||
|
||||
showLoader("Generowanie pliku...");
|
||||
$.ajax({
|
||||
method: "post",
|
||||
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportExcelWYSIWYG",
|
||||
data: {
|
||||
tableData: JSON.stringify(tableData)
|
||||
},
|
||||
success: function (result) {
|
||||
downloadFile(result.fileContent, result.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
hideLoader();
|
||||
},
|
||||
error: function() {
|
||||
window.alert("Błąd podczas generowania pliku");
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
function createInsideOrder() {
|
||||
var ids = [];
|
||||
$('input.allCheck:checkbox:checked').each(function () {
|
||||
|
||||
Reference in New Issue
Block a user