Broker System for Supercredit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.0KB

  1. import {Component, Input, OnInit, Output, EventEmitter} from '@angular/core';
  2. import {FormControl, FormGroup, Validators} from '@angular/forms';
  3. import {LoanModel} from '../../models/loan.model';
  4. import {LoanSingleService} from '../../service/loan.single.service';
  5. import {HttpErrorResponse} from '@angular/common/http';
  6. @Component({
  7. selector: 'app-loan-basic-info',
  8. templateUrl: './basicinfo.component.html',
  9. styleUrls: ['./basicinfo.component.scss']
  10. })
  11. export class BasicinfoComponent implements OnInit {
  12. constructor( private service: LoanSingleService) { }
  13. @Input() Loan: LoanModel;
  14. @Output() lenderNameChanged = new EventEmitter<string>();
  15. @Output() NotifyNext = new EventEmitter<boolean>();
  16. @Output() errorOccurred = new EventEmitter<string>();
  17. public minSettlement: Date = new Date(2015, 0, 1);
  18. public maxSettlement: Date = new Date(2030, 4, 31);
  19. public basicInfo: FormGroup ;
  20. public DemoDescription = `
  21. <h1> Rich Text Editing </h1>
  22. <table>
  23. <tr> <td>
  24. <ol>
  25. <li>Text formatting</li>
  26. <li>Bulleted and numbered lists</li>
  27. <li>Hyperlinks</li>
  28. <li>Cross-browser support</li>
  29. <li>Identical HTML output across browsers</li>
  30. </ol>
  31. </td> <td width="20%" text-align="right">
  32. <img src="https://edge.alluremedia.com.au/uploads/businessinsider/2015/05/P2P-to-date.jpg"
  33. width=300">
  34. </td>
  35. </tr>
  36. </table>
  37. `;
  38. public listLoanStatus: Array<{text: string, value: string}> = [
  39. {text: '1 - Processing:   Just received from Client', value: 'Processing'} ,
  40. {text: '2 - Valuation :   Valuating From Bank', value: 'Valuation'},
  41. {text: '3 - Application in Progress:   Application Submitted', value: 'Application in Progress'},
  42. {text: '4 - Approved :   Approved by lender', value: 'Approved' },
  43. {text: '5 - Settled :   Settlement date finalized.', value: 'Settled'},
  44. {text: '6 - Finished :   Fully paid, terminated, or switched)', value: 'Finished'},
  45. ];
  46. ngOnInit(): void {
  47. this.basicInfo = new FormGroup({
  48. LoanId: new FormControl({value: this.Loan.Id, disabled: true}),
  49. Status: new FormControl(),
  50. Item: new FormControl(this.Loan.Item, Validators.required),
  51. Lender : new FormControl({value: 'SuperCredit', disabled: false}, Validators.required),
  52. Amount: new FormControl(100, [Validators.required , Validators.min(100), Validators.max(1000000000)]),
  53. Settlement: new FormControl(new Date(2020, 0, 9)),
  54. Description: new FormControl( '', Validators.maxLength(2000)),
  55. Rating: new FormControl({value: this.Loan.Rating, disabled: false}),
  56. });
  57. this.LoadBasic();
  58. }
  59. onLenderNameChange(value: string): void {
  60. console.log('emit lender change');
  61. this.lenderNameChanged.emit(value);
  62. }
  63. public next(): void {
  64. this.basicInfo.markAllAsTouched();
  65. // console.log(this.basicInfo, this.Loan);
  66. this.Loan.Lender = this.basicInfo.value.Lender;
  67. this.Loan.Status = this.basicInfo.value.Status;
  68. this.Loan.Item = this.basicInfo.value.Item;
  69. this.Loan.Amount = this.basicInfo.value.Amount;
  70. this.Loan.Settlement = this.basicInfo.value.Settlement;
  71. this.Loan.Description = this.basicInfo.value.Description;
  72. this.Loan.Rating = this.basicInfo.value.Rating;
  73. this.service.updateBasicInfo(this.Loan).subscribe(
  74. resp => {
  75. // console.log(resp);
  76. // move to next step
  77. this.NotifyNext.emit(true);
  78. },
  79. err => {
  80. const msg = err instanceof HttpErrorResponse ? err.statusText : '';
  81. this.errorOccurred.emit('Network Error Occurred : ' + err.statusText);
  82. this.NotifyNext.emit(false);
  83. }
  84. );
  85. }
  86. public loanStatus(value: string): {text: string, value: string} {
  87. this.listLoanStatus.forEach(( v) => {
  88. if (v.value = value) {
  89. return v;
  90. }
  91. });
  92. return null;
  93. }
  94. public showDemoDescription($event): void{
  95. this.basicInfo.get('Description').setValue(this.DemoDescription);
  96. }
  97. public LoadBasic(): void {
  98. if (this.Loan === undefined) {
  99. return ;
  100. }
  101. this.basicInfo.get('LoanId').setValue(this.Loan.Id);
  102. this.basicInfo.get('Lender').setValue(this.Loan.Lender);
  103. this.lenderNameChanged.emit(this.basicInfo.get('Lender').value);
  104. this.basicInfo.get('Status').setValue(this.Loan.Status);
  105. this.basicInfo.get('Item').setValue(this.Loan.Item);
  106. this.basicInfo.get('Amount').setValue(this.Loan.Amount);
  107. this.basicInfo.get('Settlement').setValue(this.Loan.Settlement);
  108. this.basicInfo.get('Description').setValue(this.Loan.Description);
  109. this.basicInfo.get('Rating').setValue(this.Loan.Rating);
  110. return ;
  111. if ( this.Loan.Status === 'Settled') {
  112. this.basicInfo.get('Status').disable({onlySelf: true, emitEvent: false});
  113. this.basicInfo.get('Item').disable({onlySelf: true, emitEvent: false});
  114. this.basicInfo.get('Amount').disable({onlySelf: true, emitEvent: false});
  115. }
  116. }
  117. }