From d17a686490571a57c498b255928f058e73dd8414 Mon Sep 17 00:00:00 2001 From: piratefinn Date: Mon, 15 Jan 2018 16:20:51 +0000 Subject: [PATCH] functional receiving, choosing and upload of transaction category --- src/app/dashboard/add-data.component.html | 14 ++++++++++++++ src/app/dashboard/add-data.component.ts | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/add-data.component.html b/src/app/dashboard/add-data.component.html index 948f868..ebdea7a 100644 --- a/src/app/dashboard/add-data.component.html +++ b/src/app/dashboard/add-data.component.html @@ -24,6 +24,20 @@ Enter the amount spent, such as 5.35 for £5.35. +
+ +
+
+ +
+ Optional: Choose the relevant Category for the purchase. +
+
diff --git a/src/app/dashboard/add-data.component.ts b/src/app/dashboard/add-data.component.ts index 7ca6cd1..f970448 100644 --- a/src/app/dashboard/add-data.component.ts +++ b/src/app/dashboard/add-data.component.ts @@ -30,6 +30,7 @@ export class AddDataComponent implements OnInit { organisationTown: string; organisationPostcode: string; amount: number; + categoryId: number; transactionAdditionType = 1; storeList = []; showAddStore = false; @@ -37,8 +38,8 @@ export class AddDataComponent implements OnInit { transactionFormInvalid = true; myDate: any; minDate: any; - categoryIds: number[] = []; - categoryNames: string[] = []; + categoryIdList: number[] = []; + categoryNameList: string[] = []; constructor( private formBuilder: FormBuilder, @@ -70,6 +71,7 @@ export class AddDataComponent implements OnInit { result => { this.categories = result; console.log(this.categories); + this.setCategoryList(result.categories); }, error => { console.log('Retrieval Error'); @@ -83,6 +85,11 @@ export class AddDataComponent implements OnInit { this.accountType = localStorage.getItem('usertype'); } + private setCategoryList(data: any) { + this.categoryIdList = Object.keys(data.ids).map(key => data.ids[key]); + this.categoryNameList = Object.keys(data.names).map(key => data.names[key]); + } + getMinDate() { // gets the April 1st date of the current year const aprilDate = moment().month(3).date(1); @@ -182,6 +189,7 @@ export class AddDataComponent implements OnInit { transaction_value : this.amount, purchase_time : purchaseTime, organisation_id : this.organisationId, + category : this.categoryId, }; break; case 2: @@ -190,6 +198,7 @@ export class AddDataComponent implements OnInit { transaction_value : this.amount, purchase_time : purchaseTime, organisation_id : this.organisationId, + category : this.categoryId, }; break; case 3: @@ -201,6 +210,7 @@ export class AddDataComponent implements OnInit { street_name : this.submitOrg.street_name, town : this.submitOrg.town, postcode : this.submitOrg.postcode, + category : this.categoryId, }; break; } @@ -251,6 +261,7 @@ export class AddDataComponent implements OnInit { this.amount = null; this.transactionFormInvalid = true; this.showAddStore = false; + this.categoryId = null; } onSubmitPayroll() {