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) {

View File

@@ -53,14 +53,20 @@ function show()
function getInvoices($source, $date, $type)
{
$db = $GLOBALS['db'];
if ($source =='') $source = '%';
$date .= '%';
$query = "SELECT i.*, wz.document_no AS wz_document_no, wz.id AS wz_id FROM ecommerce_invoices AS i
LEFT JOIN ecmstockdocouts AS wz on wz.id = i.ecmstockdocout_id
";
$query .= " WHERE i.origin LIKE '$source' AND i.register_date LIKE '$date'";
if ($type !='') {
$query.=" AND i.type='$type'";
$query .= " WHERE i.register_date LIKE '$date'";
if ($source != '') {
if ($source == 'baselinker') {
$query .= " AND i.origin IN ('allegro', 'shop')";
} else {
$query .= " AND i.origin = '$source'";
}
}
if ($type != '') {
$query .= " AND i.type='$type'";
}
$query .= " ORDER BY i.register_date";
$result = $db->query($query);
@@ -99,10 +105,11 @@ function getDates()
function getSources() {
$db = $GLOBALS['db'];
$sources = array();
$res = $db->query("SELECT DISTINCT origin FROM ecommerce_invoices");
$res = $db->query("SELECT DISTINCT origin FROM ecommerce_invoices WHERE origin NOT IN ('allegro', 'shop')");
while ($row = $db->fetchByAssoc($res)) {
$sources[]= $row['origin'];
}
$sources[] = 'baselinker';
return $sources;
}
@@ -125,14 +132,13 @@ function exportToRewizor($source, $date, $type)
}
$smarty->assign("data", $invoices);
$result = '';
if ($type == 'normal') {
$result = $smarty->display(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/rewizor.tpl');
$result = $smarty->fetch(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/rewizor.tpl');
} else {
$result = $smarty->display(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/rewizor_fvkor.tpl');
$result = $smarty->fetch(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/rewizor_fvkor.tpl');
}
// encode result as ansi
echo $result;
//echo mb_convert_encoding($result, 'ANSI', 'UTF-8');
echo mb_convert_encoding($result, 'ISO-8859-2', 'UTF-8');
}
function brecho($var)