/** Angular Imports */ import { Component , OnInit , Input } from '@angular/core' ; import { FormGroup , FormBuilder , Validators , FormControl } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; /** Custom Services */ import { LoansService } from 'app/loans/loans.service' ; import { DatePipe } from '@angular/common' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Loan Make Repayment Component
 */ @ Component ( { selector : 'mifosx-make-repayment' , templateUrl : './make-repayment.component.html' , styleUrls : [ './make-repayment.component.scss' ] } ) export class MakeRepaymentComponent implements OnInit { @ Input ( ) dataObject : any ; /** Loan Id */ loanId : string ; /** Payment Type Options */ paymentTypes : any ; /** Show payment details */ showPaymentDetails = false ; /** Minimum Date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum Date allowed. */ maxDate = new Date ( ) ; /** Repayment Loan Form */ repaymentLoanForm : FormGroup ; param { FormBuilder } formBuilder param { LoansService } loanService param { ActivatedRoute } route param { Router } router param { DatePipe } datePipe param { SettingsService } settingsService constructor ( private formBuilder , private loanService , private route , private router , private datePipe , private settingsService ) { this . loanId = this . route . parent . snapshot . params [ 'loanId' ] ; } /**
     * Creates the repayment loan form
     * and initialize with the required values
     */ ngOnInit ( ) { this . createRepaymentLoanForm ( ) ; } /**
     * Creates the create close form.
     */ createRepaymentLoanForm ( ) { this . repaymentLoanForm = this . formBuilder . group ( { 'transactionDate' : [ new Date ( ) , Validators . required ] , 'transactionAmount' : [ '' , Validators . required ] , 'paymentTypeId' : '' , 'note' : '' } ) ; } setRepaymentLoanDetails ( ) { this . paymentTypes = this . dataObject . paymentTypeOptions ; this . repaymentLoanForm . patchValue ( { transactionAmount : this . dataObject . amount , transactionDate : new Date ( this . dataObject . date ) } ) ; } /**
     * Add payment detail fields to the UI.
     */ addPaymentDetails ( ) { this . showPaymentDetails = ! this . showPaymentDetails ; if ( this . showPaymentDetails ) { this . repaymentLoanForm . addControl ( 'accountNumber' , new FormControl ( '' ) ) ; this . repaymentLoanForm . addControl ( 'checkNumber' , new FormControl ( '' ) ) ; this . repaymentLoanForm . addControl ( 'routingCode' , new FormControl ( '' ) ) ; this . repaymentLoanForm . addControl ( 'receiptNumber' , new FormControl ( '' ) ) ; this . repaymentLoanForm . addControl ( 'bankNumber' , new FormControl ( '' ) ) ; } else { this . repaymentLoanForm . removeControl ( 'accountNumber' ) ; this . repaymentLoanForm . removeControl ( 'checkNumber' ) ; this . repaymentLoanForm . removeControl ( 'routingCode' ) ; this . repaymentLoanForm . removeControl ( 'receiptNumber' ) ; this . repaymentLoanForm . removeControl ( 'bankNumber' ) ; } } /** Submits the repayment form */ submit ( ) { const prevTransactionDate = this . repaymentLoanForm . value . transactionDate ; const dateFormat = this . settingsService . dateFormat ; this . repaymentLoanForm . patchValue ( { transactionDate : this . datePipe . transform ( prevTransactionDate , dateFormat ) } ) ; const repaymentLoanData = this . repaymentLoanForm . value ; repaymentLoanData . locale = this . settingsService . language . code ; repaymentLoanData . dateFormat = dateFormat ; this . loanService . submitLoanActionButton ( this . loanId , repaymentLoanData , 'repayment' ) . subscribe ( ( response ) => { this . router . navigate ( [ '../../../general' ] , { relativeTo : this . route } ) ; } ) ; } }