Subversion Repositories SmartDukaan

Rev

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

Rev 24179 Rev 24184
Line 18... Line 18...
18
import org.apache.poi.ss.usermodel.Cell;
18
import org.apache.poi.ss.usermodel.Cell;
19
import org.apache.poi.ss.usermodel.CellStyle;
19
import org.apache.poi.ss.usermodel.CellStyle;
20
import org.apache.poi.ss.usermodel.CellType;
20
import org.apache.poi.ss.usermodel.CellType;
21
import org.apache.poi.ss.usermodel.Font;
21
import org.apache.poi.ss.usermodel.Font;
22
import org.apache.poi.ss.usermodel.HorizontalAlignment;
22
import org.apache.poi.ss.usermodel.HorizontalAlignment;
-
 
23
import org.apache.poi.ss.usermodel.RichTextString;
23
import org.apache.poi.ss.usermodel.Row;
24
import org.apache.poi.ss.usermodel.Row;
24
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
25
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
25
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.xssf.streaming.SXSSFSheet;
27
import org.apache.poi.xssf.streaming.SXSSFSheet;
27
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
28
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
Line 887... Line 888...
887
			sheet.autoSizeColumn(index);
888
			sheet.autoSizeColumn(index);
888
		}
889
		}
889
 
890
 
890
		try {
891
		try {
891
			workbook.write(outputStream);
892
			workbook.write(outputStream);
-
 
893
			workbook.close();
-
 
894
		} catch (IOException ioException) {
-
 
895
			LOGGER.error("Unable to generate excel file", ioException);
-
 
896
		}
-
 
897
	}
-
 
