Subversion Repositories SmartDukaan

Rev

Rev 13608 | Rev 13626 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13584 manish.sha 1
package in.shop2020.serving.services;
2
 
3
import java.io.BufferedWriter;
4
import java.io.FileNotFoundException;
5
import java.io.FileOutputStream;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.util.ArrayList;
9
import java.util.Collections;
10
import java.util.HashMap;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Map.Entry;
14
 
15
import javax.mail.MessagingException;
16
 
17
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
18
import org.apache.poi.hssf.usermodel.HSSFFont;
19
import org.apache.poi.hssf.usermodel.HSSFRow;
20
import org.apache.poi.hssf.usermodel.HSSFSheet;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
import org.apache.poi.hssf.util.HSSFColor;
23
import org.apache.thrift.TException;
24
 
25
import in.shop2020.model.v1.catalog.CatalogServiceException;
26
import in.shop2020.model.v1.catalog.Category;
27
import in.shop2020.model.v1.catalog.Item;
28
import in.shop2020.model.v1.order.FlipkartFaSalesSnapshot;
29
import in.shop2020.thrift.clients.CatalogClient;
30
import in.shop2020.utils.EmailUtils;
31
import in.shop2020.utils.FASalesSnapshot;
32
import in.shop2020.utils.FkExcelRow;
33
import in.shop2020.utils.FkSaleComparator;
34
import in.shop2020.utils.FkStockEstValueComparator;
35
import in.shop2020.utils.FlipkartConsumer;
36
import in.shop2020.utils.GmailUtils;
37
 
38
public class CreateSendFAStockEstReportMT{
39
 
40
	private static final String FLIPKART_FBA_SHEET = "/tmp/Mobiles-Tablets-FA-Stock-Estimation.xls";
41
	private static final String FLIPKART_FBA_SHEET_BODY = "/tmp/Mobiles-Tablets-FA-Stock-Estimation-body.html";
42
 
43
	public static void main(String[] args) throws IOException, MessagingException {
44
		CatalogClient catalogServiceClient = null;
45
        try {
46
            catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
47
        	//catalogServiceClient = new CatalogClient();
48
        } catch (Exception e) {
49
            e.printStackTrace();
50
        }
51
 
52
        in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
53
 
54
	    Map<Long, Long> currentFaInventoryMap = FlipkartConsumer.getCurrentFAInventory();
55
	    Map<Long,Double> currentFAInventorySellingPriceMap = FlipkartConsumer.getCurrentFAInventorySellingPrice();
56
	    List<FlipkartFaSalesSnapshot> salessnapshots = FlipkartConsumer.getFlipkartFbaSalesSnapshotForDays(4);
57
	    Map<Long, Map<Long,FASalesSnapshot>> itemId5daysSale = new HashMap<Long, Map<Long,FASalesSnapshot>>();
58
	    boolean skip = false;
59
	    for(FlipkartFaSalesSnapshot salessnapshot : salessnapshots) {
60
	    	try {
61
                if(itemId5daysSale.containsKey(salessnapshot.getItem_id())) {
62
                	for (Entry<Long, FASalesSnapshot> saleentry : itemId5daysSale.get(salessnapshot.getItem_id()).entrySet()) {
63
                		if(saleentry.getValue().getDateOfSale().longValue() == salessnapshot.getDateOfSale()) {
64
                			if(!salessnapshot.isIsOutOfStock()){
65
                				if(saleentry.getValue().getTotalOrderCount()==-1){
66
                                    saleentry.getValue().setTotalOrderCount(salessnapshot.getTotalOrderCount());
67
                                    saleentry.getValue().setTotalSale((float) (salessnapshot.getTotalSale()));
68
 
69
                                }
70
                                else{
71
                                    saleentry.getValue().setTotalOrderCount(saleentry.getValue().getTotalOrderCount()+ salessnapshot.getTotalOrderCount());
72
                                    saleentry.getValue().setTotalSale((float) (saleentry.getValue().getTotalSale() + salessnapshot.getTotalSale()));
73
                                }
74
                                itemId5daysSale.get(salessnapshot.getItem_id()).put(saleentry.getValue().getDateOfSale(),saleentry.getValue());
75
                			}
76
                			skip = true;
77
                            break;
78
                		}
79
                	}
80
                	if(!skip){
81
                		FASalesSnapshot faSalesSnapshot = new FASalesSnapshot();
82
                		if(!salessnapshot.isIsOutOfStock()) {
83
	                        faSalesSnapshot.setTotalOrderCount(salessnapshot.getTotalOrderCount());
84
	                        faSalesSnapshot.setTotalSale((float) salessnapshot.getTotalSale());
85
	                        faSalesSnapshot.setDateOfSale(salessnapshot.getDateOfSale());
86
	                    }else {
87
	                    	faSalesSnapshot.setTotalOrderCount(-1);
88
	                    	faSalesSnapshot.setTotalSale((float) 0);
89
	                    	faSalesSnapshot.setDateOfSale(salessnapshot.getDateOfSale());
90
                        }
91
                		itemId5daysSale.get(salessnapshot.getItem_id()).put(faSalesSnapshot.getDateOfSale(),faSalesSnapshot);
92
                	}
93
                	skip=false;
94
                }
95
                else{
96
                	Map<Long,FASalesSnapshot> last5daysSale = new HashMap<Long,FASalesSnapshot>();
97
                	FASalesSnapshot faSalesSnapshot = new FASalesSnapshot();
98
                    if (!salessnapshot.isIsOutOfStock()) {
99
                    	faSalesSnapshot.setTotalOrderCount(salessnapshot.getTotalOrderCount());
100
                    	faSalesSnapshot.setTotalSale((float) salessnapshot.getTotalSale());
101
                    	faSalesSnapshot.setDateOfSale(salessnapshot.getDateOfSale());
102
                    } 
103
                    else {
104
                    	faSalesSnapshot.setTotalOrderCount(-1);
105
                    	faSalesSnapshot.setTotalSale((float) 0);
106
                    	faSalesSnapshot.setDateOfSale(salessnapshot.getDateOfSale());
107
                    }
108
                    last5daysSale.put(faSalesSnapshot.getDateOfSale(),faSalesSnapshot);
109
                    itemId5daysSale.put(salessnapshot.getItem_id(),last5daysSale);
110
                }
111
	    	} catch (Exception e) {
112
                e.printStackTrace();
113
            }
114
	    }
115
 
116
	    HSSFWorkbook hwb = new HSSFWorkbook();
117
        HSSFSheet sheet1 = hwb.createSheet("MOVING");
118
        HSSFSheet sheet2 = hwb.createSheet("SLOW-MOVING");
119
        HSSFSheet sheet3 = hwb.createSheet("NOT-MOVING");
120
 
121
        int i=0;
122
        HSSFRow rowhead1 = sheet1.createRow((short) 0);
123
        HSSFRow rowhead2 = sheet2.createRow((short) 0);
124
        HSSFRow rowhead3 = sheet3.createRow((short) 0);
125
 
126
        rowhead1.createCell(i).setCellValue("ITEM-ID");
127
        rowhead1.createCell(++i).setCellValue("BRAND");
128
        rowhead1.createCell(++i).setCellValue("CATEGORY");
129
        rowhead1.createCell(++i).setCellValue("PRODUCT-GROUP");
130
        rowhead1.createCell(++i).setCellValue("PRODUCT-NAME");
131
        rowhead1.createCell(++i).setCellValue("SALES-HISTORY");
132
        rowhead1.createCell(++i).setCellValue("AVG-SALE");
133
        rowhead1.createCell(++i).setCellValue("STOCK-QUANTITY");
134
        rowhead1.createCell(++i).setCellValue("SELLING-PRICE");
135
        rowhead1.createCell(++i).setCellValue("STOCK-VALUE");
136
        rowhead1.createCell(++i).setCellValue("NOD-STOCK");
137
        rowhead1.createCell(++i).setCellValue("MOVEMENT-CATEGORY");
138
 
13590 manish.sha 139
        i=0;
140
 
13584 manish.sha 141
        rowhead2.createCell(i).setCellValue("ITEM-ID");
142
        rowhead2.createCell(++i).setCellValue("BRAND");
143
        rowhead2.createCell(++i).setCellValue("CATEGORY");
144
        rowhead2.createCell(++i).setCellValue("PRODUCT-GROUP");
145
        rowhead2.createCell(++i).setCellValue("PRODUCT-NAME");
146
        rowhead2.createCell(++i).setCellValue("SALES-HISTORY");
147
        rowhead2.createCell(++i).setCellValue("AVG-SALE");
148
        rowhead2.createCell(++i).setCellValue("STOCK-QUANTITY");
149
        rowhead2.createCell(++i).setCellValue("SELLING-PRICE");        
150
        rowhead2.createCell(++i).setCellValue("STOCK-VALUE");
151
        rowhead2.createCell(++i).setCellValue("NOD-STOCK");
152
        rowhead2.createCell(++i).setCellValue("MOVEMENT-CATEGORY");
153
 
13590 manish.sha 154
        i=0;
155
 
13584 manish.sha 156
        rowhead3.createCell(i).setCellValue("ITEM-ID");
157
        rowhead3.createCell(++i).setCellValue("BRAND");
158
        rowhead3.createCell(++i).setCellValue("CATEGORY");
159
        rowhead3.createCell(++i).setCellValue("PRODUCT-GROUP");
160
        rowhead3.createCell(++i).setCellValue("PRODUCT-NAME");
161
        rowhead3.createCell(++i).setCellValue("SALES-HISTORY");
162
        rowhead3.createCell(++i).setCellValue("AVG-SALE");
163
        rowhead3.createCell(++i).setCellValue("STOCK-QUANTITY");
164
        rowhead3.createCell(++i).setCellValue("SELLING-PRICE");
165
        rowhead3.createCell(++i).setCellValue("STOCK-VALUE");
166
        rowhead3.createCell(++i).setCellValue("NOD-STOCK");
167
        rowhead3.createCell(++i).setCellValue("MOVEMENT-CATEGORY");
168
 
169
        List<FkExcelRow> Moving_List = new ArrayList<FkExcelRow>();
170
        List<FkExcelRow> Replenishment_Items = new ArrayList<FkExcelRow>();
171
        List<FkExcelRow> Slow_Moving_Items = new ArrayList<FkExcelRow>();
172
        List<FkExcelRow> Not_Moving_Item_List = new ArrayList<FkExcelRow>();
173
 
174
 
175
        for (Entry<Long, Map<Long, FASalesSnapshot>> entry : itemId5daysSale.entrySet()) {
176
        	Item item = null;
177
        	Category category = null;
178
        	try {
179
                //System.out.println("Item ID is " + entry.getKey());
180
                item = catalogClient.getItem(entry.getKey());
181
                if (item.getId() == 0) {
182
                    continue;
183
                }
184
                if (item.getProductGroup().equalsIgnoreCase("Mobile Phone") || item.getProductGroup().equalsIgnoreCase("Handsets") || item.getProductGroup().equalsIgnoreCase("Tablets") ||
185
                        item.getProductGroup().equalsIgnoreCase("Compact Cameras") || 
186
                        item.getProductGroup().equalsIgnoreCase("DSLR Cameras")  || 
187
                        item.getProductGroup().equalsIgnoreCase("Cameras") || 
188
                        item.getProductGroup().equalsIgnoreCase("Digital Camera") ||
189
                        item.getProductGroup().equalsIgnoreCase("Lenses")) {
190
                }
191
                else {
192
                    continue;
193
                }
194
                if (item.isSetCategory() && item.getCategory() != 0) {
195
                    category = catalogClient.getCategory(item.getCategory());
196
                }
197
        	}
198
        	catch (CatalogServiceException e) {
199
                e.printStackTrace();
200
            } catch (TException e) {
201
                e.printStackTrace();
202
            }
203
 
204
            FkExcelRow fkExcelRow = new FkExcelRow();
205
            int count = 1;
206
            Double total_sale = 0.0;
207
            int total_sale_days = 0;
208
            float avg_total_sale = 0;
209
            StringBuilder total_days_sale = new StringBuilder();
210
 
211
            List<FASalesSnapshot> fiveDaySale = new ArrayList<FASalesSnapshot>(entry.getValue().values());
212
            Collections.sort(fiveDaySale, new FkSaleComparator());
13602 manish.sha 213
            long stockQuantity = 0;
214
            if(currentFaInventoryMap.containsKey(entry.getKey())){
215
            	stockQuantity = currentFaInventoryMap.get(entry.getKey());
216
            }else{
217
            	stockQuantity = 0;
218
            }
13584 manish.sha 219
 
220
            for(FASalesSnapshot sale : fiveDaySale) {
221
 
222
            	if (sale.getTotalOrderCount() != -1) {
223
                    total_days_sale.append(sale.getTotalOrderCount());
224
                    avg_total_sale = avg_total_sale + sale.getTotalOrderCount();
225
                    total_sale = total_sale + sale.getTotalSale();
226
                    total_sale_days++;
13624 manish.sha 227
                } else if(stockQuantity>0 && sale.getTotalOrderCount()==0){
228
                    total_days_sale.append("0");
229
                    total_sale_days++;
13584 manish.sha 230
                } else {
13624 manish.sha 231
                	total_days_sale.append("X");
13584 manish.sha 232
                }
233
                if (count != entry.getValue().size()) {
234
                    total_days_sale.append("-");
235
                }
236
                count++;
237
            }
238
            if(entry.getValue().size()<5){
239
	            while(count<=5){
240
	            	total_days_sale.append("-");
13602 manish.sha 241
	            	if(stockQuantity>0){
242
	            		total_days_sale.append("0");
243
	            		total_sale_days++;
244
	            	} else {
245
	            		total_days_sale.append("X");
246
	            	}
13584 manish.sha 247
	            	count++;
248
	            }
249
            }
250
 
251
 
252
            float total_sale_avg = 0;
253
            if (total_sale_days != 0) {
254
                total_sale_avg = avg_total_sale / total_sale_days;
255
            }
256
            fkExcelRow.setItem_id(entry.getKey());
257
 
258
            float days_of_stock = 0;
13602 manish.sha 259
 
13584 manish.sha 260
            double sellingPrice = 0.0;//
261
            if(currentFAInventorySellingPriceMap.containsKey(entry.getKey())){
262
            	sellingPrice = currentFAInventorySellingPriceMap.get(entry.getKey());
263
            }else{
264
            	sellingPrice = total_sale/avg_total_sale;
265
            }
266
            double stockValue = stockQuantity*sellingPrice;
267
            if(total_sale_avg>0){
268
            	days_of_stock = (stockQuantity/total_sale_avg);
269
            }
270
 
271
            fkExcelRow.setBrand(item.getBrand());
272
            fkExcelRow.setProductGroup(item.getProductGroup());
273
            fkExcelRow.setCategory(category.getLabel());
274
            fkExcelRow.setProductName(item.getModelName()+" "+item.getModelNumber()+" "+item.getColor());
275
            fkExcelRow.setSalesHistory(total_days_sale.toString());
276
            fkExcelRow.setAvgSale(total_sale_avg);
277
        	fkExcelRow.setStockQuantity(stockQuantity);
278
        	fkExcelRow.setSellingPrice(sellingPrice);
279
        	fkExcelRow.setStockValue(stockValue);
280
        	fkExcelRow.setNodStock(days_of_stock);
281
 
282
        	if (total_sale_avg > 0) {
13606 manish.sha 283
	        	if(days_of_stock<=20){
13584 manish.sha 284
	        		fkExcelRow.setMovementCategory("MOVING");
285
	        		Moving_List.add(fkExcelRow);
13624 manish.sha 286
	        		if(days_of_stock<=5){
287
	        			Replenishment_Items.add(fkExcelRow);
288
	        		}
13584 manish.sha 289
	        	}
290
	        	if(days_of_stock>20){
291
	        		fkExcelRow.setMovementCategory("SLOW-MOVING");
292
	        		Slow_Moving_Items.add(fkExcelRow);
293
	        	}
294
        	}else{
295
        		if(total_sale_avg == 0 && stockQuantity>0){
296
	        		fkExcelRow.setMovementCategory("NON-MOVING");
297
	        		Not_Moving_Item_List.add(fkExcelRow);
298
        		}
299
        	}
300
 
301
        }
302
 
303
        Collections.sort(Moving_List, new FkStockEstValueComparator());
304
        Collections.sort(Replenishment_Items, new FkStockEstValueComparator());
305
        Collections.sort(Slow_Moving_Items, new FkStockEstValueComparator());
306
        Collections.sort(Not_Moving_Item_List, new FkStockEstValueComparator());
307
 
308
        HSSFRow row = null;
309
        int iterator = 1;
310
        long movingStock = 0;
311
        double movingStockValue = 0;
312
 
313
        for (FkExcelRow excelrow : Moving_List){
314
        	movingStock = movingStock+excelrow.getStockQuantity();
315
        	movingStockValue = movingStockValue+excelrow.getStockValue();
316
        	row = sheet1.createRow((short) iterator);
317
            HSSFCellStyle style = hwb.createCellStyle();
318
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
319
            HSSFFont font = hwb.createFont();
320
            style.setFillForegroundColor(HSSFColor.WHITE.index);
321
            font.setColor(HSSFColor.BLACK.index);
322
            style.setFont(font);
323
            i=0;
324
            row.createCell(i).setCellValue(excelrow.getItem_id());
325
            row.createCell(++i).setCellValue(excelrow.getBrand());
326
            row.createCell(++i).setCellValue(excelrow.getCategory());
327
            row.createCell(++i).setCellValue(excelrow.getProductGroup());
328
            row.createCell(++i).setCellValue(excelrow.getProductName());
329
            row.createCell(++i).setCellValue(excelrow.getSalesHistory());
330
            row.createCell(++i).setCellValue(String.format("%.2f",excelrow.getAvgSale()));
331
            row.createCell(++i).setCellValue(excelrow.getStockQuantity());
332
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getSellingPrice()));
333
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getStockValue()));
334
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getNodStock()));
335
            row.createCell(++i).setCellValue(excelrow.getMovementCategory());
336
            iterator++;
337
        }
338
        iterator = 1;
339
        double not_moving_value = 0;
340
        long not_moving_count = 0;
341
 
342
        for (FkExcelRow excelrow : Not_Moving_Item_List) {
343
        	not_moving_value = not_moving_value + excelrow.getStockValue();
344
            not_moving_count = not_moving_count + excelrow.getStockQuantity();
345
            row = sheet3.createRow((short) iterator);
346
            HSSFCellStyle style = hwb.createCellStyle();
347
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
348
            HSSFFont font = hwb.createFont();
349
            style.setFillForegroundColor(HSSFColor.WHITE.index);
350
            font.setColor(HSSFColor.BLACK.index);
351
            style.setFont(font);
352
            i=0;
353
            row.createCell(i).setCellValue(excelrow.getItem_id());
354
            row.createCell(++i).setCellValue(excelrow.getBrand());
355
            row.createCell(++i).setCellValue(excelrow.getCategory());
356
            row.createCell(++i).setCellValue(excelrow.getProductGroup());
357
            row.createCell(++i).setCellValue(excelrow.getProductName());
358
            row.createCell(++i).setCellValue(excelrow.getSalesHistory());
359
            row.createCell(++i).setCellValue(String.format("%.2f",excelrow.getAvgSale()));
360
            row.createCell(++i).setCellValue(excelrow.getStockQuantity());
361
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getSellingPrice()));
362
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getStockValue()));
363
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getNodStock()));
364
            row.createCell(++i).setCellValue(excelrow.getMovementCategory());
