Subversion Repositories SmartDukaan

Rev

Rev 22924 | Rev 23338 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22924 Rev 23017
Line 29... Line 29...
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
30
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
31
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
31
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
32
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
32
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
33
import com.spice.profitmandi.common.model.ProfitMandiConstants;
33
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
34
import com.spice.profitmandi.common.model.SchemeModel;
34
import com.spice.profitmandi.common.model.TagListingModel;
35
import com.spice.profitmandi.common.model.TagListingModel;
35
 
36
 
36
public class ExcelUtils {
37
public class ExcelUtils {
37
	private static final String TAG_ID = "Tag Id";
38
	private static final String TAG_ID = "Tag Id";
38
	private static final String TAG_LABEL = "Tag Label";
39
	private static final String TAG_LABEL = "Tag Label";
Line 416... Line 417...
416
			sheet.autoSizeColumn(index);
417
			sheet.autoSizeColumn(index);
417
		}
418
		}
418
		
419
		
419
	    try{
420
	    try{
420
			workbook.write(outputStream);
421
			workbook.write(outputStream);
-
 
422
	    	workbook.close();
-
 
423
	    }catch(IOException ioException){
-
 
424
	    	LOGGER.error("Unable to generate excel file", ioException);
-
 
425
	    }
-
 
426
	}
-
 
427
	
-
 
