Subversion Repositories SmartDukaan

Rev

Rev 26971 | Rev 26974 | 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;
24119 govind 33
import com.spice.profitmandi.common.model.CustomRetailer;
22470 ashik.ali 34
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
35
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
22521 ashik.ali 36
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
24107 govind 37
import com.spice.profitmandi.common.model.PartnerTargetModel;
21786 ashik.ali 38
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23017 ashik.ali 39
import com.spice.profitmandi.common.model.SchemeModel;
21786 ashik.ali 40
import com.spice.profitmandi.common.model.TagListingModel;
41
 
42
public class ExcelUtils {
43
	private static final String TAG_ID = "Tag Id";
44
	private static final String TAG_LABEL = "Tag Label";
45
	private static final String ITEM_ID = "Item Id";
46
	private static final String BRAND = "Brand";
47
	private static final String MODEL_NAME = "Model Name";
48
	private static final String MODEL_NUMBER = "Model Number";
49
	private static final String COLOR = "Color";
50
	private static final String SELLING_PRICE = "Selling Price";
22204 amit.gupta 51
	private static final String MOP = "MOP";
21786 ashik.ali 52
	private static final String SUPPORT_PRICE = "Support Price";
53
	private static final String START_DATE = "Start Date";
54
	private static final String TAG_LISTING = "Tag Listing";
24107 govind 55
	private static final String FOFO_ID = "fofoId";
56
	private static final String STORE_NAME = "storeName";
57
	private static final String EMAIL = "email";
24119 govind 58
	private static final String TARGET_VALUE = "targetValue";
59
 
23568 govind 60
	private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
24119 govind 61
 
62
	public static void main(String[] args) throws Throwable {
63
		// List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
64
		// writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
21786 ashik.ali 65
	}
24119 govind 66
 
22924 ashik.ali 67
	public static List<TagListingModel> parse(InputStream inputStream) throws Exception {
24119 govind 68
 
21786 ashik.ali 69
		List<TagListingModel> tagListings = new ArrayList<>();
70
		XSSFWorkbook myWorkBook = null;
24119 govind 71
		try {
72
			// FileInputStream fileInputStream = new
73
			// FileInputStream("/home/ashikali/tag_listing1.xlsx");
74
			myWorkBook = new XSSFWorkbook(inputStream);
75
 
21786 ashik.ali 76
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
24119 govind 77
			// Return first sheet from the XLSX workbook
21786 ashik.ali 78
			XSSFSheet mySheet = myWorkBook.getSheetAt(0);
22247 amit.gupta 79
			LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
24119 govind 80
 
81
			for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
22247 amit.gupta 82
				XSSFRow row = mySheet.getRow(rowNumber);
83
				LOGGER.info("row {}", row);
84
				TagListingModel tagListing = new TagListingModel();
24119 govind 85
				if (row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC) {
22247 amit.gupta 86
					tagListing.setTagId((Double.valueOf(row.getCell(0).getNumericCellValue())).intValue());
24119 govind 87
				} else {
88
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_ID,
89
							row.getCell(0).toString(), "TGLSTNG_VE_1010");
22226 amit.gupta 90
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
21786 ashik.ali 91
					throw profitMandiBusinessException;
92
				}
24119 govind 93
 
94
				if (row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.NUMERIC) {
22247 amit.gupta 95
					tagListing.setItemId(Double.valueOf(row.getCell(2).toString()).intValue());
24119 govind 96
				} else {
97
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
98
							ITEM_ID, row.getCell(2).toString(), "TGLSTNG_VE_1010");
22247 amit.gupta 99
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
100
					throw profitMandiBusinessException;
101
				}
22204 amit.gupta 102
 
24119 govind 103
				if (row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.NUMERIC) {
22247 amit.gupta 104
					tagListing.setSellingPrice(Double.valueOf(row.getCell(7).toString()).floatValue());
24119 govind 105
				} else {
106
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
107
							SELLING_PRICE, row.getCell(7), "TGLSTNG_VE_1010");
22226 amit.gupta 108
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
22209 amit.gupta 109
					throw profitMandiBusinessException;
21786 ashik.ali 110
				}
24119 govind 111
				if (row.getCell(8) != null && row.getCell(8).getCellTypeEnum() == CellType.NUMERIC) {
22247 amit.gupta 112
					tagListing.setMop(Double.valueOf(row.getCell(8).toString()).floatValue());
24119 govind 113
				} else {
114
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(MOP,
115
							row.getCell(8), "TGLSTNG_VE_1010");
22247 amit.gupta 116
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
117
					throw profitMandiBusinessException;
118
				}
24119 govind 119
				if (row.getCell(9) != null && row.getCell(9).getCellTypeEnum() == CellType.NUMERIC) {
22247 amit.gupta 120
					tagListing.setSupportPrice(Double.valueOf(row.getCell(9).toString()).floatValue());
24119 govind 121
				} else {
122
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
123
							SUPPORT_PRICE, row.getCell(9).toString(), "TGLSTNG_VE_1010");
22247 amit.gupta 124
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
125
					throw profitMandiBusinessException;
126
				}
24119 govind 127
				if (row.getCell(10) != null && row.getCell(10).getCellTypeEnum() == CellType.NUMERIC) {
22563 amit.gupta 128
					tagListing.setMaxDiscountPrice(Double.valueOf(row.getCell(10).toString()).floatValue());
24119 govind 129
				} else {
130
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
131
							SUPPORT_PRICE, row.getCell(10).toString(), "TGLSTNG_VE_1010");
22563 amit.gupta 132
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
133
					throw profitMandiBusinessException;
134
				}
24119 govind 135
				if (row.getCell(11) != null && HSSFDateUtil.isCellDateFormatted(row.getCell(11))) {
22865 amit.gupta 136
					Date date = row.getCell(11).getDateCellValue();
22247 amit.gupta 137
					LocalDateTime startDate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
138
					tagListing.setStartDate(startDate);
24119 govind 139
				} else {
140
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
141
							START_DATE, row.getCell(11).toString(), "TGLSTNG_VE_1010");
22247 amit.gupta 142
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
24119 govind 143
					throw profitMandiBusinessException;
22247 amit.gupta 144
				}
145
				tagListings.add(tagListing);
