| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.document;
|
1 |
package com.spice.profitmandi.common.document;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
3 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| - |
|
4 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
| 4 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
5 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
| 5 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
6 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
| 6 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 7 |
import com.spice.profitmandi.common.model.EWayBillPdfModel;
|
8 |
import com.spice.profitmandi.common.model.EWayBillPdfModel;
|
| 8 |
import com.spice.profitmandi.common.model.InvoicePdfModel;
|
9 |
import com.spice.profitmandi.common.model.InvoicePdfModel;
|
| 9 |
import com.spice.profitmandi.common.model.IrnModel;
|
10 |
import com.spice.profitmandi.common.model.IrnModel;
|
| 10 |
|
11 |
|
| - |
|
12 |
import java.util.ArrayList;
|
| 11 |
import java.util.List;
|
13 |
import java.util.List;
|
| 12 |
|
14 |
|
| 13 |
/**
|
15 |
/**
|
| 14 |
* Normalized view of a printable document, consumed by the rendering {@code Section}s.
|
16 |
* Normalized view of a printable document, consumed by the rendering {@code Section}s.
|
| 15 |
*
|
17 |
*
|
| Line 55... |
Line 57... |
| 55 |
private final String documentNumber;
|
57 |
private final String documentNumber;
|
| 56 |
private final String documentDate;
|
58 |
private final String documentDate;
|
| 57 |
private final String originalInvoiceNumber;
|
59 |
private final String originalInvoiceNumber;
|
| 58 |
private final String originalInvoiceDate;
|
60 |
private final String originalInvoiceDate;
|
| 59 |
|
61 |
|
| - |
|
62 |
/** Memoized {@link #items()} result — insurance folding runs once per document. */
|
| - |
|
63 |
private List<CustomOrderItem> items;
|
| - |
|
64 |
private boolean itemsBuilt;
|
| - |
|
65 |
|
| 60 |
public DocumentData(InvoicePdfModel model, DocumentType type, String title,
|
66 |
public DocumentData(InvoicePdfModel model, DocumentType type, String title,
|
| 61 |
String documentNumber, String documentDate,
|
67 |
String documentNumber, String documentDate,
|
| 62 |
String originalInvoiceNumber, String originalInvoiceDate) {
|
68 |
String originalInvoiceNumber, String originalInvoiceDate) {
|
| 63 |
this.model = model;
|
69 |
this.model = model;
|
| 64 |
this.type = type;
|
70 |
this.type = type;
|
| Line 86... |
Line 92... |
| 86 |
return type == DocumentType.DEBIT_NOTE || type == DocumentType.CREDIT_NOTE;
|
92 |
return type == DocumentType.DEBIT_NOTE || type == DocumentType.CREDIT_NOTE;
|
| 87 |
}
|
93 |
}
|
| 88 |
|
94 |
|
| 89 |
public CustomCustomer customer() { return model.getCustomer(); }
|
95 |
public CustomCustomer customer() { return model.getCustomer(); }
|
| 90 |
public CustomRetailer retailer() { return model.getRetailer(); }
|
96 |
public CustomRetailer retailer() { return model.getRetailer(); }
|
| - |
|
97 |
/**
|
| - |
|
98 |
* Printable lines: the order items followed by one line per insurance policy.
|
| - |
|
99 |
*
|
| - |
|
100 |
* <p>An extended-warranty / damage-protection policy is not a catalog item, so it has no
|
| - |
|
101 |
* {@code fofo_order_item} row and arrives on the model as a {@link CustomInsurancePolicy}
|
| - |
|
102 |
* instead. It is still a supply on the invoice and must be printed and taxed like any other
|
| - |
|
103 |
* line, so it is folded in here — at the single accessor every section reads — rather than in
|
| - |
|
104 |
* each section. Insurance sold after the device sale gets its own invoice, whose only line is
|
| - |
|
105 |
* the policy; without this the whole table (and therefore the totals) came out empty.
|
| - |
|
106 |
*/
|
| - |
|
107 |
public List<CustomOrderItem> items() {
|
| - |
|
108 |
if (!itemsBuilt) {
|
| - |
|
109 |
items = buildItems();
|
| - |
|
110 |
itemsBuilt = true;
|
| - |
|
111 |
}
|
| - |
|
112 |
return items;
|
| - |
|
113 |
}
|
| - |
|
114 |
|
| - |
|
115 |
private List<CustomOrderItem> buildItems() {
|
| - |
|
116 |
List<CustomInsurancePolicy> policies = model.getInsurancePolicies();
|
| - |
|
117 |
if (policies == null || policies.isEmpty()) {
|
| - |
|
118 |
// No policies: hand back the model's own list untouched so nothing else can shift.
|
| - |
|
119 |
return model.getOrderItems();
|
| - |
|
120 |
}
|
| - |
|
121 |
List<CustomOrderItem> combined = new ArrayList<>();
|
| - |
|
122 |
if (model.getOrderItems() != null) {
|
| - |
|
123 |
combined.addAll(model.getOrderItems());
|
| - |
|
124 |
}
|
| - |
|
125 |
boolean intraState = intraState();
|
| - |
|
126 |
for (CustomInsurancePolicy policy : policies) {
|
| - |
|
127 |
combined.add(toOrderItem(policy, intraState));
|
| - |
|
128 |
}
|
| - |
|
129 |
return combined;
|
| - |
|
130 |
}
|
| - |
|
131 |
|
| - |
|
132 |
/**
|
| - |
|
133 |
* Maps a policy onto a printable line, mirroring the columns the pre-refactor renderer emitted:
|
| - |
|
134 |
* quantity 1, no discount, the taxable value repeated in the Rate column, and only the tax side
|
| - |
|
135 |
* that applies to this supply populated — matching how real order items are built, so the
|
| - |
|
136 |
* margin-scheme rate column (which sums all three tax amounts) stays correct.
|
| - |
|
137 |
*/
|
| - |
|
138 |
private static CustomOrderItem toOrderItem(CustomInsurancePolicy policy, boolean intraState) {
|
| 91 |
public List<CustomOrderItem> items() { return model.getOrderItems(); }
|
139 |
CustomOrderItem item = new CustomOrderItem();
|
| - |
|
140 |
item.setDescription(policy.getDescription());
|
| - |
|
141 |
item.setHsnCode(policy.getHsnCode());
|
| - |
|
142 |
item.setQuantity(1);
|
| - |
|
143 |
item.setRate(policy.getRate());
|
| - |
|
144 |
item.setDiscount(0f);
|
| - |
|
145 |
item.setAmount(policy.getRate());
|
| - |
|
146 |
item.setNetAmount(policy.getNetAmount());
|
| - |
|
147 |
if (intraState) {
|
| - |
|
148 |
item.setCgstRate(policy.getCgstRate());
|
| - |
|
149 |
item.setCgstAmount(policy.getCgstAmount());
|
| - |
|
150 |
item.setSgstRate(policy.getSgstRate());
|
| - |
|
151 |
item.setSgstAmount(policy.getSgstAmount());
|
| - |
|
152 |
} else {
|
| - |
|
153 |
item.setIgstRate(policy.getIgstRate());
|
| - |
|
154 |
item.setIgstAmount(policy.getIgstAmount());
|
| - |
|
155 |
}
|
| - |
|
156 |
return item;
|
| - |
|
157 |
}
|
| - |
|
158 |
|
| 92 |
public List<CustomPaymentOption> paymentOptions() { return model.getPaymentOptions(); }
|
159 |
public List<CustomPaymentOption> paymentOptions() { return model.getPaymentOptions(); }
|
| 93 |
public List<String> creditTerms() { return model.getCreditTerms(); }
|
160 |
public List<String> creditTerms() { return model.getCreditTerms(); }
|
| 94 |
public IrnModel irnModel() { return model.getIrnModel(); }
|
161 |
public IrnModel irnModel() { return model.getIrnModel(); }
|
| 95 |
public String irnErrorMessage() { return model.getIrnErrorMessage(); }
|
162 |
public String irnErrorMessage() { return model.getIrnErrorMessage(); }
|
| 96 |
public EWayBillPdfModel eWayBill() { return model.geteWayBillPdfModel(); }
|
163 |
public EWayBillPdfModel eWayBill() { return model.geteWayBillPdfModel(); }
|