Skip to content

Commit

Permalink
Issue #39
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dellermann committed Mar 4, 2014
1 parent fccac9a commit 334466c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 25 additions & 10 deletions grails-app/conf/org/amcworld/springcrm/ViewFilters.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 =
Expand All @@ -82,15 +88,24 @@ 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 = {
session[sessionKey('offset')] = params.offset
}
}

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'
Expand All @@ -110,7 +125,7 @@ class ViewFilters {
* view.
*/
if (!params.confirmed) {
redirect(controller: controllerName, action: 'list')
redirect controller: controllerName, action: 'list'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 334466c

Please sign in to comment.