365
            iterator++;
366
        }
367
 
368
        iterator = 1;
369
        double slow_moving_value = 0;
370
        long slow_moving_count = 0;
371
 
372
        for (FkExcelRow excelrow : Slow_Moving_Items) {
373
        	slow_moving_value = slow_moving_value + excelrow.getStockValue();
374
        	slow_moving_count = slow_moving_count + excelrow.getStockQuantity();
375
            row = sheet2.createRow((short) iterator);
376
            HSSFCellStyle style = hwb.createCellStyle();
377
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
378
            HSSFFont font = hwb.createFont();
379
            style.setFillForegroundColor(HSSFColor.WHITE.index);
380
            font.setColor(HSSFColor.BLACK.index);
381
            style.setFont(font);
382
            i=0;
383
            row.createCell(i).setCellValue(excelrow.getItem_id());
384
            row.createCell(++i).setCellValue(excelrow.getBrand());
385
            row.createCell(++i).setCellValue(excelrow.getCategory());
386
            row.createCell(++i).setCellValue(excelrow.getProductGroup());
387
            row.createCell(++i).setCellValue(excelrow.getProductName());
388
            row.createCell(++i).setCellValue(excelrow.getSalesHistory());
389
            row.createCell(++i).setCellValue(String.format("%.2f",excelrow.getAvgSale()));
390
            row.createCell(++i).setCellValue(excelrow.getStockQuantity());
391
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getSellingPrice()));
392
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getStockValue()));
393
            row.createCell(++i).setCellValue(String.format("%.0f",excelrow.getNodStock()));
