Chargeback Loan Transaction
This commit is contained in:
+112
-5
@@ -1,5 +1,5 @@
|
||||
/** Angular Imports */
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
@@ -8,6 +8,12 @@ import { LoansService } from 'app/loans/loans.service';
|
||||
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { OrganizationService } from 'app/organization/organization.service';
|
||||
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
|
||||
import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
|
||||
import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base';
|
||||
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
|
||||
/** Custom Dialogs */
|
||||
|
||||
@@ -20,14 +26,27 @@ import { Dates } from 'app/core/utils/dates';
|
||||
templateUrl: './view-transaction.component.html',
|
||||
styleUrls: ['./view-transaction.component.scss']
|
||||
})
|
||||
export class ViewTransactionComponent {
|
||||
export class ViewTransactionComponent implements OnInit {
|
||||
|
||||
/** Transaction data. */
|
||||
transactionData: any;
|
||||
/** Is Editable */
|
||||
allowEdition = true;
|
||||
/** Is Undoable */
|
||||
allowUndo = true;
|
||||
/** Is Undoable */
|
||||
allowUndo = true;
|
||||
/** Is able to be Chargeback */
|
||||
allowChargeback = true;
|
||||
existTransactionRelations = false;
|
||||
|
||||
paymentTypeOptions: {}[] = [];
|
||||
transactionRelations = new MatTableDataSource();
|
||||
/** Columns to be displayed in Transaction Relations table. */
|
||||
displayedColumns: string[] = ['relationType', 'toTransaction', 'amount'];
|
||||
isFullRelated = false;
|
||||
amountRelationsAllowed = 0;
|
||||
|
||||
clientId: number;
|
||||
loanId: number;
|
||||
|
||||
/**
|
||||
* Retrieves the Transaction data from `resolve`.
|
||||
@@ -43,13 +62,43 @@ export class ViewTransactionComponent {
|
||||
private dateUtils: Dates,
|
||||
private router: Router,
|
||||
public dialog: MatDialog,
|
||||
private settingsService: SettingsService) {
|
||||
private settingsService: SettingsService,
|
||||
private organizationService: OrganizationService) {
|
||||
this.route.data.subscribe((data: { loansAccountTransaction: any }) => {
|
||||
this.transactionData = data.loansAccountTransaction;
|
||||
this.allowEdition = !this.transactionData.manuallyReversed && !(this.transactionData.type.id === 20 || this.transactionData.type.id === 21 || this.transactionData.type.id === 22
|
||||
|| this.transactionData.type.id === 23);
|
||||
this.allowUndo = !this.transactionData.manuallyReversed;
|
||||
this.allowChargeback = this.transactionData.type.repayment;
|
||||
if (this.transactionData.type.repayment) {
|
||||
if (this.transactionData.transactionRelations) {
|
||||
this.transactionRelations.data = this.transactionData.transactionRelations;
|
||||
this.existTransactionRelations = (this.transactionData.transactionRelations.length > 0);
|
||||
let amountRelations = 0;
|
||||
this.transactionData.transactionRelations.forEach((relation: any) => {
|
||||
amountRelations += relation.amount;
|
||||
});
|
||||
this.amountRelationsAllowed = this.transactionData.amount - amountRelations;
|
||||
this.isFullRelated = (this.amountRelationsAllowed === 0);
|
||||
this.allowChargeback = this.transactionData.type.repayment && !this.isFullRelated;
|
||||
}
|
||||
}
|
||||
if (!this.allowChargeback || this.existTransactionRelations) {
|
||||
this.allowUndo = false;
|
||||
this.allowEdition = false;
|
||||
}
|
||||
});
|
||||
this.clientId = this.route.snapshot.params['clientId'];
|
||||
this.loanId = this.route.snapshot.params['loanId'];
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.allowChargeback) {
|
||||
this.organizationService.getPaymentTypesWithCode().toPromise()
|
||||
.then(data => {
|
||||
this.paymentTypeOptions = data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,4 +126,62 @@ export class ViewTransactionComponent {
|
||||
});
|
||||
}
|
||||
|
||||
chargebackTransaction() {
|
||||
const accountId = this.route.parent.parent.parent.snapshot.params['loanId'];
|
||||
const formfields: FormfieldBase[] = [
|
||||
new SelectBase({
|
||||
controlName: 'paymentTypeId',
|
||||
label: 'Payment Type',
|
||||
value: '',
|
||||
options: { label: 'name', value: 'id', data: this.paymentTypeOptions },
|
||||
required: true,
|
||||
order: 1
|
||||
}),
|
||||
new InputBase({
|
||||
controlName: 'amount',
|
||||
label: 'Amount',
|
||||
value: this.amountRelationsAllowed,
|
||||
type: 'number',
|
||||
required: true,
|
||||
max: this.amountRelationsAllowed,
|
||||
order: 2
|
||||
})
|
||||
];
|
||||
const data = {
|
||||
title: 'Chargeback Repayment Transaction',
|
||||
layout: { addButtonText: 'Chargeback' },
|
||||
formfields: formfields
|
||||
};
|
||||
const chargebackDialogRef = this.dialog.open(FormDialogComponent, { data });
|
||||
chargebackDialogRef.afterClosed().subscribe((response: { data: any }) => {
|
||||
if (response.data) {
|
||||
if (response.data.value.amount <= this.amountRelationsAllowed) {
|
||||
const locale = this.settingsService.language.code;
|
||||
const payload = {
|
||||
transactionAmount: response.data.value.amount,
|
||||
paymentTypeId: response.data.value.paymentTypeId,
|
||||
locale
|
||||
};
|
||||
this.loansService.executeLoansAccountTransactionsCommand(accountId, 'chargeback', payload, this.transactionData.id).subscribe(() => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loanTransactionRelatedLink(transactionId: number) {
|
||||
return `/#/clients/${this.clientId}/loans-accounts/${this.loanId}/transactions/${transactionId}`;
|
||||
}
|
||||
|
||||
loanTransactionColor(): string {
|
||||
if (this.transactionData.manuallyReversed) {
|
||||
return 'undo';
|
||||
}
|
||||
if (this.existTransactionRelations) {
|
||||
return 'linked';
|
||||
}
|
||||
return 'active';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user