Skip to content

Commit eba2623

Browse files
Merge branch 'dev'
2 parents 8b72098 + e32db1c commit eba2623

17 files changed

Lines changed: 372 additions & 110 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>cc.altius.FASP.rest.webservice</groupId>
1212
<artifactId>FASP</artifactId>
13-
<version>2.120[5733]</version>
13+
<version>2.121[5745]</version>
1414
<name>QAT</name>
1515
<description>Quantification Analytics Tool</description>
1616
<packaging>jar</packaging>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import cc.altius.FASP.model.rowMapper.StockAdjustmentReportOutputRowMapper;
114114
import cc.altius.FASP.service.AclService;
115115
import cc.altius.FASP.utils.ArrayUtils;
116+
import cc.altius.FASP.utils.LogUtils;
116117
import java.util.Date;
117118
import java.util.HashMap;
118119
import java.util.LinkedList;
@@ -179,11 +180,12 @@ public List<GlobalConsumptionOutput> getGlobalConsumption(GlobalConsumptionInput
179180
params.put("stopDate", gc.getStopDate());
180181
params.put("realmCountryIds", gc.getRealmCountryIdString());
181182
params.put("programIds", gc.getProgramIdString());
183+
params.put("versionId", gc.getVersionId());
184+
params.put("equivalencyUnitId", gc.getEquivalencyUnitId());
182185
params.put("planningUnitIds", gc.getPlanningUnitIdString());
183-
params.put("reportView", gc.getReportView());
184-
params.put("approvedSupplyPlanOnly", gc.isUseApprovedSupplyPlanOnly());
186+
params.put("viewBy", gc.getViewBy());
185187
params.put("curUser", curUser.getUserId());
186-
return this.namedParameterJdbcTemplate.query("CALL globalConsumption(:curUser, :realmId, :realmCountryIds, :programIds, :planningUnitIds, :startDate, :stopDate, :reportView, :approvedSupplyPlanOnly)", params, new GlobalConsumptionOutputResultSetExtractor());
188+
return this.namedParameterJdbcTemplate.query("CALL globalConsumption(:curUser, :realmId, :realmCountryIds, :equivalencyUnitId, :programIds, :planningUnitIds, :startDate, :stopDate, :viewBy, :versionId)", params, new GlobalConsumptionOutputResultSetExtractor());
187189
}
188190

189191
// Report no 4

