feat: collateral module

This commit is contained in:
Ramveer
2022-07-22 13:37:21 +05:30
parent ed1395bb20
commit 22428de9b1
58 changed files with 1892 additions and 61 deletions
@@ -0,0 +1,82 @@
<div class="container">
<mat-card>
<form [formGroup]="clientCollateralForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Collateral</mat-label>
<mat-select required formControlName="collateralId">
<mat-option *ngFor="let clientCollateral of clientCollateralOptions" [value]="clientCollateral.id">
{{ clientCollateral.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="clientCollateralForm.controls.collateralId.hasError('required')">
Collateral is <strong>required</strong>
</mat-error>
</mat-form-field>
<div *ngIf="collateralDetails" fxLayout="column">
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput required formControlName="name">
</mat-form-field>
<mat-form-field>
<mat-label>Type/Quality</mat-label>
<input matInput required formControlName="quality">
</mat-form-field>
<mat-form-field>
<mat-label>Unit Type</mat-label>
<input matInput required formControlName="unitType">
</mat-form-field>
<mat-form-field>
<mat-label>Base Price</mat-label>
<input matInput required formControlName="basePrice">
</mat-form-field>
<mat-form-field>
<mat-label>Percentage To Base</mat-label>
<input matInput required formControlName="pctToBase">
</mat-form-field>
<mat-form-field>
<mat-label>Quantity</mat-label>
<input matInput required formControlName="quantity">
<mat-error *ngIf="clientCollateralForm.controls.quantity.hasError('required')">
Quantity is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Total</mat-label>
<input matInput required formControlName="totalValue">
</mat-form-field>
<mat-form-field>
<mat-label>Total Collateral Value</mat-label>
<input matInput required formControlName="totalCollateralValue">
</mat-form-field>
</div>
</div>
</mat-card-content>
<mat-card-actions fxLayoutGap="5px" fxLayout="row" fsLayout.xs="column" fxLayoutAlign="center">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!clientCollateralForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,4 @@
.container {
width: 37rem;
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddClientCollateralComponent } from './add-client-collateral.component';
describe('AddClientCollateralComponent', () => {
let component: AddClientCollateralComponent;
let fixture: ComponentFixture<AddClientCollateralComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ AddClientCollateralComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AddClientCollateralComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,115 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/**
* Custom Services
*/
import { ClientsService } from 'app/clients/clients.service';
import { ProductsService } from 'app/products/products.service';
import { SettingsService } from 'app/settings/settings.service';
@Component({
selector: 'mifosx-add-client-collateral',
templateUrl: './add-client-collateral.component.html',
styleUrls: ['./add-client-collateral.component.scss']
})
export class AddClientCollateralComponent implements OnInit {
/** Client Collateral Form */
clientCollateralForm: FormGroup;
/** Client Collateral Options */
clientCollateralOptions: any;
/** Client Id */
clientId: any;
/** Collateral Details */
collateralDetails: any;
/**
* Retirives Collateral Form from `resolve`
* @param {FormBuilder} formBuilder Form bUilder.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router.
* @param {ProductsService} productsService Products Service
*/
constructor(
private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private productsService: ProductsService,
private clientsService: ClientsService,
private settingsService: SettingsService,
) {
this.route.data.subscribe((data: { clientActionData: any }) => {
this.clientCollateralOptions = data.clientActionData;
console.log(this.clientCollateralOptions);
});
this.clientId = this.route.parent.snapshot.params['clientId'];
}
ngOnInit(): void {
this.createClientCollateralForm();
this.buildDependencies();
}
/**
* Subscribe to Form controls value changes
*/
buildDependencies() {
this.clientCollateralForm.controls.collateralId.valueChanges.subscribe(collateralId => {
this.productsService.getCollateral(collateralId).subscribe((data: any) => {
this.collateralDetails = data;
console.log(data);
this.clientCollateralForm.patchValue({
'name': data.name,
'quality': data.quality,
'unitType': data.unitType,
'basePrice': this.collateralDetails.basePrice,
'pctToBase': this.collateralDetails.pctToBase,
});
});
});
this.clientCollateralForm.controls.quantity.valueChanges.subscribe((quantity: any) => {
this.clientCollateralForm.patchValue({
'totalValue': this.collateralDetails.basePrice * quantity,
'totalCollateralValue': this.collateralDetails.basePrice * this.collateralDetails.pctToBase * quantity / 100
});
});
}
/**
* Creates the Clients Collaterals Form
*/
createClientCollateralForm() {
this.clientCollateralForm = this.formBuilder.group({
'collateralId': [ '', Validators.required ],
'quantity': [ '', Validators.required ],
'name': [{ value: '', disabled: true }],
'quality': [{value: '', disabled: true}],
'unitType': [{value: '', disabled: true}],
'basePrice': [{value: '', disabled: true}],
'pctToBase': [{value: '', disabled: true}],
'totalValue': [{value: '', disabled: true}],
'totalCollateralValue': [{value: '', disabled: true}],
});
}
/**
* Submits Client Collateral
*/
submit() {
const collateralId = this.clientCollateralForm.value.collateralId;
const quantity = this.clientCollateralForm.value.quantity;
const locale = this.settingsService.language.code;
const clientCollateral = {
collateralId,
quantity,
locale
};
this.clientsService.createClientCollateral(this.clientId, clientCollateral).subscribe(() => {
this.router.navigate(['../../'], {relativeTo: this.route});
});
}
}
@@ -15,3 +15,4 @@
<mifosx-take-survey *ngIf="actions['Take Survey']"></mifosx-take-survey>
<mifosx-client-screen-reports *ngIf="actions['Client Screen Reports']"></mifosx-client-screen-reports>
<mifosx-create-self-service-user *ngIf="actions['Create Self Service User']"></mifosx-create-self-service-user>
<mifosx-add-client-collateral *ngIf="actions['Create Collateral']"></mifosx-add-client-collateral>
@@ -29,7 +29,8 @@ export class ClientActionsComponent {
'Add Charge': boolean
'Take Survey': boolean
'Client Screen Reports': boolean,
'Create Self Service User': boolean
'Create Self Service User': boolean,
'Create Collateral': boolean
} = {
'Assign Staff': false,
'Close': false,
@@ -46,7 +47,8 @@ export class ClientActionsComponent {
'Add Charge': false,
'Take Survey': false,
'Client Screen Reports': false,
'Create Self Service User': false
'Create Self Service User': false,
'Create Collateral': false
};
/**