v20200420
authorkilian <ksaffran@dks.lu>
Mon, 20 Apr 2020 10:55:51 +0000 (12:55 +0200)
committerkilian <ksaffran@dks.lu>
Mon, 20 Apr 2020 10:55:51 +0000 (12:55 +0200)
dev/profile/server/invoicejournal.sqlite
main.js
server/api/lib/pdfreport.pm
server/htdocs/css/dkstheme.css
server/tmpl/lists/invoicedefaults.tt [new file with mode: 0644]
server/tmpl/module/invoices/invoice.js
server/tmpl/module/invoices/invoice.tt

index 77ee2f8..1e80208 100644 (file)
Binary files a/dev/profile/server/invoicejournal.sqlite and b/dev/profile/server/invoicejournal.sqlite differ
diff --git a/main.js b/main.js
index ccbb02e..ddf44a0 100644 (file)
--- a/main.js
+++ b/main.js
@@ -5,6 +5,8 @@ const os = require('os')
 const fs = require('fs')
 const {ipcMain} = require('electron')
 var child = require('child_process').execFile;
+var { spawn } = require('child_process');
+//var { spawn } = require('child_process').execFile;
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the JavaScript object is garbage collected.
 let mainWindow
@@ -20,10 +22,10 @@ function createWindow () {
   console.log(os.platform());
         if (os.platform() == "win32"){
                executablePath = "C:\\Strawberry\\perl\\bin\\perl.exe";
-               parameters = [app.getAppPath() + "\\server\\invoicejournal.pl"];
+               parameters = [app.getAppPath() + "\\invoicejournal.pl"];
         } else { //os.platform() == "darwin"
                executablePath = "/Users/kilian/perl5/perlbrew/perls/perl-5.28.1/bin/perl";
-               parameters = [app.getAppPath() + "/server/invoicejournal.pl"];
+               parameters = [app.getAppPath() + "/invoicejournal.pl"];
         }
    console.log(parameters);
   mainWindow = new BrowserWindow({
@@ -45,15 +47,15 @@ function createWindow () {
     appcfg.type = "standalone";
   }
   if (appcfg){
-    if (!appcfg.host){
-      appcfg.host ="localhost";
-    }
-    if (!appcfg.host){
-      appcfg.port ="6060";
-    }
-    if (!appcfg.protocol){
-      appcfg.protocol ="http";
-    } 
+    // if (!appcfg.host){
+    //   appcfg.host ="localhost";
+    // }
+    // if (!appcfg.host){
+    //   appcfg.port ="6060";
+    // }
+    // if (!appcfg.protocol){
+    //   appcfg.protocol ="http";
+    // 
     console.log(appcfg);
     if (appcfg.type == "standalone"){
       console.log("Start Child");
@@ -66,13 +68,18 @@ function createWindow () {
           // var test = app.getPath('USERPROFILE');
           // console.log("Path:" + test);
           // console.log(data.toString());
-          mainWindow.show()
+          
         } 
       });
-    }
+    } else if (appcfg.type == "server"){
+      console.log("Start Spawned");
+      const subprocess = spawn(executablePath,parameters,{ detached: true, stdio: 'ignore'});
+      subprocess.unref();
+    } 
   }
   console.log(appcfg.protocol + '://'+appcfg.host+':'+ appcfg.port+'/index.html');
   // and load the index.html of the app.
+  
   mainWindow.loadURL(appcfg.protocol + '://'+appcfg.host+':'+ appcfg.port+'/index.html')
   mainWindow.setMenu(null)
   mainWindow.maximize()
@@ -87,9 +94,6 @@ function createWindow () {
       });
     }
     item.setSavePath(savepath);
-    
-    
-
     item.on('updated', (event, state) => {
     if (state === 'interrupted') {
       console.log('Download is interrupted but can be resumed')
@@ -111,7 +115,7 @@ function createWindow () {
       }
     })
   })
-  
+  mainWindow.show()
   //mainWindow.show()
   // Open the DevTools.
   mainWindow.webContents.openDevTools()
