From 642580f291f814d84acfb1865337ad4fe25b07e1 Mon Sep 17 00:00:00 2001 From: Kilian Saffran Date: Fri, 12 Apr 2019 21:57:33 +0200 Subject: [PATCH] version x --- main.js | 51 ++++++++++------ modules/paywindow/index.js | 21 +++---- package-lock.json | 27 ++++---- package.json | 9 +-- server/htdocs/js/print.js | 105 +++++++++++++++++++++++++++++--- server/htdocs/js/webdatabase.js | 4 +- server/htdocs/receipt.html | 74 ++++++++-------------- server/htdocs/ticket.html | 72 ---------------------- 8 files changed, 185 insertions(+), 178 deletions(-) delete mode 100644 server/htdocs/ticket.html diff --git a/main.js b/main.js index 2282997..f47d8f9 100644 --- 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 diff --git a/modules/paywindow/index.js b/modules/paywindow/index.js index 69635d2..b207af2 100644 --- a/modules/paywindow/index.js +++ b/modules/paywindow/index.js @@ -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(); diff --git a/package-lock.json b/package-lock.json index cb09a18..d285d48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -135,9 +135,9 @@ "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", @@ -889,9 +889,9 @@ "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", @@ -1170,7 +1170,8 @@ "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", @@ -1264,9 +1265,9 @@ } }, "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", @@ -1609,9 +1610,9 @@ } }, "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", diff --git a/package.json b/package.json index 88a0497..6a6016d 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -27,13 +27,14 @@ "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" + } } diff --git a/server/htdocs/js/print.js b/server/htdocs/js/print.js index 9c3d168..8445e7f 100644 --- a/server/htdocs/js/print.js +++ b/server/htdocs/js/print.js @@ -1,20 +1,109 @@ -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 = ''+ + ''+ trdata.sqldata[i].quantity+''+ + ''+ trdata.sqldata[i].productname+''+ + ''+ trdata.sqldata[i].grossamount+''+ + ''; + 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('
' + + '

Hand an Hand fir Afrika

' + + '

Drivers Day Hellange 2019

' + + '

Ticket

' + + '
' + + '' + + '' + + '
'+ trdata.sqldata[i].quantity+''+ trdata.sqldata[i].productname+'
' + + '
' + + '

' + + ''+trvalues.sqldata[0]['created']+'
' + + ''+trvalues.sqldata[0]['id']+'' + + '

' + + '
'); + } + } +} + +$( 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(); } + + diff --git a/server/htdocs/js/webdatabase.js b/server/htdocs/js/webdatabase.js index 39b7345..b9c6b40 100755 --- a/server/htdocs/js/webdatabase.js +++ b/server/htdocs/js/webdatabase.js @@ -4,8 +4,8 @@ var appdb = { dbquery: function(sQuery){ var result= {sqldata:[]}; - //console.log(sQuery); - console.log(appdb.url + '/' + appdb.dbfile ); + // console.log(sQuery); + // console.log(appdb.url + '/' + appdb.dbfile ); //dump(this.url + 'db=' + this.dbfile + '&type=' + type + '&sql=' +encodeURIComponent(sQuery) + "\n"); $.ajax({ encoding:"UTF-8", diff --git a/server/htdocs/receipt.html b/server/htdocs/receipt.html index 864b46e..d3b487f 100644 --- a/server/htdocs/receipt.html +++ b/server/htdocs/receipt.html @@ -4,19 +4,9 @@ Receipt - - - - - - - - - - - - - + +
- - -
+
+ + - + + + + \ No newline at end of file diff --git a/server/htdocs/ticket.html b/server/htdocs/ticket.html deleted file mode 100644 index 384fbf8..0000000 --- a/server/htdocs/ticket.html +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - Ticket - - - - - - - - - - - - -
-

Hand an Hand fir Afrika

-

Drivers Day Hellange 2019

-

Ticket

-
- - -
1Produkt Name
- -
-

- DD.MM.YYYY HH:MM
- 550e8400-e29b-11d4-a716-446655440000

-
-
-

Hand an Hand fir Afrika

-

Drivers Day Hellange 2019

-

Ticket

-
- - -
1Produkt Name
- -
-

- DD.MM.YYYY HH:MM
- 550e8400-e29b-11d4-a716-446655440000

-
- - - \ No newline at end of file -- 2.39.5