| 4600 |
varun.gupt |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.ByteArrayOutputStream;
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.FileInputStream;
|
|
|
6 |
import java.io.FileNotFoundException;
|
|
|
7 |
import java.io.IOException;
|
|
|
8 |
import java.text.DateFormat;
|
|
|
9 |
import java.text.ParseException;
|
|
|
10 |
import java.text.SimpleDateFormat;
|
| 4715 |
varun.gupt |
11 |
import java.util.ArrayList;
|
| 4600 |
varun.gupt |
12 |
import java.util.Date;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
|
| 4734 |
varun.gupt |
17 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
18 |
import in.shop2020.logistics.Provider;
|
| 4600 |
varun.gupt |
19 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
|
|
20 |
import in.shop2020.model.v1.catalog.Vendor;
|
|
|
21 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
22 |
import in.shop2020.model.v1.order.Order;
|
| 4734 |
varun.gupt |
23 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 4600 |
varun.gupt |
24 |
import in.shop2020.model.v1.order.PaymentSettlement;
|
|
|
25 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
26 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
27 |
import in.shop2020.payments.Payment;
|
|
|
28 |
import in.shop2020.payments.PaymentException;
|
|
|
29 |
import in.shop2020.payments.PaymentGateway;
|
|
|
30 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 4734 |
varun.gupt |
31 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 4600 |
varun.gupt |
32 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
33 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
34 |
|
|
|
35 |
import javax.servlet.ServletContext;
|
|
|
36 |
import javax.servlet.ServletOutputStream;
|
|
|
37 |
import javax.servlet.http.HttpServletRequest;
|
|
|
38 |
import javax.servlet.http.HttpServletResponse;
|
|
|
39 |
import javax.servlet.http.HttpSession;
|
|
|
40 |
|
|
|
41 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
42 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
43 |
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
44 |
import org.apache.poi.ss.usermodel.Font;
|
|
|
45 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
46 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
47 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
48 |
import org.apache.poi.ss.util.CellRangeAddress;
|
| 4601 |
varun.gupt |
49 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
50 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
51 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
52 |
import org.apache.struts2.convention.annotation.Results;
|
| 4600 |
varun.gupt |
53 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
54 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
55 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
56 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
57 |
import org.apache.struts2.util.ServletContextAware;
|
| 4715 |
varun.gupt |
58 |
import org.apache.thrift.TApplicationException;
|
| 4600 |
varun.gupt |
59 |
import org.apache.thrift.TException;
|
|
|
60 |
import org.apache.thrift.transport.TTransportException;
|
|
|
61 |
import org.slf4j.Logger;
|
|
|
62 |
import org.slf4j.LoggerFactory;
|
|
|
63 |
|
| 4715 |
varun.gupt |
64 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
65 |
|
| 4600 |
varun.gupt |
66 |
/**
|
|
|
67 |
* @author Varun Gupta
|
|
|
68 |
* @description: This class handles web requests to generate vendor specific reconciliation reports
|
|
|
69 |
* for given vendor for a given date range
|
|
|
70 |
*/
|
| 4745 |
varun.gupt |
71 |
//
|
| 4715 |
varun.gupt |
72 |
//@InterceptorRefs({
|
|
|
73 |
// @InterceptorRef("defaultStack"),
|
|
|
74 |
// @InterceptorRef("login")
|
|
|
75 |
//})
|
|
|
76 |
//@Results({
|
|
|
77 |
// @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
78 |
//})
|
|
|
79 |
public class VendorReconciliationController extends ValidationAwareSupport implements ServletRequestAware, ServletResponseAware, ServletContextAware {
|
| 4600 |
varun.gupt |
80 |
|
|
|
81 |
private static Logger logger = LoggerFactory.getLogger(VendorReconciliationController.class);
|
|
|
82 |
|
|
|
83 |
private enum OrderReportColumn {
|
|
|
84 |
ORDER_ID(0),
|
|
|
85 |
ORDER_DATE(1),
|
|
|
86 |
BILLING_NUMBER(2),
|
|
|
87 |
BILLING_DATE(3),
|
|
|
88 |
DELIVERY_DATE(4),
|
|
|
89 |
SETTLEMENT_DATE(5),
|
|
|
90 |
CURRENT_STATUS(6),
|
| 4745 |
varun.gupt |
91 |
PAYMENT_STATUS(7),
|
| 4600 |
varun.gupt |
92 |
BRAND(7),
|
|
|
93 |
MODEL_NAME(8),
|
|
|
94 |
MODEL_NUMBER(9),
|
|
|
95 |
COLOR(10),
|
|
|
96 |
QUANTITY(11),
|
|
|
97 |
UNIT_TRANSFER_PRICE(12),
|
|
|
98 |
UNIT_SELLING_PRICE(13),
|
|
|
99 |
TOTAL_TRANSFER_PRICE(14),
|
|
|
100 |
TOTAL_SELLING_PRICE(15),
|
|
|
101 |
GATEWAY_TRANSACTION_ID(16),
|
|
|
102 |
PAYMENT_TYPE(17),
|
|
|
103 |
PAYMENT_ID(18),
|
|
|
104 |
COUPON_CODE(19),
|
|
|
105 |
SERVICE_TAX(20),
|
|
|
106 |
OTHER_CHARGES(21),
|
| 4715 |
varun.gupt |
107 |
NET_COLLECTION(22),
|
|
|
108 |
REFUND(23),
|
|
|
109 |
FINAL_AMOUNT(24),
|
|
|
110 |
IS_RESHIPED_ORDER(25);
|
| 4600 |
varun.gupt |
111 |
// COUPON_CATEGORY(19),
|
|
|
112 |
// DISCOUNT(20),
|
|
|
113 |
|
|
|
114 |
private int value;
|
|
|
115 |
|
|
|
116 |
OrderReportColumn(int value) {
|
|
|
117 |
this.value = value;
|
|
|
118 |
}
|
|
|
119 |
public int getValue(){
|
|
|
120 |
return this.value;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
private enum OrderMismatchColumn {
|
|
|
125 |
ORDER_ID(0),
|
|
|
126 |
EXPECTED_COLLECTION(1),
|
|
|
127 |
ACTUAL_COLLECTION(2);
|
|
|
128 |
|
|
|
129 |
private int value;
|
|
|
130 |
|
|
|
131 |
OrderMismatchColumn(int value) {
|
|
|
132 |
this.value = value;
|
|
|
133 |
}
|
|
|
134 |
public int getValue(){
|
|
|
135 |
return this.value;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
private HttpServletRequest request;
|
|
|
140 |
private HttpServletResponse response;
|
|
|
141 |
private ServletContext context;
|
|
|
142 |
private HttpSession session;
|
|
|
143 |
private List<Vendor> vendors;
|
|
|
144 |
private String reportSource;
|
| 4715 |
varun.gupt |
145 |
private List<Long> orderIdsWithoutSuccess;
|
| 4600 |
varun.gupt |
146 |
|
|
|
147 |
private File hdfcSettlementReport;
|
|
|
148 |
|
|
|
149 |
private File ebsSettlementReport;
|
|
|
150 |
private File ebsSettlementSummary;
|
|
|
151 |
|
|
|
152 |
private String bluedartSettlementDate;
|
|
|
153 |
private File bluedartSettlementReport;
|
|
|
154 |
|
| 4715 |
varun.gupt |
155 |
private String aramexSettlementDate;
|
|
|
156 |
private File aramexSettlementReport;
|
|
|
157 |
|
| 4600 |
varun.gupt |
158 |
private Map<Long, Map<String, Double>> misMatches = new HashMap<Long, Map<String, Double>>();
|
|
|
159 |
private Map<Long, String> ebsSettlementSummaries;
|
|
|
160 |
|
| 4734 |
varun.gupt |
161 |
private List<OrderStatus> refundOrderStatuses = new ArrayList<OrderStatus>();
|
|
|
162 |
|
| 4745 |
varun.gupt |
163 |
private List<Order> refundedOrdersBilledinDateRange = new ArrayList<Order>();
|
|
|
164 |
private List<Order> reshippedOrders = new ArrayList<Order>();
|
|
|
165 |
|
| 4600 |
varun.gupt |
166 |
private final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
167 |
|
|
|
168 |
public VendorReconciliationController() {
|
|
|
169 |
try {
|
|
|
170 |
CatalogClient csc = new CatalogClient();
|
|
|
171 |
Client catalogClient = csc.getClient();
|
|
|
172 |
|
|
|
173 |
vendors = catalogClient.getAllVendors();
|
| 4715 |
varun.gupt |
174 |
orderIdsWithoutSuccess = new ArrayList<Long>();
|
|
|
175 |
|
| 4600 |
varun.gupt |
176 |
TransactionClient tsc = new TransactionClient();
|
|
|
177 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
178 |
|
|
|
179 |
ebsSettlementSummaries = transactionClient.getEBSSettlementSummaries();
|
| 4715 |
varun.gupt |
180 |
logger.info("", ebsSettlementSummaries);
|
| 4600 |
varun.gupt |
181 |
|
| 4715 |
varun.gupt |
182 |
} catch (TException e) {
|
|
|
183 |
logger.error("TException", e);
|
|
|
184 |
|
|
|
185 |
} catch (TransactionServiceException e) {
|
|
|
186 |
logger.error("TransactionServiceException", e);
|
| 4600 |
varun.gupt |
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public String index() {
|
|
|
191 |
return "report";
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public HttpHeaders create() {
|
|
|
195 |
|
|
|
196 |
String formType = request.getParameter("formtype");
|
| 4715 |
varun.gupt |
197 |
logger.info("Form Type: " + formType);
|
| 4600 |
varun.gupt |
198 |
|
|
|
199 |
if (formType.equals("uploadEBSSettlementSummary")) {
|
|
|
200 |
uploadEBSSettlementSummary();
|
|
|
201 |
|
|
|
202 |
} else if (formType.equals("uploadEBSSettlements")) {
|
|
|
203 |
uploadEBSSettlements();
|
|
|
204 |
|
|
|
205 |
} else if (formType.equals("uploadHDFCSettlements")) {
|
|
|
206 |
uploadHDFCSettlements();
|
|
|
207 |
|
|
|
208 |
} else if (formType.equals("uploadBluedartSettlements")) {
|
|
|
209 |
uploadBluedartSettlements();
|
| 4715 |
varun.gupt |
210 |
|
|
|
211 |
} else if (formType.equals("uploadAramexSettlements")) {
|
|
|
212 |
uploadAramexSettlements();
|
| 4600 |
varun.gupt |
213 |
}
|
| 4715 |
varun.gupt |
214 |
logger.info("Order Ids where no successful payment was found", orderIdsWithoutSuccess);
|
|
|
215 |
|
| 4600 |
varun.gupt |
216 |
return new DefaultHttpHeaders("report");
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public HttpHeaders generateReconciliationReport() {
|
|
|
220 |
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
| 4734 |
varun.gupt |
221 |
|
|
|
222 |
refundOrderStatuses.add(OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST);
|
|
|
223 |
refundOrderStatuses.add(OrderStatus.RTO_REFUNDED);
|
|
|
224 |
refundOrderStatuses.add(OrderStatus.DOA_VALID_REFUNDED);
|
|
|
225 |
refundOrderStatuses.add(OrderStatus.DOA_INVALID_REFUNDED);
|
|
|
226 |
refundOrderStatuses.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
|
|
227 |
refundOrderStatuses.add(OrderStatus.DOA_REFUNDED_RCVD_DAMAGED);
|
|
|
228 |
refundOrderStatuses.add(OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT);
|
|
|
229 |
refundOrderStatuses.add(OrderStatus.RTO_DAMAGED_REFUNDED);
|
|
|
230 |
refundOrderStatuses.add(OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED);
|
|
|
231 |
refundOrderStatuses.add(OrderStatus.RET_PRODUCT_USABLE_REFUNDED);
|
|
|
232 |
refundOrderStatuses.add(OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED);
|
|
|
233 |
refundOrderStatuses.add(OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT);
|
|
|
234 |
refundOrderStatuses.add(OrderStatus.RET_REFUNDED_RCVD_DAMAGED);
|
|
|
235 |
refundOrderStatuses.add(OrderStatus.LOST_IN_TRANSIT_REFUNDED);
|
| 4600 |
varun.gupt |
236 |
|
|
|
237 |
try {
|
|
|
238 |
//Formatting Form input parameters
|
|
|
239 |
|
|
|
240 |
Date startDate = dateFormat.parse(request.getParameter("start"));
|
|
|
241 |
Date endDate = dateFormat.parse(request.getParameter("end"));
|
|
|
242 |
long vendorId = Long.parseLong(request.getParameter("vendor"));
|
|
|
243 |
|
|
|
244 |
logger.info(startDate + " " + endDate + " " + vendorId);
|
|
|
245 |
|
| 4745 |
varun.gupt |
246 |
String vendorName = getVendorName(vendorId);
|
| 4600 |
varun.gupt |
247 |
DateFormat dateFormatForFile = new SimpleDateFormat("dd.MM.yyyy");
|
| 4715 |
varun.gupt |
248 |
|
| 4600 |
varun.gupt |
249 |
response.setContentType("application/vnd.ms-excel");
|
|
|
250 |
response.setHeader("Content-disposition", "inline; filename=" + vendorName + "-reconciliation-from-" + dateFormatForFile.format(startDate) + "-" + dateFormatForFile.format(endDate) + ".xls");
|
|
|
251 |
|
|
|
252 |
ServletOutputStream sos;
|
|
|
253 |
try {
|
| 4745 |
varun.gupt |
254 |
ByteArrayOutputStream baos = getReconciliationReport(vendorId, startDate, endDate);
|
| 4600 |
varun.gupt |
255 |
sos = response.getOutputStream();
|
|
|
256 |
baos.writeTo(sos);
|
|
|
257 |
sos.flush();
|
|
|
258 |
} catch (IOException e) {
|
|
|
259 |
logger.error("Error while streaming the hotspot reconciliation report", e);
|
|
|
260 |
}
|
|
|
261 |
} catch (ParseException e) {
|
|
|
262 |
logger.error("Unable to parse the start or end date", e);
|
|
|
263 |
} catch (NullPointerException e) {
|
|
|
264 |
logger.error("NullPointerException", e);
|
| 4745 |
varun.gupt |
265 |
}
|
| 4600 |
varun.gupt |
266 |
return new DefaultHttpHeaders("report");
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public void uploadEBSSettlementSummary() {
|
|
|
270 |
|
|
|
271 |
DateFormat settlementDateFormat = new SimpleDateFormat("dd MMM,yyyy hh:mm:ss a");
|
|
|
272 |
DateFormat transactionDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
273 |
|
|
|
274 |
Workbook wb = null;
|
|
|
275 |
try {
|
|
|
276 |
wb = new HSSFWorkbook(new FileInputStream(ebsSettlementSummary));
|
|
|
277 |
} catch (FileNotFoundException e) {
|
|
|
278 |
logger.error("Unable to open the Settlement Summary report", e);
|
|
|
279 |
} catch (IOException e) {
|
|
|
280 |
logger.error("Unable to open the Settlement Summary report", e);
|
|
|
281 |
}
|
|
|
282 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
283 |
|
|
|
284 |
int indexSettlementId = 0;
|
|
|
285 |
int indexSettlementDate = 1;
|
|
|
286 |
int indexTransactionDateFrom = 2;
|
|
|
287 |
int indexTransactionDateTo = 3;
|
|
|
288 |
int indexAmount = 4;
|
|
|
289 |
|
|
|
290 |
Row firstRow = sheet.getRow(0);
|
|
|
291 |
Row secondRow = sheet.getRow(1);
|
|
|
292 |
Row thirdRow = sheet.getRow(2);
|
|
|
293 |
Row fourthRow = sheet.getRow(3);
|
|
|
294 |
Row fifthRow = sheet.getRow(4);
|
|
|
295 |
|
|
|
296 |
TransactionClient tsc;
|
|
|
297 |
|
|
|
298 |
try {
|
|
|
299 |
tsc = new TransactionClient();
|
|
|
300 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
301 |
|
|
|
302 |
for(Row row: sheet) {
|
|
|
303 |
if(row.equals(firstRow) || row.equals(secondRow) || row.equals(thirdRow) || row.equals(fourthRow) || row.equals(fifthRow)) {
|
|
|
304 |
continue;
|
|
|
305 |
}
|
|
|
306 |
long settlementId = (long) row.getCell(indexSettlementId).getNumericCellValue();
|
|
|
307 |
String settlementDateStr = row.getCell(indexSettlementDate).getStringCellValue();
|
|
|
308 |
String transactionDateFromStr = row.getCell(indexTransactionDateFrom).getStringCellValue();
|
|
|
309 |
String transactionDateToStr = row.getCell(indexTransactionDateTo).getStringCellValue();
|
|
|
310 |
Double amount = row.getCell(indexAmount).getNumericCellValue();
|
|
|
311 |
|
|
|
312 |
Date settlementDate = settlementDateFormat.parse(settlementDateStr);
|
|
|
313 |
Date transactionDateFrom = transactionDateFormat.parse(transactionDateFromStr);
|
|
|
314 |
Date transactionDateTo = transactionDateFormat.parse(transactionDateToStr);
|
|
|
315 |
|
|
|
316 |
try {
|
|
|
317 |
transactionClient.saveEBSSettlementSummary(settlementId, settlementDate.getTime(), transactionDateFrom.getTime(), transactionDateTo.getTime(), amount);
|
|
|
318 |
|
|
|
319 |
} catch (Exception e) {
|
|
|
320 |
e.printStackTrace();
|
|
|
321 |
}
|
|
|
322 |
}
|
|
|
323 |
} catch (Exception e) {
|
|
|
324 |
e.printStackTrace();
|
|
|
325 |
}
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
public void uploadHDFCSettlements() {
|
|
|
329 |
logger.info("Uploading HDFC settlements");
|
|
|
330 |
|
|
|
331 |
Workbook wb = null;
|
|
|
332 |
try {
|
|
|
333 |
wb = new HSSFWorkbook(new FileInputStream(this.hdfcSettlementReport));
|
|
|
334 |
} catch (FileNotFoundException e) {
|
| 4734 |
varun.gupt |
335 |
String errMsg = "Unable to open the HDFC Payout report";
|
|
|
336 |
logger.error(errMsg, e);
|
|
|
337 |
addActionError(errMsg);
|
|
|
338 |
return;
|
| 4600 |
varun.gupt |
339 |
} catch (IOException e) {
|
| 4734 |
varun.gupt |
340 |
String errMsg = "Unable to open the HDFC Payout report";
|
|
|
341 |
logger.error(errMsg, e);
|
|
|
342 |
addActionError(errMsg);
|
|
|
343 |
return;
|
| 4600 |
varun.gupt |
344 |
}
|
|
|
345 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
346 |
|
|
|
347 |
Row firstRow = sheet.getRow(0);
|
|
|
348 |
|
|
|
349 |
int indexRECFMT = 2;
|
|
|
350 |
int indexSettlementDate = 7;
|
|
|
351 |
int indexPaymentId = 13;
|
|
|
352 |
int indexMSF = 14;
|
|
|
353 |
int indexServiceTax = 15;
|
|
|
354 |
int indexEduCess = 16;
|
|
|
355 |
int indexNetCollection = 17;
|
|
|
356 |
|
|
|
357 |
TransactionClient tsc;
|
|
|
358 |
String paymentIdStr = "";
|
|
|
359 |
long paymentId = 0;
|
| 4734 |
varun.gupt |
360 |
|
|
|
361 |
int countSuccessfulInserts = 0;
|
|
|
362 |
int countRefunds = 0;
|
| 4600 |
varun.gupt |
363 |
|
|
|
364 |
try {
|
|
|
365 |
tsc = new TransactionClient();
|
|
|
366 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
367 |
|
|
|
368 |
for (Row row: sheet) {
|
|
|
369 |
if(row.equals(firstRow)) continue;
|
|
|
370 |
|
|
|
371 |
try {
|
|
|
372 |
String recfmt = row.getCell(indexRECFMT).getStringCellValue();
|
|
|
373 |
Date settlementDate = row.getCell(indexSettlementDate).getDateCellValue();
|
|
|
374 |
double netCollection = row.getCell(indexNetCollection).getNumericCellValue();
|
|
|
375 |
paymentIdStr = row.getCell(indexPaymentId).getStringCellValue().replace("'", "");
|
|
|
376 |
paymentId = Long.parseLong(paymentIdStr);
|
|
|
377 |
|
|
|
378 |
logger.info("paymentId: " + paymentId + ", recfmt: " + recfmt + ", settlementDate: " + settlementDate + ", netCollection: " + netCollection);
|
|
|
379 |
|
| 4715 |
varun.gupt |
380 |
if (recfmt.trim().equalsIgnoreCase("CVD")) {
|
|
|
381 |
if (netCollection > 0.0) netCollection *= -1.0;
|
|
|
382 |
transactionClient.savePaymentSettlements(settlementDate.getTime(), 1, paymentId, 0.0, 0.0, netCollection);
|
| 4734 |
varun.gupt |
383 |
countRefunds += 1;
|
| 4600 |
varun.gupt |
384 |
|
|
|
385 |
} else {
|
|
|
386 |
double msf = row.getCell(indexMSF).getNumericCellValue();
|
|
|
387 |
double serviceTax = row.getCell(indexServiceTax).getNumericCellValue();
|
|
|
388 |
double eduCess = row.getCell(indexEduCess).getNumericCellValue();
|
|
|
389 |
logger.info("msf: " + msf + ", serviceTax: " + serviceTax + ", eduCess: " + eduCess);
|
|
|
390 |
|
|
|
391 |
transactionClient.savePaymentSettlements(settlementDate.getTime(), 1, paymentId, serviceTax, (eduCess + msf), netCollection);
|
| 4734 |
varun.gupt |
392 |
countSuccessfulInserts += 1;
|
| 4600 |
varun.gupt |
393 |
}
|
|
|
394 |
} catch (NumberFormatException e) {
|
| 4734 |
varun.gupt |
395 |
String errMsg = "NumberFormatException recieved for payment Id, " + paymentIdStr;
|
|
|
396 |
logger.error(errMsg + e);
|
|
|
397 |
addActionError(errMsg);
|
| 4600 |
varun.gupt |
398 |
|
|
|
399 |
} catch (TransactionServiceException e) {
|
| 4734 |
varun.gupt |
400 |
String errMsg = "TransactionServiceException recieved for payment Id, " + paymentId;
|
|
|
401 |
logger.error(errMsg + e);
|
|
|
402 |
addActionError(errMsg);
|
| 4600 |
varun.gupt |
403 |
}
|
|
|
404 |
}
|
|
|
405 |
} catch (TTransportException e) {
|
|
|
406 |
logger.error("TTransportException recieved for payment Id," + Long.toString(paymentId) + " " + e);
|
|
|
407 |
|
|
|
408 |
} catch (TException e) {
|
|
|
409 |
logger.error("TException recieved for payment Id," + Long.toString(paymentId) + " " + e);
|
|
|
410 |
}
|
| 4734 |
varun.gupt |
411 |
addActionMessage("Added settlements for " + countSuccessfulInserts + " payments");
|
|
|
412 |
addActionMessage("Added settlements for " + countRefunds + " refund payments");
|
| 4600 |
varun.gupt |
413 |
}
|
|
|
414 |
|
|
|
415 |
public void uploadEBSSettlements() {
|
|
|
416 |
Workbook wb = null;
|
|
|
417 |
try {
|
|
|
418 |
wb = new HSSFWorkbook(new FileInputStream(this.ebsSettlementReport));
|
|
|
419 |
} catch (FileNotFoundException e) {
|
| 4734 |
varun.gupt |
420 |
logger.error("Unable to open the EBS Settlement detail report", e);
|
| 4600 |
varun.gupt |
421 |
} catch (IOException e) {
|
| 4734 |
varun.gupt |
422 |
logger.error("Unable to open the EBS Settlement detail report", e);
|
| 4600 |
varun.gupt |
423 |
}
|
|
|
424 |
|
|
|
425 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
426 |
|
|
|
427 |
Row firstRow = sheet.getRow(0);
|
|
|
428 |
Row secondRow = sheet.getRow(1);
|
|
|
429 |
|
|
|
430 |
int indexPaymentId = 2;
|
|
|
431 |
int indexTxnType = 5;
|
|
|
432 |
int indexAmount = 6;
|
|
|
433 |
|
|
|
434 |
Map<Long, Map<String, Double>> map = new HashMap<Long, Map<String,Double>>();
|
|
|
435 |
Map <String, Double> record;
|
| 4734 |
varun.gupt |
436 |
int countPaymentIds = 0;
|
| 4600 |
varun.gupt |
437 |
|
|
|
438 |
try {
|
|
|
439 |
for (Row row: sheet) {
|
|
|
440 |
if(row.equals(firstRow) || row.equals(secondRow)) continue;
|
|
|
441 |
|
|
|
442 |
long paymentId = Long.parseLong(row.getCell(indexPaymentId).getStringCellValue());
|
|
|
443 |
String transactionType = row.getCell(indexTxnType).getStringCellValue();
|
|
|
444 |
double amount = row.getCell(indexAmount).getNumericCellValue();
|
|
|
445 |
|
|
|
446 |
if(map.containsKey(paymentId)) {
|
|
|
447 |
map.get(paymentId).put(transactionType, amount);
|
|
|
448 |
|
|
|
449 |
} else {
|
|
|
450 |
record = new HashMap<String, Double>();
|
|
|
451 |
record.put(transactionType, amount);
|
|
|
452 |
map.put(paymentId, record);
|
| 4734 |
varun.gupt |
453 |
countPaymentIds += 1;
|
| 4600 |
varun.gupt |
454 |
}
|
|
|
455 |
}
|
|
|
456 |
} catch (NullPointerException e) {
|
|
|
457 |
logger.error("" + e);
|
|
|
458 |
}
|
| 4734 |
varun.gupt |
459 |
addActionMessage("Total Payment Ids added: " + countPaymentIds);
|
| 4600 |
varun.gupt |
460 |
|
|
|
461 |
TransactionClient tsc;
|
|
|
462 |
long settlementId = Long.parseLong(request.getParameter("settlementId"));
|
|
|
463 |
|
| 4734 |
varun.gupt |
464 |
int countPaymentsRecieved = 0;
|
|
|
465 |
int countPaymentsRefunded = 0;
|
|
|
466 |
|
| 4600 |
varun.gupt |
467 |
try {
|
|
|
468 |
tsc = new TransactionClient();
|
|
|
469 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
| 4734 |
varun.gupt |
470 |
long settlementDate;
|
| 4600 |
varun.gupt |
471 |
|
| 4734 |
varun.gupt |
472 |
try {
|
|
|
473 |
settlementDate = transactionClient.getEBSSettlementDate(settlementId);
|
|
|
474 |
} catch (TransactionServiceException e) {
|
|
|
475 |
String errMsg = "Could not retrieve EBS Settlement date for settlementId, " + settlementId;
|
|
|
476 |
logger.error(errMsg + e);
|
|
|
477 |
addActionError(errMsg);
|
|
|
478 |
return;
|
|
|
479 |
}
|
|
|
480 |
|
| 4600 |
varun.gupt |
481 |
for (long paymentId: map.keySet()) {
|
|
|
482 |
record = map.get(paymentId);
|
|
|
483 |
|
|
|
484 |
if(record.containsKey("Captured")) {
|
|
|
485 |
double capturedAmount = record.get("Captured");
|
|
|
486 |
double tdr = record.get("TDR");
|
|
|
487 |
double serviceTax = record.get("ServiceTax");
|
|
|
488 |
|
|
|
489 |
if(tdr < 0) tdr *= -1;
|
|
|
490 |
if(serviceTax < 0) serviceTax *= -1;
|
|
|
491 |
|
|
|
492 |
double amount = capturedAmount - tdr - serviceTax;
|
| 4734 |
varun.gupt |
493 |
|
|
|
494 |
try {
|
|
|
495 |
transactionClient.savePaymentSettlements(settlementDate, 2, paymentId, serviceTax, tdr, amount);
|
|
|
496 |
} catch (TransactionServiceException e) {
|
|
|
497 |
String errMsg = "Could not save settlement for paymentId, " + paymentId;
|
|
|
498 |
logger.error(errMsg + e);
|
|
|
499 |
addActionError(errMsg);
|
|
|
500 |
}
|
|
|
501 |
countPaymentsRecieved += 1;
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
if(record.containsKey("Refunded")) {
|
| 4600 |
varun.gupt |
505 |
double refundedAmount = record.get("Refunded");
|
|
|
506 |
|
|
|
507 |
if (refundedAmount > 0) refundedAmount *= -1;
|
|
|
508 |
|
| 4734 |
varun.gupt |
509 |
try {
|
|
|
510 |
transactionClient.savePaymentSettlements(settlementDate, 2, paymentId, 0.0, 0.0, refundedAmount);
|
|
|
511 |
} catch (TransactionServiceException e) {
|
|
|
512 |
String errMsg = "Could not save refund settlement for paymentId, " + paymentId;
|
|
|
513 |
logger.error(errMsg + e);
|
|
|
514 |
addActionError(errMsg);
|
|
|
515 |
}
|
|
|
516 |
countPaymentsRefunded += 1;
|
| 4600 |
varun.gupt |
517 |
}
|
|
|
518 |
}
|
| 4734 |
varun.gupt |
519 |
addActionMessage("Total count of payments recieved: " + countPaymentsRecieved);
|
|
|
520 |
addActionMessage("Total count of payments refunded: " + countPaymentsRefunded);
|
| 4600 |
varun.gupt |
521 |
|
| 4734 |
varun.gupt |
522 |
try {
|
|
|
523 |
transactionClient.markEBSSettlementUploaded(settlementId);
|
|
|
524 |
} catch (TransactionServiceException e) {
|
|
|
525 |
String errMsg = "Could not mark settlement for details Uploaded. Settlement ID: " + settlementId;
|
|
|
526 |
logger.error(errMsg + e);
|
|
|
527 |
addActionError(errMsg);
|
|
|
528 |
}
|
| 4600 |
varun.gupt |
529 |
} catch (TTransportException e) {
|
|
|
530 |
logger.error("TTransportException " + e);
|
|
|
531 |
} catch (TException e) {
|
|
|
532 |
logger.error("TException " + e);
|
|
|
533 |
}
|
|
|
534 |
}
|
|
|
535 |
|
|
|
536 |
public void uploadBluedartSettlements() {
|
|
|
537 |
|
|
|
538 |
Workbook wb = null;
|
|
|
539 |
try {
|
|
|
540 |
wb = new HSSFWorkbook(new FileInputStream(this.bluedartSettlementReport));
|
|
|
541 |
} catch (FileNotFoundException e) {
|
|
|
542 |
logger.error("Unable to open the Settlement report", e);
|
|
|
543 |
} catch (IOException e) {
|
|
|
544 |
logger.error("Unable to open the Settlement report", e);
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
548 |
|
|
|
549 |
Row firstRow = sheet.getRow(0);
|
|
|
550 |
logger.info("Cell count:" + firstRow.getPhysicalNumberOfCells());
|
|
|
551 |
|
| 4734 |
varun.gupt |
552 |
int indexOrderId = 0;
|
|
|
553 |
int indexAmount = 1;
|
| 4600 |
varun.gupt |
554 |
|
|
|
555 |
TransactionClient tsc;
|
| 4734 |
varun.gupt |
556 |
int countSuccessfulSaves = 0;
|
| 4600 |
varun.gupt |
557 |
|
|
|
558 |
try {
|
|
|
559 |
long settlementDate = DATE_FORMAT.parse(bluedartSettlementDate).getTime();
|
|
|
560 |
tsc = new TransactionClient();
|
|
|
561 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
562 |
|
|
|
563 |
for (Row row : sheet) {
|
| 4875 |
varun.gupt |
564 |
long orderId = 0;
|
| 4600 |
varun.gupt |
565 |
try {
|
|
|
566 |
if(row.equals(firstRow)) continue;
|
| 4875 |
varun.gupt |
567 |
orderId = (long) row.getCell(indexOrderId).getNumericCellValue();
|
| 4715 |
varun.gupt |
568 |
|
| 4600 |
varun.gupt |
569 |
double amount = row.getCell(indexAmount).getNumericCellValue();
|
| 4875 |
varun.gupt |
570 |
transactionClient.saveCODPaymentSettlement(orderId, settlementDate, amount);
|
|
|
571 |
logger.info("SettlementDate: " + settlementDate + ", OrderId: " + orderId + ", Amount: " + amount);
|
|
|
572 |
countSuccessfulSaves += 1;
|
| 4600 |
varun.gupt |
573 |
|
|
|
574 |
} catch (NullPointerException e) {
|
| 4875 |
varun.gupt |
575 |
logger.error("For OrderId: " + orderId + " " + e);
|
| 4600 |
varun.gupt |
576 |
|
| 4875 |
varun.gupt |
577 |
} catch (TransactionServiceException e) {
|
|
|
578 |
logger.error("For OrderId: " + orderId + " " + e);
|
| 4600 |
varun.gupt |
579 |
}
|
|
|
580 |
}
|
|
|
581 |
} catch (ParseException e) {
|
|
|
582 |
logger.error("Could not parse " + bluedartSettlementDate + " " + e);
|
| 4875 |
varun.gupt |
583 |
addActionError(e.getMessage());
|
|
|
584 |
|
| 4600 |
varun.gupt |
585 |
} catch (TTransportException e) {
|
|
|
586 |
logger.error("" + e);
|
| 4875 |
varun.gupt |
587 |
addActionError(e.getMessage());
|
|
|
588 |
|
| 4600 |
varun.gupt |
589 |
} catch (TException e) {
|
|
|
590 |
logger.error("" + e);
|
| 4875 |
varun.gupt |
591 |
addActionError(e.getMessage());
|
| 4600 |
varun.gupt |
592 |
}
|
| 4734 |
varun.gupt |
593 |
addActionMessage("Successfully added Bluedart settlement details for " + countSuccessfulSaves + " orders");
|
| 4600 |
varun.gupt |
594 |
}
|
|
|
595 |
|
| 4715 |
varun.gupt |
596 |
public void uploadAramexSettlements() {
|
|
|
597 |
logger.info("Uploading Aramex Settlements" + this.aramexSettlementDate);
|
|
|
598 |
|
|
|
599 |
if(this.aramexSettlementDate.equals("")) {
|
|
|
600 |
addActionError("Settlement date cannot be left blank");
|
|
|
601 |
return;
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
Workbook wb = null;
|
|
|
605 |
try {
|
|
|
606 |
wb = new HSSFWorkbook(new FileInputStream(this.aramexSettlementReport));
|
|
|
607 |
} catch (FileNotFoundException e) {
|
| 4875 |
varun.gupt |
608 |
addActionError(e.getMessage());
|
| 4715 |
varun.gupt |
609 |
logger.error("Unable to open the Settlement report", e);
|
|
|
610 |
} catch (IOException e) {
|
| 4875 |
varun.gupt |
611 |
addActionError(e.getMessage());
|
| 4715 |
varun.gupt |
612 |
logger.error("Unable to open the Settlement report", e);
|
|
|
613 |
} catch (NullPointerException e) {
|
|
|
614 |
addActionError(e.getMessage());
|
|
|
615 |
logger.error("Unable to open the Settlement report", e);
|
|
|
616 |
return;
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
620 |
|
|
|
621 |
int indexOrderId = 0;
|
| 4734 |
varun.gupt |
622 |
int indexAmount = 1;
|
| 4715 |
varun.gupt |
623 |
|
|
|
624 |
Row firstRow = sheet.getRow(0);
|
|
|
625 |
logger.info("Cell count:" + firstRow.getPhysicalNumberOfCells());
|
|
|
626 |
|
|
|
627 |
TransactionClient tsc;
|
| 4734 |
varun.gupt |
628 |
int countSuccessfulSaves = 0;
|
| 4715 |
varun.gupt |
629 |
try {
|
|
|
630 |
long settlementDate = DATE_FORMAT.parse(aramexSettlementDate).getTime();
|
|
|
631 |
|
|
|
632 |
tsc = new TransactionClient();
|
|
|
633 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
634 |
|
|
|
635 |
for (Row row: sheet) {
|
|
|
636 |
if(row.equals(firstRow)) continue;
|
|
|
637 |
|
|
|
638 |
long orderId = (long) row.getCell(indexOrderId).getNumericCellValue();
|
|
|
639 |
double amount = row.getCell(indexAmount).getNumericCellValue();
|
|
|
640 |
|
|
|
641 |
try {
|
| 4875 |
varun.gupt |
642 |
transactionClient.saveCODPaymentSettlement(orderId, settlementDate, amount);
|
| 4734 |
varun.gupt |
643 |
countSuccessfulSaves += 1;
|
| 4715 |
varun.gupt |
644 |
|
|
|
645 |
} catch (TransactionServiceException e) {
|
|
|
646 |
logger.error("Transaction Service Exception while getting order for id, " + orderId, e);
|
| 4875 |
varun.gupt |
647 |
addActionError("Transaction Service Exception while getting order for id, " + orderId);
|
| 4715 |
varun.gupt |
648 |
}
|
|
|
649 |
}
|
|
|
650 |
} catch (ParseException e) {
|
|
|
651 |
addActionError("Could not parse " + aramexSettlementDate);
|
|
|
652 |
logger.error("Could not parse " + aramexSettlementDate + " " + e);
|
| 4875 |
varun.gupt |
653 |
|
| 4715 |
varun.gupt |
654 |
} catch (TTransportException e) {
|
| 4875 |
varun.gupt |
655 |
addActionError(e.getMessage());
|
| 4715 |
varun.gupt |
656 |
logger.error("" + e);
|
| 4875 |
varun.gupt |
657 |
|
| 4715 |
varun.gupt |
658 |
} catch (TException e) {
|
| 4875 |
varun.gupt |
659 |
addActionError(e.getMessage());
|
| 4715 |
varun.gupt |
660 |
logger.error("" + e);
|
|
|
661 |
}
|
| 4734 |
varun.gupt |
662 |
addActionMessage("Successfully added Aramex settlement details for " + countSuccessfulSaves + " orders");
|
| 4715 |
varun.gupt |
663 |
}
|
|
|
664 |
|
| 4600 |
varun.gupt |
665 |
// Prepares the XLS worksheet object and fills in the data with proper formatting
|
| 4745 |
varun.gupt |
666 |
private ByteArrayOutputStream getReconciliationReport(long vendorId, Date startDate, Date endDate) {
|
|
|
667 |
|
|
|
668 |
List<Order> billedOrders = null;
|
| 4875 |
varun.gupt |
669 |
List<Order> settledOrders = null;
|
|
|
670 |
|
| 4745 |
varun.gupt |
671 |
try {
|
|
|
672 |
TransactionClient tsc = new TransactionClient();
|
|
|
673 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
674 |
|
|
|
675 |
PaymentClient psc = new PaymentClient();
|
|
|
676 |
in.shop2020.payments.PaymentService.Client paymentClient = psc.getClient();
|
|
|
677 |
|
|
|
678 |
billedOrders = transactionClient.getBilledOrdersForVendor(vendorId, startDate.getTime(), endDate.getTime());
|
|
|
679 |
logger.info("Billed Orders count: " + billedOrders.size());
|
|
|
680 |
|
|
|
681 |
List<PaymentSettlement> paymentSettlements = transactionClient.getSettlementsByDate(startDate.getTime(), endDate.getTime(), false);
|
|
|
682 |
logger.info("Settlement Count: " + paymentSettlements.size());
|
|
|
683 |
|
| 4875 |
varun.gupt |
684 |
settledOrders = new ArrayList<Order>();
|
| 4745 |
varun.gupt |
685 |
|
|
|
686 |
for (PaymentSettlement paymentSettlement: paymentSettlements) {
|
|
|
687 |
Payment payment = paymentClient.getPayment(paymentSettlement.getPaymentId());
|
|
|
688 |
Transaction txn = transactionClient.getTransaction(payment.getMerchantTxnId());
|
|
|
689 |
settledOrders.addAll(txn.getOrders());
|
|
|
690 |
}
|
|
|
691 |
logger.info("Settled Orders count: " + settledOrders.size());
|
|
|
692 |
|
|
|
693 |
} catch (TransactionServiceException e) {
|
|
|
694 |
String errMsg = "Transaction Service Exception occured";
|
|
|
695 |
logger.error(errMsg, e);
|
|
|
696 |
addActionError(errMsg);
|
|
|
697 |
} catch (TTransportException e) {
|
|
|
698 |
String errMsg = "Transaction Service Exception occured";
|
|
|
699 |
logger.error(errMsg, e);
|
|
|
700 |
addActionError(errMsg);
|
|
|
701 |
} catch (TException e) {
|
|
|
702 |
// TODO Auto-generated
|
|
|
703 |
String errMsg = "Transaction Service Exception occured";
|
|
|
704 |
logger.error(errMsg, e);
|
|
|
705 |
addActionError(errMsg);
|
|
|
706 |
|
|
|
707 |
} catch (PaymentException e) {
|
|
|
708 |
String errMsg = "Transaction Service Exception occured";
|
|
|
709 |
logger.error(errMsg, e);
|
|
|
710 |
addActionError(errMsg);
|
|
|
711 |
}
|
|
|
712 |
|
| 4875 |
varun.gupt |
713 |
List<Order> settledOrdersForVendor = new ArrayList<Order>();
|
|
|
714 |
|
|
|
715 |
for (Order order: settledOrders) {
|
|
|
716 |
if(order.getVendorId() == vendorId) {
|
|
|
717 |
settledOrdersForVendor.add(order);
|
|
|
718 |
}
|
|
|
719 |
}
|
|
|
720 |
logger.info("Settled Order count for Vendor: " + settledOrdersForVendor.size());
|
|
|
721 |
|
| 4600 |
varun.gupt |
722 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| 4745 |
varun.gupt |
723 |
|
| 4600 |
varun.gupt |
724 |
Workbook wb = new HSSFWorkbook();
|
| 4875 |
varun.gupt |
725 |
|
| 4600 |
varun.gupt |
726 |
//Create the style for the title row
|
|
|
727 |
Font font = wb.createFont();
|
|
|
728 |
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
|
|
729 |
CellStyle boldStyle = wb.createCellStyle();
|
|
|
730 |
boldStyle.setFont(font);
|
|
|
731 |
|
|
|
732 |
CellStyle rightAlignStyle = wb.createCellStyle();
|
|
|
733 |
rightAlignStyle.setAlignment(CellStyle.ALIGN_RIGHT);
|
|
|
734 |
|
|
|
735 |
Sheet orderSheet = wb.createSheet("Orders");
|
| 4875 |
varun.gupt |
736 |
Sheet reshippedOrderSheet = wb.createSheet("Reshipped");
|
| 4600 |
varun.gupt |
737 |
Sheet mismatchSheet = wb.createSheet("Mismatches");
|
|
|
738 |
|
| 4875 |
varun.gupt |
739 |
populateOrderSheet(settledOrdersForVendor, startDate, endDate, orderSheet, boldStyle, rightAlignStyle);
|
|
|
740 |
populateReshippedOrderSheet(reshippedOrders, reshippedOrderSheet);
|
| 4600 |
varun.gupt |
741 |
populateMismatchSheet(mismatchSheet);
|
|
|
742 |
|
|
|
743 |
// Write the workbook to the output stream
|
|
|
744 |
try {
|
|
|
745 |
wb.write(baosXLS);
|
|
|
746 |
baosXLS.close();
|
|
|
747 |
} catch (IOException e) {
|
|
|
748 |
logger.error("Unable to write the hotspot reconciliation report to the byte array", e);
|
|
|
749 |
}
|
|
|
750 |
return baosXLS;
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
private void populateMismatchSheet(Sheet sheet) {
|
|
|
754 |
int serialNo = 0;
|
|
|
755 |
Row titleRow = sheet.createRow(serialNo ++);
|
|
|
756 |
Cell titleCell = titleRow.createCell(0);
|
|
|
757 |
titleCell.setCellValue("Order Reconciliation Report (Mis-matches)");
|
|
|
758 |
|
|
|
759 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
|
|
|
760 |
sheet.createRow(serialNo ++);
|
|
|
761 |
|
|
|
762 |
Row headerRow = sheet.createRow(serialNo ++);
|
|
|
763 |
headerRow.createCell(OrderMismatchColumn.ORDER_ID.getValue()).setCellValue("Order Id");
|
|
|
764 |
headerRow.createCell(OrderMismatchColumn.EXPECTED_COLLECTION.getValue()).setCellValue("Expected Collection");
|
|
|
765 |
headerRow.createCell(OrderMismatchColumn.ACTUAL_COLLECTION.getValue()).setCellValue("Actual Collection");
|
|
|
766 |
|
|
|
767 |
for (long orderId: misMatches.keySet()) {
|
|
|
768 |
Row contentRow = sheet.createRow(serialNo ++);
|
|
|
769 |
contentRow.createCell(OrderMismatchColumn.ORDER_ID.getValue()).setCellValue(orderId);
|
|
|
770 |
contentRow.createCell(OrderMismatchColumn.EXPECTED_COLLECTION.getValue()).setCellValue(misMatches.get(orderId).get("expected"));
|
|
|
771 |
contentRow.createCell(OrderMismatchColumn.ACTUAL_COLLECTION.getValue()).setCellValue(misMatches.get(orderId).get("actual"));
|
|
|
772 |
}
|
|
|
773 |
}
|
|
|
774 |
|
| 4875 |
varun.gupt |
775 |
private void populateReshippedOrderSheet(List<Order> orders, Sheet sheet) {
|
|
|
776 |
short serialNo = 0;
|
|
|
777 |
|
|
|
778 |
// Create the title row and put all the titles in it. Rows are 0 based.
|
|
|
779 |
Row titleRow = sheet.createRow(serialNo ++);
|
|
|
780 |
Cell titleCell = titleRow.createCell(0);
|
|
|
781 |
titleCell.setCellValue("Reshipped Orders");
|
|
|
782 |
|
|
|
783 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
|
|
784 |
|
|
|
785 |
sheet.createRow(serialNo ++);
|
|
|
786 |
|
|
|
787 |
Row headerRow = sheet.createRow(serialNo ++);
|
|
|
788 |
headerRow.createCell(OrderReportColumn.ORDER_ID.getValue()).setCellValue("Order Id");
|
|
|
789 |
headerRow.createCell(OrderReportColumn.ORDER_DATE.getValue()).setCellValue("Order Date");
|
|
|
790 |
headerRow.createCell(OrderReportColumn.BILLING_NUMBER.getValue()).setCellValue("Billing Number");
|
|
|
791 |
headerRow.createCell(OrderReportColumn.BILLING_DATE.getValue()).setCellValue("Billing Date");
|
|
|
792 |
headerRow.createCell(OrderReportColumn.DELIVERY_DATE.getValue()).setCellValue("Delivery Date");
|
|
|
793 |
headerRow.createCell(OrderReportColumn.SETTLEMENT_DATE.getValue()).setCellValue("Settlement Date");
|
|
|
794 |
headerRow.createCell(OrderReportColumn.BRAND.getValue()).setCellValue("Brand");
|
|
|
795 |
headerRow.createCell(OrderReportColumn.MODEL_NAME.getValue()).setCellValue("Model Name");
|
|
|
796 |
headerRow.createCell(OrderReportColumn.MODEL_NUMBER.getValue()).setCellValue("Model Number");
|
|
|
797 |
headerRow.createCell(OrderReportColumn.COLOR.getValue()).setCellValue("Color");
|
|
|
798 |
headerRow.createCell(OrderReportColumn.QUANTITY.getValue()).setCellValue("Quantity");
|
|
|
799 |
headerRow.createCell(OrderReportColumn.UNIT_TRANSFER_PRICE.getValue()).setCellValue("Unit Transfer Price");
|
|
|
800 |
headerRow.createCell(OrderReportColumn.UNIT_SELLING_PRICE.getValue()).setCellValue("Unit Selling Price");
|
|
|
801 |
headerRow.createCell(OrderReportColumn.TOTAL_TRANSFER_PRICE.getValue()).setCellValue("Total Transfer Price");
|
|
|
802 |
headerRow.createCell(OrderReportColumn.TOTAL_SELLING_PRICE.getValue()).setCellValue("Total Selling Price");
|
|
|
803 |
headerRow.createCell(OrderReportColumn.CURRENT_STATUS.getValue()).setCellValue("Current Status");
|
|
|
804 |
headerRow.createCell(OrderReportColumn.GATEWAY_TRANSACTION_ID.getValue()).setCellValue("Gateway Transaction Id");
|
|
|
805 |
headerRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue("Payment Type");
|
|
|
806 |
headerRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue("Payment Status");
|
|
|
807 |
headerRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue("Payment Id");
|
|
|
808 |
headerRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue("Coupon Code");
|
|
|
809 |
// headerRow.createCell(OrderReportColumn.COUPON_CATEGORY.getValue()).setCellValue("Coupon Category");
|
|
|
810 |
// headerRow.createCell(OrderReportColumn.DISCOUNT.getValue()).setCellValue("Discount");
|
|
|
811 |
headerRow.createCell(OrderReportColumn.SERVICE_TAX.getValue()).setCellValue("Service Tax");
|
|
|
812 |
headerRow.createCell(OrderReportColumn.OTHER_CHARGES.getValue()).setCellValue("Other Charges");
|
|
|
813 |
headerRow.createCell(OrderReportColumn.NET_COLLECTION.getValue()).setCellValue("Net Collection");
|
|
|
814 |
|
|
|
815 |
sheet.createRow(serialNo ++);
|
|
|
816 |
|
|
|
817 |
TransactionClient tsc;
|
|
|
818 |
PaymentClient psc;
|
|
|
819 |
LogisticsClient lsc;
|
|
|
820 |
|
|
|
821 |
try {
|
|
|
822 |
tsc = new TransactionClient();
|
|
|
823 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
824 |
|
|
|
825 |
psc = new PaymentClient();
|
|
|
826 |
in.shop2020.payments.PaymentService.Client paymentClient = psc.getClient();
|
|
|
827 |
|
|
|
828 |
lsc = new LogisticsClient();
|
|
|
829 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
|
|
830 |
|
|
|
831 |
Map<Long, String> codProviders = new HashMap<Long, String>();
|
|
|
832 |
|
|
|
833 |
for (Provider provider: logisticsClient.getAllProviders()) {
|
|
|
834 |
codProviders.put(provider.getId(), provider.getName());
|
|
|
835 |
}
|
|
|
836 |
|
|
|
837 |
List<PaymentGateway> tPaymentGateways = paymentClient.getActivePaymentGateways();
|
|
|
838 |
Map<Long, String> paymentGateways = new HashMap<Long, String>();
|
|
|
839 |
|
|
|
840 |
for (PaymentGateway tPaymentGateway: tPaymentGateways) {
|
|
|
841 |
paymentGateways.put(tPaymentGateway.getId(), tPaymentGateway.getName());
|
|
|
842 |
}
|
|
|
843 |
|
|
|
844 |
int countMultipleOrderTxns = 0;
|
|
|
845 |
|
|
|
846 |
for (Order order: orders) {
|
|
|
847 |
logger.info("For order: " + order.getId());
|
|
|
848 |
|
|
|
849 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
850 |
double transferPrice = lineItem.getTransfer_price();
|
|
|
851 |
Payment payment = null;
|
|
|
852 |
|
|
|
853 |
try {
|
|
|
854 |
if(order.isCod()) {
|
|
|
855 |
payment = paymentClient.getPaymentForTxnId(order.getTransactionId()).get(0);
|
|
|
856 |
} else {
|
|
|
857 |
payment = paymentClient.getSuccessfulPaymentForTxnId(order.getTransactionId());
|
|
|
858 |
}
|
|
|
859 |
logger.info("getSuccessfulPaymentForTxnId, " + order.getTransactionId() + ": " + payment);
|
|
|
860 |
|
|
|
861 |
} catch (TApplicationException e) {
|
|
|
862 |
orderIdsWithoutSuccess.add(order.getId());
|
|
|
863 |
String errMsg = "Exception while getting successfull payment for transaction Id, " + order.getTransactionId();
|
|
|
864 |
logger.error(errMsg, e);
|
|
|
865 |
addActionError(errMsg);
|
|
|
866 |
}
|
|
|
867 |
|
|
|
868 |
Transaction txn = transactionClient.getTransaction(order.getTransactionId());
|
|
|
869 |
PaymentSettlement paymentSettlement = null;
|
|
|
870 |
String paymentType = null;
|
|
|
871 |
|
|
|
872 |
if(payment != null) {
|
|
|
873 |
paymentSettlement = transactionClient.getSettlementForPaymentId(payment.getPaymentId());
|
|
|
874 |
paymentType = paymentGateways.get(payment.getGatewayId());
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
double totalSellingPrice = lineItem.getTotal_price();
|
|
|
878 |
double serviceTax = 0.0;
|
|
|
879 |
double otherCollectionCharges = 0.0;
|
|
|
880 |
double netCollection = 0.0;
|
|
|
881 |
|
|
|
882 |
if(paymentSettlement != null) {
|
|
|
883 |
serviceTax = paymentSettlement.getServiceTax();
|
|
|
884 |
otherCollectionCharges = paymentSettlement.getOtherCharges();
|
|
|
885 |
netCollection = paymentSettlement.getNetCollection();
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
if (netCollection < 0.0) {
|
|
|
889 |
paymentType = paymentType + "-REFUND";
|
|
|
890 |
}
|
|
|
891 |
|
|
|
892 |
Row contentRow = sheet.createRow(serialNo++);
|
|
|
893 |
contentRow.createCell(OrderReportColumn.ORDER_ID.getValue()).setCellValue(order.getId());
|
|
|
894 |
contentRow.createCell(OrderReportColumn.ORDER_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getCreated_timestamp())));
|
|
|
895 |
contentRow.createCell(OrderReportColumn.BILLING_NUMBER.getValue()).setCellValue(order.getInvoice_number());
|
|
|
896 |
contentRow.createCell(OrderReportColumn.BILLING_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getBilling_timestamp())));
|
|
|
897 |
contentRow.createCell(OrderReportColumn.DELIVERY_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getDelivery_timestamp())));
|
|
|
898 |
contentRow.createCell(OrderReportColumn.BRAND.getValue()).setCellValue(getValueForEmptyString(lineItem.getBrand()));
|
|
|
899 |
contentRow.createCell(OrderReportColumn.MODEL_NAME.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
|
|
|
900 |
contentRow.createCell(OrderReportColumn.MODEL_NUMBER.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
|
|
|
901 |
contentRow.createCell(OrderReportColumn.COLOR.getValue()).setCellValue(getValueForEmptyString(lineItem.getColor()));
|
|
|
902 |
contentRow.createCell(OrderReportColumn.QUANTITY.getValue()).setCellValue(lineItem.getQuantity());
|
|
|
903 |
contentRow.createCell(OrderReportColumn.UNIT_TRANSFER_PRICE.getValue()).setCellValue(transferPrice);
|
|
|
904 |
contentRow.createCell(OrderReportColumn.UNIT_SELLING_PRICE.getValue()).setCellValue(lineItem.getUnit_price());
|
|
|
905 |
contentRow.createCell(OrderReportColumn.TOTAL_TRANSFER_PRICE.getValue()).setCellValue(transferPrice * lineItem.getQuantity());
|
|
|
906 |
contentRow.createCell(OrderReportColumn.TOTAL_SELLING_PRICE.getValue()).setCellValue(totalSellingPrice);
|
|
|
907 |
contentRow.createCell(OrderReportColumn.CURRENT_STATUS.getValue()).setCellValue(order.getStatusDescription());
|
|
|
908 |
|
|
|
909 |
double refund = 0.0;
|
|
|
910 |
|
|
|
911 |
if(order.isCod()) {
|
|
|
912 |
contentRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue("COD - " + codProviders.get(order.getLogistics_provider_id()));
|
|
|
913 |
} else {
|
|
|
914 |
contentRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue(paymentType);
|
|
|
915 |
}
|
|
|
916 |
|
|
|
917 |
if (payment != null) {
|
|
|
918 |
contentRow.createCell(OrderReportColumn.SETTLEMENT_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(paymentSettlement.getSettlementDate())));
|
|
|
919 |
contentRow.createCell(OrderReportColumn.GATEWAY_TRANSACTION_ID.getValue()).setCellValue(payment.getGatewayTxnId());
|
|
|
920 |
contentRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue(payment.getStatus().name());
|
|
|
921 |
contentRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue(payment.getPaymentId());
|
|
|
922 |
}
|
|
|
923 |
contentRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue(txn.getCoupon_code());
|
|
|
924 |
contentRow.createCell(OrderReportColumn.SERVICE_TAX.getValue()).setCellValue(serviceTax);
|
|
|
925 |
contentRow.createCell(OrderReportColumn.OTHER_CHARGES.getValue()).setCellValue(otherCollectionCharges);
|
|
|
926 |
contentRow.createCell(OrderReportColumn.NET_COLLECTION.getValue()).setCellValue(netCollection);
|
|
|
927 |
}
|
|
|
928 |
|
|
|
929 |
logger.info("Order Ids where no successful payment was found: " + orderIdsWithoutSuccess.size());
|
|
|
930 |
logger.info(orderIdsWithoutSuccess.toString());
|
|
|
931 |
|
|
|
932 |
sheet.createRow(serialNo++);
|
|
|
933 |
|
|
|
934 |
} catch (TTransportException e) {
|
|
|
935 |
logger.error("TTransportException " + e);
|
|
|
936 |
} catch (PaymentException e) {
|
|
|
937 |
logger.error("PaymentException " + e);
|
|
|
938 |
} catch (TException e) {
|
|
|
939 |
logger.error("TException " + e);
|
|
|
940 |
} catch (TransactionServiceException e) {
|
|
|
941 |
logger.error("Transaction Service Exception " + e);
|
|
|
942 |
} catch (LogisticsServiceException e) {
|
|
|
943 |
addActionError("Error loading list of COD providers");
|
|
|
944 |
logger.error("Logistics Service Exception " + e);
|
|
|
945 |
}
|
|
|
946 |
}
|
|
|
947 |
|
| 4600 |
varun.gupt |
948 |
private void populateOrderSheet(List<Order> orders, Date startDate, Date endDate, Sheet sheet, CellStyle style, CellStyle rightAlignStyle) {
|
|
|
949 |
short serialNo = 0;
|
|
|
950 |
|
|
|
951 |
// Create the title row and put all the titles in it. Rows are 0 based.
|
|
|
952 |
Row titleRow = sheet.createRow(serialNo ++);
|
|
|
953 |
Cell titleCell = titleRow.createCell(0);
|
|
|
954 |
titleCell.setCellValue("Order Reconciliation Report (" + DATE_FORMAT.format(startDate) + " - " + DATE_FORMAT.format(endDate) + ")");
|
|
|
955 |
titleCell.setCellStyle(style);
|
|
|
956 |
|
|
|
957 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
|
|
958 |
|
|
|
959 |
sheet.createRow(serialNo ++);
|
|
|
960 |
|
|
|
961 |
Row headerRow = sheet.createRow(serialNo ++);
|
|
|
962 |
headerRow.createCell(OrderReportColumn.ORDER_ID.getValue()).setCellValue("Order Id");
|
|
|
963 |
headerRow.createCell(OrderReportColumn.ORDER_DATE.getValue()).setCellValue("Order Date");
|
|
|
964 |
headerRow.createCell(OrderReportColumn.BILLING_NUMBER.getValue()).setCellValue("Billing Number");
|
|
|
965 |
headerRow.createCell(OrderReportColumn.BILLING_DATE.getValue()).setCellValue("Billing Date");
|
|
|
966 |
headerRow.createCell(OrderReportColumn.DELIVERY_DATE.getValue()).setCellValue("Delivery Date");
|
|
|
967 |
headerRow.createCell(OrderReportColumn.SETTLEMENT_DATE.getValue()).setCellValue("Settlement Date");
|
|
|
968 |
headerRow.createCell(OrderReportColumn.BRAND.getValue()).setCellValue("Brand");
|
|
|
969 |
headerRow.createCell(OrderReportColumn.MODEL_NAME.getValue()).setCellValue("Model Name");
|
|
|
970 |
headerRow.createCell(OrderReportColumn.MODEL_NUMBER.getValue()).setCellValue("Model Number");
|
|
|
971 |
headerRow.createCell(OrderReportColumn.COLOR.getValue()).setCellValue("Color");
|
|
|
972 |
headerRow.createCell(OrderReportColumn.QUANTITY.getValue()).setCellValue("Quantity");
|
|
|
973 |
headerRow.createCell(OrderReportColumn.UNIT_TRANSFER_PRICE.getValue()).setCellValue("Unit Transfer Price");
|
|
|
974 |
headerRow.createCell(OrderReportColumn.UNIT_SELLING_PRICE.getValue()).setCellValue("Unit Selling Price");
|
|
|
975 |
headerRow.createCell(OrderReportColumn.TOTAL_TRANSFER_PRICE.getValue()).setCellValue("Total Transfer Price");
|
|
|
976 |
headerRow.createCell(OrderReportColumn.TOTAL_SELLING_PRICE.getValue()).setCellValue("Total Selling Price");
|
|
|
977 |
headerRow.createCell(OrderReportColumn.CURRENT_STATUS.getValue()).setCellValue("Current Status");
|
|
|
978 |
headerRow.createCell(OrderReportColumn.GATEWAY_TRANSACTION_ID.getValue()).setCellValue("Gateway Transaction Id");
|
|
|
979 |
headerRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue("Payment Type");
|
| 4745 |
varun.gupt |
980 |
headerRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue("Payment Status");
|
| 4600 |
varun.gupt |
981 |
headerRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue("Payment Id");
|
|
|
982 |
headerRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue("Coupon Code");
|
|
|
983 |
// headerRow.createCell(OrderReportColumn.COUPON_CATEGORY.getValue()).setCellValue("Coupon Category");
|
|
|
984 |
// headerRow.createCell(OrderReportColumn.DISCOUNT.getValue()).setCellValue("Discount");
|
|
|
985 |
headerRow.createCell(OrderReportColumn.SERVICE_TAX.getValue()).setCellValue("Service Tax");
|
|
|
986 |
headerRow.createCell(OrderReportColumn.OTHER_CHARGES.getValue()).setCellValue("Other Charges");
|
|
|
987 |
headerRow.createCell(OrderReportColumn.NET_COLLECTION.getValue()).setCellValue("Net Collection");
|
| 4715 |
varun.gupt |
988 |
headerRow.createCell(OrderReportColumn.REFUND.getValue()).setCellValue("Refund");
|
|
|
989 |
headerRow.createCell(OrderReportColumn.FINAL_AMOUNT.getValue()).setCellValue("Final Amount");
|
| 4600 |
varun.gupt |
990 |
|
|
|
991 |
sheet.createRow(serialNo ++);
|
|
|
992 |
|
|
|
993 |
TransactionClient tsc;
|
|
|
994 |
PaymentClient psc;
|
| 4734 |
varun.gupt |
995 |
LogisticsClient lsc;
|
| 4745 |
varun.gupt |
996 |
|
| 4600 |
varun.gupt |
997 |
try {
|
|
|
998 |
tsc = new TransactionClient();
|
|
|
999 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
|
|
|
1000 |
|
|
|
1001 |
psc = new PaymentClient();
|
|
|
1002 |
in.shop2020.payments.PaymentService.Client paymentClient = psc.getClient();
|
|
|
1003 |
|
| 4734 |
varun.gupt |
1004 |
lsc = new LogisticsClient();
|
|
|
1005 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
|
|
1006 |
|
|
|
1007 |
Map<Long, String> codProviders = new HashMap<Long, String>();
|
|
|
1008 |
|
|
|
1009 |
for (Provider provider: logisticsClient.getAllProviders()) {
|
|
|
1010 |
codProviders.put(provider.getId(), provider.getName());
|
|
|
1011 |
}
|
|
|
1012 |
|
| 4600 |
varun.gupt |
1013 |
List<PaymentGateway> tPaymentGateways = paymentClient.getActivePaymentGateways();
|
|
|
1014 |
Map<Long, String> paymentGateways = new HashMap<Long, String>();
|
|
|
1015 |
|
|
|
1016 |
for (PaymentGateway tPaymentGateway: tPaymentGateways) {
|
|
|
1017 |
paymentGateways.put(tPaymentGateway.getId(), tPaymentGateway.getName());
|
|
|
1018 |
}
|
|
|
1019 |
|
| 4715 |
varun.gupt |
1020 |
List <Long> orderIds = new ArrayList<Long>();
|
| 4734 |
varun.gupt |
1021 |
Map<Long, List<Order>> orderMap = new HashMap<Long, List<Order>>();
|
| 4745 |
varun.gupt |
1022 |
|
|
|
1023 |
int countMultipleOrderTxns = 0;
|
| 4715 |
varun.gupt |
1024 |
|
| 4600 |
varun.gupt |
1025 |
for(Order order : orders) {
|
| 4875 |
varun.gupt |
1026 |
if(order.getBilling_timestamp() == 0) {
|
|
|
1027 |
continue;
|
|
|
1028 |
}
|
| 4715 |
varun.gupt |
1029 |
orderIds.add(order.getId());
|
| 4734 |
varun.gupt |
1030 |
|
|
|
1031 |
if (orderMap.containsKey(order.getTransactionId())) {
|
|
|
1032 |
orderMap.get(order.getTransactionId()).add(order);
|
| 4745 |
varun.gupt |
1033 |
countMultipleOrderTxns += 1;
|
| 4734 |
varun.gupt |
1034 |
|
|
|
1035 |
} else {
|
|
|
1036 |
List<Order> o = new ArrayList<Order>();
|
|
|
1037 |
o.add(order);
|
|
|
1038 |
orderMap.put(order.getTransactionId(), o);
|
|
|
1039 |
}
|
| 4715 |
varun.gupt |
1040 |
}
|
|
|
1041 |
|
| 4745 |
varun.gupt |
1042 |
// Getting list of order ids belonging to reshipped orders
|
|
|
1043 |
List<Long> reshippedOrderIds = transactionClient.getReshippedOrderIds(orderIds);
|
| 4715 |
varun.gupt |
1044 |
|
| 4734 |
varun.gupt |
1045 |
for(long txnId: orderMap.keySet()) {
|
|
|
1046 |
List<Order> orderList = orderMap.get(txnId);
|
|
|
1047 |
|
|
|
1048 |
for (Order order: orderList) {
|
|
|
1049 |
logger.info("For order: " + order.getId());
|
| 4875 |
varun.gupt |
1050 |
|
|
|
1051 |
// Orders where payment was captured but never billed
|
|
|
1052 |
if(order.getBilling_timestamp() == 0) {
|
|
|
1053 |
continue;
|
|
|
1054 |
}
|
|
|
1055 |
|
|
|
1056 |
if (reshippedOrderIds.contains(order.getId())) {
|
| 4745 |
varun.gupt |
1057 |
reshippedOrders.add(order);
|
|
|
1058 |
continue;
|
|
|
1059 |
}
|
| 4734 |
varun.gupt |
1060 |
|
|
|
1061 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
1062 |
double transferPrice = lineItem.getTransfer_price();
|
|
|
1063 |
Payment payment = null;
|
| 4715 |
varun.gupt |
1064 |
|
| 4734 |
varun.gupt |
1065 |
try {
|
| 4745 |
varun.gupt |
1066 |
if(order.isCod()) {
|
|
|
1067 |
payment = paymentClient.getPaymentForTxnId(order.getTransactionId()).get(0);
|
|
|
1068 |
} else {
|
|
|
1069 |
payment = paymentClient.getSuccessfulPaymentForTxnId(order.getTransactionId());
|
|
|
1070 |
}
|
|
|
1071 |
logger.info("getSuccessfulPaymentForTxnId, " + order.getTransactionId() + ": " + payment);
|
| 4734 |
varun.gupt |
1072 |
|
|
|
1073 |
} catch (TApplicationException e) {
|
|
|
1074 |
orderIdsWithoutSuccess.add(order.getId());
|
| 4745 |
varun.gupt |
1075 |
String errMsg = "Exception while getting successfull payment for transaction Id, " + order.getTransactionId();
|
|
|
1076 |
logger.error(errMsg, e);
|
|
|
1077 |
addActionError(errMsg);
|
| 4734 |
varun.gupt |
1078 |
}
|
|
|
1079 |
|
|
|
1080 |
Transaction txn = transactionClient.getTransaction(order.getTransactionId());
|
|
|
1081 |
PaymentSettlement paymentSettlement = null;
|
|
|
1082 |
String paymentType = null;
|
|
|
1083 |
|
|
|
1084 |
if(payment != null) {
|
|
|
1085 |
paymentSettlement = transactionClient.getSettlementForPaymentId(payment.getPaymentId());
|
|
|
1086 |
paymentType = paymentGateways.get(payment.getGatewayId());
|
|
|
1087 |
}
|
|
|
1088 |
|
|
|
1089 |
double totalSellingPrice = lineItem.getTotal_price();
|
|
|
1090 |
double serviceTax = 0.0;
|
|
|
1091 |
double otherCollectionCharges = 0.0;
|
|
|
1092 |
double netCollection = 0.0;
|
|
|
1093 |
|
|
|
1094 |
if(paymentSettlement != null) {
|
|
|
1095 |
serviceTax = paymentSettlement.getServiceTax();
|
|
|
1096 |
otherCollectionCharges = paymentSettlement.getOtherCharges();
|
|
|
1097 |
netCollection = paymentSettlement.getNetCollection();
|
|
|
1098 |
}
|
|
|
1099 |
|
|
|
1100 |
if (netCollection < 0.0) {
|
|
|
1101 |
paymentType = paymentType + "-REFUND";
|
|
|
1102 |
}
|
|
|
1103 |
double expectedCollection = totalSellingPrice - otherCollectionCharges - serviceTax;
|
|
|
1104 |
|
|
|
1105 |
//FIXME ignore differences of upto 50 paisa
|
|
|
1106 |
if (netCollection > 0.0 && expectedCollection != netCollection) {
|
|
|
1107 |
Map <String, Double> mismatch = new HashMap<String, Double>();
|
|
|
1108 |
mismatch.put("expected", expectedCollection);
|
|
|
1109 |
mismatch.put("actual", netCollection);
|
|
|
1110 |
misMatches.put(order.getId(), mismatch);
|
|
|
1111 |
}
|
| 4600 |
varun.gupt |
1112 |
|
| 4734 |
varun.gupt |
1113 |
Row contentRow = sheet.createRow(serialNo++);
|
|
|
1114 |
contentRow.createCell(OrderReportColumn.ORDER_ID.getValue()).setCellValue(order.getId());
|
|
|
1115 |
contentRow.createCell(OrderReportColumn.ORDER_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getCreated_timestamp())));
|
|
|
1116 |
contentRow.createCell(OrderReportColumn.BILLING_NUMBER.getValue()).setCellValue(order.getInvoice_number());
|
|
|
1117 |
contentRow.createCell(OrderReportColumn.BILLING_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getBilling_timestamp())));
|
|
|
1118 |
contentRow.createCell(OrderReportColumn.DELIVERY_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getDelivery_timestamp())));
|
|
|
1119 |
contentRow.createCell(OrderReportColumn.BRAND.getValue()).setCellValue(getValueForEmptyString(lineItem.getBrand()));
|
|
|
1120 |
contentRow.createCell(OrderReportColumn.MODEL_NAME.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
|
|
|
1121 |
contentRow.createCell(OrderReportColumn.MODEL_NUMBER.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
|
|
|
1122 |
contentRow.createCell(OrderReportColumn.COLOR.getValue()).setCellValue(getValueForEmptyString(lineItem.getColor()));
|
|
|
1123 |
contentRow.createCell(OrderReportColumn.QUANTITY.getValue()).setCellValue(lineItem.getQuantity());
|
|
|
1124 |
contentRow.createCell(OrderReportColumn.UNIT_TRANSFER_PRICE.getValue()).setCellValue(transferPrice);
|
|
|
1125 |
contentRow.createCell(OrderReportColumn.UNIT_SELLING_PRICE.getValue()).setCellValue(lineItem.getUnit_price());
|
|
|
1126 |
contentRow.createCell(OrderReportColumn.TOTAL_TRANSFER_PRICE.getValue()).setCellValue(transferPrice * lineItem.getQuantity());
|
|
|
1127 |
contentRow.createCell(OrderReportColumn.TOTAL_SELLING_PRICE.getValue()).setCellValue(totalSellingPrice);
|
|
|
1128 |
contentRow.createCell(OrderReportColumn.CURRENT_STATUS.getValue()).setCellValue(order.getStatusDescription());
|
| 4715 |
varun.gupt |
1129 |
|
| 4734 |
varun.gupt |
1130 |
double refund = 0.0;
|
| 4715 |
varun.gupt |
1131 |
|
| 4745 |
varun.gupt |
1132 |
if(order.isCod()) {
|
|
|
1133 |
contentRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue("COD - " + codProviders.get(order.getLogistics_provider_id()));
|
|
|
1134 |
} else {
|
|
|
1135 |
contentRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue(paymentType);
|
|
|
1136 |
}
|
|
|
1137 |
|
| 4734 |
varun.gupt |
1138 |
if (payment != null) {
|
|
|
1139 |
contentRow.createCell(OrderReportColumn.SETTLEMENT_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(paymentSettlement.getSettlementDate())));
|
|
|
1140 |
contentRow.createCell(OrderReportColumn.GATEWAY_TRANSACTION_ID.getValue()).setCellValue(payment.getGatewayTxnId());
|
| 4745 |
varun.gupt |
1141 |
contentRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue(payment.getStatus().name());
|
| 4734 |
varun.gupt |
1142 |
contentRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue(payment.getPaymentId());
|
|
|
1143 |
}
|
|
|
1144 |
contentRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue(txn.getCoupon_code());
|
|
|
1145 |
contentRow.createCell(OrderReportColumn.SERVICE_TAX.getValue()).setCellValue(serviceTax);
|
|
|
1146 |
contentRow.createCell(OrderReportColumn.OTHER_CHARGES.getValue()).setCellValue(otherCollectionCharges);
|
|
|
1147 |
contentRow.createCell(OrderReportColumn.NET_COLLECTION.getValue()).setCellValue(netCollection);
|
|
|
1148 |
contentRow.createCell(OrderReportColumn.FINAL_AMOUNT.getValue()).setCellValue(netCollection - refund);
|
|
|
1149 |
}
|
|
|
1150 |
}
|
|
|
1151 |
|
| 4745 |
varun.gupt |
1152 |
logger.info("Reshipped Orders ", reshippedOrders);
|
|
|
1153 |
|
| 4715 |
varun.gupt |
1154 |
logger.info("Order Ids where no successful payment was found: " + orderIdsWithoutSuccess.size());
|
|
|
1155 |
logger.info(orderIdsWithoutSuccess.toString());
|
| 4875 |
varun.gupt |
1156 |
logger.info("Reshipped Order Ids: " + reshippedOrderIds);
|
| 4745 |
varun.gupt |
1157 |
logger.info("countMultipleOrderTxns: " + countMultipleOrderTxns);
|
| 4715 |
varun.gupt |
1158 |
|
|
|
1159 |
sheet.createRow(serialNo++);
|
| 4875 |
varun.gupt |
1160 |
|
|
|
1161 |
List<PaymentSettlement> refundSettlements = transactionClient.getSettlementsByDate(startDate.getTime(), endDate.getTime(), true);
|
|
|
1162 |
logger.info("Refunds: " + refundSettlements.size());
|
|
|
1163 |
logger.info(refundSettlements.toString());
|
|
|
1164 |
|
|
|
1165 |
Map<Long, PaymentSettlement> refunds = new HashMap<Long, PaymentSettlement>();
|
|
|
1166 |
|
|
|
1167 |
for (PaymentSettlement settlement: refundSettlements) {
|
|
|
1168 |
refunds.put(settlement.getPaymentId(), settlement);
|
|
|
1169 |
}
|
|
|
1170 |
|
| 4715 |
varun.gupt |
1171 |
// Refunds belonging to orders billed before the start date of supplied billing date range
|
|
|
1172 |
for (long paymentId: refunds.keySet()) {
|
|
|
1173 |
Payment payment = paymentClient.getPayment(paymentId);
|
|
|
1174 |
Transaction txn = transactionClient.getTransaction(payment.getMerchantTxnId());
|
|
|
1175 |
PaymentSettlement paymentSettlement = refunds.get(paymentId);
|
|
|
1176 |
|
|
|
1177 |
for (Order order: txn.getOrders()) {
|
| 4734 |
varun.gupt |
1178 |
if(!refundOrderStatuses.contains(order.getStatus())) continue;
|
|
|
1179 |
|
| 4715 |
varun.gupt |
1180 |
Row contentRow = sheet.createRow(serialNo++);
|
|
|
1181 |
|
|
|
1182 |
LineItem lineItem = order.getLineitems().get(0);
|
|
|
1183 |
double transferPrice = lineItem.getTransfer_price();
|
|
|
1184 |
double totalSellingPrice = lineItem.getTotal_price();
|
|
|
1185 |
String paymentType = paymentGateways.get(payment.getGatewayId()) + "-REFUND";
|
|
|
1186 |
|
|
|
1187 |
contentRow.createCell(OrderReportColumn.ORDER_ID.getValue()).setCellValue(order.getId());
|
|
|
1188 |
contentRow.createCell(OrderReportColumn.ORDER_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getCreated_timestamp())));
|
|
|
1189 |
contentRow.createCell(OrderReportColumn.BILLING_NUMBER.getValue()).setCellValue(order.getInvoice_number());
|
|
|
1190 |
contentRow.createCell(OrderReportColumn.BILLING_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getBilling_timestamp())));
|
|
|
1191 |
contentRow.createCell(OrderReportColumn.DELIVERY_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(order.getDelivery_timestamp())));
|
|
|
1192 |
contentRow.createCell(OrderReportColumn.BRAND.getValue()).setCellValue(getValueForEmptyString(lineItem.getBrand()));
|
|
|
1193 |
contentRow.createCell(OrderReportColumn.MODEL_NAME.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
|
|
|
1194 |
contentRow.createCell(OrderReportColumn.MODEL_NUMBER.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
|
|
|
1195 |
contentRow.createCell(OrderReportColumn.COLOR.getValue()).setCellValue(getValueForEmptyString(lineItem.getColor()));
|
|
|
1196 |
contentRow.createCell(OrderReportColumn.QUANTITY.getValue()).setCellValue(lineItem.getQuantity());
|
|
|
1197 |
contentRow.createCell(OrderReportColumn.UNIT_TRANSFER_PRICE.getValue()).setCellValue(transferPrice);
|
|
|
1198 |
contentRow.createCell(OrderReportColumn.UNIT_SELLING_PRICE.getValue()).setCellValue(lineItem.getUnit_price());
|
|
|
1199 |
contentRow.createCell(OrderReportColumn.TOTAL_TRANSFER_PRICE.getValue()).setCellValue(transferPrice * lineItem.getQuantity());
|
|
|
1200 |
contentRow.createCell(OrderReportColumn.TOTAL_SELLING_PRICE.getValue()).setCellValue(totalSellingPrice);
|
|
|
1201 |
contentRow.createCell(OrderReportColumn.CURRENT_STATUS.getValue()).setCellValue(order.getStatusDescription());
|
| 4875 |
varun.gupt |
1202 |
|
| 4715 |
varun.gupt |
1203 |
contentRow.createCell(OrderReportColumn.SETTLEMENT_DATE.getValue()).setCellValue(DATE_FORMAT.format(new Date(paymentSettlement.getSettlementDate())));
|
|
|
1204 |
contentRow.createCell(OrderReportColumn.GATEWAY_TRANSACTION_ID.getValue()).setCellValue(payment.getGatewayTxnId());
|
|
|
1205 |
contentRow.createCell(OrderReportColumn.PAYMENT_TYPE.getValue()).setCellValue(paymentType);
|
|
|
1206 |
contentRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue(payment.getPaymentId());
|
|
|
1207 |
|
|
|
1208 |
contentRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue(txn.getCoupon_code());
|
|
|
1209 |
contentRow.createCell(OrderReportColumn.SERVICE_TAX.getValue()).setCellValue(0.0);
|
|
|
1210 |
contentRow.createCell(OrderReportColumn.OTHER_CHARGES.getValue()).setCellValue(0.0);
|
|
|
1211 |
contentRow.createCell(OrderReportColumn.NET_COLLECTION.getValue()).setCellValue(paymentSettlement.getNetCollection());
|
|
|
1212 |
}
|
|
|
1213 |
}
|
|
|
1214 |
|
| 4600 |
varun.gupt |
1215 |
} catch (TTransportException e) {
|
| 4715 |
varun.gupt |
1216 |
logger.error("TTransportException " + e);
|
| 4600 |
varun.gupt |
1217 |
} catch (PaymentException e) {
|
| 4715 |
varun.gupt |
1218 |
logger.error("PaymentException " + e);
|
| 4600 |
varun.gupt |
1219 |
} catch (TException e) {
|
| 4715 |
varun.gupt |
1220 |
logger.error("TException " + e);
|
| 4600 |
varun.gupt |
1221 |
} catch (TransactionServiceException e) {
|
| 4734 |
varun.gupt |
1222 |
logger.error("Transaction Service Exception " + e);
|
|
|
1223 |
} catch (LogisticsServiceException e) {
|
|
|
1224 |
addActionError("Error loading list of COD providers");
|
|
|
1225 |
logger.error("Logistics Service Exception " + e);
|
| 4600 |
varun.gupt |
1226 |
}
|
|
|
1227 |
}
|
|
|
1228 |
|
|
|
1229 |
public List<Vendor> getAllVendors() {
|
|
|
1230 |
return this.vendors;
|
|
|
1231 |
}
|
|
|
1232 |
|
|
|
1233 |
private String getValueForEmptyString(String s){
|
|
|
1234 |
if(s==null || s.equals(""))
|
|
|
1235 |
return "-";
|
|
|
1236 |
else
|
|
|
1237 |
return s;
|
|
|
1238 |
}
|
|
|
1239 |
|
|
|
1240 |
private String getVendorName(long vendorId) {
|
|
|
1241 |
for (Vendor vendor: vendors) {
|
|
|
1242 |
if (vendor.getId() == vendorId) return vendor.getName();
|
|
|
1243 |
}
|
|
|
1244 |
return null;
|
|
|
1245 |
}
|
|
|
1246 |
|
|
|
1247 |
public String getReportSource() {
|
|
|
1248 |
return reportSource;
|
|
|
1249 |
}
|
|
|
1250 |
|
|
|
1251 |
public void setReportSource(String reportSource) {
|
|
|
1252 |
this.reportSource = reportSource;
|
|
|
1253 |
}
|
|
|
1254 |
|
|
|
1255 |
public File getHdfcSettlementReport() {
|
|
|
1256 |
return hdfcSettlementReport;
|
|
|
1257 |
}
|
|
|
1258 |
|
|
|
1259 |
public void setHdfcSettlementReport(File hdfcSettlementReport) {
|
|
|
1260 |
this.hdfcSettlementReport = hdfcSettlementReport;
|
|
|
1261 |
}
|
|
|
1262 |
|
|
|
1263 |
public File getEbsSettlementSummary() {
|
|
|
1264 |
return ebsSettlementSummary;
|
|
|
1265 |
}
|
|
|
1266 |
|
|
|
1267 |
public void setEbsSettlementSummary(File ebsSettlementSummary) {
|
|
|
1268 |
this.ebsSettlementSummary = ebsSettlementSummary;
|
|
|
1269 |
}
|
|
|
1270 |
|
|
|
1271 |
public File getEbsSettlementReport() {
|
|
|
1272 |
return ebsSettlementReport;
|
|
|
1273 |
}
|
|
|
1274 |
|
|
|
1275 |
public void setEbsSettlementReport(File ebsSettlementReport) {
|
|
|
1276 |
this.ebsSettlementReport = ebsSettlementReport;
|
|
|
1277 |
}
|
|
|
1278 |
|
|
|
1279 |
public String getBluedartSettlementDate() {
|
|
|
1280 |
return bluedartSettlementDate;
|
|
|
1281 |
}
|
|
|
1282 |
|
|
|
1283 |
public void setBluedartSettlementDate(String bluedartSettlementDate) {
|
|
|
1284 |
this.bluedartSettlementDate = bluedartSettlementDate;
|
|
|
1285 |
}
|
|
|
1286 |
|
|
|
1287 |
public File getBluedartSettlementReport() {
|
|
|
1288 |
return bluedartSettlementReport;
|
|
|
1289 |
}
|
|
|
1290 |
|
|
|
1291 |
public void setBluedartSettlementReport(File bluedartSettlementReport) {
|
|
|
1292 |
this.bluedartSettlementReport = bluedartSettlementReport;
|
|
|
1293 |
}
|
|
|
1294 |
|
| 4715 |
varun.gupt |
1295 |
public String getAramexSettlementDate() {
|
|
|
1296 |
return this.aramexSettlementDate;
|
|
|
1297 |
}
|
|
|
1298 |
|
|
|
1299 |
public void setAramexSettlementDate(String aramexSettlementDate) {
|
|
|
1300 |
this.aramexSettlementDate = aramexSettlementDate;
|
|
|
1301 |
}
|
|
|
1302 |
|
|
|
1303 |
public void setAramexSettlementReport(File aramexSettlementReport) {
|
|
|
1304 |
this.aramexSettlementReport = aramexSettlementReport;
|
|
|
1305 |
}
|
|
|
1306 |
|
|
|
1307 |
public File getAramexSettlementReport() {
|
|
|
1308 |
return aramexSettlementReport;
|
|
|
1309 |
}
|
|
|
1310 |
|
| 4600 |
varun.gupt |
1311 |
@Override
|
| 4715 |
varun.gupt |
1312 |
public void setServletContext(ServletContext context) {
|
| 4600 |
varun.gupt |
1313 |
this.context = context;
|
|
|
1314 |
}
|
|
|
1315 |
|
|
|
1316 |
public String getServletContextPath() {
|
|
|
1317 |
return context.getContextPath();
|
|
|
1318 |
}
|
|
|
1319 |
|
|
|
1320 |
@Override
|
|
|
1321 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
1322 |
this.response = response;
|
|
|
1323 |
}
|
|
|
1324 |
|
|
|
1325 |
@Override
|
|
|
1326 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
1327 |
this.request = request;
|
|
|
1328 |
this.session = request.getSession();
|
|
|
1329 |
}
|
|
|
1330 |
|
|
|
1331 |
public Map<Long, String> getEBSSettlementSummaries() {
|
|
|
1332 |
return ebsSettlementSummaries;
|
|
|
1333 |
}
|
|
|
1334 |
}
|