Author: meynier Date: 2013-08-07 15:34:26 +0200 (Wed, 07 Aug 2013) New Revision: 380 Url: http://chorem.org/projects/chorem/repository/revisions/380 Log: Added the total calculation and various other small modifications Added: trunk/chorem-entities/src/main/java/org/chorem/project/TotalQuotationCalculation.java Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java trunk/chorem-entities/src/main/java/org/chorem/project/QuotationCalculation.java Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2013-08-01 14:16:31 UTC (rev 379) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2013-08-07 13:34:26 UTC (rev 380) @@ -32,6 +32,7 @@ import org.chorem.entities.ConfigurationImpl; import org.chorem.entities.ContactDetails; import org.chorem.entities.Employee; +import org.chorem.entities.EmployeeHR; import org.chorem.entities.Invoice; import org.chorem.entities.InvoiceMigration; import org.chorem.entities.Quotation; @@ -400,12 +401,13 @@ if(e.getCompany(false) != null) companyW = restore(e.getCompany(false).getWikittyId()); - if(w.hasExtension("EmployeeHR") && w.getFieldAsDouble("EmployeeHR", "dailyReturn") != 0) { - return w.getFieldAsDouble("EmployeeHR", "dailyReturn"); + if(w.hasExtension(EmployeeHR.EXT_EMPLOYEEHR) && + w.getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR, EmployeeHR.FIELD_EMPLOYEEHR_DAILYRETURN) != 0) { + return w.getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR, EmployeeHR.FIELD_EMPLOYEEHR_DAILYRETURN); } - else if(companyW != null && companyW.hasExtension("CompanyHR") - && companyW.getFieldAsDouble("CompanyHR", "dailyReturn") != 0) { - return companyW.getFieldAsDouble("CompanyHR", "dailyReturn"); + else if(companyW != null && companyW.hasExtension(CompanyHR.EXT_COMPANYHR) + && companyW.getFieldAsDouble(CompanyHR.EXT_COMPANYHR, EmployeeHR.FIELD_EMPLOYEEHR_DAILYRETURN) != 0) { + return companyW.getFieldAsDouble(CompanyHR.EXT_COMPANYHR, EmployeeHR.FIELD_EMPLOYEEHR_DAILYRETURN); } else { return this.getConfiguration().getDailyReturn(); @@ -423,13 +425,14 @@ if(e.getCompany(false) != null) companyW = restore(e.getCompany(false).getWikittyId()); - if(companyW.hasExtension("CompanyHR") && companyW.getFieldAsDouble("CompanyHR", "dailyHoursWorked") != 0) { - if(w.hasExtension("EmployeeHR") && w.getFieldAsDouble("EmployeeHR", "partialTime") != 0) { - return companyW.getFieldAsDouble("CompanyHR", "dailyHoursWorked") * - (w.getFieldAsDouble("EmployeeHR", "partialTime")/100); + if(companyW.hasExtension(CompanyHR.EXT_COMPANYHR) && + companyW.getFieldAsDouble(CompanyHR.EXT_COMPANYHR,CompanyHR.FIELD_COMPANYHR_DAILYHOURSWORKED) != 0) { + if(w.hasExtension(EmployeeHR.EXT_EMPLOYEEHR) && w.getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR, EmployeeHR.FIELD_EMPLOYEEHR_PARTIALTIME) != 0) { + return companyW.getFieldAsDouble(CompanyHR.EXT_COMPANYHR, CompanyHR.FIELD_COMPANYHR_DAILYHOURSWORKED) * + (w.getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR, EmployeeHR.FIELD_EMPLOYEEHR_PARTIALTIME)/100); } else { - return companyW.getFieldAsDouble("CompanyHR", "dailyHoursWorked"); + return companyW.getFieldAsDouble(CompanyHR.EXT_COMPANYHR, CompanyHR.FIELD_COMPANYHR_DAILYHOURSWORKED); } } Modified: trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java 2013-08-01 14:16:31 UTC (rev 379) +++ trunk/chorem-entities/src/main/java/org/chorem/project/AdcCalculation.java 2013-08-07 13:34:26 UTC (rev 380) @@ -3,12 +3,14 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.List; import org.chorem.ChoremClient; import org.chorem.ChoremUtil; import org.chorem.entities.Employee; import org.chorem.entities.EmployeeHR; +import org.chorem.entities.FinancialTransaction; import org.chorem.entities.Interval; import org.chorem.entities.Quotation; import org.chorem.entities.Time; @@ -17,57 +19,57 @@ import org.nuiton.wikitty.query.WikittyQueryMaker; import org.nuiton.wikitty.query.WikittyQueryResult; +import com.arjuna.ats.jta.transaction.Transaction; + public class AdcCalculation { - ChoremClient client; - EmployeeHR e; - Company company; - Date start; - Date end; /** * Calculates the total gains made by the company in one year * @return */ - public double getTotalGain() { + public static double getTotalExpenses(ChoremClient client, Company company, Date start, Date end) { - WikittyQuery gainQuery = new WikittyQueryMaker() + WikittyQuery expenseQuery = new WikittyQueryMaker() .and() - .exteq("Closed") - .containsOne(Quotation.ELEMENT_FIELD_QUOTATION_SUPPLIER, getEmployeesHR()) + .exteq(FinancialTransaction.EXT_FINANCIALTRANSACTION) .or() - .bw(Interval.FQ_FIELD_INTERVAL_BEGINDATE, start, end) - .bw(Interval.FQ_FIELD_INTERVAL_ENDDATE, start, end) + .containsOne(FinancialTransaction.ELEMENT_FIELD_FINANCIALTRANSACTION_PAYER, getEmployeesHR(client, company)) + .eq(FinancialTransaction.ELEMENT_FIELD_FINANCIALTRANSACTION_PAYER, company) + .close() + .bw(FinancialTransaction.ELEMENT_FIELD_FINANCIALTRANSACTION_PAYMENTDATE, start, end) .end(); - WikittyQueryResult<Quotation> result = client.findAllByQuery(Quotation.class, gainQuery); + WikittyQueryResult<FinancialTransaction> result = client.findAllByQuery(FinancialTransaction.class, expenseQuery); double total = 0; - for(Quotation q : result.getAll()) { - total += q.getAmount(); + for(FinancialTransaction ft : result.getAll()) { + total += ft.getAmount(); } return total; } + + /** * calculates all the salaries of the employees ponderated by the productivity rate * @return */ - public double getTotalSalaries() { + public static double getTotalSalaries(ChoremClient client, Company company) { //pondéré par pct de productivité double total = 0; - for(EmployeeHR e : getEmployeesHR()) { + for(EmployeeHR e : getEmployeesHR(client, company)) { total += e.getSalary() * (e.getProductivityRate()/100); } return total; } - private List<EmployeeHR> getEmployeesHR() { + private static List<EmployeeHR> getEmployeesHR(ChoremClient client, Company company) { WikittyQuery employeeQuery = new WikittyQueryMaker().and() - .exteq("EmployeeHR") + .exteq(EmployeeHR.EXT_EMPLOYEEHR) .eq(Employee.ELEMENT_FIELD_EMPLOYEE_COMPANY, company) .end(); WikittyQueryResult<EmployeeHR> result = client.findAllByQuery(EmployeeHR.class, employeeQuery); @@ -76,17 +78,17 @@ } /** - * Calculates the sum of all the tims object linked to the company + * Calculates the sum of all the times object linked to the company * @return */ - public double getTotalTimes() { + public static double getTotalTimes(ChoremClient client, Company company, Date start, Date end) { WikittyQuery empQuery = new WikittyQueryMaker() .eq(Employee.ELEMENT_FIELD_EMPLOYEE_COMPANY, company).end(); WikittyQueryResult<Employee> empResult = client.findAllByQuery(Employee.class, empQuery); WikittyQuery timeQuery = new WikittyQueryMaker() .and() - .exteq("Time") + .exteq(Time.EXT_TIME) .containsOne(Time.ELEMENT_FIELD_TIME_EMPLOYEE, empResult.getAll()) .or() .bw(Interval.FQ_FIELD_INTERVAL_BEGINDATE, start, end) @@ -102,38 +104,76 @@ return total; } - public double getAdc() { + /** + * Returns the employee's adc + * @return + */ + public static double getAdc(ChoremClient client, EmployeeHR e) { + Company company = e.getCompany(false); + Date end = new GregorianCalendar().getTime(); + Calendar cstart = new GregorianCalendar(); + cstart.add(Calendar.YEAR, -1); + Date start = cstart.getTime(); - double expenses = getTotalGain(); - double salaries = getTotalSalaries(); - double times = getTotalTimes(); + double expenses = getTotalExpenses(client, company, start, end); + double salaries = getTotalSalaries(client, company); + double times = getTotalTimes(client, company, start, end); double dailyHoursWorked = client.getDailyHoursWorked(e); - double dailySalary = client.restore(e.getWikittyId()).getFieldAsDouble("EmployeeHR", "salary")/21.5; - System.out.println("GAIN : " + expenses); - System.out.println("SALAIRES : " + salaries); + double dailySalary = client.restore(e.getWikittyId()) + .getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR,EmployeeHR.FIELD_EMPLOYEEHR_SALARY)/21.5; + + System.out.println("EXPENSES : " + expenses); + System.out.println("SALARIES : " + salaries); System.out.println("TIMES : " + times); - System.out.println("DAILY HW : " + dailyHoursWorked); - System.out.println("DAILY SALARY : " + dailySalary); + System.out.println("DHW : " + dailyHoursWorked); + System.out.println("SALARY : " + dailySalary); + + double adc = ( (expenses/salaries)/times ) * dailyHoursWorked * dailySalary; + //dailySalary = dailySalary *1.6; //charges patronales + //double adc = dailySalary; - return adc; } - - public AdcCalculation(EmployeeHR e, ChoremClient client) { - this.e = e; - this.company = e.getCompany(false); - this.client = client; - this.end = new GregorianCalendar().getTime(); - Calendar start = new GregorianCalendar(); - start.add(Calendar.YEAR, -1); - this.start = start.getTime(); + public static HashMap<String, Double> getMultipleAdc(ChoremClient client, List<EmployeeHR> employees) { + if(employees.size() == 0) + return null; + Company company = employees.get(0).getCompany(false); + Date end = new GregorianCalendar().getTime(); + Calendar cstart = new GregorianCalendar(); + cstart.add(Calendar.YEAR, -1); + Date start = cstart.getTime(); + + double expenses = getTotalExpenses(client, company, start, end); + double salaries = getTotalSalaries(client, company); + double times = getTotalTimes(client, company, start, end); + + HashMap<String, Double> adcs = new HashMap<String, Double>(); + for(EmployeeHR e : employees) { + double dailyHoursWorked = client.getDailyHoursWorked(e); + double dailySalary = client.restore(e.getWikittyId()) + .getFieldAsDouble(EmployeeHR.EXT_EMPLOYEEHR, EmployeeHR.FIELD_EMPLOYEEHR_SALARY)/21.5; + System.out.println("EXPENSES : " + expenses); + System.out.println("SALAIRES : " + salaries); + System.out.println("TIMES : " + times); + System.out.println("DAILY HW : " + dailyHoursWorked); + System.out.println("DAILY SALARY : " + dailySalary); + adcs.put(e.getWikittyId(),( (expenses/salaries)/times ) * dailyHoursWorked * dailySalary); + } + //dailySalary = dailySalary *1.6; //charges patronales + //double adc = dailySalary; + + return adcs; + } + + + } Modified: trunk/chorem-entities/src/main/java/org/chorem/project/QuotationCalculation.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/project/QuotationCalculation.java 2013-08-01 14:16:31 UTC (rev 379) +++ trunk/chorem-entities/src/main/java/org/chorem/project/QuotationCalculation.java 2013-08-07 13:34:26 UTC (rev 380) @@ -7,7 +7,6 @@ import org.chorem.entities.Employee; import org.chorem.entities.Quotation; import org.chorem.entities.Task; -import java.util.Set; public class QuotationCalculation extends Calculation<Quotation> { Added: trunk/chorem-entities/src/main/java/org/chorem/project/TotalQuotationCalculation.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/project/TotalQuotationCalculation.java (rev 0) +++ trunk/chorem-entities/src/main/java/org/chorem/project/TotalQuotationCalculation.java 2013-08-07 13:34:26 UTC (rev 380) @@ -0,0 +1,122 @@ +package org.chorem.project; + +import java.util.HashMap; +import java.util.List; + +import org.chorem.ChoremClient; +import org.chorem.entities.Employee; +import org.chorem.entities.Quotation; +import org.chorem.entities.Task; + +public class TotalQuotationCalculation extends Calculation<Quotation> { + + + private List<QuotationCalculation> calculations; + + public TotalQuotationCalculation(List<QuotationCalculation> calculations) { + super(null, totalAmount(calculations), totalEstimatedDays(calculations), null); + //super(q, q.getAmount(), q.getEstimatedDays(), client); + this.calculations = calculations; + } + + private static double totalAmount(List<QuotationCalculation> calculations) { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getObject().getAmount(); + + } + return total; + } + + private static double totalEstimatedDays(List<QuotationCalculation> calculations) { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getObject().getEstimatedDays(); + + } + return total; + } + + public double getAmount() { + return amount; + } + + public double getEstimatedDays() { + return nbDays; + } + + + @Override + public double realDays() { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getRealDays(); + + } + return total; + + } + + @Override + public double avgReturn() { + + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getAvgReturn(); + + } + return total; + } + + @Override + public double realReturn() { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getRealReturn(); + + } + return total; + } + + @Override + public double expectedProfit() { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getExpectedProfit(); + + } + return total; + } + + @Override + public double lossOrProfit() { + double total = 0; + for(QuotationCalculation q : calculations) { + total += q.getLossOrProfit(); + + } + return total; + } + + + + + + + @Override + public HashMap<Employee, Double> getPercentages() { + return null; + } + + @Override + public HashMap<Employee, Double> getTimePercentages() { + return null; + } + + + @Override + public HashMap<Employee, Double> getTimes() { + return null; + } + +}