diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index e7c4825..e25cab9 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -74,9 +74,12 @@ interface FormValues { this.addChangeValue(); - 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()); + const row : FormGroup = this.lifeFormArray.controls[ i - 1 ]; + const lifeChange : AssetLifeChange = asset.life[i]; + row.get( 'initialValueAsset' )?.setValue( lifeChange.initial); + const ym : YearMonth = lifeChange.when; + //const when_txt = ym.toFormValue(); + row.get( 'year_month' )?.setValue( lifeChange.when.year +'-' + lifeChange.when.month ); } diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts index c827b6f..4167b94 100644 --- a/src/app/asset-calculator/assets/asset.ts +++ b/src/app/asset-calculator/assets/asset.ts @@ -6,14 +6,21 @@ export enum TypeDepreciation{ export class YearMonth{ readonly year : number ; readonly month : number ; - constructor( year_month:string ){ - const [ year, month ] = year_month.split( '-').map(Number); - this.year = year; - this.month =month; + + constructor( year_month:string | YearMonth ){ + if (typeof year_month === 'string') { + const [year, month] = year_month.split('-').map(Number); + this.year = year; + this.month = month; + } else { + this.year = year_month.year; + this.month = year_month.month; + } } - toFormValue(){ - return this.year + "-" + this.month; + + toFormValue() { + return `${this.year}-${this.month.toString().padStart(2, '0')}`; } }