Author: bpoussin Date: 2012-06-04 07:08:40 +0200 (Mon, 04 Jun 2012) New Revision: 173 Url: http://chorem.org/repositories/revision/chorem/173 Log: - ajout de category sur invoiceable (et ajout en preload) - modif des dashboard qui utilisait Quotation.type pour utiliser Quotation.category - ajout page admin pour l'objet Configuration - ajout d'extension dans la base dans la sequence d'init de programme - ajout dasboard budget (fonctionne pas encore, probleme de recherche des noeuds racines) Added: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/AdminAction.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardBudget.jsp Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java trunk/chorem-entities/src/main/xmi/chorem-model.properties trunk/chorem-entities/src/main/xmi/chorem-model.zargo trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java trunk/chorem-webmotion/src/main/resources/mapping trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardProfitability.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardQuotation.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial.jsp Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-06-04 05:08:40 UTC (rev 173) @@ -94,6 +94,7 @@ List<WikittyExtension> exts = new ArrayList<WikittyExtension>(); exts.addAll(org.chorem.entities.ConfigurationAbstract.extensions); + exts.addAll(org.chorem.entities.CategoryAbstract.extensions); exts.addAll(org.chorem.entities.AttachmentAbstract.extensions); exts.addAll(org.chorem.entities.CompanyAbstract.extensions); exts.addAll(org.chorem.entities.ContactDetailsAbstract.extensions); @@ -116,6 +117,13 @@ exts.addAll(org.chorem.entities.VacationAbstract.extensions); exts.addAll(org.chorem.entities.WorkerAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyGroupAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyUserAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyTreeNodeAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyHookAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyAuthorisationAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyLabelAbstract.extensions); + ws.storeExtension(null, exts); } } Modified: trunk/chorem-entities/src/main/xmi/chorem-model.properties =================================================================== --- trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-06-04 05:08:40 UTC (rev 173) @@ -1,4 +1,6 @@ -org.chorem.entities.Configration.class.tagvalue.version=2.0 +org.chorem.entities.Configuration.class.tagvalue.version=2.0 +org.chorem.entities.Category.class.tagvalue.version=3.0 +org.chorem.entities.Category.class.tagvalue.toString=%WikittyTreeNode.name|noname$s org.chorem.entities.Project.class.tagvalue.version=5.0 org.chorem.entities.Project.class.tagvalue.toString=%Project.name|noname$s org.chorem.entities.Project.class.tagvalue.sortOrder=Project.name @@ -69,17 +71,17 @@ org.chorem.entities.Attachment.class.tagvalue.toString=%Attachment.name|noname$s (%Attachment.mimetype|notype$s) %Attachment.date$tF org.chorem.entities.Attachment.class.tagvalue.sortOrder=Attachment.name,Attachment.mimetype,Attachment.date org.chorem.entities.Quotation.class.tagvalue.version=10.0 -org.chorem.entities.Quotation.class.tagvalue.preload=Quotation.project;Quotation.customer;Quotation.supplier -org.chorem.entities.Quotation.class.tagvalue.toString=%Interval.beginDate$tF-%Interval.endDate$tF %Quotation.reference|noref$s(%Quotation.type|notype$s) %Quotation.description|nodescription$s +org.chorem.entities.Quotation.class.tagvalue.preload=Quotation.project;Quotation.customer;Quotation.supplier;Quotation.category +org.chorem.entities.Quotation.class.tagvalue.toString=%Interval.beginDate$tF-%Interval.endDate$tF %Quotation.reference|noref$s(%Quotation.category|noCategory$s) %Quotation.description|nodescription$s org.chorem.entities.Quotation.class.tagvalue.sortOrder=Interval.beginDate,Interval.endDate,Quotation.reference,Quotation.type,Quotation.description org.chorem.entities.Quotation.attribute.status.tagvalue.allowed=DRAFT,SEND,REJECTED,ACCEPTED,STARTED,DELIVERED,VRS,WARRANTY,CLOSED org.chorem.entities.Quotation.attribute.conversionHope.tagvalue.min=0 org.chorem.entities.Quotation.attribute.conversionHope.tagvalue.max=100 -org.chorem.entities.Invoice.class.tagvalue.version=6.0 -org.chorem.entities.Invoice.class.tagvalue.preload=Invoice.target +org.chorem.entities.Invoice.class.tagvalue.version=8.0 +org.chorem.entities.Invoice.class.tagvalue.preload=Invoice.target;Invoice.customer;Invoice.supplier org.chorem.entities.Invoice.class.tagvalue.toString=%Invoice.reference|noref$s %Invoice.amount|noamount$s %Invoice.postedDate$tF %Invoice.expectedDate$tF %Invoice.paymentDate$tF org.chorem.entities.Invoice.class.tagvalue.sortOrder=Invoice.postedDate,Invoice.expectedDate,Invoice.paymentDate,Invoice.reference,Invoice.amount -org.chorem.entities.Invoiceable.class.tagvalue.version=6.0 -org.chorem.entities.Invoiceable.class.tagvalue.preload=Invoiceable.customer;Invoiceable.supplier +org.chorem.entities.Invoiceable.class.tagvalue.version=8.0 +org.chorem.entities.Invoiceable.class.tagvalue.preload=Invoiceable.category org.chorem.entities.Invoiceable.class.tagvalue.toString=%Invoiceable.name|noname$s org.chorem.entities.Invoiceable.class.tagvalue.sortOrder=Invoiceable.name Modified: trunk/chorem-entities/src/main/xmi/chorem-model.zargo =================================================================== (Binary files differ) Added: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/AdminAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/AdminAction.java (rev 0) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/AdminAction.java 2012-06-04 05:08:40 UTC (rev 173) @@ -0,0 +1,37 @@ +package org.chorem.webmotion.actions; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.ChoremClient; +import org.chorem.entities.Configuration; +import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.render.Render; +import org.nuiton.wikitty.query.WikittyQuery; +import org.nuiton.wikitty.query.WikittyQueryMaker; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class AdminAction extends WebMotionController { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(AdminAction.class); + + /** + * Bilan du nombre de jour travaille sur des projets client depuis le 01/01 par employer de la + * societe par defaut (Configuration.defaultCompany) + */ + public Render variables(ChoremClient client) { + Configuration conf = client.getConfiguration(); + + GenericAction g = new GenericAction(); + return g.view(client, conf.getWikittyId(), null); + } + +} 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-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/DashboardAction.java 2012-06-04 05:08:40 UTC (rev 173) @@ -8,18 +8,22 @@ import java.util.Date; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.ChoremClient; import org.chorem.entities.Attachment; +import org.chorem.entities.Category; import org.chorem.entities.Configuration; import org.chorem.entities.ConfigurationImpl; import org.chorem.entities.Employee; @@ -35,10 +39,14 @@ import org.debux.webmotion.server.render.Render; import org.nuiton.util.ObjectUtil; import org.nuiton.wikitty.entities.Element; +import org.nuiton.wikitty.entities.ElementField; +import org.nuiton.wikitty.entities.WikittyTreeNode; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; import org.nuiton.wikitty.query.WikittyQueryParser; import org.nuiton.wikitty.query.WikittyQueryResult; +import org.nuiton.wikitty.query.WikittyQueryResultTreeNode; +import org.nuiton.wikitty.query.conditions.Aggregate; /** * @@ -63,11 +71,17 @@ * @param <K> * @param <V> */ - static public class MapWithDefault<K, V> implements Map<K, V> { + static public class MapWithDefault<K, V> implements Map<K, V>, Cloneable { protected Map<K, V> map; protected Object defaultValue; protected Collection args; + @Override + public Object clone() throws CloneNotSupportedException { + MapWithDefault result = (MapWithDefault)super.clone(); + return result; + } + /** * L'objet par default utilise est l'objet passe en parametre s'il n'est * pas clonable ou un clone de l'objet s'il est clonable. @@ -622,4 +636,116 @@ "workingProjectDaysByEmployee", days ); } + + /** + * Prévisionnel entre deux dates en fonction des factures + */ + public Render budget(ChoremClient client, Date start, Date end, String filter) { + if (log.isDebugEnabled()) { + log.debug(String.format( + "budget for period '%s' to '%s' with filter '%s'", + start, end, filter)); + } + String companyId = client.getConfiguration().getDefaultCompany(); + + if (start == null) { + start = new Date(); + start = DateUtils.addMonths(start, -1); + } + + if (end == null) { + end = DateUtils.addMonths(start, 6); + } + + // La somme des factures que la company doit payer jusqu'a la date demandee + WikittyQuery debt = new WikittyQueryMaker() + .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) + .and() + .eq(Invoice.FQ_FIELD_INVOICE_CUSTOMER, companyId) + .lt(Invoice.FQ_FIELD_INVOICE_EXPECTEDDATE, start) + .end() + .setLimit(WikittyQuery.MAX); + + // La somme des factures que la company doit percevoir jusqu'a la date demandee + WikittyQuery income = new WikittyQueryMaker() + .select(Invoice.FQ_FIELD_INVOICE_AMOUNT, Aggregate.SUM) + .and() + .eq(Invoice.FQ_FIELD_INVOICE_SUPPLIER, companyId) + .lt(Invoice.FQ_FIELD_INVOICE_EXPECTEDDATE, start) + .end() + .setLimit(WikittyQuery.MAX); + + // La liste des factures entre les deux dates + WikittyQuery q = new WikittyQueryMaker().and() + .parse(filter) + .bw(Invoice.FQ_FIELD_INVOICE_EXPECTEDDATE, start, end) + .end() + .setLimit(WikittyQuery.MAX); + + Double[] amounts = client.findByQuery(Double.class, debt, income); + WikittyQueryResult<Invoice> invoices = client.findAllByQuery(Invoice.class, q); + + WikittyQuery categoriesQuery = new WikittyQueryMaker() + .exteq(Category.EXT_CATEGORY) + .end(); + WikittyQuery rootCategoriesQuery = new WikittyQueryMaker().and() + .exteq(Category.EXT_CATEGORY) + .isNull(Category.FQ_FIELD_WIKITTYTREENODE_PARENT) + .end() + .addSortAscending(new ElementField(Category.FQ_FIELD_CATEGORY_INDEX)); + + WikittyQueryResult<Category>[] categories = + client.findAllByQuery(Category.class, categoriesQuery, rootCategoriesQuery); + + + String dateFormat = "MM/yyyy"; + + List<String> dates = new LinkedList<String>(); + do { + dates.add(DateFormatUtils.format(start, dateFormat)); + start = DateUtils.addMonths(start, 1); + } while (!start.after(end)); + + + // key: date as MM/yyyy + Map<String, Map<Category, Double>> values = new HashMap<String, Map<Category, Double>>(); + + for (String d : dates) { + Map<Category, Double> catMap = new HashMap<Category, Double>(); + values.put(d, catMap); + for (Category c: categories[0]) { + catMap.put(c, 0.0); + } + } + + for (Invoice i : invoices) { + String date = DateFormatUtils.format(i.getExpectedDate(), dateFormat); + Map<Category, Double> catMap = values.get(date); + System.out.println(String.format("*** date '%s' %s map %s", date, dates, values)); + Category c = i.getCategory(true); + System.out.println("c: " + c + " catMap: " + catMap); + if (catMap.containsKey(c)) { + double v = catMap.get(c); + v += i.getAmount(); + catMap.put(c, v); + } + } + + List<WikittyQueryResultTreeNode<Category>> categoriesTree = + new LinkedList<WikittyQueryResultTreeNode<Category>>(); + for (Category c : categories[1]) { + WikittyQueryResultTreeNode<Category> treeResults = + client.findTreeNode(Category.class, c.getWikittyId(), Integer.MAX_VALUE, false, null); + if (treeResults != null) { + CollectionUtils.addAll(categoriesTree, treeResults.iterator()); + } + } + + System.out.println("DDDD dates: " + dates + " categoriesTree: " + categoriesTree + " values: " + values); + return renderView("dashboardBudget.jsp", + "dates", dates, + "categoriesTree", categoriesTree, + "values", values); + } + } Modified: trunk/chorem-webmotion/src/main/resources/mapping =================================================================== --- trunk/chorem-webmotion/src/main/resources/mapping 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/resources/mapping 2012-06-04 05:08:40 UTC (rev 173) @@ -28,6 +28,8 @@ * /wikitty-json/search?term={query} action:GenericAction.searchJson * /wikitty-json/get/{id} action:GenericAction.getById * /fragment/dashboard/{method} action:DashboardAction.{method} +* /admin view:contact.jsp +* /admin/{method} action:AdminAction.{method} * /contact view:contact.jsp * /project view:project.jsp * /financial view:financial.jsp Added: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardBudget.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardBudget.jsp (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardBudget.jsp 2012-06-04 05:08:40 UTC (rev 173) @@ -0,0 +1,33 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="/WEB-INF/wikitty.tld" prefix="w"%> + +<h1>Budget</h1> + +<form> + date start: <input type="date" name="start"/> + end: <input type="date" name="end"/> + <input type="submit"/> +</form> + +<table class="table table-striped table-bordered table-condensed"> + <thead> + <tr> + <c:forEach var="d" items="${dates}"> + <th>${d}</th> + </c:forEach> + </tr> + </thead> + <tbody> + <c:forEach var="c" items="${categoriesTree}"> + <tr> + <td class="level${c.level}">${c.userObject}</td> + </tr> + <tr> + <c:forEach var="d" items="${dates}"> + <td>${values.get(d).get(c.userObject)}</td> + </c:forEach> + </tr> + </tbody> + </c:forEach> +</table> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardProfitability.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardProfitability.jsp 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardProfitability.jsp 2012-06-04 05:08:40 UTC (rev 173) @@ -7,7 +7,7 @@ <thead> <tr> <th>Project</th> - <th>Type</th> + <th>Category</th> <th>Description</th> <th>estimated days</th> <th>Amount</th> @@ -24,7 +24,7 @@ <tbody> <tr> <td><a href="<c:url value="/wikitty/Project/view/${q.project}"/>">${q.getProject(false).getName()}</a></td> - <td>${q.type}</td> + <td>${q.category}</td> <td><a href="<c:url value="/wikitty/Quotation/view/${q.wikittyId}"/>">${q.description}</a></td> <td>${q.estimatedDays}</td> <td>${q.amount}</td> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardQuotation.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardQuotation.jsp 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/dashboardQuotation.jsp 2012-06-04 05:08:40 UTC (rev 173) @@ -7,7 +7,7 @@ <thead> <tr> <th>Project</th> - <th>Type</th> + <th>Category</th> <th>Description</th> <th>Customer</th> <th>Supplier</th> @@ -23,7 +23,7 @@ <tbody> <tr> <td><a href="<c:url value="/wikitty/Project/view/${q.project}"/>">${q.getProject(false).getName()}</a></td> - <td>${q.type}</td> + <td>${q.category}</td> <td><a href="<c:url value="/wikitty/Quotation/view/${q.wikittyId}"/>">${q.description}</a></td> <td><a href="<c:url value="/wikitty/Employee/view/${q.customer}"/>">${q.getCustomer(false)}</a></td> <td><a href="<c:url value="/wikitty/Employee/view/${q.supplier}"/>">${q.getSupplier(false)}</a></td> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-06-04 05:08:40 UTC (rev 173) @@ -107,6 +107,10 @@ <li><a href="<c:url value="/wikitty/Invoice/search"/>"><i class="icon-th-list icon-black"></i> All invoices</a></li> <li><a href="<c:url value="/wikitty/Invoice/edit/new"/>"><i class="icon-plus icon-black"></i> Add invoice</a></li> <li class="divider"></li> + <li>Category</li> + <li><a href="<c:url value="/wikitty/Category/search"/>"><i class="icon-th-list icon-black"></i> All categories</a></li> + <li><a href="<c:url value="/wikitty/Category/edit/new"/>"><i class="icon-plus icon-black"></i> Add category</a></li> + <li class="divider"></li> <li>Other</li> <li><a href="/wikitty/search?query=extension=Accounting">Accounting</a></li> </ul> @@ -127,6 +131,21 @@ <li><a href="/wikitty/search?query=extension=Interview">Annual interview</a></li> </ul> </li> + <li class="dropdown nav-group"> + <a href="/admin">Admin</a> + <a href="#" + class="dropdown-toggle" + data-toggle="dropdown"> + <b class="caret"></b> + </a> + <ul class="dropdown-menu"> + <li>User</li> + <li><a href="<c:url value="/wikitty/WikittyUser/search"/>"><i class="icon-th-list icon-black"></i> All users</a></li> + <li><a href="<c:url value="/wikitty/WikittyUser/edit/new"/>"><i class="icon-plus icon-black"></i> Add user</a></li> + <li class="divider"></li> + <li><a href="/admin/variables">Variables</a></li> + </ul> + </li> </ul> <form class="navbar-search pull-left" action="<c:url value="/wikitty/search"/>"> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial.jsp 2012-06-02 03:17:10 UTC (rev 172) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial.jsp 2012-06-04 05:08:40 UTC (rev 173) @@ -9,3 +9,4 @@ <jsp:include page="/fragment/dashboard/invoice?query=${query}"/> <jsp:include page="/fragment/dashboard/profitability?query=${query}"/> +<jsp:include page="/fragment/dashboard/budget?query=${query}"/>