Skip to content

Commit 6043487

Browse files
committed
Merge branch 'dev' of https://github.com/CCAFS/MARLO.git into dev
2 parents 783fece + 07ac425 commit 6043487

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/FundingSourcesSummaryAction.java

+55-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import org.cgiar.ccafs.marlo.config.APConstants;
2020
import org.cgiar.ccafs.marlo.data.manager.CrpManager;
2121
import org.cgiar.ccafs.marlo.data.manager.CrpProgramManager;
22+
import org.cgiar.ccafs.marlo.data.manager.DeliverableFundingSourceManager;
2223
import org.cgiar.ccafs.marlo.data.manager.ProjectManager;
2324
import org.cgiar.ccafs.marlo.data.model.Crp;
25+
import org.cgiar.ccafs.marlo.data.model.DeliverableFundingSource;
2426
import org.cgiar.ccafs.marlo.data.model.FundingSource;
2527
import org.cgiar.ccafs.marlo.data.model.FundingSourceBudget;
2628
import org.cgiar.ccafs.marlo.data.model.FundingSourceInstitution;
@@ -29,6 +31,7 @@
2931
import org.cgiar.ccafs.marlo.data.model.ProjectBudget;
3032
import org.cgiar.ccafs.marlo.data.model.ProjectClusterActivity;
3133
import org.cgiar.ccafs.marlo.data.model.ProjectFocus;
34+
import org.cgiar.ccafs.marlo.data.model.ProjectStatusEnum;
3235
import org.cgiar.ccafs.marlo.utils.APConfig;
3336

3437
import java.io.ByteArrayInputStream;
@@ -82,6 +85,7 @@ public class FundingSourcesSummaryAction extends BaseAction implements Summary {
8285
private CrpManager crpManager;
8386
private CrpProgramManager programManager;
8487
private ProjectManager projectManager;
88+
private DeliverableFundingSourceManager deliverableFundingSourceManager;
8589

8690
// XLSX bytes
8791
private byte[] bytesXLSX;
@@ -91,11 +95,12 @@ public class FundingSourcesSummaryAction extends BaseAction implements Summary {
9195

9296
@Inject
9397
public FundingSourcesSummaryAction(APConfig config, CrpManager crpManager, CrpProgramManager programManager,
94-
ProjectManager projectManager) {
98+
ProjectManager projectManager, DeliverableFundingSourceManager deliverableFundingSourceManager) {
9599
super(config);
96100
this.crpManager = crpManager;
97101
this.programManager = programManager;
98102
this.projectManager = projectManager;
103+
this.deliverableFundingSourceManager = deliverableFundingSourceManager;
99104
}
100105

101106
@Override
@@ -287,9 +292,9 @@ public String getFundingSourceFileURL() {
287292
private TypedTableModel getFundingSourcesProjectsTableModel() {
288293
TypedTableModel model = new TypedTableModel(
289294
new String[] {"fs_title", "fs_id", "finance_code", "lead_partner", "fs_window", "project_id", "total_budget",
290-
"flagships", "coas"},
295+
"flagships", "coas", "deliverables"},
291296
new Class[] {String.class, Long.class, String.class, String.class, String.class, String.class, Double.class,
292-
String.class, String.class},
297+
String.class, String.class, String.class},
293298
0);
294299

295300
for (FundingSource fundingSource : loggedCrp.getFundingSources().stream()
@@ -304,12 +309,16 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
304309

305310

306311
for (ProjectBudget projectBudget : fundingSource.getProjectBudgets().stream()
307-
.filter(pb -> pb.isActive() && pb.getYear() == year && pb.getProject() != null).collect(Collectors.toList())) {
312+
.filter(pb -> pb.isActive() && pb.getYear() == year && pb.getProject() != null && pb.getProject().isActive()
313+
&& pb.getProject().getStatus() != null
314+
&& pb.getProject().getStatus().intValue() == Integer.parseInt(ProjectStatusEnum.Ongoing.getStatusId()))
315+
.collect(Collectors.toList())) {
308316
String lead_partner = "";
309317
String project_id = "";
310318
Double total_budget = 0.0;
311319
String flagships = null;
312320
String coas = null;
321+
String deliverables = "";
313322

314323
project_id = projectBudget.getProject().getId().toString();
315324
if (project_id != null && !project_id.isEmpty()) {
@@ -325,8 +334,28 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
325334
flagships +=
326335
"\n " + programManager.getCrpProgramById(projectFocuses.getCrpProgram().getId()).getAcronym();
327336
}
328-
}
337+
// get deliverable funding sources
338+
Long projectID = Long.parseLong(project_id);
339+
340+
for (DeliverableFundingSource deliverableFundingSource : this.deliverableFundingSourceManager.findAll()
341+
.stream()
342+
.filter(df -> df.getFundingSource().getId().longValue() == fundingSource.getId().longValue()
343+
&& df.isActive() && df.getDeliverable() != null && df.getDeliverable().isActive()
344+
&& df.getDeliverable().getProject() != null
345+
&& df.getDeliverable().getProject().getId().longValue() == projectID.longValue())
346+
.sorted((df1, df2) -> Long.compare(df1.getDeliverable().getId(), df2.getDeliverable().getId()))
347+
.collect(Collectors.toList())) {
348+
if (deliverables.length() == 0) {
349+
deliverables = "D" + deliverableFundingSource.getDeliverable().getId();
350+
} else {
351+
deliverables += ", D" + deliverableFundingSource.getDeliverable().getId();
352+
}
353+
}
329354

355+
}
356+
if (deliverables.isEmpty()) {
357+
deliverables = null;
358+
}
330359
// get CoAs related to the project sorted by acronym
331360
if (projectBudget.getProject().getProjectClusterActivities() != null) {
332361
for (ProjectClusterActivity projectClusterActivity : projectBudget.getProject()
@@ -348,7 +377,7 @@ private TypedTableModel getFundingSourcesProjectsTableModel() {
348377
total_budget = projectBudget.getAmount();
349378

350379
model.addRow(new Object[] {fs_title, fs_id, finance_code, lead_partner, fs_window, project_id, total_budget,
351-
flagships, coas});
380+
flagships, coas, deliverables});
352381
}
353382

354383
}
@@ -359,10 +388,10 @@ private TypedTableModel getFundingSourcesTableModel() {
359388
TypedTableModel model = new TypedTableModel(
360389
new String[] {"fs_title", "fs_id", "finance_code", "lead_partner", "fs_window", "project_id", "total_budget",
361390
"summary", "start_date", "end_date", "contract", "status", "pi_name", "pi_email", "donor",
362-
"total_budget_projects", "contract_name", "flagships", "coas"},
391+
"total_budget_projects", "contract_name", "flagships", "coas", "deliverables"},
363392
new Class[] {String.class, Long.class, String.class, String.class, String.class, String.class, Double.class,
364393
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
365-
Double.class, String.class, String.class, String.class},
394+
Double.class, String.class, String.class, String.class, String.class},
366395
0);
367396
SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy");
368397

