-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added gain loss view and functionality
- Loading branch information
1 parent
047858a
commit e509e2c
Showing
7 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class GainLoss { | ||
market: number; | ||
purchase: number; | ||
difference: number; | ||
percent: number; | ||
growth: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h3>Percent Gain or Loss on Investment</h3> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">Current Value</label> | ||
<div class="control"> | ||
<input (keyup)="calculatePercent()" [(ngModel)]="GainLoss.market" class="input" type="text"> | ||
</div> | ||
</div> | ||
<div class="field"> | ||
<label class="label">Purchase Price</label> | ||
<div class="control"> | ||
<input (keyup)="calculatePercent()" [(ngModel)]="GainLoss.purchase" class="input" type="text"> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="column"> | ||
<h1>Yield</h1> | ||
<h3>{{ GainLoss.percent }}% {{ GainLoss.growth }}</h3> | ||
</div> | ||
<div class="column"> | ||
<p> | ||
By entering a purchase price and the current value of an asset you can calculate what percent you have gained or lost on an particular asset. | ||
</p> | ||
</div> | ||
</div> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { GainLossComponent } from './gain-loss.component'; | ||
|
||
describe('GainLossComponent', () => { | ||
let component: GainLossComponent; | ||
let fixture: ComponentFixture<GainLossComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ GainLossComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GainLossComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { GainLoss } from '../gain-loss' | ||
|
||
@Component({ | ||
selector: 'app-gain-loss', | ||
templateUrl: './gain-loss.component.html', | ||
styleUrls: ['./gain-loss.component.scss'] | ||
}) | ||
export class GainLossComponent implements OnInit { | ||
|
||
GainLoss: GainLoss = { | ||
market: 0, | ||
purchase: 0, | ||
difference: 0, | ||
percent: 0, | ||
growth: '' | ||
} | ||
|
||
calculatePercent() { | ||
this.GainLoss.difference = this.GainLoss.market - this.GainLoss.purchase; | ||
|
||
if (this.GainLoss.difference < 0) { | ||
this.GainLoss.growth = 'loss'; | ||
} else { | ||
this.GainLoss.growth = 'gain'; | ||
} | ||
|
||
this.GainLoss.percent = Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) < 0 ? -Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) : Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) ; | ||
|
||
} | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |