Hello everyone,
I Have just created a form which accepts all the values from the user,like this:-
Now I want these values to be displayed in table:-
Now the values are displayed well,but I want to show the calculation too.,My balance is empty field here,but I wish that the balance should come out to be deposit-withdrawl(in the above example -450)
my html code:-
<form [formGroup]="journal" (ngSubmit)="journaldata()">
<ion-card>
<ion-card-header>
JOURNAL </ion-card-header>
<ion-card-content> <ion-item>
<ion-label>Date<span> <sup>*</sup></span>
</ion-label>
<ion-input type="text" formControlName="date">
</ion-input>
</ion-item>
<ion-item> <ion-label>Details<span> <sup>*</sup></span></ion-label>
<ion-input type="text" formControlName="details">
</ion-input>
</ion-item>
<ion-item>
<ion-label>Withdrawl<span> <sup>
*</sup></span></ion-label>
<ion-input type="text" formControlName="withdrawl"></ion-input> </ion-item> <ion-item>
<ion-label>Deposit<span> <sup>
*</sup></span></ion-label>
<ion-input type="text" formControlName="deposit"></ion-input> </ion-item> <ion-item>
<ion-label>ACCOUNT NAME</ion-label>
<ion-select formControlName="accountname" multiple="false" > <ion-option *ngFor='let journal of accountsList' [value]="journal">{{journal }}</ion-option> </ion-select>
</ion-item>
<!-- <ion-item>
<ion-label> Account Name<span> <sup>*</sup></span></ion-label>
<ion-input type="text" formControlName="accountname">
</ion-input>
</ion-item>-->
<ion-item>
<ion-label>Bank Reconcilation<span> <sup>
*</sup></span></ion-label>
<ion-input type="text" formControlName="bank"></ion-input> </ion-item>
<ion-item>
<ion-list>
<button ion-button (click)="journaldata()" >Create Journal</button> </ion-list></ion-item>
My ts file-
import { Component } from '@angular/core';import
{ IonicPage, NavController, NavParams }
from 'ionic-angular';import {JournaladdProvider} from '../../providers/journaladd/journaladd';import{Validators,FormBuilder,FormGroup}from'@angular/forms';
import {AddaccountProvider} from '../../providers/addaccount/addaccount';/** * Generated class for the JournalPage page. * * See http://ionicframework.com/docs/components/#navigation for more info * on Ionic pages and navigation. */@IonicPage()@Component({ selector: 'page-journal', templateUrl: 'journal.html',})export class JournalPage {journal:FormGroup;
accountsList : any = [];
accountSelected: any;
list: any = {};
name:any=[];
add:any={};
constructor(public navCtrl:NavController,public navParams:NavParams, public store:AddaccountProvider, public formBuilder: FormBuilder )
{
this.journal = this.formBuilder.group({
date: ['', Validators.required],
withdrawl: [''],deposit:[''],bank:[''],details:['',Validators.required], accountname: ['', Validators.required],
});
this.store.getAccountList().then(journal => {
this.accountsList = journal;
// this.transfer.value.accountSelected = this.accountsList[0];
});
}
ionViewDidLoad()
{ console.log('ionViewDidLoad JournalPage');
}
ionViewWillEnter()
{
this.store.getAccountList().then(transfer => {
this.accountsList = transfer;
//this.transfer.value.accountSelected = this.accountsList[0];
});
} journaldata()
{
let balance = this.journal.value.deposit - this.journal.value.withdraw;
let key = this.journal.value.accountname;
key = this._formatString(key);
let checkbook = [];
let datas = {date: new Date().toLocaleDateString(), num: 1, description: this.journal.value.details, r:
'R', withdraw: this.journal.value.withdrawl,
deposit: this.journal.value.deposit,balance:balance};
checkbook.push(datas);
this.list = { created: new Date().toString(), details:this.journal.value.details,withdrawl: this.journal.value.withdrawl, deposit: this.journal.value.deposit ,accountname:this.journal.value.accountname,bank:this.journal.value.bank,checkbook:checkbook
};
this.store.set(key, JSON.stringify(this.list));
alert('Journal Created'); /* this.list =
{ created: new Date().toString(), details:this.journal.value.details,withdrawl: this.journal.value.withdrawl, deposit: this.journal.value.deposit ,accountname:this.journal.value.accountname,bank:this.journal.value.bank }; this.store.set(JSON.stringify(this.list));
alert('Journal Created');*/
// console.log(JSON.stringify(this.j));
//console.log("error");
// this.store.set(JSON.stringify(this.j)); }
_formatString(name)
{ /* Remove whitespaces
*/ while(name.indexOf(" ") != -1)
{ name = name.replace(" ","");
}
return name;
}
}
Thanks in advance,I have tried to calculate the balance using,
let balance = this.journal.value.deposit - this.journal.value.withdraw;
and passed in the array:-
let datas = {date: new Date().toLocaleDateString(), num: 1, description: this.journal.value.details, r: 'R', withdraw: this.journal.value.withdrawl,
deposit: this.journal.value.deposit,balance:balance};
checkbook.push(datas);
Please guide where I am wrong.
Thanks in advance