Skip to content

Commit

Permalink
Merge pull request #30 from hmrc/refactor/flatten-annual-statement-ou…
Browse files Browse the repository at this point in the history
…tput-json

Refactor/flatten annual statement output json
  • Loading branch information
flashingpumpkin authored Dec 12, 2017
2 parents 2394946 + 5851618 commit 8859bb9
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 203 deletions.
24 changes: 8 additions & 16 deletions app/uk/gov/hmrc/epayeapi/models/in/EpayeAnnualStatement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,24 @@ package uk.gov.hmrc.epayeapi.models.in
import org.joda.time.LocalDate
import uk.gov.hmrc.epayeapi.models.TaxYear

case class DebitAndCredit(
debit: BigDecimal = 0,
credit: BigDecimal = 0
)

case class Cleared(
payment: BigDecimal = 0,
credit: BigDecimal = 0
)

case class LineItem(
taxYear: TaxYear,
taxMonth: Option[EpayeTaxMonth],
charges: DebitAndCredit,
cleared: Cleared,
balance: DebitAndCredit,
charges: BigDecimal,
payments: BigDecimal,
credits: BigDecimal,
balance: BigDecimal,
dueDate: LocalDate,
isSpecified: Boolean = false,
codeText: Option[String] = None,
itemType: Option[String] = None
)

case class AnnualTotal(
charges: DebitAndCredit,
cleared: Cleared,
balance: DebitAndCredit
charges: BigDecimal,
payments: BigDecimal,
credits: BigDecimal,
balance: BigDecimal
)