index a49197f..f8063b0 100644 (file)
@@ -12,7 +12,7 @@ sub new {
     my $self = bless {}, $class;
     $self->{tmplpath} =$p->{tmplpath};
     $self->{tmp} =$p->{tmp};
-    $self->{wkhtmltopdf} = $RealBin.'/tools/wkhtmltopdf'.(($^O eq "MSWin32")?'.exe':'');
+    $self->{wkhtmltopdf} = $RealBin.'/server/tools/wkhtmltopdf'.(($^O eq "MSWin32")?'.exe':'');
     return $self;
 }
 
index 10bb72b..842bde5 100644 (file)
@@ -1826,6 +1826,10 @@ width: 100%;
 
 }
 
+.portal tbody tr:nth-child(even) { 
+       background-color: rgb(247, 247, 247);
+}
+
 .portal tbody tr:hover{
        background-color: #959fb9;
 }
@@ -1834,9 +1838,7 @@ width: 100%;
        background-color: #acacac!important;
 }
 
-.portal tbody tr:nth-child(even) { 
-background-color: rgb(247, 247, 247);
-}
+
 
 
 ::-webkit-scrollbar {
diff --git a/server/tmpl/lists/invoicedefaults.tt b/server/tmpl/lists/invoicedefaults.tt
new file mode 100644 (file)
index 0000000..f5a4789
--- /dev/null
@@ -0,0 +1,3 @@
+[% FOREACH idef= dksdb.query("select id,defvalue from invoicejournal where id in ('vat','id_invoicetemplate','invoicedeadlinedays','id_address','sql_autoinvoicereference');") %]
+[% invdefaults.${idef.item('id')} = idef %]
+[% END %]
\ No newline at end of file
index 4df109a..e6f348e 100644 (file)
@@ -1,7 +1,12 @@
+[% USE dksdb = DBI(dsn,dbuser,dbpassword) %]
+[% PROCESS lists/invoicedefaults.tt %]
 
-//  function initmodule(){
  var invoice = {
-  
+  defaultdata: {
+    [% FOREACH key IN invdefaults.keys %]
+      "[% invdefaults.item(key).item('id') %]":"[% invdefaults.item(key).item('defvalue') %]",
+    [% END %]
+  },
   init: function(){
     invoice.hasPDF();
     invoice.changedDirection(true);
       } 
     }
   },
