Author: ymartel Date: 2014-07-07 11:00:39 +0200 (Mon, 07 Jul 2014) New Revision: 417 Url: http://forge.chorem.org/projects/chorem/repository/revisions/417 Log: UI is ready to create expense accounts Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-07-04 09:47:25 UTC (rev 416) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-07-07 09:00:39 UTC (rev 417) @@ -33,19 +33,25 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import com.google.gson.Gson; +import org.apache.commons.lang3.StringUtils; import org.chorem.ChoremClient; +import org.chorem.entities.Category; import org.chorem.entities.CategoryImpl; import org.chorem.entities.Employee; import org.chorem.entities.EmployeeImpl; import org.chorem.entities.ExpenseAccount; +import org.chorem.entities.ExpenseAccountEntry; import org.chorem.entities.ExpenseAccountEntryImpl; import org.chorem.entities.ExpenseAccountImpl; +import org.chorem.entities.Project; import org.chorem.webmotion.PaginatedResult; import org.chorem.webmotion.bean.financial.ExpenseAccountBean; import org.chorem.webmotion.bean.financial.ExpenseAccountEntryBean; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.util.DateUtil; +import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; import org.nuiton.wikitty.query.WikittyQueryResult; @@ -124,8 +130,34 @@ Employee employee = client.restore(Employee.class, employeeId); if (expenseAccountWikitty == null) { expenseAccountWikitty = new ExpenseAccountImpl(); + expenseAccountWikitty.setEmployee(employee); } - //TODO ymartel 2014/04/11 just do it + expenseAccountWikitty.setBeginDate(expenseAccount.getStartDate()); + expenseAccountWikitty.setEndDate(expenseAccount.getEndDate()); + Set<ExpenseAccountEntryBean> expenseAccountEntries = expenseAccount.getExpenseAccountEntries(); + if (expenseAccountEntries != null) { + for (ExpenseAccountEntryBean expenseAccountEntryBean : expenseAccountEntries) { + ExpenseAccountEntry expenseAccountEntry = new ExpenseAccountEntryImpl(); + expenseAccountEntry.setReference(expenseAccountEntryBean.getJustificationNumber()); + expenseAccountEntry.setEmittedDate(new Date(expenseAccountEntryBean.getEmittedDate())); + expenseAccountEntry.setDescription(expenseAccountEntryBean.getDescription()); + expenseAccountEntry.setAmount(expenseAccountEntryBean.getAmount()); + expenseAccountEntry.setVAT(expenseAccountEntryBean.getVAT()); + String projectId = expenseAccountEntryBean.getProjectId(); + if (StringUtils.isNotBlank(projectId)) { + Wikitty project = client.restore(projectId); + expenseAccountEntry.setTarget(project); + } + String categoryId = expenseAccountEntryBean.getCategoryId(); + if (StringUtils.isNotBlank(categoryId)) { + Category category = client.restore(Category.class, categoryId); + expenseAccountEntry.setCategory(category); + } + + expenseAccountWikitty.addExpenseAccountEntry(expenseAccountEntry); + } + } + client.store(expenseAccountWikitty); } public Render findExpenseAccount(ChoremClient client, String expenseAccountId) { @@ -137,39 +169,6 @@ if (expenseAccount == null) { expenseAccount = new ExpenseAccountImpl(); -// expenseAccountBean.setId("new");n -// -// //XXX ymartel 2014/04/08 Some Fake datas, just for test -// employee = client.findAllByExample(new EmployeeImpl(), 0, 1).get(0); -// expenseAccountBean.setEmployeeName(employee.toString()); -// expenseAccountBean.setEmployeeId(employee.getWikittyId()); -// -// expenseAccountBean.setMonth(3); -// expenseAccountBean.setYear(2014); -// -// int capacity = categories.size(); -// expenseAccountEntries = new HashSet<>(capacity); -// Random random = new Random(); -// for (CategoryImpl category : categories) { -// ExpenseAccountEntryBean expenseAccountEntry = new ExpenseAccountEntryBean(); -// int randomInt = random.nextInt(capacity); -// expenseAccountEntry.setEmittedDate(DateUtil.createDate(01, 03, 2014).getTime()); -// expenseAccountEntry.setDescription("blabla" + randomInt); -// expenseAccountEntry.setJustificationNumber(String.valueOf(randomInt)); -// double amount = random.nextDouble(); -// expenseAccountEntry.setAmount(amount); -// double vat = random.nextDouble(); -// expenseAccountEntry.setVAT(vat); -// expenseAccountEntry.setTotal(amount + vat); -// expenseAccountEntry.setCategoryName(category.toString()); -// expenseAccountEntry.setProjectName("aucun"); -// if (random.nextBoolean()) { -// expenseAccountEntry.setPaymentDate(DateUtil.createDate(31, 03, 2014).getTime()); -// } -// expenseAccountEntries.add(expenseAccountEntry); -// } -// expenseAccountBean.setExpenseAccountEntries(expenseAccountEntries); - } ExpenseAccountBean expenseAccountBean = TRANSFORM_EXPENSE_ACCOUNT_TO_BEAN.apply(expenseAccount); Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java 2014-07-04 09:47:25 UTC (rev 416) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java 2014-07-07 09:00:39 UTC (rev 417) @@ -31,6 +31,7 @@ public class ExpenseAccountEntryBean implements Serializable { protected String categoryName; + protected String categoryId; protected long emittedDate; protected long paymentDate; protected String description; @@ -49,6 +50,14 @@ this.categoryName = categoryName; } + public String getCategoryId() { + return categoryId; + } + + public void setCategoryId(String categoryId) { + this.categoryId = categoryId; + } + public long getEmittedDate() { return emittedDate; } Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-07-04 09:47:25 UTC (rev 416) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-07-07 09:00:39 UTC (rev 417) @@ -1,8 +1,15 @@ + <td><input type="text" ng-model="newExpenseAccountEntry.justificationNumber" name="newExpenseAccountEntry.justificationNumber" size="10" style='width:100%'></td> <td><input type="date" ng-model="newExpenseAccountEntry.emittedDate" name="newExpenseAccountEntry.emittedDate" size="10" maxlength="10" style='width:90%'></td> - <td><input type="text" ng-model="newExpenseAccountEntry.project" name="newExpenseAccountEntry.project" size="4" style='width:100%'></td> + <td> + <input type="text" ng-model="newExpenseAccountEntry.projectName" name="newExpenseAccountEntry.project" size="4" style='width:100%' id="text-newExpenseAccountEntry-project" auto-complete data-source="Project" data-model="newExpenseAccountEntry" data-base-field="project"> + <input type="hidden" ng-model="newExpenseAccountEntry.projectId" id="hidden-newExpenseAccountEntry-project"/> + </td> <td><input type="text" ng-model="newExpenseAccountEntry.description" name="newExpenseAccountEntry.description" style='width:100%'></td> - <td><input type="text" ng-model="newExpenseAccountEntry.category" name="newExpenseAccountEntry.category" style='width:100%'></td> + <td> + <input type="text" ng-model="newExpenseAccountEntry.categoryName" name="newExpenseAccountEntry.category" style='width:100%' id="text-newExpenseAccountEntry-category" auto-complete data-source="Category" data-model="newExpenseAccountEntry" data-base-field="category"> + <input type="hidden" ng-model="newExpenseAccountEntry.categoryId" id="hidden-newExpenseAccountEntry-category"/> + </td> <td><input type="number" ng-model="newExpenseAccountEntry.amount" name="newExpenseAccountEntry.amount" min="0" style='width:100%'></td> <td><input type="number" ng-model="newExpenseAccountEntry.VAT" name="newExpenseAccountEntry.VAT" min="0" style='width:100%'></td> <td>{{(newExpenseAccountEntry.amount * 1) + (newExpenseAccountEntry.VAT * 1)}}</td> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-07-04 09:47:25 UTC (rev 416) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-07-07 09:00:39 UTC (rev 417) @@ -44,27 +44,13 @@ <dl> <dd ng-if="expenseAccount && expenseAccount.employeeId"><a href="<c:url value="/wikitty/view/{{expenseAccount.employeeId}}"/>">{{expenseAccount.employeeName}}</a></dd> <dd ng-if="!expenseAccount || !expenseAccount.employeeId"> - <input type="text" ng-model="expenseAccount.employeeName" id="text-expenseAccount-employee" auto-complete auto-complete-source=<c:url value="/wikitty-json/search?extension=Employee"/> /> + <input type="text" ng-model="expenseAccount.employeeName" id="text-expenseAccount-employee" auto-complete data-source="Employee" data-model="expenseAccount" data-base-field="employee" /> <input type="hidden" ng-model="expenseAccount.employeeId" id="hidden-expenseAccount-employee"/> - <!-- script> - $(function() { - $( "#text-expenseAccount-employee" ).autocompleteByExtension({ - source: "<c:url value="/wikitty-json/search?extension=Employee"/>", - minLength: 2, - select: function( event, ui ) { - $( "#text-expenseAccount-employee" ).val( ui.item.label ); - $( "#hidden-expenseAccount-employee" ).val( ui.item.id ); - return false; - } - }); - }); - </script --> - </dd> <dd ng-if="editPeriod == false">Period from {{expenseAccount.startDate |date}} to {{expenseAccount.endDate |date}}</dd> - <dd ng-if="editPeriod == true">StartDate : <input type="date" ng-model="newExpenseAccount.startDate" name="newExpenseAccount.startDate"></dd> - <dd ng-if="editPeriod == true">EndDate : <input type="date" ng-model="newExpenseAccount.endDate" name="newExpenseAccount.endDate"></dd> + <dd ng-if="editPeriod == true">StartDate : <input type="date" ng-model="expenseAccount.startDate" name="expenseAccount.startDate"></dd> + <dd ng-if="editPeriod == true">EndDate : <input type="date" ng-model="expenseAccount.endDate" name="expenseAccount.endDate"></dd> </dl> </div> Modified: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-07-04 09:47:25 UTC (rev 416) +++ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-07-07 09:00:39 UTC (rev 417) @@ -60,22 +60,21 @@ app.directive("autoComplete", function() { return { - restrict : "A" , - require : '^ngModel', - link : function (scope, element, attrs) { + require : 'ngModel', + link : function ($scope, element, attrs) { // prevent html5/browser auto completion attrs.$set('autocomplete','off'); - scope.autocomplete = $(element).autocompleteByExtension({ - source: scope.baseURL + "wikitty-json/search?extension=Employee", - minLength: 2, - select: function(event, ui) { - scope.expenseAccount.employeeName = ui.item.label; - scope.expenseAccount.employeeId = ui.item.id; - return true; - } - }); + $scope.autocomplete = $(element).autocompleteByExtension({ + source: $scope.baseURL + "wikitty-json/search?extension=" + $(element).data("source"), + minLength: 2, + select: function(event, ui) { + $scope[$(element).data("model")][$(element).data("baseField") + "Name"] = ui.item.label; + $scope[$(element).data("model")][$(element).data("baseField") + "Id"] = ui.item.id; + return true; + } + }); } } }); \ No newline at end of file