Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EY-4877 endringer etterbetaling utfall i brev #6665

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,12 @@ private fun BrevutfallOgEtterbetalingDto.toBrevutfall(
private fun BrevutfallOgEtterbetalingDto.toEtterbetaling(
behandlingId: UUID,
bruker: BrukerTokenInfo,
): Etterbetaling? {
val etterbetalingCopy = etterbetaling
return if (etterbetalingCopy?.datoFom != null && etterbetalingCopy.datoTom != null) {
Etterbetaling.fra(
behandlingId = behandlingId,
datoFom = etterbetalingCopy.datoFom,
datoTom = etterbetalingCopy.datoTom,
inneholderKrav = etterbetalingCopy.inneholderKrav,
frivilligSkattetrekk = etterbetalingCopy.frivilligSkattetrekk,
etterbetalingPeriodeValg = etterbetalingCopy.etterbetalingPeriodeValg,
kilde = Grunnlagsopplysning.Saksbehandler.create(bruker.ident()),
)
} else {
null
}
}
): Etterbetaling? =
Etterbetaling.fra(
behandlingId = behandlingId,
frivilligSkattetrekk = etterbetaling?.frivilligSkattetrekk,
kilde = Grunnlagsopplysning.Saksbehandler.create(bruker.ident()),
)

private fun Brevutfall.toDto() =
BrevutfallDto(
Expand All @@ -167,12 +157,8 @@ private fun Brevutfall.toDto() =
private fun Etterbetaling.toDto() =
EtterbetalingDto(
behandlingId = behandlingId,
datoFom = fom.atDay(1),
datoTom = tom.atEndOfMonth(),
kilde = kilde,
inneholderKrav = inneholderKrav,
frivilligSkattetrekk = frivilligSkattetrekk,
etterbetalingPeriodeValg = etterbetalingPeriodeValg,
)

class OpphoerIkkeSatt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import no.nav.etterlatte.libs.common.behandling.Revurderingaarsak
import no.nav.etterlatte.libs.common.behandling.SakType
import no.nav.etterlatte.libs.common.feilhaandtering.GenerellIkkeFunnetException
import no.nav.etterlatte.libs.ktor.token.BrukerTokenInfo
import org.slf4j.LoggerFactory
import java.util.UUID

class BehandlingInfoService(
private val behandlingInfoDao: BehandlingInfoDao,
private val behandlingService: BehandlingService,
private val behandlingsstatusService: BehandlingStatusService,
) {
private val logger = LoggerFactory.getLogger(BehandlingInfoService::class.java)

fun lagreBrevutfallOgEtterbetaling(
behandlingId: UUID,
brukerTokenInfo: BrukerTokenInfo,
Expand Down Expand Up @@ -84,7 +81,6 @@ class BehandlingInfoService(
return null
}

sjekkEtterbetalingFoerVirkningstidspunkt(behandling, etterbetaling)
return behandlingInfoDao.lagreEtterbetaling(etterbetaling)
}

Expand Down Expand Up @@ -137,19 +133,6 @@ class BehandlingInfoService(
}
}

private fun sjekkEtterbetalingFoerVirkningstidspunkt(
behandling: Behandling,
etterbetaling: Etterbetaling,
) {
val virkningstidspunkt =
behandling.virkningstidspunkt?.dato
?: throw BrevutfallException.VirkningstidspunktIkkeSatt(behandling.id)

if (etterbetaling.fom < virkningstidspunkt) {
throw EtterbetalingException.EtterbetalingFraDatoErFoerVirk(etterbetaling.fom, virkningstidspunkt)
}
}

private fun sjekkAldersgruppeSattVedBarnepensjon(
behandling: Behandling,
brevutfall: Brevutfall,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,23 @@
package no.nav.etterlatte.behandling.behandlinginfo

import no.nav.etterlatte.libs.common.behandling.EtterbetalingPeriodeValg
import no.nav.etterlatte.libs.common.feilhaandtering.UgyldigForespoerselException
import no.nav.etterlatte.libs.common.grunnlag.Grunnlagsopplysning
import java.time.LocalDate
import java.time.YearMonth
import java.util.UUID

data class Etterbetaling(
val behandlingId: UUID,
val fom: YearMonth,
val tom: YearMonth,
val inneholderKrav: Boolean?,
val frivilligSkattetrekk: Boolean?,
val etterbetalingPeriodeValg: EtterbetalingPeriodeValg?,
val kilde: Grunnlagsopplysning.Saksbehandler,
) {
init {
if (fom > tom) {
throw EtterbetalingException.EtterbetalingFomErEtterTom(fom, tom)
}
if (tom > YearMonth.now()) {
throw EtterbetalingException.EtterbetalingTomErFramITid(tom)
}
}

companion object {
fun fra(
behandlingId: UUID,
datoFom: LocalDate?,
datoTom: LocalDate?,
inneholderKrav: Boolean?,
frivilligSkattetrekk: Boolean?,
etterbetalingPeriodeValg: EtterbetalingPeriodeValg?,
kilde: Grunnlagsopplysning.Saksbehandler,
): Etterbetaling {
if (datoFom == null || datoTom == null) {
throw EtterbetalingException.EtterbetalingManglerDato()
}
return Etterbetaling(
): Etterbetaling =
Etterbetaling(
behandlingId = behandlingId,
fom = YearMonth.from(datoFom),
tom = YearMonth.from(datoTom),
inneholderKrav = inneholderKrav,
frivilligSkattetrekk = frivilligSkattetrekk,
etterbetalingPeriodeValg = etterbetalingPeriodeValg,
kilde = kilde,
)
}
}
}

sealed class EtterbetalingException {
class EtterbetalingManglerDato :
UgyldigForespoerselException(
code = "MANGLER_FRA_ELLER_TIL_DATO",
detail = "Etterbetaling må ha en fra-dato og en til-dato",
)

class EtterbetalingFomErEtterTom(
fom: YearMonth,
tom: YearMonth,
) : UgyldigForespoerselException(
code = "FRA_DATO_ETTER_TIL_DATO",
detail = "Fra-dato ($fom) kan ikke være etter til-dato ($tom).",
)

class EtterbetalingTomErFramITid(
tom: YearMonth,
) : UgyldigForespoerselException(
code = "TIL_DATO_FRAM_I_TID",
detail = "Til-dato ($tom) er fram i tid.",
)

class EtterbetalingFraDatoErFoerVirk(
fom: YearMonth,
virkningstidspunkt: YearMonth,
) : UgyldigForespoerselException(
code = "FRA_DATO_FOER_VIRK",
detail = "Fra-dato ($fom) er før virkningstidspunkt ($virkningstidspunkt)",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import no.nav.etterlatte.libs.common.behandling.Aldersgruppe
import no.nav.etterlatte.libs.common.behandling.BehandlingStatus
import no.nav.etterlatte.libs.common.behandling.BehandlingType
import no.nav.etterlatte.libs.common.behandling.Brevutfall
import no.nav.etterlatte.libs.common.behandling.EtterbetalingPeriodeValg
import no.nav.etterlatte.libs.common.behandling.Feilutbetaling
import no.nav.etterlatte.libs.common.behandling.FeilutbetalingValg
import no.nav.etterlatte.libs.common.behandling.SakType
Expand All @@ -33,7 +32,6 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
import java.time.LocalDate
import java.time.YearMonth
import java.util.UUID
import javax.sql.DataSource

Expand Down Expand Up @@ -169,8 +167,6 @@ internal class BehandlingInfoDaoTest(
val lagretEtterbetaling = dao.lagreEtterbetaling(etterbetaling)

lagretEtterbetaling shouldNotBe null
lagretEtterbetaling.fom shouldBe etterbetaling.fom
lagretEtterbetaling.tom shouldBe etterbetaling.tom
lagretEtterbetaling.kilde shouldBe etterbetaling.kilde
}

Expand Down Expand Up @@ -209,11 +205,7 @@ internal class BehandlingInfoDaoTest(
private fun etterbetaling(behandlingId: UUID) =
Etterbetaling(
behandlingId = behandlingId,
fom = YearMonth.of(2023, 11),
tom = YearMonth.of(2023, 12),
inneholderKrav = true,
frivilligSkattetrekk = true,
etterbetalingPeriodeValg = EtterbetalingPeriodeValg.UNDER_3_MND,
kilde = Grunnlagsopplysning.Saksbehandler("Z1234567", Tidspunkt.now()),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import no.nav.etterlatte.libs.common.behandling.Brevutfall
import no.nav.etterlatte.libs.common.behandling.BrevutfallDto
import no.nav.etterlatte.libs.common.behandling.BrevutfallOgEtterbetalingDto
import no.nav.etterlatte.libs.common.behandling.EtterbetalingDto
import no.nav.etterlatte.libs.common.behandling.EtterbetalingPeriodeValg
import no.nav.etterlatte.libs.common.behandling.Feilutbetaling
import no.nav.etterlatte.libs.common.behandling.FeilutbetalingValg
import no.nav.etterlatte.libs.common.behandling.SakType
Expand All @@ -41,7 +40,6 @@ import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import java.time.LocalDate
import java.time.YearMonth
import java.util.UUID

Expand Down Expand Up @@ -113,10 +111,6 @@ internal class BehandlingInfoRoutesTest {
opprettetBrevutfallOgEtterbetaling.brevutfall?.aldersgruppe shouldBe dto.brevutfall?.aldersgruppe
opprettetBrevutfallOgEtterbetaling.brevutfall?.kilde shouldNotBe null

opprettetBrevutfallOgEtterbetaling.etterbetaling?.datoFom shouldBe dto.etterbetaling?.datoFom
opprettetBrevutfallOgEtterbetaling.etterbetaling?.datoTom shouldBe dto.etterbetaling?.datoTom
opprettetBrevutfallOgEtterbetaling.etterbetaling?.inneholderKrav shouldBe dto.etterbetaling?.inneholderKrav
opprettetBrevutfallOgEtterbetaling.etterbetaling?.etterbetalingPeriodeValg shouldBe dto.etterbetaling?.etterbetalingPeriodeValg
opprettetBrevutfallOgEtterbetaling.etterbetaling?.frivilligSkattetrekk shouldBe dto.etterbetaling?.frivilligSkattetrekk
opprettetBrevutfallOgEtterbetaling.etterbetaling?.kilde shouldNotBe null
}
Expand Down Expand Up @@ -171,10 +165,6 @@ internal class BehandlingInfoRoutesTest {
val etterbetaling: EtterbetalingDto = response.body()
response.status shouldBe HttpStatusCode.OK

etterbetaling.datoFom shouldBe dto.etterbetaling?.datoFom
etterbetaling.datoTom shouldBe dto.etterbetaling?.datoTom
etterbetaling.inneholderKrav shouldBe dto.etterbetaling?.inneholderKrav
etterbetaling.etterbetalingPeriodeValg shouldBe dto.etterbetaling?.etterbetalingPeriodeValg
etterbetaling.frivilligSkattetrekk shouldBe dto.etterbetaling?.frivilligSkattetrekk
}
}
Expand Down Expand Up @@ -209,12 +199,8 @@ internal class BehandlingInfoRoutesTest {
private fun etterbetaling(behandlingId: UUID) =
Etterbetaling(
behandlingId = behandlingId,
fom = YearMonth.of(2023, 1),
tom = YearMonth.of(2023, 2),
inneholderKrav = true,
kilde = Grunnlagsopplysning.Saksbehandler.create("Saksbehandler01"),
frivilligSkattetrekk = true,
etterbetalingPeriodeValg = EtterbetalingPeriodeValg.UNDER_3_MND,
)

private fun brevutfallOgEtterbetalingDto(behandlingId: UUID = UUID.randomUUID()) =
Expand All @@ -232,11 +218,7 @@ internal class BehandlingInfoRoutesTest {
etterbetaling =
EtterbetalingDto(
behandlingId = behandlingId,
datoFom = LocalDate.of(2023, 1, 1),
datoTom = LocalDate.of(2023, 2, 28),
inneholderKrav = true,
frivilligSkattetrekk = true,
etterbetalingPeriodeValg = EtterbetalingPeriodeValg.UNDER_3_MND,
kilde = null,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import no.nav.etterlatte.libs.common.behandling.Aldersgruppe
import no.nav.etterlatte.libs.common.behandling.BehandlingStatus
import no.nav.etterlatte.libs.common.behandling.BehandlingType
import no.nav.etterlatte.libs.common.behandling.Brevutfall
import no.nav.etterlatte.libs.common.behandling.EtterbetalingPeriodeValg
import no.nav.etterlatte.libs.common.behandling.Feilutbetaling
import no.nav.etterlatte.libs.common.behandling.FeilutbetalingValg
import no.nav.etterlatte.libs.common.behandling.Revurderingaarsak
Expand Down Expand Up @@ -139,23 +138,6 @@ internal class BehandlingInfoServiceTest {
}
}

@Test
fun `skal feile ved opprettelse av etterbetaling hvis etterbetaling fra-dato er foer virkningstidspunkt`() {
val behandlingId = randomUUID()
val etterbetaling =
etterbetaling(
behandlingId = behandlingId,
fom = YearMonth.of(2022, 12),
tom = YearMonth.of(2023, 1),
)

every { behandlingInfoDao.hentEtterbetaling(any()) } returns etterbetaling

assertThrows<EtterbetalingException.EtterbetalingFraDatoErFoerVirk> {
behandlingInfoService.lagreEtterbetaling(behandling(behandlingId), etterbetaling)
}
}

@Test
fun `skal slette etterbetaling hvis den er null og det allerede finnes en etterbetaling`() {
val behandlingId = randomUUID()
Expand Down Expand Up @@ -261,17 +243,10 @@ internal class BehandlingInfoServiceTest {
kilde = Grunnlagsopplysning.Saksbehandler.create("Saksbehandler01"),
)

private fun etterbetaling(
behandlingId: UUID,
fom: YearMonth = YearMonth.of(2023, 1),
tom: YearMonth = YearMonth.of(2023, 2),
) = Etterbetaling(
behandlingId = behandlingId,
fom = fom,
tom = tom,
inneholderKrav = true,
frivilligSkattetrekk = true,
etterbetalingPeriodeValg = EtterbetalingPeriodeValg.UNDER_3_MND,
kilde = Grunnlagsopplysning.Saksbehandler.create("Saksbehandler01"),
)
private fun etterbetaling(behandlingId: UUID) =
Etterbetaling(
behandlingId = behandlingId,
frivilligSkattetrekk = true,
kilde = Grunnlagsopplysning.Saksbehandler.create("Saksbehandler01"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class BrevDataMapperFerdigstillingVedtak(
innholdMedVedlegg,
avdoede,
utbetalingsinfo.await(),
etterbetaling.await(),
etterbetaling.await().frivilligSkattetrekk,
requireNotNull(trygdetid.await()) { "Mangler trygdetid" },
requireNotNull(grunnbeloep.await()) { "Mangler grunnbeløp" },
utlandstilknytningType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import no.nav.etterlatte.brev.Brevkoder
import no.nav.etterlatte.brev.Brevtype
import no.nav.etterlatte.brev.Slate
import no.nav.etterlatte.brev.adresse.RegoppslagResponseDTO
import no.nav.etterlatte.libs.common.behandling.EtterbetalingPeriodeValg
import no.nav.etterlatte.libs.common.person.Folkeregisteridentifikator
import no.nav.etterlatte.libs.common.person.MottakerFoedselsnummer
import no.nav.etterlatte.libs.common.sak.SakId
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt
import java.time.LocalDate
import java.util.UUID

fun mottakerFraAdresse(
Expand Down Expand Up @@ -109,9 +107,5 @@ data class OpprettNyttBrev(
}

data class EtterbetalingDTO(
val datoFom: LocalDate,
val datoTom: LocalDate,
val inneholderKrav: Boolean?,
val frivilligSkattetrekk: Boolean?,
val etterbetalingPeriodeValg: EtterbetalingPeriodeValg?,
)
Loading