| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.services;
|
1 |
package in.shop2020.support.services;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.order.LineItem;
|
3 |
import in.shop2020.model.v1.order.LineItem;
|
| 4 |
import in.shop2020.model.v1.order.Order;
|
4 |
import in.shop2020.model.v1.order.Order;
|
| 5 |
import in.shop2020.model.v1.order.OrderStatus;
|
- |
|
| 6 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
5 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 7 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
6 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 8 |
|
7 |
|
| 9 |
import java.io.ByteArrayOutputStream;
|
8 |
import java.io.ByteArrayOutputStream;
|
| 10 |
import java.io.FileNotFoundException;
|
9 |
import java.io.FileNotFoundException;
|
| 11 |
import java.io.FileOutputStream;
|
10 |
import java.io.FileOutputStream;
|
| 12 |
import java.io.IOException;
|
11 |
import java.io.IOException;
|
| 13 |
import java.util.Calendar;
|
12 |
import java.util.Calendar;
|
| 14 |
import java.util.Date;
|
- |
|
| 15 |
import java.util.GregorianCalendar;
|
13 |
import java.util.GregorianCalendar;
|
| 16 |
import java.util.HashMap;
|
14 |
import java.util.HashMap;
|
| 17 |
import java.util.List;
|
15 |
import java.util.List;
|
| 18 |
import java.util.Map;
|
16 |
import java.util.Map;
|
| 19 |
import java.util.Map.Entry;
|
17 |
import java.util.Map.Entry;
|
| 20 |
|
18 |
|
| 21 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
19 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| - |
|
20 |
import org.apache.poi.ss.usermodel.CellStyle;
|
| - |
|
21 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
| 22 |
import org.apache.poi.ss.usermodel.Row;
|
22 |
import org.apache.poi.ss.usermodel.Row;
|
| 23 |
import org.apache.poi.ss.usermodel.Sheet;
|
23 |
import org.apache.poi.ss.usermodel.Sheet;
|
| 24 |
import org.apache.poi.ss.usermodel.Workbook;
|
24 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 25 |
import org.apache.thrift.TException;
|
25 |
import org.apache.thrift.TException;
|
| 26 |
|
26 |
|
| Line 34... |
Line 34... |
| 34 |
e.printStackTrace();
|
34 |
e.printStackTrace();
|
| 35 |
}
|
35 |
}
|
| 36 |
}
|
36 |
}
|
| 37 |
|
37 |
|
| 38 |
public ByteArrayOutputStream generatePendingOrdersDetails(long warehouseId){
|
38 |
public ByteArrayOutputStream generatePendingOrdersDetails(long warehouseId){
|
| - |
|
39 |
final int COL_SNO = 0,
|
| - |
|
40 |
COL_ORDER_ID = 1,
|
| - |
|
41 |
COL_CUSTOMER_NAME = 2,
|
| - |
|
42 |
COL_CUTOMER_PHONE = 3,
|
| - |
|
43 |
COL_SHIPPING_LOCATION = 4,
|
| - |
|
44 |
COL_PRODUCT_GROUP = 5,
|
| - |
|
45 |
COL_MODEL = 6,
|
| - |
|
46 |
COL_COLOUR = 7,
|
| - |
|
47 |
COL_QTY = 8,
|
| - |
|
48 |
COL_PRICE = 9;
|
| - |
|
49 |
final int COL_SUMMARY_SNO = 0, COL_SUMMARY_PRODUCT = 1, COL_SUMMARY_QTY = 2;
|
| - |
|
50 |
|
| 39 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
51 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| 40 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
52 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
| 41 |
List<Order> orders = null;
|
53 |
List<Order> orders = null;
|
| 42 |
|
54 |
|
| 43 |
try {
|
55 |
try {
|
| Line 50... |
Line 62... |
| 50 |
e.printStackTrace();
|
62 |
e.printStackTrace();
|
| 51 |
return baosXLS;
|
63 |
return baosXLS;
|
| 52 |
}
|
64 |
}
|
| 53 |
|
65 |
|
| 54 |
Workbook wb = new HSSFWorkbook();
|
66 |
Workbook wb = new HSSFWorkbook();
|
| - |
|
67 |
CreationHelper createHelper = wb.getCreationHelper();
|
| 55 |
Sheet detailedSheet = wb.createSheet("Detailed sheet");
|
68 |
Sheet detailedSheet = wb.createSheet("Detailed sheet");
|
| - |
|
69 |
detailedSheet.getPrintSetup().setLandscape(true); // Sets the print orientation as Landscape, by default its Portrait.
|
| - |
|
70 |
detailedSheet.setMargin(Sheet.RightMargin, 0.5);
|
| - |
|
71 |
detailedSheet.setPrintGridlines(true);
|
| 56 |
Sheet summarySheet = wb.createSheet("Summary sheet");
|
72 |
Sheet summarySheet = wb.createSheet("Summary sheet");
|
| - |
|
73 |
summarySheet.setPrintGridlines(true);
|
| 57 |
Map<String, Double> summaryMap = new HashMap<String, Double>();
|
74 |
Map<String, Double> summaryMap = new HashMap<String, Double>();
|
| - |
|
75 |
|
| - |
|
76 |
CellStyle csRA = wb.createCellStyle();
|
| - |
|
77 |
csRA.setAlignment(CellStyle.ALIGN_RIGHT);
|
| 58 |
|
78 |
|
| - |
|
79 |
CellStyle csWT = wb.createCellStyle();
|
| - |
|
80 |
csWT.setWrapText(true);
|
| - |
|
81 |
|
| - |
|
82 |
CellStyle weightStyle = wb.createCellStyle();
|
| - |
|
83 |
weightStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.00"));
|
| - |
|
84 |
|
| 59 |
Calendar date = new GregorianCalendar();
|
85 |
Calendar date = new GregorianCalendar();
|
| 60 |
int year = date.get(Calendar.YEAR);
|
86 |
int year = date.get(Calendar.YEAR);
|
| 61 |
int month = date.get(Calendar.MONTH) +1;
|
87 |
int month = date.get(Calendar.MONTH) +1;
|
| 62 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
88 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
| 63 |
int hour = date.get(Calendar.HOUR_OF_DAY);
|
89 |
int hour = date.get(Calendar.HOUR_OF_DAY);
|
| 64 |
int minute = date.get(Calendar.MINUTE);
|
90 |
int minute = date.get(Calendar.MINUTE);
|
| 65 |
|
91 |
|
| 66 |
Row dateRow = detailedSheet.createRow(1);
|
92 |
Row dateRow = detailedSheet.createRow(1);
|
| 67 |
dateRow.createCell(0).setCellValue("Date");
|
93 |
dateRow.createCell(2).setCellValue("Date");
|
| 68 |
dateRow.createCell(1).setCellValue(String.format("%4d-%02d-%02d", year, month, day));
|
94 |
dateRow.createCell(3).setCellValue(String.format("%4d-%02d-%02d", year, month, day));
|
| 69 |
|
95 |
|
| 70 |
Row timeRow = detailedSheet.createRow(2);
|
96 |
Row timeRow = detailedSheet.createRow(2);
|
| 71 |
timeRow.createCell(0).setCellValue("Time");
|
97 |
timeRow.createCell(2).setCellValue("Time");
|
| 72 |
timeRow.createCell(1).setCellValue(String.format("%02d:%02d", hour, minute));
|
98 |
timeRow.createCell(3).setCellValue(String.format("%02d:%02d", hour, minute));
|
| 73 |
|
99 |
|
| 74 |
Row batchRow = detailedSheet.createRow(3);
|
100 |
Row batchRow = detailedSheet.createRow(3);
|
| 75 |
batchRow.createCell(0).setCellValue("Batch No.");
|
101 |
batchRow.createCell(2).setCellValue("Batch No.");
|
| 76 |
batchRow.createCell(1).setCellValue(orders.get(0).getBatchNo());
|
102 |
batchRow.createCell(3).setCellValue(orders.get(0).getBatchNo() + "");
|
| 77 |
|
103 |
|
| 78 |
Row detailsHeaderRow = detailedSheet.createRow(5);
|
104 |
Row detailsHeaderRow = detailedSheet.createRow(5);
|
| 79 |
detailsHeaderRow.createCell(0).setCellValue("Sl No");
|
105 |
detailsHeaderRow.createCell(COL_SNO).setCellValue("SNo");
|
| 80 |
detailsHeaderRow.createCell(1).setCellValue("Order ID");
|
106 |
detailsHeaderRow.createCell(COL_ORDER_ID).setCellValue("Order ID");
|
| - |
|
107 |
|
| 81 |
detailsHeaderRow.createCell(2).setCellValue("Customer Name");
|
108 |
detailsHeaderRow.createCell(COL_CUSTOMER_NAME).setCellValue("Customer Name");
|
| - |
|
109 |
detailedSheet.setColumnWidth(COL_CUSTOMER_NAME, 5000);
|
| - |
|
110 |
|
| 82 |
detailsHeaderRow.createCell(3).setCellValue("Shipping City");
|
111 |
detailsHeaderRow.createCell(COL_CUTOMER_PHONE).setCellValue("Customer Phone");
|
| - |
|
112 |
|
| 83 |
detailsHeaderRow.createCell(4).setCellValue("Shipping State");
|
113 |
detailsHeaderRow.createCell(COL_SHIPPING_LOCATION).setCellValue("Shipping Location");
|
| - |
|
114 |
detailedSheet.setColumnWidth(COL_SHIPPING_LOCATION, 5000);
|
| - |
|
115 |
|
| 84 |
detailsHeaderRow.createCell(5).setCellValue("Product Group");
|
116 |
detailsHeaderRow.createCell(COL_PRODUCT_GROUP).setCellValue("Product Group");
|
| - |
|
117 |
|
| 85 |
detailsHeaderRow.createCell(6).setCellValue("Brand");
|
118 |
detailsHeaderRow.createCell(COL_MODEL).setCellValue("Brand / Model");
|
| - |
|
119 |
detailedSheet.setColumnWidth(COL_MODEL, 5000);
|
| - |
|
120 |
|
| 86 |
detailsHeaderRow.createCell(7).setCellValue("Model");
|
121 |
detailsHeaderRow.createCell(COL_COLOUR).setCellValue("Colour");
|
| 87 |
detailsHeaderRow.createCell(8).setCellValue("Colour");
|
122 |
detailsHeaderRow.createCell(COL_QTY).setCellValue("QTY.");
|
| - |
|
123 |
detailsHeaderRow.getCell(COL_QTY).setCellStyle(csRA);
|
| 88 |
detailsHeaderRow.createCell(9).setCellValue("QTY.");
|
124 |
detailsHeaderRow.createCell(COL_PRICE).setCellValue("Price");
|
| - |
|
125 |
detailsHeaderRow.getCell(COL_PRICE).setCellStyle(csRA);
|
| - |
|
126 |
|
| 89 |
|
127 |
|
| 90 |
Row summaryHeaderRow = summarySheet.createRow((short)0);
|
128 |
Row summaryHeaderRow = summarySheet.createRow((short)0);
|
| 91 |
summaryHeaderRow.createCell(0).setCellValue("Sl No.");
|
129 |
summaryHeaderRow.createCell(COL_SUMMARY_SNO).setCellValue("Sl No.");
|
| 92 |
summaryHeaderRow.createCell(1).setCellValue("Product");
|
130 |
summaryHeaderRow.createCell(COL_SUMMARY_PRODUCT).setCellValue("Product");
|
| 93 |
summaryHeaderRow.createCell(2).setCellValue("Quantity");
|
131 |
summaryHeaderRow.createCell(COL_SUMMARY_QTY).setCellValue("Quantity");
|
| 94 |
|
132 |
|
| 95 |
short rowNum = 5;
|
133 |
short rowNum = 5;
|
| - |
|
134 |
String customerName, shippingLocation, brandModel;
|
| - |
|
135 |
float rowHeight = detailedSheet.getDefaultRowHeightInPoints();
|
| 96 |
for(int i = 0; i<orders.size(); i++){
|
136 |
for(int i = 0; i<orders.size(); i++){
|
| 97 |
Order order = orders.get(i);
|
137 |
Order order = orders.get(i);
|
| 98 |
rowNum++;
|
138 |
rowNum++;
|
| 99 |
Row contentRow = detailedSheet.createRow(rowNum);
|
139 |
Row contentRow = detailedSheet.createRow(rowNum);
|
| 100 |
contentRow.createCell(0).setCellValue(order.getSerialNo());
|
140 |
contentRow.createCell(COL_SNO).setCellValue(order.getSerialNo() + "");
|
| 101 |
contentRow.createCell(1).setCellValue(order.getId());
|
141 |
contentRow.createCell(COL_ORDER_ID).setCellValue(order.getId() + "");
|
| - |
|
142 |
|
| 102 |
contentRow.createCell(2).setCellValue(getValueForEmptyString(order.getCustomer_name()));
|
143 |
customerName = getValueForEmptyString(order.getCustomer_name());
|
| 103 |
contentRow.createCell(3).setCellValue(getValueForEmptyString(order.getCustomer_city()));
|
144 |
contentRow.createCell(COL_CUSTOMER_NAME).setCellValue(customerName);
|
| - |
|
145 |
contentRow.getCell(COL_CUSTOMER_NAME).setCellStyle(csWT);
|
| - |
|
146 |
|
| 104 |
contentRow.createCell(4).setCellValue(getValueForEmptyString(order.getCustomer_state()));
|
147 |
contentRow.createCell(COL_CUTOMER_PHONE).setCellValue(getValueForEmptyString(order.getCustomer_mobilenumber()));
|
| 105 |
|
148 |
|
| - |
|
149 |
shippingLocation = getValueForEmptyString(order.getCustomer_city()) + " (" +
|
| - |
|
150 |
getValueForEmptyString(order.getCustomer_state()) + ")";
|
| - |
|
151 |
contentRow.createCell(COL_SHIPPING_LOCATION).setCellValue(shippingLocation);
|
| - |
|
152 |
contentRow.getCell(COL_SHIPPING_LOCATION).setCellStyle(csWT);
|
| - |
|
153 |
|
| 106 |
List<LineItem> lineItems = order.getLineitems();
|
154 |
List<LineItem> lineItems = order.getLineitems();
|
| 107 |
LineItem lineItem = lineItems.get(0);
|
155 |
LineItem lineItem = lineItems.get(0);
|
| 108 |
contentRow.createCell(5).setCellValue(getValueForEmptyString(lineItem.getProductGroup()));
|
156 |
contentRow.createCell(COL_PRODUCT_GROUP).setCellValue(getValueForEmptyString(lineItem.getProductGroup()));
|
| - |
|
157 |
|
| 109 |
contentRow.createCell(6).setCellValue(getValueForEmptyString(lineItem.getBrand()));
|
158 |
brandModel = getValueForEmptyString(lineItem.getBrand()) + " / " +
|
| 110 |
contentRow.createCell(7).setCellValue(lineItem.getModel_number() + " " + getValueForEmptyString(lineItem.getModel_name()));
|
159 |
lineItem.getModel_number() + " " + getValueForEmptyString(lineItem.getModel_name());
|
| - |
|
160 |
contentRow.createCell(COL_MODEL).setCellValue(brandModel);
|
| - |
|
161 |
contentRow.getCell(COL_MODEL).setCellStyle(csWT);
|
| - |
|
162 |
|
| 111 |
contentRow.createCell(8).setCellValue(lineItem.getColor());
|
163 |
contentRow.createCell(COL_COLOUR).setCellValue(lineItem.getColor());
|
| 112 |
contentRow.createCell(9).setCellValue(lineItem.getQuantity());
|
164 |
contentRow.createCell(COL_QTY).setCellValue(lineItem.getQuantity());
|
| - |
|
165 |
contentRow.createCell(COL_PRICE).setCellValue(lineItem.getTotal_price());
|
| - |
|
166 |
contentRow.getCell(COL_PRICE).setCellStyle(weightStyle);
|
| - |
|
167 |
|
| - |
|
168 |
int maxLength = Math.max(brandModel.length(), Math.max(customerName.length(), shippingLocation.length()));
|
| - |
|
169 |
contentRow.setHeightInPoints((maxLength / (5000/256) + 1) * rowHeight); // Set Row Height
|
| 113 |
|
170 |
|
| 114 |
//Add this item to the summary map to print the summary sheet
|
171 |
//Add this item to the summary map to print the summary sheet
|
| 115 |
String itemKey = lineItem.getProductGroup() + " " +
|
172 |
String itemKey = lineItem.getProductGroup() + " " +
|
| 116 |
lineItem.getBrand() + " " +
|
173 |
lineItem.getBrand() + " " +
|
| 117 |
lineItem.getModel_number() + " " +
|
174 |
lineItem.getModel_number() + " " +
|
| Line 124... |
Line 181... |
| 124 |
quantity = lineItem.getQuantity();
|
181 |
quantity = lineItem.getQuantity();
|
| 125 |
}
|
182 |
}
|
| 126 |
summaryMap.put(itemKey, quantity);
|
183 |
summaryMap.put(itemKey, quantity);
|
| 127 |
}
|
184 |
}
|
| 128 |
|
185 |
|
| - |
|
186 |
detailedSheet.autoSizeColumn(COL_SNO);
|
| - |
|
187 |
detailedSheet.autoSizeColumn(COL_ORDER_ID);
|
| - |
|
188 |
detailedSheet.autoSizeColumn(COL_CUTOMER_PHONE);
|
| - |
|
189 |
detailedSheet.autoSizeColumn(COL_PRODUCT_GROUP);
|
| - |
|
190 |
detailedSheet.autoSizeColumn(COL_COLOUR);
|
| - |
|
191 |
detailedSheet.autoSizeColumn(COL_QTY);
|
| - |
|
192 |
detailedSheet.autoSizeColumn(COL_PRICE);
|
| - |
|
193 |
|
| - |
|
194 |
|
| 129 |
rowNum = 1;
|
195 |
rowNum = 1;
|
| 130 |
for(Entry<String, Double> entry : summaryMap.entrySet()){
|
196 |
for(Entry<String, Double> entry : summaryMap.entrySet()){
|
| 131 |
Row summaryRow = summarySheet.createRow(rowNum);
|
197 |
Row summaryRow = summarySheet.createRow(rowNum);
|
| 132 |
summaryRow.createCell(0).setCellValue(rowNum);
|
198 |
summaryRow.createCell(COL_SUMMARY_SNO).setCellValue(rowNum);
|
| 133 |
summaryRow.createCell(1).setCellValue(entry.getKey());
|
199 |
summaryRow.createCell(COL_SUMMARY_PRODUCT).setCellValue(entry.getKey());
|
| 134 |
summaryRow.createCell(2).setCellValue(entry.getValue());
|
200 |
summaryRow.createCell(COL_SUMMARY_QTY).setCellValue(entry.getValue());
|
| 135 |
rowNum++;
|
201 |
rowNum++;
|
| 136 |
}
|
202 |
}
|
| 137 |
|
203 |
|
| - |
|
204 |
summarySheet.autoSizeColumn(COL_SUMMARY_PRODUCT);
|
| 138 |
// Write the workbook to the output stream
|
205 |
// Write the workbook to the output stream
|
| 139 |
try {
|
206 |
try {
|
| 140 |
wb.write(baosXLS);
|
207 |
wb.write(baosXLS);
|
| 141 |
baosXLS.close();
|
208 |
baosXLS.close();
|
| 142 |
} catch (IOException e) {
|
209 |
} catch (IOException e) {
|
| Line 153... |
Line 220... |
| 153 |
}
|
220 |
}
|
| 154 |
|
221 |
|
| 155 |
public static void main(String[] args) {
|
222 |
public static void main(String[] args) {
|
| 156 |
PendingOrdersGenerator pendingOrdersGenerator = new PendingOrdersGenerator();
|
223 |
PendingOrdersGenerator pendingOrdersGenerator = new PendingOrdersGenerator();
|
| 157 |
try {
|
224 |
try {
|
| - |
|
225 |
String userHome = System.getProperty("user.home");
|
| 158 |
FileOutputStream f = new FileOutputStream("/home/ashish/Downloads/pending-orders.xls");
|
226 |
FileOutputStream f = new FileOutputStream(userHome + "/pending-orders.xls");
|
| 159 |
ByteArrayOutputStream baosXLS = pendingOrdersGenerator.generatePendingOrdersDetails(1);
|
227 |
ByteArrayOutputStream baosXLS = pendingOrdersGenerator.generatePendingOrdersDetails(1);
|
| 160 |
baosXLS.writeTo(f);
|
228 |
baosXLS.writeTo(f);
|
| 161 |
f.close();
|
229 |
f.close();
|
| 162 |
} catch (FileNotFoundException e) {
|
230 |
} catch (FileNotFoundException e) {
|
| 163 |
e.printStackTrace();
|
231 |
e.printStackTrace();
|