diff --git a/src/app/asset-calculator/asset-calculator.component.html b/src/app/asset-calculator/asset-calculator.component.html index 60cced5..0187ebc 100644 --- a/src/app/asset-calculator/asset-calculator.component.html +++ b/src/app/asset-calculator/asset-calculator.component.html @@ -87,6 +87,9 @@ --> + + diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index 1c9d03c..4a6b23b 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -2,7 +2,7 @@ import {Component, effect, OnInit, signal } from '@angular/core'; import {ReactiveFormsModule, FormGroup, Validators, FormControl} from '@angular/forms'; import {CurrencyPipe,DecimalPipe,PercentPipe} from '@angular/common'; import {AssetsModule} from './assets/assets.module' -import {Asset, Positions, AssetPlanPosition, TypeDepreciation } from './assets/asset'; +import {Asset, Positions, AssetPlanPosition, TypeDepreciation, YearMonth, AssetLifeChange } from './assets/asset'; import {AssetService} from './assets/service/asset.service' @Component({ @@ -27,6 +27,11 @@ export class AssetCalculatorComponent implements OnInit{ // Asset + addChangeValue() { + throw new Error('Method not implemented.'); + } + + positions = new Positions(); @@ -40,7 +45,7 @@ export class AssetCalculatorComponent implements OnInit{ } ); constructor(private assetService : AssetService ){ - effect( () => { this.calculate();}); + effect( () => { this.calculate(); }); } ngOnInit(): void{ @@ -48,14 +53,10 @@ export class AssetCalculatorComponent implements OnInit{ } calculate(){ - const asset : Asset = { - initialValueAsset : this.initialValueAsset(), - depreciationRate : this.depreciationRate(), - year : this.year(), - month : this.month(), - type : this.typeDepreciation(), - factorValue : this.factorValue() - } + const when = new YearMonth( this.year(), this.month() ) + const asset = new Asset( this.depreciationRate(), when, this.typeDepreciation(), this.factorValue() ) + const creationlifeChange = new AssetLifeChange( when, this.initialValueAsset(), 0, 0 ); + asset.addChange(creationlifeChange); this.calculateForAsset( asset ); } @@ -73,7 +74,7 @@ export class AssetCalculatorComponent implements OnInit{ sum += position.calculatedDepreciation; position.sum = sum; - + if( 1 == position.when.month ){ sumThisYear = position.calculatedDepreciation; }else{ diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts index 9e9c758..733fb70 100644 --- a/src/app/asset-calculator/assets/asset.ts +++ b/src/app/asset-calculator/assets/asset.ts @@ -3,39 +3,63 @@ export enum TypeDepreciation{ linear, digressive } -export interface Asset { - initialValueAsset : number ; +export class YearMonth{ + readonly year : number ; + readonly month : number ; + constructor( year: number, month:number ){ + this.year = year; + this.month =month; + + } +} + + +export class AssetLifeChange{ + readonly when : YearMonth; + readonly initial : number; + readonly residual : number; + readonly depreciation : number; + + constructor( when : YearMonth, + initial : number, + residual : number, + depreciation: number ){ + this.when = when; + this.initial = initial; + this.residual = residual; + this.depreciation = depreciation; + } + +} + + +export class Asset { + start : YearMonth ; depreciationRate : number ; - type : TypeDepreciation; - - year : number; - month : number; - + type : TypeDepreciation; factorValue : number; -/* - constructor( initialValueAsset : number, - depreciationRate : number, - typeDepreciation : TypeDepreciation, - year : number, - month: number, - factorValue: number ){ - this.initialValueAsset = initialValueAsset; - this.depreciationRate = depreciationRate; - this.type = typeDepreciation; - this.year = year; - this.month = month; + life : AssetLifeChange[]=[]; + + + addChange( change : AssetLifeChange){ + this.life.push( change ); + } + + constructor( depreciationRate : number, + start : YearMonth, + type : TypeDepreciation, + factorValue : number ){ + this.depreciationRate = depreciationRate; + this.start = start; + this.type = type; this.factorValue = factorValue; } - */ + } -export class YearMonth{ - year : number = 0; - month :number = 0; -} export class AssetPlanPosition{ - when : YearMonth = new YearMonth(); + when : YearMonth = new YearMonth(0,0); calculatedDepreciation : number = 0; sum:number = 0; sumThisYear:number = 0;