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.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();

View File

@ -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;