Subversion Repositories SmartDukaan

Rev

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

Rev 3293 Rev 3315
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.LineItem;
3
import in.shop2020.model.v1.order.LineItem;
4
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.Order;
5
import in.shop2020.model.v1.order.OrderStatus;
5
import in.shop2020.model.v1.order.OrderStatus;
6
import in.shop2020.model.v1.order.TransactionServiceException;
-
 
7
import in.shop2020.model.v1.user.Affiliate;
6
import in.shop2020.model.v1.user.Affiliate;
8
import in.shop2020.model.v1.user.MasterAffiliate;
7
import in.shop2020.model.v1.user.MasterAffiliate;
9
import in.shop2020.model.v1.user.TrackLog;
8
import in.shop2020.model.v1.user.TrackLog;
10
import in.shop2020.model.v1.user.UserAffiliateException;
9
import in.shop2020.model.v1.user.UserAffiliateException;
11
import in.shop2020.model.v1.user.UserContextService.Client;
10
import in.shop2020.model.v1.user.UserContextService.Client;
12
import in.shop2020.payments.Payment;
11
import in.shop2020.payments.Payment;
13
import in.shop2020.payments.PaymentException;
-
 
14
import in.shop2020.support.utils.ReportsUtils;
12
import in.shop2020.support.utils.ReportsUtils;
15
import in.shop2020.thrift.clients.PaymentClient;
13
import in.shop2020.thrift.clients.PaymentClient;
16
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.TransactionClient;
17
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.thrift.clients.UserClient;
18
 
16
 
Line 24... Line 22...
24
import java.util.ArrayList;
22
import java.util.ArrayList;
25
import java.util.Calendar;
23
import java.util.Calendar;
26
import java.util.Date;
24
import java.util.Date;
27
import java.util.HashMap;
25
import java.util.HashMap;
28
import java.util.HashSet;
26
import java.util.HashSet;
29
import java.util.LinkedList;
-
 
30
import java.util.List;
27
import java.util.List;
31
import java.util.Map;
28
import java.util.Map;
-
 
29
import java.util.Map.Entry;
32
import java.util.Set;
30
import java.util.Set;
-
 
31
import java.util.SortedSet;
-
 
32
import java.util.TimeZone;
-
 
33
import java.util.TreeSet;
33
 
34
 
34
import javax.servlet.ServletOutputStream;
35
import javax.servlet.ServletOutputStream;
35
import javax.servlet.http.HttpServletRequest;
36
import javax.servlet.http.HttpServletRequest;
36
import javax.servlet.http.HttpServletResponse;
37
import javax.servlet.http.HttpServletResponse;
37
import javax.servlet.http.HttpSession;
38
import javax.servlet.http.HttpSession;
Line 72... Line 73...
72
	private HttpServletRequest request;
73
	private HttpServletRequest request;
73
	private HttpSession session;
74
	private HttpSession session;
74
    
75
    
75
	private String errorMsg = "";
76
	private String errorMsg = "";
76
	private List<MasterAffiliate> masterAffiliates;
77
	private List<MasterAffiliate> masterAffiliates;
-
 
78
	private Date startDate = null;
-
 
79
	private Date endDate = null;
77
	
80
	
78
	@Override
81
	@Override
79
	public void setServletResponse(HttpServletResponse res) {
82
	public void setServletResponse(HttpServletResponse res) {
80
		this.response = res;
83
		this.response = res;
81
	}
84
	}
Line 105... Line 108...
105
    }
108
    }
106
	
109
	