@@ -497,9 +526,26 @@ private TypedTableModel getFundingSourcesTableModel() {
497526
total_budget_projects += projectBudget.getAmount();
498527
}
499528

529+
// get deliverable funding sources
530+
String deliverables = "";
531+
for (DeliverableFundingSource deliverableFundingSource : this.deliverableFundingSourceManager.findAll().stream()
532+
.filter(df -> df.getFundingSource().getId().longValue() == fundingSource.getId().longValue() && df.isActive()
533+
&& df.getDeliverable() != null && df.getDeliverable().isActive() && df.getDeliverable().getProject() != null
534+
&& df.getDeliverable().getProject().isActive())
535+
.sorted((df1, df2) -> Long.compare(df1.getDeliverable().getId(), df2.getDeliverable().getId()))
536+
.collect(Collectors.toList())) {
537+
if (deliverables.length() == 0) {
538+
deliverables = "D" + deliverableFundingSource.getDeliverable().getId();
539+
} else {
540+
deliverables += ", D" + deliverableFundingSource.getDeliverable().getId();
541+
}
542+
}
543+
if (deliverables.isEmpty()) {
544+
deliverables = null;
545+
}
500546
model.addRow(new Object[] {fs_title, fs_id, finance_code, lead_partner, fs_window, project_id, total_budget,
501547
summary, start_date, end_date, contract, status, pi_name, pi_email, donor, total_budget_projects, contract_name,
502-
flagships, coas});
548+
flagships, coas, deliverables});
503549
}
504550
return model;
505551
}
Binary file not shown.
Binary file not shown.

marlo-web/src/main/webapp/js/global/fundingSourcesPopup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ function ajaxService(url,data) {
550550
$select.addOption(e.id, e.name);
551551
});
552552
console.log(data.budgetTypeID);
553-
if(data.budgetTypeID == "1") {
553+
if(data.budgetTypeID == "1" && $select.find("option:selected").val() == "-1") {
554554
$select.val($(".cgiarConsortium").text());
555555
}
556556
$select.trigger("change.select2");

0 commit comments

Comments
 (0)