From df6c469965d920d91b4552d025a3f21f5f2f35bd Mon Sep 17 00:00:00 2001 From: piratefinn Date: Tue, 20 Mar 2018 16:53:29 +0000 Subject: [PATCH] added updating transaction --- .../dashboard/transaction-log.component.html | 19 +++++++++ .../dashboard/transaction-log.component.ts | 40 ++++++++++++------- src/app/providers/api-service.ts | 10 +++++ src/app/shared/recur-result.component.html | 4 +- src/app/shared/recur-result.component.ts | 5 ++- src/app/shared/recur-table.component.html | 2 +- src/app/shared/recur-table.component.ts | 1 + 7 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/app/dashboard/transaction-log.component.html b/src/app/dashboard/transaction-log.component.html index d24c301..0638a50 100644 --- a/src/app/dashboard/transaction-log.component.html +++ b/src/app/dashboard/transaction-log.component.html @@ -114,6 +114,25 @@ Optional: Choose the Budget Type for the majority of the purchase. +
+
+ WARNING: Clicking "Delete" will completely remove the Recurring Transaction. +
+
+
+
+ + +
+
+ + diff --git a/src/app/dashboard/transaction-log.component.ts b/src/app/dashboard/transaction-log.component.ts index d05babe..e9e10ce 100644 --- a/src/app/dashboard/transaction-log.component.ts +++ b/src/app/dashboard/transaction-log.component.ts @@ -25,6 +25,8 @@ export class TransactionLogComponent implements OnInit { categoryIdList: number[] = []; categoryList: any; categoryNameList: string[] = []; + transactionFormStatus: string; + transactionFormStatusError = 'Error received, please try again.'; public paginateConfig: PaginationInstance = { id: 'transpaginate', @@ -89,9 +91,7 @@ export class TransactionLogComponent implements OnInit { recurringTransactionDetails(clicked, template: TemplateRef) { this.clickedRecur = clicked; - console.log(this.clickedRecur); - this.updatedTime = moment(this.clickedRecur.last_updated).format('YYYY-MM-DD[T]HH:mm'); - this.startTime = moment(this.clickedRecur.start_time).format('YYYY-MM-DD[T]HH:mm'); + this.updatedTime = moment(this.clickedRecur.display_time, 'llll').format('YYYY-MM-DD[T]HH:mm'); this.openModal(template); } @@ -100,34 +100,44 @@ export class TransactionLogComponent implements OnInit { } editRecurringTransaction() { - let updatedDateSubmit = moment(this.updatedTime, 'YYYY-MM-DD[T]HH:mm').local().format('YYYY-MM-DD[T]HH:mm:ss.SSSZ'); - let startTimeSubmit = moment(this.startTime, 'YYYY-MM-DD[T]HH:mm').local().format('YYYY-MM-DD[T]HH:mm:ss.SSSZ'); + let updatedTimeSubmit = moment(this.updatedTime, 'YYYY-MM-DD[T]HH:mm').local().format('YYYY-MM-DD[T]HH:mm:ss.SSSZ'); + this.clickedRecur.display_time = moment(this.updatedTime).format('llll'); let myParams = { - category: this.clickedRecur.category, + category: 111, essential: this.clickedRecur.essential, id: this.clickedRecur.id, - last_updated: this.updatedDate, - recurring_period: this.updatedDateSubmit, + apply_time: updatedTimeSubmit, + recurring_period: this.clickedRecur.recurring_period, seller: this.clickedRecur.seller, - start_time: this.startTimeSubmit, value: this.clickedRecur.value, }; - /******************************/ - this.api - .upload(myParams) + .recurUpdate(myParams) .subscribe( result => { if ( result.success === true ) { - console.log('Successful Upload'); + this.transactionFormStatus = 'success'; + this.resetForm(); } else { - console.log('Upload Error'); + this.transactionFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message); + this.transactionFormStatus = 'send_failed'; } }, error => { - console.log('Upload Error'); + console.log(error); + try { + console.log(error.error); + this.transactionFormStatusError = '"' + error.error.error + '" Error, ' + error.error.message; + } catch (e) { + this.transactionFormStatusError = 'There was a server error, please try again later.'; + } + this.transactionFormStatus = 'send_failed'; } ); } + deleteRecurringTransaction() { + + } + } diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index bbf3464..519d272 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -158,6 +158,16 @@ export class ApiService { ); } + // Uploads a transaction + + public recurUpdate(data) { + data.session_key = this.sessionKey; + return this.http.post( + this.apiUrl + '/recurring-transactions', + data + ); + } + // gets payroll list for log public payrollList(data) { diff --git a/src/app/shared/recur-result.component.html b/src/app/shared/recur-result.component.html index c716883..c494b71 100644 --- a/src/app/shared/recur-result.component.html +++ b/src/app/shared/recur-result.component.html @@ -1,6 +1,6 @@ {{recur.seller}} {{categories[recur.category] || 'Uncategorised'}} -{{recur.essential}} -{{updatedDate}} +{{recur.essential == 1 ? 'true' : 'false'}} +{{recur.display_time}} {{recur.recurring_period}} {{recur.value}} diff --git a/src/app/shared/recur-result.component.ts b/src/app/shared/recur-result.component.ts index ca495b4..3532464 100644 --- a/src/app/shared/recur-result.component.ts +++ b/src/app/shared/recur-result.component.ts @@ -10,6 +10,7 @@ interface RecurData { seller: string; start_time: string; value: number; + display_time: any; } @Component({ @@ -25,9 +26,9 @@ export class RecurResultComponent { ngOnInit(): void { if (this.recur.last_updated) { - this.updatedDate = moment(this.recur.last_updated).format('llll'); + this.recur.display_time = moment(this.recur.last_updated).format('llll'); } else { - this.updatedDate = moment(this.recur.start_time).format('llll'); + this.recur.display_time = moment(this.recur.start_time).format('llll'); } } diff --git a/src/app/shared/recur-table.component.html b/src/app/shared/recur-table.component.html index 35fd96e..a6ec55d 100644 --- a/src/app/shared/recur-table.component.html +++ b/src/app/shared/recur-table.component.html @@ -5,7 +5,7 @@ Seller Category Essential - Last Updated + Last Applied Recurring Period Value diff --git a/src/app/shared/recur-table.component.ts b/src/app/shared/recur-table.component.ts index 0b5e32d..c2f6ef0 100644 --- a/src/app/shared/recur-table.component.ts +++ b/src/app/shared/recur-table.component.ts @@ -10,6 +10,7 @@ interface RecurData { seller: string; start_time: string; value: number; + display_time: any; } @Component({