New version with story life of Asset
This commit is contained in:
parent
7011fec720
commit
7b953c5761
|
|
@ -1,53 +1,77 @@
|
|||
package tk.artikus.assets.services;
|
||||
|
||||
import lombok.Data;
|
||||
import tk.artikus.assets.Asset;
|
||||
import tk.artikus.assets.AssetDepreciationMethod;
|
||||
import tk.artikus.assets.AssetLife;
|
||||
import tk.artikus.assets.AssetLifeChange;
|
||||
import tk.artikus.assets.tools.YearMonth;
|
||||
|
||||
@Data
|
||||
public class AssetFromAngular {
|
||||
|
||||
String initialValueAsset;
|
||||
|
||||
int year;
|
||||
int month;
|
||||
AssetDepreciationMethod.Type type;
|
||||
String depreciationRate;
|
||||
String factorValue;
|
||||
|
||||
Asset toAsset() {
|
||||
|
||||
Asset asset = new Asset();
|
||||
AssetLife assetLife = new AssetLife();
|
||||
|
||||
YearMonth yearMonth = YearMonth.builder().year( year ).month( month ).build();
|
||||
asset.setStartOfDepreciation( yearMonth );
|
||||
|
||||
long lDepreciation = txtToLong( depreciationRate );
|
||||
long lFactor = txtToLong( factorValue );
|
||||
AssetDepreciationMethod assetDepreciationMethod = AssetDepreciationMethod.builder().type( type )
|
||||
.factor( 0, lFactor ).rate( 0, lDepreciation ).build();
|
||||
|
||||
asset.setFromYearDepreciationMethod( yearMonth.getYear(), assetDepreciationMethod );
|
||||
|
||||
long initialValue = txtToLong( initialValueAsset );
|
||||
|
||||
AssetLifeChange assetLifeChange = new AssetLifeChange( yearMonth.prev(), initialValue, 0, 0 );
|
||||
assetLife.registerChange( assetLifeChange );
|
||||
|
||||
asset.setLife( assetLife );
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
private long txtToLong( String value ) {
|
||||
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() {
|
||||
return YearMonth.builder().year( year ).month( month ).build();
|
||||
}
|
||||
}
|
||||
|
||||
record AssetLifeChangeFromAngular(YearMonthFromAngular when, String initial, String residual, String depreciation) {
|
||||
AssetLifeChange toAssetLifeChange( boolean isFirst ) {
|
||||
|
||||
YearMonth yearMonth = when.toYearMonth();
|
||||
if( isFirst ) {
|
||||
yearMonth = yearMonth.prev();
|
||||
}
|
||||
return AssetLifeChange.builder().when( yearMonth )
|
||||
.initial( Convert.txtToLong(initial) )
|
||||
.residual( Convert.txtToLong( residual ) )
|
||||
.depreciation( Convert.txtToLong( depreciation ) )
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public record AssetFromAngular(
|
||||
YearMonthFromAngular start,
|
||||
String depreciationRate,
|
||||
AssetDepreciationMethod.Type type,
|
||||
String factorValue,
|
||||
AssetLifeChangeFromAngular[] life) {
|
||||
|
||||
Asset toAsset() {
|
||||
|
||||
Asset asset = new Asset();
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
AssetLife assetLife = new AssetLife();
|
||||
|
||||
for( AssetLifeChangeFromAngular l : life ) {
|
||||
AssetLifeChange assetLifeChange = l.toAssetLifeChange(assetLife.noStory() );
|
||||
assetLife.registerChange( assetLifeChange );
|
||||
|
||||
}
|
||||
asset.setLife( assetLife );
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,12 @@ public class YearMonth implements Comparable< YearMonth >{
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder yearMonth( YearMonth yearMonth ){
|
||||
this.year = yearMonth.getYear();
|
||||
this.month = yearMonth.getMonth();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder month( int month ){
|
||||
this.month = month;
|
||||
return this;
|
||||
|
|
|
|||
Loading…
Reference in New Issue