| Line 6... |
Line 6... |
| 6 |
import java.io.FileOutputStream;
|
6 |
import java.io.FileOutputStream;
|
| 7 |
import java.io.IOException;
|
7 |
import java.io.IOException;
|
| 8 |
import java.util.ArrayList;
|
8 |
import java.util.ArrayList;
|
| 9 |
import java.util.Calendar;
|
9 |
import java.util.Calendar;
|
| 10 |
import java.util.GregorianCalendar;
|
10 |
import java.util.GregorianCalendar;
|
| - |
|
11 |
import java.util.HashMap;
|
| - |
|
12 |
import java.util.LinkedHashMap;
|
| 11 |
import java.util.List;
|
13 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
14 |
import java.util.Map;
|
| - |
|
15 |
import java.util.Map.Entry;
|
| 13 |
|
16 |
|
| 14 |
import in.shop2020.logistics.DeliveryType;
|
17 |
import in.shop2020.logistics.DeliveryType;
|
| 15 |
import in.shop2020.logistics.LogisticsService.Client;
|
18 |
import in.shop2020.logistics.LogisticsService.Client;
|
| 16 |
import in.shop2020.logistics.LogisticsServiceException;
|
19 |
import in.shop2020.logistics.LogisticsServiceException;
|
| 17 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
20 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
| Line 20... |
Line 23... |
| 20 |
import in.shop2020.model.v1.catalog.status;
|
23 |
import in.shop2020.model.v1.catalog.status;
|
| 21 |
import in.shop2020.support.utils.FileUtils;
|
24 |
import in.shop2020.support.utils.FileUtils;
|
| 22 |
import in.shop2020.support.utils.ReportsUtils;
|
25 |
import in.shop2020.support.utils.ReportsUtils;
|
| 23 |
import in.shop2020.thrift.clients.CatalogClient;
|
26 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 24 |
import in.shop2020.thrift.clients.LogisticsClient;
|
27 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| - |
|
28 |
import in.shop2020.utils.CategoryManager;
|
| 25 |
|
29 |
|
| 26 |
import javax.servlet.ServletContext;
|
30 |
import javax.servlet.ServletContext;
|
| 27 |
import javax.servlet.ServletOutputStream;
|
31 |
import javax.servlet.ServletOutputStream;
|
| 28 |
import javax.servlet.http.HttpServletRequest;
|
32 |
import javax.servlet.http.HttpServletRequest;
|
| 29 |
import javax.servlet.http.HttpServletResponse;
|
33 |
import javax.servlet.http.HttpServletResponse;
|
| Line 137... |
Line 141... |
| 137 |
}
|
141 |
}
|
| 138 |
return "index";
|
142 |
return "index";
|
| 139 |
}
|
143 |
}
|
| 140 |
|
144 |
|
| 141 |
private ByteArrayOutputStream generateInventoryStockReport(){
|
145 |
private ByteArrayOutputStream generateInventoryStockReport(){
|
| 142 |
List<RowItem> outOfStockItems = new ArrayList<RowItem>();
|
146 |
Map<String, Map<String, List<RowItem>>> categoryWiseStock = new LinkedHashMap<String, Map<String, List<RowItem>>>();
|
| 143 |
List<RowItem> itemsDeliverableNextDay = new ArrayList<RowItem>();
|
147 |
String nextDay = "Deliverable on Next Day";
|
| 144 |
List<RowItem> itemsNotDeliverableNextDay = new ArrayList<RowItem>();
|
148 |
String notNextDay = "Not Deliverable on Next Day";
|
| 145 |
|
149 |
String notAvailable = "Out of Stock";
|
| 146 |
LogisticsClient logisticsServiceClient;
|
150 |
LogisticsClient logisticsServiceClient;
|
| 147 |
CatalogClient catalogClientService;
|
151 |
CatalogClient catalogClientService;
|
| 148 |
try {
|
152 |
try {
|
| 149 |
catalogClientService = new CatalogClient();
|
153 |
catalogClientService = new CatalogClient();
|
| 150 |
logisticsServiceClient = new LogisticsClient();
|
154 |
logisticsServiceClient = new LogisticsClient();
|
| 151 |
in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
|
155 |
in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
|
| 152 |
List<Item> items = client.getAllItems(false);
|
156 |
List<Item> items = client.getAllItems(false);
|
| 153 |
Client logisticsClient = logisticsServiceClient.getClient();
|
157 |
Client logisticsClient = logisticsServiceClient.getClient();
|
| 154 |
|
158 |
|
| - |
|
159 |
CategoryManager catm = CategoryManager.getCategoryManager();
|
| 155 |
for(Item item : items){
|
160 |
for(Item item : items){
|
| 156 |
if(!"Handsets".equals(item.getProductGroup()))
|
- |
|
| 157 |
continue;
|
- |
|
| 158 |
status state = item.getItemStatus();
|
161 |
status state = item.getItemStatus();
|
| 159 |
switch(state){
|
162 |
switch(state){
|
| 160 |
case IN_PROCESS:
|
163 |
case IN_PROCESS:
|
| 161 |
case CONTENT_COMPLETE:
|
164 |
case CONTENT_COMPLETE:
|
| 162 |
case DELETED:
|
165 |
case DELETED:
|
| 163 |
case PHASED_OUT:
|
166 |
case PHASED_OUT:
|
| 164 |
continue;
|
167 |
continue;
|
| 165 |
case PAUSED:
|
168 |
case PAUSED:
|
| 166 |
case PAUSED_BY_RISK:
|
169 |
case PAUSED_BY_RISK:
|
| 167 |
case ACTIVE:
|
170 |
case ACTIVE:
|
| - |
|
171 |
if(item.getCategory() == -1 || item.getCategory() == 0){
|
| - |
|
172 |
continue;
|
| - |
|
173 |
}
|
| - |
|
174 |
String category = catm.getCategory(catm.getCategory(item.getCategory()).getParent_category_id()).getLabel();
|
| - |
|
175 |
|
| - |
|
176 |
Map<String, List<RowItem>> sheetsMap = categoryWiseStock.get(category);
|
| - |
|
177 |
if(sheetsMap == null){
|
| - |
|
178 |
sheetsMap = new HashMap<String, List<RowItem>>();
|
| - |
|
179 |
categoryWiseStock.put(category, sheetsMap);
|
| - |
|
180 |
sheetsMap.put(nextDay, new ArrayList<RowItem>());
|
| - |
|
181 |
sheetsMap.put(notNextDay, new ArrayList<RowItem>());
|
| - |
|
182 |
sheetsMap.put(notAvailable, new ArrayList<RowItem>());
|
| - |
|
183 |
}
|
| - |
|
184 |
|
| - |
|
185 |
|
| 168 |
long deliveryDays = 3;
|
186 |
long deliveryDays = 3;
|
| 169 |
try{
|
187 |
try{
|
| - |
|
188 |
|
| 170 |
deliveryDays = logisticsClient.getLogisticsEstimation(item.getId(), DEFAULT_PINCODE, DeliveryType.PREPAID).getDeliveryTime();
|
189 |
deliveryDays = logisticsClient.getLogisticsEstimation(item.getId(), DEFAULT_PINCODE, DeliveryType.PREPAID).getDeliveryTime();
|
| 171 |
}catch (LogisticsServiceException e) {
|
190 |
}catch (LogisticsServiceException e) {
|
| 172 |
logger.error("Error while getting estimate of the inventory for item " + item.getId(), e);
|
191 |
logger.error("Error while getting estimate of the inventory for item " + item.getId(), e);
|
| 173 |
}
|
192 |
}
|
| 174 |
RowItem rowItem = new RowItem(item, deliveryDays);
|
193 |
RowItem rowItem = new RowItem(item, deliveryDays);
|
| 175 |
if(state == status.ACTIVE){
|
194 |
if(state == status.ACTIVE){
|
| 176 |
if(deliveryDays == NEXT_DAY_DELAY)
|
195 |
if(deliveryDays == NEXT_DAY_DELAY)
|
| 177 |
itemsDeliverableNextDay.add(rowItem);
|
196 |
sheetsMap.get(nextDay).add(rowItem);
|
| 178 |
else
|
197 |
else
|
| 179 |
itemsNotDeliverableNextDay.add(rowItem);
|
198 |
sheetsMap.get(notNextDay).add(rowItem);
|
| 180 |
}else
|
199 |
}else
|
| 181 |
outOfStockItems.add(rowItem);
|
200 |
sheetsMap.get(notAvailable).add(rowItem);
|
| 182 |
}
|
201 |
}
|
| 183 |
}
|
202 |
}
|
| 184 |
} catch (TTransportException e) {
|
203 |
} catch (TTransportException e) {
|
| 185 |
logger.error("Unable to get the items from the inventory", e);
|
204 |
logger.error("Unable to get the items from the inventory", e);
|
| 186 |
return null;
|
205 |
return null;
|
| Line 194... |
Line 213... |
| 194 |
|
213 |
|
| 195 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
214 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| 196 |
|
215 |
|
| 197 |
Workbook wb = new HSSFWorkbook();
|
216 |
Workbook wb = new HSSFWorkbook();
|
| 198 |
|
217 |
|
| - |
|
218 |
// for(String category: categoryWiseStock.keySet()){
|
| - |
|
219 |
// Map<String, List<RowItem>> value = categoryWiseStock.get(category);
|
| 199 |
createSheet(wb, "Items Deliverable on Next Day", itemsDeliverableNextDay);
|
220 |
// createSheet(wb, category + " - " + nextDay, value.get(nextDay));
|
| 200 |
createSheet(wb, "Items Not Deliverable on Next Day", itemsNotDeliverableNextDay);
|
221 |
// createSheet(wb, category + " - " + notNextDay, value.get(notNextDay));
|
| - |
|
222 |
// createSheet(wb, category + " - " + notAvailable, value.get(notAvailable));
|
| - |
|
223 |
// }
|
| - |
|
224 |
|
| - |
|
225 |
//Hardcoding to maintain category
|
| - |
|
226 |
List<String> categories = new ArrayList<String>();
|
| - |
|
227 |
categories.add("Mobile Phones");
|
| - |
|
228 |
categories.add("Tablets");
|
| - |
|
229 |
categories.add("Mobile Accessories");
|
| - |
|
230 |
categories.add("Laptops");
|
| - |
|
231 |
categories.add("Laptop Accessories");
|
| - |
|
232 |
for(String category: categories){
|
| - |
|
233 |
Map<String, List<RowItem>> value = categoryWiseStock.get(category);
|
| 201 |
createSheet(wb, "Out of Stock Items", outOfStockItems);
|
234 |
createSheet(wb, category + " - " + nextDay, value.get(nextDay));
|
| - |
|
235 |
createSheet(wb, category + " - " + notNextDay, value.get(notNextDay));
|
| - |
|
236 |
createSheet(wb, category + " - " + notAvailable, value.get(notAvailable));
|
| - |
|
237 |
}
|
| - |
|
238 |
|
| 202 |
|
239 |
|
| 203 |
try {
|
240 |
try {
|
| 204 |
wb.write(baosXLS);
|
241 |
wb.write(baosXLS);
|
| 205 |
baosXLS.close();
|
242 |
baosXLS.close();
|
| 206 |
} catch (IOException e) {
|
243 |
} catch (IOException e) {
|