-  
+  setInvoiceDates(){
+    invoice.setDeadlineDate();
+    invoice.setReference();
+  },
+  setDeadlineDate: function(){
+    var invid = document.getElementById("invoices_id").value;
+    var invdate = document.getElementById("invoices_invoicedate-" + invid).value;
+    var dldays = parseInt(document.getElementById("invoices_deadlinedays-" + invid).value);
+    var dldate =  new Date(invdate);
+    dldate.setDate(dldate.getDate() + dldays);
+    record.setValue(document.getElementById("invoices_deadlinedate-" + invid),dldate.toISOString().substring(0,10));
+  },
+  setDeadlineDays: function(){
+    var invid = document.getElementById("invoices_id").value;
+    var invdate = new Date(document.getElementById("invoices_invoicedate-" + invid).value);
+    var dldate = new Date(document.getElementById("invoices_deadlinedate-" + invid).value);
+    var days = dldate-invdate;
+    record.setValue(document.getElementById("invoices_deadlinedays-" + invid),days);
+  },
+  setReference(){
+    var invid = document.getElementById("invoices_id").value;
+    var direction = document.getElementById("invoices_direction-" + invid).value;
+    var strinvdate = document.getElementById("invoices_invoicedate-" + invid).value;
+    if (direction == "out"){
+      invdate = new Date(strinvdate);
+      var nsql = invoice.defaultdata.sql_autoinvoicereference;
+      nsql = nsql.replace(/date\('now','localtime'\)/g,"date('"+ invdate.toISOString().substring(0,10) +"')");
+      console.log("SQL:" + nsql)
+      req.reqdata("POST","db.cgi",{"sql":nsql},invoice.fillReference);  
+    } 
+  },
+  fillReference: function(data){
+    console.log(data);
+    if (data){
+      var invid = document.getElementById("invoices_id").value;
+      record.setValue(document.getElementById("invoices_reference-" + invid),data["0"].reference);
+    }
+  },
   addProduct: function(){
      
      req.reqdata("POST","db.cgi",{"get":"products","id":table.selection},invoice.setProduct);
index 12d21b6..58347e5 100644 (file)
@@ -9,9 +9,9 @@
 [% PROCESS lists/reportlist.tt %]
 [% USE Dumper %]
 [% qinv =dksdb.query("select inv.*
-,printf('%.2f',sum(netamount)) as netamount
-,printf('%.2f',sum(taxamount)) as vatamount
-,printf('%.2f',sum(netamount + taxamount)) as grossamount
+,printf('%.2f',sum(bk.netamount)) as netamount
+,printf('%.2f',sum(bk.taxamount)) as vatamount
+,printf('%.2f',sum(bk.netamount + bk.taxamount)) as grossamount
 from invoices inv join bookings bk on (inv.id=bk.id_invoices) where inv.id='${params.id}';") %]
 
 [% qbook =dksdb.prepare("SELECT id, id_invoices, id_products, producttype, sku, replace(quantity,'.',',') as quantity, replace(printf('%.2f',coalesce(unitamount,0.0)),'.',',') as unitamount, unit,name, description, taxpercent
@@ -54,13 +54,13 @@ from bookings where id_invoices='${params.id}';") %]
         </div>
         <div class="w3-row">
           <div class="w3-cell" style="max-width: 130px;">
-            [% inputbox('invoicedate','invoices',inv.0.id,'Datum','date','','','',inv.0.invoicedate,'') %]
+            [% inputbox('invoicedate','invoices',inv.0.id,'Datum','date','','','',inv.0.invoicedate,'','invoice.setInvoiceDates();') %]
           </div>
           <div class="w3-cell" style="width: 40px;">
-            [% inputbox('deadlinedays','invoices',inv.0.id,'Tage','number','','','',inv.0.deadlinedays,'') %]
+            [% inputbox('deadlinedays','invoices',inv.0.id,'Tage','number','','','',inv.0.deadlinedays,'','invoice.setDeadlineDate();') %]
           </div>
           <div class="w3-cell" style="max-width: 130px;">
-            [% inputbox('deadlinedate','invoices',inv.0.id,'Fälligkeit','date','','','',inv.0.deadlinedate,'') %]
+            [% inputbox('deadlinedate','invoices',inv.0.id,'Fälligkeit','date','','','',inv.0.deadlinedate,'','invoice.setDeadlineDays();') %]
           </div>
           
         </div>
@@ -193,7 +193,7 @@ from bookings where id_invoices='${params.id}';") %]
               <td style="min-width: [% cols.unit %]px;width: [% cols.unit %]px;max-width: [% cols.unit %]px;">[% bk.unit %]</td>
               <td  class="w3-right-align" style="min-width: [% cols.unit %]px;width: [% cols.unit %]px;max-width: [% cols.unit %]px;">[% bk.unitamount %]€</td>
               <td class="w3-right-align" style="min-width: [% cols.vatpercent %]px;width: [% cols.vatpercent %]px;max-width: [% cols.vatpercent %]px;">[% bk.vatpercent %]%</td>
-              <td class="w3-right-align" style="min-width: [% cols.vat %]px;width: [% cols.vat %]px;max-width: [% cols.vat %]px;">[% bk.vatamount %]€</td>
+              <td class="w3-right-align" style="min-width: [% cols.vat %]px;width: [% cols.vat %]px;max-width: [% cols.vat %]px;">[% bk.taxamount %]€</td>
               <td class="w3-right-align" style="min-width: [% cols.netamount %]px;width: [% cols.netamount %]px;max-width: [% cols.netamount %]px;">[% bk.netamount %]€</td>
               <td class="w3-right-align" style="min-width: [% cols.grossamount %]px;width: [% cols.grossamount %]px;max-width: [% cols.grossamount %]px;">[% bk.grossamount %]€</td>
               <td></td>