Subversion Repositories SmartDukaan

Rev

Rev 22521 | Rev 22865 | 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;
10
import java.util.List;
11
 
12
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
22470 ashik.ali 13
import org.apache.poi.ss.usermodel.Cell;
14
import org.apache.poi.ss.usermodel.CellStyle;
21786 ashik.ali 15
import org.apache.poi.ss.usermodel.CellType;
22470 ashik.ali 16
import org.apache.poi.ss.usermodel.Font;
22521 ashik.ali 17
import org.apache.poi.ss.usermodel.HorizontalAlignment;
22470 ashik.ali 18
import org.apache.poi.ss.usermodel.Row;
21786 ashik.ali 19
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
22470 ashik.ali 20
import org.apache.poi.ss.util.CellRangeAddress;
21
import org.apache.poi.xssf.streaming.SXSSFSheet;
22
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
22247 amit.gupta 23
import org.apache.poi.xssf.usermodel.XSSFRow;
21786 ashik.ali 24
import org.apache.poi.xssf.usermodel.XSSFSheet;
25
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
22226 amit.gupta 26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
21786 ashik.ali 28
 
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22470 ashik.ali 30
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
31
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
22521 ashik.ali 32
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
21786 ashik.ali 33
import com.spice.profitmandi.common.model.ProfitMandiConstants;
34
import com.spice.profitmandi.common.model.TagListingModel;
35
 
36
public class ExcelUtils {
37
	private static final String TAG_ID = "Tag Id";
38
	private static final String TAG_LABEL = "Tag Label";
39
	private static final String ITEM_ID = "Item Id";
40
	private static final String BRAND = "Brand";
41
	private static final String MODEL_NAME = "Model Name";
42
	private static final String MODEL_NUMBER = "Model Number";
43
	private static final String COLOR = "Color";
44
	private static final String SELLING_PRICE = "Selling Price";
22204 amit.gupta 45
	private static final String MOP = "MOP";
21786 ashik.ali 46
	private static final String SUPPORT_PRICE = "Support Price";
47
	private static final String START_DATE = "Start Date";
48
	private static final String TAG_LISTING = "Tag Listing";
49
 
22226 amit.gupta 50
	private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
21786 ashik.ali 51
 
52
	public static void main(String[] args) throws Throwable{
22470 ashik.ali 53
		//List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
54
		//writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
21786 ashik.ali 55
	}
22247 amit.gupta 56
	public static List<TagListingModel> parse(InputStream inputStream) throws Throwable {
21786 ashik.ali 57
 
58
		List<TagListingModel> tagListings = new ArrayList<>();
59
		XSSFWorkbook myWorkBook = null;
60
		try{
61
			//FileInputStream fileInputStream = new FileInputStream("/home/ashikali/tag_listing1.xlsx");
62
			myWorkBook = new XSSFWorkbook (inputStream);
63
 
64
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
65
			// Return first sheet from the XLSX workbook 
66
			XSSFSheet mySheet = myWorkBook.getSheetAt(0);
22247 amit.gupta 67
			LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
21786 ashik.ali 68
 
22247 amit.gupta 69
			for(int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++){
70
				XSSFRow row = mySheet.getRow(rowNumber);
71
				LOGGER.info("row {}", row);
72
				TagListingModel tagListing = new TagListingModel();
73
				if(row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC){
74
					tagListing.setTagId((Double.valueOf(row.getCell(0).getNumericCellValue())).intValue());
75
				}else{
76
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
22226 amit.gupta 77
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
21786 ashik.ali 78
					throw profitMandiBusinessException;
79
				}
22247 amit.gupta 80
 
81
				if(row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.NUMERIC){
82
					tagListing.setItemId(Double.valueOf(row.getCell(2).toString()).intValue());
83
				}else{
84
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ITEM_ID, row.getCell(2).toString(), "TGLSTNG_VE_1010");
85
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
86
					throw profitMandiBusinessException;
87
				}
22204 amit.gupta 88
 
22247 amit.gupta 89
				if(row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.NUMERIC){
90
					tagListing.setSellingPrice(Double.valueOf(row.getCell(7).toString()).floatValue());
91
				}else{
92
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SELLING_PRICE, row.getCell(7), "TGLSTNG_VE_1010");
22226 amit.gupta 93
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
22209 amit.gupta 94
					throw profitMandiBusinessException;
21786 ashik.ali 95
				}
22247 amit.gupta 96
				if(row.getCell(8) != null && row.getCell(8).getCellTypeEnum() == CellType.NUMERIC){
97
					tagListing.setMop(Double.valueOf(row.getCell(8).toString()).floatValue());
98
				}else{
99
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(MOP, row.getCell(8), "TGLSTNG_VE_1010");
100
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
101
					throw profitMandiBusinessException;
102
				}
103
				if(row.getCell(9) != null && row.getCell(9).getCellTypeEnum() == CellType.NUMERIC){
104
					tagListing.setSupportPrice(Double.valueOf(row.getCell(9).toString()).floatValue());
105
				}else{
106
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(9).toString(), "TGLSTNG_VE_1010");
107
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
108
					throw profitMandiBusinessException;
109
				}
22563 amit.gupta 110
				if(row.getCell(10) != null && row.getCell(10).getCellTypeEnum() == CellType.NUMERIC){
111
					tagListing.setMaxDiscountPrice(Double.valueOf(row.getCell(10).toString()).floatValue());
112
				}else{
113
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(10).toString(), "TGLSTNG_VE_1010");
114
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
115
					throw profitMandiBusinessException;
116
				}
