From cd5e726089f65cd8a313e78d3175f09ce7768952 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 1 Nov 2024 16:47:39 +0100 Subject: [PATCH] New version of assets --- .../asset-calculator.component.html | 117 ++++++++---------- .../asset-calculator.component.ts | 2 +- src/app/asset-calculator/assets/asset.ts | 8 -- src/app/fixed-asset/fixed-asset.component.ts | 89 +++++++++---- 4 files changed, 119 insertions(+), 97 deletions(-) diff --git a/src/app/asset-calculator/asset-calculator.component.html b/src/app/asset-calculator/asset-calculator.component.html index 0d05ca5..adb8b39 100644 --- a/src/app/asset-calculator/asset-calculator.component.html +++ b/src/app/asset-calculator/asset-calculator.component.html @@ -1,11 +1,4 @@ - -
@@ -13,76 +6,76 @@
-
-
-
- -
-
- - - @if(assetsDepreciationFormGroup.get('initialValueSet')?.invalid && assetsDepreciationFormGroup.get('initialValueSet')?.touched){ -
Wartość niepoprawna!. Podaj kwotę w zł np 3000.05 (czyli 3000 zł i 5 gr)
- }@else{ - } - -
-
+ +
+
+ +
+
+ + + @if(assetsDepreciationFormGroup.get('initialValueSet')?.invalid && assetsDepreciationFormGroup.get('initialValueSet')?.touched){ +
Wartość niepoprawna!. Podaj kwotę w zł np 3000.05 (czyli 3000 zł i 5 gr)
+ }@else{ + } + +
+
-
-
- -
-
- -
-
- -
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
-
-
- -
-
- - -
+
+
+
+
+
+ +
+
-
-
- + @if( TypeDepreciation.digressive === typeDepreciation() ){ +
+
+
- +
- - @if( TypeDepreciation.digressive === typeDepreciation() ){ -
-
- -
-
- -
-
- } + } - -
+ +
diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index 322416f..99bff60 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -1,4 +1,4 @@ -import {Component, effect, computed, OnInit, signal } from '@angular/core'; +import {Component, effect, OnInit, signal } from '@angular/core'; import {ReactiveFormsModule, FormGroup, Validators, FormControl, FormArray} from '@angular/forms'; import {CurrencyPipe,DecimalPipe,PercentPipe, NgFor} from '@angular/common'; diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts index f18f261..0546f8e 100644 --- a/src/app/asset-calculator/assets/asset.ts +++ b/src/app/asset-calculator/assets/asset.ts @@ -65,16 +65,8 @@ export class AssetsContainer{ assets: Map = new Map(); constructor(){ - this.initDefault(); } - initDefault(){ - const yearMonth = new YearMonth('2024-11'); - this.assets.set('Inv01', new Asset( 1000, yearMonth, TypeDepreciation.linear, 20 ) ); - this.assets.set('Inv02', new Asset( 3000, yearMonth, TypeDepreciation.linear, 20 ) ); - this.assets.set('Inv03', new Asset( 5000, yearMonth, TypeDepreciation.linear, 15 ) ); - - } delete( nrInv: string ){ this.assets.delete(nrInv); diff --git a/src/app/fixed-asset/fixed-asset.component.ts b/src/app/fixed-asset/fixed-asset.component.ts index a18e6be..bab702c 100644 --- a/src/app/fixed-asset/fixed-asset.component.ts +++ b/src/app/fixed-asset/fixed-asset.component.ts @@ -1,66 +1,103 @@ import { Component } from '@angular/core'; -import { AssetsContainer, Asset } from '../asset-calculator/assets/asset'; +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: [], + imports: [ReactiveFormsModule], template:`
-

Lista środków trwałych( prace w toku )

+

Lista środków trwałych

- + - - + + - - @for( asset of assetsContainer.getNrAssets(); track asset[0] ) { - - - - - - + + + @for( assetFormGroup of assetFormArray.controls; track $index ) { + + + + + + + - } + + }
Numer inwentarzowyZmiany wartościWartość Metoda amortyzacjiPlanStawka
{{asset[0]}} - 1 zmian - 1 metodWylicz plan - -
+ + + +
- +
`, styleUrl: './fixed-asset.component.css' }) export class FixedAssetComponent { + + static indexNr = 1; + + TypeDepreciation = TypeDepreciation; + assetsContainer : AssetsContainer; + + assetFormArray : FormArray; + - constructor(){ + constructor( private fb: FormBuilder ){ + this.assetsContainer = new AssetsContainer (); + this.assetFormArray = this.fb.array([]) } - initDefault(){ - this.assetsContainer.initDefault(); + + delete( index : number ){ + this.assetFormArray.removeAt( index ); } - delete( nrInv : string){ - this.assetsContainer.delete( nrInv ); + 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 ); + + } }