Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21786 ashik.ali 1
package com.spice.profitmandi.common.util;
2
 
3
import java.io.IOException;
4
import java.io.InputStream;
22470 ashik.ali 5
import java.io.OutputStream;
21786 ashik.ali 6
import java.time.LocalDateTime;
7
import java.time.ZoneId;
8
import java.util.ArrayList;
9
import java.util.Date;
23819 govind 10
import java.util.LinkedHashMap;
21786 ashik.ali 11
import java.util.List;
23819 govind 12
import java.util.Map;
13
import java.util.Set;
21786 ashik.ali 14
 
24052 amit.gupta 15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
21786 ashik.ali 17
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
22470 ashik.ali 18
import org.apache.poi.ss.usermodel.Cell;
19
import org.apache.poi.ss.usermodel.CellStyle;
21786 ashik.ali 20
import org.apache.poi.ss.usermodel.CellType;
22470 ashik.ali 21
import org.apache.poi.ss.usermodel.Font;
22521 ashik.ali 22
import org.apache.poi.ss.usermodel.HorizontalAlignment;
22470 ashik.ali 23
import org.apache.poi.ss.usermodel.Row;
21786 ashik.ali 24
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
22470 ashik.ali 25
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.xssf.streaming.SXSSFSheet;
27
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
22247 amit.gupta 28
import org.apache.poi.xssf.usermodel.XSSFRow;
21786 ashik.ali 29
import org.apache.poi.xssf.usermodel.XSSFSheet;
30
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
31
 
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22470 ashik.ali 33
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
34
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
22521 ashik.ali 35
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
21786 ashik.ali 36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23017 ashik.ali 37
import com.spice.profitmandi.common.model.SchemeModel;
21786 ashik.ali 38
import com.spice.profitmandi.common.model.TagListingModel;
39
 
40
public class ExcelUtils {
41
	private static final String TAG_ID = "Tag Id";
42
	private static final String TAG_LABEL = "Tag Label";
43
	private static final String ITEM_ID = "Item Id";
44
	private static final String BRAND = "Brand";
45
	private static final String MODEL_NAME = "Model Name";
46
	private static final String MODEL_NUMBER = "Model Number";
47
	private static final String COLOR = "Color";
48
	private static final String SELLING_PRICE = "Selling Price";
22204 amit.gupta 49
	private static final String MOP = "MOP";
21786 ashik.ali 50
	private static final String SUPPORT_PRICE = "Support Price";
51
	private static final String START_DATE = "Start Date";
52
	private static final String TAG_LISTING = "Tag Listing";
53
 
23568 govind 54
	private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
21786 ashik.ali 55
 
56
	public static void main(String[] args) throws Throwable{
22470 ashik.ali 57
		//List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
58
		//writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
21786 ashik.ali 59
	}
22924 ashik.ali 60
	public static List<TagListingModel> parse(InputStream inputStream) throws Exception {
21786 ashik.ali 61
 
62
		List<TagListingModel> tagListings = new ArrayList<>();
63
		XSSFWorkbook myWorkBook = null;
64
		try{
65
			//FileInputStream fileInputStream = new FileInputStream("/home/ashikali/tag_listing1.xlsx");
66
			myWorkBook = new XSSFWorkbook (inputStream);
67
 
68
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
69
			// Return first sheet from the XLSX workbook 
70
			XSSFSheet mySheet = myWorkBook.getSheetAt(0);
22247 amit.gupta 71
			LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
21786 ashik.ali 72
 
22247 amit.gupta 73
			for(int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++){
74
				XSSFRow row = mySheet.getRow(rowNumber);
75
				LOGGER.info("row {}", row);
76
				TagListingModel tagListing = new TagListingModel();
77
				if(row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC){
78
					tagListing.setTagId((Double.valueOf(row.getCell(0).getNumericCellValue())).intValue());
79
				}else{
80
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
22226 amit.gupta 81
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
21786 ashik.ali 82
					throw profitMandiBusinessException;
83
				}
22247 amit.gupta 84
 
85
				if(row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.NUMERIC){
86
					tagListing.setItemId(Double.valueOf(row.getCell(2).toString()).intValue());
87
				}else{
88
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ITEM_ID, row.getCell(2).toString(), "TGLSTNG_VE_1010");
89
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
90
					throw profitMandiBusinessException;
91
				}
22204 amit.gupta 92
 
22247 amit.gupta 93
				if(row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.NUMERIC){
94
					tagListing.setSellingPrice(Double.valueOf(row.getCell(7).toString()).floatValue());
95
				}else{
96
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SELLING_PRICE, row.getCell(7), "TGLSTNG_VE_1010");
22226 amit.gupta 97
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
22209 amit.gupta 98
					throw profitMandiBusinessException;
21786 ashik.ali 99
				}
22247 amit.gupta 100
				if(row.getCell(8) != null && row.getCell(8).getCellTypeEnum() == CellType.NUMERIC){
101
					tagListing.setMop(Double.valueOf(row.getCell(8).toString()).floatValue());
102
				}else{
103
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(MOP, row.getCell(8), "TGLSTNG_VE_1010");
104
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
105
					throw profitMandiBusinessException;
106
				}
107
				if(row.getCell(9) != null && row.getCell(9).getCellTypeEnum() == CellType.NUMERIC){
108
					tagListing.setSupportPrice(Double.valueOf(row.getCell(9).toString()).floatValue());
109
				}else{
110
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(9).toString(), "TGLSTNG_VE_1010");
111
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
112
					throw profitMandiBusinessException;
113
				}
22563 amit.gupta 114
				if(row.getCell(10) != null && row.getCell(10).getCellTypeEnum() == CellType.NUMERIC){
115
					tagListing.setMaxDiscountPrice(Double.valueOf(row.getCell(10).toString()).floatValue());
116
				}else{
117
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(10).toString(), "TGLSTNG_VE_1010");
118
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
119
					throw profitMandiBusinessException;
120
				}
