From: kilian (ksmachome) Date: Mon, 25 Nov 2019 06:35:12 +0000 (+0100) Subject: invoices X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=51483938175ec409e65f777443144c0952c232c8;p=dksnas.git invoices --- diff --git a/CGI/tmpl/app/creorga/index.tt b/CGI/tmpl/app/creorga/index.tt index 271f190..d15d27e 100644 --- a/CGI/tmpl/app/creorga/index.tt +++ b/CGI/tmpl/app/creorga/index.tt @@ -8,7 +8,7 @@ - + Creorga diff --git a/CGI/tmpl/app/invoicejournal/index.tt b/CGI/tmpl/app/invoicejournal/index.tt index 2e22f47..5b92a2c 100644 --- a/CGI/tmpl/app/invoicejournal/index.tt +++ b/CGI/tmpl/app/invoicejournal/index.tt @@ -13,7 +13,7 @@
- + Invoice Journal
diff --git a/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.js b/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.js index bfd383e..bd13d79 100644 --- a/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.js +++ b/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.js @@ -1,18 +1,19 @@ var tbl = null; var tblproducts = null; var tblfiles = null; +var currentinvoice = null; var statustypes = [{ "value": "planned", "label": "geplant" }, { "value": "sended", "label": "verschickt" }, { "value": "received", "label": "erhalten" }, { "value": "payed", "label": "bezahlt" }, { "value": "overdue", "label": "überfällig" } ]; - +var currenttemplate = { "base": null, "elements": null }; var statuslang = { "planned": "geplant", "payed": "bezahlt", "received": "erhalten", "overdue": "überfällig", "sended": "verschickt" }; var quarters = [{ "value": "Q1", "label": "Q1" }, { "value": "Q2", "label": "Q2" }, { "value": "Q3", "label": "Q3" }, { "value": "Q4", "label": "Q4" }]; var invoicetypes = [{ "value": "inv-out", "label": "Ausgangs-Rechnung" }, { "value": "inv-in", "label": "Eingangs-Rechnung" }, { "value": "crn-out", "label": "Ausgangs-Gutschrift" }, { "value": "crn-in", "label": "Eingangs-Gutschrift" }]; -var templates = [{ "value": "dks-deutsch", "label": "DKS - Deutsch" }, { "value": "dks-french", "label": "DKS Französisch" }, { "value": "dks-english", "label": "DKS - english" }]; +// var templates = [{ "value": "dks-deutsch", "label": "DKS - Deutsch" }, { "value": "dks-french", "label": "DKS Französisch" }, { "value": "dks-english", "label": "DKS - english" }]; var choice = { "invoices": { @@ -22,7 +23,7 @@ var choice = { "bquarter": null, "byear": null, "invoicetype": null, - "template": null + "id_template": null } }; @@ -34,13 +35,13 @@ var choicedata = { "bquarter": { "view": "quarters" }, "byear": { "view": "businessyears" }, "invoicetype": { "data": invoicetypes }, - "template": { "data": templates } + "id_template": { "view": "templates" } } }; function initpage() { - console.log(mpref.cfg); - console.log("APP:" + parent.app); + //console.log(mpref.cfg); + //console.log("APP:" + parent.app); flatpickr(".datefield", { altInput: true, altFormat: "d.m.Y", @@ -168,14 +169,14 @@ function inittblfiles() { function gettblfilesdata() { var udata = tbl.getSelectedData(); if (udata[0]) { - console.log(udata[0]); + //console.log(udata[0]); req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "fileslist", "filter": "id_invoice=" + udata[0].id }, loadtblfilesdata); } return false; } function loadtblfilesdata(data) { - console.log(data); + //console.log(data); if (data && data.sqldata) { tblfiles.setData(data.sqldata); } @@ -266,14 +267,14 @@ function inittblbookings() { function gettblbookingdata() { var udata = tbl.getSelectedData(); if (udata[0]) { - console.log(udata[0]); + //console.log(udata[0]); req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "bookings", "filter": "id_invoice=" + udata[0].id }, loadtblbookingdata); } return false; } function loadtblbookingdata(data) { - console.log(data); + //console.log(data); if (data && data.sqldata) { tblproducts.setData(data.sqldata); } @@ -287,7 +288,7 @@ function gettbldata() { } function loadtbldata(data) { - console.log(data); + //console.log(data); if (data && data.sqldata) { tbl.setData(data.sqldata); } @@ -298,8 +299,9 @@ function edit() { var udata = tbl.getSelectedData(); //cleanform("invoices"); if (udata[0]) { - console.log(udata[0]); - req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "invoicelist", "filter": "id=" + udata[0].id }, fillinvoice); + currentinvoice = udata[0]; + //console.log(udata[0]); + req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "invoices", "filter": "id=" + udata[0].id }, fillinvoice); viewinvoicepanel(); } return false; @@ -309,6 +311,11 @@ function fillinvoice(data) { if (data && data.sqldata) { //console.log(data); fillformbydataclass("invoices", data.sqldata[0], false); + //console.log(data.sqldata[0].invoicetype); + currentinvoice = data.sqldata[0]; + if (data.sqldata[0].invoicetype == "inv-out") { + document.getElementById("netamount").readonly = true; + } gettblbookingdata(); } return false; @@ -329,7 +336,14 @@ function remove() { function viewinvoicepanel() { document.getElementById('tbl_invoices').style.display = 'none'; document.getElementById('pnl_invoices').style.display = 'block'; - + var x = document.getElementsByClassName("invlist"); + for (i = 0; i < x.length; i++) { + x[i].style.display = "none"; + } + x = document.getElementsByClassName("invdata"); + for (i = 0; i < x.length; i++) { + x[i].style.display = "block"; + } return false; } @@ -337,6 +351,14 @@ function viewtable() { gettbldata(); document.getElementById('pnl_invoices').style.display = 'none'; document.getElementById('tbl_invoices').style.display = 'block'; + var x = document.getElementsByClassName("invlist"); + for (i = 0; i < x.length; i++) { + x[i].style.display = "block"; + } + x = document.getElementsByClassName("invdata"); + for (i = 0; i < x.length; i++) { + x[i].style.display = "none"; + } return false; } @@ -369,7 +391,7 @@ function fillchoices() { shouldSort: false }); if (choicedata[f][c]['view']) { - console.log("We have a view:" + choicedata[f][c]['view']); + //console.log("We have a view:" + choicedata[f][c]['view']); getchoicedata(choicedata[f][c]['view']); } } @@ -384,23 +406,64 @@ function loadtab(tabname) { x[i].style.display = "none"; } document.getElementById("tab_" + tabname).style.display = "block"; + x = document.getElementsByClassName("tabbtn"); + + for (i = 0; i < x.length; i++) { + //console.log(x[i].classList); + x[i].classList.remove("w3-blue-grey"); + } + document.getElementById("tabbtn_" + tabname).classList.add("w3-blue-grey"); + x = document.getElementsByClassName("tabxbtn"); + for (i = 0; i < x.length; i++) { + x[i].style.display = "none"; + } + x = document.getElementsByClassName("tabbtn" + tabname); + for (i = 0; i < x.length; i++) { + x[i].style.display = "block"; + } return false; } + + function geninvoice() { + req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "templates", "filter": "id=" + document.getElementById("id_template").value }, gettemplateelements); + return false; +} + +function gettemplateelements(data) { + if (data && data.sqldata) { + currenttemplate["base"] = data.sqldata[0]; + req.reqdata("POST", "db.cgi", { "db": parent.app + "/" + mpref.cfg.db, "get": "templateelements", "filter": "id_template=" + document.getElementById("id_template").value }, makepdf); + } + +} + +function makepdf(data) { + if (data && data.sqldata) { + currenttemplate["elements"] = data.sqldata; + } + console.log(currenttemplate); tblproducts.download("pdf", document.getElementById("reference").value + ".pdf", { - orientation: "portrait", + orientation: currenttemplate.base.orientation, jsPDF: { - unit: "mm", + unit: currenttemplate.base.unit, }, autoTable(doc) { - doc.setFontSize(10); - doc.text("DKS s.à r.l.", 160, 10); - doc.text("8b, rue du Moulin", 160, 15); - doc.text("L-6914 Roodt/Syre", 160, 20); - doc.setFontSize(20); - doc.text("Invoice", 160, 70); + for (var i in currenttemplate.elements) { + var cel = currenttemplate.elements[i]; + if (cel['etype'] == 'text') { + setpdftext(doc, cel); + } + if (cel['etype'] == 'image') { + setpdfimage(doc, cel); + } + } + + // doc.text("DKS s.à r.l.\n8b, rue du Moulin\nL-6914 Roodt/Syre\n\nTel: +352 691504574\ninfo@dks.lu / www.dks.lu", 160, 10); + // doc.setFontSize(20); + // doc.text("Rechnung", 160, 70); // styles: { // fillColor: [100, 255, 255] @@ -409,7 +472,12 @@ function geninvoice() { // id: {fillColor: 255} // }, return { - margin: { top: 130, bottom: 10, left: 15, right: 10 }, + margin: { + top: parseInt(currenttemplate.base.top), + bottom: parseInt(currenttemplate.base.bottom), + left: parseInt(currenttemplate.base.left), + right: parseInt(currenttemplate.base.right) + }, } }, @@ -417,4 +485,38 @@ function geninvoice() { //carry out an action on the doc object } }); +} + +function setpdftext(pdf, el) { + if (el['fontsize']) { + pdf.setFontSize(el['fontsize']); + } + const regex = /%%([\w]+)%%/gm; + var etext = el['edata']; + var m; + while ((m = regex.exec(etext)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === regex.lastIndex) { + regex.lastIndex++; + } + + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + //etext.replace('') + if (groupIndex == 1) { + if (document.getElementById(match)) { + etext.replace('%%' + match + '%%', currentinvoice[match]); + } + + } + //console.log(`Found match, group ${groupIndex}: ${match}`); + }); + + } + etext.replace(regex, ''); + pdf.text(etext, el['xpos'], el['ypos']); +} + +function setpdfimage(pdf,el){ + } \ No newline at end of file diff --git a/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.tt b/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.tt index e01fe65..02a7625 100644 --- a/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.tt +++ b/CGI/tmpl/app/invoicejournal/module/invoicejournal/index.tt @@ -3,26 +3,33 @@
- - - - + + + + +