107
	public String create()	{
110
	public String create()	{
108
	    try   {
111
	    try   {
109
	        long mAfId = Long.parseLong(request.getParameter("masterAffiliate"));
112
	        long mAfId = Long.parseLong(request.getParameter("masterAffiliate"));
110
	        String filename;
113
	        String mAffName;
111
	        String startDateStr = request.getParameter("startDate");
114
	        String startDateStr = request.getParameter("startDate");
112
	        String endDateStr = request.getParameter("endDate");
115
	        String endDateStr = request.getParameter("endDate");
113
	        
116
	        
114
	        DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
117
	        DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
115
	        Date startDate = null, endDate = null;
118
	        df.setTimeZone(TimeZone.getTimeZone("IST"));
116
	        try {
119
	        try {
117
	            startDate = df.parse(startDateStr);
120
	            startDate = df.parse(startDateStr);
118
	            endDate = df.parse(endDateStr);
121
	            endDate = df.parse(endDateStr);
119
	            Calendar cal = Calendar.getInstance();
122
	            Calendar cal = Calendar.getInstance();
120
	            cal.setTime(endDate);
123
	            cal.setTime(endDate);
121
	            cal.add(Calendar.DATE, 1);
-
 
122
	            endDate.setTime(cal.getTimeInMillis());
124
	            endDate.setTime(cal.getTimeInMillis());
123
	        } catch (ParseException pe) {
125
	        } catch (ParseException pe) {
124
	            errorMsg = "Please enter start and end dates in format MM/dd/yyyy";
126
	            errorMsg = "Please enter start and end dates in format MM/dd/yyyy";
125
	            return "report";
127
	            return "report";
126
	        }
128
	        }
Line 130... Line 132...
130
            TransactionClient transactionServiceClient = new TransactionClient();
132
            TransactionClient transactionServiceClient = new TransactionClient();
131
            
133
            
132
            Client userClient = userContextServiceClient.getClient();
134
            Client userClient = userContextServiceClient.getClient();
133
            in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
135
            in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
134
            
136
            
135
            Set<Long> Payments = new HashSet<Long>();
-
 
136
            List<Map<String, String>> contentRows = new LinkedList<Map<String,String>>();
-
 
137
            List<Affiliate> affiliates;
137
            List<Affiliate> affiliates;
138
            if (mAfId == -1) {
138
            if (mAfId == -1) {
139
                filename = "All";
139
                mAffName = "All";
140
                affiliates = new ArrayList<Affiliate>();
140
                affiliates = new ArrayList<Affiliate>();
141
                for(MasterAffiliate mAffiliate : userClient.getAllMasterAffiliates()) {
141
                for(MasterAffiliate mAffiliate : userClient.getAllMasterAffiliates()) {
142
                    affiliates.addAll(userClient.getAffiliatesByMasterAffiliate(mAffiliate.getId()));
142
                    affiliates.addAll(userClient.getAffiliatesByMasterAffiliate(mAffiliate.getId()));
143
                }
143
                }
144
            }
144
            }
145
            else {
145
            else {
146
                affiliates = userClient.getAffiliatesByMasterAffiliate(mAfId);
146
                affiliates = userClient.getAffiliatesByMasterAffiliate(mAfId);
147
                filename = userClient.getMasterAffiliateById(mAfId).getName();
147
                mAffName = userClient.getMasterAffiliateById(mAfId).getName();
148
            }
148
            }
149
            
149
            
-
 
150
            SortedSet<Date> dates = new TreeSet<Date>();
-
 
151
            Map<Date, Long> registerCountMap = new HashMap<Date, Long>();
-
 
152
            Map<Date, Double> saleQuantityMap = new HashMap<Date, Double>();
-
 
153
            Map<Date, Double> saleAmountMap = new HashMap<Date, Double>();
-
 
154
            
-
 
155
            Map<Date, Map<String, Double>> productQuantityMap = new HashMap<Date, Map<String, Double>>();
-
 
156
            Map<Date, Map<String, Double>> productAmountMap = new HashMap<Date, Map<String,Double>>();
-
 
157
            
150
            for (Affiliate aff : affiliates) {
158
            for (Affiliate aff : affiliates) {
151
                MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(aff.getMasterAffiliateId());
159
                Set<Long> Payments = new HashSet<Long>(); // To deal with multiple refreshes on pay-success page.
152
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId(), startDate.getTime(), endDate.getTime())) {
160
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId(), startDate.getTime(), endDate.getTime())) {
153
                    boolean orderCompleted = false;
161
                    Date date = df.parse(df.format(new Date(tracklog.getAddedOn())));
154
                    Map<String, String> contentRow = new HashMap<String, String>();
162
                    dates.add(date);
155
                    contentRow.put("mAffiliate", mAffiliate.getName());
163
                    if (tracklog.getEvent().equals("new registration")) {
156
                    contentRow.put("affiliate", aff.getName());
164
                        if (registerCountMap.containsKey(date)) {
157
                    contentRow.put("affiliateUrl", aff.getUrl());
165
                            Long count = registerCountMap.get(date);
158
                    contentRow.put("date",String.valueOf(tracklog.getAddedOn()));
166
                            registerCountMap.put(date, ++count);
159
                    contentRow.put("event", tracklog.getEvent());
167
                        }
160
                    contentRow.put("url", tracklog.getUrl());
168
                        else {
161
                    if (tracklog.getEvent().equals("payment success")) {
169
                            registerCountMap.put(date, 1l);
162
                        try {
170
                        }
-
 
171
                    }
-
 
172
                    else if (tracklog.getEvent().equals("payment success")) {
163
                            long paymentId = Long.parseLong(tracklog.getData().replaceAll("\\(*\\)", ""));
173
                        long paymentId = Long.parseLong(tracklog.getData().replaceAll("\\(*\\)", ""));
164
                            if (Payments.contains(paymentId)) {
174
                        if (Payments.contains(paymentId)) {
165
                                continue;
175
                            continue;
166
                            }
176
                        }
167
                            Payments.add(paymentId);
177
                        Payments.add(paymentId);
168
                            Payment payment = paymentClient.getPayment(paymentId);
178
                        Payment payment = paymentClient.getPayment(paymentId);
169
                            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(
179
                        List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(
170
                                            payment.getMerchantTxnId(),
180
                                        payment.getMerchantTxnId(),
171
                                            payment.getUserId());
181
                                        payment.getUserId());
172
                            contentRow.put("amount", Double.toString(payment.getAmount()));
-
 
173
                            String itemString = "";
-
 
174
                            for (Order order : orders) {
182
                        for (Order order : orders) {
175
                                if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
183
                            if (order.getStatus() != OrderStatus.DELIVERY_SUCCESS) {
176
                                    orderCompleted = true;
-
 
177
                                }
-
 
178
                                List<LineItem> items = order.getLineitems();
184
                                List<LineItem> items = order.getLineitems();
-
 
185
                                if (saleAmountMap.containsKey(date)) {
-
 
186
                                    Double amount = saleAmountMap.get(date);
-
 
187
                                    amount += order.getTotal_amount();
-
 
188
                                    saleAmountMap.put(date, amount);
-
 
189
                                }
-
 
190
                                else {
-
 
191
                                    saleAmountMap.put(date, order.getTotal_amount());
-
 
192
                                }
179
                                for (LineItem item : items) {
193
                                for (LineItem item : items) {
-
 
194
                                    if (saleQuantityMap.containsKey(date)) {
-
 
195
                                        Double quantity = saleQuantityMap.get(date);
-
 
196
                                        quantity += item.getQuantity();
-
 
197
                                        saleQuantityMap.put(date, quantity);
-
 
198
                                    }
-
 
199
                                    else {
-
 
200
                                        saleQuantityMap.put(date, item.getQuantity());
-
 
201
                                    }
-
 
202
                                    
180
                                    itemString += item.getBrand() + " "
203
                                    String productName = item.getBrand() + " "
181
                                            + item.getModel_name() + " "
204
                                            + item.getModel_name() + " "
182
                                            + item.getModel_number() + "("
205
                                            + item.getModel_number();
-
 
206
                                    productName = productName.replace("null", "").replaceAll("  ", " ").trim();
-
 
207
                                    if (productQuantityMap.containsKey(date)) {
-
 
208
                                        Map<String, Double> pQuantityMap = productQuantityMap.get(date);
-
 
209
                                        if (pQuantityMap.containsKey(productName)) {
-
 
210
                                            Double quantity = pQuantityMap.get(productName);
183
                                            + item.getQuantity() + ", "
211
                                            quantity += item.getQuantity();
-
 
212
                                            pQuantityMap.put(productName, quantity);
-
 
213
                                        }
-
 
214
                                        else {
-
 
215
                                            pQuantityMap.put(productName, item.getQuantity());
-
 
216
                                        }
-
 
217
                                    }
-
 
218
                                    else {
-
 
219
                                        Map<String, Double> pQuantityMap = new HashMap<String, Double>();
-
 
220
                                        pQuantityMap.put(productName, item.getQuantity());
-
 
221
                                        productQuantityMap.put(date, pQuantityMap);
-
 
222
                                    }
-
 
223
                                    
-
 
224
                                    if (productAmountMap.containsKey(date)) {
-
 
225
                                        Map<String, Double> pAmountMap = productAmountMap.get(date);
-
 
226
                                        if (pAmountMap.containsKey(productName)) {
-
 
227
                                            Double amount = pAmountMap.get(productName);
184
                                            + item.getTotal_price() + "), ";
228
                                            amount += item.getTotal_price();
-
 
229
                                            pAmountMap.put(productName, amount);
-
 
230
                                        }
-
 
231
                                        else {
-
 
232
                                            pAmountMap.put(productName, item.getTotal_price());
-
 
233
                                        }
-
 
234
                                    }
-
 
235
                                    else {
-
 
236
                                        Map<String, Double> pAmountMap = new HashMap<String, Double>();
-
 
237
                                        pAmountMap.put(productName, item.getTotal_price());
-
 
238
                                        productAmountMap.put(date, pAmountMap);
-
 
239
                                    }
185
                                }
240
                                }
186
                                contentRow.put("items", itemString.replaceAll("null", ""));
-
 
187
                            }
241
                            }
188
                        } catch (PaymentException e) {
-
 
189
                            log.error("Error while getting payment info", e);
-
 
190
                        } catch (TransactionServiceException e) {
-
 
191
                            log.error("Error while getting order info", e);
-
 
192
                        } catch (TException e) {
-
 
193
                            log.error("Unable to get order or payment info", e);
-
 
194
                        } catch (NullPointerException e) {
-
 
195
                            log.error("Unexpected exception", e);
-
 
196
                        }
242
                        }
197
                    }
243
                    }
198
                    contentRow.put("data", tracklog.getData());
-
 
199
                    if (orderCompleted) {
-
 
200
                        contentRows.add(contentRow);
-
 
201
                    }
-
 
202
                }
244
                }
203
            }
