Asset Externalization Owner management for Loans (#1771)

Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
José Alberto Hernández
2023-06-21 12:17:47 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 1b60a8f43c
commit bddf46cccd
36 changed files with 704 additions and 126 deletions
@@ -0,0 +1,57 @@
<div class="container mat-elevation-z8">
<mat-card>
<form [formGroup]="saleLoanForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field (click)="settlementDatePicker.open()">
<mat-label>Settlement Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="settlementDatePicker" required
formControlName="settlementDate">
<mat-datepicker-toggle matSuffix [for]="settlementDatePicker"></mat-datepicker-toggle>
<mat-datepicker #settlementDatePicker></mat-datepicker>
<mat-error *ngIf="saleLoanForm.controls.settlementDate.hasError('required')">
Settlement Date <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="!isBuyBack()">
<mat-label>Purchase Price Ratio</mat-label>
<input type="number" matInput required formControlName="purchasePriceRatio">
<mat-error *ngIf="saleLoanForm.controls.purchasePriceRatio.hasError('required')">
Purchase Price Ratio <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="!isBuyBack()">
<mat-label>Owner External Id</mat-label>
<input matInput formControlName="ownerExternalId">
<mat-error *ngIf="saleLoanForm.controls.ownerExternalId.hasError('required')">
Owner External Id <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Transfer External Id</mat-label>
<input matInput formControlName="transferExternalId">
</mat-form-field>
</div>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../general']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!saleLoanForm.valid"
*mifosxHasPermission="'SALE_LOAN'">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AssetTransferLoanComponent } from './asset-transfer-loan.component';
describe('AssetTransferLoanComponent', () => {
let component: AssetTransferLoanComponent;
let fixture: ComponentFixture<AssetTransferLoanComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ AssetTransferLoanComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AssetTransferLoanComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,90 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Dates } from 'app/core/utils/dates';
import { ExternalAssetOwnerService } from 'app/loans/external-asset-owner.service';
import { SettingsService } from 'app/settings/settings.service';
@Component({
selector: 'mifosx-asset-transfer-loan',
templateUrl: './asset-transfer-loan.component.html',
styleUrls: ['./asset-transfer-loan.component.scss']
})
export class AssetTransferLoanComponent implements OnInit {
BUYBACK_COMMAND = 'buyback';
SALE_COMMAND = 'sale';
command: string;
/** Loan Id */
loanId: string;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/** Sale Loan Form */
saleLoanForm: FormGroup;
constructor(private formBuilder: FormBuilder,
private externalAssetOwnerService: ExternalAssetOwnerService,
private route: ActivatedRoute,
private router: Router,
private dateUtils: Dates,
private settingsService: SettingsService) {
this.loanId = this.route.snapshot.params['loanId'];
const actionName = this.route.snapshot.params['action'];
this.command = (actionName === 'Sale Loan') ? this.SALE_COMMAND : this.BUYBACK_COMMAND;
}
/**
* Creates the sale loan form
* and initialize with the required values
*/
ngOnInit() {
this.minDate = this.settingsService.businessDate;
this.maxDate = this.settingsService.maxAllowedDate;
this.createSaleLoanForm();
}
isBuyBack(): boolean {
return (this.command === this.BUYBACK_COMMAND);
}
/**
* Creates the create close form.
*/
createSaleLoanForm() {
this.saleLoanForm = this.formBuilder.group({
'settlementDate': [this.settingsService.businessDate, Validators.required],
'purchasePriceRatio': ['', Validators.required],
'transferExternalId': '',
'ownerExternalId': ['', Validators.required]
});
if (this.isBuyBack()) {
this.saleLoanForm.removeControl('purchasePriceRatio');
this.saleLoanForm.removeControl('ownerExternalId');
}
}
submit() {
const saleLoanFormData = this.saleLoanForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevsettlementDate: Date = this.saleLoanForm.value.settlementDate;
if (saleLoanFormData.settlementDate instanceof Date) {
saleLoanFormData.settlementDate = this.dateUtils.formatDate(prevsettlementDate, dateFormat);
}
const data = {
...saleLoanFormData,
dateFormat,
locale
};
this.externalAssetOwnerService.executeExternalAssetOwnerLoanCommand(this.loanId, data, this.command)
.subscribe((response: any) => {
this.router.navigate(['../../external-asset-owner'], { relativeTo: this.route });
});
}
}
@@ -27,3 +27,4 @@
<mifosx-edit-repayment-schedule *ngIf="actions['Edit Repayment Schedule']"></mifosx-edit-repayment-schedule>
<mifosx-charge-off [dataObject]="actionButtonData" *ngIf="actions['Charge-Off']"></mifosx-charge-off>
<mifosx-undo-command [actionName]="actionName" *ngIf="actions['Undo Charge-Off']"></mifosx-undo-command>
<mifosx-asset-transfer-loan *ngIf="actions['Sale Loan'] || actions['Buy Back Loan']"></mifosx-asset-transfer-loan>
@@ -42,7 +42,9 @@ export class LoanAccountActionsComponent {
'Credit Balance Refund': boolean,
'Edit Repayment Schedule': boolean,
'Charge-Off': boolean,
'Undo Charge-Off': boolean
'Undo Charge-Off': boolean,
'Sale Loan': boolean,
'Buy Back Loan': boolean
} = {
'Close': false,
'Undo Approval': false,
@@ -73,7 +75,9 @@ export class LoanAccountActionsComponent {
'Credit Balance Refund': false,
'Edit Repayment Schedule': false,
'Charge-Off': false,
'Undo Charge-Off': false
'Undo Charge-Off': false,
'Sale Loan': false,
'Buy Back Loan': false
};
actionButtonData: any;