Skip to content

Commit

Permalink
Merge branch 'master' into DTSCCI-958
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagreaney authored Nov 15, 2024
2 parents 7b054df + 656a710 commit 6a6a707
Show file tree
Hide file tree
Showing 7 changed files with 657 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDateTime;
import static uk.gov.hmcts.reform.civil.utils.DefaultJudgmentUtils.calculateFixedCosts;
import static uk.gov.hmcts.reform.civil.utils.DefaultJudgmentUtils.calculateFixedCostsOnEntry;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType;
import static uk.gov.hmcts.reform.civil.utils.PersistDataUtils.persistFlagsForParties;
Expand Down Expand Up @@ -269,8 +270,48 @@ private CallbackResponse partialPayment(CallbackParams callbackParams) {
}
}

if (!errors.isEmpty()) {
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}

CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();

// show old fixed costs screen if claim was created before new fixed
// costs screen at claim issue was released
if (caseData.getFixedCosts() == null) {
caseDataBuilder.showOldDJFixedCostsScreen(YesOrNo.YES);
}

// otherwise show new dj fixed costs screen if judgment amount is more
// than 25. judgment amount = claim amount + interest - partial amount
if (caseData.getFixedCosts() != null) {
BigDecimal judgmentAmount = calculateJudgmentAmountForFixedCosts(caseData);
if (YesOrNo.YES.equals(caseData.getFixedCosts().getClaimFixedCosts())) {
if (judgmentAmount.compareTo(BigDecimal.valueOf(25)) > 0) {
caseDataBuilder.showDJFixedCostsScreen(YesOrNo.YES);
} else {
caseDataBuilder.showDJFixedCostsScreen(YesOrNo.NO);
}
}
// if case is applicable to new fixed costs but new screen will not
// be shown due to the above conditions, then skip straight to
// repayment breakdown screen
if (caseDataBuilder.build().getShowDJFixedCostsScreen() == null
|| YesOrNo.NO.equals(caseDataBuilder.build().getShowDJFixedCostsScreen())) {
// calculate repayment breakdown
StringBuilder repaymentBreakdown = buildRepaymentBreakdown(
caseData,
callbackParams);

caseDataBuilder.repaymentSummaryObject(repaymentBreakdown.toString());
}
}

return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.data(caseDataBuilder.build().toMap(objectMapper))
.build();

}
Expand All @@ -296,24 +337,10 @@ private CallbackResponse repaymentBreakdownCalculate(CallbackParams callbackPara

CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder();
BigDecimal interest = interestCalculator.calculateInterest(caseData);
BigDecimal totalInterest = caseData.getTotalInterest() != null ? caseData.getTotalInterest() : BigDecimal.ZERO;
var claimWithInterest = caseData.getTotalClaimAmount().add(totalInterest);
var claimfee = feesService.getFeeDataByTotalClaimAmount(claimWithInterest);
BigDecimal claimFeePounds;
if (caseData.getOutstandingFeeInPounds() != null) {
claimFeePounds = caseData.getOutstandingFeeInPounds();
} else {
claimFeePounds = MonetaryConversions.penniesToPounds(claimfee.getCalculatedAmountInPence());
}
BigDecimal fixedCost = calculateFixedCosts(caseData);

StringBuilder repaymentBreakdown = buildRepaymentBreakdown(
caseData,
interest,
claimFeePounds,
fixedCost,
callbackParams
);
callbackParams);

caseDataBuilder.repaymentSummaryObject(repaymentBreakdown.toString());
return AboutToStartOrSubmitCallbackResponse.builder()
Expand All @@ -322,19 +349,32 @@ private CallbackResponse repaymentBreakdownCalculate(CallbackParams callbackPara
}

