Skip to content

Commit f0d476f

Browse files
Merge branch 'QAT-6053' into dev
2 parents fd5f91d + 9d57244 commit f0d476f

28 files changed

Lines changed: 1447 additions & 1040 deletions

src/main/java/cc/altius/FASP/dao/impl/ReportDaoImpl.java

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,13 @@
6868
import cc.altius.FASP.model.report.ShipmentDetailsMonthRowMapper;
6969
import cc.altius.FASP.model.report.ShipmentGlobalDemandCountryShipmentSplitRowMapper;
7070
import cc.altius.FASP.model.report.ShipmentGlobalDemandCountrySplitRowMapper;
71-
import cc.altius.FASP.model.report.ShipmentGlobalDemandDateSplitRowMapper;
7271
import cc.altius.FASP.model.report.ShipmentGlobalDemandInput;
7372
import cc.altius.FASP.model.report.ShipmentGlobalDemandOutput;
74-
import cc.altius.FASP.model.report.ShipmentGlobalDemandShipmentListRowMapper;
75-
import cc.altius.FASP.model.report.ShipmentOverviewFundindSourceSplitRowMapper;
73+
import cc.altius.FASP.model.report.ShipmentOverviewFspaCostAndPercRowMapper;
74+
import cc.altius.FASP.model.report.ShipmentOverviewFspaSplitRowMapper;
7675
import cc.altius.FASP.model.report.ShipmentOverviewInput;
7776
import cc.altius.FASP.model.report.ShipmentOverviewOutput;
78-
import cc.altius.FASP.model.report.ShipmentOverviewPlanningUnitSplitRowMapper;
79-
import cc.altius.FASP.model.report.ShipmentOverviewProcurementAgentSplit;
80-
import cc.altius.FASP.model.report.ShipmentOverviewProcurementAgentSplitRowMapper;
77+
import cc.altius.FASP.model.report.ShipmentOverviewPlanningUnitQuantityResultSetExtractor;
8178
import cc.altius.FASP.model.report.ShipmentReportInput;
8279
import cc.altius.FASP.model.report.ShipmentReportOutput;
8380
import cc.altius.FASP.model.report.ShipmentReportOutputRowMapper;
@@ -113,10 +110,8 @@
113110
import cc.altius.FASP.model.rowMapper.StockAdjustmentReportOutputRowMapper;
114111
import cc.altius.FASP.service.AclService;
115112
import cc.altius.FASP.utils.ArrayUtils;
116-
import cc.altius.FASP.utils.LogUtils;
117113
import java.util.Date;
118114
import java.util.HashMap;
119-
import java.util.LinkedList;
120115
import java.util.List;
121116
import java.util.Map;
122117
import java.util.stream.Collectors;
@@ -530,51 +525,27 @@ public ShipmentDetailsOutput getShipmentDetails(ShipmentDetailsInput sd, CustomU
530525
@Override
531526
public ShipmentOverviewOutput getShipmentOverview(ShipmentOverviewInput so, CustomUserDetails curUser) {
532527
Map<String, Object> params = new HashMap<String, Object>();
528+
params.put("curUser", curUser.getUserId());
533529
params.put("realmId", so.getRealmId());
534530
params.put("startDate", so.getStartDate());
535531
params.put("stopDate", so.getStopDate());
536532
params.put("realmCountryIds", so.getRealmCountryIdsString());
537533
params.put("programIds", so.getProgramIdsString());
534+
params.put("versionId", so.getVersionId());
535+
params.put("fspa", so.getFspa());
536+
params.put("fspaIds", so.getFundingSourceIdsString());
538537
params.put("planningUnitIds", so.getPlanningUnitIdsString());
539-
params.put("fundingSourceIds", so.getFundingSourceIdsString());
540538
params.put("shipmentStatusIds", so.getShipmentStatusIdsString());
541-
params.put("approvedSupplyPlanOnly", so.isUseApprovedSupplyPlanOnly());
542-
params.put("groupByProcurementAgentType", so.isGroupByProcurementAgentType());
543-
params.put("curUser", curUser.getUserId());
539+
544540
ShipmentOverviewOutput soo = new ShipmentOverviewOutput();
545-
String sql = "";
546-
if (!so.isGroupByFundingSourceType()) {
547-
sql = "CALL shipmentOverview_FundingSourceSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :fundingSourceIds, :planningUnitIds, :shipmentStatusIds, :approvedSupplyPlanOnly)";
548-
} else {
549-
sql = "CALL shipmentOverview_FundingSourceTypeSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :fundingSourceIds, :planningUnitIds, :shipmentStatusIds, :approvedSupplyPlanOnly)";
550-
}
551-
soo.setFundingSourceSplit(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewFundindSourceSplitRowMapper()));
552-
sql = "CALL shipmentOverview_PlanningUnitSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :fundingSourceIds, :planningUnitIds, :shipmentStatusIds, :approvedSupplyPlanOnly)";
553-
soo.setPlanningUnitSplit(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewPlanningUnitSplitRowMapper()));
554-
if (!so.isGroupByProcurementAgentType()) {
555-
sql = "CALL shipmentOverview_ProcurementAgentSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :fundingSourceIds, :planningUnitIds, :shipmentStatusIds, :approvedSupplyPlanOnly)";
556-
} else {
557-
sql = "CALL shipmentOverview_ProcurementAgentTypeSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :fundingSourceIds, :planningUnitIds, :shipmentStatusIds, :approvedSupplyPlanOnly)";
558-
}
559-
List<ShipmentOverviewProcurementAgentSplit> sopList = this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewProcurementAgentSplitRowMapper());
560-
if (!sopList.isEmpty()) {
561-
List<String> keyListToRemove = new LinkedList<>();
562-
for (String key : sopList.get(0).getProcurementAgentQty().keySet()) {
563-
Double total = sopList.stream()
564-
.map(x -> (Double) x.getProcurementAgentQty().get(key))
565-
.collect(Collectors.summingDouble(Double::doubleValue));
566-
if (total.doubleValue() == 0) {
567-
// Add to the remove List
568-
keyListToRemove.add(key);
569-
}
570-
}
571-
keyListToRemove.forEach(key -> {
572-
sopList.forEach(sop -> {
573-
sop.getProcurementAgentQty().remove(key);
574-
});
575-
});
576-
}
577-
soo.setProcurementAgentSplit(sopList);
541+
String sql = "CALL shipmentOverview_planningUnitQuantity(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :versionId, :fspa, :fspaIds, :planningUnitIds, :shipmentStatusIds)";
542+
soo.setPlanningUnitQuantity(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewPlanningUnitQuantityResultSetExtractor()));
543+
sql = "CALL shipmentOverview_fspaCost(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :versionId, :fspa, :fspaIds, :planningUnitIds, :shipmentStatusIds)";
544+
soo.setFspaCostAndPerc(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewFspaCostAndPercRowMapper()));
545+
sql = "CALL shipmentOverview_fspaProgramSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :versionId, :fspa, :fspaIds, :planningUnitIds, :shipmentStatusIds)";
546+
soo.setFspaProgramSplit(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewFspaSplitRowMapper()));
547+
sql = "CALL shipmentOverview_fspaCountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :versionId, :fspa, :fspaIds, :planningUnitIds, :shipmentStatusIds)";
548+
soo.setFspaCountrySplit(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentOverviewFspaSplitRowMapper()));
578549
return soo;
579550
}
580551