121
				if(row.getCell(11) != null && HSSFDateUtil.isCellDateFormatted(row.getCell(11))){
22865 amit.gupta 122
					Date date = row.getCell(11).getDateCellValue();
22247 amit.gupta 123
					LocalDateTime startDate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
124
					tagListing.setStartDate(startDate);
125
				}else{
22865 amit.gupta 126
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(START_DATE, row.getCell(11).toString(), "TGLSTNG_VE_1010");
22247 amit.gupta 127
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
128
					throw  profitMandiBusinessException;
129
				}
130
				tagListings.add(tagListing);
21786 ashik.ali 131
			}
132
			myWorkBook.close();
22247 amit.gupta 133
		} catch(IOException ioException){
22206 amit.gupta 134
			ioException.printStackTrace();
21786 ashik.ali 135
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(), "EXL_VE_1000");
22247 amit.gupta 136
		} finally {
21786 ashik.ali 137
			if(myWorkBook != null){
138
				try {
139
					myWorkBook.close();
140
				} catch (IOException e) {
141
					// TODO Auto-generated catch block
142
					e.printStackTrace();
143
				}
144
			}
145
		}
146
		return tagListings;
147
	}
22470 ashik.ali 148
 
22521 ashik.ali 149
	public static void writeInventoryItemAgingModels(List<InventoryItemAgingModel> inventoryItemAgingModels, List<Integer> intervals, OutputStream outputStream){
22470 ashik.ali 150
		SXSSFWorkbook workbook = new SXSSFWorkbook();
151
 
152
		//CreationHelper createHelper = workbook.getCreationHelper();
153
 
154
		SXSSFSheet sheet = workbook.createSheet("InventoryItemAging");
155
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
156
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
157
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
158
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
159
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
160
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
161
		sheet.trackAllColumnsForAutoSizing();
162
 
163
 
164
	    Row rowHeader = sheet.createRow(0);
165
	    Cell cellItemIdHeader = rowHeader.createCell(0);
166
		cellItemIdHeader.setCellValue("Item Id");
167
		Cell cellBrandHeader = rowHeader.createCell(1);
168
		cellBrandHeader.setCellValue("Brand");
169
		Cell cellModelNameHeader = rowHeader.createCell(2);
170
		cellModelNameHeader.setCellValue("Model Name");
171
		Cell cellModelNumberHeader = rowHeader.createCell(3);
172
		cellModelNumberHeader.setCellValue("Model Number");
173
		Cell cellColorHeader = rowHeader.createCell(4);
174
		cellColorHeader.setCellValue("Color");
175
		Cell cellTypeHeader = rowHeader.createCell(5);
176
		cellTypeHeader.setCellValue("Item Type");
177
		Row rowPriceQuantity = sheet.createRow(1);
178
		for(int index = 0, colIndex = 6; index < intervals.size() + 1; index++, colIndex = colIndex + 2){
179
			Cell cellHeader = rowHeader.createCell(colIndex);
180
			if(index == 0){
181
				cellHeader.setCellValue("Less Than "+intervals.get(index)+" Days");
182
			}else if(index < intervals.size()){
183
				cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
184
			}else{
185
				cellHeader.setCellValue("More Than "+intervals.get(index - 1)+" Days");
186
			}
187
			sheet.addMergedRegion(new CellRangeAddress(0, 0, colIndex, colIndex + 1));
188
			rowHeader.createCell(colIndex + 1);
189
			Cell cellPrice = rowPriceQuantity.createCell(colIndex);
190
			cellPrice.setCellValue("Price");
191
			Cell cellQuantity = rowPriceQuantity.createCell(colIndex + 1);
192
			cellQuantity.setCellValue("Quantity");
193
		}
194
		Font font = workbook.createFont();
195
		CellStyle cellStyle = workbook.createCellStyle();
196
		font.setBold(true);
197
		//font.setFontHeight((short)16);
198
		cellStyle.setFont(font);
22486 ashik.ali 199
		for(int i = 0; i < 8 + (intervals.size() * 2); i++){
22470 ashik.ali 200
			rowHeader.getCell(i).setCellStyle(cellStyle);
201
			if(rowPriceQuantity.getCell(i) != null){
202
				rowPriceQuantity.getCell(i).setCellStyle(cellStyle);
203
			}
204
		}
205
 
206
		for(int index = 0; index < inventoryItemAgingModels.size(); index++){
207
			InventoryItemAgingModel inventoryItemAgingModel = inventoryItemAgingModels.get(index);
208
	    	Row rowValues = sheet.createRow(index + 2);
209
	    	Cell cellItemId = rowValues.createCell(0);
210
	    	cellItemId.setCellValue(inventoryItemAgingModel.getItemId());
211
	    	Cell cellBrand = rowValues.createCell(1);
212
	    	cellBrand.setCellValue(inventoryItemAgingModel.getBrand());
213
	    	Cell cellModelName = rowValues.createCell(2);
214
	    	cellModelName.setCellValue(inventoryItemAgingModel.getModelName());
215
	    	Cell cellModelNumber = rowValues.createCell(3);
216
	    	cellModelNumber.setCellValue(inventoryItemAgingModel.getModelNumber());
217
	    	Cell cellColor = rowValues.createCell(4);
218
	    	cellColor.setCellValue(inventoryItemAgingModel.getColor());
219
	    	Cell cellType = rowValues.createCell(5);
220
	    	cellType.setCellValue(inventoryItemAgingModel.getItemType().toString());
221
	    	List<InventoryItemAgingValue> inventoryItemAgingValues = inventoryItemAgingModel.getValues();
222
	    	//LOGGER.info("inventoryItemAgingValues {}", inventoryItemAgingValues);
223
	    	for(int i = 0, colIndex = 6; i < inventoryItemAgingValues.size(); i++, colIndex = colIndex + 2){
224
	    		Cell cellPrice = rowValues.createCell(colIndex);
225
	    		InventoryItemAgingValue inventoryItemAgingValue = inventoryItemAgingValues.get(i); 
226
	    		//LOGGER.info("inventoryItemAgingValue {}", inventoryItemAgingValue);
227
	    		Cell cellQuantity = rowValues.createCell(colIndex + 1);
228
	    		if(inventoryItemAgingValue != null){
229
	    			cellPrice.setCellValue(inventoryItemAgingValue.getPrice());
230
	    			cellQuantity.setCellValue(inventoryItemAgingValue.getQuantity());
231
	    		}else{
22521 ashik.ali 232
	    			cellPrice.setCellValue("-");
233
	    			cellQuantity.setCellValue("-");
22470 ashik.ali 234
	    		}
235
	    	}
236
	    }
237
 
22486 ashik.ali 238
		for(int index = 0; index < 8 + (intervals.size() * 2); index++){
22470 ashik.ali 239
			sheet.autoSizeColumn(index);
240
		}
241
 
242
	    try{
22486 ashik.ali 243
			workbook.write(outputStream);
22470 ashik.ali 244
	    	workbook.close();
245
	    }catch(IOException ioException){
22486 ashik.ali 246
	    	LOGGER.error("Unable to generate excel file", ioException);
22470 ashik.ali 247
	    }
248
	}
