Download FV asDocument from E5 CRM; E-Commerce: fix rewizor encoding

This commit is contained in:
2025-06-05 20:02:44 +00:00
parent 7e46fc97b6
commit 0c87d23283
11 changed files with 666 additions and 503 deletions

View File

@@ -24,22 +24,46 @@ $(document).ready(function () {
});
function exportToRewizor(source, date, type) {
if (type == undefined || type == null || type == "") {
alert("Wybierz rodzaj faktur (normalne lub korekty).");
return;
}
if (source == undefined || source == null || source == "") {
alert("Wybierz źródło faktur.");
return;
}
blockUI("Trwa generowanie pliku...");
$.ajax({
url: "index.php?module=EcmInvoiceOuts&action=ecommerce&ajax=exportToRewizor&to_pdf=1&source="+source+"&date="+date+"&type="+type,
type: "GET",
success: function (data) {
var xhr = new XMLHttpRequest();
xhr.open('GET', "index.php?module=EcmInvoiceOuts&action=ecommerce&ajax=exportToRewizor&to_pdf=1&source="+source+"&date="+date+"&type="+type, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
if (xhr.status === 200) {
var arrayBuffer = xhr.response;
var bytes = new Uint8Array(arrayBuffer);
var data = '';
for (var i = 0; i < bytes.length; i++) {
data += String.fromCharCode(bytes[i]);
}
data = data.replace(/ {4}/g, "");
data = data.replace(/\n/g, "\r\n");
var bytes = new TextEncoder("windows-1252", { NONSTANDARD_allowLegacyEncoding: true }).encode(data);
var filename = "rewizor-allegro.epp";
var blob = new Blob([bytes], { type: "text/csv"});
var finalBytes = new Uint8Array(data.length);
for (var i = 0; i < data.length; i++) {
finalBytes[i] = data.charCodeAt(i) & 0xFF;
}
var filename = `rewizor-${source}-${type}.epp`;
var blob = new Blob([finalBytes], { type: "text/plain;charset=iso-8859-2"});
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", filename);
@@ -48,16 +72,21 @@ function exportToRewizor(source, date, type) {
link.click();
document.body.removeChild(link);
}
$.unblockUI();
}
$.unblockUI();
},
error: function () {
} else {
window.alert("Błąd eksportu.");
$.unblockUI();
}
});
};
xhr.onerror = function() {
window.alert("Błąd eksportu.");
$.unblockUI();
};
xhr.send();
}
function blockUI($msg) {