21786 ashik.ali 146
			}
147
			myWorkBook.close();
24119 govind 148
		} catch (IOException ioException) {
22206 amit.gupta 149
			ioException.printStackTrace();
24119 govind 150
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
151
					"EXL_VE_1000");
22247 amit.gupta 152
		} finally {
24119 govind 153
			if (myWorkBook != null) {
21786 ashik.ali 154
				try {
155
					myWorkBook.close();
156
				} catch (IOException e) {
157
					// TODO Auto-generated catch block
158
					e.printStackTrace();
159
				}
160
			}
161
		}
162
		return tagListings;
163
	}
24119 govind 164
 
165
	public static void writeInventoryItemAgingModels(List<InventoryItemAgingModel> inventoryItemAgingModels,
166
			List<Integer> intervals, OutputStream outputStream) {
22470 ashik.ali 167
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 168
 
169
		// CreationHelper createHelper = workbook.getCreationHelper();
26961 amit.gupta 170
		boolean showPartner = inventoryItemAgingModels.get(0).getFofoId() == 0;
171
		int nonValueColumns = 6;
22470 ashik.ali 172
		SXSSFSheet sheet = workbook.createSheet("InventoryItemAging");
173
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
174
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
175
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
176
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
177
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
178
		sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
179
		sheet.trackAllColumnsForAutoSizing();
26961 amit.gupta 180
 
181
		int rowIndex = 0;
182
		Row rowHeader = sheet.createRow(rowIndex++);
183
		Row rowPriceQuantity = sheet.createRow(rowIndex++);
184
		int i=0;
185
		if(showPartner) {
186
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
187
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
188
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 8));
189
			Cell cellFofoIdHeader = rowHeader.createCell(i++);
190
			cellFofoIdHeader.setCellValue("Partner Id");
191
			Cell cellStoreCodeHeader = rowHeader.createCell(i++);
192
			cellStoreCodeHeader.setCellValue("Store Code");
193
			Cell cellStoreNameHeader = rowHeader.createCell(i++);
194
			cellStoreNameHeader.setCellValue("Store Name");
195
			nonValueColumns = 9;
196
		}
197
		Cell cellItemIdHeader = rowHeader.createCell(i++);
22470 ashik.ali 198
		cellItemIdHeader.setCellValue("Item Id");
26961 amit.gupta 199
		Cell cellBrandHeader = rowHeader.createCell(i++);
22470 ashik.ali 200
		cellBrandHeader.setCellValue("Brand");
26961 amit.gupta 201
		Cell cellModelNameHeader = rowHeader.createCell(i++);
22470 ashik.ali 202
		cellModelNameHeader.setCellValue("Model Name");
26961 amit.gupta 203
		Cell cellModelNumberHeader = rowHeader.createCell(i++);
22470 ashik.ali 204
		cellModelNumberHeader.setCellValue("Model Number");
26961 amit.gupta 205
		Cell cellColorHeader = rowHeader.createCell(i++);
22470 ashik.ali 206
		cellColorHeader.setCellValue("Color");
26961 amit.gupta 207
		Cell cellTypeHeader = rowHeader.createCell(i++);
22470 ashik.ali 208
		cellTypeHeader.setCellValue("Item Type");
26961 amit.gupta 209
		for (int index = 0; index <= intervals.size(); index++) {
210
			Cell cellHeader = rowHeader.createCell(i++);
24119 govind 211
			if (index == 0) {
212
				cellHeader.setCellValue("Less Than " + intervals.get(index) + " Days");
213
			} else if (index < intervals.size()) {
22470 ashik.ali 214
				cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
24119 govind 215
			} else {
216
				cellHeader.setCellValue("More Than " + intervals.get(index - 1) + " Days");
22470 ashik.ali 217
			}
26961 amit.gupta 218
			sheet.addMergedRegion(new CellRangeAddress(0, 0, i-1, i));
219
			rowHeader.createCell(i++);
220
			Cell cellPrice = rowPriceQuantity.createCell(i-2);
22470 ashik.ali 221
			cellPrice.setCellValue("Price");
26961 amit.gupta 222
			Cell cellQuantity = rowPriceQuantity.createCell(i-1);
22470 ashik.ali 223
			cellQuantity.setCellValue("Quantity");
224
		}
26961 amit.gupta 225
 
22470 ashik.ali 226
		Font font = workbook.createFont();
26961 amit.gupta 227
		font.setBold(true);
22470 ashik.ali 228
		CellStyle cellStyle = workbook.createCellStyle();
229
		cellStyle.setFont(font);
26961 amit.gupta 230
		for (int j = 0; j < nonValueColumns + ((intervals.size()+1)) * 2; j++) {
231
			rowHeader.getCell(j).setCellStyle(cellStyle);
24119 govind 232
			if (rowPriceQuantity.getCell(i) != null) {
22470 ashik.ali 233
				rowPriceQuantity.getCell(i).setCellStyle(cellStyle);
234
			}
235
		}
26961 amit.gupta 236
		for (InventoryItemAgingModel inventoryItemAgingModel : inventoryItemAgingModels) {
26972 amit.gupta 237
			i=0;
26961 amit.gupta 238
			Row rowValues = sheet.createRow(rowIndex++);
239
			if(showPartner) {
240
				rowHeader.createCell(i++).setCellValue(inventoryItemAgingModel.getFofoId());
241
				rowHeader.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreCode());
242
				rowHeader.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreName());
243
			}
244
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getItemId());
245
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getBrand());
246
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getModelName());
247
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getModelNumber());
248
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getColor());
249
			rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getItemType().toString());
24119 govind 250
			List<InventoryItemAgingValue> inventoryItemAgingValues = inventoryItemAgingModel.getValues();
251
			// LOGGER.info("inventoryItemAgingValues {}", inventoryItemAgingValues);
26961 amit.gupta 252
			for (InventoryItemAgingValue inventoryItemAgingValue : inventoryItemAgingValues) {
24119 govind 253
				if (inventoryItemAgingValue != null) {
26961 amit.gupta 254
					rowValues.createCell(i++).setCellValue(inventoryItemAgingValue.getPrice());
255
					rowValues.createCell(i++).setCellValue(inventoryItemAgingValue.getQuantity());
24119 govind 256
				} else {
26961 amit.gupta 257
					rowValues.createCell(i++).setCellValue("-");
258
					rowValues.createCell(i++).setCellValue("-");
24119 govind 259
				}
260
			}