249
 
22521 ashik.ali 250
	public static void writeItemCompleteLedgerModels(List<ItemCompleteLedgerModel> itemCompleteLedgerModels, OutputStream outputStream){
251
		SXSSFWorkbook workbook = new SXSSFWorkbook();
252
 
253
		//CreationHelper createHelper = workbook.getCreationHelper();
254
 
255
		SXSSFSheet sheet = workbook.createSheet("ItemCompleteLeger");
256
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
257
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
258
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
259
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
260
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
261
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
262
		sheet.trackAllColumnsForAutoSizing();
263
 
264
 
265
	    Row rowHeader = sheet.createRow(0);
266
	    Cell cellItemIdHeader = rowHeader.createCell(0);
267
		cellItemIdHeader.setCellValue("Item Id");
268
		Cell cellBrandHeader = rowHeader.createCell(1);
269
		cellBrandHeader.setCellValue("Brand");
270
		Cell cellModelNameHeader = rowHeader.createCell(2);
271
		cellModelNameHeader.setCellValue("Model Name");
272
		Cell cellModelNumberHeader = rowHeader.createCell(3);
273
		cellModelNumberHeader.setCellValue("Model Number");
274
		Cell cellColorHeader = rowHeader.createCell(4);
275
		cellColorHeader.setCellValue("Color");
276
		Cell cellTypeHeader = rowHeader.createCell(5);
277
		cellTypeHeader.setCellValue("Item Type");
278
		Cell cellOpeningBalanceHeader = rowHeader.createCell(6);
279
		cellOpeningBalanceHeader.setCellValue("Opening Balance");
280
		Cell cellInwardsHeader = rowHeader.createCell(9);
281
		cellInwardsHeader.setCellValue("Inwards");
282
		Cell cellOutwardsHeader = rowHeader.createCell(12);
283
		cellOutwardsHeader.setCellValue("Outwards");
284
		Cell cellClosingBalanceHeader = rowHeader.createCell(15);
285
		cellClosingBalanceHeader.setCellValue("Closing Balance");
286
		Row rowQuantityRateValue = sheet.createRow(1);
287
 
288
		for(int index = 6; index < 18; index = index + 3){
289
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
290
			cellQuantityHeader.setCellValue("Quantity");
291
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
292
			cellRateHeader.setCellValue("Rate");
293
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
294
			cellValueHeader.setCellValue("Value");
295
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
296
		}
297
		Font font = workbook.createFont();
298
		CellStyle cellStyle = workbook.createCellStyle();
299
		font.setBold(true);
300
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
301
		//font.setFontHeight((short)16);
302
		cellStyle.setFont(font);
303
		for(int i = 0; i < 18; i++){
304
			if(rowHeader.getCell(i) != null){
305
				rowHeader.getCell(i).setCellStyle(cellStyle);
306
			}
307
		}
308
		int openingQuantityTotal = 0;
309
		float openingValueTotal = 0;
310
		int inwardsQuantityTotal = 0;
311
		float inwardsValueTotal = 0;
312
		int outwardsQuantityTotal = 0;
313
		float outwardsValueTotal = 0;
314
		int closingQuantityTotal = 0;
315
		float closingValueTotal = 0;
316
		for(int index = 0; index < itemCompleteLedgerModels.size(); index++){
317
			ItemCompleteLedgerModel itemCompleteLedgerModel = itemCompleteLedgerModels.get(index);
318
	    	Row rowValues = sheet.createRow(index + 2);
319
	    	Cell cellItemId = rowValues.createCell(0);
320
	    	cellItemId.setCellValue(itemCompleteLedgerModel.getItemValue().getItemId());
321
	    	Cell cellBrand = rowValues.createCell(1);
322
	    	cellBrand.setCellValue(itemCompleteLedgerModel.getItemValue().getBrand());
323
	    	Cell cellModelName = rowValues.createCell(2);
324
	    	cellModelName.setCellValue(itemCompleteLedgerModel.getItemValue().getModelName());
325
	    	Cell cellModelNumber = rowValues.createCell(3);
326
	    	cellModelNumber.setCellValue(itemCompleteLedgerModel.getItemValue().getModelNumber());
327
	    	Cell cellColor = rowValues.createCell(4);
328
	    	cellColor.setCellValue(itemCompleteLedgerModel.getItemValue().getColor());
329
	    	Cell cellType = rowValues.createCell(5);
330
	    	cellType.setCellValue(itemCompleteLedgerModel.getItemValue().getItemType().toString());
331
	    	Cell cellOpeningQuantity = rowValues.createCell(6);
332
	    	Cell cellOpeningRate = rowValues.createCell(7);
333
	    	Cell cellOpeningValue = rowValues.createCell(8);
334
	    	if(itemCompleteLedgerModel.getOpeningLedger() == null){
335
	    		cellOpeningQuantity.setCellValue("-");
336
	    		cellOpeningRate.setCellValue("-");
337
	    		cellOpeningValue.setCellValue("-");
338
	    	}else{
339
	    		cellOpeningQuantity.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getQuantity());
340
	    		cellOpeningRate.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getRate());
341
	    		cellOpeningValue.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getValue());
