diff --git a/.classpath b/.classpath index 9bf7015..4ed820d 100644 --- a/.classpath +++ b/.classpath @@ -12,27 +12,27 @@ - + - + - + - + - + @@ -127,22 +127,22 @@ - + - + - + - + @@ -177,27 +177,27 @@ - + - + - + - + - + diff --git a/application.properties b/application.properties index e44b407..3d55d14 100644 --- a/application.properties +++ b/application.properties @@ -3,4 +3,4 @@ app.grails.version=2.5.5 app.name=StamPOS app.servlet.version=3.0 -app.version=2.9.0 +app.version=2.9.1 diff --git a/grails-app/controllers/stampos/BestellingController.groovy b/grails-app/controllers/stampos/BestellingController.groovy index 77f587f..729ff3b 100644 --- a/grails-app/controllers/stampos/BestellingController.groovy +++ b/grails-app/controllers/stampos/BestellingController.groovy @@ -39,6 +39,8 @@ class BestellingController { BestelRegel br = new BestelRegel(bestelling: bestelling, aantal: aantal, productPrijs: pp); br.save(); bestelRegels.add(br) + + tegoed -= aantal * pp.prijs } bestelling.bestelRegels = bestelRegels pushService.orderDone(bestelling) diff --git a/grails-app/controllers/stampos/WeeklyController.groovy b/grails-app/controllers/stampos/WeeklyController.groovy index a2b0c11..54ba914 100644 --- a/grails-app/controllers/stampos/WeeklyController.groovy +++ b/grails-app/controllers/stampos/WeeklyController.groovy @@ -8,11 +8,14 @@ class WeeklyController { static DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy") def index() { - Date today = new Date().clearTime() - Date endDate = params.endDate ? new Date(params.endDate as long) : today - Date beginDate = params.beginDate ? new Date(params.beginDate as long) : endDate - 7 - - def ordered = BestelRegel.executeQuery("select br.productPrijs.product.naam, sum(br.aantal), sum(br.aantal * br.productPrijs.prijs) from BestelRegel br where br.bestelling.datum > :dateFrom and br.bestelling.datum < :dateTo group by br.productPrijs.product.naam", + Date now = new Date() + Date beginDate = params.beginDate ? new Date(params.beginDate as long) : getStartOfWeek(now) + Date endDate = params.endDate ? new Date(params.endDate as long) : getEndOfWeek(now) + + def ordered = BestelRegel.executeQuery("select br.productPrijs.product.naam, sum(br.aantal), sum(br.aantal * br.productPrijs.prijs) from BestelRegel br "+ + "where br.bestelling.datum > :dateFrom and br.bestelling.datum < :dateTo "+ + "group by br.productPrijs.product.naam "+ + "order by br.productPrijs.product.sortering, br.productPrijs.product.naam", [dateFrom: beginDate, dateTo: endDate]) boolean nothingOrdered = ordered.isEmpty() int totalAmount = 0 @@ -44,6 +47,49 @@ class WeeklyController { previousEndDate: (endDate - 7).getTime(), nextBeginDate: (beginDate + 7).getTime(), nextEndDate: (endDate + 7).getTime(), - shouldShowLinkToNextWeek: endDate < today] + shouldShowLinkToNextWeek: endDate < getEndOfWeek(now)] } + + private Date getStartOfWeek(Date date) { + def cal = Calendar.instance + cal.setTime(date); + + while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { + cal.add(Calendar.DAY_OF_WEEK, -1) + } + + return getStartOfDay(cal.time) + } + + private Date getEndOfWeek(Date date) { + def cal = Calendar.instance + cal.setTime(date); + + while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { + cal.add(Calendar.DAY_OF_WEEK, +1) + } + + return getEndOfDay(cal.time) + } + + private Date getEndOfDay(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); + return calendar.getTime(); + } + + private Date getStartOfDay(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTime(); + } + } diff --git a/grails-app/views/instelling/overzicht.gsp b/grails-app/views/instelling/overzicht.gsp index 1df826c..04c453d 100644 --- a/grails-app/views/instelling/overzicht.gsp +++ b/grails-app/views/instelling/overzicht.gsp @@ -42,7 +42,7 @@
- +

@@ -74,7 +74,7 @@

- +
diff --git a/web-app/js/javascript.js b/web-app/js/javascript.js index 1c5c71a..8394685 100644 --- a/web-app/js/javascript.js +++ b/web-app/js/javascript.js @@ -362,7 +362,7 @@ function confirmOrder() { alert(message); } - $("#credit").html(userdata.tegoed.toFixed(2)); + $("#credit").html(formatter.format(userdata.tegoed)); clearOrder(); clearTimeout(naOrderKlantWegTimeout);