394
            row.createCell(++i).setCellValue(excelrow.getMovementCategory());
395
            iterator++;
396
        }
397
 
398
        FileOutputStream fileOut = null;
399
        try {
400
            fileOut = new FileOutputStream(FLIPKART_FBA_SHEET);
401
        } catch (FileNotFoundException e) {
402
            e.printStackTrace();
403
        }
404
        try {
405
            hwb.write(fileOut);
406
        } catch (IOException e) {
407
            e.printStackTrace();
408
        }
409
        try {
410
            fileOut.close();
411
        } catch (IOException e) {
412
            e.printStackTrace();
413
        }
414
 
415
        StringBuffer sb = new StringBuffer();
416
        sb.append("<html><table border=\"1\" align=\"center\">"
417
                + "<caption><b>" + "ITEMS TO REPLENISH" + "</b></caption>"
418
                + "<tr>" + "<td><b>" + "ITEM-ID" + "</b></td>" + "<td><b>"
419
                + "BRAND" + "</b></td>" + "<td><b>" + "CATEGORY" + "</b></td>"
420
                + "<td><b>" + "PRODUCT-GROUP" + "</b></td>" + "<td><b>"
421
                + "PRODUCT-NAME" + "</b></td>" + "<td><b>" + "SALES-HISTORY"
422
                + "</b></td>" + "<td><b>" + "AVG-SALE" + "</b></td>"
423
                + "</b></td>" + "<td><b>" + "CURRENT-STOCK" + "</b></td>"
424
                + "<td><b>" + "NO-OF-DAYS-STOCK" + "</b></td>" 
425
                + "<td><b>" + "STOCK-VALUE" + "</b></td>"+ "</tr>");
