| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.controllers;
|
1 |
package in.shop2020.support.controllers;
|
| 2 |
|
2 |
|
| 3 |
|
3 |
|
| 4 |
|
4 |
|
| 5 |
import in.shop2020.model.v1.order.Attribute;
|
5 |
import in.shop2020.model.v1.order.Attribute;
|
| - |
|
6 |
import in.shop2020.model.v1.order.LineItem;
|
| 6 |
import in.shop2020.model.v1.order.Order;
|
7 |
import in.shop2020.model.v1.order.Order;
|
| 7 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
8 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
9 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 9 |
import in.shop2020.thrift.clients.TransactionClient;
|
10 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 10 |
|
11 |
|
| - |
|
12 |
import java.io.ByteArrayOutputStream;
|
| - |
|
13 |
import java.io.IOException;
|
| - |
|
14 |
import java.text.DateFormat;
|
| - |
|
15 |
import java.text.ParseException;
|
| - |
|
16 |
import java.text.SimpleDateFormat;
|
| 11 |
import java.util.ArrayList;
|
17 |
import java.util.ArrayList;
|
| 12 |
import java.util.Calendar;
|
18 |
import java.util.Calendar;
|
| - |
|
19 |
import java.util.Date;
|
| - |
|
20 |
import java.util.HashMap;
|
| 13 |
import java.util.List;
|
21 |
import java.util.List;
|
| 14 |
|
22 |
|
| 15 |
import javax.servlet.ServletContext;
|
23 |
import javax.servlet.ServletContext;
|
| - |
|
24 |
import javax.servlet.ServletOutputStream;
|
| 16 |
import javax.servlet.http.HttpServletRequest;
|
25 |
import javax.servlet.http.HttpServletRequest;
|
| 17 |
import javax.servlet.http.HttpServletResponse;
|
26 |
import javax.servlet.http.HttpServletResponse;
|
| 18 |
|
27 |
|
| - |
|
28 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| - |
|
29 |
import org.apache.poi.ss.usermodel.CellStyle;
|
| - |
|
30 |
import org.apache.poi.ss.usermodel.DataFormat;
|
| - |
|
31 |
import org.apache.poi.ss.usermodel.Font;
|
| - |
|
32 |
import org.apache.poi.ss.usermodel.Row;
|
| - |
|
33 |
import org.apache.poi.ss.usermodel.Sheet;
|
| - |
|
34 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 19 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
35 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
| 20 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
36 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
| 21 |
import org.apache.struts2.util.ServletContextAware;
|
37 |
import org.apache.struts2.util.ServletContextAware;
|
| 22 |
import org.apache.thrift.TException;
|
38 |
import org.apache.thrift.TException;
|
| 23 |
import org.apache.thrift.transport.TTransportException;
|
39 |
import org.apache.thrift.transport.TTransportException;
|
| Line 108... |
Line 124... |
| 108 |
try {
|
124 |
try {
|
| 109 |
Client client = (new TransactionClient()).getClient();
|
125 |
Client client = (new TransactionClient()).getClient();
|
| 110 |
if(action.equals("markreceived")){
|
126 |
if(action.equals("markreceived")){
|
| 111 |
long orderId = Long.parseLong(orderIdString);
|
127 |
long orderId = Long.parseLong(orderIdString);
|
| 112 |
client.markOrderAsReceivedAtStore(orderId, Calendar.getInstance().getTimeInMillis());
|
128 |
client.markOrderAsReceivedAtStore(orderId, Calendar.getInstance().getTimeInMillis());
|
| - |
|
129 |
}else if(action.equals("markrejected")){
|
| - |
|
130 |
long orderId = Long.parseLong(orderIdString);
|
| - |
|
131 |
Order order = client.getOrder(orderId);
|
| - |
|
132 |
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| - |
|
133 |
String returnReason = formatter.format(Calendar.getInstance().getTime()) + "|Returned from store.";
|
| - |
|
134 |
HashMap<String, String> orderMap = new HashMap<String, String>();
|
| - |
|
135 |
orderMap.put(order.getAirwaybill_no(), returnReason);
|
| - |
|
136 |
client.markAsRTOrders(order.getLogistics_provider_id(), orderMap);
|
| 113 |
}else if(action.equals("markdelivered")){
|
137 |
}else if(action.equals("markdelivered")){
|
| 114 |
long orderId = Long.parseLong(orderIdString);
|
138 |
long orderId = Long.parseLong(orderIdString);
|
| 115 |
String receiver = request.getParameter("receiver");
|
139 |
String receiver = request.getParameter("receiver");
|
| 116 |
String secretCode = request.getParameter("secretcode");
|
140 |
String secretCode = request.getParameter("secretcode");
|
| 117 |
Order order = client.getOrder(orderId);
|
141 |
Order order = client.getOrder(orderId);
|
| Line 146... |
Line 170... |
| 146 |
long providerId = Long.parseLong(request.getParameter("providerID"));
|
170 |
long providerId = Long.parseLong(request.getParameter("providerID"));
|
| 147 |
List<Long> orderIds = new ArrayList<Long>();
|
171 |
List<Long> orderIds = new ArrayList<Long>();
|
| 148 |
for(String orderIdString1: orderIdsString.split(":")){
|
172 |
for(String orderIdString1: orderIdsString.split(":")){
|
| 149 |
orderIds.add(Long.parseLong(orderIdString1));
|
173 |
orderIds.add(Long.parseLong(orderIdString1));
|
| 150 |
}
|
174 |
}
|
| - |
|
175 |
List<String> awbs = new ArrayList<String>();
|
| - |
|
176 |
for(String awb: request.getParameter("awbs").split(":")){
|
| - |
|
177 |
awbs.add(awb);
|
| - |
|
178 |
}
|
| 151 |
client.markOrdersAsReturnedFromStore(providerId, orderIds);
|
179 |
client.markOrdersAsReturnedFromStore(providerId, orderIds, awbs);
|
| - |
|
180 |
}else if(action.equals("getreport")){
|
| - |
|
181 |
|
| - |
|
182 |
String startDateStr = request.getParameter("startDate");
|
| - |
|
183 |
String endDateStr = request.getParameter("endDate");
|
| - |
|
184 |
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
|
| - |
|
185 |
Date startDate = null, endDate = null;
|
| - |
|
186 |
try {
|
| - |
|
187 |
startDate = df.parse(startDateStr);
|
| - |
|
188 |
endDate = df.parse(endDateStr);
|
| - |
|
189 |
Calendar cal = Calendar.getInstance();
|
| - |
|
190 |
cal.setTime(endDate);
|
| - |
|
191 |
cal.add(Calendar.DATE, 1);
|
| - |
|
192 |
endDate.setTime(cal.getTimeInMillis());
|
| - |
|
193 |
} catch (ParseException pe) {
|
| - |
|
194 |
error = "Please enter start and end dates in format MM/dd/yyyy";
|
| - |
|
195 |
}
|
| - |
|
196 |
if(!error.equalsIgnoreCase("")){
|
| - |
|
197 |
setId("report");
|
| - |
|
198 |
return show();
|
| - |
|
199 |
}
|
| - |
|
200 |
|
| - |
|
201 |
ByteArrayOutputStream baos = generateCollectionReport(startDate, endDate, storeId);
|
| - |
|
202 |
|
| - |
|
203 |
if (baos == null) {
|
| - |
|
204 |
error = "No output for given date range";
|
| - |
|
205 |
} else {
|
| - |
|
206 |
error = "Generating report...";
|
| - |
|
207 |
}
|
| - |
|
208 |
response.setContentType("application/vnd.ms-excel");
|
| - |
|
209 |
response.setHeader("Content-disposition", "inline; filename=collection-report.xls");
|
| - |
|
210 |
ServletOutputStream sos;
|
| - |
|
211 |
try {
|
| - |
|
212 |
sos = response.getOutputStream();
|
| - |
|
213 |
baos.writeTo(sos);
|
| - |
|
214 |
sos.flush();
|
| - |
|
215 |
error = "Report generated";
|
| - |
|
216 |
} catch (IOException e) {
|
| - |
|
217 |
error = "Failed to write to response.";
|
| - |
|
218 |
logger.error("Unable to stream the colection report", e);
|
| - |
|
219 |
}
|
| - |
|
220 |
if(!error.equalsIgnoreCase("")){
|
| - |
|
221 |
setId("report");
|
| - |
|
222 |
return show();
|
| - |
|
223 |
}
|
| 152 |
}
|
224 |
}
|
| 153 |
|
- |
|
| 154 |
return "index";
|
225 |
return "index";
|
| 155 |
} catch (TTransportException e) {
|
226 |
} catch (TTransportException e) {
|
| 156 |
// TODO Auto-generated catch block
|
227 |
// TODO Auto-generated catch block
|
| 157 |
e.printStackTrace();
|
228 |
e.printStackTrace();
|
| 158 |
} catch (NumberFormatException e) {
|
229 |
} catch (NumberFormatException e) {
|
| Line 167... |
Line 238... |
| 167 |
}
|
238 |
}
|
| 168 |
return "index";
|
239 |
return "index";
|
| 169 |
}
|
240 |
}
|
| 170 |
|
241 |
|
| 171 |
|
242 |
|
| - |
|
243 |
private ByteArrayOutputStream generateCollectionReport(Date startDate, Date endDate, long storeId) throws TException {
|
| - |
|
244 |
List<Order> orders = client.getOrdersCollectionAtStore(storeId, startDate.getTime(), endDate.getTime(), false);
|
| - |
|
245 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| - |
|
246 |
|
| - |
|
247 |
Workbook wb = new HSSFWorkbook();
|
| - |
|
248 |
|
| - |
|
249 |
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
250 |
Font font = wb.createFont();
|
| - |
|
251 |
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
| - |
|
252 |
CellStyle style = wb.createCellStyle();
|
| - |
|
253 |
style.setFont(font);
|
| - |
|
254 |
|
| - |
|
255 |
DataFormat format = wb.createDataFormat();
|
| - |
|
256 |
CellStyle styleAmount = wb.createCellStyle();
|
| - |
|
257 |
styleAmount.setDataFormat(format.getFormat("#,##0.00"));
|
| - |
|
258 |
|
| - |
|
259 |
Sheet collectionSheet = wb.createSheet("Collection");
|
| - |
|
260 |
short collectionSerialNo = 0;
|
| - |
|
261 |
|
| - |
|
262 |
Row headerRow = collectionSheet.createRow(collectionSerialNo++);
|
| - |
|
263 |
headerRow.createCell(0).setCellValue("S.No");
|
| - |
|
264 |
headerRow.createCell(1).setCellValue("Order Id");
|
| - |
|
265 |
headerRow.createCell(2).setCellValue("Product");
|
| - |
|
266 |
headerRow.createCell(3).setCellValue("Order Type");
|
| - |
|
267 |
headerRow.createCell(4).setCellValue("Collection Date");
|
| - |
|
268 |
headerRow.createCell(5).setCellValue("Order Amount");
|
| - |
|
269 |
headerRow.createCell(6).setCellValue("Collected Amount");
|
| - |
|
270 |
headerRow.createCell(7).setCellValue("Store Margin");
|
| - |
|
271 |
|
| - |
|
272 |
for(Order order: orders){
|
| - |
|
273 |
Row contentRow = collectionSheet.createRow(collectionSerialNo++);
|
| - |
|
274 |
LineItem line = order.getLineitems().get(0);
|
| - |
|
275 |
String productName = line.getBrand() + " " + line.getModel_name() + " " + line.getModel_number() + " " + line.getColor();
|
| - |
|
276 |
productName = productName.replaceAll("null", "").replaceAll(" ", " ");
|
| - |
|
277 |
contentRow.createCell(0).setCellValue(collectionSerialNo-1);
|
| - |
|
278 |
contentRow.createCell(1).setCellValue(order.getId());
|
| - |
|
279 |
contentRow.createCell(2).setCellValue(productName);
|
| - |
|
280 |
contentRow.createCell(3).setCellValue(order.isCod() ? "COD" : "Prepaid");
|
| - |
|
281 |
contentRow.createCell(4).setCellValue(formatter.format(order.getDelivery_timestamp()));
|
| - |
|
282 |
contentRow.createCell(5).setCellValue(order.getTotal_amount());
|
| - |
|
283 |
contentRow.createCell(6).setCellValue(order.isCod() ? order.getTotal_amount() : 0.0);
|
| - |
|
284 |
contentRow.createCell(7).setCellValue(order.isCod() ? .01 * order.getTotal_amount() : .005 * order.getTotal_amount());
|
| - |
|
285 |
}
|
| - |
|
286 |
|
| - |
|
287 |
try {
|
| - |
|
288 |
wb.write(baosXLS);
|
| - |
|
289 |
baosXLS.close();
|
| - |
|
290 |
} catch (IOException e) {
|
| - |
|
291 |
logger.error("Error while streaming payment details report", e);
|
| - |
|
292 |
}
|
| - |
|
293 |
return baosXLS;
|
| - |
|
294 |
}
|
| - |
|
295 |
|
| 172 |
public List<Order> getReceivePendingOrders() throws TException{
|
296 |
public List<Order> getReceivePendingOrders() throws TException{
|
| 173 |
Client client = (new TransactionClient()).getClient();
|
297 |
Client client = (new TransactionClient()).getClient();
|
| 174 |
return client.getReceivePendingOrders(storeId);
|
298 |
return client.getReceivePendingOrders(storeId);
|
| 175 |
}
|
299 |
}
|
| 176 |
|
300 |
|
| 177 |
public List<Order> getReceivedAtStoreOrders() throws TException{
|
301 |
public List<Order> getReceivedAtStoreOrders() throws TException{
|
| Line 179... |
Line 303... |
| 179 |
return client.getReceivedAtStoreOrders(storeId);
|
303 |
return client.getReceivedAtStoreOrders(storeId);
|
| 180 |
}
|
304 |
}
|
| 181 |
|
305 |
|
| 182 |
public String getSecretCode(long orderId) throws TException{
|
306 |
public String getSecretCode(long orderId) throws TException{
|
| 183 |
List<Attribute> attributes = client.getAllAttributesForOrderId(orderId);
|
307 |
List<Attribute> attributes = client.getAllAttributesForOrderId(orderId);
|
| - |
|
308 |
String secretCode = "";
|
| 184 |
for(Attribute attribute: attributes){
|
309 |
for(Attribute attribute: attributes){
|
| 185 |
if(attribute.getName() == "SECRET_CODE"){
|
310 |
if(attribute.getName().equals("SECRET_CODE") ){
|
| 186 |
return attribute.getValue();
|
311 |
secretCode = attribute.getValue();
|
| 187 |
}
|
312 |
}
|
| 188 |
}
|
313 |
}
|
| 189 |
return "";
|
314 |
return secretCode;
|
| 190 |
}
|
315 |
}
|
| 191 |
|
316 |
|
| 192 |
public void setId(String id) {
|
317 |
public void setId(String id) {
|
| 193 |
this.id = id;
|
318 |
this.id = id;
|
| 194 |
}
|
319 |
}
|