245
            }
204
             
246
            
205
            // Preparing XLS file for output
247
            // Preparing XLS file for output
206
            response.setContentType("application/vnd.ms-excel");
248
            response.setContentType("application/vnd.ms-excel");
207
            
249
            
208
            response.setHeader("Content-disposition", "inline; filename=" + filename + "-affiliate-report" + ".xls");
250
            response.setHeader("Content-disposition", "inline; filename=" + mAffName + "-affiliate-report" + ".xls");
209
            
251
            
210
            ServletOutputStream sos;
252
            ServletOutputStream sos;
211
            try {
253
            try {
212
                ByteArrayOutputStream baos = getSpreadSheetData(contentRows);
254
                ByteArrayOutputStream baos = getSpreadSheetData(mAffName, dates, registerCountMap, saleQuantityMap, saleAmountMap, productQuantityMap, productAmountMap);
213
                sos = response.getOutputStream();
255
                sos = response.getOutputStream();
214
                baos.writeTo(sos);
256
                baos.writeTo(sos);
215
                sos.flush();
257
                sos.flush();
216
            } catch (IOException e) {
258
            } catch (IOException e) {
217
                log.error("Unable to stream the affiliates report", e);
259
                log.error("Unable to stream the affiliates report", e);
Line 228... Line 270...
228
            errorMsg = e.getMessage();
270
            errorMsg = e.getMessage();
229
        }
271
        }
