From 55b76bb1a7975e3eca55a8777a7c6af0b96ed560 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 4 Nov 2024 22:48:38 +0100 Subject: [PATCH] New version of services --- .../assets/services/AssetFromAngular.java | 56 ++++++++++++------- .../artikus/assets/services/AssetService.java | 1 - 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/tk/artikus/assets/services/AssetFromAngular.java b/src/main/java/tk/artikus/assets/services/AssetFromAngular.java index e9b43af..6427e2c 100644 --- a/src/main/java/tk/artikus/assets/services/AssetFromAngular.java +++ b/src/main/java/tk/artikus/assets/services/AssetFromAngular.java @@ -6,16 +6,6 @@ import tk.artikus.assets.AssetLife; import tk.artikus.assets.AssetLifeChange; import tk.artikus.assets.tools.YearMonth; -class Convert{ - static long txtToLong( String value ) { - value = value.replace( ",", "" ); - float fInitial = Float.parseFloat( value ); - long lValue = (long) (fInitial * 100); - return lValue; - } -} - - record YearMonthFromAngular(int year, int month) { YearMonth toYearMonth() { @@ -23,6 +13,21 @@ record YearMonthFromAngular(int year, int month) { } } +record AssetDepreciationMethodFromAngular( String year, AssetDepreciationMethod.Type type, String factor, String rate ) { + AssetDepreciationMethod toAssetDepreciationMethod(){ + return AssetDepreciationMethod.builder() + .type( type ) + .factor( 0, Convert.txtToLong( factor ) ) + .rate( 0, Convert.txtToLong( rate ) ) + .build(); + } + + int getYear() { + return (int)Convert.txtToInt( year ); + } + +} + record AssetLifeChangeFromAngular(YearMonthFromAngular when, String initial, String residual, String depreciation) { AssetLifeChange toAssetLifeChange( boolean isFirst ) { @@ -38,12 +43,23 @@ record AssetLifeChangeFromAngular(YearMonthFromAngular when, String initial, Str } } +class Convert{ + static long txtToLong( String value ) { + value = value.replace( ",", "" ); + float fInitial = Float.parseFloat( value ); + long lValue = (long) (fInitial * 100); + return lValue; + } + static int txtToInt( String value ) { + return Integer.valueOf( value ); + } +} + + public record AssetFromAngular( YearMonthFromAngular start, - String depreciationRate, - AssetDepreciationMethod.Type type, - String factorValue, - AssetLifeChangeFromAngular[] life) { + AssetLifeChangeFromAngular[] life, + AssetDepreciationMethodFromAngular[] depreciationMethods) { Asset toAsset() { @@ -52,13 +68,11 @@ public record AssetFromAngular( YearMonth start = this.start.toYearMonth(); asset.setStartOfDepreciation( start ); - - long lDepreciation = Convert.txtToLong( depreciationRate ); - long lFactor = Convert.txtToLong( factorValue ); - AssetDepreciationMethod assetDepreciationMethod = AssetDepreciationMethod.builder().type( type ) - .factor( 0, lFactor ).rate( 0, lDepreciation ).build(); - - asset.setFromYearDepreciationMethod( start.getYear(), assetDepreciationMethod ); + + for( AssetDepreciationMethodFromAngular depreciationMethodFromAngular : depreciationMethods ) { + asset.setFromYearDepreciationMethod(depreciationMethodFromAngular.getYear(), + depreciationMethodFromAngular.toAssetDepreciationMethod() ); + } AssetLife assetLife = new AssetLife(); diff --git a/src/main/java/tk/artikus/assets/services/AssetService.java b/src/main/java/tk/artikus/assets/services/AssetService.java index 036a967..3e115fc 100644 --- a/src/main/java/tk/artikus/assets/services/AssetService.java +++ b/src/main/java/tk/artikus/assets/services/AssetService.java @@ -2,7 +2,6 @@ package tk.artikus.assets.services; import java.util.Collection; -import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody;