Plan amortyzacji
@@ -108,7 +134,7 @@
- @for (position of positions.positions; track $index) {
+ @for (position of amortizations.positions; track $index) {
| {{$index+1}} |
{{ position.when.year }} |
@@ -116,7 +142,7 @@
{{ position.calculatedDepreciation | number:'1.2-2' }} |
{{ position.sum | number:'1.2-2' }} |
- @if( 12 == position.when.month || $index == positions.positions.length-1){
+ @if( 12 == position.when.month || $index == amortizations.positions.length-1){
|
|
@@ -132,5 +158,7 @@
+
+
diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts
index 4a6b23b..c8b9d18 100644
--- a/src/app/asset-calculator/asset-calculator.component.ts
+++ b/src/app/asset-calculator/asset-calculator.component.ts
@@ -1,6 +1,6 @@
-import {Component, effect, OnInit, signal } from '@angular/core';
-import {ReactiveFormsModule, FormGroup, Validators, FormControl} from '@angular/forms';
-import {CurrencyPipe,DecimalPipe,PercentPipe} from '@angular/common';
+import {Component, effect, computed, OnInit, signal } from '@angular/core';
+import {ReactiveFormsModule, FormGroup, Validators, FormControl, FormArray} from '@angular/forms';
+import {CurrencyPipe,DecimalPipe,PercentPipe, NgFor} from '@angular/common';
import {AssetsModule} from './assets/assets.module'
import {Asset, Positions, AssetPlanPosition, TypeDepreciation, YearMonth, AssetLifeChange } from './assets/asset';
import {AssetService} from './assets/service/asset.service'
@@ -8,7 +8,7 @@ import {AssetService} from './assets/service/asset.service'
@Component({
selector: 'app-asset-calculator',
standalone: true,
- imports: [ CurrencyPipe, DecimalPipe, PercentPipe, AssetsModule, ReactiveFormsModule ] ,
+ imports: [ CurrencyPipe, DecimalPipe, PercentPipe, AssetsModule, ReactiveFormsModule, NgFor ] ,
templateUrl: "asset-calculator.component.html",
styleUrl: 'asset-calculator.component.css'
})
@@ -16,8 +16,6 @@ export class AssetCalculatorComponent implements OnInit{
TypeDepreciation = TypeDepreciation;
- // Asset{}
-
initialValueAsset = signal( 3000 );
depreciationRate = signal( 20 );
year = signal( 2024 );
@@ -25,51 +23,58 @@ export class AssetCalculatorComponent implements OnInit{
typeDepreciation = signal< TypeDepreciation>( TypeDepreciation.linear );
factorValue = signal( 2 );
- // Asset
+ life : AssetLifeChange[] =[] ;
+ lifeFormArray = new FormArray([]);
- addChangeValue() {
- throw new Error('Method not implemented.');
- }
-
+ amortizations = new Positions();
- positions = new Positions();
-
- assetsDepreciationForm = new FormGroup( {
+ assetsDepreciationFormGroup = new FormGroup( {
initialValueAsset : new FormControl( this.initialValueAsset(), [ Validators.required, this.currencyValidator ]),
depreciationRate : new FormControl( this.depreciationRate() ) ,
year : new FormControl( this.year() ),
month : new FormControl( this.month() ),
typeDepreciation : new FormControl( this.typeDepreciation ),
- factorValue : new FormControl( this.factorValue, [Validators.required,Validators.max(2)] )
+ factorValue : new FormControl( this.factorValue, [Validators.required,Validators.max(2)] ),
+
} );
constructor(private assetService : AssetService ){
- effect( () => { this.calculate(); });
+
+ effect( () => { this.calculate(); });
+
}
ngOnInit(): void{
-
+ this.lifeFormArray.valueChanges.subscribe((value) => {
+ this.calculate();
+ })
}
calculate(){
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);
+ asset.addChange( creationlifeChange );
+ for( let changeControlGroup of this.lifeFormArray.controls ){
+ const initialValueAsset = changeControlGroup.get('initialValueAsset')?.value;
+ const year = changeControlGroup.get('year')?.value;
+ const month= changeControlGroup.get('month')?.value
+ asset.addChange( new AssetLifeChange( new YearMonth( year, month ), initialValueAsset, 0, 0 )) ;
+ }
this.calculateForAsset( asset );
}
calculateForAsset( asset : Asset ) {
this.assetService.calculate( asset ).subscribe(
- positions => { this.positions=positions; this.calculateToValues() });
+ positions => { this.amortizations=positions; this.calculateToValues() });
}
calculateToValues() {
let sum :number = 0;
let sumThisYear: number = 0;
- for(let position of this.positions.positions ){
+ for(let position of this.amortizations.positions ){
position.calculatedDepreciation = position.calculatedDepreciation *0.01;
sum += position.calculatedDepreciation;
@@ -96,5 +101,28 @@ export class AssetCalculatorComponent implements OnInit{
return regex.test(value) ? null : { invalidCurrency: true };
}
+ // lifeSignal = signal(this.lifeFormArray);
+
+ // changeValuCount = computed(() => this.lifeSignal().length);
+
+
+ addChangeValue() {
+ const change = new AssetLifeChange(new YearMonth( this.year(), this.month()), 1000, 0, 0 );
+
+ const newFormGroup = new FormGroup( {
+ initialValueAsset: new FormControl( change.initial ),
+ year : new FormControl( change.when.year ),
+ month : new FormControl( change.when.month )
+ } )
+
+ this.lifeFormArray.push(newFormGroup);
+
+ // this.lifeSignal.set( this.lifeFormArray );
+ }
+
+ removeChange(index: number) {
+
+ this.lifeFormArray.removeAt(index);
+ }
}
diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts
index 733fb70..95282aa 100644
--- a/src/app/asset-calculator/assets/asset.ts
+++ b/src/app/asset-calculator/assets/asset.ts
@@ -41,7 +41,7 @@ export class Asset {
life : AssetLifeChange[]=[];
- addChange( change : AssetLifeChange){
+ addChange( change : AssetLifeChange ){
this.life.push( change );
}