@@ -594,44 +565,11 @@ public ShipmentGlobalDemandOutput getShipmentGlobalDemand(ShipmentGlobalDemandIn
594565
params.put("includePlannedShipments", sgd.isIncludePlannedShipments());
595566
params.put("curUser", curUser.getUserId());
596567
ShipmentGlobalDemandOutput sgdo = new ShipmentGlobalDemandOutput();
597-
// String sql = "CALL shipmentGlobalDemand_ShipmentList(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :reportView, :fundingSourceProcurementAgentIds, :planningUnitId, :approvedSupplyPlanOnly, :includePlannedShipments)";
598-
// sgdo.setShipmentList(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentGlobalDemandShipmentListRowMapper()));
599-
// switch (sgd.getReportView()) {
600-
// case 1: //Funding Source
601-
// sql = "CALL shipmentGlobalDemand_FundingSourceDateSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :reportView, :fundingSourceProcurementAgentIds, :planningUnitId, :approvedSupplyPlanOnly, :includePlannedShipments)";
602-
// break;
603-
// case 2: // Procurement Agent
604-
// sql = "CALL shipmentGlobalDemand_ProcurementAgentDateSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :reportView, :fundingSourceProcurementAgentIds, :planningUnitId, :approvedSupplyPlanOnly, :includePlannedShipments)";
605-
// break;
606-
// case 3: // Procurement Agent Type
607-
// sql = "CALL shipmentGlobalDemand_ProcurementAgentTypeDateSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :reportView, :fundingSourceProcurementAgentIds, :planningUnitId, :approvedSupplyPlanOnly, :includePlannedShipments)";
608-
// break;
609-
// case 4: // Funding Source Type
610-
// sql = "CALL shipmentGlobalDemand_FundingSourceTypeDateSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :reportView, :fundingSourceProcurementAgentIds, :planningUnitId, :approvedSupplyPlanOnly, :includePlannedShipments)";
611-
// break;
612-
// }
613-
// sgdo.setDateSplitList(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentGlobalDemandDateSplitRowMapper()));
614-
// String sql = "";
615-
// switch (sgd.getReportView()) {
616-
// case 1: //Funding Source
617-
// sql = "CALL shipmentGlobalDemand_FundingSourceCountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
618-
// break;
619-
// case 2: // Procurement Agent
620-
// sql = "CALL shipmentGlobalDemand_ProcurementAgentCountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
621-
// break;
622-
// case 3: // Procurement Agent Type
623-
// sql = "CALL shipmentGlobalDemand_ProcurementAgentTypeCountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
624-
// break;
625-
// case 4: // Funding Source Type
626-
// sql = "CALL shipmentGlobalDemand_FundingSourceTypeCountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
627-
// break;
628-
// }
629-
// sgdo.setCountrySplitList(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentGlobalDemandCountrySplitRowMapper()));
630-
//
631568
String sql = "CALL shipmentGlobalDemand_CountrySplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
632569
sgdo.setCountrySplitList(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentGlobalDemandCountrySplitRowMapper()));
633570
sql = "CALL shipmentGlobalDemand_CountryShipmentSplit(:curUser, :realmId, :startDate, :stopDate, :realmCountryIds, :programIds, :equivalencyUnitId, :planningUnitIds, :reportView, :fundingSourceProcurementAgentIds, :includePlannedShipments)";
634571
sgdo.setCountryShipmentSplitList(this.namedParameterJdbcTemplate.query(sql, params, new ShipmentGlobalDemandCountryShipmentSplitRowMapper(sgd.isIncludePlannedShipments())));
572+
635573
return sgdo;
636574
}
637575

