},\r
confirm(title,message,strbtnok,strbtncancel,action){\r
document.getElementById("dlgconfirm_title").innerHTML = title;\r
- document.getElementById("dlgconfirm_message").innerHTML = message;\r
+ document.getElementById("dlgconfirm_text").innerHTML = message;\r
document.getElementById("dlgconfirm_btnok").innerHTML = strbtnok;\r
document.getElementById("dlgconfirm_btncancel").innerHTML = strbtncancel;\r
document.getElementById("dlgconfirm_btnok").setAttribute("onclick","document.getElementById('dlgconfirm').style.display='none';" + action);\r
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);
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");
}
console.log(args);
const pdfout = spawn(usersystem.getApplicationPath()+ '/tools/wkhtmltopdf.exe', args);
pdfout.stdout.on('data', (data) => {
+
console.log(`pdfout stdout: ${data}`);
});
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});
+ }
+
});
}
}
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 {
myapp.loaddialog("InvoiceBooking").then(result => {
booking.initDialog();
});
+
//invoice.changedDirection(true);
},
},
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;
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);
}
},
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 {
}
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);
//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.
}
}
{title: "Typ", field: "invoicetype",headerFilter:"select", headerFilterParams:{values:headerinvtypes},formatter:function(cell, formatterParams){ var value = cell.getValue(); if (value){ return "<span class="+ invtypes[value].class+">" + invtypes[value].text + "</span>" } return ""; } },
]
});
-
+ myapp.loaddialog("confirm").then(result => {
+
+ });
},
gettbldata: function(){
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);
},
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();
});
});
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 => {