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>
</form>
<input class="btn btn-secondary col-auto" name="addChangeValue"
[disabled]=assetsDepreciationForm.invalid (click)=addChangeValue() type="button" value="Dodaj zmianę wartości ">
</div>

View File

@ -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{

View File

@ -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;