@@ -699,7 +637,7 @@ public List<BudgetReportOutput> getBudgetReport(BudgetReportInput br, CustomUser
699637
+ "LEFT JOIN vw_funding_source_type fst ON fs.FUNDING_SOURCE_TYPE_ID=fst.FUNDING_SOURCE_TYPE_ID "
700638
+ "LEFT JOIN vw_currency c ON b.CURRENCY_ID=c.CURRENCY_ID "
701639
+ "LEFT JOIN ( "
702-
+ " SELECT "
640+
+ " SELECT "
703641
+ " st.BUDGET_ID, "
704642
+ " SUM(IF(st.SHIPMENT_STATUS_ID IN (1), ((IFNULL(st.FREIGHT_COST,0)+IFNULL(st.PRODUCT_COST,0))*s.CONVERSION_RATE_TO_USD),0)) `PLANNED_BUDGET`, "
705643
+ " SUM(IF(st.SHIPMENT_STATUS_ID IN (3,4,5,6,7,9), ((IFNULL(st.FREIGHT_COST,0)+IFNULL(st.PRODUCT_COST,0))*s.CONVERSION_RATE_TO_USD),0)) `ORDERED_BUDGET`, SUM(IF(:programIds='' OR FIND_IN_SET(s.PROGRAM_ID, :programIds), 1, 0)) AS MATCH_COUNT "
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package cc.altius.FASP.model.report;
6+
7+
import cc.altius.FASP.model.SimpleCodeObject;
8+
import cc.altius.FASP.model.Views;
9+
import com.fasterxml.jackson.annotation.JsonView;
10+
import java.io.Serializable;
11+
import java.util.Objects;
12+
13+
/**
14+
*
15+
* @author akil
16+
*/
17+
public class ShipmentOverviewFspaCostAndPerc implements Serializable {
18+
19+
@JsonView(Views.ReportView.class)
20+
private SimpleCodeObject fspa;
21+
@JsonView(Views.ReportView.class)
22+
private double cost;
23+
@JsonView(Views.ReportView.class)
24+
private double perc;
25+
26+
public SimpleCodeObject getFspa() {
27+
return fspa;
28+
}
29+
30+
public void setFspa(SimpleCodeObject fspa) {
31+
this.fspa = fspa;
32+
}
33+
34+
public double getCost() {
35+
return cost;
36+
}
37+
38+
public void setCost(double cost) {
39+
this.cost = cost;
40+
}
41+
42+
public double getPerc() {
43+
return perc;
44+
}
45+
46+
public void setPerc(double perc) {
47+
this.perc = perc;
48+
}
49+
50+
@Override
51+
public int hashCode() {
52+
int hash = 7;
53+
hash = 67 * hash + Objects.hashCode(this.fspa);
54+
return hash;
55+
}
56+
57+
@Override
58+
public boolean equals(Object obj) {
59+
if (this == obj) {
60+
return true;
61+
}
62+
if (obj == null) {
63+
return false;
64+
}
65+
if (getClass() != obj.getClass()) {
66+
return false;
67+
}
68+
final ShipmentOverviewFspaCostAndPerc other = (ShipmentOverviewFspaCostAndPerc) obj;
69+
return Objects.equals(this.fspa, other.fspa);
70+
}
71+
72+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package cc.altius.FASP.model.report;
6+
7+
import cc.altius.FASP.model.SimpleCodeObject;
8+
import cc.altius.FASP.model.rowMapper.LabelRowMapper;
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import org.springframework.jdbc.core.RowMapper;
12+
13+
/**
14+
*
15+
* @author akil
16+
*/
17+
public class ShipmentOverviewFspaCostAndPercRowMapper implements RowMapper<ShipmentOverviewFspaCostAndPerc> {
18+
19+
@Override
20+
public ShipmentOverviewFspaCostAndPerc mapRow(ResultSet rs, int rowNum) throws SQLException {
21+
ShipmentOverviewFspaCostAndPerc item = new ShipmentOverviewFspaCostAndPerc();
22+
item.setFspa(new SimpleCodeObject(rs.getInt("FSPA_ID"), new LabelRowMapper("FSPA_").mapRow(rs, rowNum), rs.getString("FSPA_CODE")));
23+
item.setCost(rs.getDouble("TOTAL_COST"));
24+
return item;
25+
}
26+
27+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package cc.altius.FASP.model.report;
7+
8+
import cc.altius.FASP.model.SimpleCodeObject;
9+
import cc.altius.FASP.model.SimpleObject;
10+
import cc.altius.FASP.model.Views;
11+
import com.fasterxml.jackson.annotation.JsonView;
12+
import java.io.Serializable;
13+
14+
/**
15+
*
16+
* @author akil
17+
*/
18+
public class ShipmentOverviewFspaSplit implements Serializable {
19+
20+
@JsonView(Views.ReportView.class)
21+
private SimpleCodeObject fspa;
22+
@JsonView(Views.ReportView.class)
23+
private SimpleCodeObject programCountry;
24+
@JsonView(Views.ReportView.class)
25+
private SimpleObject planningUnit;
26+
@JsonView(Views.ReportView.class)
27+
private double quantity;
28+
@JsonView(Views.ReportView.class)
29+
private double cost;
30+
@JsonView(Views.ReportView.class)
31+
private double freightCost;
32+
@JsonView(Views.ReportView.class)
33+
private double perc;
34+
35+
public SimpleCodeObject getFspa() {
36+
return fspa;
37+
}
38+
39+
public void setFspa(SimpleCodeObject fspa) {
40+
this.fspa = fspa;
41+
}
42+
43+
public SimpleCodeObject getProgramCountry() {
44+
return programCountry;
45+
}
46+
47+
public void setProgramCountry(SimpleCodeObject programCountry) {
48+
this.programCountry = programCountry;
49+
}
50+
51+
public SimpleObject getPlanningUnit() {
52+
return planningUnit;
53+
}
54+
55+
public void setPlanningUnit(SimpleObject planningUnit) {
56+
this.planningUnit = planningUnit;
57+
}
58+
59+
public double getQuantity() {
60+
return quantity;
61+
}
62+
63+
public void setQuantity(double quantity) {
64+
this.quantity = quantity;
65+
}
66+
67+
public double getCost() {
68+
return cost;
69+
}
70+
71+
public void setCost(double cost) {
72+
this.cost = cost;
73+
}
74+
75+
public double getFreightCost() {
76+
return freightCost;
77+
}
78+
79+
public void setFreightCost(double freightCost) {
80+
this.freightCost = freightCost;
81+
}
82+
83+
public double getPerc() {
84+
return perc;
85+
}
86+
87+
public void setPerc(double perc) {
88+
this.perc = perc;
89+
}
90+
91+
@JsonView(Views.ReportView.class)
92+
public double getTotalCost() {
93+
return this.freightCost + this.cost;
94+
}
95+
96+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package cc.altius.FASP.model.report;
6+
7+
import cc.altius.FASP.model.SimpleCodeObject;
8+
import cc.altius.FASP.model.SimpleObject;
9+
import cc.altius.FASP.model.rowMapper.LabelRowMapper;
10+
import java.sql.ResultSet;
11+
import java.sql.SQLException;
12+
import org.springframework.jdbc.core.RowMapper;
13+
14+
/**
15+
*
16+
* @author akil
17+
*/
18+
public class ShipmentOverviewFspaSplitRowMapper implements RowMapper<ShipmentOverviewFspaSplit> {
19+
20+
@Override
21+
public ShipmentOverviewFspaSplit mapRow(ResultSet rs, int rowNum) throws SQLException {
22+
ShipmentOverviewFspaSplit item = new ShipmentOverviewFspaSplit();
23+
item.setFspa(new SimpleCodeObject(rs.getInt("FSPA_ID"), new LabelRowMapper("FSPA_").mapRow(rs, rowNum), rs.getString("FSPA_CODE")));
24+
item.setProgramCountry(new SimpleCodeObject(rs.getInt("P_ID"), new LabelRowMapper("P_").mapRow(rs, rowNum), rs.getString("P_CODE")));
25+
item.setPlanningUnit(new SimpleObject(rs.getInt("PU_ID"), new LabelRowMapper("PU_").mapRow(rs, rowNum)));
26+
item.setQuantity(rs.getDouble("SHIPMENT_QTY"));
27+
item.setCost(rs.getDouble("COST"));
28+
item.setFreightCost(rs.getDouble("FREIGHT_COST"));
29+
return item;
30+
}
31+
32+
}

0 commit comments

Comments
 (0)