342
	    		openingQuantityTotal = openingQuantityTotal + itemCompleteLedgerModel.getOpeningLedger().getQuantity();
343
	    		openingValueTotal = openingValueTotal + itemCompleteLedgerModel.getOpeningLedger().getValue();
344
	    	}
345
	    	Cell cellInwardsQuantity = rowValues.createCell(9);
346
	    	Cell cellInwardsRate = rowValues.createCell(10);
347
	    	Cell cellInwardsValue = rowValues.createCell(11);
348
	    	if(itemCompleteLedgerModel.getInwardsLedger() == null){
349
	    		cellInwardsQuantity.setCellValue("-");
350
	    		cellInwardsRate.setCellValue("-");
351
	    		cellInwardsValue.setCellValue("-");
352
	    	}else{
353
	    		cellInwardsQuantity.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getQuantity());
354
	    		cellInwardsRate.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getRate());
355
	    		cellInwardsValue.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getValue());
356
	    		inwardsQuantityTotal = inwardsQuantityTotal + itemCompleteLedgerModel.getInwardsLedger().getQuantity();
357
	    		inwardsValueTotal = inwardsValueTotal + itemCompleteLedgerModel.getInwardsLedger().getValue();
358
	    	}
359
	    	Cell cellOutwardsQuantity = rowValues.createCell(12);
