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