Skip to content

Commit

Permalink
Merge pull request #123 from hmrc/revert-121-SASS-9200
Browse files Browse the repository at this point in the history
Revert "SASS-9200 Income Submission with correct deductions"
  • Loading branch information
hs3t authored Jul 31, 2024
2 parents 303c55d + c44cfde commit 9fbaee3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 62 deletions.
21 changes: 0 additions & 21 deletions app/models/connector/api_1895/request/Deductions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package models.connector.api_1895.request

import models.connector.api_1786.DeductionsType
import play.api.libs.json.{Format, Json}

case class Deductions(costOfGoods: Option[SelfEmploymentDeductionsDetailPosNegType],
Expand All @@ -38,24 +37,4 @@ case class Deductions(costOfGoods: Option[SelfEmploymentDeductionsDetailPosNegTy

object Deductions {
implicit lazy val deductionsTypeJsonFormat: Format[Deductions] = Json.format[Deductions]

def fromApi1786(source: DeductionsType): Deductions =
Deductions(
costOfGoods = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.costOfGoods),
constructionIndustryScheme = SelfEmploymentDeductionsDetailType.fromApi1786(source.constructionIndustryScheme),
staffCosts = SelfEmploymentDeductionsDetailType.fromApi1786(source.staffCosts),
travelCosts = SelfEmploymentDeductionsDetailType.fromApi1786(source.travelCosts),
premisesRunningCosts = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.premisesRunningCosts),
maintenanceCosts = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.maintenanceCosts),
adminCosts = SelfEmploymentDeductionsDetailType.fromApi1786(source.adminCosts),
businessEntertainmentCosts = SelfEmploymentDeductionsDetailType.fromApi1786(source.businessEntertainmentCosts),
advertisingCosts = SelfEmploymentDeductionsDetailType.fromApi1786(source.advertisingCosts),
interest = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.interest),
financialCharges = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.financialCharges),
badDebt = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.badDebt),
professionalFees = SelfEmploymentDeductionsDetailAllowablePosNegType.fromApi1786(source.professionalFees),
depreciation = SelfEmploymentDeductionsDetailPosNegType.fromApi1786(source.depreciation),
other = SelfEmploymentDeductionsDetailType.fromApi1786(source.other),
simplifiedExpenses = source.simplifiedExpenses
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package models.connector.api_1895.request

import models.connector.api_1786.SelfEmploymentDeductionsDetailTypeAllowableNegDisPos
import play.api.libs.json._

