|
196 | 196 | </template> |
197 | 197 | <template #item-slot-downloads="{ item }"> |
198 | 198 | <div |
199 | | - v-if="item.statusCode === InvoiceStatus.COMPLETED || item.statusCode === InvoiceStatus.PAID" |
| 199 | + v-if="canDownloadReceipt(item, false)" |
200 | 200 | class="receipt" |
201 | | - @click="downloadReceipt(item)" |
| 201 | + @click="downloadReceipt(item, false)" |
202 | 202 | > |
203 | 203 | <v-icon |
204 | 204 | color="primary" |
|
306 | 306 | v-if="isColumnVisible('downloads')" |
307 | 307 | class="dropdown-cell" |
308 | 308 | > |
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> |
310 | 319 | </td> |
311 | 320 | <td |
312 | 321 | v-if="isColumnVisible('actions')" |
@@ -360,21 +369,50 @@ export default defineComponent({ |
360 | 369 | return props.headers.some(header => header.col === columnName) |
361 | 370 | } |
362 | 371 |
|
363 | | - const getInvoiceStatus = (item: Transaction) => { |
| 372 | + const getInvoiceStatusForDisplay = (item: Transaction): InvoiceStatus => { |
364 | 373 | // Special case for Online Banking - it shouldn't show NSF, should show Pending. |
365 | 374 | if (item.paymentMethod === PaymentTypes.ONLINE_BANKING && |
366 | 375 | item.statusCode === InvoiceStatus.SETTLEMENT_SCHEDULED) { |
367 | | - return invoiceStatusDisplay[InvoiceStatus.PENDING] |
| 376 | + return InvoiceStatus.PENDING |
368 | 377 | } |
369 | 378 | // Check for partial refunds - this should take priority |
370 | 379 | if (item.partialRefunds?.length > 0) { |
371 | 380 | if ([PaymentTypes.ONLINE_BANKING, PaymentTypes.PAD].includes(item.paymentMethod)) { |
372 | | - return invoiceStatusDisplay[InvoiceStatus.PARTIALLY_CREDITED] |
| 381 | + return InvoiceStatus.PARTIALLY_CREDITED |
373 | 382 | } else { |
374 | | - return invoiceStatusDisplay[InvoiceStatus.PARTIALLY_REFUNDED] |
| 383 | + return InvoiceStatus.PARTIALLY_REFUNDED |
375 | 384 | } |
376 | 385 | } |
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) |
378 | 416 | } |
379 | 417 |
|
380 | 418 | const hasDropdownContent = (item: Transaction): boolean => { |
@@ -615,10 +653,10 @@ export default defineComponent({ |
615 | 653 | } |
616 | 654 | }) |
617 | 655 |
|
618 | | - async function downloadReceipt (item: Transaction) { |
| 656 | + async function downloadReceipt (item: Transaction, isRefund: boolean = false) { |
619 | 657 | emit('isDownloadingReceipt', true) |
620 | 658 | 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) |
622 | 660 | const filename = `bcregistry-receipts-${item.id}.pdf` |
623 | 661 | CommonUtils.fileDownload(receipt.data, filename, 'application/pdf') |
624 | 662 | emit('isDownloadingReceipt', false) |
@@ -676,6 +714,7 @@ export default defineComponent({ |
676 | 714 | loadTransactionList, |
677 | 715 | getInvoiceStatus, |
678 | 716 | datePickerValue, |
| 717 | + canDownloadReceipt, |
679 | 718 | downloadReceipt |
680 | 719 | } |
681 | 720 | } |
|
0 commit comments