diff --git a/src/components/UtilityLine/UtilityAccountSummary.js b/src/components/UtilityLine/UtilityAccountSummary.js index 6d4c67c4033fcda3606d0a9592d69b927411636d..e6adb850c947595e770ba6b0336f2fff4fcd3211 100644 --- a/src/components/UtilityLine/UtilityAccountSummary.js +++ b/src/components/UtilityLine/UtilityAccountSummary.js @@ -59,21 +59,27 @@ class UtilityAccountSummary extends Component { }); // Sum each usage - let totals = filterdDisaggregateData.reduce((acc, item) => { - Object.keys(item).forEach((key) => { + let totals = filterdDisaggregateData.reduce((acc, oneBill) => { + Object.keys(oneBill).forEach((key) => { if (!key.includes('date') && key !== 'other' && key !== 'unit_price') { - acc[key] = (acc[key] || 0) + item[key]; - acc[`${key}_cost`] = acc[key] * item.unit_price; - acc.total += item[key]; - acc.total_cost += item[key] * item.unit_price; + acc[key] = (acc[key] || 0) + oneBill[key]; + acc[`${key}_cost`] = acc[key] * oneBill.unit_price; } - }); return acc; }, { total: 0, total_cost: 0 }); + // Sum total usage and total cost + Object.keys(totals).forEach((key) => { + if (!key.includes('cost')) { + totals.total += totals[key]; + } else { + totals.total_cost += totals[key]; + } + }); + // Round all usages totals = Object.keys(totals) .reduce((acc, key) => {