426
 
427
        int count = 0;
428
        for(FkExcelRow excelRow: Replenishment_Items){
429
        	if (count < 10) {
430
                sb.append("<tr>" + "<td>"+ excelRow.getItem_id() +"</td>"
431
                		+"<td>"+ excelRow.getBrand() +"</td>"
432
                		+"<td>"+ excelRow.getCategory() +"</td>"
433
                		+"<td>"+ excelRow.getProductGroup() +"</td>"
434
                		+"<td>"+ excelRow.getProductName() +"</td>"
435
                		+"<td>"+ excelRow.getSalesHistory() +"</td>"
436
                		+"<td>"+ Math.round(excelRow.getAvgSale() * 100.0) / 100.0 +"</td>"
437
                		+"<td>"+ excelRow.getStockQuantity() +"</td>"
438
                		+"<td>"+ String.format("%.0f",excelRow.getNodStock()) +"</td>"
439
                		+"<td>"+ String.format("%.0f",excelRow.getStockValue()) +"</td></tr>");
440
                count++;
441
        	}else{
442
        		break;
443
        	}
444
        }
445
        sb.append("</table>");
446
        sb.append("<table border=\"1\" align=\"center\">"
447
                + "<caption><b>" + "SLOW-MOVING-ITEMS" + "</b></caption>"
448
                + "<tr>" + "<td><b>" + "ITEM-ID" + "</b></td>" + "<td><b>"
449
                + "BRAND" + "</b></td>" + "<td><b>" + "CATEGORY" + "</b></td>"
450
                + "<td><b>" + "PRODUCT-GROUP" + "</b></td>" + "<td><b>"
451
                + "PRODUCT-NAME" + "</b></td>" + "<td><b>" + "SALES-HISTORY"
452
                + "</b></td>" + "<td><b>" + "AVG-SALE" + "</b></td>"
453
                + "</b></td>" + "<td><b>" + "CURRENT-STOCK" + "</b></td>"
454
                + "<td><b>" + "NO-OF-DAYS-STOCK" + "</b></td>" 
455
                + "<td><b>" + "STOCK-VALUE" + "</b></td>"+ "</tr>");
