From 43419048663ab097c8a0b3781446e43cbed7201d Mon Sep 17 00:00:00 2001 From: Daniel Ellermann Date: Tue, 6 Dec 2016 12:35:02 +0100 Subject: [PATCH] Turnover overview optimizations Optimize the turnover overview: - compute net instead of gross values - allow ordering by organization and turnover - add index numbers to each row in the overview - add links to turnover report for a particular organization --- grails-app/conf/buildNumber | 2 +- .../springcrm/ReportController.groovy | 5 +-- grails-app/i18n/messages.properties | 3 -- grails-app/i18n/messages_de.properties | 3 -- .../InvoicingTransactionService.groovy | 43 +++++++++++-------- grails-app/views/report/turnoverOverview.gsp | 26 ++++++----- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/grails-app/conf/buildNumber b/grails-app/conf/buildNumber index 2e6b2815..785aa110 100644 --- a/grails-app/conf/buildNumber +++ b/grails-app/conf/buildNumber @@ -1 +1 @@ -11054 \ No newline at end of file +11061 \ No newline at end of file diff --git a/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy b/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy index ed8dca8f..10e63fcd 100644 --- a/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy +++ b/grails-app/controllers/org/amcworld/springcrm/ReportController.groovy @@ -136,11 +136,10 @@ class ReportController { */ def turnoverOverview() { int year = params.year as Integer ?: 0i - String order = params.order ?: 'desc' Map turnoverList = invoicingTransactionService.computeTurnoverList( - year, order == 'asc' + year, params.sort ?: 'turnover', params.order ?: 'desc' ) /* find first and last year of all customer accounts */ @@ -149,7 +148,7 @@ class ReportController { [ turnoverList: turnoverList, yearStart: yearStart, yearEnd: yearEnd, - year: year, order: order + year: year ] } diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index ebd27f71..f8eae7a2 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -1221,7 +1221,4 @@ project.currentProjects.btn.projects=All projects report.turnoverOverview.title=Turnover overview report.turnoverOverview.year.label=Year report.turnoverOverview.year.overview=Total -report.turnoverOverview.order.label=Order -report.turnoverOverview.order.asc=ascending -report.turnoverOverview.order.desc=descending report.turnoverOverview.btn.submit=Show diff --git a/grails-app/i18n/messages_de.properties b/grails-app/i18n/messages_de.properties index e6bf579e..e8800a3a 100644 --- a/grails-app/i18n/messages_de.properties +++ b/grails-app/i18n/messages_de.properties @@ -1221,7 +1221,4 @@ project.currentProjects.btn.projects=Alle Projekte report.turnoverOverview.title=Umsatzübersicht report.turnoverOverview.year.label=Jahr report.turnoverOverview.year.overview=Gesamt -report.turnoverOverview.order.label=Sortierung -report.turnoverOverview.order.asc=aufsteigend -report.turnoverOverview.order.desc=absteigend report.turnoverOverview.btn.submit=Anzeigen diff --git a/grails-app/services/org/amcworld/springcrm/InvoicingTransactionService.groovy b/grails-app/services/org/amcworld/springcrm/InvoicingTransactionService.groovy index 9b7ae9e4..96291961 100644 --- a/grails-app/services/org/amcworld/springcrm/InvoicingTransactionService.groovy +++ b/grails-app/services/org/amcworld/springcrm/InvoicingTransactionService.groovy @@ -50,34 +50,43 @@ class InvoicingTransactionService implements Service { * Computes a list of turnover of all organizations optionally filtered by * the given year. * - * @param year the given year; if zero the total turnover is computed - * @param orderAsc if {@code true} the turnover values are sorted - * ascending; if {@code false} they are sorted descending - * @return a sorted map containing the organizations and their - * turnover + * @param year the given year; if zero the total turnover is computed + * @param sort the property to sort by; must be either {@code turnover} or + * {@code organization} + * @param order the sort order; either {@code asc} or {@code desc} + * @return a sorted map containing the organizations and their + * turnover * @since 2.1 */ Map computeTurnoverList(int year = 0, - boolean orderAsc = false) + String sort = 'turnover', + String order = 'desc') { + if (sort != 'turnover') { + sort = 'ii.invoicingTransaction.organization.name' + } String sql = """ select - i.organization, - sum(i.total) - ifnull(( + ii.invoicingTransaction.organization, + sum(ii.quantity * ii.unitPrice) - ifnull(( select - sum(c.total) + sum(ci.quantity * ci.unitPrice) from - CreditMemo c + InvoicingItem ci where - c.organization = i.organization - ${getTurnoverWhere(year, 'c', 'and ')} + ci.invoicingTransaction.type = 'C' and + ci.invoicingTransaction.organization = + ii.invoicingTransaction.organization + ${getTurnoverWhere(year, 'ci.invoicingTransaction', 'and ')} group by - c.organization + ci.invoicingTransaction.organization ), 0) as turnover - from Invoice i - ${getTurnoverWhere(year, 'i', 'where ')} - group by i.organization - order by turnover ${orderAsc ? 'asc' : 'desc'} + from InvoicingItem ii + where + ii.invoicingTransaction.type = 'I' + ${getTurnoverWhere(year, 'ii.invoicingTransaction', 'and ')} + group by ii.invoicingTransaction.organization + order by ${sort} ${order} """ Map args = year > 0 ? [year: year] : [: ] List l = Invoice.executeQuery(sql, args) as List diff --git a/grails-app/views/report/turnoverOverview.gsp b/grails-app/views/report/turnoverOverview.gsp index 05dcfa5c..05b372a8 100644 --- a/grails-app/views/report/turnoverOverview.gsp +++ b/grails-app/views/report/turnoverOverview.gsp @@ -30,6 +30,8 @@ + +
-
- - -
@@ -61,17 +55,21 @@ - - + + + - + +
- -
${i + 1}. - ${entry.key.name} + ${entry.key.name}