230
        return null;
272
        return null;
231
	}
273
	}
232
	
274
	
233
	// Prepares the XLS worksheet object and fills in the data with proper formatting
275
    // Prepares the XLS worksheet object and fills in the data with proper formatting
234
	private ByteArrayOutputStream getSpreadSheetData(List<Map<String, String>> contentRows)
276
	private ByteArrayOutputStream getSpreadSheetData(String mAffName, 
-
 
277
	        SortedSet<Date> dates,
-
 
278
            Map<Date, Long> registerCountMap,
-
 
279
            Map<Date, Double> saleQuantityMap,
-
 
280
            Map<Date, Double> saleAmountMap, 
-
 
281
            Map<Date, Map<String, Double>> productQuantityMap,
-
 
282
            Map<Date, Map<String, Double>> productAmountMap)
235
	{
283
	{
236
	    ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
284
	    ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
237
 
285
 
238
		Workbook wb = new HSSFWorkbook();
286
		Workbook wb = new HSSFWorkbook();
239
	    
287
	    
Line 242... Line 290...
242
	    CellStyle style = wb.createCellStyle();
290
	    CellStyle style = wb.createCellStyle();
243
	    style.setFont(font);
291
	    style.setFont(font);
244
	    
292
	    
245
	    CreationHelper createHelper = wb.getCreationHelper();
293
	    CreationHelper createHelper = wb.getCreationHelper();
246
	    CellStyle dateCellStyle = wb.createCellStyle();
294
	    CellStyle dateCellStyle = wb.createCellStyle();
247
	    dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("DD/MM/YYYY HH:MM"));
295
	    dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("DD/MM/YYYY"));
