r376 - in trunk: chorem-entities/src/main/java/org/chorem/project chorem-webmotion/src/main/webapp/WEB-INF/jsp chorem-webmotion/src/main/webapp/js
Author: meynier Date: 2013-07-25 17:23:55 +0200 (Thu, 25 Jul 2013) New Revision: 376 Url: http://chorem.org/projects/chorem/repository/revisions/376 Log: Add model and view files Added: trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/employeeEdit.jsp trunk/chorem-webmotion/src/main/webapp/js/employeeEdit.js Added: trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java (rev 0) +++ trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java 2013-07-25 15:23:55 UTC (rev 376) @@ -0,0 +1,103 @@ +package org.chorem.project; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import org.chorem.ChoremClient; +import org.chorem.ChoremUtil; +import org.chorem.entities.EmployeeHR; +import org.chorem.entities.Interval; +import org.chorem.entities.Quotation; +import org.chorem.entities.Time; +import org.nuiton.wikitty.query.WikittyQuery; +import org.nuiton.wikitty.query.WikittyQueryMaker; +import org.nuiton.wikitty.query.WikittyQueryResult; + +public class AdcCalculation { + + ChoremClient client; + EmployeeHR e; + Date start; + Date end; + + public double getTotalGain() { + + WikittyQuery gainQuery = new WikittyQueryMaker() + .and() + .exteq("Closed") + .or() + .bw(Interval.FQ_FIELD_INTERVAL_BEGINDATE, start, end) + .bw(Interval.FQ_FIELD_INTERVAL_ENDDATE, start, end) + .end(); + + WikittyQueryResult<Quotation> result = client.findAllByQuery(Quotation.class, gainQuery); + + double total = 0; + for(Quotation q : result.getAll()) { + total += q.getAmount(); + } + + return total; + } + + public double getTotalSalaries() { + //pondéré par pct d eproductivité + WikittyQuery employeeQuery = new WikittyQueryMaker().exteq("EmployeeHR").end(); + WikittyQueryResult<EmployeeHR> result = client.findAllByQuery(EmployeeHR.class, employeeQuery); + + double total = 0; + for(EmployeeHR e : result.getAll()) { + total += e.getSalary() * (e.getProductivityRate()/100); + } + return total; + } + + public double getTotalTimes() { + WikittyQuery timeQuery = new WikittyQueryMaker() + .and() + .exteq("Time") + .or() + .bw(Interval.FQ_FIELD_INTERVAL_BEGINDATE, start, end) + .bw(Interval.FQ_FIELD_INTERVAL_ENDDATE, start, end) + .end(); + + WikittyQueryResult<Time> result = client.findAllByQuery(Time.class, timeQuery); + + double total = 0; + for(Time t : result.getAll()) { + total += ChoremUtil.getPeriodInHours(t.getBeginDate(), t.getEndDate()); + } + + return total; + } + + public double getAdc() { + end = new GregorianCalendar().getTime(); + Calendar start = new GregorianCalendar(); + start.add(Calendar.YEAR, -1); + this.start = start.getTime(); + double expenses = getTotalGain(); + double salaries = getTotalSalaries(); + double times = getTotalTimes(); + + double dailyHoursWorked = client.getDailyHoursWorked(e); + double dailySalary = client.restore(e.getWikittyId()).getFieldAsDouble("EmployeeHR", "salary")/21.5; + + double adc = ( (expenses/salaries)/times ) * dailyHoursWorked * dailySalary; + + + return adc; + } + + + public AdcCalculation(EmployeeHR e, ChoremClient client) { + this.e = e; + this.client = client; + } + + + + + +} Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/employeeEdit.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/employeeEdit.jsp 2013-07-25 15:22:40 UTC (rev 375) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/employeeEdit.jsp 2013-07-25 15:23:55 UTC (rev 376) @@ -95,18 +95,18 @@ maxFractionDigits="2" value="${employee.productivityRate}"/>%</td> <td class="partialTime"><f:formatNumber type="number" maxFractionDigits="2" value="${employee.partialTime}"/>%</td> - <td class="dailyReturn"><f:formatNumber type="number" - maxFractionDigits="2" value="${employee.dailyReturn}"/> + <td class="dailyReturn"><span class="adc"><f:formatNumber type="number" + maxFractionDigits="2" value="${employee.dailyReturn}"/></span> + <c:if test='${employee.object.wikitty.hasExtension("EmployeeHR")}'> <a class="cjmRefresh" style="cursor:pointer"> - <i class="icon icon-refresh"></i></a></td> - <td class="rowEdit"><a class="employeeEdit" style="cursor:pointer"><i class="icon icon-edit"></i></a></td> + <i class="icon icon-refresh"></i></a></c:if></td> + <td class="cellEdit"><a class="employeeEdit" style="cursor:pointer"><i class="icon icon-edit"></i></a></td> </tr> <c:set var="count" value="${count + 1}"/> </c:forEach> </tbody> </table> - <script src="<c:url value='/js/employeeEdit.js'/>"></script> Modified: trunk/chorem-webmotion/src/main/webapp/js/employeeEdit.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/employeeEdit.js 2013-07-25 15:22:40 UTC (rev 375) +++ trunk/chorem-webmotion/src/main/webapp/js/employeeEdit.js 2013-07-25 15:23:55 UTC (rev 376) @@ -9,7 +9,9 @@ }); $(".employeeEdit").click(employeeEdit); - + $(".cjmRefresh").click(calculateAdc); + + function employeeEdit() { var row = $(this).parent().parent(); var salary = row.find(".salary"); @@ -23,18 +25,11 @@ prod.html("<input type = 'text' size='3' value='"+$.trim(prod.html()).replace('%','')+"'/>"); time.attr("oldVal", $.trim(time.html())); time.html("<input type = 'text' size='3' value='"+$.trim(time.html()).replace('%','')+"'/>"); - cjm.attr("oldVal", $.trim(cjm.html())); - cjm.html("<input type = 'text' size='3' value='"+$.trim(cjm.html()).replace('%','')+"'/>"); + cjm.attr("oldVal", $.trim(cjm.find('.adc').html())); + cjm.html("<input type = 'text' size='3' value='"+$.trim(cjm.find('.adc').html()).replace('%','')+"'/>"); + displayConfirmation(row); - - - $(this).parent().html("<a class='editOk' style='cursor:pointer'><i class='icon icon-ok'></i></a>" - + "<a class='editCancel' style='cursor:pointer'><i class='icon icon-remove'></i></a>" - ); - row.find(".editCancel").click(editCancel); - row.find(".editOk").click(editOk); - } function editCancel() { @@ -49,12 +44,10 @@ salary.html($.trim(salary.attr('oldVal'))); prod.html($.trim(prod.attr('oldVal'))); time.html($.trim(time.attr('oldVal'))); - cjm.html($.trim(cjm.attr('oldVal'))); - $(this).parent().html("<a class='employeeEdit' style='cursor:pointer'><i class='icon icon-edit'></i></a>" - ); - row.find(".employeeEdit").click(employeeEdit); + displayEdit(row); + displayDailyReturn(row, $.trim(cjm.attr('oldVal'))); } @@ -71,12 +64,12 @@ var prodVal = $.trim(prod.find("input").attr('value')); var timeVal = $.trim(time.find("input").attr('value')); var cjmVal = $.trim(cjm.find("input").attr('value')); - + + blockEdit(row); $.get(createUrl("/admin/employeeEdit/json/editEmployeeValues/",row.attr("id"), "?salaryStr=", salaryVal, "&productivityRateStr=", prodVal, "&partialTimeStr=", timeVal, "&dailyReturnStr=", cjmVal), function(ret){ - console.log(ret); var data = ret['data']; if(data === "error") { @@ -88,23 +81,71 @@ row.find("." + errors[i]["field"]).append( "<span class='errorMessage'>"+errors[i]["errorMessage"]+"</span>"); } + displayConfirmation(row); } else { salary.html(data['salary']); prod.html(data["productivityRate"]+"%"); time.html(data['partialTime']+"%"); - cjm.html(data['dailyReturn']); + displayDailyReturn(row, data['dailyReturn']); row.find('.dailyHoursWorked').html(data['dailyHoursWorked']); - cell.html("<a class='employeeEdit' style='cursor:pointer'><i class='icon icon-edit'></i></a>"); + displayEdit(row); + } - row.find(".employeeEdit").click(employeeEdit); + } ); } + + function calculateAdc() { + var row = $(this).parent().parent(); + var cjm = row.find(".dailyReturn"); + blockDailyReturn(row); + blockEdit(row); + $.get(createUrl("/admin/employeeEdit/json/requestAdc/",row.attr("id")), + function(ret){ + var adc = ret['adc']; + displayDailyReturn(row, adc); + displayEdit(row); + }); + + } + + function blockEdit(row) { + row.find('.cellEdit').html('wait...'); + } + + function blockDailyReturn(row) { + row.find('.dailyReturn').html('wait...'); + } + + function displayConfirmation(row) { + var cell = row.find('.cellEdit'); + cell.html("<a class='editOk' style='cursor:pointer'><i class='icon icon-ok'></i></a>" + + "<a class='editCancel' style='cursor:pointer'><i class='icon icon-remove'></i></a>" + ); + row.find(".editCancel").click(editCancel); + row.find(".editOk").click(editOk); + + } + + function displayEdit(row) { + var cell = row.find('.cellEdit'); + cell.html("<a class='employeeEdit' style='cursor:pointer'><i class='icon icon-edit'></i></a>"); + cell.find(".employeeEdit").click(employeeEdit); + } + + function displayDailyReturn(row, val) { + row.find('.dailyReturn').html('<span class="adc">' + val + ' </span><a class="cjmRefresh" style="cursor:pointer">' + +'<i class="icon icon-refresh"></i></a>'); + row.find(".cjmRefresh").click(calculateAdc); + } + + }); \ No newline at end of file
participants (1)
-
meynier@users.chorem.org