@ -104,14 +104,13 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
if ( DataUtils . transactionUnicityCheck ( realm , date !! , amount , type ) ) {
val transaction = realm . copyToRealm ( Transaction ( ) )
transaction . date = date !!
transaction . amount = amount
transaction . type = type
val bankroll = Bankroll . getOrCreate ( realm , currencyCode !! , currencyCode = currencyCode !! , currencyRate = currencyRate )
transaction . bankroll = bankroll
return transaction
val bankroll = Bankroll . getOrCreate (
realm ,
currencyCode !! ,
currencyCode = currencyCode !! ,
currencyRate = currencyRate
)
return Transaction . newInstance ( realm , bankroll , date !! , type , amount )
} else {
Timber . d ( " Transaction already exists " )
}
@ -130,11 +129,14 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
var endDate : Date ? = null
var isLive = true
var bankrollName : String ? = null
var bankrollName = " "
var currencyCode : String ? = null
var currencyRate : Double ? = null
var additionalBuyins = 0.0 // rebuy + addon
var stackingIn : Double ? = null
var stackingOut : Double ? = null
fields . forEach { field ->
this . fieldMapping [ field ] ?. let { index ->
@ -158,7 +160,8 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
session . result ?. buyin = buyin
if ( session . type == Session . Type . TOURNAMENT . ordinal ) {
session . tournamentEntryFee = buyin
} else { }
} else {
}
}
is SessionField . CashedOut -> session . result ?. cashout = field . parse ( value )
is SessionField . SessionType -> {
@ -177,12 +180,14 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
is SessionField . Game -> {
if ( value . isNotEmpty ( ) ) {
session . game = realm . getOrCreate ( value )
} else { }
} else {
}
}
is SessionField . Location -> {
if ( value . isNotEmpty ( ) ) {
session . location = realm . getOrCreate ( value )
} else { }
} else {
}
}
is SessionField . Bankroll -> bankrollName = value
is SessionField . LimitType -> session . limit = Limit . getInstance ( value ) ?. ordinal
@ -200,7 +205,8 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
is SessionField . TournamentName -> {
if ( value . isNotEmpty ( ) ) {
session . tournamentName = realm . getOrCreate ( value )
} else { }
} else {
}
}
is SessionField . TournamentType -> session . tournamentType =
TournamentType . getValueForLabel ( value ) ?. ordinal
@ -208,6 +214,12 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
field . parse ( value ) ?. toInt ( )
is SessionField . CurrencyCode -> currencyCode = value
is SessionField . CurrencyRate -> currencyRate = field . parse ( value )
is SessionField . StackingIn -> {
stackingIn = field . parse ( value )
}
is SessionField . StackingOut -> {
stackingOut = field . parse ( value )
}
else -> {
}
}
@ -215,11 +227,12 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
}
if ( bankrollName . isNullOr Empty ( ) ) {
if ( bankrollName . isEmpty ( ) ) {
bankrollName = " Import "
}
session . bankroll = Bankroll . getOrCreate ( realm , bankrollName ?: " Import " , isLive , currencyCode , currencyRate )
val bankroll = Bankroll . getOrCreate ( realm , bankrollName , isLive , currencyCode , currencyRate )
session . bankroll = bankroll
session . result ?. buyin ?. let {
session . result ?. buyin = it + additionalBuyins
@ -233,6 +246,19 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
val managedSession = realm . copyToRealm ( session )
managedSession . startDate = startDate
managedSession . endDate = endDate
if ( stackingIn != null && stackingIn != 0.0 ) {
val type = TransactionType . getByValue ( TransactionType . Value . STACKING _INCOMING , realm )
val transaction = Transaction . newInstance ( realm , bankroll , startDate , type , stackingIn !! )
this . addAdditionallyCreatedIdentifiable ( transaction )
}
if ( stackingOut != null && stackingOut != 0.0 ) {
val type = TransactionType . getByValue ( TransactionType . Value . STACKING _OUTGOING , realm )
val transaction = Transaction . newInstance ( realm , bankroll , startDate , type , stackingOut !! )
this . addAdditionallyCreatedIdentifiable ( transaction )
}
return managedSession
} else {
Timber . d ( " Session already exists(count= $count ): sd= $startDate , ed= $endDate , net= $net " )