Prepare to version with many changes of Asset

This commit is contained in:
Artur 2024-10-25 00:07:46 +02:00
parent db7147571d
commit 8ec034d5e2
3 changed files with 64 additions and 36 deletions

View File

@ -87,6 +87,9 @@
--> -->
</div> </div>
</form> </form>
<input class="btn btn-secondary col-auto" name="addChangeValue"
[disabled]=assetsDepreciationForm.invalid (click)=addChangeValue() type="button" value="Dodaj zmianę wartości ">
</div> </div>

View File

@ -2,7 +2,7 @@ import {Component, effect, OnInit, signal } from '@angular/core';
import {ReactiveFormsModule, FormGroup, Validators, FormControl} from '@angular/forms'; import {ReactiveFormsModule, FormGroup, Validators, FormControl} from '@angular/forms';
import {CurrencyPipe,DecimalPipe,PercentPipe} from '@angular/common'; import {CurrencyPipe,DecimalPipe,PercentPipe} from '@angular/common';
import {AssetsModule} from './assets/assets.module' 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' import {AssetService} from './assets/service/asset.service'
@Component({ @Component({
@ -27,6 +27,11 @@ export class AssetCalculatorComponent implements OnInit{
// Asset // Asset
addChangeValue() {
throw new Error('Method not implemented.');
}
positions = new Positions(); positions = new Positions();
@ -40,7 +45,7 @@ export class AssetCalculatorComponent implements OnInit{
} ); } );
constructor(private assetService : AssetService ){ constructor(private assetService : AssetService ){
effect( () => { this.calculate();}); effect( () => { this.calculate(); });
} }
ngOnInit(): void{ ngOnInit(): void{
@ -48,14 +53,10 @@ export class AssetCalculatorComponent implements OnInit{
} }
calculate(){ calculate(){
const asset : Asset = { const when = new YearMonth( this.year(), this.month() )
initialValueAsset : this.initialValueAsset(), const asset = new Asset( this.depreciationRate(), when, this.typeDepreciation(), this.factorValue() )
depreciationRate : this.depreciationRate(), const creationlifeChange = new AssetLifeChange( when, this.initialValueAsset(), 0, 0 );
year : this.year(), asset.addChange(creationlifeChange);
month : this.month(),
type : this.typeDepreciation(),
factorValue : this.factorValue()
}
this.calculateForAsset( asset ); this.calculateForAsset( asset );
} }
@ -73,7 +74,7 @@ export class AssetCalculatorComponent implements OnInit{
sum += position.calculatedDepreciation; sum += position.calculatedDepreciation;
position.sum = sum; position.sum = sum;
if( 1 == position.when.month ){ if( 1 == position.when.month ){
sumThisYear = position.calculatedDepreciation; sumThisYear = position.calculatedDepreciation;
}else{ }else{

View File

@ -3,39 +3,63 @@ export enum TypeDepreciation{
linear, digressive linear, digressive
} }
export interface Asset { export class YearMonth{
initialValueAsset : number ; 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 ; depreciationRate : number ;
type : TypeDepreciation; type : TypeDepreciation;
year : number;
month : number;
factorValue : number; factorValue : number;
/* life : AssetLifeChange[]=[];
constructor( initialValueAsset : number,
depreciationRate : number,
typeDepreciation : TypeDepreciation, addChange( change : AssetLifeChange){
year : number, this.life.push( change );
month: number, }
factorValue: number ){
this.initialValueAsset = initialValueAsset; constructor( depreciationRate : number,
this.depreciationRate = depreciationRate; start : YearMonth,
this.type = typeDepreciation; type : TypeDepreciation,
this.year = year; factorValue : number ){
this.month = month; this.depreciationRate = depreciationRate;
this.start = start;
this.type = type;
this.factorValue = factorValue; this.factorValue = factorValue;
} }
*/
} }
export class YearMonth{
year : number = 0;
month :number = 0;
}
export class AssetPlanPosition{ export class AssetPlanPosition{
when : YearMonth = new YearMonth(); when : YearMonth = new YearMonth(0,0);
calculatedDepreciation : number = 0; calculatedDepreciation : number = 0;
sum:number = 0; sum:number = 0;
sumThisYear:number = 0; sumThisYear:number = 0;