360
	    	Cell cellOutwardsRate = rowValues.createCell(13);
361
	    	Cell cellOutwardsValue = rowValues.createCell(14);
362
	    	if(itemCompleteLedgerModel.getOutwardsLedger() == null){
363
	    		cellOutwardsQuantity.setCellValue("-");
364
	    		cellOutwardsRate.setCellValue("-");
365
	    		cellOutwardsValue.setCellValue("-");
366
	    	}else{
367
	    		cellOutwardsQuantity.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getQuantity());
368
	    		cellOutwardsRate.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getRate());
369
	    		cellOutwardsValue.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getValue());
370
	    		outwardsQuantityTotal = outwardsQuantityTotal + itemCompleteLedgerModel.getOutwardsLedger().getQuantity();
371
	    		outwardsValueTotal = outwardsValueTotal + itemCompleteLedgerModel.getOutwardsLedger().getValue();
372
	    	}
373
	    	Cell cellClosingQuantity = rowValues.createCell(15);
374
	    	Cell cellClosingRate = rowValues.createCell(16);
375
	    	Cell cellClosingValue = rowValues.createCell(17);
376
	    	if(itemCompleteLedgerModel.getClosingLedger() == null){
377
	    		cellClosingQuantity.setCellValue("-");
378
	    		cellClosingRate.setCellValue("-");
379
	    		cellClosingValue.setCellValue("-");
380
	    	}else{
381
	    		cellClosingQuantity.setCellValue(itemCompleteLedgerModel.getClosingLedger().getQuantity());
382
	    		cellClosingRate.setCellValue(itemCompleteLedgerModel.getClosingLedger().getRate());
383
	    		cellClosingValue.setCellValue(itemCompleteLedgerModel.getClosingLedger().getValue());
384
	    		closingQuantityTotal = closingQuantityTotal + itemCompleteLedgerModel.getClosingLedger().getQuantity();
385
	    		closingValueTotal = closingValueTotal + itemCompleteLedgerModel.getClosingLedger().getValue();
386
	    	}
387
	    }
388
 
389
		Row rowTotal = sheet.createRow(itemCompleteLedgerModels.size() + 2);
390
 
391
		if(openingQuantityTotal > 0){
392
			Cell cellOpeningQuantityTotal = rowTotal.createCell(6);
393
			cellOpeningQuantityTotal.setCellValue(openingQuantityTotal);
394
			Cell cellOpeningValueTotal = rowTotal.createCell(8);
395
			cellOpeningValueTotal.setCellValue(openingValueTotal);
396
		}
397
 