248
	    
296
	    
-
 
297
	    createSummarySheet(mAffName, dates, registerCountMap, saleQuantityMap, saleAmountMap, wb, style, dateCellStyle);
249
	    createAffiliateSheet(contentRows, wb, style, dateCellStyle);
298
	    createSaleDetailSheet(mAffName, dates, productQuantityMap, productAmountMap, wb, style, dateCellStyle);
250
	        	
299
	        	
251
		// Write the workbook to the output stream
300
		// Write the workbook to the output stream
252
		try {
301
		try {
253
			wb.write(baosXLS);
302
			wb.write(baosXLS);
254
			baosXLS.close();
303
			baosXLS.close();
Line 256... Line 305...
256
			log.error("Unable to get the byte array for the affiliate report", e);
305
			log.error("Unable to get the byte array for the affiliate report", e);
257
		}		
306
		}		
258
		return baosXLS;
307
		return baosXLS;
259
	}
308
	}
260
	
309
	
261
	private void createAffiliateSheet(List<Map<String, String>> contentRows, Workbook wb, CellStyle style, CellStyle dateCellStyle) 
310
    private void createSaleDetailSheet(String mAffName, SortedSet<Date> dates,
-
 
311
            Map<Date, Map<String, Double>> productQuantityMap,
-
 
312
            Map<Date, Map<String, Double>> productAmountMap, Workbook wb,
-
 
313
            CellStyle style, CellStyle dateCellStyle) {
-
 
314
        // Product Sales SHEET
-
 
315
        Sheet affSheet = wb.createSheet("Product Sales Report");
-
 
316
        short affSerialNo = 0;
-
 
317
        
-
 
318
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
-
 
319
 
-
 
320
        Row affTitleRow = affSheet.createRow(affSerialNo ++);
-
 
321
        Cell affTitleCell = affTitleRow.createCell(0);
-
 
322
        affTitleCell.setCellValue("Modelwise Sales Report");
-
 
323
        affTitleCell.setCellStyle(style);
-
 
324
        affSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
-
 
325
        
-
 
326
        affSheet.createRow(affSerialNo ++);
-
 
327
        Row affNameRow = affSheet.createRow(affSerialNo ++);
-
 
328
        Cell affNameCell = affNameRow.createCell(0);
-
 
329
        affNameCell.setCellValue("Affiliate : " + mAffName);
-
 
330
        affNameCell.setCellStyle(style);
-
 
331
        affSheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6));
-
 
332
        
-
 
333
        Row affDateRangeRow = affSheet.createRow(affSerialNo ++);
-
 
334
        Cell affDateRangeCell = affDateRangeRow.createCell(0);
-
 
335
        affDateRangeCell.setCellValue("Date Range : " + df.format(startDate) + " - " + df.format(endDate));
-
 
336
        affDateRangeCell.setCellStyle(style);
-
 
337
        affSheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6));
-
 
338
        
-
 
339
        affSheet.createRow(affSerialNo ++);affSheet.createRow(affSerialNo ++);
-
 
340
        
-
 
