| 7343 |
anupam.sin |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import in.shop2020.model.v1.order.HotspotStore;
|
|
|
5 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
6 |
import in.shop2020.model.v1.order.Order;
|
|
|
7 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
8 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
9 |
import in.shop2020.model.v1.order.RechargeTransaction;
|
| 7427 |
anupam.sin |
10 |
import in.shop2020.model.v1.order.StoreOrderCollection;
|
| 7393 |
anupam.sin |
11 |
import in.shop2020.model.v1.order.StoreOrderDetail;
|
| 7343 |
anupam.sin |
12 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
13 |
import in.shop2020.thrift.clients.HelperClient;
|
|
|
14 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
15 |
import in.shop2020.utils.Mail;
|
|
|
16 |
|
|
|
17 |
import java.io.ByteArrayOutputStream;
|
|
|
18 |
import java.io.IOException;
|
|
|
19 |
import java.nio.ByteBuffer;
|
|
|
20 |
import java.text.DateFormat;
|
|
|
21 |
import java.text.SimpleDateFormat;
|
|
|
22 |
import java.util.ArrayList;
|
|
|
23 |
import java.util.Calendar;
|
|
|
24 |
import java.util.Date;
|
|
|
25 |
import java.util.List;
|
|
|
26 |
import java.util.Random;
|
|
|
27 |
|
|
|
28 |
import javax.servlet.ServletContext;
|
|
|
29 |
import javax.servlet.ServletOutputStream;
|
|
|
30 |
import javax.servlet.http.HttpServletRequest;
|
|
|
31 |
import javax.servlet.http.HttpServletResponse;
|
|
|
32 |
import javax.servlet.http.HttpSession;
|
|
|
33 |
|
|
|
34 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
35 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
36 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
37 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 7348 |
anupam.sin |
38 |
import org.apache.thrift.meta_data.SetMetaData;
|
| 7343 |
anupam.sin |
39 |
import org.slf4j.Logger;
|
|
|
40 |
import org.slf4j.LoggerFactory;
|
|
|
41 |
|
| 7386 |
anupam.sin |
42 |
public class ReportController extends BaseController {
|
| 7343 |
anupam.sin |
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
*/
|
|
|
47 |
private static final long serialVersionUID = 1L;
|
|
|
48 |
|
|
|
49 |
private static Logger logger = LoggerFactory.getLogger(ReportController.class);
|
|
|
50 |
|
|
|
51 |
protected HttpServletRequest request;
|
|
|
52 |
protected HttpSession session;
|
|
|
53 |
protected HttpServletResponse response;
|
|
|
54 |
private ServletContext context;
|
|
|
55 |
private String startDate;
|
|
|
56 |
private String endDate;
|
|
|
57 |
private String status;
|
|
|
58 |
private String dateselector;
|
|
|
59 |
private String searchError = "";
|
|
|
60 |
private Long number = null;
|
|
|
61 |
private String passwordGeneration = "";
|
|
|
62 |
|
|
|
63 |
private static final String chars = "0123456789";
|
|
|
64 |
private static final int LENGTH = 4;
|
|
|
65 |
private static final Random random = new Random();
|
|
|
66 |
private TransactionClient tsc;
|
|
|
67 |
private in.shop2020.model.v1.order.TransactionService.Client tClient;
|
|
|
68 |
|
|
|
69 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
|
|
70 |
private final DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
71 |
private final DateFormat df4Filename = new SimpleDateFormat("EEE_dd_MMM");
|
|
|
72 |
|
| 7348 |
anupam.sin |
73 |
private String returnType;
|
| 7343 |
anupam.sin |
74 |
private List<Order> orders = null;
|
|
|
75 |
private List<Order> searchResult = null;
|
| 7348 |
anupam.sin |
76 |
private Long orderId;
|
| 7343 |
anupam.sin |
77 |
|
| 7349 |
anupam.sin |
78 |
private Long refundAmount;
|
|
|
79 |
|
| 7343 |
anupam.sin |
80 |
private boolean showReprintColumn = false;
|
| 7611 |
anupam.sin |
81 |
|
|
|
82 |
private int reportType;
|
| 7343 |
anupam.sin |
83 |
|
|
|
84 |
public ReportController(){
|
| 7386 |
anupam.sin |
85 |
super();
|
| 7343 |
anupam.sin |
86 |
try {
|
|
|
87 |
tsc = new TransactionClient();
|
|
|
88 |
tClient = tsc.getClient();
|
|
|
89 |
} catch (Exception e) {
|
|
|
90 |
logger.error("Error connecting to one of the user, order or payment service", e);
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
public String index() {
|
| 7386 |
anupam.sin |
96 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
|
|
97 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
|
|
98 |
return "authfail";
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
|
| 7343 |
anupam.sin |
102 |
if(!hotspotStores.containsKey(storeId)){
|
|
|
103 |
try{
|
|
|
104 |
HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
|
|
|
105 |
hotspotStores.put(storeId, hotSpotStore);
|
|
|
106 |
} catch (Exception e) {
|
|
|
107 |
logger.error("Unable to get store", e);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
long today = -1;
|
|
|
112 |
today = new Date().getTime();
|
|
|
113 |
try {
|
|
|
114 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
115 |
orders = tClient.getOrdersForStore(0, storeId, today, today, statuses);
|
|
|
116 |
} catch (Exception e) {
|
|
|
117 |
setSearchError("Error getting all transactions for today. Please try again.");
|
|
|
118 |
logger.error("Unable to get all Transactions for today", e);
|
|
|
119 |
}
|
|
|
120 |
return "index";
|
|
|
121 |
}
|
|
|
122 |
|
| 7348 |
anupam.sin |
123 |
public String search() {
|
| 7386 |
anupam.sin |
124 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
|
|
125 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
|
|
126 |
return "authfail";
|
|
|
127 |
}
|
| 7343 |
anupam.sin |
128 |
if(number != null) {
|
|
|
129 |
try {
|
|
|
130 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| 7423 |
anupam.sin |
131 |
setSearchResult(tClient.getOrdersForStore(number, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), -1, -1, statuses));
|
| 7343 |
anupam.sin |
132 |
if(searchResult.size() == 0) {
|
| 7423 |
anupam.sin |
133 |
setSearchError("Could not find any orders with this number. Please try again.");
|
| 7343 |
anupam.sin |
134 |
}
|
|
|
135 |
} catch(Exception e) {
|
|
|
136 |
setSearchError("Some error occured. Please try again.");
|
|
|
137 |
logger.error("Error during search", e);
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
return index();
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public String getCollection() throws Exception{
|
| 7386 |
anupam.sin |
144 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
|
|
145 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
|
|
146 |
return "authfail";
|
|
|
147 |
}
|
| 7427 |
anupam.sin |
148 |
|
|
|
149 |
long sDate = -1;
|
|
|
150 |
long eDate = -1;
|
|
|
151 |
|
|
|
152 |
if(dateselector.equals("1")) {
|
|
|
153 |
sDate = new Date().getTime();
|
|
|
154 |
eDate = sDate;
|
|
|
155 |
}else if (dateselector.equals("2")) {
|
|
|
156 |
sDate = new Date().getTime() - 86400*1000;
|
|
|
157 |
eDate = sDate;
|
|
|
158 |
}else {
|
|
|
159 |
if(!(startDate.equals(""))) {
|
|
|
160 |
sDate = dateFormatter.parse(startDate).getTime();
|
|
|
161 |
startDate = dateFormatter.format(sDate);
|
|
|
162 |
}
|
|
|
163 |
if(!endDate.equals("")) {
|
|
|
164 |
eDate = dateFormatter.parse(endDate).getTime();
|
|
|
165 |
endDate = dateFormatter.format(eDate);
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
| 7343 |
anupam.sin |
169 |
long today = -1;
|
|
|
170 |
today = new Date().getTime();
|
| 7427 |
anupam.sin |
171 |
List<StoreOrderCollection> collections = tClient.getCollectionsForStore(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), sDate, eDate);
|
|
|
172 |
ByteArrayOutputStream baos = generateCollectionReport(collections);
|
| 7343 |
anupam.sin |
173 |
response.setContentType("application/vnd.ms-excel");
|
|
|
174 |
String fileName = "collection-report";
|
|
|
175 |
String todayDate = df4Filename.format(new Date(today));
|
|
|
176 |
fileName = fileName + "-" + todayDate;
|
|
|
177 |
fileName = fileName + ".xls";
|
|
|
178 |
response.setHeader("Content-disposition", "inline; filename=" + fileName);
|
|
|
179 |
ServletOutputStream sos;
|
|
|
180 |
try {
|
|
|
181 |
sos = response.getOutputStream();
|
|
|
182 |
baos.writeTo(sos);
|
|
|
183 |
sos.flush();
|
|
|
184 |
} catch (IOException e) {
|
|
|
185 |
e.printStackTrace();
|
|
|
186 |
}
|
|
|
187 |
return null;
|
|
|
188 |
|
|
|
189 |
}
|
|
|
190 |
|
| 7427 |
anupam.sin |
191 |
private ByteArrayOutputStream generateCollectionReport(List<StoreOrderCollection> collections) {
|
| 7343 |
anupam.sin |
192 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
|
|
193 |
Workbook wb = new HSSFWorkbook();
|
| 7427 |
anupam.sin |
194 |
Sheet reportSheet = wb.createSheet("Collection Report");
|
| 7343 |
anupam.sin |
195 |
Row reportSheetHeader = reportSheet.createRow((short)0);
|
|
|
196 |
reportSheetHeader.createCell(0).setCellValue("Order ID");
|
| 7427 |
anupam.sin |
197 |
reportSheetHeader.createCell(1).setCellValue("Date");
|
| 7348 |
anupam.sin |
198 |
reportSheetHeader.createCell(2).setCellValue("Product");
|
| 7427 |
anupam.sin |
199 |
reportSheetHeader.createCell(3).setCellValue("Collection Type");
|
|
|
200 |
reportSheetHeader.createCell(4).setCellValue("Amount");
|
|
|
201 |
reportSheetHeader.createCell(5).setCellValue("Cash");
|
|
|
202 |
reportSheetHeader.createCell(6).setCellValue("Card");
|
| 7343 |
anupam.sin |
203 |
|
| 7427 |
anupam.sin |
204 |
|
|
|
205 |
|
| 7343 |
anupam.sin |
206 |
int serialNo = 0;
|
|
|
207 |
|
| 7427 |
anupam.sin |
208 |
for(StoreOrderCollection collection : collections) {
|
| 7343 |
anupam.sin |
209 |
serialNo++;
|
|
|
210 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
| 7427 |
anupam.sin |
211 |
contentRow.createCell(0).setCellValue(collection.getOrderId());
|
|
|
212 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(collection.getPushedAt())));
|
|
|
213 |
contentRow.createCell(2).setCellValue(collection.getProductName());
|
|
|
214 |
contentRow.createCell(3).setCellValue(collection.getCollectionType());
|
|
|
215 |
contentRow.createCell(4).setCellValue(collection.getAdvanceAmount());
|
|
|
216 |
contentRow.createCell(5).setCellValue(collection.getCash());
|
|
|
217 |
contentRow.createCell(6).setCellValue(collection.getCard());
|
| 7343 |
anupam.sin |
218 |
}
|
|
|
219 |
try {
|
|
|
220 |
wb.write(baosXLS);
|
|
|
221 |
} catch (IOException e) {
|
| 7611 |
anupam.sin |
222 |
log.error("Could not write to XLS file", e);
|
| 7343 |
anupam.sin |
223 |
}
|
|
|
224 |
return baosXLS;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
public String create() throws Exception{
|
|
|
229 |
long sDate = -1;
|
|
|
230 |
long eDate = -1;
|
|
|
231 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
|
|
232 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
|
|
233 |
return "authfail";
|
|
|
234 |
}
|
|
|
235 |
if(dateselector.equals("1")) {
|
|
|
236 |
sDate = new Date().getTime();
|
|
|
237 |
eDate = sDate;
|
|
|
238 |
}else if (dateselector.equals("2")) {
|
|
|
239 |
sDate = new Date().getTime() - 86400*1000;
|
|
|
240 |
eDate = sDate;
|
|
|
241 |
}else {
|
|
|
242 |
if(!(startDate.equals(""))) {
|
|
|
243 |
sDate = dateFormatter.parse(startDate).getTime();
|
|
|
244 |
startDate = dateFormatter.format(sDate);
|
|
|
245 |
}
|
|
|
246 |
if(!endDate.equals("")) {
|
|
|
247 |
eDate = dateFormatter.parse(endDate).getTime();
|
|
|
248 |
endDate = dateFormatter.format(sDate);
|
|
|
249 |
}
|
|
|
250 |
}
|
| 7427 |
anupam.sin |
251 |
|
|
|
252 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| 7611 |
anupam.sin |
253 |
if(reportType == 1) {
|
|
|
254 |
statuses.add(OrderStatus.DELIVERY_SUCCESS);
|
|
|
255 |
}
|
| 7427 |
anupam.sin |
256 |
orders = tClient.getOrdersForStore(0, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), sDate, eDate, statuses);
|
| 7343 |
anupam.sin |
257 |
|
| 7427 |
anupam.sin |
258 |
ByteArrayOutputStream baos = generateReport(orders);
|
| 7343 |
anupam.sin |
259 |
|
|
|
260 |
response.setContentType("application/vnd.ms-excel");
|
| 7427 |
anupam.sin |
261 |
String fileName = "sales-report";
|
| 7343 |
anupam.sin |
262 |
if (!startDate.equals("")) {
|
|
|
263 |
fileName = fileName + "-" + startDate.replaceAll("\\\\", "_") ;
|
|
|
264 |
}
|
|
|
265 |
if (!endDate.equals("")) {
|
|
|
266 |
fileName = fileName + "-" + endDate.replaceAll("\\\\", "_") ;
|
|
|
267 |
}
|
|
|
268 |
fileName = fileName + ".xls";
|
|
|
269 |
response.setHeader("Content-disposition", "inline; filename=" + fileName);
|
|
|
270 |
ServletOutputStream sos;
|
|
|
271 |
try {
|
|
|
272 |
sos = response.getOutputStream();
|
|
|
273 |
baos.writeTo(sos);
|
|
|
274 |
sos.flush();
|
|
|
275 |
} catch (IOException e) {
|
|
|
276 |
e.printStackTrace();
|
|
|
277 |
}
|
|
|
278 |
return "index";
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
|
| 7427 |
anupam.sin |
282 |
private ByteArrayOutputStream generateReport(List<Order> orders) {
|
| 7343 |
anupam.sin |
283 |
|
| 7427 |
anupam.sin |
284 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| 7343 |
anupam.sin |
285 |
Workbook wb = new HSSFWorkbook();
|
|
|
286 |
Sheet reportSheet = wb.createSheet("Recharge Report");
|
| 7427 |
anupam.sin |
287 |
|
| 7343 |
anupam.sin |
288 |
Row reportSheetHeader = reportSheet.createRow((short)0);
|
|
|
289 |
reportSheetHeader.createCell(0).setCellValue("Order ID");
|
|
|
290 |
reportSheetHeader.createCell(1).setCellValue("Order Date");
|
| 7427 |
anupam.sin |
291 |
reportSheetHeader.createCell(2).setCellValue("Product");
|
|
|
292 |
reportSheetHeader.createCell(3).setCellValue("Status");
|
|
|
293 |
reportSheetHeader.createCell(4).setCellValue("Order Amount");
|
|
|
294 |
reportSheetHeader.createCell(5).setCellValue("Advance");
|
| 7343 |
anupam.sin |
295 |
|
|
|
296 |
int serialNo = 0;
|
|
|
297 |
|
| 7427 |
anupam.sin |
298 |
for(Order order : orders) {
|
| 7343 |
anupam.sin |
299 |
serialNo++;
|
|
|
300 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
| 7427 |
anupam.sin |
301 |
contentRow.createCell(0).setCellValue(order.getId());
|
|
|
302 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
|
|
|
303 |
contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
|
| 7527 |
anupam.sin |
304 |
contentRow.createCell(3).setCellValue(order.getStatus().getDescription());
|
| 7427 |
anupam.sin |
305 |
contentRow.createCell(4).setCellValue(order.getTotal_amount());
|
|
|
306 |
contentRow.createCell(5).setCellValue(order.getAdvanceAmount());
|
| 7343 |
anupam.sin |
307 |
}
|
|
|
308 |
try {
|
|
|
309 |
wb.write(baosXLS);
|
|
|
310 |
} catch (IOException e) {
|
|
|
311 |
e.printStackTrace();
|
|
|
312 |
}
|
|
|
313 |
return baosXLS;
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
public String downloadInvoice() {
|
|
|
317 |
ByteBuffer buffer = null;
|
|
|
318 |
try {
|
|
|
319 |
if (number == null || number == 0) {
|
|
|
320 |
log.error("rechargeId is 0");
|
|
|
321 |
return "index";
|
|
|
322 |
}
|
|
|
323 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
324 |
TransactionService.Client orderClient = transactionServiceClient.getClient();
|
| 7409 |
anupam.sin |
325 |
buffer = orderClient.getStoreOrderAdvanceInvoice(number, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")));
|
| 7343 |
anupam.sin |
326 |
if(!buffer.hasArray()) {
|
| 7409 |
anupam.sin |
327 |
log.error("The invoice was not found for orderId : " + number);
|
| 7343 |
anupam.sin |
328 |
}
|
|
|
329 |
} catch (Exception e) {
|
|
|
330 |
System.out.println(e.getMessage());
|
|
|
331 |
}
|
|
|
332 |
response.setContentType("application/pdf");
|
| 7399 |
anupam.sin |
333 |
response.setHeader("Content-disposition", "attachment; filename=receipt-" + number.toString() + ".pdf");
|
| 7343 |
anupam.sin |
334 |
|
|
|
335 |
ServletOutputStream sos;
|
|
|
336 |
try {
|
|
|
337 |
sos = response.getOutputStream();
|
|
|
338 |
sos.write(buffer.array());
|
|
|
339 |
sos.flush();
|
|
|
340 |
} catch (Exception e) {
|
|
|
341 |
System.out.println("Unable to stream the invoice file");
|
|
|
342 |
}
|
|
|
343 |
return "index";
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
public String sendPassword() throws Exception {
|
|
|
347 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
|
|
348 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
|
|
349 |
return "authfail";
|
|
|
350 |
}
|
|
|
351 |
Long storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
|
|
|
352 |
|
|
|
353 |
char[] buf = new char[LENGTH];
|
|
|
354 |
for (int i = 0; i < buf.length; i++) {
|
|
|
355 |
buf[i] = chars.charAt(random.nextInt(chars.length()));
|
|
|
356 |
}
|
|
|
357 |
String password = new String(buf);
|
|
|
358 |
|
|
|
359 |
try {
|
|
|
360 |
TransactionClient tcl = new TransactionClient();
|
|
|
361 |
HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(storeId, "");
|
|
|
362 |
boolean wasPasswordSet = tcl.getClient().updateHotspotStorePassword(storeId, password);
|
|
|
363 |
if(!wasPasswordSet) {
|
|
|
364 |
passwordGeneration = "FAIL";
|
|
|
365 |
return index();
|
|
|
366 |
}
|
|
|
367 |
List<String> toList = new ArrayList<String>();
|
|
|
368 |
toList.add(hotSpotStore.getEmail());
|
|
|
369 |
HelperClient helperServiceClient = null;
|
|
|
370 |
helperServiceClient = new HelperClient();
|
|
|
371 |
in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
Mail mail = new Mail();
|
|
|
375 |
mail.setSubject("New Password for Saholic Recharge");
|
|
|
376 |
mail.setTo(toList);
|
|
|
377 |
mail.setData("Your new password is : " + password);
|
|
|
378 |
client.sendMail(mail);
|
|
|
379 |
} catch(Exception e) {
|
|
|
380 |
passwordGeneration = "FAIL";
|
|
|
381 |
logger.error("Password generation/sending failed for storeId : " + storeId, e);
|
|
|
382 |
}
|
|
|
383 |
passwordGeneration = "SUCCESS";
|
|
|
384 |
return index();
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
public String getDateTime(long milliseconds) {
|
|
|
388 |
Calendar cal = Calendar.getInstance();
|
|
|
389 |
cal.setTimeInMillis(milliseconds);
|
|
|
390 |
return formatter.format(cal.getTime());
|
|
|
391 |
}
|
| 7348 |
anupam.sin |
392 |
|
|
|
393 |
public String cancelRequest() {
|
|
|
394 |
try{
|
|
|
395 |
TransactionClient tcl = new TransactionClient();
|
| 7393 |
anupam.sin |
396 |
long storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
|
|
|
397 |
StoreOrderDetail sod = tcl.getClient().getStoreOrderDetail(orderId, storeId);
|
| 7611 |
anupam.sin |
398 |
if(sod.getCardAmount() > 0 && "debit".equals(sod.getCardType())) {
|
|
|
399 |
logger.error("Error : Cancellation cannot be requested for order with Debit Card Transaction : " + orderId.toString());
|
|
|
400 |
setSearchError("Amount was paid by Debit card. Please call customer care to get this order cancelled.");
|
|
|
401 |
number = orderId;
|
|
|
402 |
return search();
|
|
|
403 |
}
|
| 7393 |
anupam.sin |
404 |
tcl.getClient().saveRefundAmountsForStoreOrder(orderId, storeId, sod.getCashAmount(), sod.getCardAmount());
|
| 7399 |
anupam.sin |
405 |
tcl.getClient().markOrderCancellationRequestReceived(orderId);
|
|
|
406 |
tcl.getClient().markOrderCancellationRequestConfirmed(orderId);
|
| 7386 |
anupam.sin |
407 |
tcl.getClient().refundOrder(orderId, "Store", "User requested for cancellation");
|
| 7348 |
anupam.sin |
408 |
} catch (Exception e) {
|
|
|
409 |
logger.error("Could not mark order as cancellation requested for id : " + orderId.toString(), e);
|
|
|
410 |
setSearchError("Request failed. Try again or call customer care.");
|
|
|
411 |
}
|
|
|
412 |
number = orderId;
|
|
|
413 |
return search();
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
public String requestReturn() {
|
|
|
417 |
try{
|
|
|
418 |
TransactionClient tcl = new TransactionClient();
|
|
|
419 |
if(returnType.equals("doa")) {
|
|
|
420 |
tcl.getClient().markOrderDoaRequestReceived(orderId);
|
|
|
421 |
} else if(returnType.equals("return")) {
|
|
|
422 |
tcl.getClient().markOrderReturnRequestReceived(orderId);
|
|
|
423 |
} else {
|
|
|
424 |
setSearchError("Error in requesting return. Try Again.");
|
|
|
425 |
}
|
|
|
426 |
} catch (Exception e) {
|
|
|
427 |
logger.error("Could not mark order as return requested for id : " + orderId.toString(), e);
|
|
|
428 |
setSearchError("Request failed. Try again or call customer care.");
|
|
|
429 |
}
|
|
|
430 |
number = orderId;
|
|
|
431 |
return search();
|
|
|
432 |
}
|
| 7349 |
anupam.sin |
433 |
|
| 7611 |
anupam.sin |
434 |
// public String refundOrder() {
|
|
|
435 |
// number = orderId;
|
|
|
436 |
// try{
|
|
|
437 |
// TransactionClient tcl = new TransactionClient();
|
|
|
438 |
// Order order = tcl.getClient().getOrder(number);
|
|
|
439 |
// if(order.getTotal_amount() < refundAmount) {
|
|
|
440 |
// setSearchError("You cannot refund more than Rs. " + refundAmount.toString());
|
|
|
441 |
// return search();
|
|
|
442 |
// }
|
|
|
443 |
// tcl.getClient().refundOrder(orderId, "ANU", "Cancelled");
|
|
|
444 |
// setSearchError("SUCCESSFUL. Please refund Rs. " + refundAmount.toString() + " to the customer.");
|
|
|
445 |
// } catch (Exception e) {
|
|
|
446 |
// logger.error("Could not mark order as return requested for id : " + orderId.toString(), e);
|
|
|
447 |
// setSearchError("Could not refund. Try again or call customer care.");
|
|
|
448 |
// }
|
|
|
449 |
// return search();
|
|
|
450 |
// }
|
| 7343 |
anupam.sin |
451 |
|
|
|
452 |
public List<Order> getOrders(){
|
|
|
453 |
return orders;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
457 |
this.request = req;
|
|
|
458 |
this.session = req.getSession();
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
public void setServletContext(ServletContext context) {
|
|
|
462 |
this.context = context;
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
466 |
this.response = response;
|
|
|
467 |
}
|
|
|
468 |
|
|
|
469 |
public String getServletContextPath() {
|
|
|
470 |
return context.getContextPath();
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
public String getProductName(LineItem item) {
|
|
|
474 |
return item.getBrand()
|
|
|
475 |
+ (item.getModel_name() == null ? "" : " " + item.getModel_name())
|
|
|
476 |
+ (item.getModel_number() == null ? "" : " " + item.getModel_number())
|
|
|
477 |
+ (item.getColor() == null || item.getColor() == "" ? "" : " (" + item.getColor() + ")");
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
public String getStartDate() {
|
|
|
481 |
return startDate;
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
public void setStartDate(String startDate) {
|
|
|
486 |
this.startDate = startDate;
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
public String getEndDate() {
|
|
|
490 |
return endDate;
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
|
|
|
494 |
public void setEndDate(String endDate) {
|
|
|
495 |
this.endDate = endDate;
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
public String getStatus() {
|
|
|
499 |
return status;
|
|
|
500 |
}
|
|
|
501 |
|
|
|
502 |
|
|
|
503 |
public void setStatus(String status) {
|
|
|
504 |
this.status = status;
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
|
|
|
508 |
public String getDateselector() {
|
|
|
509 |
return dateselector;
|
|
|
510 |
}
|
|
|
511 |
|
|
|
512 |
|
|
|
513 |
public void setDateselector(String dateselector) {
|
|
|
514 |
this.dateselector = dateselector;
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
public void setSearchError(String searchError) {
|
|
|
519 |
this.searchError = searchError;
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
|
|
|
523 |
public String getSearchError() {
|
|
|
524 |
return searchError;
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
|
|
|
528 |
public void setNumber(Long number) {
|
|
|
529 |
this.number = number;
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
public Long getNumber() {
|
|
|
534 |
return number;
|
|
|
535 |
}
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
public void setSearchResult(List<Order> searchResult) {
|
|
|
539 |
this.searchResult = searchResult;
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
public List<Order> getSearchResult() {
|
|
|
544 |
if(searchResult == null)
|
|
|
545 |
searchResult = new ArrayList<Order>();
|
|
|
546 |
return searchResult;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
public void setShowReprintColumn(boolean showReprintColumn) {
|
|
|
551 |
this.showReprintColumn = showReprintColumn;
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
public boolean shouldShowReprintColumn() {
|
|
|
556 |
return showReprintColumn;
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
public void setPasswordGeneration(String passwordGeneration) {
|
|
|
561 |
this.passwordGeneration = passwordGeneration;
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
public String getPasswordGeneration() {
|
|
|
566 |
return passwordGeneration;
|
|
|
567 |
}
|
| 7348 |
anupam.sin |
568 |
|
|
|
569 |
|
|
|
570 |
public void setOrderId(Long orderId) {
|
|
|
571 |
this.orderId = orderId;
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
public Long getOrderId() {
|
|
|
576 |
return orderId;
|
|
|
577 |
}
|
|
|
578 |
|
|
|
579 |
|
|
|
580 |
public void setReturnType(String returnType) {
|
|
|
581 |
this.returnType = returnType;
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
public String getReturnType() {
|
|
|
586 |
return returnType;
|
|
|
587 |
}
|
| 7349 |
anupam.sin |
588 |
|
|
|
589 |
|
|
|
590 |
public void setRefundAmount(Long refundAmount) {
|
|
|
591 |
this.refundAmount = refundAmount;
|
|
|
592 |
}
|
|
|
593 |
|
|
|
594 |
|
|
|
595 |
public Long getRefundAmount() {
|
|
|
596 |
return refundAmount;
|
|
|
597 |
}
|
| 7343 |
anupam.sin |
598 |
|
| 7386 |
anupam.sin |
599 |
public boolean isOrderPlacedOnSameDay(long orderTime) {
|
|
|
600 |
Calendar calOrderDate = Calendar.getInstance();
|
|
|
601 |
calOrderDate.setTimeInMillis(orderTime);
|
|
|
602 |
|
|
|
603 |
Calendar cal = Calendar.getInstance();
|
|
|
604 |
if(cal.get(Calendar.DATE) == calOrderDate.get(Calendar.DATE)
|
|
|
605 |
&& cal.get(Calendar.MONTH) == calOrderDate.get(Calendar.MONTH)
|
|
|
606 |
&& cal.get(Calendar.YEAR) == calOrderDate.get(Calendar.YEAR)) {
|
|
|
607 |
return true;
|
|
|
608 |
}
|
|
|
609 |
return false;
|
|
|
610 |
}
|
| 7611 |
anupam.sin |
611 |
|
|
|
612 |
public boolean debitCardNotUsed(long orderId) {
|
|
|
613 |
try {
|
|
|
614 |
TransactionClient tcl = new TransactionClient();
|
|
|
615 |
StoreOrderDetail sod = tcl.getClient().getStoreOrderDetail(orderId, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")));
|
|
|
616 |
if("debit".equals(sod.getCardType())) {
|
|
|
617 |
return false;
|
|
|
618 |
}
|
|
|
619 |
else {
|
|
|
620 |
return true;
|
|
|
621 |
}
|
|
|
622 |
} catch(Exception e) {
|
|
|
623 |
//We cannot be sure so not taking any risks.
|
|
|
624 |
log.error("Unable to get storeOrderDetail for order Id : " + orderId, e);
|
|
|
625 |
return false;
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
}
|
| 7343 |
anupam.sin |
629 |
|
| 7611 |
anupam.sin |
630 |
|
|
|
631 |
public int getReportType() {
|
|
|
632 |
return reportType;
|
|
|
633 |
}
|
|
|
634 |
|
|
|
635 |
|
|
|
636 |
public void setReportType(int reportType) {
|
|
|
637 |
this.reportType = reportType;
|
|
|
638 |
}
|
|
|
639 |
|
| 7343 |
anupam.sin |
640 |
}
|