117
				if(row.getCell(11) != null && HSSFDateUtil.isCellDateFormatted(row.getCell(11))){
22247 amit.gupta 118
					Date date = row.getCell(10).getDateCellValue();
119
					LocalDateTime startDate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
120
					tagListing.setStartDate(startDate);
121
				}else{
122
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(START_DATE, row.getCell(10).toString(), "TGLSTNG_VE_1010");
123
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
124
					throw  profitMandiBusinessException;
125
				}
126
				tagListings.add(tagListing);
21786 ashik.ali 127
			}
128
			myWorkBook.close();
22247 amit.gupta 129
		} catch(IOException ioException){
22206 amit.gupta 130
			ioException.printStackTrace();
21786 ashik.ali 131
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(), "EXL_VE_1000");
22247 amit.gupta 132
		} finally {
21786 ashik.ali 133
			if(myWorkBook != null){
134
				try {
135
					myWorkBook.close();
136
				} catch (IOException e) {
137
					// TODO Auto-generated catch block
138
					e.printStackTrace();
139
				}
140
			}
141
		}
142
		return tagListings;
143
	}
22470 ashik.ali 144
 
22521 ashik.ali 145
	public static void writeInventoryItemAgingModels(List<InventoryItemAgingModel> inventoryItemAgingModels, List<Integer> intervals, OutputStream outputStream){
22470 ashik.ali 146
		SXSSFWorkbook workbook = new SXSSFWorkbook();
147
 
148
		//CreationHelper createHelper = workbook.getCreationHelper();
149
 
150
		SXSSFSheet sheet = workbook.createSheet("InventoryItemAging");
151
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
152
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
153
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
154
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
155
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
156
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
157
		sheet.trackAllColumnsForAutoSizing();
158
 
159
 
160
	    Row rowHeader = sheet.createRow(0);
161
	    Cell cellItemIdHeader = rowHeader.createCell(0);
162
		cellItemIdHeader.setCellValue("Item Id");
163
		Cell cellBrandHeader = rowHeader.createCell(1);
164
		cellBrandHeader.setCellValue("Brand");
165
		Cell cellModelNameHeader = rowHeader.createCell(2);
166
		cellModelNameHeader.setCellValue("Model Name");
167
		Cell cellModelNumberHeader = rowHeader.createCell(3);
168
		cellModelNumberHeader.setCellValue("Model Number");
169
		Cell cellColorHeader = rowHeader.createCell(4);
170
		cellColorHeader.setCellValue("Color");
171
		Cell cellTypeHeader = rowHeader.createCell(5);
172
		cellTypeHeader.setCellValue("Item Type");
173
		Row rowPriceQuantity = sheet.createRow(1);
174
		for(int index = 0, colIndex = 6; index < intervals.size() + 1; index++, colIndex = colIndex + 2){
175
			Cell cellHeader = rowHeader.createCell(colIndex);
176
			if(index == 0){
177
				cellHeader.setCellValue("Less Than "+intervals.get(index)+" Days");
178
			}else if(index < intervals.size()){
179
				cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
180
			}else{
181
				cellHeader.setCellValue("More Than "+intervals.get(index - 1)+" Days");
182
			}
183
			sheet.addMergedRegion(new CellRangeAddress(0, 0, colIndex, colIndex + 1));
184
			rowHeader.createCell(colIndex + 1);
185
			Cell cellPrice = rowPriceQuantity.createCell(colIndex);
186
			cellPrice.setCellValue("Price");
187
			Cell cellQuantity = rowPriceQuantity.createCell(colIndex + 1);
188
			cellQuantity.setCellValue("Quantity");
189
		}
190
		Font font = workbook.createFont();
191
		CellStyle cellStyle = workbook.createCellStyle();
192
		font.setBold(true);
193
		//font.setFontHeight((short)16);
194
		cellStyle.setFont(font);
22486 ashik.ali 195
		for(int i = 0; i < 8 + (intervals.size() * 2); i++){
22470 ashik.ali 196
			rowHeader.getCell(i).setCellStyle(cellStyle);
197
			if(rowPriceQuantity.getCell(i) != null){
198
				rowPriceQuantity.getCell(i).setCellStyle(cellStyle);
199
			}
200
		}
201
 
202
		for(int index = 0; index < inventoryItemAgingModels.size(); index++){
203
			InventoryItemAgingModel inventoryItemAgingModel = inventoryItemAgingModels.get(index);
204
	    	Row rowValues = sheet.createRow(index + 2);
205
	    	Cell cellItemId = rowValues.createCell(0);
206
	    	cellItemId.setCellValue(inventoryItemAgingModel.getItemId());
207
	    	Cell cellBrand = rowValues.createCell(1);
208
	    	cellBrand.setCellValue(inventoryItemAgingModel.getBrand());
209
	    	Cell cellModelName = rowValues.createCell(2);
210
	    	cellModelName.setCellValue(inventoryItemAgingModel.getModelName());
211
	    	Cell cellModelNumber = rowValues.createCell(3);
212
	    	cellModelNumber.setCellValue(inventoryItemAgingModel.getModelNumber());
213
	    	Cell cellColor = rowValues.createCell(4);
214
	    	cellColor.setCellValue(inventoryItemAgingModel.getColor());
215
	    	Cell cellType = rowValues.createCell(5);
216
	    	cellType.setCellValue(inventoryItemAgingModel.getItemType().toString());
217
	    	List<InventoryItemAgingValue> inventoryItemAgingValues = inventoryItemAgingModel.getValues();
218
	    	//LOGGER.info("inventoryItemAgingValues {}", inventoryItemAgingValues);
219
	    	for(int i = 0, colIndex = 6; i < inventoryItemAgingValues.size(); i++, colIndex = colIndex + 2){
220
	    		Cell cellPrice = rowValues.createCell(colIndex);
221
	    		InventoryItemAgingValue inventoryItemAgingValue = inventoryItemAgingValues.get(i); 
222
	    		//LOGGER.info("inventoryItemAgingValue {}", inventoryItemAgingValue);
223
	    		Cell cellQuantity = rowValues.createCell(colIndex + 1);
224
	    		if(inventoryItemAgingValue != null){
225
	    			cellPrice.setCellValue(inventoryItemAgingValue.getPrice());
226
	    			cellQuantity.setCellValue(inventoryItemAgingValue.getQuantity());
227
	    		}else{
22521 ashik.ali 228
	    			cellPrice.setCellValue("-");
229
	    			cellQuantity.setCellValue("-");
22470 ashik.ali 230
	    		}
231
	    	}
232
	    }
233
 
22486 ashik.ali 234
		for(int index = 0; index < 8 + (intervals.size() * 2); index++){
22470 ashik.ali 235
			sheet.autoSizeColumn(index);
236
		}
237
 
238
	    try{
22486 ashik.ali 239
			workbook.write(outputStream);
22470 ashik.ali 240
	    	workbook.close();
241
	    }catch(IOException ioException){
22486 ashik.ali 242
	    	LOGGER.error("Unable to generate excel file", ioException);
22470 ashik.ali 243
	    }
244
	}