398
		if(inwardsQuantityTotal > 0){
399
			Cell cellInwardsQuantityTotal = rowTotal.createCell(9);
400
			cellInwardsQuantityTotal.setCellValue(inwardsQuantityTotal);
401
			Cell cellInwardsValueTotal = rowTotal.createCell(11);
402
			cellInwardsValueTotal.setCellValue(inwardsValueTotal);
403
		}
404
 
405
		if(outwardsQuantityTotal > 0){
406
			Cell cellOutwardsQuantityTotal = rowTotal.createCell(12);
407
			cellOutwardsQuantityTotal.setCellValue(outwardsQuantityTotal);
408
			Cell cellOutwardsValueTotal = rowTotal.createCell(14);
409
			cellOutwardsValueTotal.setCellValue(outwardsValueTotal);
410
		}
411
 
412
		if(closingQuantityTotal > 0){
413
			Cell cellClosingQuantityTotal = rowTotal.createCell(15);
414
			cellClosingQuantityTotal.setCellValue(closingQuantityTotal);
415
			Cell cellClosingValueTotal = rowTotal.createCell(17);
416
			cellClosingValueTotal.setCellValue(closingValueTotal);
417
		}
418
 
419
		for(int index = 0; index < 18; index++){
420
			sheet.autoSizeColumn(index);
421
		}
422
 
423
	    try{
424
			workbook.write(outputStream);
425
	    	workbook.close();
426
	    }catch(IOException ioException){
427
	    	LOGGER.error("Unable to generate excel file", ioException);
428
	    }
429
	}
23017 ashik.ali 430
 