/** utility object for deductions where by you must only have a positive or negative amount and the disallowable amount must be positive.
Expand All @@ -32,6 +31,4 @@ object SelfEmploymentDeductionsDetailAllowablePosNegType {
implicit lazy val selfEmploymentDeductionsDetailAllowablePosNegTypeJsonFormat: Format[SelfEmploymentDeductionsDetailAllowablePosNegType] =
Json.format[SelfEmploymentDeductionsDetailAllowablePosNegType]

def fromApi1786(source: Option[SelfEmploymentDeductionsDetailTypeAllowableNegDisPos]): Option[SelfEmploymentDeductionsDetailAllowablePosNegType] =
source.map(x => SelfEmploymentDeductionsDetailAllowablePosNegType(Some(x.amount), x.disallowableAmount))
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package models.connector.api_1895.request

import models.connector.api_1786.SelfEmploymentDeductionsDetailTypePosNeg
import play.api.libs.json.{Format, Json}

/** Represents the Swagger definition for selfEmploymentDeductionsDetailPosNegType.
Expand All @@ -33,6 +32,4 @@ object SelfEmploymentDeductionsDetailPosNegType {
implicit lazy val selfEmploymentDeductionsDetailPosNegTypeJsonFormat: Format[SelfEmploymentDeductionsDetailPosNegType] =
Json.format[SelfEmploymentDeductionsDetailPosNegType]

def fromApi1786(source: Option[SelfEmploymentDeductionsDetailTypePosNeg]): Option[SelfEmploymentDeductionsDetailPosNegType] =
source.map(x => SelfEmploymentDeductionsDetailPosNegType(x.amount, x.disallowableAmount))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package models.connector.api_1895.request

import play.api.libs.json.{Format, Json}
import models.connector.api_1786.{SelfEmploymentDeductionsDetailType => SelfEmploymentDeductionsDetailType1786}

/** Represents the Swagger definition for selfEmploymentDeductionsDetailType.
*
Expand All @@ -33,6 +32,4 @@ object SelfEmploymentDeductionsDetailType {
implicit lazy val selfEmploymentDeductionsDetailTypeJsonFormat: Format[SelfEmploymentDeductionsDetailType] =
Json.format[SelfEmploymentDeductionsDetailType]

def fromApi1786(source: Option[SelfEmploymentDeductionsDetailType1786]): Option[SelfEmploymentDeductionsDetailType] =
source.map(x => SelfEmploymentDeductionsDetailType(x.amount, x.disallowableAmount))
}
3 changes: 2 additions & 1 deletion app/models/frontend/income/IncomeJourneyAnswers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package models.frontend.income

import models.connector.{api_1786, api_1803}
import models.connector.api_1803
import models.connector.api_1786
import models.database.income.IncomeStorageAnswers
import play.api.libs.json.{Json, OFormat}

Expand Down
39 changes: 11 additions & 28 deletions app/services/journeyAnswers/IncomeAnswersService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import models.common.TaxYear.{endDate, startDate}
import models.common._
import models.connector.api_1802.request._
import models.connector.api_1894.request.{CreateSEPeriodSummaryRequestBody, CreateSEPeriodSummaryRequestData, FinancialsType, IncomesType}
import models.connector.api_1895.request.{AmendSEPeriodSummaryRequestBody, AmendSEPeriodSummaryRequestData, Deductions, Incomes}
import models.connector.api_1895.request.{AmendSEPeriodSummaryRequestBody, AmendSEPeriodSummaryRequestData, Incomes}
import models.connector.api_1965.ListSEPeriodSummariesResponse
import models.database.income.IncomeStorageAnswers
import models.domain.ApiResultT
Expand Down Expand Up @@ -65,17 +65,14 @@ class IncomeAnswersServiceImpl @Inject() (repository: JourneyAnswersRepository,
maybeDbAnswers <- getPersistedAnswers[IncomeStorageAnswers](row)
} yield maybeDbAnswers

// TODO: We need to confirm what actual APIs in QA returns for this, based on that we may have to change `annualNonFinancials` value. SASS-9292 is the ticket for this.
def saveAnswers(ctx: JourneyContextWithNino, answers: IncomeJourneyAnswers)(implicit hc: HeaderCarrier): ApiResultT[Unit] = {
import ctx._
val storageAnswers = IncomeStorageAnswers.fromJourneyAnswers(answers)

val upsertBody = CreateAmendSEAnnualSubmissionRequestBody.mkRequest(
annualAdjustments = Some(
AnnualAdjustments.empty.copy(includedNonTaxableProfits = answers.notTaxableAmount, outstandingBusinessIncome = answers.otherIncomeAmount)),
annualAllowances = Some(AnnualAllowances.empty.copy(tradingIncomeAllowance = answers.tradingAllowanceAmount)),
annualNonFinancials =
None // TODO: Verify in QA if we need to set it to empty or copy values if exists. And link between annualNonFinancials and annualAllowances
Some(AnnualAdjustments.empty.copy(includedNonTaxableProfits = answers.notTaxableAmount, outstandingBusinessIncome = answers.otherIncomeAmount)),
Some(AnnualAllowances.empty.copy(tradingIncomeAllowance = answers.tradingAllowanceAmount)),
None
)
val maybeUpsertData = upsertBody.map(CreateAmendSEAnnualSubmissionRequestData(taxYear, nino, businessId, _))

Expand All @@ -96,7 +93,6 @@ class IncomeAnswersServiceImpl @Inject() (repository: JourneyAnswersRepository,
case DeclareExpenses => EitherT.rightT[Future, ServiceError](())
}

// TODO: We need to confirm what actual APIs in QA returns for this, based on that we may have to change `taxTakenOffTradingIncome` value. SASS-9292 is the ticket for this.
private def upsertPeriodSummary(response: ListSEPeriodSummariesResponse, ctx: JourneyContextWithNino, answers: IncomeJourneyAnswers)(implicit
hc: HeaderCarrier): EitherT[Future, ServiceError, Unit] = {
import ctx._
Expand All @@ -107,28 +103,15 @@ class IncomeAnswersServiceImpl @Inject() (repository: JourneyAnswersRepository,
val createIncome = IncomesType(answers.turnoverIncomeAmount.some, answers.nonTurnoverIncomeAmount)
val createBody = CreateSEPeriodSummaryRequestBody(startDate(taxYear), endDate(taxYear), Some(FinancialsType(createIncome.some, None)))
val createData = CreateSEPeriodSummaryRequestData(taxYear, businessId, nino, createBody)

EitherT(connector.createSEPeriodSummary(createData)).leftAs[ServiceError].void
connector.createSEPeriodSummary(createData)
} else {
val amendIncome = Incomes(
turnover = answers.turnoverIncomeAmount.some,
other = answers.nonTurnoverIncomeAmount,
taxTakenOffTradingIncome =
None // TODO: Verify in QA if we need to set it to empty or copy values if exists. And link between taxTakenOffTradingIncome and amendIncome.
)

for {
periodicSummaryDetails <- EitherT(connector.getPeriodicSummaryDetail(ctx)).leftAs[ServiceError]
updatedDeductions = answers.tradingAllowance match {
case UseTradingAllowance => None
case DeclareExpenses => periodicSummaryDetails.financials.deductions
}
amendBody = AmendSEPeriodSummaryRequestBody(amendIncome.some, updatedDeductions.map(Deductions.fromApi1786))
amendData = AmendSEPeriodSummaryRequestData(taxYear, nino, businessId, amendBody)
_ <- EitherT(connector.amendSEPeriodSummary(amendData)).leftAs[ServiceError]
} yield ()
val amendIncome = Incomes(answers.turnoverIncomeAmount.some, answers.nonTurnoverIncomeAmount, None)
val amendBody = AmendSEPeriodSummaryRequestBody(amendIncome.some, None)
val amendData = AmendSEPeriodSummaryRequestData(taxYear, nino, businessId, amendBody)

connector.amendSEPeriodSummary(amendData)
}

result
EitherT(result).leftAs[ServiceError].void
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class IncomeAnswersServiceImplSpec extends AnyWordSpecLike with Matchers with Ma
connector.createAmendSEAnnualSubmission(*)(*, *) returns
Future.successful(api1802SuccessResponse.asRight)

connector.getPeriodicSummaryDetail(*)(*, *) returns
Future.successful(api1786DeductionsSuccessResponse.asRight)

val answers: IncomeJourneyAnswers = incomeJourneyAnswersGen.sample.get
val ctx: JourneyContextWithNino = JourneyContextWithNino(currTaxYear, businessId, mtditid, nino)

Expand Down

0 comments on commit 9fbaee3

Please sign in to comment.