456
 
457
        count = 0;
458
        for(FkExcelRow excelRow : Slow_Moving_Items){
459
        	if (count < 10) {
460
                sb.append("<tr>" + "<td>"+ excelRow.getItem_id() +"</td>"
461
                		+"<td>"+ excelRow.getBrand() +"</td>"
462
                		+"<td>"+ excelRow.getCategory() +"</td>"
463
                		+"<td>"+ excelRow.getProductGroup() +"</td>"
464
                		+"<td>"+ excelRow.getProductName() +"</td>"
465
                		+"<td>"+ excelRow.getSalesHistory() +"</td>"
466
                		+"<td>"+ Math.round(excelRow.getAvgSale() * 100.0) / 100.0 +"</td>"
467
                		+"<td>"+ excelRow.getStockQuantity() +"</td>"
468
                		+"<td>"+ String.format("%.0f",excelRow.getNodStock()) +"</td>"
469
                		+"<td>"+ String.format("%.0f",excelRow.getStockValue()) +"</td></tr>");
470
                count++;
471
        	}else{
472
        		break;
473
        	}
474
        }
475
        sb.append("</table>");
476
        sb.append("<table border=\"1\" align=\"center\">"
477
                + "<caption><b>" + "NON-MOVING-ITEMS" + "</b></caption>"
478
                + "<tr>" + "<td><b>" + "ITEM-ID" + "</b></td>" + "<td><b>"
479
                + "BRAND" + "</b></td>" + "<td><b>" + "CATEGORY" + "</b></td>"
480
                + "<td><b>" + "PRODUCT-GROUP" + "</b></td>" + "<td><b>"
481
                + "PRODUCT-NAME" + "</b></td>" + "<td><b>" + "SALES-HISTORY"
482
                + "</b></td>" + "<td><b>" + "AVG-SALE" + "</b></td>"
483
                + "</b></td>" + "<td><b>" + "CURRENT-STOCK" + "</b></td>"
484
                + "<td><b>" + "NO-OF-DAYS-STOCK" + "</b></td>" 
485
                + "<td><b>" + "STOCK-VALUE" + "</b></td>"+ "</tr>");
486
 
487
        count = 0;
488
        for(FkExcelRow excelRow : Not_Moving_Item_List){
489
        	if (count < 10) {
490
                sb.append("<tr>" + "<td>"+ excelRow.getItem_id() +"</td>"
491
                		+"<td>"+ excelRow.getBrand() +"</td>"
492
                		+"<td>"+ excelRow.getCategory() +"</td>"
493
                		+"<td>"+ excelRow.getProductGroup() +"</td>"
494
                		+"<td>"+ excelRow.getProductName() +"</td>"
495
                		+"<td>"+ excelRow.getSalesHistory() +"</td>"
496
                		+"<td>"+ Math.round(excelRow.getAvgSale() * 100.0) / 100.0 +"</td>"
497
                		+"<td>"+ excelRow.getStockQuantity() +"</td>"
498
                		+"<td>"+ String.format("%.0f",excelRow.getNodStock()) +"</td>"
499
                		+"<td>"+ String.format("%.0f",excelRow.getStockValue()) +"</td></tr>");
500
                count++;
501
        	}else{
502
        		break;
503
        	}
504
        }
