added updating transaction

This commit is contained in:
piratefinn 2018-03-20 16:53:29 +00:00
parent 49bd7d2e0c
commit 2188c1272f
7 changed files with 61 additions and 20 deletions

View file

@ -114,6 +114,25 @@
<span class="help-block"><strong>Optional:</strong> Choose the Budget Type for the majority of the purchase.</span> <span class="help-block"><strong>Optional:</strong> Choose the Budget Type for the majority of the purchase.</span>
</div> </div>
</div> </div>
<div class="form-group row">
<div class="input-group">
<span class="col-12"><strong>WARNING: Clicking "Delete" will completely remove the Recurring Transaction.</strong></span>
</div>
</div>
<div class="col-md-12">
<div [ngSwitch]="transactionFormStatus">
<div *ngSwitchCase="'success'" class="alert alert-success" role="alert">
Edit Succeeded.
</div>
<div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert">
{{transactionFormStatusError}}
</div>
</div>
</div>
</div>
<div class="modal-footer d-flex justify-content-between">
<button type="submit" (click)="deleteRecurringTransaction()" class="btn btn-sm btn-danger"><i class="fa fa-times"></i> Delete</button>
<button type="submit" (click)="editRecurringTransaction()" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i> Edit</button>
</div> </div>
</ng-template> </ng-template>
</div> </div>

View file

@ -25,6 +25,8 @@ export class TransactionLogComponent implements OnInit {
categoryIdList: number[] = []; categoryIdList: number[] = [];
categoryList: any; categoryList: any;
categoryNameList: string[] = []; categoryNameList: string[] = [];
transactionFormStatus: string;
transactionFormStatusError = 'Error received, please try again.';
public paginateConfig: PaginationInstance = { public paginateConfig: PaginationInstance = {
id: 'transpaginate', id: 'transpaginate',
@ -89,9 +91,7 @@ export class TransactionLogComponent implements OnInit {
recurringTransactionDetails(clicked, template: TemplateRef<any>) { recurringTransactionDetails(clicked, template: TemplateRef<any>) {
this.clickedRecur = clicked; this.clickedRecur = clicked;
console.log(this.clickedRecur); this.updatedTime = moment(this.clickedRecur.display_time, 'llll').format('YYYY-MM-DD[T]HH:mm');
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.openModal(template); this.openModal(template);
} }
@ -100,34 +100,44 @@ export class TransactionLogComponent implements OnInit {
} }
editRecurringTransaction() { editRecurringTransaction() {
let updatedDateSubmit = moment(this.updatedTime, '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');
let startTimeSubmit = moment(this.startTime, '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 = { let myParams = {
category: this.clickedRecur.category, category: 111,
essential: this.clickedRecur.essential, essential: this.clickedRecur.essential,
id: this.clickedRecur.id, id: this.clickedRecur.id,
last_updated: this.updatedDate, apply_time: updatedTimeSubmit,
recurring_period: this.updatedDateSubmit, recurring_period: this.clickedRecur.recurring_period,
seller: this.clickedRecur.seller, seller: this.clickedRecur.seller,
start_time: this.startTimeSubmit,
value: this.clickedRecur.value, value: this.clickedRecur.value,
}; };
/******************************/
this.api this.api
.upload(myParams) .recurUpdate(myParams)
.subscribe( .subscribe(
result => { result => {
if ( result.success === true ) { if ( result.success === true ) {
console.log('Successful Upload'); this.transactionFormStatus = 'success';
this.resetForm();
} else { } else {
console.log('Upload Error'); this.transactionFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message);
this.transactionFormStatus = 'send_failed';
} }
}, },
error => { 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() {
}
} }

View file

@ -158,6 +158,16 @@ export class ApiService {
); );
} }
// Uploads a transaction
public recurUpdate(data) {
data.session_key = this.sessionKey;
return this.http.post<any>(
this.apiUrl + '/recurring-transactions',
data
);
}
// gets payroll list for log // gets payroll list for log
public payrollList(data) { public payrollList(data) {

View file

@ -1,6 +1,6 @@
<td (click)="recurClick()">{{recur.seller}}</td> <td (click)="recurClick()">{{recur.seller}}</td>
<td (click)="recurClick()">{{categories[recur.category] || 'Uncategorised'}}</td> <td (click)="recurClick()">{{categories[recur.category] || 'Uncategorised'}}</td>
<td (click)="recurClick()">{{recur.essential}}</td> <td (click)="recurClick()">{{recur.essential == 1 ? 'true' : 'false'}}</td>
<td (click)="recurClick()">{{updatedDate}}</td> <td (click)="recurClick()">{{recur.display_time}}</td>
<td (click)="recurClick()">{{recur.recurring_period}}</td> <td (click)="recurClick()">{{recur.recurring_period}}</td>
<td (click)="recurClick()">{{recur.value}}</td> <td (click)="recurClick()">{{recur.value}}</td>

View file

@ -10,6 +10,7 @@ interface RecurData {
seller: string; seller: string;
start_time: string; start_time: string;
value: number; value: number;
display_time: any;
} }
@Component({ @Component({
@ -25,9 +26,9 @@ export class RecurResultComponent {
ngOnInit(): void { ngOnInit(): void {
if (this.recur.last_updated) { 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 { } else {
this.updatedDate = moment(this.recur.start_time).format('llll'); this.recur.display_time = moment(this.recur.start_time).format('llll');
} }
} }

View file

@ -5,7 +5,7 @@
<th>Seller</th> <th>Seller</th>
<th>Category</th> <th>Category</th>
<th>Essential</th> <th>Essential</th>
<th>Last Updated</th> <th>Last Applied</th>
<th>Recurring Period</th> <th>Recurring Period</th>
<th>Value</th> <th>Value</th>
</tr> </tr>

View file

@ -10,6 +10,7 @@ interface RecurData {
seller: string; seller: string;
start_time: string; start_time: string;
value: number; value: number;
display_time: any;
} }
@Component({ @Component({