Merge pull request #66 from Pear-Trading/finn/essentialpurchase

added essential purchase
This commit is contained in:
Finn 2018-03-02 17:00:17 +00:00 committed by GitHub
commit db5a712a5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 13 deletions

View file

@ -24,6 +24,15 @@
<span class="help-block">Enter the amount spent, such as 5.35 for £5.35.</span> <span class="help-block">Enter the amount spent, such as 5.35 for £5.35.</span>
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-md-3 form-control-label" for="text-input">Essential Purchase</label>
<div class="col-md-9">
<div class="input-group">
<input type="checkbox" class="mr-auto" [(ngModel)]="essentialPurchase" (ngModelChange)="transactionFormValidate()">
</div>
<span class="help-block">Tick if the purchase is deemed an essential purchase for budgeting purposes.</span>
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<label class="col-md-3 form-control-label" for="text-input">Budget Type</label> <label class="col-md-3 form-control-label" for="text-input">Budget Type</label>
<div class="col-md-9"> <div class="col-md-9">

View file

@ -32,6 +32,7 @@ export class AddDataComponent implements OnInit {
amount: number; amount: number;
// Assumes Groceries is 1st category // Assumes Groceries is 1st category
categoryId: number = 1; categoryId: number = 1;
essentialPurchase = false;
transactionAdditionType = 1; transactionAdditionType = 1;
storeList = []; storeList = [];
showAddStore = false; showAddStore = false;
@ -88,12 +89,9 @@ export class AddDataComponent implements OnInit {
private setCategoryList(data: any) { private setCategoryList(data: any) {
let 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]); this.categoryNameList = Object.keys(data.names).map(key => data.names[key]);
console.log(categoryIdList);
let halfLength = Math.floor(categoryIdList.length / 2); let halfLength = Math.floor(categoryIdList.length / 2);
this.leftCategoryIdList = categoryIdList.splice(0, halfLength); this.leftCategoryIdList = categoryIdList.splice(0, halfLength);
console.log(this.leftCategoryIdList);
this.rightCategoryIdList = categoryIdList; this.rightCategoryIdList = categoryIdList;
console.log(this.rightCategoryIdList);
} }
getMinDate() { getMinDate() {
@ -196,6 +194,7 @@ export class AddDataComponent implements OnInit {
purchase_time : purchaseTime, purchase_time : purchaseTime,
organisation_id : this.organisationId, organisation_id : this.organisationId,
category : this.categoryId, category : this.categoryId,
essential : this.essentialPurchase,
}; };
break; break;
case 2: case 2:
@ -204,7 +203,7 @@ export class AddDataComponent implements OnInit {
transaction_value : this.amount, transaction_value : this.amount,
purchase_time : purchaseTime, purchase_time : purchaseTime,
organisation_id : this.organisationId, organisation_id : this.organisationId,
category : this.categoryId, essential : this.essentialPurchase,
}; };
break; break;
case 3: case 3:
@ -216,7 +215,7 @@ export class AddDataComponent implements OnInit {
street_name : this.submitOrg.street_name, street_name : this.submitOrg.street_name,
town : this.submitOrg.town, town : this.submitOrg.town,
postcode : this.submitOrg.postcode, postcode : this.submitOrg.postcode,
category : this.categoryId, essential : this.essentialPurchase,
}; };
break; break;
} }

View file

@ -10,8 +10,19 @@
</div><!--/.row--> </div><!--/.row-->
<div class="chart-wrapper"> <div class="chart-wrapper">
<ul class="horizontal-bars type-2"> <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;"> <li *ngFor="let categoryEntry of weekList1 | slice:0:categoryLimit1; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category] || 'Uncategorised' }}</span> <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"> <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> ({{ (categoryEntry.value || 0 ) / weekListValueSum1 | percent:'1.0-0' }})</span></span>
<div class="bars"> <div class="bars">
@ -41,8 +52,19 @@
</div><!--/.row--> </div><!--/.row-->
<div class="chart-wrapper"> <div class="chart-wrapper">
<ul class="horizontal-bars type-2"> <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;"> <li *ngFor="let categoryEntry of weekList2 | slice:0:categoryLimit2; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category] || 'Uncategorised' }}</span> <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"> <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> ({{ (categoryEntry.value || 0 ) / weekListValueSum2 | percent:'1.0-0' }})</span></span>
<div class="bars"> <div class="bars">
@ -72,8 +94,19 @@
</div><!--/.row--> </div><!--/.row-->
<div class="chart-wrapper"> <div class="chart-wrapper">
<ul class="horizontal-bars type-2"> <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;"> <li *ngFor="let categoryEntry of weekList3 | slice:0:categoryLimit3; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category] || 'Uncategorised' }}</span> <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"> <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> ({{ (categoryEntry.value || 0 ) / weekListValueSum3 | percent:'1.0-0' }})</span></span>
<div class="bars"> <div class="bars">
@ -103,8 +136,19 @@
</div><!--/.row--> </div><!--/.row-->
<div class="chart-wrapper"> <div class="chart-wrapper">
<ul class="horizontal-bars type-2"> <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;"> <li *ngFor="let categoryEntry of weekList4 | slice:0:categoryLimit4; let i=index;">
<span class="title">{{ categoryNameList[categoryEntry.category] || 'Uncategorised' }}</span> <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"> <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> ({{ (categoryEntry.value || 0 ) / weekListValueSum4 | percent:'1.0-0' }})</span></span>
<div class="bars"> <div class="bars">

View file

@ -26,6 +26,10 @@ export class CategoryMonthComponent implements OnInit {
weekListValueSum2: number = 0; weekListValueSum2: number = 0;
weekListValueSum3: number = 0; weekListValueSum3: number = 0;
weekListValueSum4: number = 0; weekListValueSum4: number = 0;
weekEssential1: number = 0;
weekEssential2: number = 0;
weekEssential3: number = 0;
weekEssential4: number = 0;
categoryList: number[] = []; categoryList: number[] = [];
dayList: any[] = []; dayList: any[] = [];
@ -84,11 +88,16 @@ export class CategoryMonthComponent implements OnInit {
function prop<T, K extends keyof T>(obj: T, key: K) { function prop<T, K extends keyof T>(obj: T, key: K) {
return obj[key]; return obj[key];
} }
this.weekList1 = prop(data.data, this.myWeek1); this.weekList1 = prop(data.data.categories, this.myWeek1);
this.weekList2 = prop(data.data, this.myWeek2); this.weekList2 = prop(data.data.categories, this.myWeek2);
this.weekList3 = prop(data.data, this.myWeek3); this.weekList3 = prop(data.data.categories, this.myWeek3);
this.weekList4 = prop(data.data, this.myWeek4); this.weekList4 = prop(data.data.categories, this.myWeek4);
this.getMaxValue(this.weekList1, this.weekList2, this.weekList3, this.weekList4); 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, private getMaxValue (data1: any,