src/main/java/cc/altius/FASP/model/report/CountryConsumptionData.java renamed to src/main/java/cc/altius/FASP/model/report/CountryOrProgramConsumptionData.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
*
1515
* @author akil
1616
*/
17-
public class CountryConsumptionData implements Serializable {
17+
public class CountryOrProgramConsumptionData implements Serializable {
1818

19-
public CountryConsumptionData(SimpleCodeObject country, double forecastedConsumption, double actualConsumption) {
20-
this.country = country;
19+
public CountryOrProgramConsumptionData(SimpleCodeObject label, double forecastedConsumption, double actualConsumption) {
20+
this.label = label;
2121
this.forecastedConsumption = forecastedConsumption;
2222
this.actualConsumption = actualConsumption;
2323
}
24-
24+
2525
@JsonView(Views.ReportView.class)
26-
SimpleCodeObject country;
26+
SimpleCodeObject label;
2727
@JsonView(Views.ReportView.class)
2828
double forecastedConsumption;
2929
@JsonView(Views.ReportView.class)
@@ -45,12 +45,12 @@ public void setActualConsumption(double actualConsumption) {
4545
this.actualConsumption = actualConsumption;
4646
}
4747

48-
public SimpleCodeObject getCountry() {
49-
return country;
48+
public SimpleCodeObject getLabel() {
49+
return label;
5050
}
5151

52-
public void setCountry(SimpleCodeObject country) {
53-
this.country = country;
52+
public void setLabel(SimpleCodeObject label) {
53+
this.label = label;
5454
}
5555

5656
}

src/main/java/cc/altius/FASP/model/report/GlobalConsumptionInput.java

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ public class GlobalConsumptionInput {
2020
private int realmId;
2121
private String[] realmCountryIds;
2222
private String[] programIds;
23-
private String[] planningUnitIds;
23+
private int versionId; // If a Single Program is selected then versionId is relevant. When Multiple Programs are selected this should be 0. If single program is selected then cannot be 0. -1 for latest versionId
24+
private int equivalencyUnitId; // 0 if not selected or then value if selected
25+
private String[] planningUnitIds; // Use list of PU's if an EquivalencyUnit is provided, if no equivalencyUnitId is selected then only use the first PU from the list
2426
@JsonDeserialize(using = JsonDateDeserializer.class)
2527
@JsonSerialize(using = JsonDateSerializer.class)
2628
private Date startDate;
2729
@JsonDeserialize(using = JsonDateDeserializer.class)
2830
@JsonSerialize(using = JsonDateSerializer.class)
2931
private Date stopDate;
30-
private int reportView; // 1 = Planning Unit, 2 = Forecasting Unit
31-
private boolean useApprovedSupplyPlanOnly;
32+
private int viewBy; // View by Country = 1, View by Program = 2
3233

3334
public int getRealmId() {
3435
return realmId;
@@ -38,7 +39,6 @@ public void setRealmId(int realmId) {
3839
this.realmId = realmId;
3940
}
4041

41-
4242
public String[] getRealmCountryIds() {
4343
return realmCountryIds;
4444
}
@@ -55,6 +55,22 @@ public void setProgramIds(String[] programIds) {
5555
this.programIds = programIds;
5656
}
5757

58+
public int getVersionId() {
59+
return versionId;
60+
}
61+
62+
public void setVersionId(int versionId) {
63+
this.versionId = versionId;
64+
}
65+
66+
public int getEquivalencyUnitId() {
67+
return equivalencyUnitId;
68+
}
69+
70+
public void setEquivalencyUnitId(int equivalencyUnitId) {
71+
this.equivalencyUnitId = equivalencyUnitId;
72+
}
73+
5874
public String[] getPlanningUnitIds() {
5975
return planningUnitIds;
6076
}
@@ -79,59 +95,49 @@ public void setStopDate(Date stopDate) {
7995
this.stopDate = stopDate;
8096
}
8197

82-
public int getReportView() {
83-
return reportView;
84-
}
85-
86-
public void setReportView(int reportView) {
87-
this.reportView = reportView;
98+
public int getViewBy() {
99+
return viewBy;
88100
}
89101

90-
public boolean isUseApprovedSupplyPlanOnly() {
91-
return useApprovedSupplyPlanOnly;
92-
}
93-
94-
public void setUseApprovedSupplyPlanOnly(boolean useApprovedSupplyPlanOnly) {
95-
this.useApprovedSupplyPlanOnly = useApprovedSupplyPlanOnly;
102+
public void setViewBy(int viewBy) {
103+
this.viewBy = viewBy;
96104
}
97105

98106
public String getRealmCountryIdString() {
99107
if (this.realmCountryIds == null) {
100108
return "";
101109
} else {
102-
String opt = String.join("','", this.realmCountryIds);
103-
if (this.realmCountryIds.length > 0) {
104-
return "'" + opt + "'";
105-
} else {
106-
return opt;
107-
}
110+
return String.join(",", this.realmCountryIds);
108111
}
109112
}
110113

111114
public String getProgramIdString() {
112115
if (this.programIds == null) {
113116
return "";
114117
} else {
115-
String opt = String.join("','", this.programIds);
116-
if (this.programIds.length > 0) {
117-
return "'" + opt + "'";
118-
} else {
119-
return opt;
120-
}
118+
return String.join(",", this.programIds);
121119
}
122120
}
123121

124122
public String getPlanningUnitIdString() {
125123
if (this.planningUnitIds == null) {
126124
return "";
127125
} else {
128-
String opt = String.join("','", this.planningUnitIds);
129-
if (this.planningUnitIds.length > 0) {
130-
return "'" + opt + "'";
126+
if (isEquivalencyUnitSelected()) {
127+
return String.join(",", this.planningUnitIds);
131128
} else {
132-
return opt;
129+
return this.planningUnitIds[0].toString();
133130
}
134131
}
135132
}
136133

134+
public boolean isEquivalencyUnitSelected() {
135+
return this.equivalencyUnitId != 0;
136+
}
137+
138+
@Override
139+
public String toString() {
140+
return "GlobalConsumptionInput{" + "realmId=" + realmId + ", realmCountryIds=" + getRealmCountryIdString() + ", programIds=" + getProgramIdString() + ", equivalencyUnitId=" + equivalencyUnitId + ", planningUnitIds=" + getPlanningUnitIdString() + ", startDate=" + startDate + ", stopDate=" + stopDate + ", viewBy=" + viewBy + '}';
141+
}
142+
137143
}

src/main/java/cc/altius/FASP/model/report/GlobalConsumptionOutput.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public class GlobalConsumptionOutput implements Serializable {
2828
@JsonSerialize(using = JsonDateSerializer.class)
2929
Date transDate;
3030
@JsonView(Views.ReportView.class)
31-
Map<String, CountryConsumptionData> countryConsumption;
31+
Map<String, CountryOrProgramConsumptionData> consumption;
3232

3333
public GlobalConsumptionOutput() {
34-
countryConsumption = new HashMap<>();
34+
consumption = new HashMap<>();
3535
}
3636

3737
public Date getTransDate() {
@@ -42,20 +42,20 @@ public void setTransDate(Date transDate) {
4242
this.transDate = transDate;
4343
}
4444

45-
public Map<String, CountryConsumptionData> getCountryConsumption() {
46-
return countryConsumption;
45+
public Map<String, CountryOrProgramConsumptionData> getConsumption() {
46+
return consumption;
4747
}
4848

49-
public void setCountryConsumption(Map<String, CountryConsumptionData> countryConsumption) {
50-
this.countryConsumption = countryConsumption;
49+
public void setConsumption(Map<String, CountryOrProgramConsumptionData> consumption) {
50+
this.consumption = consumption;
5151
}
5252

5353
public double getTotalForecastedConsumption() {
54-
return this.countryConsumption.values().stream().map(x -> x.getForecastedConsumption()).reduce((double)0.0, Double::sum);
54+
return this.consumption.values().stream().map(x -> x.getForecastedConsumption()).reduce((double)0.0, Double::sum);
5555
}
5656

5757
public double getTotalActualConsumption() {
58-
return this.countryConsumption.values().stream().map(x -> x.getActualConsumption()).reduce((double)0.0, Double::sum);
58+
return this.consumption.values().stream().map(x -> x.getActualConsumption()).reduce((double)0.0, Double::sum);
5959
}
6060

6161
public double getTotalConsumption() {

src/main/java/cc/altius/FASP/model/report/GlobalConsumptionOutputResultSetExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public List<GlobalConsumptionOutput> extractData(ResultSet rs) throws SQLExcepti
3535
} else {
3636
gc = gcoList.get(idx);
3737
}
38-
gc.getCountryConsumption().put(rs.getString("COUNTRY_CODE"),
39-
new CountryConsumptionData(
40-
new SimpleCodeObject(rs.getInt("REALM_COUNTRY_ID"), new LabelRowMapper("COUNTRY_").mapRow(rs, 1), rs.getString("COUNTRY_CODE")),
38+
gc.getConsumption().put(rs.getString("CODE"),
39+
new CountryOrProgramConsumptionData(
40+
new SimpleCodeObject(rs.getInt("ID"), new LabelRowMapper("").mapRow(rs, 1), rs.getString("CODE")),
4141
rs.getDouble("FORECASTED_CONSUMPTION"),
4242
rs.getDouble("ACTUAL_CONSUMPTION")
4343
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.SimpleObject;
8+
import cc.altius.FASP.model.Views;
9+
import com.fasterxml.jackson.annotation.JsonView;
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
*
15+
* @author akil
16+
*/
17+
public class GlobalConsumptionOutputWrapper implements Serializable {
18+
19+
@JsonView(Views.ReportView.class)
20+
private SimpleObject product;
21+
@JsonView(Views.ReportView.class)
22+
private List<GlobalConsumptionOutput> dataList;
23+
24+
public GlobalConsumptionOutputWrapper(SimpleObject product, List<GlobalConsumptionOutput> dataList) {
25+
this.product = product;
26+
this.dataList = dataList;
27+
}
28+
29+
public SimpleObject getProduct() {
30+
return product;
31+
}
32+
33+
public void setProduct(SimpleObject product) {
34+
this.product = product;
35+
}
36+
37+
public List<GlobalConsumptionOutput> getDataList() {
38+
return dataList;
39+
}
40+
41+
public void setDataList(List<GlobalConsumptionOutput> dataList) {
42+
this.dataList = dataList;
43+
}
44+
45+
}

src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,26 @@ public ResponseEntity getConsumptionForecastVsActual(@RequestBody ConsumptionFor
209209
/**
210210
* <pre>
211211
* Sample JSON
212-
* { "realmId": 1, "realmCountryIds": [5,51], "programIds": [2028,2029,2535], "planningUnitIds": [778,2692], "startDate": "2019-01-01", "stopDate": "2019-12-01", "reportView": 1, "useApprovedSupplyPlanOnly":0}
212+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [2535],"versionId":-1,"equivalencyUnitId": 1,"planningUnitIds": [2735,2733,2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
213+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [2535],"versionId":148,"equivalencyUnitId": 1,"planningUnitIds": [2735,2733,2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
214+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [2535,2512,2570],"versionId":0,"equivalencyUnitId": 1,"planningUnitIds": [2735,2733,2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
215+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 1,"planningUnitIds": [2735,2733,2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
216+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 1,"planningUnitIds": [2735,2733,2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 2}
217+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2735],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
218+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2733],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
219+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 1}
220+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2735],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 2}
221+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2733],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 2}
222+
* {"realmId": 1,"realmCountryIds": [5,50,51],"programIds": [],"versionId":0,"equivalencyUnitId": 0,"planningUnitIds": [2731],"startDate": "2025-01-01","stopDate": "2025-12-01","viewBy": 2}
213223
* -- realmId must be a valid realm that you want to run this Global report for
214224
* -- RealmCountryIds is the list of Countries that you want to run the report for. Empty means all Countries
215225
* -- ProgramIds is the list of Programs that you want to run the report for. Empty means all Programs
216-
* -- PlanningUnitIds is the list of PlanningUnits that you want to run the report for. Empty means all Planning Units
226+
* -- VersionId should be 0 when Multiple Programs are selected. VersionId will be picked only when Single Program is selected. -1 to get the latest Version of that Program
227+
* -- EquivalencyUnitId is the list of EquivalencyUnit that you want to view the output in terms of. 0 Means not selected and Positive integer value means selected
228+
* -- PlanningUnitIds is the list of PlanningUnits that you want to run the report for (Single select if EquivalencyUnitId=0, Multi-select only if Equivalency Unit Id is selected)
217229
* -- startDate and stopDate are the range between which you want to run the report for`
218-
* -- reportView = 1 shows the Consumption in PlanningUnits
219-
* -- reportView = 2 shows the Consumption in ForecastingUnits
230+
* -- viewBy = 1 shows the report in terms of Country
231+
* -- viewBy = 2 shows the report in terms of Program
220232
* </pre>
221233
*
222234
* @param gci

src/main/java/cc/altius/FASP/service/ReportService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import cc.altius.FASP.model.report.DropdownsForStockStatusVerticalOutput;
1919
import cc.altius.FASP.model.report.ExpiredStockInput;
2020
import cc.altius.FASP.model.report.ExpiredStockOutput;
21-
import cc.altius.FASP.model.report.ForecastErrorInput;
2221
import cc.altius.FASP.model.report.ForecastErrorInputNew;
2322
import cc.altius.FASP.model.report.ForecastErrorOutput;
2423
import cc.altius.FASP.model.report.ForecastMetricsComparisionInput;
@@ -30,7 +29,7 @@
3029
import cc.altius.FASP.model.report.FundingSourceShipmentReportInput;
3130
import cc.altius.FASP.model.report.FundingSourceShipmentReportOutput;
3231
import cc.altius.FASP.model.report.GlobalConsumptionInput;
33-
import cc.altius.FASP.model.report.GlobalConsumptionOutput;
32+
import cc.altius.FASP.model.report.GlobalConsumptionOutputWrapper;
3433
import cc.altius.FASP.model.report.InventoryTurnsInput;
3534
import cc.altius.FASP.model.report.InventoryTurnsOutput;
3635
import cc.altius.FASP.model.report.MonthlyForecastInput;
@@ -84,7 +83,7 @@ public interface ReportService {
8483
public List<ConsumptionForecastVsActualOutput> getConsumptionForecastVsActual(ConsumptionForecastVsActualInput cfa, CustomUserDetails curUser) throws AccessControlFailedException;
8584

8685
// Report no 3
87-
public List<GlobalConsumptionOutput> getGlobalConsumption(GlobalConsumptionInput gci, CustomUserDetails curUser) throws AccessControlFailedException;
86+
public GlobalConsumptionOutputWrapper getGlobalConsumption(GlobalConsumptionInput gci, CustomUserDetails curUser) throws AccessControlFailedException;
8887

8988
// Report no 4
9089
public List<ForecastMetricsMonthlyOutput> getForecastMetricsMonthly(ForecastMetricsMonthlyInput fmi, CustomUserDetails curUser) throws AccessControlFailedException;

0 commit comments

Comments
 (0)