| 37790 |
amit |
1 |
package com.spice.profitmandi.service.inventory;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
4 |
|
|
|
5 |
import java.math.BigDecimal;
|
|
|
6 |
import java.math.RoundingMode;
|
|
|
7 |
import java.time.LocalDate;
|
|
|
8 |
import java.time.LocalDateTime;
|
|
|
9 |
import java.time.LocalTime;
|
|
|
10 |
import java.util.ArrayList;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* What a return is worth when Finance settles it as B2C after NIC refused it for a cancelled or
|
|
|
15 |
* invalid buyer GSTIN: every returned line at its value net of GST, in whole rupees.
|
|
|
16 |
* <p>
|
|
|
17 |
* Standard accounting rounding - each line's net value is rounded HALF_UP to the rupee, and the
|
|
|
18 |
* refund is the sum of those lines, so the line table and the total always agree. The gross is
|
|
|
19 |
* rounded the same way, and the GST retained is simply gross minus refund. The same object feeds
|
|
|
20 |
* the Finance popup, both notification mails and the server-side check of the amount Finance types
|
|
|
21 |
* in, so the three can never disagree.
|
|
|
22 |
*/
|
|
|
23 |
public class B2cRefundQuote {
|
|
|
24 |
|
|
|
25 |
public static class Line {
|
|
|
26 |
private final int refId;
|
|
|
27 |
private final String description;
|
|
|
28 |
private final long quantity;
|
|
|
29 |
private final BigDecimal grossAmount;
|
|
|
30 |
private final BigDecimal gstRate;
|
|
|
31 |
private final long netAmount;
|
|
|
32 |
|
|
|
33 |
Line(int refId, String description, long quantity, BigDecimal grossAmount, BigDecimal gstRate) {
|
|
|
34 |
this.refId = refId;
|
|
|
35 |
this.description = description;
|
|
|
36 |
this.quantity = quantity;
|
|
|
37 |
this.grossAmount = grossAmount.setScale(0, RoundingMode.HALF_UP);
|
|
|
38 |
this.gstRate = gstRate;
|
|
|
39 |
BigDecimal divisor = BigDecimal.ONE.add(gstRate.movePointLeft(2));
|
|
|
40 |
// One rounding step, straight to the rupee - rounding to paisa first would double-round.
|
|
|
41 |
this.netAmount = grossAmount.divide(divisor, 0, RoundingMode.HALF_UP).longValueExact();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/** Order id in the invoice-return flow, inventory item id in the debit-note flow. */
|
|
|
45 |
public int getRefId() {
|
|
|
46 |
return refId;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public String getDescription() {
|
|
|
50 |
return description;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public long getQuantity() {
|
|
|
54 |
return quantity;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public long getGrossAmount() {
|
|
|
58 |
return grossAmount.longValueExact();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public BigDecimal getGstRate() {
|
|
|
62 |
return gstRate;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public long getNetAmount() {
|
|
|
66 |
return netAmount;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public String getFormattedGross() {
|
|
|
70 |
return FormattingUtils.formatDigit(getGrossAmount());
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public String getFormattedNet() {
|
|
|
74 |
return FormattingUtils.formatDigit(netAmount);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public String getFormattedGstRate() {
|
|
|
78 |
return gstRate.stripTrailingZeros().toPlainString();
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private int purchaseReturnOrderId;
|
|
|
83 |
private String flow;
|
|
|
84 |
private String invoiceNumber;
|
|
|
85 |
private int fofoId;
|
|
|
86 |
private String partnerName;
|
|
|
87 |
private String partnerCode;
|
|
|
88 |
private String buyerGstin;
|
|
|
89 |
private String reason;
|
|
|
90 |
private String stage;
|
|
|
91 |
private int attempts;
|
|
|
92 |
private LocalDateTime lastAttemptAt;
|
|
|
93 |
private String lastAttemptBy;
|
|
|
94 |
private final List<Line> lines = new ArrayList<>();
|
|
|
95 |
|
|
|
96 |
void addLine(int refId, String description, long quantity, BigDecimal grossAmount, BigDecimal gstRate) {
|
|
|
97 |
lines.add(new Line(refId, description, quantity, grossAmount, gstRate));
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public List<Line> getLines() {
|
|
|
101 |
return lines;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
public long getGrossTotal() {
|
|
|
105 |
return lines.stream().mapToLong(Line::getGrossAmount).sum();
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
public long getRefundAmount() {
|
|
|
109 |
return lines.stream().mapToLong(Line::getNetAmount).sum();
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public long getGstRetained() {
|
|
|
113 |
return getGrossTotal() - getRefundAmount();
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public long getTotalQuantity() {
|
|
|
117 |
return lines.stream().mapToLong(Line::getQuantity).sum();
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public String getFormattedGrossTotal() {
|
|
|
121 |
return FormattingUtils.formatDigit(getGrossTotal());
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public String getFormattedRefundAmount() {
|
|
|
125 |
return FormattingUtils.formatDigit(getRefundAmount());
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public String getFormattedGstRetained() {
|
|
|
129 |
return FormattingUtils.formatDigit(getGstRetained());
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/** The B2C option stays open until the end of the calendar day of the latest refusal. */
|
|
|
133 |
public LocalDateTime getAvailableUntil() {
|
|
|
134 |
return lastAttemptAt == null ? null : lastAttemptAt.toLocalDate().atTime(LocalTime.of(23, 59, 59));
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public boolean isAvailable() {
|
|
|
138 |
return lastAttemptAt != null && lastAttemptAt.toLocalDate().equals(LocalDate.now());
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
public String getFormattedAvailableUntil() {
|
|
|
142 |
return getAvailableUntil() == null ? "" : FormattingUtils.format(getAvailableUntil());
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public String getFormattedLastAttemptAt() {
|
|
|
146 |
return lastAttemptAt == null ? "" : FormattingUtils.format(lastAttemptAt);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public int getPurchaseReturnOrderId() {
|
|
|
150 |
return purchaseReturnOrderId;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
public void setPurchaseReturnOrderId(int purchaseReturnOrderId) {
|
|
|
154 |
this.purchaseReturnOrderId = purchaseReturnOrderId;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public String getFlow() {
|
|
|
158 |
return flow;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public void setFlow(String flow) {
|
|
|
162 |
this.flow = flow;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public String getInvoiceNumber() {
|
|
|
166 |
return invoiceNumber;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public void setInvoiceNumber(String invoiceNumber) {
|
|
|
170 |
this.invoiceNumber = invoiceNumber;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
public int getFofoId() {
|
|
|
174 |
return fofoId;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
public void setFofoId(int fofoId) {
|
|
|
178 |
this.fofoId = fofoId;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
public String getPartnerName() {
|
|
|
182 |
return partnerName;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
public void setPartnerName(String partnerName) {
|
|
|
186 |
this.partnerName = partnerName;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public String getPartnerCode() {
|
|
|
190 |
return partnerCode;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public void setPartnerCode(String partnerCode) {
|
|
|
194 |
this.partnerCode = partnerCode;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public String getBuyerGstin() {
|
|
|
198 |
return buyerGstin;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
public void setBuyerGstin(String buyerGstin) {
|
|
|
202 |
this.buyerGstin = buyerGstin;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public String getReason() {
|
|
|
206 |
return reason;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public void setReason(String reason) {
|
|
|
210 |
this.reason = reason;
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public String getStage() {
|
|
|
214 |
return stage;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public void setStage(String stage) {
|
|
|
218 |
this.stage = stage;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
public int getAttempts() {
|
|
|
222 |
return attempts;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public void setAttempts(int attempts) {
|
|
|
226 |
this.attempts = attempts;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
public LocalDateTime getLastAttemptAt() {
|
|
|
230 |
return lastAttemptAt;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
public void setLastAttemptAt(LocalDateTime lastAttemptAt) {
|
|
|
234 |
this.lastAttemptAt = lastAttemptAt;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
public String getLastAttemptBy() {
|
|
|
238 |
return lastAttemptBy;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
public void setLastAttemptBy(String lastAttemptBy) {
|
|
|
242 |
this.lastAttemptBy = lastAttemptBy;
|
|
|
243 |
}
|
|
|
244 |
}
|