261
		}
262
 
26961 amit.gupta 263
		for (int index = 0; index < nonValueColumns + ((intervals.size()+1) * 2); index++) {
22470 ashik.ali 264
			sheet.autoSizeColumn(index);
265
		}
24119 govind 266
 
267
		try {
22486 ashik.ali 268
			workbook.write(outputStream);
24119 govind 269
			workbook.close();
270
		} catch (IOException ioException) {
271
			LOGGER.error("Unable to generate excel file", ioException);
272
		}
22470 ashik.ali 273
	}
24119 govind 274
 
25380 amit.gupta 275
	public static void writeItemCompleteLedgerModels(
276
			Map<String, List<ItemCompleteLedgerModel>> itemCompleteLedgerModelsMap, OutputStream outputStream) {
22521 ashik.ali 277
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 278
 
279
		// CreationHelper createHelper = workbook.getCreationHelper();
280
 
25380 amit.gupta 281
		for (Map.Entry<String, List<ItemCompleteLedgerModel>> itemCompleteLedgerModelsEntry : itemCompleteLedgerModelsMap
282
				.entrySet()) {
24215 amit.gupta 283
			SXSSFSheet sheet = workbook.createSheet(itemCompleteLedgerModelsEntry.getKey());
284
			List<ItemCompleteLedgerModel> itemCompleteLedgerModels = itemCompleteLedgerModelsEntry.getValue();
285
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
286
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
287
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
288
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
289
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
290
			sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
291
			sheet.trackAllColumnsForAutoSizing();
25380 amit.gupta 292
 
24215 amit.gupta 293
			Row rowHeader = sheet.createRow(0);
294
			Cell cellItemIdHeader = rowHeader.createCell(0);
295
			cellItemIdHeader.setCellValue("Item Id");
296
			Cell cellBrandHeader = rowHeader.createCell(1);
297
			cellBrandHeader.setCellValue("Brand");
298
			Cell cellModelNameHeader = rowHeader.createCell(2);
299
			cellModelNameHeader.setCellValue("Model Name");
300
			Cell cellModelNumberHeader = rowHeader.createCell(3);
301
			cellModelNumberHeader.setCellValue("Model Number");
302
			Cell cellColorHeader = rowHeader.createCell(4);
303
			cellColorHeader.setCellValue("Color");
304
			Cell cellTypeHeader = rowHeader.createCell(5);
305
			cellTypeHeader.setCellValue("Item Type");
306
			Cell cellOpeningBalanceHeader = rowHeader.createCell(6);
307
			cellOpeningBalanceHeader.setCellValue("Opening Balance");
308
			Cell cellInwardsHeader = rowHeader.createCell(9);
309
			cellInwardsHeader.setCellValue("Inwards");
310
			Cell cellOutwardsHeader = rowHeader.createCell(12);
311
			cellOutwardsHeader.setCellValue("Outwards");
312
			Cell cellClosingBalanceHeader = rowHeader.createCell(15);
313
			cellClosingBalanceHeader.setCellValue("Closing Balance");
314
			Row rowQuantityRateValue = sheet.createRow(1);
25380 amit.gupta 315
 
24215 amit.gupta 316
			for (int index = 6; index < 18; index = index + 3) {
317
				Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
318
				cellQuantityHeader.setCellValue("Quantity");
319
				Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
320
				cellRateHeader.setCellValue("Rate");
321
				Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
322
				cellValueHeader.setCellValue("Value");
323
				sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
22521 ashik.ali 324
			}
24215 amit.gupta 325
			Font font = workbook.createFont();
326
			CellStyle cellStyle = workbook.createCellStyle();
327
			font.setBold(true);
328
			cellStyle.setAlignment(HorizontalAlignment.CENTER);
329
			// font.setFontHeight((short)16);
330
			cellStyle.setFont(font);
331
			for (int i = 0; i < 18; i++) {
332
				if (rowHeader.getCell(i) != null) {
333
					rowHeader.getCell(i).setCellStyle(cellStyle);
334
				}
24119 govind 335
			}
24215 amit.gupta 336
			int openingQuantityTotal = 0;
337
			float openingValueTotal = 0;
338
			int inwardsQuantityTotal = 0;
339
			float inwardsValueTotal = 0;
340
			int outwardsQuantityTotal = 0;
341
			float outwardsValueTotal = 0;
342
			int closingQuantityTotal = 0;
343
			float closingValueTotal = 0;
344
			for (int index = 0; index < itemCompleteLedgerModels.size(); index++) {
345
				ItemCompleteLedgerModel itemCompleteLedgerModel = itemCompleteLedgerModels.get(index);
346
				Row rowValues = sheet.createRow(index + 2);
347
				Cell cellItemId = rowValues.createCell(0);
348
				cellItemId.setCellValue(itemCompleteLedgerModel.getItemValue().getItemId());
349
				Cell cellBrand = rowValues.createCell(1);
350
				cellBrand.setCellValue(itemCompleteLedgerModel.getItemValue().getBrand());
351
				Cell cellModelName = rowValues.createCell(2);
352
				cellModelName.setCellValue(itemCompleteLedgerModel.getItemValue().getModelName());
353
				Cell cellModelNumber = rowValues.createCell(3);
354
				cellModelNumber.setCellValue(itemCompleteLedgerModel.getItemValue().getModelNumber());
355
				Cell cellColor = rowValues.createCell(4);
356
				cellColor.setCellValue(itemCompleteLedgerModel.getItemValue().getColor());
357
				Cell cellType = rowValues.createCell(5);
358
				cellType.setCellValue(itemCompleteLedgerModel.getItemValue().getItemType().toString());
359
				Cell cellOpeningQuantity = rowValues.createCell(6);
360
				Cell cellOpeningRate = rowValues.createCell(7);
361
				Cell cellOpeningValue = rowValues.createCell(8);
362
				if (itemCompleteLedgerModel.getOpeningLedger() == null) {
363
					cellOpeningQuantity.setCellValue("-");
364
					cellOpeningRate.setCellValue("-");
365
					cellOpeningValue.setCellValue("-");
366
				} else {
367
					cellOpeningQuantity.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getQuantity());
368
					cellOpeningRate.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getRate());
369
					cellOpeningValue.setCellValue(itemCompleteLedgerModel.getOpeningLedger().getValue());
25380 amit.gupta 370
					openingQuantityTotal = openingQuantityTotal
371
							+ itemCompleteLedgerModel.getOpeningLedger().getQuantity();
24215 amit.gupta 372
					openingValueTotal = openingValueTotal + itemCompleteLedgerModel.getOpeningLedger().getValue();
373
				}
374
				Cell cellInwardsQuantity = rowValues.createCell(9);
375
				Cell cellInwardsRate = rowValues.createCell(10);
376
				Cell cellInwardsValue = rowValues.createCell(11);
377
				if (itemCompleteLedgerModel.getInwardsLedger() == null) {
378
					cellInwardsQuantity.setCellValue("-");
379
					cellInwardsRate.setCellValue("-");
380
					cellInwardsValue.setCellValue("-");
381
				} else {
382
					cellInwardsQuantity.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getQuantity());
383
					cellInwardsRate.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getRate());
