Skip to content

Commit

Permalink
budget summary
Browse files Browse the repository at this point in the history
  • Loading branch information
OchiengPaul442 committed Jan 16, 2024
1 parent 2dcbe04 commit ea8087d
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.summary-container {
display: flex;
flex-direction: column;
justify-content: flex-start;
margin-bottom: 1.2rem;

h2 {
margin: 0 0 0.5rem 0;
padding: 0;
font-size: 1rem;
font-weight: 500;
color: #000;
}

.summary-list {
display: flex;
gap: 1rem;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;

p {
margin: 0;
padding: 0;
font-size: 1rem;
font-weight: 400;
color: #000;

span {
font-weight: 501;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BudgetSummaryComponent } from './budget-summary.component';

describe('BudgetSummaryComponent', () => {
let component: BudgetSummaryComponent;
let fixture: ComponentFixture<BudgetSummaryComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BudgetSummaryComponent],
}).compileComponents();

fixture = TestBed.createComponent(BudgetSummaryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Component, Input, OnInit } from '@angular/core';

@Component({
selector: 'budget-summary',
template: `
<div class="summary-container">
<h2>Budget Summary</h2>
<div class="summary-list">
<p matTooltip="Total Family Labour Hours">
TFLH: <span>{{ totalFamilyLabourHours }}</span>
</p>
<p matTooltip="Total Inputs Value">
TIV: <span>{{ totalInputsValue }}</span>
</p>
<p matTooltip="Total Outputs Value">
TOV: <span>{{ totalOutputsValue }}</span>
</p>
<p matTooltip="Total Produce Consumed">
TPC: <span>{{ totalProduceConsumed }}</span>
</p>
<p matTooltip="Final Cash Balance">
FCB: <span>{{ finalCashBalance }}</span>
</p>
</div>
</div>
`,
styleUrls: ['./budget-summary.component.scss'],
})
export class BudgetSummaryComponent implements OnInit {
@Input() budgetData: any;

totalFamilyLabourHours: number = 0;
totalInputsValue: number = 0;
totalOutputsValue: number = 0;
totalProduceConsumed: number = 0;
finalCashBalance: number = 0;

ngOnInit(): void {
this.calculateSummary();
}

calculateSummary() {
this.budgetData.data.forEach((item) => {
item.familyLabour.forEach((member) => {
this.totalFamilyLabourHours += member.values.quantity;
});

item.inputs.forEach((input) => {
this.totalInputsValue += input.values.total;
});

item.outputs.forEach((output) => {
this.totalOutputsValue += output.values.total;
});

item.produceConsumed.forEach((consumed) => {
this.totalProduceConsumed += consumed.values.quantity;
});
});

this.finalCashBalance = this.totalOutputsValue - this.totalInputsValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PicsaCommonComponentsModule } from '@picsa/components';
import { PicsaDialogsModule } from '@picsa/shared/features';
import { PicsaDbModule } from '@picsa/shared/modules';
import { MobxAngularModule } from 'mobx-angular';
import { MatTooltipModule } from '@angular/material/tooltip';

import { BudgetMaterialModule } from '../material.module';
// Components
Expand All @@ -29,6 +30,7 @@ import { BudgetListItemComponent, BudgetListItemRenameDialog } from './list-item
import { BudgetShareDialogComponent } from './share-dialog/share-dialog.component';
import { BudgetPeriodSummaryComponent } from './summary/period-summary';
import { BudgetTableComponent } from './table/budget-table';
import { BudgetSummaryComponent } from './budget-summary/budget-summary.component';

const components = [
BudgetBalanceLegendComponent,
Expand All @@ -51,6 +53,7 @@ const components = [
BudgetPeriodSummaryComponent,
BudgetShareDialogComponent,
BudgetTableComponent,
BudgetSummaryComponent,
];

@NgModule({
Expand All @@ -65,6 +68,7 @@ const components = [
MobxAngularModule,
PicsaDbModule,
RouterModule,
MatTooltipModule,
],
exports: components,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<mat-card appearance="raised" style="margin-bottom: 10px; padding: 16px; cursor: pointer">
<div style="display: flex">
<budget-card-image class="small" [card]="budget.meta.enterprise"></budget-card-image>
<div style="flex: 1">
<div style="flex: 1; position: relative">
<mat-card-title>{{ budget.meta.title }}</mat-card-title>
<mat-card-content>{{ budget.meta.description }}</mat-card-content>
<mat-card-subtitle>{{ budget._created | date }}</mat-card-subtitle>
<budget-summary [budgetData]="budget"></budget-summary>
<mat-card-subtitle style="position: absolute; bottom: 0; right: 0"
>{{ budget._created | date }}</mat-card-subtitle
>
</div>
<button
mat-icon-button
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"execa": "^5.1.1",
"fs-extra": "^10.1.0",
"husky": "^8.0.0",
"husky": "^8.0.3",
"jest": "29.4.3",
"jest-circus": "^29.5.0",
"jest-environment-jsdom": "29.4.3",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14847,7 +14847,7 @@ __metadata:
languageName: node
linkType: hard

"husky@npm:^8.0.0":
"husky@npm:^8.0.3":
version: 8.0.3
resolution: "husky@npm:8.0.3"
bin:
Expand Down Expand Up @@ -16472,7 +16472,7 @@ __metadata:
"leaflet-draw@github:enketo/Leaflet.draw#ff730785db7fcccbf2485ffcf4dffe1238a7c617":
version: 1.0.4
resolution: "leaflet-draw@https://github.com/enketo/Leaflet.draw.git#commit=ff730785db7fcccbf2485ffcf4dffe1238a7c617"
checksum: 253998170af27f886d05b245c85429767e272647221daaf8d94ff5b86f75b8cbb96cc76a8a88492243166a214bc3b66b3ae704a81f74c862f09ac6c9495f731e
checksum: ff548d48c7562be501934f81303061204450e037005ef08591049951adb3044778a6e9c97daa6bac57827ce8864d4637046a8a5669fab5ab43feec7bb3bed86f
languageName: node
linkType: hard

Expand Down Expand Up @@ -19047,7 +19047,7 @@ __metadata:
glob: ^8.1.0
hls.js: ^1.4.12
html2canvas: ^1.4.1
husky: ^8.0.0
husky: ^8.0.3
intro.js: ^7.0.1
jest: 29.4.3
jest-circus: ^29.5.0
Expand Down

0 comments on commit ea8087d

Please sign in to comment.