From 1509538afbde106d81395722db2516b88cb4a8e0 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 4 Nov 2024 09:27:33 +0100 Subject: [PATCH] Some changes with row life of asset --- .../asset-calculator/asset-calculator.component.ts | 12 ++++++++++-- src/app/asset-calculator/assets/asset.ts | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index aebe98a..e7c4825 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -71,20 +71,28 @@ interface FormValues { factorValue : asset.factorValue, }) for( let i = 1; i < asset.life.length; i++ ){ + this.addChangeValue(); - // /this.lifeFormArray.controls[ i -1 ]..patchValue( asset.life[i].initial ); + + const row = this.lifeFormArray.controls[ i -1 ] as FormGroup; + row.get( 'initialValueAsset' )?.setValue(asset.life[i].initial); + // row.get( 'year_month' )?.setValue( asset.life[i].when.toFormValue()); + + } } } private controlsToAsset() : Asset { + const formValues = this.assetsDepreciationFormGroup.value as FormValues; const when = new YearMonth( formValues.year_month ); const asset = new Asset( formValues.depreciationRate, when, formValues.typeDepreciation, formValues.factorValue ); const creationlifeChange = new AssetLifeChange(when, formValues.initialValueAsset , 0, 0); asset.addChange( creationlifeChange ); - for (let changeControlGroup of this.lifeFormArray.controls) { + + for( let changeControlGroup of this.lifeFormArray.controls ) { const initialValueAsset = changeControlGroup.get('initialValueAsset')?.value; const year_month = changeControlGroup.get('year_month')?.value; asset.addChange(new AssetLifeChange(new YearMonth(year_month), initialValueAsset, 0, 0)); diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts index 0546f8e..c827b6f 100644 --- a/src/app/asset-calculator/assets/asset.ts +++ b/src/app/asset-calculator/assets/asset.ts @@ -12,6 +12,9 @@ export class YearMonth{ this.month =month; } + toFormValue(){ + return this.year + "-" + this.month; + } }