@NotNull
private StringBuilder buildRepaymentBreakdown(CaseData caseData, BigDecimal interest, BigDecimal claimFeePounds,
BigDecimal fixedCost, CallbackParams callbackParams) {
private StringBuilder buildRepaymentBreakdown(CaseData caseData, CallbackParams callbackParams) {

BigDecimal interest = interestCalculator.calculateInterest(caseData);
BigDecimal totalInterest = caseData.getTotalInterest() != null ? caseData.getTotalInterest() : BigDecimal.ZERO;
var claimWithInterest = caseData.getTotalClaimAmount().add(totalInterest);
var claimfee = feesService.getFeeDataByTotalClaimAmount(claimWithInterest);
BigDecimal claimFeePounds;
if (caseData.getOutstandingFeeInPounds() != null) {
claimFeePounds = caseData.getOutstandingFeeInPounds();
} else {
claimFeePounds = MonetaryConversions.penniesToPounds(claimfee.getCalculatedAmountInPence());
}

BigDecimal fixedCost = BigDecimal.valueOf(0);
if (caseData.getFixedCosts() == null) {
fixedCost = calculateFixedCosts(caseData);
} else {
if (caseData.getFixedCosts() != null && caseData.getFixedCosts().getFixedCostAmount() != null) {
fixedCost = calculateFixedCostsOnEntry(caseData, calculateJudgmentAmountForFixedCosts(caseData));
}
}
BigDecimal partialPaymentPounds = getPartialPayment(caseData);
//calculate the relevant total, total claim value + interest if any, claim fee for case,
// and subtract any partial payment
var subTotal = caseData.getTotalClaimAmount()
.add(interest)
.add(claimFeePounds);
if (caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES) {
subTotal = subTotal.add(fixedCost);
}
theOverallTotal = subTotal.subtract(partialPaymentPounds);
BigDecimal subTotal = getSubTotal(caseData, interest, claimFeePounds, fixedCost);
theOverallTotal = calculateOverallTotal(partialPaymentPounds, subTotal);
//creates the text on the page, based on calculated values
StringBuilder repaymentBreakdown = new StringBuilder();
if (caseData.isLRvLipOneVOne()
Expand All @@ -360,7 +400,9 @@ private StringBuilder buildRepaymentBreakdown(CaseData caseData, BigDecimal inte
repaymentBreakdown.append("\n ### Claim interest amount \n").append("£").append(interest.setScale(2));
}

if (caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES) {
if ((caseData.getFixedCosts() != null
&& YesOrNo.YES.equals(caseData.getFixedCosts().getClaimFixedCosts()))
|| caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES) {
repaymentBreakdown.append("\n ### Fixed cost amount \n").append("£").append(fixedCost.setScale(2));
}
repaymentBreakdown.append("\n").append("### Claim fee amount \n £").append(claimFeePounds.setScale(2)).append(
Expand All @@ -376,6 +418,19 @@ private StringBuilder buildRepaymentBreakdown(CaseData caseData, BigDecimal inte
return repaymentBreakdown;
}

@NotNull
private BigDecimal getSubTotal(CaseData caseData, BigDecimal interest, BigDecimal claimFeePounds, BigDecimal fixedCost) {
var subTotal = caseData.getTotalClaimAmount()
.add(interest)
.add(claimFeePounds);
if (caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES
|| (caseData.getFixedCosts() != null
&& YesOrNo.YES.equals(caseData.getFixedCosts().getClaimFixedCosts()))) {
subTotal = subTotal.add(fixedCost);
}
return subTotal;
}

private BigDecimal getPartialPayment(CaseData caseData) {

BigDecimal partialPaymentPounds = new BigDecimal(0);
Expand Down Expand Up @@ -454,6 +509,18 @@ private CallbackResponse generateClaimForm(CallbackParams callbackParams) {
.state(nextState)
.build();
}

private BigDecimal calculateOverallTotal(BigDecimal partialPaymentPounds, BigDecimal subTotal) {
return subTotal.subtract(partialPaymentPounds);
}

private BigDecimal calculateJudgmentAmountForFixedCosts(CaseData caseData) {
BigDecimal interest = interestCalculator.calculateInterest(caseData);

BigDecimal subTotal = caseData.getTotalClaimAmount().add(interest);
BigDecimal partialPaymentPounds = getPartialPayment(caseData);
return calculateOverallTotal(partialPaymentPounds, subTotal);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ public boolean isApplicantRepresented() {
private SmallClaimsMediation smallClaimsMediationSectionStatement;

private FixedCosts fixedCosts;
private YesOrNo showDJFixedCostsScreen;
private YesOrNo showOldDJFixedCostsScreen;
private YesOrNo claimFixedCostsOnEntryDJ;

@JsonIgnore
public boolean isResponseAcceptedByClaimant() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService;
import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;
import uk.gov.hmcts.reform.civil.utils.DefaultJudgmentUtils;
import uk.gov.hmcts.reform.civil.utils.InterestCalculator;
import uk.gov.hmcts.reform.civil.utils.MonetaryConversions;

Expand Down Expand Up @@ -284,8 +285,21 @@ private BigDecimal getClaimFee(CaseData caseData) {
claimFeePounds = caseData.getOutstandingFeeInPounds();
}

if (caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES) {
if (caseData.getPaymentConfirmationDecisionSpec() == YesOrNo.YES
&& caseData.getFixedCosts() == null) {
claimFeePounds = claimFeePounds.add(calculateFixedCosts(caseData));
} else if (caseData.getFixedCosts() != null) {
// if new mandatory fixed costs question was answered at claim issue
if (YesOrNo.YES.equals(caseData.getClaimFixedCostsOnEntryDJ())) {
// if new fixed costs was chosen in DJ
claimFeePounds = claimFeePounds.add(DefaultJudgmentUtils.calculateFixedCostsOnEntry(
caseData, JudgmentsOnlineHelper.getDebtAmount(caseData, interestCalculator)));
} else if (YesOrNo.YES.equals(caseData.getFixedCosts().getClaimFixedCosts())) {
// only claimed new fixed costs at claim issue
claimFeePounds = claimFeePounds.add(MonetaryConversions.penniesToPounds(
BigDecimal.valueOf(Integer.parseInt(
caseData.getFixedCosts().getFixedCostAmount()))));
}
}
return claimFeePounds.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : claimFeePounds.setScale(2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.reform.civil.utils;

import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.CaseData;

import java.math.BigDecimal;
Expand All @@ -13,6 +14,9 @@ public class DefaultJudgmentUtils {
private static final int ENTRY_FIXED_COST_22 = 22;
private static final int ENTRY_FIXED_COST_30 = 30;

private static final BigDecimal JUDGMENT_AMOUNT_5000 = BigDecimal.valueOf(5000);
private static final BigDecimal JUDGMENT_AMOUNT_25 = BigDecimal.valueOf(25);

private DefaultJudgmentUtils() {

}
Expand All @@ -35,4 +39,17 @@ public static BigDecimal calculateFixedCosts(CaseData caseData) {
}
return new BigDecimal(fixedCost);
}

public static BigDecimal calculateFixedCostsOnEntry(CaseData caseData, BigDecimal judgmentAmount) {
BigDecimal claimIssueFixedCost = MonetaryConversions.penniesToPounds(BigDecimal.valueOf(
Integer.parseInt(caseData.getFixedCosts().getFixedCostAmount())));
if (YesOrNo.YES.equals(caseData.getClaimFixedCostsOnEntryDJ())) {
if (judgmentAmount.compareTo(JUDGMENT_AMOUNT_5000) > 0) {
return claimIssueFixedCost.add(BigDecimal.valueOf(ENTRY_FIXED_COST_30));
} else if (judgmentAmount.compareTo(JUDGMENT_AMOUNT_25) > 0) {
return claimIssueFixedCost.add(BigDecimal.valueOf(ENTRY_FIXED_COST_22));
}
}
return claimIssueFixedCost;
}
}
Loading

0 comments on commit 6a6a707

Please sign in to comment.