From 334466c0a5a495913d9f8e073d2adf38d62d9918 Mon Sep 17 00:00:00 2001 From: Daniel Ellermann Date: Tue, 4 Mar 2014 21:28:08 +0100 Subject: [PATCH] Issue #39 I implement issue #39 (remember the current view in sales journal). I store the selected month and year in the session if the user calls the sales journal and restore these values if no month and year are submitted. --- application.properties | 6 ++-- .../org/amcworld/springcrm/ViewFilters.groovy | 35 +++++++++++++------ .../springcrm/ReportController.groovy | 6 ++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/application.properties b/application.properties index 4900acdb..f1b1bc59 100644 --- a/application.properties +++ b/application.properties @@ -1,7 +1,7 @@ #Grails Metadata file -#Tue Mar 04 20:02:36 CET 2014 -app.buildDate=2014-03-04T20\:02\:36+0100 -app.buildNumber=6056 +#Tue Mar 04 21:10:33 CET 2014 +app.buildDate=2014-03-04T21\:10\:33+0100 +app.buildNumber=6059 app.buildProfile=development app.grails.version=2.3.4.BUILD-SNAPSHOT app.name=springcrm diff --git a/grails-app/conf/org/amcworld/springcrm/ViewFilters.groovy b/grails-app/conf/org/amcworld/springcrm/ViewFilters.groovy index 02ace468..593fe4be 100644 --- a/grails-app/conf/org/amcworld/springcrm/ViewFilters.groovy +++ b/grails-app/conf/org/amcworld/springcrm/ViewFilters.groovy @@ -1,7 +1,7 @@ /* * ViewFilters.groovy * - * Copyright (c) 2011-2013, Daniel Ellermann + * Copyright (c) 2011-2014, Daniel Ellermann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,16 @@ class ViewFilters { UserService userService def filters = { + + def exchangeSetting = + { def params, String paramName, def settings, String settingsKey -> + if (params[paramName] == null) { + params[paramName] = settings[settingsKey] + } else { + settings[settingsKey] = params[paramName] + } + } + commonData(controller: '*', action: '*') { after = { model -> if (model) { @@ -54,18 +64,14 @@ class ViewFilters { def sessionKey = { String name -> String key = name + controllerName.capitalize() if (params.type) key += params.type - return key + key } before = { - def f = { pk, s, sk -> - if (params[pk] == null) params[pk] = s[sk] - else s[sk] = params[pk] - } /* store or restore offset */ String key = sessionKey('offset') - f('offset', session, key) + exchangeSetting params, 'offset', session, key /* compute number of entries of the associated domain */ GrailsClass cls = @@ -82,8 +88,8 @@ class ViewFilters { String name = controllerName.capitalize() User user = session.user if (!user.attached) user.attach() - f('sort', user.settings, "sort${name}") - f('order', user.settings, "order${name}") + exchangeSetting params, 'sort', user.settings, "sort${name}" + exchangeSetting params, 'order', user.settings, "order${name}" } after = { @@ -91,6 +97,15 @@ class ViewFilters { } } + salesJournalView(controller: 'report', action: 'sales-journal') { + before = { + User user = session.user + if (!user.attached) user.attach() + exchangeSetting params, 'year', session, 'salesJournalYear' + exchangeSetting params, 'month', session, 'salesJournalMonth' + } + } + selectorView(controller: '*', action: 'list') { after = { model -> String view = (params.view == 'selector') ? 'selectorList' : 'list' @@ -110,7 +125,7 @@ class ViewFilters { * view. */ if (!params.confirmed) { - redirect(controller: controllerName, action: 'list') + redirect controller: controllerName, action: 'list' } } } diff --git a/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy b/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy index 8f3d26f9..c33ed74c 100644 --- a/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy +++ b/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy @@ -27,7 +27,7 @@ import static java.util.Calendar.* * The class {@code ReportController} produces several reports such as sales * journals. * - * @author Daniel Ellermann + * @author Daniel Ellermann * @version 1.3 */ class ReportController { @@ -38,7 +38,8 @@ class ReportController { def salesJournal() { def cal = Calendar.instance - int year = (params.year as Integer) ?: cal[YEAR] + def currentYear = cal[YEAR] + int year = (params.year as Integer) ?: currentYear cal[YEAR] = year int month = cal[MONTH] + 1 if (params.month) { @@ -79,6 +80,7 @@ class ReportController { if (!l.empty) yearStart = Math.min(yearStart, l[0].docDate[YEAR]) l = CreditMemo.list(sort: 'docDate', order: 'desc', max: 1) if (!l.empty) yearEnd = Math.max(yearEnd, l[0].docDate[YEAR]) + yearEnd = Math.max(yearEnd, currentYear) def total = 0.0 def totalPaymentAmount = 0.0