Skip to content

Commit ac71982

Browse files
authored
29718 - Update auth-web transactions to show receipt download button for refunds (#3555)
1 parent 6b73bc6 commit ac71982

File tree

5 files changed

+79
-15
lines changed

5 files changed

+79
-15
lines changed

auth-web/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auth-web",
3-
"version": "2.10.26",
3+
"version": "2.10.27",
44
"appName": "Auth Web",
55
"sbcName": "SBC Common Components",
66
"private": true,

auth-web/src/components/auth/account-settings/transaction/TransactionsDataTable.vue

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@
196196
</template>
197197
<template #item-slot-downloads="{ item }">
198198
<div
199-
v-if="item.statusCode === InvoiceStatus.COMPLETED || item.statusCode === InvoiceStatus.PAID"
199+
v-if="canDownloadReceipt(item, false)"
200200
class="receipt"
201-
@click="downloadReceipt(item)"
201+
@click="downloadReceipt(item, false)"
202202
>
203203
<v-icon
204204
color="primary"
@@ -306,7 +306,16 @@
306306
v-if="isColumnVisible('downloads')"
307307
class="dropdown-cell"
308308
>
309-
<!-- Empty cell for downloads column -->
309+
<div
310+
v-if="canDownloadReceipt(item, true)"
311+
class="receipt"
312+
@click="downloadReceipt(item, true)"
313+
>
314+
<v-icon color="primary">
315+
mdi-file-pdf-outline
316+
</v-icon>
317+
<span>Receipt</span>
318+
</div>
310319
</td>
311320
<td
312321
v-if="isColumnVisible('actions')"
@@ -360,21 +369,50 @@ export default defineComponent({
360369
return props.headers.some(header => header.col === columnName)
361370
}
362371
363-
const getInvoiceStatus = (item: Transaction) => {
372+
const getInvoiceStatusForDisplay = (item: Transaction): InvoiceStatus => {
364373
// Special case for Online Banking - it shouldn't show NSF, should show Pending.
365374
if (item.paymentMethod === PaymentTypes.ONLINE_BANKING &&
366375
item.statusCode === InvoiceStatus.SETTLEMENT_SCHEDULED) {
367-
return invoiceStatusDisplay[InvoiceStatus.PENDING]
376+
return InvoiceStatus.PENDING
368377
}
369378
// Check for partial refunds - this should take priority
370379
if (item.partialRefunds?.length > 0) {
371380
if ([PaymentTypes.ONLINE_BANKING, PaymentTypes.PAD].includes(item.paymentMethod)) {
372-
return invoiceStatusDisplay[InvoiceStatus.PARTIALLY_CREDITED]
381+
return InvoiceStatus.PARTIALLY_CREDITED
373382
} else {
374-
return invoiceStatusDisplay[InvoiceStatus.PARTIALLY_REFUNDED]
383+
return InvoiceStatus.PARTIALLY_REFUNDED
375384
}
376385
}
377-
return invoiceStatusDisplay[item.statusCode]
386+
return item.statusCode
387+
}
388+
389+
const getInvoiceStatus = (item: Transaction) => {
390+
return invoiceStatusDisplay[getInvoiceStatusForDisplay(item)]
391+
}
392+
393+
const refundStatus = new Set<InvoiceStatus>([
394+
InvoiceStatus.CREDITED,
395+
InvoiceStatus.REFUNDED,
396+
InvoiceStatus.PARTIALLY_REFUNDED,
397+
InvoiceStatus.PARTIALLY_CREDITED
398+
])
399+
400+
const paidStatus = new Set<InvoiceStatus>([
401+
InvoiceStatus.COMPLETED,
402+
InvoiceStatus.PAID
403+
])
404+
405+
const canDownloadReceipt = (
406+
item: Transaction,
407+
expandRow: boolean = false
408+
): boolean => {
409+
const status = getInvoiceStatusForDisplay(item)
410+
411+
if (refundStatus.has(status)) {
412+
return true
413+
}
414+
415+
return !expandRow && paidStatus.has(status)
378416
}
379417
380418
const hasDropdownContent = (item: Transaction): boolean => {
@@ -615,10 +653,10 @@ export default defineComponent({
615653
}
616654
})
617655
618-
async function downloadReceipt (item: Transaction) {
656+
async function downloadReceipt (item: Transaction, isRefund: boolean = false) {
619657
emit('isDownloadingReceipt', true)
620658
const currentAccount = JSON.parse(ConfigHelper.getFromSession(SessionStorageKeys.CurrentAccount || '{}'))
621-
const receipt = await PaymentService.postReceipt(item, currentAccount.id)
659+
const receipt = await PaymentService.postReceipt(item, currentAccount.id, isRefund)
622660
const filename = `bcregistry-receipts-${item.id}.pdf`
623661
CommonUtils.fileDownload(receipt.data, filename, 'application/pdf')
624662
emit('isDownloadingReceipt', false)
@@ -676,6 +714,7 @@ export default defineComponent({
676714
loadTransactionList,
677715
getInvoiceStatus,
678716
datePickerValue,
717+
canDownloadReceipt,
679718
downloadReceipt
680719
}
681720
}

auth-web/src/services/payment.services.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ export default class PaymentService {
4444
)
4545
}
4646

47-
static postReceipt (invoice: any, accountId: string): AxiosPromise<any> {
47+
static postReceipt (invoice: any, accountId: string, isRefund: boolean = false): AxiosPromise<any> {
4848
const url = `${ConfigHelper.getPayAPIURL()}/payment-requests/${invoice.id}/receipts`
4949
const headers = {
5050
'Accept': 'application/pdf',
5151
'Account-Id': accountId
5252
}
5353
const body = {
54-
filingDateTime: CommonUtils.formatDateToHumanReadable(invoice.createdOn)
54+
filingDateTime: CommonUtils.formatDateToHumanReadable(invoice.createdOn),
55+
isRefund: isRefund
5556
}
5657
return axios.post(url, body, { headers, responseType: 'blob' as 'json' })
5758
}

auth-web/tests/unit/components/TransactionsDataTable.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,28 @@ describe('TransactionsDataTable tests', () => {
432432
expect(partialCreditItem.type).toBe('Refund as credits')
433433
expect(partialCreditItem.status).toBe('Partially Credited')
434434
})
435+
436+
it('canDownloadReceipt - should handle expandRow parameter correctly', async () => {
437+
const paidTransaction = createTestTransaction({
438+
statusCode: InvoiceStatus.PAID,
439+
paymentMethod: PaymentTypes.DIRECT_PAY
440+
})
441+
expect(wrapper.vm.canDownloadReceipt(paidTransaction, false)).toBe(true)
442+
expect(wrapper.vm.canDownloadReceipt(paidTransaction, true)).toBe(false)
443+
444+
const partiallyRefundedTransaction = createTestTransaction({
445+
statusCode: InvoiceStatus.PAID,
446+
paymentMethod: PaymentTypes.DIRECT_PAY,
447+
partialRefunds: [createPartialRefund({ refundAmount: 50 })]
448+
})
449+
expect(wrapper.vm.canDownloadReceipt(partiallyRefundedTransaction, false)).toBe(true)
450+
expect(wrapper.vm.canDownloadReceipt(partiallyRefundedTransaction, true)).toBe(true)
451+
452+
const creditedTransaction = createTestTransaction({
453+
statusCode: InvoiceStatus.CREDITED,
454+
paymentMethod: PaymentTypes.PAD
455+
})
456+
expect(wrapper.vm.canDownloadReceipt(creditedTransaction, false)).toBe(true)
457+
expect(wrapper.vm.canDownloadReceipt(creditedTransaction, true)).toBe(true)
458+
})
435459
})

0 commit comments

Comments
 (0)