Skip to content

Commit

Permalink
Turnover overview optimizations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dellermann committed Dec 6, 2016
1 parent ecd3b34 commit 4341904
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion grails-app/conf/buildNumber
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11054
11061
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ class ReportController {
*/
def turnoverOverview() {
int year = params.year as Integer ?: 0i
String order = params.order ?: 'desc'

Map<Organization, BigDecimal> turnoverList =
invoicingTransactionService.computeTurnoverList(
year, order == 'asc'
year, params.sort ?: 'turnover', params.order ?: 'desc'
)

/* find first and last year of all customer accounts */
Expand All @@ -149,7 +148,7 @@ class ReportController {

[
turnoverList: turnoverList, yearStart: yearStart, yearEnd: yearEnd,
year: year, order: order
year: year
]
}

Expand Down
3 changes: 0 additions & 3 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions grails-app/i18n/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Organization, BigDecimal> 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<String, Object> args = year > 0 ? [year: year] : [: ]
List<Object[]> l = Invoice.executeQuery(sql, args) as List<Object[]>
Expand Down
26 changes: 12 additions & 14 deletions grails-app/views/report/turnoverOverview.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

<g:render template="/layouts/flashMessage"/>
<g:form action="turnoverOverview" method="get" class="form-inline">
<g:hiddenField name="sort" value="${params.sort}"/>
<g:hiddenField name="order" value="${params.order}"/>
<div class="form-group">
<label for="year"
><g:message code="report.turnoverOverview.year.label"
Expand All @@ -38,14 +40,6 @@
value="${year}" class="form-control"
noSelection="[0: message(code: 'report.turnoverOverview.year.overview')]"/>
</div>
<div class="form-group">
<label for="order"
><g:message code="report.turnoverOverview.order.label"
/></label>
<g:select from="['asc', 'desc']" id="order" name="order"
value="${order}" class="form-control"
valueMessagePrefix="report.turnoverOverview.order"/>
</div>
<button type="submit" class="btn btn-primary">
<g:message code="report.turnoverOverview.btn.submit"/>
</button>
Expand All @@ -61,17 +55,21 @@
<table class="table data-table price-table report report-turnover">
<thead>
<tr>
<th>
<g:message code="invoicingTransaction.organization.label"/>
</th>
<th><g:message code="report.turnover.turnover.total"/></th>
<th></th>
<g:sortableColumn property="organization" params="[year: year]"
title="${message(code: 'invoicingTransaction.organization.label')}"/>
<g:sortableColumn property="turnover" params="[year: year]"
title="${message(code: 'report.turnover.turnover.total')}"/>
</tr>
</thead>
<tbody>
<g:each in="${turnoverList}" var="entry">
<g:each in="${turnoverList}" var="entry" status="i">
<tr>
<td class="col-type-number turnover-overview-index">${i + 1}.</td>
<td class="col-type-ref turnover-overview-organization">
${entry.key.name}
<g:link action="turnoverReport"
params="['organization.id': entry.key.id]"
>${entry.key.name}</g:link>
</td>
<td class="col-type-currency turnover-overview-turnover">
<g:formatCurrency number="${entry.value}" displayZero="true"
Expand Down

0 comments on commit 4341904

Please sign in to comment.