From 1bef28288b7926a296b9cd84aedd695feb124deb Mon Sep 17 00:00:00 2001 From: Kilian Saffran Date: Tue, 3 Nov 2020 08:08:29 +0100 Subject: [PATCH] duplicate delete invoice --- desktopapp/js/global/myapp.js | 2 +- desktopapp/js/global/report.js | 21 ++++++++++++++++++-- desktopapp/js/modules/invoice.js | 33 +++++++++++-------------------- desktopapp/js/modules/invoices.js | 12 +++++++---- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/desktopapp/js/global/myapp.js b/desktopapp/js/global/myapp.js index 8810bfe..7692348 100644 --- a/desktopapp/js/global/myapp.js +++ b/desktopapp/js/global/myapp.js @@ -63,7 +63,7 @@ let myapp = { }, confirm(title,message,strbtnok,strbtncancel,action){ document.getElementById("dlgconfirm_title").innerHTML = title; - document.getElementById("dlgconfirm_message").innerHTML = message; + document.getElementById("dlgconfirm_text").innerHTML = message; document.getElementById("dlgconfirm_btnok").innerHTML = strbtnok; document.getElementById("dlgconfirm_btncancel").innerHTML = strbtncancel; document.getElementById("dlgconfirm_btnok").setAttribute("onclick","document.getElementById('dlgconfirm').style.display='none';" + action); diff --git a/desktopapp/js/global/report.js b/desktopapp/js/global/report.js index 613782a..987a9a6 100644 --- a/desktopapp/js/global/report.js +++ b/desktopapp/js/global/report.js @@ -6,7 +6,9 @@ let report = { tmpoutput: null, output: null, pdfoptions: null, + callback: null, data: null, + reportfile:null, open: function(reporttype,fname){ console.log("prefs",preferences.global.currentdataset.datapath); console.log("open", preferences.global.currentdataset.datapath + '/' + reporttype + '/' + fname); @@ -14,16 +16,21 @@ let report = { window.open(preferences.global.currentdataset.datapath + '/' + reporttype + '/' + fname); } }, - generate: function(id_report,reportdata,fname){ + generate: function(id_report,reportdata,fname,callback){ db.query("select * from newreports WHERE id='"+id_report+"';").then(data => { console.log(data); report.id_report = id_report; report.tmpoutput = report.tmpfolder + fname + ".pdf"; - report.output = preferences.global.currentdataset.datapath + '/' + data.reporttype + '/' + fname + ".test.pdf"; + report.output = preferences.global.currentdataset.datapath + '/' + data.reporttype + '/' + fname + ".pdf"; + report.reportfile = fname+ ".pdf"; report.pdfoptions = JSON.parse(data.pdfoptions); + report.callback = callback; if (!fs.existsSync(report.tmpfolder)){ fs.mkdirSync(usersystem.profilepath() + 'tmp/'); } + if (!fs.existsSync(path.dirname(report.tmpoutput))){ + fs.mkdirSync(path.dirname(report.tmpoutput)); + } if (fs.existsSync(report.tmpfolder + fname + ".pdf")){ fs.unlinkSync(report.tmpfolder + fname + ".pdf"); } @@ -98,6 +105,7 @@ let report = { console.log(args); const pdfout = spawn(usersystem.getApplicationPath()+ '/tools/wkhtmltopdf.exe', args); pdfout.stdout.on('data', (data) => { + console.log(`pdfout stdout: ${data}`); }); @@ -107,6 +115,15 @@ let report = { pdfout.on('close', (code) => { console.log(`pdfout: child process exited with code ${code}`); + if (code == 0){ + console.log("Copy",report.tmpoutput,"to",report.output); + if (fs.existsSync(report.output)){ + fs.unlinkSync(report.output); + } + fs.copyFileSync(report.tmpoutput,report.output); + report.callback({"file":report.reportfile}); + } + }); } } diff --git a/desktopapp/js/modules/invoice.js b/desktopapp/js/modules/invoice.js index c7841f3..c1cd0f1 100644 --- a/desktopapp/js/modules/invoice.js +++ b/desktopapp/js/modules/invoice.js @@ -11,8 +11,9 @@ let invoice = { console.log("ID Invoice:",id); db.query("SELECT inv.*,sum(bk.netamount) AS netamount,sum(bk.taxamount) AS vatamount,sum(bk.netamount + bk.taxamount) AS grossamount FROM invoices inv JOIN bookings bk ON (inv.id = bk.id_invoices) WHERE inv.id='"+id+"' GROUP BY inv.id;").then(data => { dataform.fillform('invoices',invoice.selects,data); - invoice.getBookingData(); invoice.hasPDF(data.pdffile); + invoice.getBookingData(); + myapp.viewpanel('invoice'); }); }else { @@ -75,6 +76,7 @@ let invoice = { myapp.loaddialog("InvoiceBooking").then(result => { booking.initDialog(); }); + //invoice.changedDirection(true); }, @@ -264,10 +266,11 @@ let invoice = { }, createPDF: function(){ let idreport = invoice.selects["invoices_id_template"].selected(); - let fname = document.getElementById("invoices_reference").value - report.generate(idreport,{"id": invoice.current_id},"DKS_" + fname); + let fname = document.getElementById("invoices_businessyear").value +"/" + preferences.defaultdata.fileprefix +document.getElementById("invoices_reference").value; + report.generate(idreport,{"id": invoice.current_id}, fname,invoice.afterPDFCreation); //req.reqreport({"generate":idreport,data:{"id":invoice.current_id}},invoice.afterPDFCreation) }, + afterPDFCreation: function(data){ if (data && data.file){ document.getElementById("invoices_pdffile").value=data.file; @@ -279,8 +282,8 @@ let invoice = { openPDF: function(){ if (document.getElementById("invoices_pdffile").value != ''){ document.getElementById("invoices_businessyear").value; - console.log("invoice.openPDF",document.getElementById("invoices_businessyear").value + '/' + document.getElementById("invoices_pdffile").value); - report.open('invoice',document.getElementById("invoices_businessyear").value + '/' + document.getElementById("invoices_pdffile").value); + console.log("invoice.openPDF", document.getElementById("invoices_pdffile").value); + report.open('invoice', document.getElementById("invoices_pdffile").value); //location.href=api + 'report.cgi?open=' + encodeURIComponent(document.getElementById("invoices_pdffile").value); } }, @@ -301,7 +304,7 @@ let invoice = { invoice.hasPDF(); }, hasPDF: function(pdffile){ - //console.log("set PDF Button!" + document.getElementById("invoices_pdffile").value); + console.log("set PDF Button!" + document.getElementById("invoices_pdffile").value); if (document.getElementById("invoices_pdffile").value != '' || pdffile != null){ document.getElementById("btnOpenPDF").style.display = 'block'; } else { @@ -315,16 +318,6 @@ let invoice = { } return colsum; }, - // resetsums: function(){ - // req.reqdata({"dbschema":"dks","get":"invoicesums","id":invoice.current_id}, invoice.fillsumfields); - // }, - // fillsumfields: function(data){ - // if (data && data[0]){ - // document.getElementById("invoices_netamount").value=data[0].netamount; - // document.getElementById("invoices_vatamount").value=data[0].vatamount; - // document.getElementById("invoices_grossamount").value=data[0].grossamount; - // } - // }, setPayed: function(){ let payedval = document.getElementById("invoices_grossamount").value; dataform.setValue(document.getElementById("invoices_payedamount"),payedval); @@ -391,12 +384,8 @@ let invoice = { //invoice.getBookingData(); myapp.closeDialog("InvoiceBooking"); }, - nextsequence: function(){ - db.execAsync("update defaultdata set pref=cast(pref as integer) + 1 where id='invoicesequence';").then(res => { - db.query("select pref from defaultdata where id='invoicesequence'").then(seq => { - preferences.defaultdata.invoicesequence = seq.pref; - }); - }); + sendEmail: function(){ + preferences.global. } } diff --git a/desktopapp/js/modules/invoices.js b/desktopapp/js/modules/invoices.js index 0c590ae..33f3cb4 100644 --- a/desktopapp/js/modules/invoices.js +++ b/desktopapp/js/modules/invoices.js @@ -80,7 +80,9 @@ let invoices = { {title: "Typ", field: "invoicetype",headerFilter:"select", headerFilterParams:{values:headerinvtypes},formatter:function(cell, formatterParams){ var value = cell.getValue(); if (value){ return "" + invtypes[value].text + "" } return ""; } }, ] }); - + myapp.loaddialog("confirm").then(result => { + + }); }, gettbldata: function(){ @@ -89,6 +91,7 @@ let invoices = { db.queryarray("SELECT inv.invoicedate, inv.id, inv.accountname, inv.reference, inv.status, sum(COALESCE(bk.netamount, 0.0)) AS netamount, sum(COALESCE(bk.taxamount, 0.0)) AS vatamount, sum(COALESCE(bk.netamount, 0.0) + COALESCE(bk.taxamount, 0.0)) AS grossamount, inv.businessyear, inv.id_accounts, inv.invoicetype FROM invoices inv LEFT JOIN bookings bk ON inv.id = bk.id_invoices GROUP BY inv.id ORDER BY inv.invoicedate DESC;") .then(data => { invoices.tbl.setData(data).then(dd => { if (sel[0]){ + console.log(sel[0]); invoices.tbl.selectRow(sel[0].id); //.then(xx => { // table.scrollToRow(table.getSelectedRows(), "top", false); @@ -137,8 +140,9 @@ let invoices = { }, remove: function(data){ var sel = invoices.tbl.getSelectedData(); - db.exec("DELETE FROM bookings where id_invoices='"+sel[0].id+"'").then(res => { - db.exec("DELETE FROM invoices where id='"+sel[0].id+"'").then(res => { + db.execAsync("DELETE FROM bookings where id_invoices='"+sel[0].id+"';").then(res => { + db.execAsync("DELETE FROM invoices where id='"+sel[0].id+"';").then(res => { + invoices.tbl.deselectRow(sel[0].id); invoices.gettbldata(); }); }); @@ -152,7 +156,7 @@ let invoices = { let today=moment().format('YYYY-MM-DD'); let deadline=moment().add(preferences.defaultdata.invoicedeadlinedays,'days').format('YYYY-MM-DD'); let newref= invoice.getNewReference(today); - let inssql = "INSERT INTO invoices (id, id_template, id_offer, accountvatid, clientnumber, isinnereu, payedamount, businessyear, invoicedate, deadlinedays, deadlinedate, status, footertext, reference, invoicetype, headertext, pdffile, offerreference, referencenumber, id_accounts, accountname, accountaddress, accountzip, accountcity, accountcountry) SELECT '"+ newid.id+"' as id, id_template, id_offer, accountvatid, clientnumber, isinnereu, null as payedamount, businessyear, date('"+today+"') as invoicedate,'"+preferences.defaultdata.invoicedeadlinedays+"' as deadlinedays,date('"+deadline+"') as deadlinedate, 'preparation' as status, footertext, '"+newref +"' AS reference, invoicetype, headertext, pdffile, offerreference, referencenumber, id_accounts, accountname, accountaddress, accountzip, accountcity, accountcountry FROM invoices where id='"+ sel[0].id+"';"; + let inssql = "INSERT INTO invoices (id, id_template, id_offer, accountvatid, clientnumber, isinnereu, payedamount, businessyear, invoicedate, deadlinedays, deadlinedate, status, footertext, reference, invoicetype, headertext, pdffile, offerreference, referencenumber, id_accounts, accountname, accountaddress, accountzip, accountcity, accountcountry) SELECT '"+ newid.id+"' as id, id_template, id_offer, accountvatid, clientnumber, isinnereu, null as payedamount, businessyear, date('"+today+"') as invoicedate,'"+preferences.defaultdata.invoicedeadlinedays+"' as deadlinedays,date('"+deadline+"') as deadlinedate, 'preparation' as status, footertext, '"+newref +"' AS reference, invoicetype, headertext, null as pdffile, offerreference, referencenumber, id_accounts, accountname, accountaddress, accountzip, accountcity, accountcountry FROM invoices where id='"+ sel[0].id+"';"; console.log("Execute:" + inssql); db.execAsync(inssql).then(res => { db.queryarray("select * from bookings where id_invoices='"+ sel[0].id+"'").then( bc => { -- 2.39.5