898
	public static void writeDailySaleReportVsTargetForPartner(Map<Integer,String> targetIdAndTargetNameMap,Map<Integer, Float> targetIdAndtargetValuesMap, Map<Integer, Double> targetIdAndsaleValuesMap,
-
 
899
			Map<Integer, CustomRetailer> targetIdAndCustomRetailerMap, Map<Integer, String> targetIdAndSlabNamesMap,
-
 
900
			Map<Integer, Double> targetIdAndsaleValuesPercentageMap, Map<Integer, Float> targetIdAndtargetdailyAverageSaleMap,
-
 
901
			Map<Integer, Double> targetIdAndRemainingTargetMap, Map<Integer, Double> targetIdAndtodayAchievementsMap,
-
 
902
			 Map<Integer, String> targetIdAndSalesHeadMap , OutputStream outputStream) {
-
 
903
		SXSSFWorkbook workbook = new SXSSFWorkbook();
-
 
904
 
-
 
905
		// CreationHelper createHelper = workbook.getCreationHelper();
-
 
906
 
-
 
907
		SXSSFSheet sheet = workbook.createSheet("DailySaleReports");
-
 
908
		sheet.trackAllColumnsForAutoSizing();
-
 
909
 
-
 
910
		Row rowHeader = sheet.createRow(0);
-
 
911
		Cell cellTarget = rowHeader.createCell(0);
-
 
912
		cellTarget.setCellValue("Target Name");
-
 
913
		Cell cellBusiness = rowHeader.createCell(1);
-
 
914
		cellBusiness.setCellValue("Business Manager");
-
 
915
		Cell cellAssistant = rowHeader.createCell(2);
-
 
916
		cellAssistant.setCellValue("Assistant Manager");
-
 
917
		Cell cellStoreName = rowHeader.createCell(3);
-
 
918
		cellStoreName.setCellValue("Store Name");
-
 
919
		Cell cellTargetValue = rowHeader.createCell(4);
-
 
920
		cellTargetValue.setCellValue("Target Value");
-
 
921
		Cell cellDailyTarget = rowHeader.createCell(5);
-
 
922
		cellDailyTarget.setCellValue("Daily Target");
-
 
923
		Cell cellTodayAchievement = rowHeader.createCell(6);
-
 
924
		cellTodayAchievement.setCellValue("Today's Sale");
-
 
925
		Cell cellMonthlySaleValue = rowHeader.createCell(7);
-
 
926
		cellMonthlySaleValue.setCellValue("Total Sale");
-
 
927
		Cell cellMonthlySaleValuePercentage = rowHeader.createCell(8);
-
 
928
		cellMonthlySaleValuePercentage.setCellValue("Total Sale%");
-
 
929
		Cell cellRemainingTarget = rowHeader.createCell(9);
-
 
930
		cellRemainingTarget.setCellValue("Remaining");
-
 
931
		Cell cellEligibility = rowHeader.createCell(10);
-
 
932
		cellEligibility.setCellValue("Eligibility");
-
 
933
		Font font = workbook.createFont();
-
 
934
		CellStyle cellStyle = workbook.createCellStyle();
-
 
935
		font.setBold(true);
-
 
936
		cellStyle.setAlignment(HorizontalAlignment.CENTER);
-
 
937
		// font.setFontHeight((short)16);
-
 
938
		cellStyle.setFont(font);
-
 
939
		for (int i = 0; i < 14; i++) {
-
 
940
			if (rowHeader.getCell(i) != null) {
-
 
941
				rowHeader.getCell(i).setCellStyle(cellStyle);
-
 
942
			}
-
 
943
		}
-
 
944
		int rownum = 1;
-
 
945
		for (Integer targetId : targetIdAndTargetNameMap.keySet()) {
-
 
946
			Row row = sheet.createRow(rownum++);
-
 
947
			int cellnum = 0;
-
 
948
			Cell cellTargetName = row.createCell(cellnum++);
-
 
949
			if (targetIdAndTargetNameMap.get(targetId)==null||targetIdAndTargetNameMap.get(targetId)=="") {
-
 
950
				cellTargetName.setCellValue("");
-
 
951
				
-
 
952
			} else {
-
 
953
				cellTargetName.setCellValue(targetIdAndTargetNameMap.get(targetId));
-
 
954
			}
-
 
955
			Cell cellBusinessManager = row.createCell(cellnum++);
-
 
956
			if (targetIdAndCustomRetailerMap.get(targetId) != null) {
-
 
957
				if (targetIdAndCustomRetailerMap.get(targetId).equals("Kamal")) {
-
 
958
					cellBusinessManager.setCellValue("Mohinder");
-
 
959
				} else {
-
 
960
					cellBusinessManager.setCellValue((RichTextString) targetIdAndCustomRetailerMap.get(targetId));
-
 
961
				}
-
 
962
			} else {
-
 
963
				cellBusinessManager.setCellValue("-");
-
 
964
			}
-
 
965
			Cell cellAssistantManager = row.createCell(cellnum++);
-
 
966
			if (targetIdAndSalesHeadMap.get(targetId) != null) {
-
 
967
				if (targetIdAndSalesHeadMap.get(targetId).equals("Kamal")) {
-
 
968
					cellAssistantManager.setCellValue(targetIdAndSalesHeadMap.get(targetId));
-
 
969
				} else {
-
 
970
					cellAssistantManager.setCellValue("");
-
 
971
				}
-
 
972
			} else {
-
 
973
				cellAssistantManager.setCellValue("");
-
 
974
			}
-
 
975
 
-
 
976
			Cell cellMTDTargetValue = row.createCell(cellnum++);
-
 
977
			if (targetIdAndtargetValuesMap.get(targetId) != null) {
-
 
978
				cellMTDTargetValue.setCellValue(targetIdAndtargetValuesMap.get(targetId));
-
 
979
			} else {
-
 
980
				cellMTDTargetValue.setCellValue("-");
-
 
981
			}
-
 
982
 
-
 
983
			Cell cellDailyTargetValue = row.createCell(cellnum++);
-
 
984
			if (targetIdAndtargetdailyAverageSaleMap.get(targetId) != null) {
-
 
985
				String formatting = FormattingUtils.formatDecimalTwoDigits(targetIdAndtargetdailyAverageSaleMap.get(targetId));
-
 
986
				cellDailyTargetValue.setCellValue(formatting);
-
 
987
			} else {
-
 
988
				cellDailyTargetValue.setCellValue(0);
-
 
989
			}
-
 
990
			Cell cellTodayAchieveMentSaleValue = row.createCell(cellnum++);
-
 
991
			if (targetIdAndtodayAchievementsMap.get(targetId) != null) {
-
 
992
				cellTodayAchieveMentSaleValue.setCellValue(targetIdAndtodayAchievementsMap.get(targetId));
-
 
993
			} else {
-
 
994
				cellTodayAchieveMentSaleValue.setCellValue(0);
-
 
995
			}
-
 
996
			Cell cellMTDAchievement = row.createCell(cellnum++);
-
 
997
			if (targetIdAndsaleValuesMap.get(targetId) != null) {
-
 
998
				cellMTDAchievement.setCellValue(targetIdAndsaleValuesMap.get(targetId));
-
 
999
			} else {
-
 
1000
				cellMTDAchievement.setCellValue(0);
-
 
1001
			}
-
 
1002
			Cell cellMTDAchievementPercentage = row.createCell(cellnum++);
-
 
1003
			if (targetIdAndsaleValuesPercentageMap.get(targetId) != null) {
-
 
1004
				cellMTDAchievementPercentage.setCellValue(targetIdAndsaleValuesPercentageMap.get(targetId) + "%");
-
 
1005
			} else {
-
 
1006
				cellMTDAchievementPercentage.setCellValue(0 + "%");
-
 
1007
			}
-
 
1008
 
-
 
1009
			Cell cellRemaining = row.createCell(cellnum++);
-
 
1010
			if (targetIdAndRemainingTargetMap.get(targetId) != null) {
-
 
1011
				cellRemaining.setCellValue(targetIdAndRemainingTargetMap.get(targetId));
-
 
1012
			} else {
-
 
1013
				cellRemaining.setCellValue(0);
-
 
1014
			}
-
 
1015
 
-
 
1016
			Cell cellEligible = row.createCell(cellnum++);
-
 
1017
			if (targetIdAndSlabNamesMap.get(targetId) != null) {
-
 
1018
				cellEligible.setCellValue(targetIdAndSlabNamesMap.get(targetId));
-
 
1019
			} else {
-
 
1020
				cellEligible.setCellValue("-");
-
 
1021
			}
-
 
1022
		}
-
 
1023
 
-
 
1024
		for (int index = 0; index < targetIdAndsaleValuesMap.size(); index++) {
-
 
1025
			sheet.autoSizeColumn(index);
-
 
1026
		}
-
 
1027
 
-
 
1028
		try {
-
 
1029
			workbook.write(outputStream);
892
			workbook.close();
1030
			workbook.close();
893
		} catch (IOException ioException) {
1031
		} catch (IOException ioException) {
894
			LOGGER.error("Unable to generate excel file", ioException);
1032
			LOGGER.error("Unable to generate excel file", ioException);
895
		}
1033
		}
896
	}
1034
	}