Subversion Repositories SmartDukaan

Rev

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

Rev 2393 Rev 2501
Line 13... Line 13...
13
import in.shop2020.thrift.clients.UserContextServiceClient;
13
import in.shop2020.thrift.clients.UserContextServiceClient;
14
 
14
 
15
import java.io.ByteArrayOutputStream;
15
import java.io.ByteArrayOutputStream;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.text.ParseException;
17
import java.text.ParseException;
-
 
18
import java.util.ArrayList;
18
import java.util.Date;
19
import java.util.Date;
19
import java.util.HashMap;
20
import java.util.HashMap;
20
import java.util.HashSet;
21
import java.util.HashSet;
21
import java.util.LinkedList;
22
import java.util.LinkedList;
22
import java.util.List;
23
import java.util.List;
Line 79... Line 80...
79
            Client userClient = userContextServiceClient.getClient();
80
            Client userClient = userContextServiceClient.getClient();
80
            in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
81
            in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
81
            in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
82
            in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
82
            
83
            
83
            Set<Long> Payments = new HashSet<Long>();
84
            Set<Long> Payments = new HashSet<Long>();
84
            List<Map<String, String>> contentRows = new LinkedList<Map<String,String>>(); 
85
            List<Map<String, String>> contentRows = new LinkedList<Map<String,String>>();
-
 
86
            List<Affiliate> affiliates;
-
 
87
            if (mAfId == -1) {
-
 
88
                affiliates = new ArrayList<Affiliate>();
-
 
89
                for(MasterAffiliate mAffiliate : userClient.getAllMasterAffiliates()) {
-
 
90
                    affiliates.addAll(userClient.getAffiliatesByMasterAffiliate(mAffiliate.getId()));
-
 
91
                }
-
 
92
            }
-
 
93
            else {
85
            MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(mAfId);
94
                MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(mAfId);
86
            for (Affiliate aff : userClient.getAffiliatesByMasterAffiliate(mAfId)) {
95
                affiliates = userClient.getAffiliatesByMasterAffiliate(mAfId);
-
 
96
            }
-
 
97
            for (Affiliate aff : affiliates) {
-
 
98
                MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(aff.getMasterAffiliateId());
87
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId())) {
99
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId())) {
88
                    Map<String, String> contentRow = new HashMap<String, String>();
100
                    Map<String, String> contentRow = new HashMap<String, String>();
89
                    contentRow.put("mAffiliate", mAffiliate.getName());
101
                    contentRow.put("mAffiliate", mAffiliate.getName());
90
                    contentRow.put("affiliate", aff.getName());
102
                    contentRow.put("affiliate", aff.getName());
91
                    contentRow.put("affiliateUrl", aff.getUrl());
103
                    contentRow.put("affiliateUrl", aff.getUrl());
Line 133... Line 145...
133
            
145
            
134
            response.setHeader("Content-disposition", "inline; filename=affiliate-report" + ".xls");
146
            response.setHeader("Content-disposition", "inline; filename=affiliate-report" + ".xls");
135
            
147
            
136
            ServletOutputStream sos;
148
            ServletOutputStream sos;
137
            try {
149
            try {
138
                ByteArrayOutputStream baos = getSpreadSheetData(contentRows, mAffiliate);
150
                ByteArrayOutputStream baos = getSpreadSheetData(contentRows);
139
                sos = response.getOutputStream();
151
                sos = response.getOutputStream();
140
                baos.writeTo(sos);
152
                baos.writeTo(sos);
141
                sos.flush();
153
                sos.flush();
142
            } catch (IOException e) {
154
            } catch (IOException e) {
143
                errorMsg = "Failed to write to response.";
155
                errorMsg = "Failed to write to response.";
Line 156... Line 168...
156
        }
168
        }
157
        return null;
169
        return null;
158
	}
170
	}
159
	
171
	
160
	// Prepares the XLS worksheet object and fills in the data with proper formatting
172
	// Prepares the XLS worksheet object and fills in the data with proper formatting
161
	private ByteArrayOutputStream getSpreadSheetData(List<Map<String, String>> contentRows, MasterAffiliate mAffiliate)
173
	private ByteArrayOutputStream getSpreadSheetData(List<Map<String, String>> contentRows)
162
	{
174
	{
163
	    ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
175
	    ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
164
 
176
 
165
		Workbook wb = new HSSFWorkbook();
177
		Workbook wb = new HSSFWorkbook();
166
	    
178
	    
Line 171... Line 183...
171
	    
183
	    
172
	    CreationHelper createHelper = wb.getCreationHelper();
184
	    CreationHelper createHelper = wb.getCreationHelper();
173
	    CellStyle dateCellStyle = wb.createCellStyle();
185
	    CellStyle dateCellStyle = wb.createCellStyle();
174
	    dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("DD/MM/YYYY HH:MM"));
186
	    dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("DD/MM/YYYY HH:MM"));
175
	    
187
	    
176
	    createAffiliateSheet(contentRows, mAffiliate, wb, style, dateCellStyle);
188
	    createAffiliateSheet(contentRows, wb, style, dateCellStyle);
177
	        	
189
	        	
178
		// Write the workbook to the output stream
190
		// Write the workbook to the output stream
179
		try {
191
		try {
180
			wb.write(baosXLS);
192
			wb.write(baosXLS);
181
			baosXLS.close();
193
			baosXLS.close();
Line 183... Line 195...
183
			e.printStackTrace();
195
			e.printStackTrace();
184
		}		
196
		}		
185
		return baosXLS;
197
		return baosXLS;
186
	}
198
	}
187
	
199
	
188
	private void createAffiliateSheet(
-
 
189
	        List<Map<String, String>> contentRows, 
200
	private void createAffiliateSheet(List<Map<String, String>> contentRows, Workbook wb, CellStyle style, CellStyle dateCellStyle) 
190
			MasterAffiliate mAffiliate, Workbook wb, 
-
 
191
			CellStyle style, CellStyle dateCellStyle) 
-
 
192
	{
201
	{
193
		// Affiliate SHEET
202
		// Affiliate SHEET
194
	    Sheet affSheet = wb.createSheet("Affiliates Report");
203
	    Sheet affSheet = wb.createSheet("Affiliates Report");
195
	    short affSerialNo = 0;
204
	    short affSerialNo = 0;
196
 
205
 
197
	    Row affTitleRow = affSheet.createRow(affSerialNo ++);
206
	    Row affTitleRow = affSheet.createRow(affSerialNo ++);
198
	    Cell affTitleCell = affTitleRow.createCell(0);
207
	    Cell affTitleCell = affTitleRow.createCell(0);
199
	    affTitleCell.setCellValue(mAffiliate.getName() + " Affiliates Report");
208
	    affTitleCell.setCellValue("Affiliates Report");
200
	    affTitleCell.setCellStyle(style);
209
	    affTitleCell.setCellStyle(style);
201
	    
210
	    
202
	    affSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
211
	    affSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
203
	    
212
	    
204
	    affSheet.createRow(affSerialNo ++);
213
	    affSheet.createRow(affSerialNo ++);