431
	public static void writeSchemeModels(List<SchemeModel> schemeModels, OutputStream outputStream){
432
		SXSSFWorkbook workbook = new SXSSFWorkbook();
433
 
434
		//CreationHelper createHelper = workbook.getCreationHelper();
435
 
436
		SXSSFSheet sheet = workbook.createSheet("Schemes");
437
		sheet.trackAllColumnsForAutoSizing();
438
 
439
 
440
	    Row rowHeader = sheet.createRow(0);
441
	    Cell cellSchemeIdHeader = rowHeader.createCell(0);
442
		cellSchemeIdHeader.setCellValue("Scheme Id");
443
		Cell cellNameHeader = rowHeader.createCell(1);
444
		cellNameHeader.setCellValue("Name");
445
		Cell cellDescriptionHeader = rowHeader.createCell(2);
446
		cellDescriptionHeader.setCellValue("Description");
447
		Cell cellSchemeTypeHeader = rowHeader.createCell(3);
448
		cellSchemeTypeHeader.setCellValue("Scheme Type");
449
		Cell cellAmountTypeHeader = rowHeader.createCell(4);
450
		cellAmountTypeHeader.setCellValue("Amount Type");
451
		Cell cellAmountHeader = rowHeader.createCell(5);
452
		cellAmountHeader.setCellValue("Amount");
453
		Cell cellStartDateTimeHeader = rowHeader.createCell(6);
454
		cellStartDateTimeHeader.setCellValue("Start Date Time");
455
		Cell cellEndDateTimeHeader = rowHeader.createCell(7);
456
		cellEndDateTimeHeader.setCellValue("End Date Time");
457
		Cell cellCreatedAtHeader = rowHeader.createCell(8);
458
		cellCreatedAtHeader.setCellValue("Created At");
459
		Cell cellActiveHeader = rowHeader.createCell(9);
460
		cellActiveHeader.setCellValue("Active");
461
		Cell cellExpireHeader = rowHeader.createCell(10);
462
		cellExpireHeader.setCellValue("Expire");
463
		Cell cellCreatedByHeader = rowHeader.createCell(11);
464
		cellCreatedByHeader.setCellValue("Created By");
465
		Cell cellItemIdsHeader = rowHeader.createCell(12);
466
		cellItemIdsHeader.setCellValue("Item Ids");
467
		Cell cellRetailerIdsHeader = rowHeader.createCell(13);
468
		cellRetailerIdsHeader.setCellValue("Retailer Ids");
469
		//Row rowQuantityRateValue = sheet.createRow(1);
470
 
471
		/*for(int index = 6; index < 18; index = index + 3){
472
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
473
			cellQuantityHeader.setCellValue("Quantity");
474
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
475
			cellRateHeader.setCellValue("Rate");
476
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
477
			cellValueHeader.setCellValue("Value");
478
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
479
		}*/
480
		Font font = workbook.createFont();
481
		CellStyle cellStyle = workbook.createCellStyle();
482
		font.setBold(true);
483
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
484
		//font.setFontHeight((short)16);
485
		cellStyle.setFont(font);
486
		for(int i = 0; i < 14; i++){
487
			if(rowHeader.getCell(i) != null){
488
				rowHeader.getCell(i).setCellStyle(cellStyle);
489
			}
490
		}
491
 
492
		for(int index = 0; index < schemeModels.size(); index++){
493
			SchemeModel schemeModel = schemeModels.get(index);
494
			//ItemCompleteLedgerModel itemCompleteLedgerModel = itemCompleteLedgerModels.get(index);
495
	    	Row rowValues = sheet.createRow(index + 1);
496
	    	Cell cellSchemeId = rowValues.createCell(0);
497
			cellSchemeId.setCellValue(schemeModel.getSchemeId());
498
			Cell cellName = rowValues.createCell(1);
499
			cellName.setCellValue(schemeModel.getName());
500
			Cell cellDescription = rowValues.createCell(2);
501
			cellDescription.setCellValue(schemeModel.getDescription());
502
			Cell cellSchemeType = rowValues.createCell(3);
503
			cellSchemeType.setCellValue(schemeModel.getSchemeType());
504
			Cell cellAmountType = rowValues.createCell(4);
505
			cellAmountType.setCellValue(schemeModel.getAmountType());
506
			Cell cellAmount = rowValues.createCell(5);
507
			cellAmount.setCellValue(schemeModel.getAmount());
508
			Cell cellStartDateTime = rowValues.createCell(6);
509
			cellStartDateTime.setCellValue(schemeModel.getStartDateTime());
510
			Cell cellEndDateTime = rowValues.createCell(7);
511
			cellEndDateTime.setCellValue(schemeModel.getEndDateTime());
512
			Cell cellCreatedAt = rowValues.createCell(8);
513
			cellCreatedAt.setCellValue(schemeModel.getCreateTimestamp());
514
			Cell cellActive = rowValues.createCell(9);
515
			if(schemeModel.getActiveTimestamp() !=null){
516
				cellActive.setCellValue(schemeModel.getActiveTimestamp());
517
			}else{
518
				cellActive.setCellValue("False");
519
			}
520
			Cell cellExpire = rowValues.createCell(10);
521
			if(schemeModel.getExpireTimestamp() != null){
522
				cellExpire.setCellValue(schemeModel.getExpireTimestamp());
523
			}else{
524
				cellExpire.setCellValue("False");
525
			}
526
			Cell cellCreatedBy = rowValues.createCell(11);
527
			cellCreatedBy.setCellValue(schemeModel.getCreatedBy());
528
			Cell cellItemIds = rowValues.createCell(12);
23338 ashik.ali 529
			cellItemIds.setCellValue(schemeModel.getItemStringMap().toString());
23017 ashik.ali 530
			Cell cellRetailerIds = rowValues.createCell(13);
531
			cellRetailerIds.setCellValue(schemeModel.getRetailerIdsString());
23338 ashik.ali 532
			int maxHeight = Math.max(schemeModel.getItemStringMap().size(), schemeModel.getRetailerIds().size());
23017 ashik.ali 533
			if(maxHeight > 1){
534
				rowValues.setHeight((short)(maxHeight * 240));
535
			}
536
	    }
537
 
538
		for(int index = 0; index < 14; index++){
539
			sheet.autoSizeColumn(index);
540
		}
541
 
542
	    try{
543
			workbook.write(outputStream);
544
	    	workbook.close();
545
	    }catch(IOException ioException){
546
	    	LOGGER.error("Unable to generate excel file", ioException);
547
	    }
548
	}
