forked from openMF/web-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openMF#1479 from ramvr1256/collateral
feat: collateral module
- Loading branch information
Showing
58 changed files
with
1,892 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ts/clients-view/client-actions/add-client-collateral/add-client-collateral.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
4 changes: 4 additions & 0 deletions
4
...ts/clients-view/client-actions/add-client-collateral/add-client-collateral.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container { | ||
width: 37rem; | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...clients-view/client-actions/add-client-collateral/add-client-collateral.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
115 changes: 115 additions & 0 deletions
115
...ents/clients-view/client-actions/add-client-collateral/add-client-collateral.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.