r78 - in trunk: chorem-entities/src/main chorem-entities/src/main/java chorem-entities/src/main/java/org chorem-entities/src/main/java/org/chorem chorem-entities/src/main/java/org/chorem/entities chorem-web chorem-web/src/main/java/org/chorem/action
Author: bpoussin Date: 2011-04-14 00:03:31 +0200 (Thu, 14 Apr 2011) New Revision: 78 Url: http://chorem.org/repositories/revision/chorem/78 Log: ajout de quelques requetes pour la page d'accueil Added: trunk/chorem-entities/src/main/java/ trunk/chorem-entities/src/main/java/org/ trunk/chorem-entities/src/main/java/org/chorem/ trunk/chorem-entities/src/main/java/org/chorem/entities/ trunk/chorem-entities/src/main/java/org/chorem/entities/InvoiceableUtil.java Modified: trunk/chorem-web/pom.xml trunk/chorem-web/src/main/java/org/chorem/action/HomeAction.java Added: trunk/chorem-entities/src/main/java/org/chorem/entities/InvoiceableUtil.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/entities/InvoiceableUtil.java (rev 0) +++ trunk/chorem-entities/src/main/java/org/chorem/entities/InvoiceableUtil.java 2011-04-13 22:03:31 UTC (rev 78) @@ -0,0 +1,48 @@ +package org.chorem.entities; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.wikitty.ScriptEvaluator; +import org.nuiton.wikitty.WikittyProxy; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class InvoiceableUtil { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(InvoiceableUtil.class); + + static public boolean evalCondition(WikittyProxy proxy, Invoiceable invoiceable) { + Map<String, Object> bindings = new HashMap<String, Object>(); + bindings.put("proxy", proxy); + bindings.put("invoiceable", invoiceable); + Object resultEval = ScriptEvaluator.eval(null, + invoiceable.getName(), invoiceable.getCondition(), + invoiceable.getMimetype(), bindings); + boolean result= Boolean.TRUE.equals(resultEval); + return result; + } + + static public double evalValue(WikittyProxy proxy, Invoiceable invoiceable) { + Map<String, Object> bindings = new HashMap<String, Object>(); + bindings.put("proxy", proxy); + bindings.put("invoiceable", invoiceable); + Object resultEval = ScriptEvaluator.eval(null, + invoiceable.getName(), invoiceable.getValue(), + invoiceable.getMimetype(), bindings); + + double result = 0; + if (resultEval instanceof Number) { + result = ((Number) resultEval).doubleValue(); + } + return result; + } +} Modified: trunk/chorem-web/pom.xml =================================================================== --- trunk/chorem-web/pom.xml 2011-04-13 21:44:26 UTC (rev 77) +++ trunk/chorem-web/pom.xml 2011-04-13 22:03:31 UTC (rev 78) @@ -50,7 +50,7 @@ <dependency> <groupId>org.chorem.chorem</groupId> <artifactId>chorem-entities</artifactId> - <version>${version}</version> + <version>${project.version}</version> </dependency> <dependency> Modified: trunk/chorem-web/src/main/java/org/chorem/action/HomeAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/action/HomeAction.java 2011-04-13 21:44:26 UTC (rev 77) +++ trunk/chorem-web/src/main/java/org/chorem/action/HomeAction.java 2011-04-13 22:03:31 UTC (rev 78) @@ -4,32 +4,25 @@ import java.text.ParseException; import java.util.Collections; import java.util.Date; -import java.util.HashSet; -import java.util.LinkedList; import java.util.List; -import java.util.Set; import static org.nuiton.i18n.I18n.n_; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.entities.Company; -import org.chorem.entities.Interval; import org.chorem.entities.Invoice; import org.chorem.entities.Invoiceable; +import org.chorem.entities.InvoiceableImpl; +import org.chorem.entities.InvoiceableUtil; import org.chorem.entities.Person; -import org.chorem.entities.PersonImpl; import org.chorem.entities.ProjectOrder; import org.chorem.entities.Task; import org.chorem.entities.Touch; -import org.chorem.entities.TouchImpl; import org.chorem.entities.Worker; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.WikittyUtil; -import org.nuiton.wikitty.entities.BusinessEntity; -import org.nuiton.wikitty.entities.BusinessEntityImpl; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyUser; -import org.nuiton.wikitty.entities.WikittyUserImpl; import org.nuiton.wikitty.search.Criteria; import org.nuiton.wikitty.search.FacetTopic; import org.nuiton.wikitty.search.PagedResult; @@ -83,7 +76,7 @@ /** nombre de facture a envoyer */ protected int nbInvoiceToSend = 0; /** montant des factures a envoyer*/ - protected int invoiceAmountToSend = 0; + protected double invoiceAmountToSend = 0; /** cash flow pour les 3 prochains moins */ protected double[] cashFlow = new double[3]; @@ -106,7 +99,7 @@ String now = WikittyUtil.formatDate(new Date()); WikittyUser user = proxy.getUser(); - String userId = null; + String userId = "nobody"; if (user != null) { userId = user.getWikittyId(); } @@ -130,25 +123,22 @@ .criteria().addFacetField(ProjectOrder.FQ_FIELD_PROJECTORDER_STATUS).setEndIndex(0); Criteria taskOpen = Search.query().exteq(Task.EXT_TASK) - .eq(Task.FQ_FIELD_TASK_STATUS, "") + .neq(Task.FQ_FIELD_TASK_STATUS, "closed") .criteria().setEndIndex(0); Search taskOpenForMeSearch = Search.query().exteq(Worker.EXT_WORKER) .eq(Worker.FQ_FIELD_WORKER_PERSON, userId); taskOpenForMeSearch.associated(Worker.FQ_FIELD_WORKER_TASK) - .eq(Task.FQ_FIELD_TASK_STATUS, "closed"); + .neq(Task.FQ_FIELD_TASK_STATUS, "closed"); Criteria taskOpenForMe = taskOpenForMeSearch.criteria().setEndIndex(0); Criteria invoiceToSend = Search.query().exteq(Invoiceable.EXT_INVOICEABLE) .extneq(Invoice.EXT_INVOICE) .criteria().setEndIndex(0); - // FIXME poussin 20110406 il faut evaluer les conditions pour savoir - // lesquels sont reellement a facturer. idem pour les values - - PagedResult<Wikitty>[] results = proxy.multiFindAllByCriteria( + PagedResult<Wikitty>[] results = proxy.findAllByCriteria( company, person, touchLast7days, @@ -174,8 +164,25 @@ nbTaskOpen = results[5].getNumFound(); nbTaskOpenForMe = results[6].getNumFound(); - nbInvoiceToSend = results[7].getNumFound(); -// invoiceAmountToSend = results[10].getNumFound(); + // On evalue les conditions pour savoir + // lesquels sont reellement a facturer. idem pour les values + List<InvoiceableImpl> invoiceable = + results[7].cast(proxy, InvoiceableImpl.class).getAll(); + + int invoiceableCount = 0; + double invoiceableAmount = 0; + for(InvoiceableImpl i : invoiceable) { + boolean cond = InvoiceableUtil.evalCondition(proxy, i); + if (cond) { + invoiceableCount ++; + invoiceableAmount += InvoiceableUtil.evalValue(proxy, i); + } + } + + nbInvoiceToSend = invoiceableCount; + invoiceAmountToSend = invoiceableAmount; + + // // cashFlow = new double[]{ // results[11].getNumFound(), @@ -252,7 +259,7 @@ return nbTouchForLast7DaysForMe; } - public int getInvoiceAmountToSend() { + public double getInvoiceAmountToSend() { return invoiceAmountToSend; }
participants (1)
-
bpoussin@users.chorem.org