From f930af39c120c41f14412416df96a5b072407471 Mon Sep 17 00:00:00 2001 From: Artur Date: Sun, 13 Oct 2024 18:48:46 +0200 Subject: [PATCH] Graphical changes in the interface to the depreciation calculator --- .../asset-calculator.component.html | 200 ++++++++++-------- .../asset-calculator.component.ts | 13 +- src/app/asset-calculator/assets/asset.ts | 2 +- 3 files changed, 128 insertions(+), 87 deletions(-) diff --git a/src/app/asset-calculator/asset-calculator.component.html b/src/app/asset-calculator/asset-calculator.component.html index 3ac6027..09b96d4 100644 --- a/src/app/asset-calculator/asset-calculator.component.html +++ b/src/app/asset-calculator/asset-calculator.component.html @@ -1,85 +1,119 @@ +
-

Kalkulator amortyzacyjny

-
-
- - - - - - - - - - - - - - - - - +

Kalkulator amortyzacyjny

+ +
+
+ +
+ +
+ + +
+
+ PLN +
+ @if(assetsDepreciationForm.get('initialValueSet')?.invalid && assetsDepreciationForm.get('initialValueSet')?.touched){ +
Wartość niepoprawna!. Podaj kwotę w zł np 3000.05 (czyli 3000 zł i 5 gr)
+ }@else{ + } +
+
+ +
+ +
+
+ % +
+
+
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ @if( TypeDepreciation.digressive === asset.type ){ +
+ +
+ +
+
+ } + + + + +
+
+
- - - -
Stawka amortyzacyjna %
Rok i miesiąc rozpoczęcia amortyzacjii - - - -
Metoda amortyzacji -
+ + + + + + + + + + + @for (position of positions.positions; track $index) { + + + + + + + + + + + } + +
LpRokMiesiącKwota odpisuLączny odpis
{{$index+1}}{{ position.when.year }}{{ position.when.month }}{{ position.calculatedDepreciation | number:'1.2-2' }}{{ position.sum | number:'1.2-2' }}
+
+
+ - @if( TypeDepreciation.digressive === asset.type ){ - - - - } - - - - - -
- - - - - - - - - - - - @for (position of positions.positions; track $index) { - - - - - - - - - - - } - -
LpRokMiesiącKwota odpisuLączny odpis
{{$index+1}}{{ position.when.year }}{{ position.when.month }}{{ position.calculatedDepreciation | number:'1.2-2' }}{{ position.sum | number:'1.2-2' }}
-
- - diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index 43735ea..5cf9003 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -16,10 +16,10 @@ export class AssetCalculatorComponent implements OnInit{ assetsDepreciationForm = new FormGroup( { - initialValueSet : new FormControl('20000.00'), + initialValueSet : new FormControl( '', [Validators.required, this.currencyValidator]), depreciationRate: new FormControl('') , - year : new FormControl('2022'), - month : new FormControl('10'), + year : new FormControl(''), + month : new FormControl(''), typeDepreciation: new FormControl( TypeDepreciation.linear ), factorValue : new FormControl( 2,[Validators.required,Validators.max(2)] ) } ); @@ -50,6 +50,13 @@ export class AssetCalculatorComponent implements OnInit{ return pos.when.year % 2 === 0 ? "table-light" : "table-dark"; } + // Walidator dla kwoty + currencyValidator(control: any) { + const value = control.value; + const regex = /^\d+(\.\d{1,2})?$/; // Akceptuje liczby z maksymalnie dwoma miejscami po przecinku + return regex.test(value) ? null : { invalidCurrency: true }; + } + ngOnInit(): void{ this.calculate(); } diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts index eec5eda..12b8cad 100644 --- a/src/app/asset-calculator/assets/asset.ts +++ b/src/app/asset-calculator/assets/asset.ts @@ -4,7 +4,7 @@ export enum TypeDepreciation{ } export class Asset { - initialValueAsset = '2000'; + initialValueAsset = 3000.00; year = 2024; month = 10;