-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Videreføre inntekt inn i nytt år under årlig innntektsjustering (#6259)
* Videreføre inntekt inn i nytt år under årlig innntektsjustering * Legger ved år for å kunne verifisere inntekt som videreføres
- Loading branch information
Showing
10 changed files
with
214 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/etterlatte-beregning/src/main/kotlin/avkorting/AarligInntektsjusteringService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package no.nav.etterlatte.avkorting | ||
|
||
import no.nav.etterlatte.libs.common.beregning.AarligInntektsjusteringAvkortingSjekkRequest | ||
import no.nav.etterlatte.libs.common.beregning.AarligInntektsjusteringAvkortingSjekkResponse | ||
import no.nav.etterlatte.libs.common.beregning.AvkortingGrunnlagLagreDto | ||
import no.nav.etterlatte.libs.common.feilhaandtering.InternfeilException | ||
import no.nav.etterlatte.libs.ktor.token.BrukerTokenInfo | ||
import no.nav.etterlatte.sanksjon.SanksjonService | ||
import org.slf4j.LoggerFactory | ||
import java.time.YearMonth | ||
import java.util.UUID | ||
|
||
class AarligInntektsjusteringService( | ||
private val avkortingService: AvkortingService, | ||
private val avkortingRepository: AvkortingRepository, | ||
private val sanksjonService: SanksjonService, | ||
) { | ||
private val logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
fun hentSjekkAarligInntektsjustering( | ||
request: AarligInntektsjusteringAvkortingSjekkRequest, | ||
): AarligInntektsjusteringAvkortingSjekkResponse { | ||
val sanksjoner = sanksjonService.hentSanksjon(request.sisteBehandling) | ||
return AarligInntektsjusteringAvkortingSjekkResponse( | ||
sakId = request.sakId, | ||
aar = request.aar, | ||
harInntektForAar = avkortingRepository.harSakInntektForAar(request), | ||
harSanksjon = sanksjoner?.any { it.tom == null } ?: false, | ||
) | ||
} | ||
|
||
suspend fun kopierAarligInntektsjustering( | ||
aar: Int, | ||
behandlingId: UUID, | ||
forrigeBehandlingId: UUID, | ||
brukerTokenInfo: BrukerTokenInfo, | ||
): Avkorting { | ||
avkortingService.tilstandssjekk(behandlingId, brukerTokenInfo) | ||
logger.info("Oppretter avkorting for nytt inntektsår med siste inntekt fra behandling=$forrigeBehandlingId") | ||
val forrigeAvkorting = avkortingService.hentForrigeAvkorting(forrigeBehandlingId) | ||
|
||
val siseInntekt = | ||
forrigeAvkorting.aarsoppgjoer | ||
.last() | ||
.inntektsavkorting | ||
.last() | ||
.grunnlag | ||
|
||
with(siseInntekt.periode) { | ||
if (fom.year != aar - 1 || (tom != null && tom?.year != aar - 1)) { | ||
throw InternfeilException("Årlig inntektsjustering feilet - inntekt som overføres er i feil år") | ||
} | ||
} | ||
|
||
val nyttGrunnlag = | ||
AvkortingGrunnlagLagreDto( | ||
inntektTom = siseInntekt.inntektTom, | ||
fratrekkInnAar = 0, | ||
inntektUtlandTom = siseInntekt.inntektUtlandTom, | ||
fratrekkInnAarUtland = 0, | ||
spesifikasjon = siseInntekt.spesifikasjon, | ||
fom = YearMonth.of(aar, 1), | ||
) | ||
|
||
avkortingService.beregnAvkortingMedNyttGrunnlag(behandlingId, brukerTokenInfo, nyttGrunnlag) | ||
return avkortingRepository.hentAvkorting(behandlingId) | ||
?: throw AvkortingFinnesIkkeException(behandlingId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.