23819 govind 549
	public static void writePriceDrop(Map<String, String> priceDropIMEIfofoId,int itemId,OutputStream outputStream){
550
		SXSSFWorkbook workbook = new SXSSFWorkbook();
551
 
552
		//CreationHelper createHelper = workbook.getCreationHelper();
553
 
554
		SXSSFSheet sheet = workbook.createSheet("Schemes");
555
		sheet.trackAllColumnsForAutoSizing();
556
 
557
 
558
	    Row rowHeader = sheet.createRow(0);
559
	    Cell cellItemHeader = rowHeader.createCell(0);
560
	    cellItemHeader.setCellValue("ITEMID");
561
		Cell cellIMEIHeader = rowHeader.createCell(1);
562
		cellIMEIHeader.setCellValue("IMEI");
563
		Cell cellFOFOIDHeader = rowHeader.createCell(2);
564
		cellFOFOIDHeader.setCellValue("RETAILERNAME");
565
		//Row rowQuantityRateValue = sheet.createRow(1);
566
 
567
		/*for(int index = 6; index < 18; index = index + 3){
568
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
569
			cellQuantityHeader.setCellValue("Quantity");
570
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
571
			cellRateHeader.setCellValue("Rate");
572
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
573
			cellValueHeader.setCellValue("Value");
574
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
575
		}*/
576
		Font font = workbook.createFont();
577
		CellStyle cellStyle = workbook.createCellStyle();
578
		font.setBold(true);
579
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
580
		//font.setFontHeight((short)16);
581
		cellStyle.setFont(font);
582
		for(int i = 0; i < 14; i++){
583
			if(rowHeader.getCell(i) != null){
584
				rowHeader.getCell(i).setCellStyle(cellStyle);
585
			}
586
		}
587
		LinkedHashMap<String,String> priceAmount=new LinkedHashMap<>(priceDropIMEIfofoId);
588
		Set<String> keyset=priceAmount.keySet();
589
		int rownum = 1;
590
		for (String key : keyset) {
591
            Row row = sheet.createRow(rownum++);
592
            String objArr = priceAmount.get(key);
593
            int cellnum = 0;
594
            Cell cell = row.createCell(cellnum++);
595
            cell.setCellValue(itemId);
596
            Cell cell1 = row.createCell(cellnum++);
597
            cell1.setCellValue(key);
598
            Cell cell2 = row.createCell(cellnum++);
599
            cell2.setCellValue(priceAmount.get(key));
600
            }
601
 
602
		for(int index = 0; index < 14; index++){
603
			sheet.autoSizeColumn(index);
604
		}
605
 
606
	    try{
607
			workbook.write(outputStream);
608
	    	workbook.close();
609
	    }catch(IOException ioException){
610
	    	LOGGER.error("Unable to generate excel file", ioException);
611
	    }
612
	}
613
	public static void writePriceDropForAllIMEI(Map<String,String>priceDropAmount,OutputStream outputStream){
614
		SXSSFWorkbook workbook = new SXSSFWorkbook();
615
 
616
		//CreationHelper createHelper = workbook.getCreationHelper();
617
 
618
		SXSSFSheet sheet = workbook.createSheet("Schemes");
619
		sheet.trackAllColumnsForAutoSizing();
620
 
621
 
622
	    Row rowHeader = sheet.createRow(0);
623
	    Cell cellItemHeader = rowHeader.createCell(0);
624
	    cellItemHeader.setCellValue("Itemdescription");
625
		Cell cellIMEIHeader = rowHeader.createCell(1);
626
		cellIMEIHeader.setCellValue("IMEI");
627
		//Row rowQuantityRateValue = sheet.createRow(1);
628
 
629
		/*for(int index = 6; index < 18; index = index + 3){
630
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
631
			cellQuantityHeader.setCellValue("Quantity");
632
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
633
			cellRateHeader.setCellValue("Rate");
634
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
635
			cellValueHeader.setCellValue("Value");
636
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
637
		}*/
638
		Font font = workbook.createFont();
639
		CellStyle cellStyle = workbook.createCellStyle();
640
		font.setBold(true);
641
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
642
		//font.setFontHeight((short)16);
643
		cellStyle.setFont(font);
644
		for(int i = 0; i < 14; i++){
645
			if(rowHeader.getCell(i) != null){
646
				rowHeader.getCell(i).setCellStyle(cellStyle);
647
			}
648
		}
649
		Set<String> keyset=priceDropAmount.keySet();
650
		int rownum = 1;
651
		for (String key : keyset) {
652
            Row row = sheet.createRow(rownum++);
653
            String objArr = priceDropAmount.get(key);
654
            int cellnum = 0;
655
            Cell cell = row.createCell(cellnum++);
656
            cell.setCellValue(priceDropAmount.get(key));
657
            Cell cell1 = row.createCell(cellnum++);
658
            cell1.setCellValue(key);
659
            }
660
 
661
		for(int index = 0; index < 14; index++){
662
			sheet.autoSizeColumn(index);
663
		}
664
 
665
	    try{
666
			workbook.write(outputStream);
667
	    	workbook.close();
668
	    }catch(IOException ioException){
669
	    	LOGGER.error("Unable to generate excel file", ioException);
670
	    }
671
	}
24052 amit.gupta 672
 
21786 ashik.ali 673
}