Skip to content

Commit

Permalink
fix: show time cycle negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Aug 8, 2023
1 parent 06c7c68 commit b5f36d7
Showing 1 changed file with 139 additions and 146 deletions.
285 changes: 139 additions & 146 deletions src/controllers/disbursements.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class DisbursementsController {
_.get(item, TimeCycleFieldsMapping.disbursed, 0),
10,
);
if (value) {
if (!isNaN(value)) {
const name = _.get(item, TimeCycleFieldsMapping.component, '');
const prevYearComponent = _.get(
data,
Expand All @@ -244,35 +244,33 @@ export class DisbursementsController {
);
const disbursed = _.sumBy(yearComponents, 'disbursed');
const cumulative = _.sumBy(yearComponents, 'cumulative');
if (disbursed > 0) {
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
}
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
});
return {
count: data.length,
Expand Down Expand Up @@ -359,35 +357,33 @@ export class DisbursementsController {
});
const disbursed = _.sumBy(yearComponents, 'disbursed');
const cumulative = _.sumBy(yearComponents, 'cumulative');
if (disbursed > 0) {
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
}
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
});
return {
count: data.length,
Expand Down Expand Up @@ -468,35 +464,34 @@ export class DisbursementsController {
});
const disbursed = _.sumBy(yearComponents, 'disbursed');
const cumulative = _.sumBy(yearComponents, 'cumulative');
if (disbursed > 0) {
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
}

data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
});
return {
count: data.length,
Expand Down Expand Up @@ -3090,35 +3085,34 @@ export class DisbursementsController {
});
const disbursed = _.sumBy(yearComponents, 'disbursed');
const cumulative = _.sumBy(yearComponents, 'cumulative');
if (disbursed > 0) {
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
GrantDetailTimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
GrantDetailTimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
}

data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
GrantDetailTimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
GrantDetailTimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
});
return {
count: data.length,
Expand Down Expand Up @@ -3207,35 +3201,34 @@ export class DisbursementsController {
});
const disbursed = _.sumBy(yearComponents, 'disbursed');
const cumulative = _.sumBy(yearComponents, 'cumulative');
if (disbursed > 0) {
data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
}

data.push({
year,
disbursed,
cumulative,
disbursedChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.disbursed,
}),
),
cumulativeChildren: _.orderBy(yearComponents, 'name', 'asc').map(
(yc: any) => ({
name: yc.name,
color: _.get(
TimeCycleFieldsMapping.componentColors,
yc.name,
'',
),
value: yc.cumulative,
}),
),
});
});
return {
count: data.length,
Expand Down

0 comments on commit b5f36d7

Please sign in to comment.