384
					cellInwardsValue.setCellValue(itemCompleteLedgerModel.getInwardsLedger().getValue());
25380 amit.gupta 385
					inwardsQuantityTotal = inwardsQuantityTotal
386
							+ itemCompleteLedgerModel.getInwardsLedger().getQuantity();
24215 amit.gupta 387
					inwardsValueTotal = inwardsValueTotal + itemCompleteLedgerModel.getInwardsLedger().getValue();
388
				}
389
				Cell cellOutwardsQuantity = rowValues.createCell(12);
390
				Cell cellOutwardsRate = rowValues.createCell(13);
391
				Cell cellOutwardsValue = rowValues.createCell(14);
392
				if (itemCompleteLedgerModel.getOutwardsLedger() == null) {
393
					cellOutwardsQuantity.setCellValue("-");
394
					cellOutwardsRate.setCellValue("-");
395
					cellOutwardsValue.setCellValue("-");
396
				} else {
397
					cellOutwardsQuantity.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getQuantity());
398
					cellOutwardsRate.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getRate());
399
					cellOutwardsValue.setCellValue(itemCompleteLedgerModel.getOutwardsLedger().getValue());
400
					outwardsQuantityTotal = outwardsQuantityTotal
401
							+ itemCompleteLedgerModel.getOutwardsLedger().getQuantity();
402
					outwardsValueTotal = outwardsValueTotal + itemCompleteLedgerModel.getOutwardsLedger().getValue();
403
				}
404
				Cell cellClosingQuantity = rowValues.createCell(15);
405
				Cell cellClosingRate = rowValues.createCell(16);
406
				Cell cellClosingValue = rowValues.createCell(17);
407
				if (itemCompleteLedgerModel.getClosingLedger() == null) {
408
					cellClosingQuantity.setCellValue("-");
409
					cellClosingRate.setCellValue("-");
410
					cellClosingValue.setCellValue("-");
411
				} else {
412
					cellClosingQuantity.setCellValue(itemCompleteLedgerModel.getClosingLedger().getQuantity());
413
					cellClosingRate.setCellValue(itemCompleteLedgerModel.getClosingLedger().getRate());
414
					cellClosingValue.setCellValue(itemCompleteLedgerModel.getClosingLedger().getValue());
25380 amit.gupta 415
					closingQuantityTotal = closingQuantityTotal
416
							+ itemCompleteLedgerModel.getClosingLedger().getQuantity();
24215 amit.gupta 417
					closingValueTotal = closingValueTotal + itemCompleteLedgerModel.getClosingLedger().getValue();
418
				}
24119 govind 419
			}
25380 amit.gupta 420
 
24215 amit.gupta 421
			Row rowTotal = sheet.createRow(itemCompleteLedgerModels.size() + 2);
25380 amit.gupta 422
 
24215 amit.gupta 423
			if (openingQuantityTotal > 0) {
424
				Cell cellOpeningQuantityTotal = rowTotal.createCell(6);
425
				cellOpeningQuantityTotal.setCellValue(openingQuantityTotal);
426
				Cell cellOpeningValueTotal = rowTotal.createCell(8);
427
				cellOpeningValueTotal.setCellValue(openingValueTotal);
24119 govind 428
			}
25380 amit.gupta 429
 
24215 amit.gupta 430
			if (inwardsQuantityTotal > 0) {
431
				Cell cellInwardsQuantityTotal = rowTotal.createCell(9);
432
				cellInwardsQuantityTotal.setCellValue(inwardsQuantityTotal);
433
				Cell cellInwardsValueTotal = rowTotal.createCell(11);
434
				cellInwardsValueTotal.setCellValue(inwardsValueTotal);
24119 govind 435
			}
25380 amit.gupta 436
 
24215 amit.gupta 437
			if (outwardsQuantityTotal > 0) {
438
				Cell cellOutwardsQuantityTotal = rowTotal.createCell(12);
439
				cellOutwardsQuantityTotal.setCellValue(outwardsQuantityTotal);
440
				Cell cellOutwardsValueTotal = rowTotal.createCell(14);
441
				cellOutwardsValueTotal.setCellValue(outwardsValueTotal);
442
			}
25380 amit.gupta 443
 
24215 amit.gupta 444
			if (closingQuantityTotal > 0) {
445
				Cell cellClosingQuantityTotal = rowTotal.createCell(15);
446
				cellClosingQuantityTotal.setCellValue(closingQuantityTotal);
447
				Cell cellClosingValueTotal = rowTotal.createCell(17);
448
				cellClosingValueTotal.setCellValue(closingValueTotal);
449
			}
25380 amit.gupta 450
 
24215 amit.gupta 451
			for (int index = 0; index < 18; index++) {
452
				sheet.autoSizeColumn(index);
453
			}
24119 govind 454
		}
24222 amit.gupta 455
		try {
456
			workbook.write(outputStream);
457
			workbook.close();
458
		} catch (IOException ioException) {
459
			LOGGER.error("Unable to generate excel file", ioException);
460
		}
22521 ashik.ali 461
	}
24119 govind 462
 