428
	public static void writeSchemeModels(List<SchemeModel> schemeModels, OutputStream outputStream){
-
 
429
		SXSSFWorkbook workbook = new SXSSFWorkbook();
-
 
430
	    
-
 
431
		//CreationHelper createHelper = workbook.getCreationHelper();
-
 
432
	    
-
 
433
		SXSSFSheet sheet = workbook.createSheet("Schemes");
-
 
434
		sheet.trackAllColumnsForAutoSizing();
-
 
435
		
-
 
436
		
-
 
437
	    Row rowHeader = sheet.createRow(0);
-
 
438
	    Cell cellSchemeIdHeader = rowHeader.createCell(0);
-
 
439
		cellSchemeIdHeader.setCellValue("Scheme Id");
-
 
440
		Cell cellNameHeader = rowHeader.createCell(1);
-
 
441
		cellNameHeader.setCellValue("Name");
-
 
442
		Cell cellDescriptionHeader = rowHeader.createCell(2);
-
 
443
		cellDescriptionHeader.setCellValue("Description");
-
 
444
		Cell cellSchemeTypeHeader = rowHeader.createCell(3);
-
 
445
		cellSchemeTypeHeader.setCellValue("Scheme Type");
-
 
446
		Cell cellAmountTypeHeader = rowHeader.createCell(4);
-
 
447
		cellAmountTypeHeader.setCellValue("Amount Type");
-
 
448
		Cell cellAmountHeader = rowHeader.createCell(5);
-
 
449
		cellAmountHeader.setCellValue("Amount");
-
 
450
		Cell cellStartDateTimeHeader = rowHeader.createCell(6);
-
 
451
		cellStartDateTimeHeader.setCellValue("Start Date Time");
-
 
452
		Cell cellEndDateTimeHeader = rowHeader.createCell(7);
-
 
453
		cellEndDateTimeHeader.setCellValue("End Date Time");
-
 
454
		Cell cellCreatedAtHeader = rowHeader.createCell(8);
-
 
455
		cellCreatedAtHeader.setCellValue("Created At");
-
 
456
		Cell cellActiveHeader = rowHeader.createCell(9);
-
 
457
		cellActiveHeader.setCellValue("Active");
-
 
458
		Cell cellExpireHeader = rowHeader.createCell(10);
-
 
459
		cellExpireHeader.setCellValue("Expire");
-
 
460
		Cell cellCreatedByHeader = rowHeader.createCell(11);
-
 
461
		cellCreatedByHeader.setCellValue("Created By");
-
 
462
		Cell cellItemIdsHeader = rowHeader.createCell(12);
-
 
463
		cellItemIdsHeader.setCellValue("Item Ids");
-
 
464
		Cell cellRetailerIdsHeader = rowHeader.createCell(13);
-
 
465
		cellRetailerIdsHeader.setCellValue("Retailer Ids");
-
 
466
		//Row rowQuantityRateValue = sheet.createRow(1);
-
 
467
		
-
 
468
		/*for(int index = 6; index < 18; index = index + 3){
-
 
469
			Cell cellQuantityHeader = rowQuantityRateValue.createCell(index);
-
 
470
			cellQuantityHeader.setCellValue("Quantity");
-
 
471
			Cell cellRateHeader = rowQuantityRateValue.createCell(index + 1);
-
 
472
			cellRateHeader.setCellValue("Rate");
-
 
473
			Cell cellValueHeader = rowQuantityRateValue.createCell(index + 2);
-
 
474
			cellValueHeader.setCellValue("Value");
-
 
475
			sheet.addMergedRegion(new CellRangeAddress(0, 0, index, index + 2));
-
 
476
		}*/
-
 
477
		Font font = workbook.createFont();
-
 
478
		CellStyle cellStyle = workbook.createCellStyle();
-
 
479
		font.setBold(true);
-
 
480
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
-
 
481
		//font.setFontHeight((short)16);
-
 
482
		cellStyle.setFont(font);
-
 
483
		for(int i = 0; i < 14; i++){
-
 
484
			if(rowHeader.getCell(i) != null){
-
 
485
				rowHeader.getCell(i).setCellStyle(cellStyle);
-
 
486
			}
-
 
487
		}
-
 
488
 
-
 
489
		for(int index = 0; index < schemeModels.size(); index++){
-
 
490
			SchemeModel schemeModel = schemeModels.get(index);
-
 
491
			//ItemCompleteLedgerModel itemCompleteLedgerModel = itemCompleteLedgerModels.get(index);
-
 
492
	    	Row rowValues = sheet.createRow(index + 1);
-
 
493
	    	Cell cellSchemeId = rowValues.createCell(0);
-
 
494
			cellSchemeId.setCellValue(schemeModel.getSchemeId());
-
 
495
			Cell cellName = rowValues.createCell(1);
-
 
496
			cellName.setCellValue(schemeModel.getName());
-
 
497
			Cell cellDescription = rowValues.createCell(2);
-
 
498
			cellDescription.setCellValue(schemeModel.getDescription());
-
 
499
			Cell cellSchemeType = rowValues.createCell(3);
-
 
500
			cellSchemeType.setCellValue(schemeModel.getSchemeType());
-
 
501
			Cell cellAmountType = rowValues.createCell(4);
-
 
502
			cellAmountType.setCellValue(schemeModel.getAmountType());
-
 
503
			Cell cellAmount = rowValues.createCell(5);
-
 
504
			cellAmount.setCellValue(schemeModel.getAmount());
-
 
505
			Cell cellStartDateTime = rowValues.createCell(6);
-
 
506
			cellStartDateTime.setCellValue(schemeModel.getStartDateTime());
-
 
507
			Cell cellEndDateTime = rowValues.createCell(7);
-
 
508
			cellEndDateTime.setCellValue(schemeModel.getEndDateTime());
-
 
509
			Cell cellCreatedAt = rowValues.createCell(8);
-
 
510
			cellCreatedAt.setCellValue(schemeModel.getCreateTimestamp());
-
 
511
			Cell cellActive = rowValues.createCell(9);
-
 
512
			if(schemeModel.getActiveTimestamp() !=null){
-
 
513
				cellActive.setCellValue(schemeModel.getActiveTimestamp());
-
 
514
			}else{
-
 
515
				cellActive.setCellValue("False");
-
 
516
			}
-
 
517
			Cell cellExpire = rowValues.createCell(10);
-
 
518
			if(schemeModel.getExpireTimestamp() != null){
-
 
519
				cellExpire.setCellValue(schemeModel.getExpireTimestamp());
-
 
520
			}else{
-
 
521
				cellExpire.setCellValue("False");
-
 
522
			}
-
 
523
			Cell cellCreatedBy = rowValues.createCell(11);
-
 
524
			cellCreatedBy.setCellValue(schemeModel.getCreatedBy());
-
 
525
			Cell cellItemIds = rowValues.createCell(12);
-
 
526
			cellItemIds.setCellValue(schemeModel.getItemIdsString());
-
 
527
			Cell cellRetailerIds = rowValues.createCell(13);
-
 
528
			cellRetailerIds.setCellValue(schemeModel.getRetailerIdsString());
-
 
529
			int maxHeight = Math.max(schemeModel.getItemIds().size(), schemeModel.getRetailerIds().size());
-
 
530
			if(maxHeight > 1){
-
 
531
				rowValues.setHeight((short)(maxHeight * 240));
-
 
532
			}
-
 
533
	    }
-
 
534
		
-
 
535
		for(int index = 0; index < 14; index++){
-
 
536
			sheet.autoSizeColumn(index);
-
 
537
		}
-
 
538
		
-
 
539
	    try{
-
 
540
			workbook.write(outputStream);
421
	    	workbook.close();
541
	    	workbook.close();
422
	    }catch(IOException ioException){
542
	    }catch(IOException ioException){
423
	    	LOGGER.error("Unable to generate excel file", ioException);
543
	    	LOGGER.error("Unable to generate excel file", ioException);
424
	    }
544
	    }
425
	}
545
	}