New version of services

This commit is contained in:
Artur 2024-11-04 22:48:38 +01:00
parent 37dc0a7571
commit 55b76bb1a7
2 changed files with 35 additions and 22 deletions

View File

@ -6,16 +6,6 @@ import tk.artikus.assets.AssetLife;
import tk.artikus.assets.AssetLifeChange; import tk.artikus.assets.AssetLifeChange;
import tk.artikus.assets.tools.YearMonth; 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) { record YearMonthFromAngular(int year, int month) {
YearMonth toYearMonth() { 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) { record AssetLifeChangeFromAngular(YearMonthFromAngular when, String initial, String residual, String depreciation) {
AssetLifeChange toAssetLifeChange( boolean isFirst ) { 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( public record AssetFromAngular(
YearMonthFromAngular start, YearMonthFromAngular start,
String depreciationRate, AssetLifeChangeFromAngular[] life,
AssetDepreciationMethod.Type type, AssetDepreciationMethodFromAngular[] depreciationMethods) {
String factorValue,
AssetLifeChangeFromAngular[] life) {
Asset toAsset() { Asset toAsset() {
@ -52,13 +68,11 @@ public record AssetFromAngular(
YearMonth start = this.start.toYearMonth(); YearMonth start = this.start.toYearMonth();
asset.setStartOfDepreciation( start ); asset.setStartOfDepreciation( start );
long lDepreciation = Convert.txtToLong( depreciationRate ); for( AssetDepreciationMethodFromAngular depreciationMethodFromAngular : depreciationMethods ) {
long lFactor = Convert.txtToLong( factorValue ); asset.setFromYearDepreciationMethod(depreciationMethodFromAngular.getYear(),
AssetDepreciationMethod assetDepreciationMethod = AssetDepreciationMethod.builder().type( type ) depreciationMethodFromAngular.toAssetDepreciationMethod() );
.factor( 0, lFactor ).rate( 0, lDepreciation ).build(); }
asset.setFromYearDepreciationMethod( start.getYear(), assetDepreciationMethod );
AssetLife assetLife = new AssetLife(); AssetLife assetLife = new AssetLife();

View File

@ -2,7 +2,6 @@ package tk.artikus.assets.services;
import java.util.Collection; import java.util.Collection;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;