Skip to content

Commit bc7b505

Browse files
authored
ofmcc 7380 updates to funding allocation table, to handle multiple line items (#506)
* updates to funding allocation table, to handle multiple line items per row * updates to check for unique values * removed a var
1 parent 529d52c commit bc7b505

File tree

5 files changed

+116
-11
lines changed

5 files changed

+116
-11
lines changed

backend/src/components/fundingAgreements.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { MappableObjectForFront, MappableObjectForBack } = require('../util/mappi
44
const { buildDateFilterQuery, buildFilterQuery } = require('../util/common')
55
const { getTopUpFundingByFilter } = require('./topups')
66
const { TOP_UP_FUNDING_STATUS_CODES } = require('../util/constants')
7-
const { FundingAgreementMappings, FundingReallocationRequestMappings } = require('../util/mapping/Mappings')
7+
const { FundingAgreementMappings, FundingReallocationRequestMappings, FundingAllocationChangeMappings } = require('../util/mapping/Mappings')
88
const { FUNDING_AGREEMENT_STATUS_CODES, FUNDING_AGREEMENT_STATE_CODES } = require('../util/constants')
99
const HttpStatus = require('http-status-codes')
1010
const log = require('./logger')
@@ -107,11 +107,16 @@ async function updateFundingAgreement(req, res) {
107107

108108
async function getFundingReallocationRequests(req, res) {
109109
try {
110-
const fundingReallocationRequests = []
111-
const operation = `ofm_funding_envelope_changes?$select=ofm_funding_envelope_changeid,_ofm_funding_value,ofm_funding_envelope_from,ofm_funding_envelope_to,ofm_amount_base,createdon,statuscode
112-
&$filter=(_ofm_funding_value eq ${req?.params?.fundingAgreementId})&pageSize=500`
110+
const operation = `ofm_funding_envelope_changes?$select=ofm_funding_envelope_changeid,_ofm_funding_value,ofm_funding_envelope_from,ofm_funding_envelope_to,ofm_amount_base,createdon,statuscode&$filter=(_ofm_funding_value eq ${req?.params?.fundingAgreementId})&$expand=ofm_funding_allocation_envelope_change($select=ofm_funding_envelope_from,ofm_funding_envelope_to,ofm_amount_base)&pageSize=500`
113111
const response = await getOperation(operation)
114-
response?.value?.forEach((reallocationRequest) => fundingReallocationRequests.push(new MappableObjectForFront(reallocationRequest, FundingReallocationRequestMappings).toJSON()))
112+
113+
const fundingReallocationRequests = response?.value.map((reallocationRequest) => {
114+
const fundingAllocations = reallocationRequest.ofm_funding_allocation_envelope_change?.map((allocation) => new MappableObjectForFront(allocation, FundingAllocationChangeMappings).toJSON())
115+
const fundingRequest = new MappableObjectForFront(reallocationRequest, FundingReallocationRequestMappings).toJSON()
116+
fundingRequest.fundingAllocations = fundingAllocations
117+
return fundingRequest
118+
})
119+
115120
return res.status(HttpStatus.OK).json(fundingReallocationRequests)
116121
} catch (e) {
117122
handleError(res, e)

backend/src/util/mapping/Mappings.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,18 @@ const FundingAgreementMappings = [
362362
const FundingReallocationRequestMappings = [
363363
{ back: 'ofm_funding_envelope_changeid', front: 'fundingEnvelopeId' },
364364
{ back: '_ofm_funding_value', front: 'fundingId' },
365+
{ back: 'createdon', front: 'date' },
366+
{ back: 'statuscode', front: 'statusCode' },
367+
{ back: 'statuscode@OData.Community.Display.V1.FormattedValue', front: 'statusName' },
368+
]
369+
370+
const FundingAllocationChangeMappings = [
371+
{ back: 'ofm_funding_allocationid', front: 'fundingAllocationId' },
365372
{ back: 'ofm_funding_envelope_from', front: 'envelopeCodeFrom' },
366373
{ back: 'ofm_funding_envelope_from@OData.Community.Display.V1.FormattedValue', front: 'envelopeNameFrom' },
367374
{ back: 'ofm_funding_envelope_to', front: 'envelopeCodeTo' },
368375
{ back: 'ofm_funding_envelope_to@OData.Community.Display.V1.FormattedValue', front: 'envelopeNameTo' },
369376
{ back: 'ofm_amount_base', front: 'amount' },
370-
{ back: 'createdon', front: 'date' },
371-
{ back: 'statuscode', front: 'statusCode' },
372-
{ back: 'statuscode@OData.Community.Display.V1.FormattedValue', front: 'statusName' },
373377
]
374378

375379
const PaymentMappings = [
@@ -564,4 +568,5 @@ module.exports = {
564568
UserProfileOrganizationMappings,
565569
IrregularExpenseMappings,
566570
TopUpMappings,
571+
FundingAllocationChangeMappings,
567572
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<template>
2+
<v-container>
3+
<AppDialog v-model="isDisplayed" title="Funding Re-allocation Request Details" persistent max-width="60%" @close="closeDialog">
4+
<template #content>
5+
<v-data-table :headers="fundingRequestsHeaders" :items="allocations" item-key="fundingAllocationId" density="compact" class="soft-outline" :hide-default-footer="true">
6+
<template #[`item.amount`]="{ item }">$ {{ format.formatDecimalNumber(item?.amount) }}</template>
7+
</v-data-table>
8+
</template>
9+
<template #button>
10+
<v-row justify="space-around">
11+
<v-col cols="12" md="6" class="d-flex justify-center">
12+
<AppButton id="dialog-go-back" :primary="false" size="large" width="300px" @click="closeDialog">Back to Summary</AppButton>
13+
</v-col>
14+
</v-row>
15+
</template>
16+
</AppDialog>
17+
</v-container>
18+
</template>
19+
20+
<script>
21+
import AppButton from '@/components/ui/AppButton.vue'
22+
import AppDialog from '@/components/ui/AppDialog.vue'
23+
import format from '@/utils/format'
24+
25+
export default {
26+
name: 'FundingAllocationPopup',
27+
components: { AppButton, AppDialog },
28+
props: {
29+
show: {
30+
type: Boolean,
31+
default: false,
32+
},
33+
allocations: {
34+
type: Array,
35+
default: () => [],
36+
},
37+
},
38+
emits: ['close'],
39+
data() {
40+
return {
41+
isDisplayed: false,
42+
fundingRequestsHeaders: [
43+
{ title: 'From', key: 'envelopeNameFrom' },
44+
{ title: 'To', key: 'envelopeNameTo' },
45+
{ title: 'Amount', key: 'amount', align: 'end' },
46+
],
47+
}
48+
},
49+
watch: {
50+
show: {
51+
handler(value) {
52+
this.isDisplayed = value
53+
},
54+
},
55+
},
56+
created() {
57+
this.format = format
58+
},
59+
methods: {
60+
closeDialog() {
61+
this.$emit('close')
62+
},
63+
},
64+
}
65+
</script>

frontend/src/components/funding/FundingReallocationRequestsTable.vue

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,40 @@
1616
<template #no-data>
1717
<span v-if="isEmpty(fundingReallocationRequests)">The selected facility has not submitted a funding re-allocation request.</span>
1818
</template>
19+
1920
<template #[`item.date`]="{ item }">
2021
{{ format.formatDate(item?.date) }}
2122
</template>
22-
<template #[`item.amount`]="{ item }">$ {{ format.formatDecimalNumber(item?.amount) }}</template>
23+
<template #[`item.envelopeNameFrom`]="{ item }">{{ getEnvelopeName(item.fundingAllocations, 'envelopeNameFrom') }}</template>
24+
<template #[`item.envelopeNameTo`]="{ item }">{{ getEnvelopeName(item.fundingAllocations, 'envelopeNameTo') }}</template>
25+
<template #[`item.amount`]="{ item }">$ {{ sumAmounts(item) }}</template>
2326
<template #[`item.statusCode`]="{ item }">
2427
<div class="min-width-column">
2528
<span :class="getStatusClass(item?.statusCode)">{{ item?.statusName }}</span>
2629
</div>
2730
</template>
31+
<template #[`item.fundingAllocations`]="{ item }">
32+
<div class="min-width-column">
33+
<AppButton :primary="false" size="small" @click="toggleDialog(item?.fundingAllocations)">View</AppButton>
34+
</div>
35+
</template>
2836
</v-data-table>
2937
</v-skeleton-loader>
38+
<FundingAllocationPopup :allocations="activeAllocations" :show="showDialog" @close="toggleDialog()"></FundingAllocationPopup>
3039
</v-container>
3140
</template>
3241

3342
<script>
43+
import AppButton from '@/components/ui/AppButton.vue'
3444
import { isEmpty } from 'lodash'
3545
import StatusFilter from '@/components/funding/StatusFilter.vue'
3646
import { FUNDING_REALLOCATION_REQUEST_STATUS_CODES } from '@/utils/constants'
3747
import format from '@/utils/format'
48+
import FundingAllocationPopup from '@/components/funding/FundingAllocationPopup.vue'
3849
3950
export default {
4051
name: 'FundingReallocationRequestsTable',
41-
components: { StatusFilter },
52+
components: { AppButton, FundingAllocationPopup, StatusFilter },
4253
props: {
4354
loading: {
4455
type: Boolean,
@@ -55,10 +66,13 @@ export default {
5566
{ title: 'Date', key: 'date' },
5667
{ title: 'From', key: 'envelopeNameFrom' },
5768
{ title: 'To', key: 'envelopeNameTo' },
58-
{ title: 'Amount', key: 'amount' },
69+
{ title: 'Amount', key: 'amount', align: 'end' },
5970
{ title: 'Status', key: 'statusCode' },
71+
{ title: 'Actions', key: 'fundingAllocations' },
6072
],
6173
statusFilter: null,
74+
showDialog: false,
75+
activeAllocations: undefined,
6276
}
6377
},
6478
computed: {
@@ -90,6 +104,21 @@ export default {
90104
statusFilterChanged(newVal) {
91105
this.statusFilter = newVal
92106
},
107+
sumAmounts(allocationRequest) {
108+
//ofmcc 7380- allocation requests can have multiple line items with dollar values. The table updates need to show the value of all line items together in the table.
109+
return format.formatDecimalNumber(allocationRequest.fundingAllocations.reduce((acc, curr) => acc + (Number(curr.amount) || 0), 0))
110+
},
111+
toggleDialog(allocations = []) {
112+
this.showDialog = !this.showDialog
113+
this.activeAllocations = allocations
114+
},
115+
getEnvelopeName(allocations, key) {
116+
if (!allocations?.length) return ''
117+
118+
const uniqueNames = [...new Set(allocations.map((allocation) => allocation[key]))]
119+
120+
return uniqueNames.length === 1 ? uniqueNames[0] : 'Multiple'
121+
},
93122
},
94123
}
95124
</script>

frontend/src/utils/format.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function formatBooleanToYesNo(value) {
1919

2020
function formatDate(date) {
2121
if (!date) return BLANK_FIELD
22+
//jb- I think we should remove .utc from here?
2223
return moment.utc(date).format('YYYY-MMM-DD')
2324
}
2425

0 commit comments

Comments
 (0)