Merge branch 'development' into theslby/pushapi

This commit is contained in:
Unknown 2018-03-06 12:25:58 +00:00
commit 59cbc920c2
11 changed files with 384 additions and 14 deletions

View file

@ -2,6 +2,9 @@
# Next Release
* Amended category list on transaction submission
* Added budget view for weekly breakdown of spend by category
# v0.1.3
* Made fix to Travis config

View file

@ -25,17 +25,42 @@
</div>
</div>
<div class="form-group row">
<label class="col-md-3 form-control-label" for="text-input">Category</label>
<label class="col-md-3 form-control-label" for="text-input">Essential Purchase</label>
<div class="col-md-9">
<div class="input-group">
<select type="text" class="form-control" [(ngModel)]="categoryId" size="6">
<option value="">Uncategorised</option>
<option *ngFor="let category of categoryIdList, let i=index" [ngValue]="category" >
{{ categoryNameList[i] }}
</option>
</select>
<input type="checkbox" class="mr-auto" [(ngModel)]="essentialPurchase" (ngModelChange)="transactionFormValidate()">
</div>
<span class="help-block"><strong>Optional:</strong> Choose the relevant Category for the purchase.</span>
<span class="help-block">Tick if the purchase is deemed an essential purchase for budgeting purposes.</span>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 form-control-label" for="text-input">Budget Type</label>
<div class="col-md-9">
<div class="row">
<div class="col-md-6">
<div>
<label>
<input value="" type="radio" name="radios" [(ngModel)]="categoryId">
Uncategorised
</label>
</div>
<div class="radio" *ngFor="let category of leftCategoryIdList, let i=index">
<label>
<input [value]="category" type="radio" name="radios" [(ngModel)]="categoryId">
{{ categoryNameList[i] }}
</label>
</div>
</div>
<div class="col-md-6">
<div class="radio" *ngFor="let category2 of rightCategoryIdList, let i=index">
<label>
<input [value]="category2" type="radio" name="radios" [(ngModel)]="categoryId">
{{ categoryNameList[category2 - 1] }}
</label>
</div>
</div>
</div>
<span class="help-block"><strong>Optional:</strong> Choose the Budget Type for the majority of the purchase.</span>
</div>
</div>
<div class="form-group row">

View file