463
	public static void writeSchemeModels(List<SchemeModel> schemeModels, OutputStream outputStream) {
23017 ashik.ali 464
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 465
 
466
		// CreationHelper createHelper = workbook.getCreationHelper();
467
 
23017 ashik.ali 468
		SXSSFSheet sheet = workbook.createSheet("Schemes");
469
		sheet.trackAllColumnsForAutoSizing();
24119 govind 470
 
471
		Row rowHeader = sheet.createRow(0);
472
		Cell cellSchemeIdHeader = rowHeader.createCell(0);
23017 ashik.ali 473
		cellSchemeIdHeader.setCellValue("Scheme Id");
474
		Cell cellNameHeader = rowHeader.createCell(1);
475
		cellNameHeader.setCellValue("Name");
476
		Cell cellDescriptionHeader = rowHeader.createCell(2);
477
		cellDescriptionHeader.setCellValue("Description");
478
		Cell cellSchemeTypeHeader = rowHeader.createCell(3);
479
		cellSchemeTypeHeader.setCellValue("Scheme Type");
480
		Cell cellAmountTypeHeader = rowHeader.createCell(4);
481
		cellAmountTypeHeader.setCellValue("Amount Type");
482
		Cell cellAmountHeader = rowHeader.createCell(5);
483
		cellAmountHeader.setCellValue("Amount");
484
		Cell cellStartDateTimeHeader = rowHeader.createCell(6);
485
		cellStartDateTimeHeader.setCellValue("Start Date Time");
486
		Cell cellEndDateTimeHeader = rowHeader.createCell(7);
487
		cellEndDateTimeHeader.setCellValue("End Date Time");
488
		Cell cellCreatedAtHeader = rowHeader.createCell(8);
489
		cellCreatedAtHeader.setCellValue("Created At");
490
		Cell cellActiveHeader = rowHeader.createCell(9);
491
		cellActiveHeader.setCellValue("Active");
492
		Cell cellExpireHeader = rowHeader.createCell(10);
493
		cellExpireHeader.setCellValue("Expire");
494
		Cell cellCreatedByHeader = rowHeader.createCell(11);
495
		cellCreatedByHeader.setCellValue("Created By");
496
		Cell cellItemIdsHeader = rowHeader.createCell(12);
497
		cellItemIdsHeader.setCellValue("Item Ids");
498
		Cell cellRetailerIdsHeader = rowHeader.createCell(13);
499
		cellRetailerIdsHeader.setCellValue("Retailer Ids");
24119 govind 500
		// Row rowQuantityRateValue = sheet.createRow(1);
501
 
502
		/*
503
		 * for(int index = 6; index < 18; index = index + 3){ Cell cellQuantityHeader =
504
		 * rowQuantityRateValue.createCell(index);
505
		 * cellQuantityHeader.setCellValue("Quantity"); Cell cellRateHeader =
506
		 * rowQuantityRateValue.createCell(index + 1);
507
		 * cellRateHeader.setCellValue("Rate"); Cell cellValueHeader =
508
		 * rowQuantityRateValue.createCell(index + 2);
509
		 * cellValueHeader.setCellValue("Value"); sheet.addMergedRegion(new
510
		 * CellRangeAddress(0, 0, index, index + 2)); }
511
		 */
23017 ashik.ali 512
		Font font = workbook.createFont();
513
		CellStyle cellStyle = workbook.createCellStyle();
514
		font.setBold(true);
515
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
24119 govind 516
		// font.setFontHeight((short)16);
23017 ashik.ali 517
		cellStyle.setFont(font);
24119 govind 518
		for (int i = 0; i < 14; i++) {
519
			if (rowHeader.getCell(i) != null) {
23017 ashik.ali 520
				rowHeader.getCell(i).setCellStyle(cellStyle);
521
			}
522
		}
523
 
24119 govind 524
		for (int index = 0; index < schemeModels.size(); index++) {
23017 ashik.ali 525
			SchemeModel schemeModel = schemeModels.get(index);
24119 govind 526
			// ItemCompleteLedgerModel itemCompleteLedgerModel =
527
			// itemCompleteLedgerModels.get(index);
528
			Row rowValues = sheet.createRow(index + 1);
529
			Cell cellSchemeId = rowValues.createCell(0);
23017 ashik.ali 530
			cellSchemeId.setCellValue(schemeModel.getSchemeId());
531
			Cell cellName = rowValues.createCell(1);
532
			cellName.setCellValue(schemeModel.getName());
533
			Cell cellDescription = rowValues.createCell(2);
534
			cellDescription.setCellValue(schemeModel.getDescription());
535
			Cell cellSchemeType = rowValues.createCell(3);
536
			cellSchemeType.setCellValue(schemeModel.getSchemeType());
537
			Cell cellAmountType = rowValues.createCell(4);
538
			cellAmountType.setCellValue(schemeModel.getAmountType());
539
			Cell cellAmount = rowValues.createCell(5);
540
			cellAmount.setCellValue(schemeModel.getAmount());
541
			Cell cellStartDateTime = rowValues.createCell(6);
542
			cellStartDateTime.setCellValue(schemeModel.getStartDateTime());
543
			Cell cellEndDateTime = rowValues.createCell(7);
544
			cellEndDateTime.setCellValue(schemeModel.getEndDateTime());
545
			Cell cellCreatedAt = rowValues.createCell(8);
546
			cellCreatedAt.setCellValue(schemeModel.getCreateTimestamp());
547
			Cell cellActive = rowValues.createCell(9);
24119 govind 548
			if (schemeModel.getActiveTimestamp() != null) {
23017 ashik.ali 549
				cellActive.setCellValue(schemeModel.getActiveTimestamp());
24119 govind 550
			} else {
23017 ashik.ali 551
				cellActive.setCellValue("False");
552
			}
553
			Cell cellExpire = rowValues.createCell(10);
24119 govind 554
			if (schemeModel.getExpireTimestamp() != null) {
23017 ashik.ali 555
				cellExpire.setCellValue(schemeModel.getExpireTimestamp());
24119 govind 556
			} else {
23017 ashik.ali 557
				cellExpire.setCellValue("False");
558
			}
559
			Cell cellCreatedBy = rowValues.createCell(11);
560
			cellCreatedBy.setCellValue(schemeModel.getCreatedBy());
561
			Cell cellItemIds = rowValues.createCell(12);
23338 ashik.ali 562
			cellItemIds.setCellValue(schemeModel.getItemStringMap().toString());
23017 ashik.ali 563
			Cell cellRetailerIds = rowValues.createCell(13);
564
			cellRetailerIds.setCellValue(schemeModel.getRetailerIdsString());
23338 ashik.ali 565
			int maxHeight = Math.max(schemeModel.getItemStringMap().size(), schemeModel.getRetailerIds().size());
24119 govind 566
			if (maxHeight > 1) {
567
				rowValues.setHeight((short) (maxHeight * 240));
23017 ashik.ali 568
			}
24119 govind 569
		}
570
 
571
		for (int index = 0; index < 14; index++) {
23017 ashik.ali 572
			sheet.autoSizeColumn(index);
573
		}
24119 govind 574
 
575
		try {
23017 ashik.ali 576
			workbook.write(outputStream);
24119 govind 577
			workbook.close();
578
		} catch (IOException ioException) {
579
			LOGGER.error("Unable to generate excel file", ioException);
580
		}
23017 ashik.ali 581
	}
