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 5f3c4c927f
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>
</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">
<label class="col-md-3 form-control-label" for="text-input">Budget Type</label>
<div class="col-md-9">

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;
@ -88,12 +89,9 @@ export class AddDataComponent implements OnInit {
private setCategoryList(data: any) {
let categoryIdList = Object.keys(data.ids).map(key => data.ids[key]);
this.categoryNameList = Object.keys(data.names).map(key => data.names[key]);
console.log(categoryIdList);
let halfLength = Math.floor(categoryIdList.length / 2);
this.leftCategoryIdList = categoryIdList.splice(0, halfLength);
console.log(this.leftCategoryIdList);
this.rightCategoryIdList = categoryIdList;
console.log(this.rightCategoryIdList);
}
getMinDate() {
@ -196,6 +194,7 @@ export class AddDataComponent implements OnInit {
purchase_time : purchaseTime,
organisation_id : this.organisationId,
category : this.categoryId,
essential : this.essentialPurchase,
};
break;
case 2:
@ -204,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:
@ -216,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

@ -10,8 +10,19 @@
</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] || '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">
({{ (categoryEntry.value || 0 ) / weekListValueSum1 | percent:'1.0-0' }})</span></span>
<div class="bars">
@ -41,8 +52,19 @@
</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] || '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">
({{ (categoryEntry.value || 0 ) / weekListValueSum2 | percent:'1.0-0' }})</span></span>
<div class="bars">
@ -72,8 +94,19 @@
</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] || '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">
({{ (categoryEntry.value || 0 ) / weekListValueSum3 | percent:'1.0-0' }})</span></span>
<div class="bars">
@ -103,8 +136,19 @@
</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] || '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">
({{ (categoryEntry.value || 0 ) / weekListValueSum4 | percent:'1.0-0' }})</span></span>
<div class="bars">

View file

@ -26,6 +26,10 @@ export class CategoryMonthComponent implements OnInit {
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[] = [];
@ -84,11 +88,16 @@ export class CategoryMonthComponent implements OnInit {
function prop<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
this.weekList1 = prop(data.data, this.myWeek1);
this.weekList2 = prop(data.data, this.myWeek2);
this.weekList3 = prop(data.data, this.myWeek3);
this.weekList4 = prop(data.data, this.myWeek4);
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,