245
 
22521 ashik.ali 246
	public static void writeItemCompleteLedgerModels(List<ItemCompleteLedgerModel> itemCompleteLedgerModels, OutputStream outputStream){
247
		SXSSFWorkbook workbook = new SXSSFWorkbook();
248
 
249
		//CreationHelper createHelper = workbook.getCreationHelper();
250
 
251
		SXSSFSheet sheet = workbook.createSheet("ItemCompleteLeger");
252
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
253
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
254
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
255
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
256
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
257
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
258
		sheet.trackAllColumnsForAutoSizing();
259
 
260
 
261
	    Row rowHeader = sheet.createRow(0);
262
	    Cell cellItemIdHeader = rowHeader.createCell(0);
263
		cellItemIdHeader.setCellValue("Item Id");
264
		Cell cellBrandHeader = rowHeader.createCell(1);
265
		cellBrandHeader.setCellValue("Brand");
266
		Cell cellModelNameHeader = rowHeader.createCell(2);
267
		cellModelNameHeader.setCellValue("Model Name");
268
		Cell cellModelNumberHeader = rowHeader.createCell(3);
269
		cellModelNumberHeader.setCellValue("Model Number");
270
		Cell cellColorHeader = rowHeader.createCell(4);
271
		cellColorHeader.setCellValue("Color");
272
		Cell cellTypeHeader = rowHeader.createCell(5);
273
		cellTypeHeader.setCellValue("Item Type");
274
		Cell cellOpeningBalanceHeader = rowHeader.createCell(6);
275
		cellOpeningBalanceHeader.setCellValue("Opening Balance");
276
		Cell cellInwardsHeader = rowHeader.createCell(9);
277
		cellInwardsHeader.setCellValue("Inwards");
278
		Cell cellOutwardsHeader = rowHeader.createCell(12);
279
		cellOutwardsHeader.setCellValue("Outwards");
280
		Cell cellClosingBalanceHeader = rowHeader.createCell(15);
281
		cellClosingBalanceHeader.setCellValue("Closing Balance");
282
		Row rowQuantityRateValue = sheet.createRow(1);
283
 
284
		for(int index = 6; index < 18; index = index + 3){
285
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
286
			cellQuantityHeader.setCellValue("Quantity");
287
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
288
			cellRateHeader.setCellValue("Rate");
289
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
290
			cellValueHeader.setCellValue("Value");
291
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
292
		}
293
		Font font = workbook.createFont();
294
		CellStyle cellStyle = workbook.createCellStyle();
295
		font.setBold(true);
296
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
297
		//font.setFontHeight((short)16);
298
		cellStyle.setFont(font);
299
		for(int i = 0; i < 18; i++){
300
			if(rowHeader.getCell(i) != null){
301
				rowHeader.getCell(i).setCellStyle(cellStyle);
302
			}
303
		}
304
		int openingQuantityTotal = 0;
305
		float openingValueTotal = 0;
306
		int inwardsQuantityTotal = 0;
307
		float inwardsValueTotal = 0;
308
		int outwardsQuantityTotal = 0;
309
		float outwardsValueTotal = 0;
310
		int closingQuantityTotal = 0;
311
		float closingValueTotal = 0;
312
		for(int index = 0; index < itemCompleteLedgerModels.size(); index++){
313
			ItemCompleteLedgerModel itemCompleteLedgerModel = itemCompleteLedgerModels.get(index);
314
	    	Row rowValues = sheet.createRow(index + 2);
315
	    	Cell cellItemId = rowValues.createCell(0);
316
	    	cellItemId.setCellValue(itemCompleteLedgerModel.getItemValue().getItemId());
317
	    	Cell cellBrand = rowValues.createCell(1);
318
	    	cellBrand.setCellValue(itemCompleteLedgerModel.getItemValue().getBrand());
319
	    	Cell cellModelName = rowValues.createCell(2);
320
	    	cellModelName.setCellValue(itemCompleteLedgerModel.getItemValue().getModelName());
321
	    	Cell cellModelNumber = rowValues.createCell(3);
322
	    	cellModelNumber.setCellValue(itemCompleteLedgerModel.getItemValue().getModelNumber());
323
	    	Cell cellColor = rowValues.createCell(4);
324
	    	cellColor.setCellValue(itemCompleteLedgerModel.getItemValue().getColor());
325
	    	Cell cellType = rowValues.createCell(5);
326
	    	cellType.setCellValue(itemCompleteLedgerModel.getItemValue().getItemType().toString());
327
	    	Cell cellOpeningQuantity = rowValues.createCell(6);
328
	    	Cell cellOpeningRate = rowValues.createCell(7);
329
	    	Cell cellOpeningValue = rowValues.createCell(8);
330
	    	if(itemCompleteLedgerModel.getOpeningLedger() == null){
331
	    		cellOpeningQuantity.setCellValue("-");
332
	    		cellOpeningRate.setCellValue("-");
333
	    		cellOpeningValue.setCellValue("-");
334
	    	}else{
335
	    		cellOpeningQuantity.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getQuantity());
336
	    		cellOpeningRate.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getRate());
337
	    		cellOpeningValue.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getValue());
