Author: bpoussin Date: 2012-09-14 02:02:58 +0200 (Fri, 14 Sep 2012) New Revision: 268 Url: http://chorem.org/repositories/revision/chorem/268 Log: ajout d'un dashboard: annual profit Added: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardAnnualProfit.jsp Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/report.jsp Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java 2012-09-13 16:55:55 UTC (rev 267) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java 2012-09-14 00:02:58 UTC (rev 268) @@ -31,6 +31,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.TreeMap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -143,56 +144,92 @@ // //////////////////////////////////////////////////////////////////////////// - public Render summary(ChoremClient client) { - Date now = new Date(); - Date inOneWeek = DateUtils.addDays(now, 7); - Date firstDayYear = DateUtil.setFirstDayOfYear(now); - Date lastYearNow = DateUtils.addYears(now, -1); - Date lastYearFirstDay = DateUtil.setFirstDayOfYear(lastYearNow); - - String companyId = client.getConfiguration().getDefaultCompany(); - + protected WikittyQuery[] getDebtIncomeQuery(Date first, Date last, String companyId) { // toutes les depenses depuis le debut de l'annee - WikittyQuery annualDebtQuery = new WikittyQueryMaker() + WikittyQuery debtQuery = new WikittyQueryMaker() .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) .and() .exteq(Invoice.EXT_INVOICE) - .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, firstDayYear, now) + .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, first, last) .containsOne(Invoice.FQ_FIELD_INVOICE_CUSTOMER) .select(Element.ID).or().ideq(companyId).eq(Employee.FQ_FIELD_EMPLOYEE_COMPANY, companyId).close() .end().setLimit(WikittyQuery.MAX); // toutes les factures emises depuis le debut de l'annee - WikittyQuery annualIncomeQuery = new WikittyQueryMaker() + WikittyQuery incomeQuery = new WikittyQueryMaker() .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) .and() .exteq(Invoice.EXT_INVOICE) - .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, firstDayYear, now) + .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, first, last) .containsOne(Invoice.FQ_FIELD_INVOICE_SUPPLIER) .select(Element.ID).or().ideq(companyId).eq(Employee.FQ_FIELD_EMPLOYEE_COMPANY, companyId).close() .end().setLimit(WikittyQuery.MAX); + + WikittyQuery[] result = new WikittyQuery[]{ + debtQuery, incomeQuery + }; + return result; + } - // toutes les depenses depuis le debut de l'annee - WikittyQuery lastYearAnnualDebtQuery = new WikittyQueryMaker() - .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) - .and() - .exteq(Invoice.EXT_INVOICE) - .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, lastYearFirstDay, lastYearNow) - .containsOne(Invoice.FQ_FIELD_INVOICE_CUSTOMER) - .select(Element.ID).or().ideq(companyId).eq(Employee.FQ_FIELD_EMPLOYEE_COMPANY, companyId).close() - .end().setLimit(WikittyQuery.MAX); + /** + * Dashbord qui indique pour toutes les annees du systeme le CA et les depenses + * @param client + * @return + */ + public Render annualProfit(ChoremClient client) { + Map<Date, Double[]> result = new TreeMap<Date, Double[]>(); - // toutes les factures emises depuis le debut de l'annee - WikittyQuery lastYearAnnualIncomeQuery = new WikittyQueryMaker() - .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) - .and() - .exteq(Invoice.EXT_INVOICE) - .bw(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, lastYearFirstDay, lastYearNow) - .containsOne(Invoice.FQ_FIELD_INVOICE_SUPPLIER) - .select(Element.ID).or().ideq(companyId).eq(Employee.FQ_FIELD_EMPLOYEE_COMPANY, companyId).close() + String companyId = client.getConfiguration().getDefaultCompany(); + + // La premiere annee + WikittyQuery firstDateQuery = new WikittyQueryMaker() + .select(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, Aggregate.MIN) + .exteq(Invoice.EXT_INVOICE) .end().setLimit(WikittyQuery.MAX); + // La derniere annee + WikittyQuery lastDateQuery = new WikittyQueryMaker() + .select(Invoice.FQ_FIELD_INVOICE_POSTEDDATE, Aggregate.MAX) + .exteq(Invoice.EXT_INVOICE) + .end().setLimit(WikittyQuery.MAX); + Date[] dates = client.findByQuery(Date.class, firstDateQuery, lastDateQuery); + Date firstDay = DateUtil.setFirstDayOfYear(dates[0]); + Date lastDay = DateUtil.setLastDayOfYear(dates[1]); + log.debug(String.format("first date: %s last date: %s", dates[0], dates[1])); + + Date currentFirst = firstDay; + Date currentLast = DateUtil.setLastDayOfYear(firstDay); + while (currentLast.compareTo(lastDay) <= 0) { + WikittyQuery[] annualDebtIncomeQuery = + getDebtIncomeQuery(currentFirst, currentLast, companyId); + Double[] values = client.findByQuery(Double.class, + annualDebtIncomeQuery[0], annualDebtIncomeQuery[1]); + result.put(currentFirst, values); + currentFirst = DateUtils.addYears(currentFirst, 1); + currentLast = DateUtils.addYears(currentLast, 1); + } + return renderView("dashboardAnnualProfit.jsp", "annualProfit", result); + } + + /** + * Dashbord pour la page d'accueil + * @param client + * @return + */ + public Render summary(ChoremClient client) { + Date now = new Date(); + Date inOneWeek = DateUtils.addDays(now, 7); + Date firstDayYear = DateUtil.setFirstDayOfYear(now); + Date lastYearNow = DateUtils.addYears(now, -1); + Date lastYearFirstDay = DateUtil.setFirstDayOfYear(lastYearNow); + + String companyId = client.getConfiguration().getDefaultCompany(); + + // toutes les depenses depuis le debut de l'annee + WikittyQuery[] annualDebtIncomeQuery = getDebtIncomeQuery(firstDayYear, now, companyId); + WikittyQuery[] pastAnnualDebtIncomeQuery = getDebtIncomeQuery(lastYearFirstDay, lastYearNow, companyId); + // les factures que notre societe doit payer au plus tard dans 7 jours WikittyQuery invoiceDebtQuery = new WikittyQueryMaker() .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) @@ -225,8 +262,8 @@ WikittyQueryResult<Double>[] invoices = client.findAllByQuery(Double.class, invoiceDebtQuery, invoiceIncomeQuery, - annualDebtQuery, annualIncomeQuery, - lastYearAnnualDebtQuery, lastYearAnnualIncomeQuery); + annualDebtIncomeQuery[0], annualDebtIncomeQuery[1], + pastAnnualDebtIncomeQuery[0], pastAnnualDebtIncomeQuery[1]); WikittyQueryResult<String> touchs = client.findAllByQuery(touchQuery); Copied: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardAnnualProfit.jsp (from rev 263, trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardWorkingProjectDaysByEmployee.jsp) =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardAnnualProfit.jsp (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardAnnualProfit.jsp 2012-09-14 00:02:58 UTC (rev 268) @@ -0,0 +1,46 @@ +<%-- + #%L + Chorem webmotion + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2011 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %> + +<h1>Bénéfice ou perte par année</h1> + +<table class="table table-striped table-bordered table-condensed"> + <tr> + <th>Année</th> + <th>CA HT</th> + <th>CA TTC</th> + <th>Dépense</th> + <th>Bénéfice/perte</th> + </tr> + <c:forEach var="q" items="${annualProfit.keySet()}"> + <tr> + <th><f:formatDate pattern="yyyy" value="${q}"/></th> + <td><f:formatNumber type="currency" value="${annualProfit.get(q)[1]}"/></td> + <td><f:formatNumber type="currency" value="${annualProfit.get(q)[1]*1.196}"/></td> + <td><f:formatNumber type="currency" value="${annualProfit.get(q)[0]}"/></td> + <td><f:formatNumber type="currency" value="${annualProfit.get(q)[1]*1.196 - annualProfit.get(q)[0]}"/></td> + </tr> + </c:forEach> +</table> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-09-13 16:55:55 UTC (rev 267) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-09-14 00:02:58 UTC (rev 268) @@ -152,6 +152,7 @@ <li><a href="<c:url value="/report?report=invoiceIncome"/>">Income</a></li> <li><a href="<c:url value="/report?report=profitability"/>">Profitability</a></li> <li><a href="<c:url value="/report?report=budget"/>">Budget</a></li> + <li><a href="<c:url value="/report?report=annualProfit"/>">Annual profit</a></li> </ul> </li> <li class="dropdown nav-group"> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/report.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/report.jsp 2012-09-13 16:55:55 UTC (rev 267) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/report.jsp 2012-09-14 00:02:58 UTC (rev 268) @@ -55,3 +55,6 @@ <c:if test="${report == null || report == '' || report.contains('budget')}"> <jsp:include page="/fragment/dashboard/budget"/> </c:if> + <c:if test="${report == null || report == '' || report.contains('annualProfit')}"> + <jsp:include page="/fragment/dashboard/annualProfit"/> + </c:if>