341
        Row affHeaderRow = affSheet.createRow(affSerialNo++);
-
 
342
        affHeaderRow.createCell(0).setCellValue("Date");
-
 
343
        affHeaderRow.createCell(1).setCellValue("ProductName");
-
 
344
        affHeaderRow.createCell(2).setCellValue("Sales Count");
-
 
345
        affHeaderRow.createCell(3).setCellValue("Amount");
-
 
346
        for (int i=0; i<4 ;i++) {
-
 
347
            affHeaderRow.getCell(i).setCellStyle(style);
-
 
348
        }
-
 
349
        
-
 
350
        for(Date date : dates) {
-
 
351
            if (!productQuantityMap.containsKey(date)) {
-
 
352
                continue;
-
 
353
            }
-
 
354
            for (Entry<String, Double> quantityEntry : productQuantityMap.get(date).entrySet()) {
-
 
355
                affSerialNo++;
-
 
356
                String prodName = quantityEntry.getKey();
-
 
357
                Double quantity = quantityEntry.getValue();
-
 
358
                Double amount = productAmountMap.get(date).get(prodName);
-
 
359
                Row commContentRow = affSheet.createRow(affSerialNo);
-
 
360
                commContentRow.createCell(0).setCellValue(date);
-
 
361
                commContentRow.getCell(0).setCellStyle(dateCellStyle);
-
 
362
                commContentRow.createCell(1).setCellValue(prodName);
-
 
363
                commContentRow.createCell(2).setCellValue(quantity);
-
 
364
                commContentRow.createCell(3).setCellValue(amount);
-
 
365
                
-
 
366
                for (int i = 0; i<4; i++) {
-
 
367
                    affSheet.autoSizeColumn(i);
-
 
368
                }
-
 
369
            }
-
 
370
        }
-
 
371
    }
262
	{
372
 
-
 
373
    private void createSummarySheet(String mAffName, 
-
 
374
            SortedSet<Date> dates,
-
 
375
            Map<Date, Long> registerCountMap,
-
 
376
            Map<Date, Double> saleQuantityMap,
-
 
377
            Map<Date, Double> saleAmountMap, 
-
 
378
            Workbook wb, 
-
 
379
            CellStyle style,
-
 
380
            CellStyle dateCellStyle) 
-
 
381
    {
263
		// Affiliate SHEET
382
		// Summary SHEET
264
	    Sheet affSheet = wb.createSheet("Affiliates Report");
383
	    Sheet affSheet = wb.createSheet("Summary Report");
265
	    short affSerialNo = 0;
384
	    short affSerialNo = 0;
-
 
385
	    
-
 
386
	    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
266
 
387
 
267
	    Row affTitleRow = affSheet.createRow(affSerialNo ++);
388
	    Row affTitleRow = affSheet.createRow(affSerialNo ++);
268
	    Cell affTitleCell = affTitleRow.createCell(0);
389
	    Cell affTitleCell = affTitleRow.createCell(0);
269
	    affTitleCell.setCellValue("Affiliates Report");
390
	    affTitleCell.setCellValue("Daily Stats Report");
270
	    affTitleCell.setCellStyle(style);
391
	    affTitleCell.setCellStyle(style);
271
	    
-
 
272
	    affSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
392
	    affSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
273
	    
393
	    
274
	    affSheet.createRow(affSerialNo ++);
394
	    affSheet.createRow(affSerialNo ++);
-
 
395
	    Row affNameRow = affSheet.createRow(affSerialNo ++);
-
 
396
        Cell affNameCell = affNameRow.createCell(0);
-
 
397
        affNameCell.setCellValue("Affiliate : " + mAffName);
-
 
398
        affNameCell.setCellStyle(style);
-
 
399
        affSheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6));
-
 
400
        
-
 
401
        Row affDateRangeRow = affSheet.createRow(affSerialNo ++);
-
 
402
        Cell affDateRangeCell = affDateRangeRow.createCell(0);
-
 
403
        affDateRangeCell.setCellValue("Date Range : " + df.format(startDate) + " - " + df.format(endDate));
-
 
404
        affDateRangeCell.setCellStyle(style);
-
 