505
        sb.append("</table></html>");
506
        StringBuffer stockSummary = new StringBuffer();
507
        stockSummary.append("<html><table border=\"1\" align=\"center\">" + 
508
                "<caption><b>"+ "STOCK SUMMARY" + "</b></caption>" + 
509
                "<tr>" + "<td><b>"+ "STOCK-TYPE" + "</b></td>" +"<td><b>"+
510
                "NO-OF-SKUS" + "</b></td>" +"<td><b>"
511
                + "QTY" + "</b></td>" +"<td><b>" + "VALUE"+"</tr>");
512
        stockSummary.append("<tr>" + "<td><b>"+ "MOVING" + "</b></td>" +
513
                "<td><b>" +Moving_List.size()+ "</b></td>" +"<td><b>"
514
                + "</b>"+movingStock+"</td>" +"<td><b>" + String.format("%.0f",movingStockValue)+"</tr>");
515
        stockSummary.append("<tr>" + "<td><b>"+ "SLOW-MOVING" + "</b></td>"+
516
                "<td><b>" +    Slow_Moving_Items.size() + "</b></td>" +"<td><b>"
517
                + "</b>"+slow_moving_count+"</td>" +"<td><b>" +String.format("%.0f",slow_moving_value)+"</tr>");
518
        stockSummary.append("<tr>" + "<td><b>"+ "NOT-MOVING" + "</b></td>" +
519
                "<td><b>" +    Not_Moving_Item_List.size() + "</b></td>" +"<td><b>"
520
                + "</b>"+not_moving_count+"</td>" +"<td><b>" +String.format("%.0f",not_moving_value)+"</tr>");
521
        stockSummary.append("<tr>" + "<td><b>"+ "TOTAL" + "</b></td>"+
522
                "<td><b>" +  (Moving_List.size() +Slow_Moving_Items.size()+ Not_Moving_Item_List.size()) + "</b></td>" +"<td><b>"
523
                + "</b>"+(movingStock+not_moving_count+slow_moving_count)+"</td>" +"<td><b>" +String.format("%.0f",(movingStockValue+not_moving_value+slow_moving_value))+"</tr>");
524
        stockSummary.append("</table></html>");
525
 
526
        BufferedWriter out = new BufferedWriter(new FileWriter(
527
        		FLIPKART_FBA_SHEET_BODY));
528
        out.write(stockSummary.toString()+sb.toString());
529
        out.flush();
530
        out.close();
531
        String emailFromAddress = "build-staging@shop2020.in";
532
        String password = "shop2020";
533
 
13608 manish.sha 534
        String[] sendTo = new String[]{"rajneesh.arora@shop2020.in","manish.sharma@shop2020.in","chaitnaya.vats@shop2020.in","khushal.bhatia@shop2020.in","manoj.kumar@shop2020.in","amit.gupta@shop2020.in","manoj.pal@shop2020.in","ankush.dhingra@saholic.com","j.p.gupta@shop2020.in"};
13584 manish.sha 535
        //String[] sendTo = new String[] { "manish.sharma@shop2020.in" };
536
        String emailSubjectTxt = "FA Stock Estimation Sheet (Mobiles and Tablets)";
537
        try {
538
            GmailUtils mailer = new GmailUtils();
539
            mailer.sendSSLMessage(sendTo, emailSubjectTxt, "", emailFromAddress, password, FLIPKART_FBA_SHEET, FLIPKART_FBA_SHEET_BODY);
540
        } catch (Exception ex) {
541
            ex.printStackTrace();
542
            EmailUtils emailUtils = new EmailUtils();
543
            emailUtils.sendEmail(sendTo, emailSubjectTxt, "", emailFromAddress, FLIPKART_FBA_SHEET, FLIPKART_FBA_SHEET_BODY);
544
        }
545
	}
546
}