24119 govind 582
 
583
	public static void writePriceDrop(Map<String, String> priceDropIMEIfofoId, int itemId, OutputStream outputStream) {
23819 govind 584
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 585
 
586
		// CreationHelper createHelper = workbook.getCreationHelper();
587
 
23819 govind 588
		SXSSFSheet sheet = workbook.createSheet("Schemes");
589
		sheet.trackAllColumnsForAutoSizing();
24119 govind 590
 
591
		Row rowHeader = sheet.createRow(0);
592
		Cell cellItemHeader = rowHeader.createCell(0);
593
		cellItemHeader.setCellValue("ITEMID");
23819 govind 594
		Cell cellIMEIHeader = rowHeader.createCell(1);
595
		cellIMEIHeader.setCellValue("IMEI");
596
		Cell cellFOFOIDHeader = rowHeader.createCell(2);
597
		cellFOFOIDHeader.setCellValue("RETAILERNAME");
24119 govind 598
		// Row rowQuantityRateValue = sheet.createRow(1);
599
 
600
		/*
601
		 * for(int index = 6; index < 18; index = index + 3){ Cell cellQuantityHeader =
602
		 * rowQuantityRateValue.createCell(index);
603
		 * cellQuantityHeader.setCellValue("Quantity"); Cell cellRateHeader =
604
		 * rowQuantityRateValue.createCell(index + 1);
605
		 * cellRateHeader.setCellValue("Rate"); Cell cellValueHeader =
606
		 * rowQuantityRateValue.createCell(index + 2);
607
		 * cellValueHeader.setCellValue("Value"); sheet.addMergedRegion(new
608
		 * CellRangeAddress(0, 0, index, index + 2)); }
609
		 */
23819 govind 610
		Font font = workbook.createFont();
611
		CellStyle cellStyle = workbook.createCellStyle();
612
		font.setBold(true);
613
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
24119 govind 614
		// font.setFontHeight((short)16);
23819 govind 615
		cellStyle.setFont(font);
24119 govind 616
		for (int i = 0; i < 14; i++) {
617
			if (rowHeader.getCell(i) != null) {
23819 govind 618
				rowHeader.getCell(i).setCellStyle(cellStyle);
619
			}
620
		}
24119 govind 621
		LinkedHashMap<String, String> priceAmount = new LinkedHashMap<>(priceDropIMEIfofoId);
622
		Set<String> keyset = priceAmount.keySet();
23819 govind 623
		int rownum = 1;
624
		for (String key : keyset) {
24119 govind 625
			Row row = sheet.createRow(rownum++);
626
			String objArr = priceAmount.get(key);
627
			int cellnum = 0;
628
			Cell cell = row.createCell(cellnum++);
629
			cell.setCellValue(itemId);
630
			Cell cell1 = row.createCell(cellnum++);
631
			cell1.setCellValue(key);
632
			Cell cell2 = row.createCell(cellnum++);
633
			cell2.setCellValue(priceAmount.get(key));
634
		}
635
 
636
		for (int index = 0; index < 14; index++) {
23819 govind 637
			sheet.autoSizeColumn(index);
638
		}
24119 govind 639
 
640
		try {
23819 govind 641
			workbook.write(outputStream);
24119 govind 642
			workbook.close();
643
		} catch (IOException ioException) {
644
			LOGGER.error("Unable to generate excel file", ioException);
645
		}
23819 govind 646
	}
24119 govind 647
 
648
	public static void writePriceDropForAllIMEI(Map<String, String> priceDropAmount, OutputStream outputStream) {
23819 govind 649
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 650
 
651
		// CreationHelper createHelper = workbook.getCreationHelper();
652
 
23819 govind 653
		SXSSFSheet sheet = workbook.createSheet("Schemes");
654
		sheet.trackAllColumnsForAutoSizing();
24119 govind 655
 
656
		Row rowHeader = sheet.createRow(0);
657
		Cell cellItemHeader = rowHeader.createCell(0);
658
		cellItemHeader.setCellValue("Itemdescription");
23819 govind 659
		Cell cellIMEIHeader = rowHeader.createCell(1);
660
		cellIMEIHeader.setCellValue("IMEI");
24119 govind 661
		// Row rowQuantityRateValue = sheet.createRow(1);
662
 
663
		/*
664
		 * for(int index = 6; index < 18; index = index + 3){ Cell cellQuantityHeader =
665
		 * rowQuantityRateValue.createCell(index);
666
		 * cellQuantityHeader.setCellValue("Quantity"); Cell cellRateHeader =
667
		 * rowQuantityRateValue.createCell(index + 1);
668
		 * cellRateHeader.setCellValue("Rate"); Cell cellValueHeader =
669
		 * rowQuantityRateValue.createCell(index + 2);
670
		 * cellValueHeader.setCellValue("Value"); sheet.addMergedRegion(new
671
		 * CellRangeAddress(0, 0, index, index + 2)); }
672
		 */
23819 govind 673
		Font font = workbook.createFont();
674
		CellStyle cellStyle = workbook.createCellStyle();
675
		font.setBold(true);
676
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
24119 govind 677
		// font.setFontHeight((short)16);
23819 govind 678
		cellStyle.setFont(font);
24119 govind 679
		for (int i = 0; i < 14; i++) {
680
			if (rowHeader.getCell(i) != null) {
23819 govind 681
				rowHeader.getCell(i).setCellStyle(cellStyle);
682
			}
683
		}
24119 govind 684
		Set<String> keyset = priceDropAmount.keySet();
23819 govind 685
		int rownum = 1;
686
		for (String key : keyset) {
24119 govind 687
			Row row = sheet.createRow(rownum++);
688
			String objArr = priceDropAmount.get(key);
689
			int cellnum = 0;
690
			Cell cell = row.createCell(cellnum++);
691
			cell.setCellValue(priceDropAmount.get(key));
692
			Cell cell1 = row.createCell(cellnum++);
693
			cell1.setCellValue(key);
694
		}
695
 
696
		for (int index = 0; index < 14; index++) {
23819 govind 697
			sheet.autoSizeColumn(index);
698
		}
24119 govind 699
 
700
		try {
23819 govind 701
			workbook.write(outputStream);
24119 govind 702
			workbook.close();
703
		} catch (IOException ioException) {
704
			LOGGER.error("Unable to generate excel file", ioException);
705
		}
23819 govind 706
	}
