| 37398 |
amit |
1 |
package com.spice.profitmandi.service.order;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
|
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
|
|
6 |
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Builds the printable invoice line for an extended-warranty / damage-protection policy.
|
|
|
12 |
*
|
|
|
13 |
* <p>A policy is not a catalog item, so it has no {@code fofo_order_item} row; it reaches the PDF
|
|
|
14 |
* as a {@link CustomInsurancePolicy} and is folded into the item table by
|
|
|
15 |
* {@code DocumentData.items()}. Two invoices can carry one: the partner sale invoice
|
|
|
16 |
* ({@link OrderServiceImpl#getInvoicePdfModel}) when the policy was sold alongside the device, and
|
|
|
17 |
* the standalone invoice raised on behalf of the provider when it was sold on its own. Both build
|
|
|
18 |
* the line here so the SAC, tax split and description cannot drift apart.
|
|
|
19 |
*/
|
|
|
20 |
public final class InsuranceInvoiceLine {
|
|
|
21 |
|
|
|
22 |
/** SAC for insurance services. */
|
|
|
23 |
private static final String SAC_CODE = "998716";
|
|
|
24 |
|
|
|
25 |
/** Printed when the policy carries no plan name of its own. */
|
|
|
26 |
private static final String DEFAULT_PLAN = "Damage Protection Plan";
|
|
|
27 |
|
|
|
28 |
private InsuranceInvoiceLine() {
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
public static List<CustomInsurancePolicy> from(List<InsurancePolicy> policies) {
|
|
|
32 |
List<CustomInsurancePolicy> lines = new ArrayList<>();
|
|
|
33 |
if (policies == null) {
|
|
|
34 |
return lines;
|
|
|
35 |
}
|
|
|
36 |
for (InsurancePolicy policy : policies) {
|
|
|
37 |
lines.add(from(policy));
|
|
|
38 |
}
|
|
|
39 |
return lines;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* The policy is sold tax-inclusive, so the sale amount is grossed down to the taxable value and
|
|
|
44 |
* both the inter-state and intra-state tax sides are populated; the renderer keeps whichever
|
|
|
45 |
* applies to the supply and drops the other.
|
|
|
46 |
*/
|
|
|
47 |
public static CustomInsurancePolicy from(InsurancePolicy policy) {
|
|
|
48 |
float taxRate = ProfitMandiConstants.INSURANCE_TAX_RATE;
|
|
|
49 |
float halfRate = taxRate / 2;
|
|
|
50 |
float taxableAmount = policy.getSaleAmount() / (1 + taxRate / 100);
|
|
|
51 |
|
|
|
52 |
CustomInsurancePolicy line = new CustomInsurancePolicy();
|
|
|
53 |
line.setDescription(description(policy));
|
|
|
54 |
line.setHsnCode(SAC_CODE);
|
|
|
55 |
line.setRate(taxableAmount);
|
|
|
56 |
line.setIgstRate(taxRate);
|
|
|
57 |
line.setIgstAmount(taxableAmount * taxRate / 100);
|
|
|
58 |
line.setCgstRate(halfRate);
|
|
|
59 |
line.setCgstAmount(taxableAmount * halfRate / 100);
|
|
|
60 |
line.setSgstRate(halfRate);
|
|
|
61 |
line.setSgstAmount(taxableAmount * halfRate / 100);
|
|
|
62 |
line.setNetAmount(policy.getSaleAmount());
|
|
|
63 |
return line;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* {@code policyPlan} is only populated when the policy was sold through a plan-quote flow;
|
|
|
68 |
* policies sold on their own leave it null, so fall back to the generic plan name rather than
|
|
|
69 |
* printing "null" on a tax document.
|
|
|
70 |
*/
|
|
|
71 |
private static String description(InsurancePolicy policy) {
|
|
|
72 |
String plan = policy.getPolicyPlan() != null && !policy.getPolicyPlan().trim().isEmpty()
|
|
|
73 |
? policy.getPolicyPlan()
|
|
|
74 |
: DEFAULT_PLAN;
|
|
|
75 |
return plan + " for Device #" + policy.getSerialNumber()
|
|
|
76 |
+ "\n Plan Reference - " + policy.getPolicyNumber();
|
|
|
77 |
}
|
|
|
78 |
}
|