405
        affSheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6));
-
 
406
        
-
 
407
	    affSheet.createRow(affSerialNo ++);affSheet.createRow(affSerialNo ++);
275
		
408
		
276
	    Row affHeaderRow = affSheet.createRow(affSerialNo++);
409
	    Row affHeaderRow = affSheet.createRow(affSerialNo++);
277
	    affHeaderRow.createCell(0).setCellValue("Affiliate");
-
 
278
	    affHeaderRow.createCell(1).setCellValue("Affiliate Url");
-
 
279
	    affHeaderRow.createCell(2).setCellValue("Date");
410
	    affHeaderRow.createCell(0).setCellValue("Date");
280
	    affHeaderRow.createCell(3).setCellValue("Event");
411
	    affHeaderRow.createCell(1).setCellValue("New Registrations");
281
	    affHeaderRow.createCell(4).setCellValue("Url");
-
 
282
	    affHeaderRow.createCell(5).setCellValue("Data");
-
 
283
	    affHeaderRow.createCell(6).setCellValue("Items");
412
	    affHeaderRow.createCell(2).setCellValue("Sales Count");
284
	    affHeaderRow.createCell(7).setCellValue("Amount");
413
	    affHeaderRow.createCell(3).setCellValue("Amount");
285
	    for (int i=0; i<8 ;i++) {
414
	    for (int i=0; i<4 ;i++) {
286
	        affHeaderRow.getCell(i).setCellStyle(style);
415
	        affHeaderRow.getCell(i).setCellStyle(style);
287
	    }
416
	    }
288
	    
417
	    
289
		for( Map<String, String> contentRow : contentRows) {
418
		for(Date date : dates) {
290
			affSerialNo++;
419
		    affSerialNo++;
291
			Row commContentRow = affSheet.createRow(affSerialNo);
420
			Row commContentRow = affSheet.createRow(affSerialNo);
292
			
-
 
293
			commContentRow.createCell(0).setCellValue(contentRow.get("affiliate"));
-
 
294
			commContentRow.createCell(1).setCellValue(contentRow.get("affiliateUrl"));
-
 
295
			commContentRow.createCell(2).setCellValue(new Date(Long.parseLong(contentRow.get("date"))));
-
 
296
			commContentRow.getCell(2).setCellStyle(dateCellStyle);
421
			Long registerCount = registerCountMap.get(date);
297
            commContentRow.createCell(3).setCellValue(contentRow.get("event"));
-
 
298
			commContentRow.createCell(4).setCellValue(contentRow.get("url"));
422
			Double saleQuantity = saleQuantityMap.get(date);
299
			commContentRow.createCell(5).setCellValue(contentRow.get("data"));
423
			Double saleAmount = saleAmountMap.get(date);
300
			if (contentRow.containsKey("items")) {
424
			if (registerCount == null) {
301
			    commContentRow.createCell(6).setCellValue(contentRow.get("items"));
-
 
302
			}
-
 
303
			if (contentRow.containsKey("amount")) {
425
			    registerCount = 0l;
304
	            commContentRow.createCell(7).setCellValue(contentRow.get("amount"));
-
 
305
			}
426
			}
-
 
427
			if (saleQuantity == null) {
-
 
428
                saleQuantity = 0d;
-
 
429
            }
-
 
430
			if (saleAmount == null) {
-
 
431
                saleAmount = 0d;
-
 
432
            }
-
 
433
			commContentRow.createCell(0).setCellValue(date);
-
 
434
			commContentRow.getCell(0).setCellStyle(dateCellStyle);
-
 
435
            commContentRow.createCell(1).setCellValue(registerCount);
-
 
436
			commContentRow.createCell(2).setCellValue(saleQuantity);
-
 
437
			commContentRow.createCell(3).setCellValue(saleAmount);
306
		}
438
		}
307
        for (int i = 0; i<8; i++) {
439
        for (int i = 0; i<4; i++) {
308
            affSheet.autoSizeColumn(i);
440
            affSheet.autoSizeColumn(i);
309
        }
441
        }
310
	}
442
	}
311
 
443
 
312
	public String getErrorMsg() {
444
	public String getErrorMsg() {