Subversion Repositories SmartDukaan

Rev

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