24119 govind 707
 
708
	public static List<PartnerTargetModel> parseFromExcel(InputStream inputStream) throws Exception {
709
 
24107 govind 710
		List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
711
		XSSFWorkbook myWorkBook = null;
24119 govind 712
		try {
713
			// FileInputStream fileInputStream = new
714
			// FileInputStream("/home/ashikali/tag_listing1.xlsx");
715
			myWorkBook = new XSSFWorkbook(inputStream);
716
 
24107 govind 717
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
24119 govind 718
			// Return first sheet from the XLSX workbook
24107 govind 719
			XSSFSheet mySheet = myWorkBook.getSheetAt(0);
720
			LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
24119 govind 721
 
722
			for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
24107 govind 723
				XSSFRow row = mySheet.getRow(rowNumber);
724
				LOGGER.info("row {}", row);
725
				PartnerTargetModel partnerTargetModel = new PartnerTargetModel();
24119 govind 726
 
727
				if (row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC) {
24107 govind 728
					partnerTargetModel.setFofoId((int) row.getCell(0).getNumericCellValue());
24119 govind 729
				} else {
730
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
731
							FOFO_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
24107 govind 732
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
733
					throw profitMandiBusinessException;
734
				}
24119 govind 735
				if (row.getCell(3) != null && row.getCell(3).getCellTypeEnum() == CellType.NUMERIC) {
736
					partnerTargetModel.setTargetValue((int) row.getCell(3).getNumericCellValue());
737
				} else {
738
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
739
							TARGET_VALUE, row.getCell(8), "TGLSTNG_VE_1010");
24107 govind 740
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
741
					throw profitMandiBusinessException;
742
				}
743
 
744
				partnerTargetModels.add(partnerTargetModel);
745
			}
746
			myWorkBook.close();
24119 govind 747
		} catch (IOException ioException) {
24107 govind 748
			ioException.printStackTrace();
24119 govind 749
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
750
					"EXL_VE_1000");
24107 govind 751
		} finally {
24119 govind 752
			if (myWorkBook != null) {
24107 govind 753
				try {
754
					myWorkBook.close();
755
				} catch (IOException e) {
756
					// TODO Auto-generated catch block
757
					e.printStackTrace();
758
				}
759
			}
760
		}
761
		return partnerTargetModels;
762
	}
24119 govind 763
 
