version x
authorKilian Saffran <ksaffran@dks.lu>
Fri, 12 Apr 2019 19:57:33 +0000 (21:57 +0200)
committerKilian Saffran <ksaffran@dks.lu>
Fri, 12 Apr 2019 19:57:33 +0000 (21:57 +0200)
main.js
modules/paywindow/index.js
package-lock.json
package.json
server/htdocs/js/print.js
server/htdocs/js/webdatabase.js
server/htdocs/receipt.html
server/htdocs/ticket.html [deleted file]

diff --git a/main.js b/main.js
index 2282997..f47d8f9 100644 (file)
--- a/main.js
+++ b/main.js
@@ -55,29 +55,38 @@ function createWindow () {
   
   mainWindow.show()
   // Open the DevTools.
-  mainWindow.webContents.openDevTools()
+  //mainWindow.webContents.openDevTools()
   mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) =>{
     console.log("URL:" + url);
-    console.log("frameName:" + frameName);
-    console.log(options);
-    console.log(disposition);
+    
+    function clwin(){
+      console.log("close print window!");
+      win.close();
+    }
     if (frameName === 'receipt') {
       event.preventDefault()
       Object.assign(options,{
         modal: true,
         parent: mainWindow,
-        width: 320,
+        width: 800, //320
         height: 400,
         show: false
       })
       const win = new BrowserWindow(options)
       win.setMenu(null)
-      win.once('ready-to-show', () => win.show())
-      win.loadURL(url)
-      if (url.indexOf("&action=print") > 0 ){
-          win.webContents.on('did-finish-load', () => {
-            win.webContents.print();
-          })
+      win.once('ready-to-show', () => win.hide())
+      win.loadURL(url);
+      function xclose(){win.close();}
+      win.webContents.openDevTools()
+      console.log(url.indexOf("action=print"));
+      if (url.indexOf("action=print") > 0 ){
+        win.webContents.on('did-finish-load', (event, result) => {
+           console.log("finished loading!")
+          var pp = win.webContents.getPrinters();
+          win.webContents.print({ silent: true, printBackground: false, deviceName: '' });
+           
+           
+        })          
       }
       event.newGuest = win
     }
@@ -95,22 +104,28 @@ function createWindow () {
       win.once('ready-to-show', () => win.show())
       win.loadURL(url)
       win.webContents.on('new-window', (event2, url2, frameName2, disposition2, options2, additionalFeatures2) => {
-        console.log("SubWindow for print!");
-        console.log(url2);
-        console.log(frameName2);
+        // console.log("SubWindow for print!");
+        // console.log(url2);
+        // console.log(frameName2);
         event2.preventDefault()
         Object.assign(options,{
           modal: true,
           parent: win,
-          width: 1040,
-          height: 600,
+          width: 350,
+          height: 500,
           show: false
         })
         const win2 = new BrowserWindow(options)
         win2.setMenu(null)
+        win2.once('ready-to-show', () => win2.show())
         win2.loadURL(url2)
+        //win2.webContents.openDevTools()
         win2.webContents.on('did-finish-load', () => {
-          win2.webContents.print();
+          console.log("finished loading!")
+          win2.webContents.insertCSS('html,body { all:unset; background: #fff !important; font-family:none; font-size: 12px !important; color: black !important } div#header {all: unset;float:none;} div#content { all: unset; float: none; } footer { display:none; }  #card_data { width: 100px; float: none;  text-align: left; } .white-box { box-shadow: none; background-color: transparent; border-bottom: 0px; border-radius: 0px; padding: 0px; } .logo { display:none } #map { display: none; color: white;} .spacer-large {  display: none; } #footer_text { display: none; } ');
+          //#receipt_data_tab {float: none; } #card_data { float: none; text-align: left;}
+          var pp = win2.webContents.getPrinters();
+          win2.webContents.print({ silent: false, printBackground: false, deviceName: '' });
         })
         
         //win2.print()
@@ -128,7 +143,7 @@ function createWindow () {
       })
       const win = new BrowserWindow(options)
       win.setMenu(null)
-      win.once('ready-to-show', () => win.print())
+      win.once('ready-to-show', () => win.show())
       win.loadURL(url)
       
       event.newGuest = win
index 69635d2..b207af2 100644 (file)
@@ -33,6 +33,7 @@ function loadconfig(){
   if (!localconfig){
     localconfig = {};
     localconfig['receipt'] = 1;
+    localconfig['ticket'] = 0;
     $('#printreceipt').prop('checked','checked');
   }
 }
@@ -45,13 +46,12 @@ function loadadmin(){
   
 // }
 
-function printreceipt(){
-  window.open(decodeURIComponent(mpref.cfg.serviceurl)+ "receipt.html?action=preview","receipt");
+function printreceipt(trid,receipt=0,ticket=0){
+  //console.log("print tr" + trid);
+  window.open(decodeURIComponent(mpref.cfg.serviceurl)+ "receipt.html?action=print&id="+ trid + "&receipt=" + receipt + "&ticket=" + ticket,"receipt");
 }
 
-function printticket(){
-  window.open(decodeURIComponent(mpref.cfg.serviceurl)+ "ticket.html?action=preview","receipt");
-}
+
 
 function cardwindow(){
   window.open('https://me.sumup.com/de-lu/transactionsnew',"cardview");
@@ -263,12 +263,11 @@ function save_shoppingcart(){
   $("#sumtotalcashamount").html("");
   $("#sumtotalchangeamount").html("");
   
-  if (localconfig['ticket'] && localconfig['ticket'] == 1){
-    printticket();
-  }
-  if (localconfig['receipt'] && localconfig['receipt'] == 1){
-    printreceipt();
-  }
+  console.log("printing...");
+  console.log(localconfig);
+  //if (localconfig['receipt'] || localconfig['ticket']){
+  printreceipt(shoppingcart['transaction']['id'],localconfig['receipt'],localconfig['ticket']);
+  //}
   clean_shoppingcart();
   $('#dlgPayement').modal('hide');
   //printpreview();
index cb09a18..d285d48 100644 (file)
       "integrity": "sha512-rXqOmH1VilAt2DyPzluTi2blhk17bO7ef+zLLPlWvG494pDxcM234pJ8wTc/6R40UWizAIIMgxjvxZg5kmsbag=="
     },
     "bootstrap-table": {
-      "version": "1.13.4",
-      "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.13.4.tgz",
-      "integrity": "sha512-033fnjYKgFZO98PL6E0JAqmwTJ2isoQxJBFU6BwEbIMmRZETk5iDoPGgV+7wORt4c+yABNWj8EnbFBWAHz5YPw=="
+      "version": "1.14.2",
+      "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.14.2.tgz",
+      "integrity": "sha512-TlB8YnAGg7SNixmwjre3zftOOostSfCF3zGpDUGD7xNsqVI2RwTAM5m9CPjgJe7fKVkid+EcfjEwKafr0kFnbQ=="
     },
     "brace-expansion": {
       "version": "1.1.11",
       "dev": true
     },
     "jquery": {
-      "version": "3.3.1",
-      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
-      "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg=="
+      "version": "3.4.0",
+      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.0.tgz",
+      "integrity": "sha512-ggRCXln9zEqv6OqAGXFEcshF5dSBvCkzj6Gm2gzuR5fWawaX8t7cxKVkkygKODrDAzKdoYw3l/e3pm3vlT4IbQ=="
     },
     "jsbn": {
       "version": "0.1.1",
     "paper-css": {
       "version": "0.4.1",
       "resolved": "https://registry.npmjs.org/paper-css/-/paper-css-0.4.1.tgz",
-      "integrity": "sha512-7gOjG4Hzy/ZGG/+tn8weFtSHWtQvSpkeJpFsH0nLqjXiH50zFyhajHggLEZd0hpCoYBhg5pRH5Lrg9p3EnDl2A=="
+      "integrity": "sha512-7gOjG4Hzy/ZGG/+tn8weFtSHWtQvSpkeJpFsH0nLqjXiH50zFyhajHggLEZd0hpCoYBhg5pRH5Lrg9p3EnDl2A==",
+      "dev": true
     },
     "parse-author": {
       "version": "2.0.0",
       }
     },
     "popper.js": {
-      "version": "1.14.7",
-      "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.14.7.tgz",
-      "integrity": "sha512-4q1hNvoUre/8srWsH7hnoSJ5xVmIL4qgz+s4qf2TnJIMyZFUFMGH+9vE7mXynAlHSZ/NdTmmow86muD0myUkVQ=="
+      "version": "1.15.0",
+      "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.15.0.tgz",
+      "integrity": "sha512-w010cY1oCUmI+9KwwlWki+r5jxKfTFDVoadl7MSrIujHU5MJ5OR6HTDj6Xo8aoR/QsA56x8jKjA59qGH4ELtrA=="
     },
     "pretty-bytes": {
       "version": "1.0.4",
       }
     },
     "tinymce": {
-      "version": "5.0.1",
-      "resolved": "https://registry.npmjs.org/tinymce/-/tinymce-5.0.1.tgz",
-      "integrity": "sha512-bAKaEEtRd4BsXu6ySYflhO83Cg844LHrplcaWalbdeZjFXwkodtv3G6H1x2r6ThaOdyE4+otJtxPYlfzwyKDdw=="
+      "version": "5.0.3",
+      "resolved": "https://registry.npmjs.org/tinymce/-/tinymce-5.0.3.tgz",
+      "integrity": "sha512-x7D0ttqn176Z4CWQIITMjcEtMGUjiaK0Y2FN2vO8DiyUeIHCdr70jJDSoGhuXtXX70Sw4Bd5UFfqIn/bG3HXcg=="
     },
     "tinymce-i18n": {
       "version": "19.2.11",
index 88a0497..6a6016d 100644 (file)
@@ -6,7 +6,7 @@
   "scripts": {
     "start": "electron .",
     "test": "echo \"Error: no test specified\" && exit 1",
-    "package-win": "electron-packager . cashbox --overwrite --asar --platform=win32 --arch=x64 --out=release-builds --version-string.CompanyName=DKS --version-string.FileDescription=DKS --version-string.ProductName=CashBox --icon=img/cashbox_KhG_icon.ico",
+    "package-win": "electron-packager . cashbox --overwrite --asar --platform=win32 --arch=x64 --out=release-builds --version-string.CompanyName=DKS --version-string.FileDescription=DKS --version-string.ProductName=CashBox --icon=img/cashbox_KhGn.ico",
     "build": "npm run pack:osx && npm run pack:win32 && npm run pack:win64"
   },
   "repository": {
     "jquery": "^3.3.1",
     "popper.js": "^1.14.7",
     "tinymce": "^5.0.1",
-    "tinymce-i18n": "^19.2.11"
+    "tinymce-i18n": "^19.2.11",
+    "paper-css": "^0.4.1",
+    "normalize.css": "^8.0.1"
     
   },
   "devDependencies": {
     "electron": "^4.0.5",
     "electron-packager": "^13.1.1",
-    "paper-css": "^0.4.1",
-    "normalize.css": "^8.0.1"
+    
   }
 }
index 9c3d168..8445e7f 100644 (file)
-var printconfig = {}
-$( document ).ready(function() {
-  //we need: databasename and transactionid
-  print.cfg = getSearchParams();
-});
+var printconfig = {};
+var trvalues = {};
+var trdata = {};
 
-var print = {
+var myprintdisplay = {
   cfg: null,
   getSearchParams: function (k){
     //alert(location.href);
     var p={};
-    console.log("params =>" + location.search);
+    //console.log("params =>" + location.search);
     location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v});
     return k?p[k]:p;
   },
   print: function(){
-    window.print();
+    this.print();
+  }
+}
+
+var receipt = {
+  gettransactionvalues(id){
+    trvalues = appdb.dbquery("select tr.id,strftime('%d.%m.%Y %H:%M:%S',tr.created) as created, tr.payementtype, tr.status, acc.name as account from transactions tr  left join accounts acc on (tr.id_account = acc.id) where tr.id='"+id+"';");
+  },
+  gettransactiondata(id){
+    trdata = appdb.dbquery("select quantity,productname,replace(printf('%.2f€',quantity * grossamount),'.',',') as grossamount,  grossamount as grossamountcalc from transactiondata where id_transaction='"+id+"';");
+  },
+  printreceipt(){
+    if (trvalues && trvalues.sqldata[0]){
+      $("#receipt").show();
+      $("#account").html(trvalues.sqldata[0]['account']);
+      var status = trvalues.sqldata[0]['status'];
+      if (trvalues.sqldata[0]['status'] == "payed"){
+        status += " / " + trvalues.sqldata[0]['payementtype'];
+      }
+      $("#status").html(status);
+      $("#creationdate").html(trvalues.sqldata[0]['created']);
+      $("#transactionid").html(trvalues.sqldata[0]['id']);
+      $("#receiptdata > tbody").html("");
+      var total = 0.00;
+      if (trdata){
+        for (var i in trdata.sqldata){
+          var row = '<tr>'+
+          '<td class="right">'+ trdata.sqldata[i].quantity+'</td>'+
+          '<td>'+ trdata.sqldata[i].productname+'</td>'+
+          '<td class="right">'+ trdata.sqldata[i].grossamount+'</td>'+
+          '</tr>';
+          total = total + parseFloat(trdata.sqldata[i].grossamountcalc);
+          $("#receiptdata > tbody").append(row);
+        }
+        $("#totalgross").html(total.toFixed(2) + "€")
+      }
+    }
+  },
+  printtickets(id){
+    $("#tickets").show();
+    $("#tickets").html("");
+    
+    for (var i in trdata.sqldata){
+      $("#tickets").append('<section class="sheet padding-10mm">' +
+    '<h1>Hand an Hand fir Afrika</h1>' +
+    '<h2>Drivers Day Hellange 2019</h2>' +
+    '<h3>Ticket</h3>' +
+    '<article>' +
+      '<table>' +
+        '<tr><th class="right ticket" style="width: 10%;">'+ trdata.sqldata[i].quantity+'</th><th class="ticket" style="width: 90%">'+ trdata.sqldata[i].productname+'</th></tr>' +
+      '</table>' +
+    '</article>' +
+    '<p>' +
+      '<span id="creationdate">'+trvalues.sqldata[0]['created']+'</span><br/>' +
+      '<span id="tranactionid">'+trvalues.sqldata[0]['id']+'</span>' +
+      '</p>' +
+  '</section>');
+    }
+  }
+}
+
+$( document ).ready(function() {
+  myprintdisplay.cfg = myprintdisplay.getSearchParams();
+  trvalues = {};
+  trdata = {};
+  $("#receipt").hide();
+  $("#ticket").hide();
+  //we need: databasename and transactionid
+  receipt.gettransactionvalues(myprintdisplay.cfg.id);
+  receipt.gettransactiondata(myprintdisplay.cfg.id);
+  //console.log("Hello");
+  if (myprintdisplay.cfg.receipt && myprintdisplay.cfg.receipt==1){
+    //console.log("Xreceipt")
+    receipt.printreceipt();
+  } 
+  if (myprintdisplay.cfg.ticket && myprintdisplay.cfg.ticket==1){
+    receipt.printtickets();
   }
+  //this.print().then(function(){this.close()});
+});
+
+function myFunction(){
+  //console.log(this);
+  //console.log($(this));
+  
+  setTimeout(waitforclose,5000);
+  
+}
+
+function waitforclose(){
+  this.close();
 }
 
+
+
index 39b7345..b9c6b40 100755 (executable)
@@ -4,8 +4,8 @@ var appdb = {
                dbquery: function(sQuery){\r
                \r
       var result= {sqldata:[]};\r
-      //console.log(sQuery);\r
-                       console.log(appdb.url + '/' + appdb.dbfile );\r
+      // console.log(sQuery);\r
+                       // console.log(appdb.url + '/' + appdb.dbfile );\r
                        //dump(this.url + 'db=' + this.dbfile + '&type=' + type + '&sql=' +encodeURIComponent(sQuery) + "\n");\r
                        $.ajax({\r
         encoding:"UTF-8",\r
index 864b46e..d3b487f 100644 (file)
@@ -4,19 +4,9 @@
 <head>
   <meta charset="utf-8">
   <title>Receipt</title>
-
-  <!-- Normalize or reset CSS with your favorite library -->
   <link rel="stylesheet" href="vendor/normalize/normalize.css">
-
-  <!-- Load paper.css for happy printing -->
   <link rel="stylesheet" href="vendor/paper-css/paper.css">
-
-  <!-- Set page size here: A5, A4 or A3 -->
-  <!-- Set also "landscape" if you need -->
   <style>@page { size: A7 }</style>
-
-  <!-- Custom styles for this document -->
-  <!-- <link href='https://fonts.googleapis.com/css?family=Tangerine:700' rel='stylesheet' type='text/css'> -->
   <style>
     body   { font-family: serif; }
     h1     { font-size: 12pt; font-weight: bold; line-height: 13pt; margin: 2px;}
     p      { font-size: 9pt; line-height: 7mm; }
     li     { font-size: 0pt; line-height: 5mm; }
     h1      { margin: 0 }
-    article { border: 4px double black; padding: 5mm 10mm; border-radius: 3mm }
+    article { border: 2px solid black; padding: 4mm 4mm; border-radius: 4mm }
     table {
       width: 100%;
     }
     .right {
       text-align: right;
     }
+    .left {
+      text-align: left;
+    }
+    .ticket {
+      font-weight: bold;
+      font-size: 20pt;
+    }
   </style>
 </head>
 
-<!-- Set "A5", "A4" or "A3" for class name -->
-<!-- Set also "landscape" if you need -->
-<body class="A7">
+<body class="A7" onafterprint="myFunction()">
+  <div id="tickets">
 
-  <!-- Each sheet element should have the class "sheet" -->
-  <!-- "padding-**mm" is optional: you can set 10, 15, 20 or 25 -->
-  <section class="sheet padding-5mm">
+  </div>
+
+  <section class="sheet padding-10mm" id="receipt" style="display: none;">
 
     <h1>Hand an Hand fir Afrika</h1>
     <h2>Drivers Day Hellange 2019</h2>
     <h3>Rechnung</h3>
-    <h4>Tisch: Table 2</h4>
-    <table>
+    <h4>bestellt von: <span id="account"></span></h4>
+    <table id="receiptdata">
       <thead>
-        <tr><th style="width: 10%;">Anz.</th><th style="width: 70%;">Produkt</th><th style="width: 20%;">Preis</th></tr>
+        <tr><th style="width: 10%;">Anz.</th><th class="left" style="width: 70%;">Produkt</th><th style="width: 20%;">Preis</th></tr>
       </thead>
       <tbody>
-        <tr>
-          <td class="right">1</td>
-          <td>Produkt Name</td>
-          <td class="right">0,00 €</td>
-        </tr>
-        <tr>
-            <td class="right">1</td>
-            <td>Produkt Name</td>
-            <td class="right">0,00 €</td>
-          </tr>
-          <tr>
-              <td class="right">1</td>
-              <td>Produkt Name</td>
-              <td class="right">0,00 €</td>
-            </tr>
-            <tr>
-                <td class="right">1</td>
-                <td>Produkt Name</td>
-                <td class="right">0,00 €</td>
-              </tr>
-              <tr>
-                  <td class="right">1</td>
-                  <td>Produkt Name</td>
-                  <td class="right">0,00 €</td>
-                </tr>
       </tbody>
       <tfoot>
-        <tr><th>&nbsp;</th><th class="right">Total:</th><th class="right">0,00 €</th></tr></tr>
+        <tr><th>&nbsp;</th><th class="right">Total:</th><th class="right" id="totalgross">0,00 €</th></tr></tr>
       </tfoot>
     </table>
 
-    <p>Bezahlt-Art: <span id="payementtype">Bar</span><br/>
-      <span id="creationdate">DD.MM.YYYY HH:MM</span><br/>
-      <span id="tranactionid">550e8400-e29b-11d4-a716-446655440000</span></p>
+    <p>Status: <span id="status"></span><br/>
+      <span id="creationdate"></span><br/>
+      <span id="transactionid"></span></p>
   </section>
-<script src="js/pagedata.js"></script>
+  
+  <script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
+  <script src="vendor/jquery/jquery.min.js"></script>
 <script src="js/webdatabase.js"></script>
 <script src="js/print.js"></script>
+<script>if (window.module) module = window.module;</script>
 </body>
   
 </html>
\ No newline at end of file
diff --git a/server/htdocs/ticket.html b/server/htdocs/ticket.html
deleted file mode 100644 (file)
index 384fbf8..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
-  <meta charset="utf-8">
-  <title>Ticket</title>
-  <link rel="stylesheet" href="vendor/normalize/normalize.css">
-  <link rel="stylesheet" href="vendor/paper-css/paper.css">
-  <style>@page { size: A7 }</style>
-  <style>
-    body   { font-family: serif; }
-    h1     { font-size: 12pt; font-weight: bold; line-height: 13pt; margin: 2px;}
-    h2     { font-size: 11pt; font-weight: bold; line-height: 12pt; margin: 2px;}
-    h3     { font-size: 10pt; font-weight: bold;}
-    h4     { font-size: 9pt; font-weight: bold; }
-    p      { font-size: 9pt; line-height: 7mm; }
-    li     { font-size: 0pt; line-height: 5mm; }
-    h1      { margin: 0 }
-    article { border: 2px solid black; padding: 4mm 4mm; border-radius: 4mm }
-    table {
-      width: 100%;
-    }
-    .right {
-      text-align: right;
-    }
-    section {
-      page-break-after: always;
-    }
-    .ticket {
-      font-weight: bold;
-      font-size: 20pt;
-    }
-  </style>
-</head>
-
-<!-- Set "A5", "A4" or "A3" for class name -->
-<!-- Set also "landscape" if you need -->
-<body class="A7">
-
-  <!-- Each sheet element should have the class "sheet" -->
-  <!-- "padding-**mm" is optional: you can set 10, 15, 20 or 25 -->
-  <section class="sheet padding-2mm">
-    <h1>Hand an Hand fir Afrika</h1>
-    <h2>Drivers Day Hellange 2019</h2>
-    <h3>Ticket</h3>
-    <article>
-      <table>
-        <tr><th class="right ticket" style="width: 10%;">1</th><th class="ticket" style="width: 90%">Produkt Name</th></tr>
-      </table>
-      
-    </article>
-    <p>
-      <span id="creationdate">DD.MM.YYYY HH:MM</span><br/>
-      <span id="tranactionid">550e8400-e29b-11d4-a716-446655440000</span></p>
-  </section>
-  <section class="sheet padding-5mm">
-      <h1>Hand an Hand fir Afrika</h1>
-      <h2>Drivers Day Hellange 2019</h2>
-      <h3>Ticket</h3>
-      <article>
-        <table>
-          <tr><th class="right ticket" style="width: 10%;">1</th><th class="ticket" style="width: 90%">Produkt Name</th></tr>
-        </table>
-        
-      </article>
-      <p>
-        <span id="creationdate">DD.MM.YYYY HH:MM</span><br/>
-        <span id="tranactionid">550e8400-e29b-11d4-a716-446655440000</span></p>
-    </section>
-</body>
-
-</html>
\ No newline at end of file