338
	    		openingQuantityTotal = openingQuantityTotal + itemCompleteLedgerModel.getOpeningLedger().getQuantity();
339
	    		openingValueTotal = openingValueTotal + itemCompleteLedgerModel.getOpeningLedger().getValue();
340
	    	}
341
	    	Cell cellInwardsQuantity = rowValues.createCell(9);
342
	    	Cell cellInwardsRate = rowValues.createCell(10);
343
	    	Cell cellInwardsValue = rowValues.createCell(11);
344
	    	if(itemCompleteLedgerModel.getInwardsLedger() == null){
345
	    		cellInwardsQuantity.setCellValue("-");
346
	    		cellInwardsRate.setCellValue("-");
347
	    		cellInwardsValue.setCellValue("-");
348
	    	}else{
349
	    		cellInwardsQuantity.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getQuantity());
350
	    		cellInwardsRate.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getRate());
351
	    		cellInwardsValue.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getValue());
352
	    		inwardsQuantityTotal = inwardsQuantityTotal + itemCompleteLedgerModel.getInwardsLedger().getQuantity();
353
	    		inwardsValueTotal = inwardsValueTotal + itemCompleteLedgerModel.getInwardsLedger().getValue();
354
	    	}
355
	    	Cell cellOutwardsQuantity = rowValues.createCell(12);