25380 amit.gupta 764
	public static void writeDailySaleReportVsTargetForPartner(Map<Integer, String> targetIdAndTargetNameMap,
765
			Map<Integer, Float> targetIdAndtargetValuesMap, Map<Integer, Double> targetIdAndsaleValuesMap,
24184 govind 766
			Map<Integer, CustomRetailer> targetIdAndCustomRetailerMap, Map<Integer, String> targetIdAndSlabNamesMap,
25380 amit.gupta 767
			Map<Integer, Double> targetIdAndsaleValuesPercentageMap,
768
			Map<Integer, Float> targetIdAndtargetdailyAverageSaleMap,
24184 govind 769
			Map<Integer, Double> targetIdAndRemainingTargetMap, Map<Integer, Double> targetIdAndtodayAchievementsMap,
25380 amit.gupta 770
			Map<Integer, String> targetIdAndSalesHeadMap, OutputStream outputStream) {
24184 govind 771
		SXSSFWorkbook workbook = new SXSSFWorkbook();
24119 govind 772
 
24184 govind 773
		// CreationHelper createHelper = workbook.getCreationHelper();
774
 
775
		SXSSFSheet sheet = workbook.createSheet("DailySaleReports");
776
		sheet.trackAllColumnsForAutoSizing();
777
 
778
		Row rowHeader = sheet.createRow(0);
24188 govind 779
		Cell cellStoreName = rowHeader.createCell(0);
780
		cellStoreName.setCellValue("Store Name");
24184 govind 781
		Cell cellBusiness = rowHeader.createCell(1);
782
		cellBusiness.setCellValue("Business Manager");
783
		Cell cellAssistant = rowHeader.createCell(2);
784
		cellAssistant.setCellValue("Assistant Manager");
24188 govind 785
		Cell cellSchemeName = rowHeader.createCell(3);
786
		cellSchemeName.setCellValue("Scheme Name");
24184 govind 787
		Cell cellTargetValue = rowHeader.createCell(4);
24188 govind 788
		cellTargetValue.setCellValue("Scheme Target");
789
		Cell cellMonthlySaleValue = rowHeader.createCell(5);
790
		cellMonthlySaleValue.setCellValue("Total Achievement");
791
		Cell cellMonthlySaleValuePercentage = rowHeader.createCell(6);
792
		cellMonthlySaleValuePercentage.setCellValue("Today Achievement Percentage");
793
		Cell cellDailyTargetValue = rowHeader.createCell(7);
794
		cellDailyTargetValue.setCellValue("Daily Target");
795
		Cell cellTodayAchievement = rowHeader.createCell(8);
796
		cellTodayAchievement.setCellValue("Today Achievement");
24184 govind 797
		Cell cellRemainingTarget = rowHeader.createCell(9);
24188 govind 798
		cellRemainingTarget.setCellValue("Remaining Target");
24184 govind 799
		Cell cellEligibility = rowHeader.createCell(10);
800
		cellEligibility.setCellValue("Eligibility");
801
		Font font = workbook.createFont();
802
		CellStyle cellStyle = workbook.createCellStyle();
803
		font.setBold(true);
804
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
805
		// font.setFontHeight((short)16);
806
		cellStyle.setFont(font);
807
		for (int i = 0; i < 14; i++) {
808
			if (rowHeader.getCell(i) != null) {
809
				rowHeader.getCell(i).setCellStyle(cellStyle);
810
			}
811
		}
812
		int rownum = 1;
813
		for (Integer targetId : targetIdAndTargetNameMap.keySet()) {
814
			Row row = sheet.createRow(rownum++);
815
			int cellnum = 0;
24188 govind 816
			Cell cellPartner = row.createCell(cellnum++);
817
			if (targetIdAndCustomRetailerMap.get(targetId) != null) {
818
				cellPartner.setCellValue(targetIdAndCustomRetailerMap.get(targetId).getBusinessName());
24184 govind 819
			} else {
24188 govind 820
				cellPartner.setCellValue("-");
24184 govind 821
			}
25380 amit.gupta 822
 
24184 govind 823
			Cell cellBusinessManager = row.createCell(cellnum++);
24186 govind 824
			if (targetIdAndSalesHeadMap.get(targetId) != null) {
825
				if (targetIdAndSalesHeadMap.get(targetId).equals("Kamal")) {
24184 govind 826
					cellBusinessManager.setCellValue("Mohinder");
827
				} else {
24186 govind 828
					cellBusinessManager.setCellValue(targetIdAndSalesHeadMap.get(targetId));
24184 govind 829
				}
830
			} else {
831
				cellBusinessManager.setCellValue("-");
832
			}
833
			Cell cellAssistantManager = row.createCell(cellnum++);
834
			if (targetIdAndSalesHeadMap.get(targetId) != null) {
835
				if (targetIdAndSalesHeadMap.get(targetId).equals("Kamal")) {
836
					cellAssistantManager.setCellValue(targetIdAndSalesHeadMap.get(targetId));
837
				} else {
838
					cellAssistantManager.setCellValue("");
839
				}
840
			} else {
841
				cellAssistantManager.setCellValue("");
842
			}
24188 govind 843
			Cell cellTargetName = row.createCell(cellnum++);
25380 amit.gupta 844
			if (targetIdAndTargetNameMap.get(targetId) == null || targetIdAndTargetNameMap.get(targetId) == "") {
24188 govind 845
				cellTargetName.setCellValue("");
25380 amit.gupta 846
 
24186 govind 847
			} else {
24188 govind 848
				cellTargetName.setCellValue(targetIdAndTargetNameMap.get(targetId));
24186 govind 849
			}
24184 govind 850
			Cell cellMTDTargetValue = row.createCell(cellnum++);
851
			if (targetIdAndtargetValuesMap.get(targetId) != null) {
852
				cellMTDTargetValue.setCellValue(targetIdAndtargetValuesMap.get(targetId));
853
			} else {
854
				cellMTDTargetValue.setCellValue("-");
855
			}
856
			Cell cellMTDAchievement = row.createCell(cellnum++);
857
			if (targetIdAndsaleValuesMap.get(targetId) != null) {
858
				cellMTDAchievement.setCellValue(targetIdAndsaleValuesMap.get(targetId));
859
			} else {
860
				cellMTDAchievement.setCellValue(0);
861
			}
862
			Cell cellMTDAchievementPercentage = row.createCell(cellnum++);
863
			if (targetIdAndsaleValuesPercentageMap.get(targetId) != null) {
864
				cellMTDAchievementPercentage.setCellValue(targetIdAndsaleValuesPercentageMap.get(targetId) + "%");
865
			} else {
866
				cellMTDAchievementPercentage.setCellValue(0 + "%");
867
			}
868
 
24188 govind 869
			Cell cellDailyTargetValue1 = row.createCell(cellnum++);
870
			if (targetIdAndtargetdailyAverageSaleMap.get(targetId) != null) {
25380 amit.gupta 871
				String formatting = FormattingUtils
872
						.formatDecimalTwoDigits(targetIdAndtargetdailyAverageSaleMap.get(targetId));
24188 govind 873
				cellDailyTargetValue1.setCellValue(formatting);
874
			} else {
875
				cellDailyTargetValue1.setCellValue(0);
876
			}
877
			Cell cellTodayAchieveMentSaleValue = row.createCell(cellnum++);
878
			if (targetIdAndtodayAchievementsMap.get(targetId) != null) {
879
				cellTodayAchieveMentSaleValue.setCellValue(targetIdAndtodayAchievementsMap.get(targetId));
880
			} else {
881
				cellTodayAchieveMentSaleValue.setCellValue(0);
882
			}
25380 amit.gupta 883
 
24184 govind 884
			Cell cellRemaining = row.createCell(cellnum++);
885
			if (targetIdAndRemainingTargetMap.get(targetId) != null) {
886
				cellRemaining.setCellValue(targetIdAndRemainingTargetMap.get(targetId));
887
			} else {
888
				cellRemaining.setCellValue(0);
889
			}
890
 
891
			Cell cellEligible = row.createCell(cellnum++);
892
			if (targetIdAndSlabNamesMap.get(targetId) != null) {
893
				cellEligible.setCellValue(targetIdAndSlabNamesMap.get(targetId));
894
			} else {
895
				cellEligible.setCellValue("-");
896
			}
897
		}
898
 
899
		for (int index = 0; index < targetIdAndsaleValuesMap.size(); index++) {
900
			sheet.autoSizeColumn(index);
901
		}
902
 
903
		try {
904
			workbook.write(outputStream);
905
			workbook.close();
906
		} catch (IOException ioException) {
907
			LOGGER.error("Unable to generate excel file", ioException);
908
		}
909
	}
910
 
21786 ashik.ali 911
}