This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository chorem. See http://git.chorem.org/chorem.git commit 0869812f53c102b1ef09d77523c41e7b8de1cc54 Author: kootox <jean.couteau@gmail.com> Date: Wed Jan 28 14:36:21 2015 +0100 fixes #1155 : Incohérences dans les tableaux de facturation That feature might be improved (less wikitty client calls and java loops) with wikitty Evolution #2558 : add group by clause in Query to group on specific field (http://nuiton.org/issues/2558) --- .../financial/AccountBillingReportAction.java | 6 +- .../financial/BillingPerAccountReportAction.java | 74 ++++++++++------- .../financial/BillingPerProjectReportAction.java | 96 ++++++++++++++-------- .../financial/ProjectBillingReportAction.java | 6 +- .../chorem/webmotion/actions/sales/SalesData.java | 18 ++-- .../actions/sales/SalesPerAccountReportAction.java | 2 +- .../actions/sales/SalesPerProjectReportAction.java | 2 +- 7 files changed, 124 insertions(+), 80 deletions(-) diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/AccountBillingReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/AccountBillingReportAction.java index 38253c9..7bc595a 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/AccountBillingReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/AccountBillingReportAction.java @@ -65,7 +65,7 @@ public class AccountBillingReportAction extends WebMotionController { List<Integer> listAllYearsInChorem = BillingReportHelper.listAllYears(client); - int previousYearValue = 0; + double previousYearValue = 0.0; for (Integer year:listAllYears){ Date yearFirstDay = BillingReportHelper.getFirstDayOfYear(year); @@ -80,7 +80,7 @@ public class AccountBillingReportAction extends WebMotionController { yearLastDay) .end(); - Integer sales = client.findByQuery(Integer.class, projectQuery); + Double sales = client.findByQuery(Double.class, projectQuery); //TODO JC 2012-01-26 Find a way to replace two queries into one. WikittyQuery quotationsQuery = new WikittyQueryMaker().and() @@ -93,7 +93,7 @@ public class AccountBillingReportAction extends WebMotionController { quotationsQuery).getAll(); //Progression devis envoyés - int salesProgression = 0; + double salesProgression = 0; if (previousYearValue != 0){ salesProgression = 100 * (sales - previousYearValue) / previousYearValue; } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerAccountReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerAccountReportAction.java index 2bd1477..a1ea506 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerAccountReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerAccountReportAction.java @@ -31,10 +31,7 @@ import org.nuiton.wikitty.WikittyClient; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author jcouteau <couteau@codelutin.com> @@ -75,42 +72,57 @@ public class BillingPerAccountReportAction extends WebMotionController { Date last = BillingReportHelper.getLastDayOfYear(Integer.valueOf(lastYear)); Date first = BillingReportHelper.getFirstDayOfYear(Integer.valueOf(firstYear)); - Map<Company,SalesData> salesData = new LinkedHashMap<Company, SalesData>(); + System.out.println(firstYear); + System.out.println(first); - //a query to get all the accounts - //FIXME JC 2012-01-26 Really bad to find all employees and iterate on them :( - WikittyQuery accountsQuery = new WikittyQueryMaker().and() - .exteq(Company.EXT_COMPANY).end(); + System.out.println(lastYear); + System.out.println(last); - List<Company> accounts = client.findAllByQuery(Company.class, accountsQuery).getAll(); + Map<Company,SalesData> salesData = new LinkedHashMap<>(); - //iterate and two queries per account :( - for (Company account:accounts){ + //get all the bills between first and last + WikittyQuery billsQuery = new WikittyQueryMaker() + .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) + .end(); + + List<FinancialTransaction> bills = client.findAllByQuery(FinancialTransaction.class, + billsQuery).getAll(); - SalesData projectData = new SalesData(); + Map<String,SalesData> salesDataPerId = new LinkedHashMap<>(); - WikittyQuery accountQuery = new WikittyQueryMaker() - .select().sum("FinancialTransaction.amount").where().and() - .eq(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_PAYER, account) - .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) - .end(); + //group bills by account and sum values + for (FinancialTransaction bill:bills){ + System.out.println(bill.getReference()); + String companyId = bill.getPayer(); + SalesData accountData; + if (salesDataPerId.containsKey(companyId)){ + accountData = salesDataPerId.get(companyId); + } else { + accountData = new SalesData(); + } - Integer sales = client.findByQuery(Integer.class, accountQuery); + accountData.setSales(accountData.getSales() + bill.getAmount()); + accountData.setQuotations(accountData.getQuotations()+1); + salesDataPerId.put(companyId, accountData); + } + System.out.println(salesDataPerId); - //TODO JC 2012-01-26 Find a way to replace two queries into one. - WikittyQuery quotationsQuery = new WikittyQueryMaker().and() - .eq(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_PAYER, account) - .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) - .end(); + //get accounts and create a map id->company + List<Company> accounts = client.restore(Company.class, new ArrayList<>(salesDataPerId.keySet()), false); + Map<String,Company> accountsById = new HashMap<>(); + for (Company account:accounts){ + if (account != null) { + accountsById.put(account.getWikittyId(), account); + } + } - List<FinancialTransaction> quotations = client.findAllByQuery(FinancialTransaction.class, - quotationsQuery).getAll(); + System.out.println(accountsById); - //Rempli la map que si on a des valeurs - if (null != sales && sales != 0) { - projectData.setSales(sales); - projectData.setQuotations(quotations.size()); - salesData.put(account, projectData); + //populate the output + for (Map.Entry<String, SalesData> entry : salesDataPerId.entrySet()) { + Company account = accountsById.get(entry.getKey()); + if (account != null) { + salesData.put(account, entry.getValue()); } } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerProjectReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerProjectReportAction.java index 49a0f78..192fbf4 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerProjectReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/BillingPerProjectReportAction.java @@ -29,13 +29,11 @@ import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.WikittyClient; import org.nuiton.wikitty.entities.Element; +import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author jcouteau <couteau@codelutin.com> @@ -76,43 +74,77 @@ public class BillingPerProjectReportAction extends WebMotionController { Date last = BillingReportHelper.getLastDayOfYear(Integer.valueOf(lastYear)); Date first = BillingReportHelper.getFirstDayOfYear(Integer.valueOf(firstYear)); - Map<Project,SalesData> billingData = new LinkedHashMap<Project, SalesData>(); + Map<Project,SalesData> billingData = new LinkedHashMap<>(); - //a query to get all the projects - WikittyQuery projectsQuery = new WikittyQueryMaker().and() - .exteq(Project.EXT_PROJECT).end(); + //get all the bills between first and last + WikittyQuery billsQuery = new WikittyQueryMaker() + .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) + .end(); - List<Project> projects = client.findAllByQuery(Project.class, projectsQuery).getAll(); + List<FinancialTransaction> bills = client.findAllByQuery(FinancialTransaction.class, + billsQuery).getAll(); - //a query per project :( - for (Project project:projects){ + Map<String,SalesData> billingDataPerId = new LinkedHashMap<>(); + + List<String> targetsId = new ArrayList<>(); + for (FinancialTransaction bill:bills){ + String target = bill.getTarget(); + if (target != null) { + targetsId.add(target); + } + } + + List<Wikitty> targetsWikitty = client.restore(targetsId); + + Map<String,Project> projectsById = new HashMap<>(); + + List<String> projectsId = new ArrayList<>(); + + Map <String, Wikitty> wikittyById = new HashMap<>(); - SalesData projectData = new SalesData(); + for (Wikitty wkt:targetsWikitty){ + if (wkt.hasExtension(Project.EXT_PROJECT)){ + projectsById.put(wkt.getWikittyId(), client.castTo(Project.class, wkt)); + } else if (wkt.hasExtension(Quotation.EXT_QUOTATION)){ + projectsId.add(wkt.getFieldAsWikitty(Quotation.EXT_QUOTATION, Quotation.FIELD_QUOTATION_PROJECT)); + } + } + + List<Project> projects = client.restore(Project.class, projectsId, false); + for (Project project:projects){ + projectsById.put(project.getWikittyId(), project); + } - WikittyQuery projectQuery = new WikittyQueryMaker() - .select().sum("FinancialTransaction.amount").where().and() - .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) - .containsOne(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_TARGET) - .select(Element.ID).or().ideq(project).eq(Quotation.ELEMENT_FIELD_QUOTATION_PROJECT, project).close() - .end(); + //group bills by project and sum values + for (FinancialTransaction bill:bills){ + String targetId = bill.getTarget(); + SalesData projectData; + + //if target is a quotation, replace targetId with the quotation project + if (!projectsById.containsKey(targetId)) { + Wikitty wkt = wikittyById.get(targetId); + if (wkt != null){ + targetId = wkt.getFieldAsWikitty(Quotation.EXT_QUOTATION, Quotation.FIELD_QUOTATION_PROJECT); + } + } - Integer sales = client.findByQuery(Integer.class, projectQuery); + if (billingDataPerId.containsKey(targetId)) { + projectData = billingDataPerId.get(targetId); + } else { + projectData = new SalesData(); + } - //TODO JC 2012-01-22 Find a way to replace two queries into one. - WikittyQuery transactionsQuery = new WikittyQueryMaker().and() - .bw(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_EMITTEDDATE, first, last) - .containsOne(FinancialTransaction.FQ_FIELD_FINANCIALTRANSACTION_TARGET) - .select(Element.ID).or().ideq(project).eq(Quotation.ELEMENT_FIELD_QUOTATION_PROJECT, project).close() - .end(); + projectData.setSales(projectData.getSales() + bill.getAmount()); + projectData.setQuotations(projectData.getQuotations() + 1); + billingDataPerId.put(targetId, projectData); - List<FinancialTransaction> transactions = client.findAllByQuery(FinancialTransaction.class, - transactionsQuery).getAll(); + } - //Rempli la map que si on a des valeurs - if (null != sales && sales != 0) { - projectData.setSales(sales); - projectData.setQuotations(transactions.size()); - billingData.put(project, projectData); + //populate the output + for (Map.Entry<String, SalesData> entry : billingDataPerId.entrySet()) { + Project project = projectsById.get(entry.getKey()); + if (project != null) { + billingData.put(project, entry.getValue()); } } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ProjectBillingReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ProjectBillingReportAction.java index 1450120..e75ce1e 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ProjectBillingReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ProjectBillingReportAction.java @@ -65,7 +65,7 @@ public class ProjectBillingReportAction extends WebMotionController { List<Integer> listAllYearsInChorem = BillingReportHelper.listAllYears(client); - int previousYearValue = 0; + double previousYearValue = 0; for (Integer year:listAllYears){ Date yearFirstDay = BillingReportHelper.getFirstDayOfYear(year); @@ -80,7 +80,7 @@ public class ProjectBillingReportAction extends WebMotionController { yearLastDay) .end(); - Integer billing = client.findByQuery(Integer.class, projectQuery); + Double billing = client.findByQuery(Double.class, projectQuery); //TODO JC 2012-01-22 Find a way to replace two queries into one. WikittyQuery quotationsQuery = new WikittyQueryMaker().and() @@ -93,7 +93,7 @@ public class ProjectBillingReportAction extends WebMotionController { quotationsQuery).getAll(); //Progression devis envoyés - int salesProgression = 0; + double salesProgression = 0; if (previousYearValue != 0){ salesProgression = 100 * (billing - previousYearValue) / previousYearValue; } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesData.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesData.java index 3bc467b..397cd54 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesData.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesData.java @@ -26,17 +26,17 @@ package org.chorem.webmotion.actions.sales; */ public class SalesData { - protected Integer sales; + protected Double sales = 0.0; - protected Integer quotations; + protected Integer quotations = 0; - protected Integer progression; + protected Double progression; - public Integer getSales() { + public Double getSales() { return sales; } - public void setSales(Integer sales) { + public void setSales(Double sales) { this.sales = sales; } @@ -48,9 +48,9 @@ public class SalesData { this.quotations = quotations; } - public Integer getMean() { + public Double getMean() { - Integer mean = 0; + Double mean = 0.0; if (null != sales && null != quotations && quotations != 0) { mean = sales/quotations; @@ -59,11 +59,11 @@ public class SalesData { return mean; } - public Integer getProgression() { + public Double getProgression() { return progression; } - public void setProgression(Integer progression) { + public void setProgression(Double progression) { this.progression = progression; } } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerAccountReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerAccountReportAction.java index 08e35b0..7b0fdf9 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerAccountReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerAccountReportAction.java @@ -96,7 +96,7 @@ public class SalesPerAccountReportAction extends WebMotionController { .bw(Accepted.FQ_FIELD_ACCEPTED_ACCEPTEDDATE, first, last) .end(); - Integer sales = client.findByQuery(Integer.class, accountQuery); + Double sales = client.findByQuery(Double.class, accountQuery); //TODO JC 2012-01-26 Find a way to replace two queries into one. WikittyQuery quotationsQuery = new WikittyQueryMaker().and() diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerProjectReportAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerProjectReportAction.java index 015e666..3d9279e 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerProjectReportAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesPerProjectReportAction.java @@ -95,7 +95,7 @@ public class SalesPerProjectReportAction extends WebMotionController { .bw(Accepted.FQ_FIELD_ACCEPTED_ACCEPTEDDATE, first, last) .end(); - Integer sales = client.findByQuery(Integer.class, projectQuery); + Double sales = client.findByQuery(Double.class, projectQuery); //TODO JC 2012-01-22 Find a way to replace two queries into one. WikittyQuery quotationsQuery = new WikittyQueryMaker().and() -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.