356
	    	Cell cellOutwardsRate = rowValues.createCell(13);
357
	    	Cell cellOutwardsValue = rowValues.createCell(14);
358
	    	if(itemCompleteLedgerModel.getOutwardsLedger() == null){
359
	    		cellOutwardsQuantity.setCellValue("-");
360
	    		cellOutwardsRate.setCellValue("-");
361
	    		cellOutwardsValue.setCellValue("-");
362
	    	}else{
363
	    		cellOutwardsQuantity.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getQuantity());
364
	    		cellOutwardsRate.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getRate());
365
	    		cellOutwardsValue.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getValue());
366
	    		outwardsQuantityTotal = outwardsQuantityTotal + itemCompleteLedgerModel.getOutwardsLedger().getQuantity();
367
	    		outwardsValueTotal = outwardsValueTotal + itemCompleteLedgerModel.getOutwardsLedger().getValue();
368
	    	}
369
	    	Cell cellClosingQuantity = rowValues.createCell(15);
370
	    	Cell cellClosingRate = rowValues.createCell(16);
371
	    	Cell cellClosingValue = rowValues.createCell(17);
372
	    	if(itemCompleteLedgerModel.getClosingLedger() == null){
373
	    		cellClosingQuantity.setCellValue("-");
374
	    		cellClosingRate.setCellValue("-");
375
	    		cellClosingValue.setCellValue("-");
376
	    	}else{
377
	    		cellClosingQuantity.setCellValue(itemCompleteLedgerModel.getClosingLedger().getQuantity());
378
	    		cellClosingRate.setCellValue(itemCompleteLedgerModel.getClosingLedger().getRate());
379
	    		cellClosingValue.setCellValue(itemCompleteLedgerModel.getClosingLedger().getValue());
380
	    		closingQuantityTotal = closingQuantityTotal + itemCompleteLedgerModel.getClosingLedger().getQuantity();
381
	    		closingValueTotal = closingValueTotal + itemCompleteLedgerModel.getClosingLedger().getValue();
382
	    	}
