Subversion Repositories SmartDukaan

Rev

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

Rev 4209 Rev 4410
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;
-
 
4
import in.shop2020.support.services.CourierDetailsReportMerger;
-
 
5
import in.shop2020.support.services.ManifestGenerator;
3
import in.shop2020.support.services.ManifestGenerator;
6
 
4
 
7
import java.io.ByteArrayOutputStream;
5
import java.io.ByteArrayOutputStream;
8
import java.io.FileNotFoundException;
-
 
9
import java.io.FileOutputStream;
-
 
10
import java.io.IOException;
6
import java.io.IOException;
11
import java.util.Calendar;
7
import java.util.Calendar;
12
import java.util.GregorianCalendar;
8
import java.util.GregorianCalendar;
13
import java.util.HashMap;
-
 
14
import java.util.Map;
-
 
15
 
9
 
16
import javax.servlet.ServletOutputStream;
10
import javax.servlet.ServletOutputStream;
17
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
12
import javax.servlet.http.HttpServletResponse;
19
 
13
 
Line 26... Line 20...
26
 
20
 
27
public class ManifestController implements ServletResponseAware, ServletRequestAware {
21
public class ManifestController implements ServletResponseAware, ServletRequestAware {
28
	
22
	
29
    private static Logger logger = LoggerFactory.getLogger(ManifestController.class);
23
    private static Logger logger = LoggerFactory.getLogger(ManifestController.class);
30
    
24
    
31
	//FIXME: Read this configuration from the config client
-
 
32
	private String courierDetailsPath = "/CourierDetailReports";
-
 
33
	private long warehouseId;
25
	private long warehouseId;
34
	private long providerId;
26
	private long providerId;
35
	private boolean isCod;
27
	private boolean isCod;
36
	
28
	
37
	private HttpServletRequest request;
29
	private HttpServletRequest request;
Line 54... Line 46...
54
		int year = date.get(Calendar.YEAR);
46
		int year = date.get(Calendar.YEAR);
55
		int month = date.get(Calendar.MONTH) +1;
47
		int month = date.get(Calendar.MONTH) +1;
56
		int day = date.get(Calendar.DAY_OF_MONTH);
48
		int day = date.get(Calendar.DAY_OF_MONTH);
57
		
49
		
58
		String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
50
		String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
59
		String mergedFileNameSuffix = "-" + 0 + "-"+ providerId + "-" + year + "-" + month + "-" + day;
-
 
60
		if(isCod){
-
 
61
		    fileNameSuffix = "cod" + fileNameSuffix ;
-
 
62
			mergedFileNameSuffix = "cod" + mergedFileNameSuffix;
-
 
63
		}
-
 
64
		else{
-
 
65
		    fileNameSuffix = "prepaid" + fileNameSuffix;
-
 
66
			mergedFileNameSuffix = "prepaid" + mergedFileNameSuffix;
-
 
67
		}
-
 
68
		
51
		
69
		ManifestGenerator manifestGenerator = new ManifestGenerator();
52
		ManifestGenerator manifestGenerator = new ManifestGenerator();
70
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod);
53
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod);
71
		response.setContentType("application/pdf");
54
		response.setContentType("application/pdf");
72
		
55
		
73
		CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
-
 
74
		ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(warehouseId, providerId, isCod);
-
 
75
		try {
-
 
76
			String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
-
 
77
			FileOutputStream f = new FileOutputStream(fileName);
-
 
78
			baosXLS.writeTo(f);
-
 
79
			f.close();
-
 
80
		} catch (FileNotFoundException e) {
-
 
81
			logger.error("Unable to create the courier details file", e);
-
 
82
		} catch (IOException e) {
-
 
83
		    logger.error("Unable to create the courier details file", e);
-
 
84
		}
-
 
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
		
-
 
116
		response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
56
		response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
117
		
57
		
118
		ServletOutputStream sos;
58
		ServletOutputStream sos;
119
		try {
59
		try {
120
			sos = response.getOutputStream();
60
			sos = response.getOutputStream();