export stock addresses

This commit is contained in:
Michał Zieliński
2025-11-08 12:23:19 +01:00
parent ef6b3e0f7c
commit a39ebfd84c
3 changed files with 291 additions and 187 deletions

View File

@@ -134,6 +134,23 @@ function isProductValid(id) {
return false;
}
}
function exportFile() {
$("#loader").show();
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=export&to_pdf=1",
}).done(function (data) {
$("#loader").hide();
if (data.status === 'Error') {
alert('Błąd: ' + data.msg);
} else {
console.log(data);
downloadFile(data.fileContent, data.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.');
});
}
$(document).ready(function () {
$("#address").mask("AB.CD.E.F", {
placeholder: "__.__._._",
@@ -189,12 +206,49 @@ $(document).ready(function () {
$("#searchByIndexForm").submit();
}
});
$("#exportTrigger").click(() => {
exportFile();
});
$('[name^="showAddress').click((event) => {
$("#address").val(event.target.name.split('-')[1]);
if (isAddressValid()) {
$("#searchByAddressForm").submit();
}
});
//bind buttons
});
});
function downloadFile(base64Data, fileName, mimeType) {
// Stwórz blob z danych base64
const byteCharacters = atob(base64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += 512) {
const slice = byteCharacters.slice(offset, offset + 512);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, {type: mimeType});
// Stwórz link do pobrania
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
// Dodaj link do dokumentu i kliknij go
document.body.appendChild(link);
link.click();
// Usuń link z dokumentu
setTimeout(function () {
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}, 100);
}