Subversion Repositories SmartDukaan

Rev

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

Rev 1884 Rev 2008
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.catalog.Warehouse;
3
import in.shop2020.model.v1.catalog.Warehouse;
4
import in.shop2020.model.v1.order.LineItem;
4
import in.shop2020.model.v1.order.LineItem;
5
import in.shop2020.model.v1.order.Order;
5
import in.shop2020.model.v1.order.Order;
6
import in.shop2020.model.v1.order.OrderStatus;
-
 
7
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.order.TransactionServiceException;
8
import in.shop2020.thrift.clients.CatalogServiceClient;
7
import in.shop2020.thrift.clients.CatalogServiceClient;
9
import in.shop2020.thrift.clients.TransactionServiceClient;
8
import in.shop2020.thrift.clients.TransactionServiceClient;
10
 
9
 
11
import java.text.DateFormat;
10
import java.text.DateFormat;
Line 45... Line 44...
45
 * report in XLS format for all the transactions with HotSpot within a given date range.
44
 * report in XLS format for all the transactions with HotSpot within a given date range.
46
 * 
45
 * 
47
 */
46
 */
48
public class HotspotReconciliationController implements ServletResponseAware, ServletRequestAware {
47
public class HotspotReconciliationController implements ServletResponseAware, ServletRequestAware {
49
 
48
 
-
 
49
	private enum ReportColumn{
-
 
50
		BILLING_NUMBER(0),
-
 
51
		BILLING_DATE(1),
-
 
52
		CUSTOMER_NAME(2),
-
 
53
		BRAND(3),
-
 
54
		MODEL_NAME(4),
-
 
55
		MODEL_NUMBER(5),
-
 
56
		COLOR(6),
-
 
57
		XFER_PRICE(7);
-
 
58
		
-
 
59
		private int value;
-
 
60
		
-
 
61
		ReportColumn(int value) {
-
 
62
			this.value = value;
-
 
63
		}
-
 
64
		public int getValue(){
-
 
65
			return this.value;
-
 
66
		}
-
 
67
	}
-
 
68
	
50
	//FIXME: Read this configuration from the config server
69
	//FIXME: Read this configuration from the config server
51
	//private String hotspotReconciliationReportPath = "/HotspotReports";
70
	//private String hotspotReconciliationReportPath = "/HotspotReports";
52
	
71
	
53
	private HttpServletRequest request;
72
	private HttpServletRequest request;
54
	private HttpServletResponse response;
73
	private HttpServletResponse response;
Line 87... Line 106...
87
			
106
			
88
			List <Order> orders = new ArrayList<Order>();
107
			List <Order> orders = new ArrayList<Order>();
89
 
108
 
90
			//Retrieving all the orders across all the warehouses
109
			//Retrieving all the orders across all the warehouses
91
			for(Warehouse warehouse : warehouses)	{
110
			for(Warehouse warehouse : warehouses)	{
92
				orders.addAll(client.getOrdersByBillingDate(OrderStatus.BILLED, startDate.getTime(), endDate.getTime(), warehouse.getId()));
111
				orders.addAll(client.getOrdersByBillingDate(null, startDate.getTime(), endDate.getTime(), warehouse.getId()));
93
			}
112
			}
94
			System.out.println("Total number of Orders: " + orders.size());
113
			System.out.println("Total number of Orders: " + orders.size());
95
			
114
			
96
			// Preparing XLS file for output
115
			// Preparing XLS file for output
97
			response.setContentType("application/vnd.ms-excel");
116
			response.setContentType("application/vnd.ms-excel");
98
			
117
			
-
 
118
			
99
			Calendar date = new GregorianCalendar();
119
			DateFormat dateFormatForFile = new SimpleDateFormat("dd.MM.yyyy");
100
			int year = date.get(Calendar.YEAR);
-
 
101
			int month = date.get(Calendar.MONTH) +1;
-
 
102
			int day = date.get(Calendar.DAY_OF_MONTH);
-
 
103
 
-
 
104
			response.setHeader("Content-disposition", "inline; filename=hotspot-reconciliation-" + "-" + year + "-" + month + "-" + day + ".xls");
120
			response.setHeader("Content-disposition", "inline; filename=hotspot-reconciliation-from-" + dateFormatForFile.format(startDate) + "-" + dateFormatForFile.format(endDate) + ".xls");
105
			
121
			
106
			ServletOutputStream sos;
122
			ServletOutputStream sos;
107
			try {
123
			try {
108
				ByteArrayOutputStream baos = getSpreadSheetData(orders, startDate, endDate);
124
				ByteArrayOutputStream baos = getSpreadSheetData(orders, startDate, endDate);
109
				sos = response.getOutputStream();
125
				sos = response.getOutputStream();
Line 149... Line 165...
149
	    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
165
	    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
150
	    
166
	    
151
	    sheet.createRow(serialNo ++);
167
	    sheet.createRow(serialNo ++);
152
	    
168
	    
153
	    Row headerRow = sheet.createRow(serialNo ++);
169
	    Row headerRow = sheet.createRow(serialNo ++);
154
	    headerRow.createCell(0).setCellValue("Billing Number");
170
	    headerRow.createCell(ReportColumn.BILLING_NUMBER.getValue()).setCellValue("Billing Number");
155
	    headerRow.createCell(1).setCellValue("Billing Date");
171
	    headerRow.createCell(ReportColumn.BILLING_DATE.getValue()).setCellValue("Billing Date");
-
 
172
	    headerRow.createCell(ReportColumn.CUSTOMER_NAME.getValue()).setCellValue("Customer Name");
156
	    headerRow.createCell(2).setCellValue("Brand");
173
	    headerRow.createCell(ReportColumn.BRAND.getValue()).setCellValue("Brand");
157
	    headerRow.createCell(3).setCellValue("Model Name");
174
	    headerRow.createCell(ReportColumn.MODEL_NAME.getValue()).setCellValue("Model Name");
158
	    headerRow.createCell(4).setCellValue("Model Number");
175
	    headerRow.createCell(ReportColumn.MODEL_NUMBER.getValue()).setCellValue("Model Number");
159
	    headerRow.createCell(5).setCellValue("Color");
176
	    headerRow.createCell(ReportColumn.COLOR.getValue()).setCellValue("Color");
160
	    headerRow.createCell(6).setCellValue("Transfer Price");
177
	    headerRow.createCell(ReportColumn.XFER_PRICE.getValue()).setCellValue("Transfer Price");
161
 
178
 
162
	    double totalTransferPrice = 0.0;
179
	    double totalTransferPrice = 0.0;
163
	    
180
	    
164
	    for(int i = 0; i < orders.size(); i ++)	{
181
	    for(int i = 0; i < orders.size(); i ++)	{
165
	    	Order order = orders.get(i);
182
	    	Order order = orders.get(i);
Line 168... Line 185...
168
		    
185
		    
169
		    LineItem lineItem = order.getLineitems().get(0);
186
		    LineItem lineItem = order.getLineitems().get(0);
170
		    double transferPrice = lineItem.getTransfer_price();
187
		    double transferPrice = lineItem.getTransfer_price();
171
		    totalTransferPrice += transferPrice;
188
		    totalTransferPrice += transferPrice;
172
 
189
 
173
		    contentRow.createCell(0).setCellValue(order.getInvoice_number());
190
		    contentRow.createCell(ReportColumn.BILLING_NUMBER.getValue()).setCellValue(order.getInvoice_number());
174
		    contentRow.createCell(1).setCellValue(dateFormat.format(new Date(order.getBilling_timestamp())));
191
		    contentRow.createCell(ReportColumn.BILLING_DATE.getValue()).setCellValue(dateFormat.format(new Date(order.getBilling_timestamp())));
-
 
192
		    contentRow.createCell(ReportColumn.CUSTOMER_NAME.getValue()).setCellValue(order.getCustomer_name());
175
		    contentRow.createCell(2).setCellValue(getValueForEmptyString(lineItem.getBrand()));
193
		    contentRow.createCell(ReportColumn.BRAND.getValue()).setCellValue(getValueForEmptyString(lineItem.getBrand()));
176
		    contentRow.createCell(3).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
194
		    contentRow.createCell(ReportColumn.MODEL_NAME.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
177
		    contentRow.createCell(4).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
195
		    contentRow.createCell(ReportColumn.MODEL_NUMBER.getValue()).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
178
		    contentRow.createCell(5).setCellValue(getValueForEmptyString(lineItem.getColor()));
196
		    contentRow.createCell(ReportColumn.COLOR.getValue()).setCellValue(getValueForEmptyString(lineItem.getColor()));
179
		    contentRow.createCell(6).setCellValue(transferPrice);
197
		    contentRow.createCell(ReportColumn.XFER_PRICE.getValue()).setCellValue(transferPrice);
180
	    }
198
	    }
181
	    sheet.createRow(serialNo ++);
199
	    sheet.createRow(serialNo ++);
182
    	Row contentRow = sheet.createRow(serialNo);
200
    	Row contentRow = sheet.createRow(serialNo);
183
    	contentRow.createCell(0).setCellValue("Total Transfer Price");
201
    	contentRow.createCell(0).setCellValue("Total Transfer Price");
184
    	contentRow.createCell(6).setCellValue(totalTransferPrice);
202
    	contentRow.createCell(ReportColumn.XFER_PRICE.getValue()).setCellValue(totalTransferPrice);
185
    	sheet.addMergedRegion(new CellRangeAddress(serialNo, serialNo, 0, 5));
203
    	sheet.addMergedRegion(new CellRangeAddress(serialNo, serialNo, 0, 5));
186
    	
204
    	
187
		// Write the workbook to the output stream
205
		// Write the workbook to the output stream
188
		try {
206
		try {
189
			wb.write(baosXLS);
207
			wb.write(baosXLS);
Line 216... Line 234...
216
		if(s==null || s.equals(""))
234
		if(s==null || s.equals(""))
217
			return "-";
235
			return "-";
218
		else
236
		else
219
			return s; 
237
			return s; 
220
	}
238
	}
-
 
239
	
-
 
240
	private String getDateString(Calendar date){
-
 
241
		int year = date.get(Calendar.YEAR);
-
 
242
		int month = date.get(Calendar.MONTH) +1;
-
 
243
		int day = date.get(Calendar.DAY_OF_MONTH);
-
 
244
		return "" + year + "." + month + "." + day;
-
 
245
	}
221
}
246
}
222
247