@ -32,6 +32,7 @@ export class AddDataComponent implements OnInit {
amount: number;
// Assumes Groceries is 1st category
categoryId: number = 1;
essentialPurchase = false;
transactionAdditionType = 1;
storeList = [];
showAddStore = false;
@ -39,7 +40,8 @@ export class AddDataComponent implements OnInit {
transactionFormInvalid = true;
myDate: any;
minDate: any;
categoryIdList: number[] = [];
leftCategoryIdList: number[] = [];
rightCategoryIdList: number[] = [];
categoryNameList: string[] = [];
constructor(
@ -85,8 +87,11 @@ export class AddDataComponent implements OnInit {
}
private setCategoryList(data: any) {
this.categoryIdList = Object.keys(data.ids).map(key => data.ids[key]);
let categoryIdList = Object.keys(data.ids).map(key => data.ids[key]);
this.categoryNameList = Object.keys(data.names).map(key => data.names[key]);
let halfLength = Math.floor(categoryIdList.length / 2);
this.leftCategoryIdList = categoryIdList.splice(0, halfLength);
this.rightCategoryIdList = categoryIdList;
}
getMinDate() {
@ -189,6 +194,7 @@ export class AddDataComponent implements OnInit {
purchase_time : purchaseTime,
organisation_id : this.organisationId,
category : this.categoryId,
essential : this.essentialPurchase,
};
break;
case 2:
@ -197,7 +203,7 @@ export class AddDataComponent implements OnInit {
transaction_value : this.amount,
purchase_time : purchaseTime,
organisation_id : this.organisationId,
category : this.categoryId,
essential : this.essentialPurchase,
};
break;
case 3:
@ -209,7 +215,7 @@ export class AddDataComponent implements OnInit {
street_name : this.submitOrg.street_name,
town : this.submitOrg.town,
postcode : this.submitOrg.postcode,
category : this.categoryId,
essential : this.essentialPurchase,
};
break;
}

View file

@ -0,0 +1,172 @@
<div class="animated fadeIn">
<div class=row>
<div class="col-md-6">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Purchases Last Week</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="horizontal-bars type-2">
<li *ngIf="weekList1 !== undefined">
<span class="title">Essential Purchases</span>
<span class="value">{{ ( weekEssential1.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (weekEssential1.value || 0 ) / weekListValueSum1 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(weekEssential1.value || 0 ) / weekListValueSum1 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li *ngFor="let categoryEntry of weekList1 | slice:0:categoryLimit1; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category - 1] || 'Uncategorised' }}</span>
<span class="value">{{ ( categoryEntry.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (categoryEntry.value || 0 ) / weekListValueSum1 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(categoryEntry.value || 0 ) / weekListValueSum1 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<div *ngIf="weekList1 !== undefined">
<li *ngIf="weekList1.length > categoryLimit1 && disableCategoryButton1 == false" class="divider text-center">
<button type="button" class="btn btn-sm btn-link text-muted" (click)="loadMore1()"><i class="icon-options"></i></button>
</li>
</div>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
<div class="col-md-6">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Purchases 1 Week Ago</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="horizontal-bars type-2">
<li *ngIf="weekList2 !== undefined">
<span class="title">Essential Purchases</span>
<span class="value">{{ ( weekEssential2.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (weekEssential2.value || 0 ) / weekListValueSum2 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(weekEssential2.value || 0 ) / weekListValueSum2 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li *ngFor="let categoryEntry of weekList2 | slice:0:categoryLimit2; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category - 1] || 'Uncategorised' }}</span>
<span class="value">{{ ( categoryEntry.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (categoryEntry.value || 0 ) / weekListValueSum2 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(categoryEntry.value || 0 ) / weekListValueSum2 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<div *ngIf="!weekList2 == null">
<li *ngIf="weekList2.length > categoryLimit2 && disableCategoryButtonFirst == false" class="divider text-center">
<button type="button" class="btn btn-sm btn-link text-muted" (click)="loadMore2()"><i class="icon-options"></i></button>
</li>
</div>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
<div class="col-md-6">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Purchases 2 Weeks Ago</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="horizontal-bars type-2">
<li *ngIf="weekList3 !== undefined">
<span class="title">Essential Purchases</span>
<span class="value">{{ ( weekEssential1.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (weekEssential3.value || 0 ) / weekListValueSum3 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(weekEssential3.value || 0 ) / weekListValueSum3 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li *ngFor="let categoryEntry of weekList3 | slice:0:categoryLimit3; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category - 1] || 'Uncategorised' }}</span>
<span class="value">{{ ( categoryEntry.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (categoryEntry.value || 0 ) / weekListValueSum3 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(categoryEntry.value || 0 ) / weekListValueSum3 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<div *ngIf="weekList3 !== undefined">
<li *ngIf="weekList3.length > categoryLimit3 && disableCategoryButtonFirst == false" class="divider text-center">
<button type="button" class="btn btn-sm btn-link text-muted" (click)="loadMore3()"><i class="icon-options"></i></button>
</li>
</div>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
<div class="col-md-6">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Purchases 3 Weeks Ago</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="horizontal-bars type-2">
<li *ngIf="weekList4 !== undefined">
<span class="title">Essential Purchases</span>
<span class="value">{{ ( weekEssential4.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (weekEssential4.value || 0 ) / weekListValueSum4 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(weekEssential4.value || 0 ) / weekListValueSum4 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li *ngFor="let categoryEntry of weekList4 | slice:0:categoryLimit4; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category - 1] || 'Uncategorised' }}</span>
<span class="value">{{ ( categoryEntry.value || 0 ) | currency:'GBP':'symbol':'1.2-2' }} <span class="text-muted small">
({{ (categoryEntry.value || 0 ) / weekListValueSum4 | percent:'1.0-0' }})</span></span>
<div class="bars">
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-success" role="progressbar"
[style.width]="(categoryEntry.value || 0 ) / weekListValueSum4 | percent:'1.0-0'" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<div *ngIf="!weekList4 == null">
<li *ngIf="weekList4.length > categoryLimit4 && disableCategoryButtonFirst == false" class="divider text-center">
<button type="button" class="btn btn-sm btn-link text-muted" (click)="loadMore4()"><i class="icon-options"></i></button>
</li>
</div>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
</div><!--/.row-->
</div>

View file

@ -0,0 +1,137 @@
import { Directive, Component, OnInit } from '@angular/core';
import { ApiService } from '../providers/api-service';
import { DataType } from '../shared/data-types.enum';
import * as moment from 'moment';
import 'rxjs/add/operator/map';
@Component({
templateUrl: 'category-month.component.html'
})
export class CategoryMonthComponent implements OnInit {
disableCategoryButton1: boolean = false;
disableCategoryButton2: boolean = false;
disableCategoryButton3: boolean = false;
disableCategoryButton4: boolean = false;
weekPurchaseList = {
first: 0,
};
weekList1 = [];
weekList2 = [];
weekList3 = [];
weekList4 = [];
weekListValueSum1: number = 0;
weekListValueSum2: number = 0;
weekListValueSum3: number = 0;
weekListValueSum4: number = 0;
weekEssential1: number = 0;
weekEssential2: number = 0;
weekEssential3: number = 0;
weekEssential4: number = 0;
categoryList: number[] = [];
dayList: any[] = [];
valueList: number[] = [];
myWeek1: any;
myWeek2: any;
myWeek3: any;
myWeek4: any;
categoryIdList: number[] = [];
categoryNameList: string[] = [];
categoryLimit1: number = 6;
categoryLimit2: number = 6;
categoryLimit3: number = 6;
categoryLimit4: number = 6;
constructor(
private api: ApiService,
) {
this.setDate();
this.api.categoryList().subscribe(
result => {
this.setCategoryList(result.categories);
},
error => {
console.log('Retrieval Error');
console.log( error._body );
}
);
this.api.categoryTransactionList().subscribe(
result => {
this.setData(result);
},
error => {
console.log('Retrieval Error');
console.log( error._body );
}
);
}
ngOnInit(): void {
}
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]);
}
private setDate () {
this.myWeek1 = moment().startOf('isoWeek').format('YYYY-MM-DD');
this.myWeek2 = moment(this.myWeek1).subtract(1, 'weeks').format('YYYY-MM-DD');
this.myWeek3 = moment(this.myWeek2).subtract(1, 'weeks').format('YYYY-MM-DD');
this.myWeek4 = moment(this.myWeek3).subtract(1, 'weeks').format('YYYY-MM-DD');
}
private setData (data: any) {
function prop<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
this.weekList1 = prop(data.data.categories, this.myWeek1);
this.weekList2 = prop(data.data.categories, this.myWeek2);
this.weekList3 = prop(data.data.categories, this.myWeek3);
this.weekList4 = prop(data.data.categories, this.myWeek4);
this.getMaxValue(this.weekList1, this.weekList2, this.weekList3, this.weekList4);
this.weekEssential1 = prop(data.data.essentials, this.myWeek1);
console.log(this.weekEssential1);
this.weekEssential2 = prop(data.data.essentials, this.myWeek2);
this.weekEssential3 = prop(data.data.essentials, this.myWeek3);
this.weekEssential4 = prop(data.data.essentials, this.myWeek4);
}
private getMaxValue (data1: any,
data2: any,
data3: any,
data4: any) {
if (data1) {
this.weekListValueSum1 = data1.reduce(function (s, a) {return s + a.value;}, 0);
}
if (data2) {
this.weekListValueSum2 = data2.reduce(function (s, a) {return s + a.value;}, 0);
}
if (data3) {
this.weekListValueSum3 = data3.reduce(function (s, a) {return s + a.value;}, 0);
}
if (data4) {
this.weekListValueSum4 = data4.reduce(function (s, a) {return s + a.value;}, 0);
}
}
private loadMore1 () {
this.disableCategoryButton1 = true;
this.categoryLimit1 = 20;
}
private loadMore2 () {
this.disableCategoryButton2 = true;
this.categoryLimit2 = 20;
}
private loadMore3 () {
this.disableCategoryButton3 = true;
this.categoryLimit3 = 20;
}
private loadMore4 () {
this.disableCategoryButton4 = true;
this.categoryLimit4 = 20;
}
}

View file

@ -94,7 +94,7 @@
<strong>{{ sectorPurchases[i] || 'N/A' }}</strong>
</div>
</li>
<li *ngIf="sectorLetters.length > 10 && disableSectorButton == false" class="divider text-center">
<li *ngIf="sectorLetters.length > sectorLimit && disableSectorButton == false" class="divider text-center">
<button type="button" class="btn btn-sm btn-link text-muted" (click)="loadMore()"><i class="icon-options"></i></button>
</li>
</ul>

View file

@ -168,7 +168,7 @@ export class DashboardCustomerComponent implements OnInit {
this.sectorPurchases = Object.keys(data.purchases).map(key => data.purchases[key]);
}
public loadMore () {
private loadMore () {
this.disableSectorButton = true;
this.sectorLimit = 22;
}

View file

@ -16,6 +16,7 @@ import { AccountEditComponent } from './account-edit.component';
import { AddDataComponent } from './add-data.component';
import { FeedbackComponent } from './feedback.component';
import { TransactionLogComponent } from './transaction-log.component';
import { CategoryMonthComponent } from './category-month.component';
import { PayrollLogComponent } from './payroll-log.component';
import { LeaderboardComponent } from './leaderboard.component';
import { MapComponent } from './map.component';
@ -61,6 +62,7 @@ import { environment } from '../../environments/environment';
OrgResultComponent,
OrgTableComponent,
TransactionLogComponent,
CategoryMonthComponent,
TransactionResultComponent,
PayrollLogComponent,
PayrollResultComponent,

View file

@ -12,6 +12,7 @@ import { AccountEditComponent } from './account-edit.component';
import { AddDataComponent } from './add-data.component';
import { FeedbackComponent } from './feedback.component';
import { TransactionLogComponent } from './transaction-log.component';
import { CategoryMonthComponent } from './category-month.component';
import { PayrollLogComponent } from './payroll-log.component';
import { LeaderboardComponent } from './leaderboard.component';
import { MapComponent } from './map.component';
@ -58,6 +59,11 @@ const routes: Routes = [
component: TransactionLogComponent,
data: { title: 'Transaction Log' },
},
{
path: 'category-month',
component: CategoryMonthComponent,
data: { title: 'Budget' },
},
{
path: 'map',
component: MapComponent,

View file

@ -82,6 +82,14 @@
</div>
</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/category-month']">
<div class="row no-gutters align-items-center">
<div class="col-2"><i class="icon-basket"></i></div>
<div class="col-10">Budget</div>
</div>
</a>
</li>
<li *ngIf="accountType == 'organisation'" class="nav-item">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/payroll-log']">
<div class="row no-gutters align-items-center">

View file

@ -127,6 +127,17 @@ export class ApiService {
);
}
// Basic Customer User stats API
public categoryTransactionList() {
const key = this.sessionKey;
return this.http.post<any>(
this.apiUrl + '/stats/category',
{
session_key : key,
}
);
}
// Searches organisations used for transaction submission
public search(data) {