Subversion Repositories SmartDukaan

Rev

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