Subversion Repositories SmartDukaan

Rev

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

Rev 3062 Rev 4209
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.support.services.CourierDetailsGenerator;
3
import in.shop2020.support.services.CourierDetailsGenerator;
-
 
4
import in.shop2020.support.services.CourierDetailsReportMerger;
4
import in.shop2020.support.services.ManifestGenerator;
5
import in.shop2020.support.services.ManifestGenerator;
5
 
6
 
6
import java.io.ByteArrayOutputStream;
7
import java.io.ByteArrayOutputStream;
7
import java.io.FileNotFoundException;
8
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
9
import java.io.FileOutputStream;
9
import java.io.IOException;
10
import java.io.IOException;
10
import java.util.Calendar;
11
import java.util.Calendar;
11
import java.util.GregorianCalendar;
12
import java.util.GregorianCalendar;
-
 
13
import java.util.HashMap;
-
 
14
import java.util.Map;
12
 
15
 
13
import javax.servlet.ServletOutputStream;
16
import javax.servlet.ServletOutputStream;
14
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletRequest;
15
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpServletResponse;
16
 
19
 
Line 51... Line 54...
51
		int year = date.get(Calendar.YEAR);
54
		int year = date.get(Calendar.YEAR);
52
		int month = date.get(Calendar.MONTH) +1;
55
		int month = date.get(Calendar.MONTH) +1;
53
		int day = date.get(Calendar.DAY_OF_MONTH);
56
		int day = date.get(Calendar.DAY_OF_MONTH);
54
		
57
		
55
		String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
58
		String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
-
 
59
		String mergedFileNameSuffix = "-" + 0 + "-"+ providerId + "-" + year + "-" + month + "-" + day;
56
		if(isCod)
60
		if(isCod){
57
		    fileNameSuffix = "cod" + fileNameSuffix ;
61
		    fileNameSuffix = "cod" + fileNameSuffix ;
-
 
62
			mergedFileNameSuffix = "cod" + mergedFileNameSuffix;
-
 
63
		}
58
		else
64
		else{
59
		    fileNameSuffix = "prepaid" + fileNameSuffix;
65
		    fileNameSuffix = "prepaid" + fileNameSuffix;
-
 
66
			mergedFileNameSuffix = "prepaid" + mergedFileNameSuffix;
-
 
67
		}
60
		
68
		
61
		ManifestGenerator manifestGenerator = new ManifestGenerator();
69
		ManifestGenerator manifestGenerator = new ManifestGenerator();
62
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod);
70
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod);
63
		response.setContentType("application/pdf");
71
		response.setContentType("application/pdf");
64
		
72
		
Line 73... Line 81...
73
			logger.error("Unable to create the courier details file", e);
81
			logger.error("Unable to create the courier details file", e);
74
		} catch (IOException e) {
82
		} catch (IOException e) {
75
		    logger.error("Unable to create the courier details file", e);
83
		    logger.error("Unable to create the courier details file", e);
76
		}
84
		}
77
		
85
		
-
 
86
		// FIXME This is not a useful way. We need to fix it asap. This is done just to give ease to courier company.
-
 
87
		CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
-
 
88
		try {
-
 
89
			FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + mergedFileNameSuffix + ".xls");
-
 
90
			Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
-
 
91
			
-
 
92
			String p1;
-
 
93
			if(isCod){
-
 
94
			    p1 = "cod";
-
 
95
			}
-
 
96
			else{
-
 
97
			    p1 = "prepaid";
-
 
98
			}
-
 
99
			String fName;
-
 
100
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 1 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
101
			warehouseIdFileNames.put(1L, fName);
-
 
102
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 2 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
103
			warehouseIdFileNames.put(2L, fName);
-
 
104
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 5 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
105
			warehouseIdFileNames.put(5L, fName);
-
 
106
			ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames, 1, true);
-
 
107
			binXLS.writeTo(f);
-
 
108
			f.close();
-
 
109
		} catch (FileNotFoundException e) {
-
 
110
			logger.error("Error while creating the Courier Details report", e);
-
 
111
		} catch (IOException e) {
-
 
112
			logger.error("IO error while writing the Courier Details report", e);
-
 
113
		}
-
 
114
		
-
 
115
		
78
		response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
116
		response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
79
		
117
		
80
		ServletOutputStream sos;
118
		ServletOutputStream sos;
81
		try {
119
		try {
82
			sos = response.getOutputStream();
120
			sos = response.getOutputStream();