r415 - in trunk: chorem-entities/src/main/xmi chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial chorem-webmotion/src/main/webapp/js/financial
Author: ymartel Date: 2014-07-03 17:58:51 +0200 (Thu, 03 Jul 2014) New Revision: 415 Url: http://forge.chorem.org/projects/chorem/repository/revisions/415 Log: prepare Expense Account edition Modified: 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/financial/ExpenseAccountAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.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/WEB-INF/jsp/financial/expenseAccounts.jsp trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js Modified: trunk/chorem-entities/src/main/xmi/chorem-model.properties =================================================================== --- trunk/chorem-entities/src/main/xmi/chorem-model.properties 2014-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-entities/src/main/xmi/chorem-model.properties 2014-07-03 15:58:51 UTC (rev 415) @@ -193,8 +193,8 @@ # org.chorem.entities.ExpenseAccount.class.tagvalue.version=1.0 org.chorem.entities.ExpenseAccount.class.tagvalue.preload=ExpenseAccount.employee -org.chorem.entities.ExpenseAccount.class.tagvalue.toString=%ExpenseAccount.employee$s - %ExpenseAccount.month$s/%ExpenseAccount.year$s -org.chorem.entities.ExpenseAccount.class.tagvalue.sortOrder=ExpenseAccount.year,ExpenseAccount.month +org.chorem.entities.ExpenseAccount.class.tagvalue.toString=%ExpenseAccount.employee$s - %Interval.beginDate$s/%Interval.endDate$s +org.chorem.entities.ExpenseAccount.class.tagvalue.sortOrder=Interval.beginDate,Interval.endDate # # ExpenseAccountEntry Modified: trunk/chorem-entities/src/main/xmi/chorem-model.zargo =================================================================== (Binary files differ) 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-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-07-03 15:58:51 UTC (rev 415) @@ -27,27 +27,23 @@ import java.util.Calendar; import java.util.Collection; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Random; import java.util.Set; 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.chorem.ChoremClient; import org.chorem.entities.CategoryImpl; import org.chorem.entities.Employee; import org.chorem.entities.EmployeeImpl; import org.chorem.entities.ExpenseAccount; +import org.chorem.entities.ExpenseAccountEntryImpl; import org.chorem.entities.ExpenseAccountImpl; 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.call.Call; import org.debux.webmotion.server.render.Render; import org.nuiton.util.DateUtil; import org.nuiton.wikitty.query.WikittyQuery; @@ -59,21 +55,22 @@ */ public class ExpenseAccountAction extends WebMotionController { - public PaginatedResult<ExpenseAccountBean> findAllExpenseAccounts(ChoremClient client, Integer year, Integer mounth, int page, int count) { + public PaginatedResult<ExpenseAccountBean> findAllExpenseAccounts(ChoremClient client, Integer year, Integer month, int page, int count) { - if (mounth == null) { - mounth = DateUtil.getMonth(new Date()); + if (month == null) { + month = DateUtil.getMonth(new Date()); } if (year == null) { Calendar calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); } + Date refDate = DateUtil.createDate(1, month, year); WikittyQuery totalQuery = new WikittyQueryMaker() - .select().count(ExpenseAccount.ELEMENT_FIELD_EXPENSEACCOUNT_MONTH).where().and() + .select().count(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE).where().and() .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT) - .eq(ExpenseAccount.ELEMENT_FIELD_EXPENSEACCOUNT_MONTH, mounth) - .eq(ExpenseAccount.ELEMENT_FIELD_EXPENSEACCOUNT_YEAR, year) + .le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refDate) + .ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refDate) .end(); Integer nbExpenseAccounts = client.findByQuery(Integer.class, totalQuery); @@ -84,8 +81,8 @@ WikittyQuery expAccountsQuery = new WikittyQueryMaker() .where().and() .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT) - .eq(ExpenseAccount.ELEMENT_FIELD_EXPENSEACCOUNT_MONTH, mounth) - .eq(ExpenseAccount.ELEMENT_FIELD_EXPENSEACCOUNT_YEAR, year) + .le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refDate) + .ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refDate) .end() .setOffset((page - 1) * count) .setLimit(page * count); @@ -102,14 +99,14 @@ Employee employee = client.findAllByExample(new EmployeeImpl(), 0, 1).get(0); ExpenseAccountBean fakeOne = new ExpenseAccountBean(); fakeOne.setId("fake"); - fakeOne.setMonth(03); - fakeOne.setYear(2014); + fakeOne.setStartDate(DateUtil.createDate(1, 3, 2014)); + fakeOne.setEndDate(DateUtil.createDate(31, 3, 2014)); fakeOne.setEmployeeName(employee.toString()); fakeOne.setEmployeeId(employee.getWikittyId()); ExpenseAccountBean fakeTwo = new ExpenseAccountBean(); fakeTwo.setId("fake"); - fakeTwo.setMonth(mounth); - fakeTwo.setYear(year); + fakeTwo.setStartDate(DateUtil.createDate(1, 4, 2014)); + fakeTwo.setEndDate(DateUtil.createDate(30, 4, 2014)); fakeTwo.setEmployeeName(employee.toString()); fakeTwo.setEmployeeId(employee.getWikittyId()); ArrayList<ExpenseAccountBean> expenseAccounts = new ArrayList<>(); @@ -122,12 +119,12 @@ } public void saveExpenseAccount(ChoremClient client, String expenseAccountId, ExpenseAccountBean expenseAccount) { - ExpenseAccount expenseAccountWikitty = client.restore(ExpenseAccount.class, expenseAccountId); + ExpenseAccountImpl expenseAccountWikitty = client.restore(ExpenseAccountImpl.class, expenseAccountId); + String employeeId = expenseAccount.getEmployeeId(); + Employee employee = client.restore(Employee.class, employeeId); if (expenseAccountWikitty == null) { expenseAccountWikitty = new ExpenseAccountImpl(); } - String json = expenseAccount.toJson(); - expenseAccount.toString(); //TODO ymartel 2014/04/11 just do it } @@ -137,45 +134,46 @@ WikittyQueryResult<CategoryImpl> categoriesResult = client.findAllByExample(new CategoryImpl(), 0, 10); List<CategoryImpl> categories = categoriesResult.getAll(); - ExpenseAccountBean expenseAccountBean = null; - if (expenseAccount == null) { - expenseAccountBean = new ExpenseAccountBean(); - expenseAccountBean.setId("new"); - //XXX ymartel 2014/04/08 Some Fake datas, just for test - Employee employee = client.findAllByExample(new EmployeeImpl(), 0, 1).get(0); - expenseAccountBean.setEmployeeName(employee.toString()); - expenseAccountBean.setEmployeeId(employee.getWikittyId()); + 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.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); + return renderView("financial/expenseAccountView.jsp", "expenseAccount", expenseAccountBean); } @@ -188,8 +186,9 @@ Employee employee = expenseAccount.getEmployee(false); expenseAccountBean.setEmployeeName(employee != null ? employee.toString() : null); expenseAccountBean.setEmployeeId(employee != null ? employee.getWikittyId() : null); - expenseAccountBean.setMonth(expenseAccount.getMonth()); - expenseAccountBean.setYear(expenseAccount.getYear()); + expenseAccountBean.setStartDate(expenseAccount.getBeginDate()); + expenseAccountBean.setEndDate(expenseAccount.getEndDate()); + expenseAccountBean.setEndDate(expenseAccount.getEndDate()); return expenseAccountBean; } }; Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-07-03 15:58:51 UTC (rev 415) @@ -24,6 +24,7 @@ */ import java.io.Serializable; +import java.util.Date; import java.util.Set; import com.google.gson.Gson; @@ -36,8 +37,8 @@ protected String id; protected String employeeName; protected String employeeId; - protected int month; - protected int year; + protected Date startDate; + protected Date endDate; protected Set<ExpenseAccountEntryBean> expenseAccountEntries; public String getId() { @@ -64,20 +65,20 @@ this.employeeId = employeeId; } - public int getMonth() { - return month; + public Date getStartDate() { + return startDate; } - public void setMonth(int month) { - this.month = month; + public void setStartDate(Date startDate) { + this.startDate = startDate; } - public int getYear() { - return year; + public Date getEndDate() { + return endDate; } - public void setYear(int year) { - this.year = year; + public void setEndDate(Date endDate) { + this.endDate = endDate; } public Set<ExpenseAccountEntryBean> getExpenseAccountEntries() { 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-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-07-03 15:58:51 UTC (rev 415) @@ -1,9 +1,9 @@ - <td><input type="text" ng-model="newExpenseAccountEntry.justificationNumber" name="newExpenseAccountEntry.justificationNumber" size="10"></td> - <td><input type="date" ng-model="newExpenseAccountEntry.emittedDate" name="newExpenseAccountEntry.emittedDate" size="10" maxlength="10"></td> - <td><input type="text" ng-model="newExpenseAccountEntry.project" name="newExpenseAccountEntry.project" size="4"></td> - <td><input type="text" ng-model="newExpenseAccountEntry.description" name="newExpenseAccountEntry.description" class="w100"></td> - <td><input type="text" ng-model="newExpenseAccountEntry.category" name="newExpenseAccountEntry.category" class="w100"></td> - <td><input type="number" ng-model="newExpenseAccountEntry.amount" name="newExpenseAccountEntry.amount" class="w100"></td> - <td><input type="number" ng-model="newExpenseAccountEntry.VAT" name="newExpenseAccountEntry.VAT" class="w100"></td> - <td><input type="number" ng-model="newExpenseAccountEntry.total" name="newExpenseAccountEntry.total"></td> + <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.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="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> <td><a class="btn btn-success" ng-click="addLine()"><i class="icon-pencil icon-white"></i>Validate</a></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-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-07-03 15:58:51 UTC (rev 415) @@ -25,8 +25,10 @@ <%@ taglib uri="/WEB-INF/wikitty.tld" prefix="w"%> <head> - <script data-require="angular-resource@1.2.0-rc.3" data-semver="1.2.0-rc.3" src="<c:url value='http://code.angularjs.org/1.2.0-rc.3/angular-resource.js'/>"></script> - <link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="<c:url value='http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'/>" /> + <script data-require="angular-resource@1.2.10" data-semver="1.2.10" src="<c:url value='http://code.angularjs.org/1.2.10/angular-resource.js'/>"></script> + <link data-require="bootstrap-css@*" data-semver="3.1.1" rel="stylesheet" href="<c:url value='http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'/>" /> + <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script> + <script type="text/javascript" src="<c:url value='/js/financial/expenseAccount.js'/>"></script> <script> angular.module('expenseAccountPage').value('expenseAccountInit', { @@ -39,23 +41,44 @@ <div ng-app='expenseAccountPage' ng-controller="expenseAccountView"> <div > <dl> - <dd><a href="<c:url value="/wikitty/view/{{expenseAccount.employeeId}}"/>">{{expenseAccount.employeeName}}</a></dd> - <dd>Period : {{expenseAccount.month}} / {{expenseAccount.year}}</dd> + <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" /> + <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> </dl> </div> <div> <table> <tr> - <th>Justif. Nb</th> - <th>Emitted Date</th> - <th>Project</th> - <th>Description</th> - <th>Category</th> - <th>Amount</th> - <th>VAT</th> - <th>total</th> - <th>Payment Date</th> + <th style='width:15%'>Justif. Nb</th> + <th style='width:15%'>Emitted Date</th> + <th style='width:10%'>Project</th> + <th style='width:15%'>Description</th> + <th style='width:15%%'>Category</th> + <th style='width:7%'>Amount</th> + <th style='width:7%'>VAT</th> + <th style='width:6%'>total</th> + <th style='width:10%'>Payment Date</th> </tr> <tr ng-repeat="expenseEntry in expenseAccount.expenseAccountEntries"> <td>{{expenseEntry.justificationNumber}}</td> @@ -73,8 +96,9 @@ </div> <a class="btn btn-success" ng-click="newLine()"><i class="icon-list icon-white"></i> New entry</a> <div ng-if="hasChanged == true"> - <a class="btn btn-success" ng-click="saveExpenseAccount()"><i class="icon-od icon-white"></i>Save</a> + <a class="btn btn-success" ng-click="saveExpenseAccount()"><i class="icon-od icon-white"></i>Save</a> </div> + </div> </div> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp 2014-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp 2014-07-03 15:58:51 UTC (rev 415) @@ -47,11 +47,11 @@ <td data-title="'Employee'"> <a href="<c:url value="/wikitty/view/{{expenseAccount.employeeId}}"/>">{{expenseAccount.employeeName}}</a> </td> - <td data-title="'Month'"> - {{expenseAccount.month}} + <td data-title="'Start Date'"> + {{expenseAccount.startDate |date}} </td> - <td data-title="'Year'"> - {{expenseAccount.year}} + <td data-title="'End Date'"> + {{expenseAccount.endDate |date}} </td> <td> <a class="btn btn-success" href="<c:url value="/financial/expenseAccounts/{{expenseAccount.id}}"/>">See it</a> Modified: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-04-11 16:19:46 UTC (rev 414) +++ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-07-03 15:58:51 UTC (rev 415) @@ -1,9 +1,11 @@ -var app = angular.module('expenseAccountPage', ['ngResource']); +var app = angular.module('expenseAccountPage', ['ngResource', 'ui.bootstrap']); -app.controller("expenseAccountView", function($scope, $resource, expenseAccountInit) { +app.controller("expenseAccountView", function($scope, $resource, $modal, $log, expenseAccountInit) { $scope.showNewLine = false; $scope.expenseAccount = expenseAccountInit.expenseAccount; + $scope.editPeriod = expenseAccountInit && expenseAccountInit.id ? false : true; + $scope.saveURL = expenseAccountInit.saveURL; $scope.newLine = function() { @@ -27,6 +29,10 @@ $scope.addLine = function() { + if(!$scope.expenseAccount.expenseAccountEntries) { + $scope.expenseAccount.expenseAccountEntries = []; + } + $scope.newExpenseAccountEntry.total = $scope.newExpenseAccountEntry.amount + $scope.newExpenseAccountEntry.VAT; $scope.expenseAccount.expenseAccountEntries.push($scope.newExpenseAccountEntry); $scope.hasChanged = true;
participants (1)
-
ymartel@users.chorem.org