383
	    }
384
 
385
		Row rowTotal = sheet.createRow(itemCompleteLedgerModels.size() + 2);
386
 
387
		if(openingQuantityTotal > 0){
388
			Cell cellOpeningQuantityTotal = rowTotal.createCell(6);
389
			cellOpeningQuantityTotal.setCellValue(openingQuantityTotal);
390
			Cell cellOpeningValueTotal = rowTotal.createCell(8);
391
			cellOpeningValueTotal.setCellValue(openingValueTotal);
392
		}
393
 
394
		if(inwardsQuantityTotal > 0){
395
			Cell cellInwardsQuantityTotal = rowTotal.createCell(9);
396
			cellInwardsQuantityTotal.setCellValue(inwardsQuantityTotal);
397
			Cell cellInwardsValueTotal = rowTotal.createCell(11);
398
			cellInwardsValueTotal.setCellValue(inwardsValueTotal);
399
		}
400
 
401
		if(outwardsQuantityTotal > 0){
402
			Cell cellOutwardsQuantityTotal = rowTotal.createCell(12);
403
			cellOutwardsQuantityTotal.setCellValue(outwardsQuantityTotal);
404
			Cell cellOutwardsValueTotal = rowTotal.createCell(14);
405
			cellOutwardsValueTotal.setCellValue(outwardsValueTotal);
406
		}
407
 
408
		if(closingQuantityTotal > 0){
409
			Cell cellClosingQuantityTotal = rowTotal.createCell(15);
410
			cellClosingQuantityTotal.setCellValue(closingQuantityTotal);
411
			Cell cellClosingValueTotal = rowTotal.createCell(17);
412
			cellClosingValueTotal.setCellValue(closingValueTotal);
413
		}
414
 
415
		for(int index = 0; index < 18; index++){
416
			sheet.autoSizeColumn(index);
417
		}
418
 
419
	    try{
420
			workbook.write(outputStream);
421
	    	workbook.close();
422
	    }catch(IOException ioException){
423
	    	LOGGER.error("Unable to generate excel file", ioException);
424
	    }
425
	}
21786 ashik.ali 426
}