case class AnnualStatementTable(lineItems: Seq[LineItem], totals: AnnualTotal)
Expand Down
2 changes: 0 additions & 2 deletions app/uk/gov/hmrc/epayeapi/models/in/EpayeReads.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ trait EpayeReads {
implicit lazy val taxYearReads: Reads[TaxYear] = reads[TaxYear]
implicit lazy val epayeTaxMonthReads: Reads[EpayeTaxMonth] = reads[EpayeTaxMonth]

implicit lazy val debitAndCreditReads: Reads[DebitAndCredit] = reads[DebitAndCredit]
implicit lazy val clearedReads: Reads[Cleared] = reads[Cleared]
implicit lazy val annualTotalReads: Reads[AnnualTotal] = reads[AnnualTotal]
implicit lazy val lineItemReads: Reads[LineItem] = reads[LineItem]

Expand Down
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/epayeapi/models/in/EpayeTotalsResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package uk.gov.hmrc.epayeapi.models.in

case class EpayeTotals(balance: DebitAndCredit)
case class EpayeTotals(balance: BigDecimal)
case class EpayeTotalsItem(totals: EpayeTotals)
case class EpayeTotalsResponse(rti: EpayeTotalsItem, nonRti: EpayeTotalsItem) {
def overall: BigDecimal = rti.totals.balance.debit + nonRti.totals.balance.debit
def overall: BigDecimal = rti.totals.balance + nonRti.totals.balance
}
24 changes: 12 additions & 12 deletions app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ object NonRtiChargesJson {
code <- lineItem.codeText
} yield NonRtiChargesJson(
code = code,
amount = lineItem.charges.debit,
clearedByCredits = lineItem.cleared.credit,
clearedByPayments = lineItem.cleared.payment,
balance = lineItem.balance.debit,
amount = lineItem.charges,
clearedByCredits = lineItem.credits,
clearedByPayments = lineItem.payments,
balance = lineItem.balance,
dueDate = lineItem.dueDate
)
}
Expand All @@ -66,10 +66,10 @@ object EarlierYearUpdateJson {
.find(_.itemType.contains("eyu"))
.map { lineItem =>
EarlierYearUpdateJson(
lineItem.charges.debit,
lineItem.cleared.credit,
lineItem.cleared.payment,
lineItem.balance.debit,
lineItem.charges,
lineItem.credits,
lineItem.payments,
lineItem.balance,
lineItem.dueDate
)
}
Expand Down Expand Up @@ -100,10 +100,10 @@ object MonthlyChargesJson {
taxMonth = TaxMonth(taxYear, epayeTaxMonth.month)
} yield MonthlyChargesJson(
taxMonth = taxMonth,
amount = lineItem.charges.debit,
clearedByCredits = lineItem.cleared.credit,
clearedByPayments = lineItem.cleared.payment,
balance = lineItem.balance.debit,
amount = lineItem.charges,
clearedByCredits = lineItem.credits,
clearedByPayments = lineItem.payments,
balance = lineItem.balance,
dueDate = lineItem.dueDate,
isSpecified = lineItem.isSpecified,
_links = SelfLink(Link.monthlyStatementLink(apiBaseUrl, empRef, taxYear, taxMonth))
Expand Down
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/epayeapi/models/out/SummaryJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object SummaryJson {
OutstandingCharges(
total.overall,
Breakdown(
rti = total.rti.totals.balance.debit,
nonRti = total.nonRti.totals.balance.debit
rti = total.rti.totals.balance,
nonRti = total.nonRti.totals.balance
)
),
SummaryLinks(apiBaseUrl, empRef)
Expand Down
102 changes: 24 additions & 78 deletions test/common/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@ object Fixtures {
| "taxMonth": {
| "month": 7
| },
| "charges": {
| "debit": 1200,
| "credit": 0
| },
| "cleared": {
| "cleared": 0,
| "payment": 0,
| "credit": 0
| },
| "balance": {
| "debit": 1200,
| "credit": 0
| },
| "charges":1200,
| "payments": 0,
| "credits": 0,
| "balance": 1200,
| "dueDate": "2017-11-22",
| "isSpecified": false,
| "itemType": "month"
Expand All @@ -54,19 +45,10 @@ object Fixtures {
| "taxYear": {
| "yearFrom": 2017
| },
| "charges": {
| "debit": 700,
| "credit": 0
| },
| "cleared": {
| "cleared": 0,
| "payment": 300,
| "credit": 200
| },
| "balance": {
| "debit": 200,
| "credit": 0
| },
| "charges":700,
| "payments": 300,
| "credits": 200,
| "balance": 200,
| "dueDate": "2017-04-22",
| "isSpecified": false,
| "itemType": "eyu"
Expand All @@ -78,37 +60,19 @@ object Fixtures {
| "taxMonth": {
| "month": 3
| },
| "charges": {
| "debit": 700,
| "credit": 0
| },
| "cleared": {
| "cleared": 0,
| "payment": 300,
| "credit": 200
| },
| "balance": {
| "debit": 200,
| "credit": 0
| },
| "charges":700,
| "payments": 300,
| "credits": 200,
| "balance": 200,
| "dueDate": "2017-07-22",
| "isSpecified": true
| }
| ],
| "totals": {
| "charges": {
| "debit": 1900,
| "credit": 0
| },
| "cleared": {
| "cleared": 0,
| "payment": 300,
| "credit": 200
| },
| "balance": {
| "debit": 1400,
| "credit": 0
| }
| "charges":1900,
| "payments": 300,
| "credits": 200,
| "balance": 1400
| }
| },
| "nonRti": {
Expand All @@ -117,39 +81,21 @@ object Fixtures {
| "taxYear": {
| "yearFrom": 2017
| },
| "charges": {
| "debit": 300,
| "credit": 0
| },
| "cleared": {
| "cleared": 100,
| "payment": 30,
| "credit": 70
| },
| "balance": {
| "debit": 200,
| "credit": 0
| },
| "charges":300,
| "payments": 30,
| "credits": 70,
| "balance": 200,
| "dueDate": "2017-07-22",
| "isSpecified": false,
| "itemType": "1481",
| "codeText": "NON_RTI_CIS_FIXED_PENALTY"
| }
| ],
| "totals": {
| "charges": {
| "debit": 0,
| "credit": 0
| },
| "cleared": {
| "cleared": 0,
| "payment": 0,
| "credit": 0
| },
| "balance": {
| "debit": 0,
| "credit": 0
| }
| "charges":0,
| "payments": 0,
| "credits": 0,
| "balance": 0
| }
| },
| "unallocated": 2000
Expand Down
64 changes: 16 additions & 48 deletions test/resources/epaye/annual-statement/annual-statement.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,19 @@
"taxMonth": {
"month": 1
},
"charges": {
"debit": 100.2,
"credit": 0
},
"cleared": {
"payment": 0,
"credit": 0
},
"balance": {
"debit": 100.2,
"credit": 0
},
"charges": 100.2,
"payments": 0,
"credits": 0,
"balance": 100.2,
"dueDate": "2017-05-22",
"isSpecified": false
}
],
"totals": {
"charges": {
"debit": 100.2,
"credit": 0
},
"cleared": {
"payment": 0,
"credit": 0
},
"balance": {
"debit": 100.2,
"credit": 0
}
"charges": 100.2,
"payments": 0,
"credits": 0,
"balance": 100.2
}
},
"nonRti": {
Expand All @@ -45,36 +29,20 @@
"taxYear": {
"yearFrom": 2017
},
"charges": {
"debit": 20.0,
"credit": 0
},
"cleared": {
"payment": 0,
"credit": 0
},
"balance": {
"debit": 20.0,
"credit": 0
},
"charges": 20.0,
"payments": 0,
"credits": 0,
"balance": 20.0,
"dueDate": "2018-02-22",
"isSpecified": false,
"codeText": "P11D_CLASS_1A_CHARGE"
}
],
"totals": {
"charges": {
"debit": 20.0,
"credit": 0
},
"cleared": {
"payment": 0,
"credit": 0
},
"balance": {
"debit": 20.0,
"credit": 0
}
"charges": 20.0,
"payments": 0,
"credits": 0,
"balance": 20.0
}
}
}
22 changes: 8 additions & 14 deletions test/uk/gov/hmrc/epayeapi/connectors/EpayeConnectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@ class EpayeConnectorSpec extends UnitSpec with MockitoSugar with ScalaFutures {
|{
| "rti": {
| "totals": {
| "balance": {
| "debit": 100,
| "credit": 0
| }
| "balance": 100
| }
| },
| "nonRti": {
| "totals": {
| "balance": {
| "debit": 23,
| "credit": 0
| }
| "balance": 23
| }
| }
|}
Expand All @@ -80,8 +74,8 @@ class EpayeConnectorSpec extends UnitSpec with MockitoSugar with ScalaFutures {
Await.result(connector.getTotal(empRef, hc), 2.seconds) shouldBe
EpayeSuccess(
EpayeTotalsResponse(
EpayeTotalsItem(EpayeTotals(DebitAndCredit(100, 0))),
EpayeTotalsItem(EpayeTotals(DebitAndCredit(23, 0)))
EpayeTotalsItem(EpayeTotals(100)),
EpayeTotalsItem(EpayeTotals(23))
)
)
}
Expand All @@ -99,12 +93,12 @@ class EpayeConnectorSpec extends UnitSpec with MockitoSugar with ScalaFutures {
EpayeSuccess(
EpayeAnnualStatement(
rti = AnnualStatementTable(
List(LineItem(TaxYear(2017), Some(EpayeTaxMonth(1)), DebitAndCredit(100.2, 0), Cleared(0, 0), DebitAndCredit(100.2, 0), new LocalDate(2017, 5, 22), isSpecified = false, codeText = None)),
AnnualTotal(DebitAndCredit(100.2, 0), Cleared(0, 0), DebitAndCredit(100.2, 0))
List(LineItem(TaxYear(2017), Some(EpayeTaxMonth(1)), 100.2, 0, 0, 100.2, new LocalDate(2017, 5, 22), isSpecified = false, codeText = None)),
AnnualTotal(100.2, 0, 0, 100.2)
),
nonRti = AnnualStatementTable(
List(LineItem(TaxYear(2017), None, DebitAndCredit(20.0, 0), Cleared(0, 0), DebitAndCredit(20.0, 0), new LocalDate(2018, 2, 22), false, Some("P11D_CLASS_1A_CHARGE"))),
AnnualTotal(DebitAndCredit(20.0, 0), Cleared(0, 0), DebitAndCredit(20.0, 0))
List(LineItem(TaxYear(2017), None, 20.0, 0, 0, 20.0, new LocalDate(2018, 2, 22), false, Some("P11D_CLASS_1A_CHARGE"))),
AnnualTotal(20.0, 0, 0, 20.0)
),
unallocated = None
)
Expand Down
Loading

0 comments on commit 8859bb9

Please sign in to comment.