import { Component } from '@angular/core';
import { AssetsContainer, Asset, TypeDepreciation, YearMonth } from '../asset-calculator/assets/asset';
import { ReactiveFormsModule, FormBuilder, FormGroup, Validators, FormControl, FormArray} from '@angular/forms';
@Component({
selector: 'app-fixed-asset',
standalone: true,
imports: [ReactiveFormsModule],
template:`
`,
styleUrl: './fixed-asset.component.css'
})
export class FixedAssetComponent {
static indexNr = 1;
TypeDepreciation = TypeDepreciation;
assetsContainer : AssetsContainer;
assetFormArray : FormArray;
constructor( private fb: FormBuilder ){
this.assetsContainer = new AssetsContainer ();
this.assetFormArray = this.fb.array([])
}
delete( index : number ){
this.assetFormArray.removeAt( index );
}
addNew(){
this.addNr("NrInv" + FixedAssetComponent.indexNr++ );
}
addNr( nrInv:string ):void{
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const year_month = year +'-'+month;
const yearMonth = new YearMonth( year_month ) ;
const asset = new Asset( 20, yearMonth, TypeDepreciation.linear, 10 );
const newRow= this.fb.group({
nr : [ nrInv ],
initialValue : [ 10000 ],
depreciationRate : [ 10 ],
typeDepreciation : [ TypeDepreciation.linear ],
year_month : [ year_month ]
})
this.assetFormArray.push( newRow );
}
}