Author: vbriand Date: 2011-04-21 17:01:53 +0200 (Thu, 21 Apr 2011) New Revision: 98 Url: http://chorem.org/repositories/revision/chorem/98 Log: Added the supplier and the customer for a quotation Added: trunk/chorem-web/src/main/java/org/chorem/bonzoms/EmployeeFull.java Modified: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp Modified: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-21 12:49:11 UTC (rev 97) +++ trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-21 15:01:53 UTC (rev 98) @@ -2,17 +2,24 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.ChoremProxy; import org.chorem.action.BaseAction; +import org.chorem.bonzoms.EmployeeFull; +import org.chorem.entities.Company; +import org.chorem.entities.Employee; +import org.chorem.entities.Person; import org.chorem.entities.Project; import org.chorem.entities.ProjectOrder; import org.chorem.entities.Quotation; import org.chorem.entities.QuotationImpl; import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.PagedResult; import org.nuiton.wikitty.search.Search; import com.opensymphony.xwork2.ActionContext; @@ -25,7 +32,7 @@ * @author vbriand */ public class QuotationAction extends BaseAction { - + private static final long serialVersionUID = -8773692389143447193L; private static final Log log = LogFactory.getLog(BaseAction.class); @@ -66,7 +73,7 @@ } else { result = ERROR; } - } + } } } } catch (IllegalArgumentException e) { @@ -121,6 +128,8 @@ protected String vta; protected String postedDate; protected String quotationId; + protected String supplierId; + protected String customerId; /** * Returns the project order linked with the quotation (if it exists) @@ -132,11 +141,24 @@ Search search = Search.query(); Criteria criteria = search.eq(ProjectOrder.FQ_FIELD_PROJECTORDER_QUOTATION, quotationId).criteria(); - ProjectOrder projectOrder = proxy.findByCriteria(ProjectOrder.class, criteria); + ProjectOrder projectOrder = proxy.findByCriteria(ProjectOrder.class, + criteria); return projectOrder; } + public List<EmployeeFull> getAllEmployees() { + ChoremProxy proxy = getChoremProxy(); + Search search = Search.query(); + Criteria criteria = search.exteq(Employee.EXT_EMPLOYEE).criteria(); + PagedResult<Employee> result = proxy.findAllByCriteria(Employee.class, + criteria); + List<Employee> employees = result.getAll(); + List<EmployeeFull> employeesFullList = EmployeeFull. + initEmployeeFullList(employees, proxy); + return employeesFullList; + } + /** * Stores the new quotation through the proxy * @@ -168,7 +190,21 @@ result = false; addActionError(getText(n_("chorem.date.wrongFormat"))); } + + if (proxy.restore(Person.class, supplierId) != null) { + newQuotation.setSupplier(supplierId); + } else { //If the id doesn't exist or is invalid + addActionError(getText(n_("chorem.billy.quotation.invalidSupplier"))); + result = false; + } + if (proxy.restore(Person.class, customerId) != null) { + newQuotation.setSupplier(customerId); + } else { //If the id doesn't exist or is invalid + addActionError(getText(n_("chorem.billy.quotation.invalidCustomer"))); + result = false; + } + //If everything went smoothly if (result) { proxy.store(newQuotation); @@ -292,4 +328,32 @@ public void setQuotationId(String quotationId) { this.quotationId = quotationId; } + + /** + * @return the supplierId + */ + public String getSupplierId() { + return supplierId; + } + + /** + * @param supplierId the supplierId to set + */ + public void setSupplierId(String supplierId) { + this.supplierId = supplierId; + } + + /** + * @return the customerId + */ + public String getCustomerId() { + return customerId; + } + + /** + * @param customerId the customerId to set + */ + public void setCustomerId(String customerId) { + this.customerId = customerId; + } } Added: trunk/chorem-web/src/main/java/org/chorem/bonzoms/EmployeeFull.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/bonzoms/EmployeeFull.java (rev 0) +++ trunk/chorem-web/src/main/java/org/chorem/bonzoms/EmployeeFull.java 2011-04-21 15:01:53 UTC (rev 98) @@ -0,0 +1,84 @@ +package org.chorem.bonzoms; + +import java.util.ArrayList; +import java.util.List; + +import org.chorem.ChoremProxy; +import org.chorem.entities.Company; +import org.chorem.entities.Employee; +import org.chorem.entities.Person; + +/** + * @author vbriand + */ +public class EmployeeFull { + protected Employee employee; + protected Company company; + protected Person person; + + /** + * Returns an employee with its links + * + * @param employees the list of employees + * @param proxy + * @return the list of employees + */ + public static List<EmployeeFull> initEmployeeFullList(List<Employee> employees, ChoremProxy proxy) { + Person person; + Company company; + EmployeeFull employeeTmp = new EmployeeFull(); + List<EmployeeFull> employeesFullList = new ArrayList<EmployeeFull>(); + + for (Employee employee : employees) { + employeeTmp.setEmployee(employee); + person = proxy.restore(Person.class, employee.getPerson()); + employeeTmp.setPerson(person); + company = proxy.restore(Company.class, employee.getCompany()); + employeeTmp.setCompany(company); + employeesFullList.add(employeeTmp); + } + return employeesFullList; + } + + /** + * @return the employee + */ + public Employee getEmployee() { + return employee; + } + + /** + * @param employee the employee to set + */ + public void setEmployee(Employee employee) { + this.employee = employee; + } + + /** + * @return the company + */ + public Company getCompany() { + return company; + } + + /** + * @param company the company to set + */ + public void setCompany(Company company) { + this.company = company; + } + + /** + * @return the person + */ + public Person getPerson() { + return person; + } + + /** + * @param person the person to set + */ + public void setPerson(Person person) { + this.person = person; + } +} \ No newline at end of file Property changes on: trunk/chorem-web/src/main/java/org/chorem/bonzoms/EmployeeFull.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties =================================================================== --- trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties 2011-04-21 12:49:11 UTC (rev 97) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties 2011-04-21 15:01:53 UTC (rev 98) @@ -8,6 +8,8 @@ chorem.billy.quotation.backToProjectDetails=Get back to project chorem.billy.quotation.create.error=An error occurred while creating your new quotation, please try again. If the problem persists, please contact an administrator chorem.billy.quotation.description=Description +chorem.billy.quotation.invalidCustomer= +chorem.billy.quotation.invalidSupplier= chorem.billy.quotation.postedDate=Posted date chorem.billy.quotation.projectOrder= chorem.billy.quotation.projectOrder.beginDate= Modified: trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties =================================================================== --- trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties 2011-04-21 12:49:11 UTC (rev 97) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties 2011-04-21 15:01:53 UTC (rev 98) @@ -7,7 +7,10 @@ chorem.billy.quotation.amount=Montant chorem.billy.quotation.backToProjectDetails=Retourner sur le projet chorem.billy.quotation.create.error=Une erreur s''est produite lors de la cr\u00E9ation de votre nouveau devis, merci d''essayer \u00E0 nouveau. Si le probl\u00E8me se reproduit, merci de contacter un administrateur +chorem.billy.quotation.customer=Client chorem.billy.quotation.description=Description +chorem.billy.quotation.invalidCustomer= +chorem.billy.quotation.invalidSupplier= chorem.billy.quotation.postedDate=Date de d\u00E9p\u00F4t chorem.billy.quotation.projectOrder=Contrat r\u00E9alis\u00E9 sur la base de ce devis chorem.billy.quotation.projectOrder.beginDate=Date de d\u00E9but \: {0} @@ -15,6 +18,7 @@ chorem.billy.quotation.projectOrder.endDate=Date de fin \: {0} chorem.billy.quotation.projectOrder.type=Type \: {0} chorem.billy.quotation.reference=R\u00E9f\u00E9rence +chorem.billy.quotation.supplier=Fournisseur chorem.billy.quotation.vta=TVA chorem.billy.quotationDetails.title=D\u00E9tails du devis "{0}" chorem.bonzoms.companies=Liste des entreprises Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp 2011-04-21 12:49:11 UTC (rev 97) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp 2011-04-21 15:01:53 UTC (rev 98) @@ -1,4 +1,7 @@ <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@page import="java.util.List" %> +<%@page import="org.chorem.bonzoms.EmployeeFull" %> +<%@page import="org.chorem.entities.Person" %> <%@page import="org.chorem.billy.action.QuotationAction" %> <%@taglib prefix="s" uri="/struts-tags" %> @@ -33,6 +36,27 @@ <br /> <s:textfield key="chorem.billy.quotation.postedDate" name="postedDate" labelSeparator=": " /> <br /> + <label for="supplierId" class="label"><s:text name="chorem.billy.quotation.supplier" />: </label> + <select name="supplierId" id="supplierId"> + <% + List<EmployeeFull> employees = QuotationAction.getAction().getAllEmployees(); + + for (EmployeeFull employee : employees) { + %> + <option value="<%= employee.getEmployee().getWikittyId() %>"><%= employee.getPerson().getLastName() %> <%= employee.getPerson().getFirstName() %></option> + <% } %> + </select> + <br /> + <label for="customerId" class="label"><s:text name="chorem.billy.quotation.customer" />: </label> + <select name="customerId" id="customerId"> + <% + for (EmployeeFull employee : employees) { + %> + <option value="<%= employee.getEmployee().getWikittyId() %>"><%= employee.getPerson().getLastName() %> <%= employee.getPerson().getFirstName() %></option> + <% } %> + </select> + <br /> + <br /> <s:submit key="chorem.billy.quotation.add" name="submit" /> </fieldset> </form>