43
43
* <p>
44
44
* Version 1.1 (Member Payments Automation Assembly 1.0) Change notes:
45
45
* <ol>
46
- * <li>Updated {@link #insertSheetData(Sheet, List)} method to include new <code>Release Date</code> column into
46
+ * <li>Updated {@link #insertSheetData(Sheet, List)} method to include new <code>Release Date</code> column into
47
47
* generated Excel worksheet.</li>
48
- * <li>Updated {@link #businessProcessing()} method to parse new {@link DataAccessConstants#NUMBER_RECORDS}
49
- * parameter and fix the bug with parsing {@link DataAccessConstants#START_RANK} and
48
+ * <li>Updated {@link #businessProcessing()} method to parse new {@link DataAccessConstants#NUMBER_RECORDS}
49
+ * parameter and fix the bug with parsing {@link DataAccessConstants#START_RANK} and
50
50
* {@link DataAccessConstants#END_RANK} parameters.</li>
51
51
* <li>Added {@link #USER_PAYMENT_METHOD} constant.</li>
52
52
* <li>Added {@link #PAYMENT_CONFIRMATION_TEMPLATE} constant.</li>
@@ -67,7 +67,7 @@ public class PaymentHistory extends BaseProcessor implements PactsConstants {
67
67
/**
68
68
* <p>A <code>String</code> providing the name for request attribute holding the ID of a payment method preferred by
69
69
* current user.</p>
70
- *
70
+ *
71
71
* @since 1.1
72
72
*/
73
73
public static final String USER_PAYMENT_METHOD = "userPaymentMethod" ;
@@ -81,29 +81,29 @@ public class PaymentHistory extends BaseProcessor implements PactsConstants {
81
81
public static final String PAYMENT_CONFIRMATION_TEMPLATE = "paymentConfirmationTemplate" ;
82
82
83
83
/**
84
- *
84
+ *
85
85
*/
86
86
public static final String PAYMENT_ID = "paymentId" ;
87
-
87
+
88
88
public static final String CODER = "cr" ;
89
89
private static final int DESCRIPTION_COL = 1 ;
90
90
private static final int TYPE_COL = 2 ;
91
91
private static final int CREATE_DATE_COL = 3 ;
92
92
private static final int NET_PAYMENT_COL = 4 ;
93
93
private static final int STATUS_COL = 5 ;
94
-
94
+
95
95
/**
96
96
* <p>An <code>int</code> referencing the column with release dates for payments.</p>
97
- *
97
+ *
98
98
* @since 1.1
99
99
*/
100
100
private static final int RELEASE_DATE_COL = 6 ;
101
-
101
+
102
102
private static final int PAID_DATE_COL = 7 ;
103
103
104
104
/**
105
105
* <p>Processes the incoming request. Retrieves user payments and binds them to request.</p>
106
- *
106
+ *
107
107
* @throws TCWebException if an unexpected error occurs.
108
108
*/
109
109
protected void businessProcessing () throws TCWebException {
@@ -113,14 +113,14 @@ protected void businessProcessing() throws TCWebException {
113
113
String sortColStr = StringUtils .checkNull (getRequest ().getParameter (DataAccessConstants .SORT_COLUMN ));
114
114
boolean exportToExcel = "true" .equals (getRequest ().getParameter (XLS_FORMAT ));
115
115
String numRecords = StringUtils .checkNull (getRequest ().getParameter (DataAccessConstants .NUMBER_RECORDS ));
116
-
116
+
117
117
boolean sortAscending = "asc" .equals (getRequest ().getParameter (DataAccessConstants .SORT_DIRECTION ));
118
118
int sortCol = 3 ;
119
-
119
+
120
120
if (sortColStr .trim ().length () > 0 ) {
121
121
sortCol = Integer .parseInt (sortColStr );
122
122
}
123
-
123
+
124
124
// Normalizes optional parameters and sets defaults
125
125
if ("" .equals (numRecords )) {
126
126
numRecords = "10" ;
@@ -137,27 +137,27 @@ protected void businessProcessing() throws TCWebException {
137
137
String endRank = String .valueOf (Integer .parseInt (startRank ) + Integer .parseInt (numRecords ) - 1 );
138
138
setDefault (DataAccessConstants .END_RANK , endRank );
139
139
140
-
140
+
141
141
DataInterfaceBean dib = new DataInterfaceBean ();
142
-
142
+
143
143
Map criteria = new HashMap ();
144
144
long userId = getUser ().getId ();
145
145
criteria .put (PactsConstants .USER_ID , String .valueOf (userId ));
146
146
147
147
List <BasePayment > payments = dib .findCoderPayments (criteria );
148
-
148
+
149
149
List <BasePayment > removePayments = new ArrayList <BasePayment >();
150
150
151
+ List <BasePayment > removeNonPending = new ArrayList <BasePayment >();
152
+
151
153
for (BasePayment payment : payments ) {
152
154
if (payment .getPaymentType () == 3 || payment .getPaymentType () == 5 ) {
153
155
removePayments .add (payment );
154
156
} else {
155
- if (!fullList && !exportToExcel ) {
156
- if (payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .CANCELLED_PAYMENT_STATUS )) ||
157
- payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .EXPIRED_PAYMENT_STATUS )) ||
158
- payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .PAID_PAYMENT_STATUS ))) {
159
- removePayments .add (payment );
160
- }
157
+ if (payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .CANCELLED_PAYMENT_STATUS )) ||
158
+ payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .EXPIRED_PAYMENT_STATUS )) ||
159
+ payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .PAID_PAYMENT_STATUS ))) {
160
+ removeNonPending .add (payment );
161
161
}
162
162
163
163
// Deleted payments should not be shown either way.
@@ -166,36 +166,43 @@ protected void businessProcessing() throws TCWebException {
166
166
}
167
167
}
168
168
}
169
-
169
+
170
170
payments .removeAll (removePayments );
171
-
171
+
172
+ int totalPayment = payments .size ();
173
+
174
+ if (!fullList && !exportToExcel ) {
175
+ if (removeNonPending .size () > 0 ) {
176
+ payments .removeAll (removeNonPending );
177
+ }
178
+ }
179
+
180
+ int PaymentsPending = totalPayment - removeNonPending .size ();
181
+
172
182
// sort the result in the first place
173
183
sortResult (payments , sortCol , sortAscending );
174
-
184
+
175
185
if ("on" .equalsIgnoreCase (com .topcoder .web .tc .Constants .GLOBAL_AD_FLAG )) {
176
186
removeDuplicateReasons (payments );
177
187
}
178
188
179
- List <BasePayment > paymentPendings = new ArrayList <BasePayment >();
180
- for (BasePayment payment : payments ) {
181
- if (payment .getCurrentStatus ().equals (PaymentStatusFactory .createStatus (PaymentStatus .OWED_PAYMENT_STATUS ))) {
182
- paymentPendings .add (payment );
183
- }
189
+ if (!fullList && !exportToExcel ) {
190
+ getRequest ().setAttribute ("NUM_TOTAL" , PaymentsPending );
191
+ } else {
192
+ getRequest ().setAttribute ("NUM_TOTAL" , totalPayment );
184
193
}
185
-
186
- getRequest ().setAttribute ("NUM_TOTAL" , payments .size ());
187
194
getRequest ().setAttribute ("NUM_PER_PAGE" , numRecords );
188
- getRequest ().setAttribute ("NUM_PENDING" , paymentPendings . size () );
195
+ getRequest ().setAttribute ("NUM_PENDING" , PaymentsPending );
189
196
190
197
if (exportToExcel ) {
191
198
produceXLS (payments );
192
199
} else {
193
200
// now crop
194
201
payments = cropResult (payments , Integer .parseInt (startRank ), Integer .parseInt (endRank ));
195
-
202
+
196
203
setDefault (DataAccessConstants .SORT_COLUMN , sortCol + "" );
197
204
setDefault (DataAccessConstants .SORT_DIRECTION , getRequest ().getParameter (DataAccessConstants .SORT_DIRECTION ));
198
-
205
+
199
206
getRequest ().setAttribute (PAYMENTS , payments );
200
207
getRequest ().setAttribute (CODER , userId + "" );
201
208
getRequest ().setAttribute (FULL_LIST , Boolean .valueOf (fullList ));
@@ -209,22 +216,22 @@ protected void businessProcessing() throws TCWebException {
209
216
s .addDefault (RELEASE_DATE_COL , "desc" );
210
217
s .addDefault (PAID_DATE_COL , "desc" );
211
218
getRequest ().setAttribute (SortInfo .REQUEST_KEY , s );
212
-
219
+
213
220
// Get user's payment method preferences
214
221
Long userPaymentMethod = dib .getUserPaymentMethod (userId );
215
222
getRequest ().setAttribute (USER_PAYMENT_METHOD , userPaymentMethod );
216
223
if (userPaymentMethod != null ) {
217
224
if (userPaymentMethod == PAYPAL_PAYMENT_METHOD_ID ) {
218
225
getRequest ()
219
- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
226
+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
220
227
Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_PAYPAL );
221
228
} else if (userPaymentMethod == PAYONEER_PAYMENT_METHOD_ID ) {
222
229
getRequest ()
223
- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
230
+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
224
231
Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_PAYONEER );
225
232
} else if (userPaymentMethod == WESTERN_UNION_PAYMENT_METHOD_ID ) {
226
233
getRequest ()
227
- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
234
+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
228
235
Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_WESTERN_UNION );
229
236
}
230
237
}
@@ -300,22 +307,22 @@ private void insertSheetData(Sheet sheet, List<BasePayment> payments) {
300
307
}
301
308
302
309
/**
303
- * <p>Gets the items for the specified range within the specified list.</p>
304
- *
305
- * @param result a <code>List</code> providing the data.
310
+ * <p>Gets the items for the specified range within the specified list.</p>
311
+ *
312
+ * @param result a <code>List</code> providing the data.
306
313
* @param startRank an <code>int</code> providing the index of starting item.
307
314
* @param endRank an <code>int</code> providing the index of last item.
308
- * @return a <code>List</code> listing the items within the specified range.
315
+ * @return a <code>List</code> listing the items within the specified range.
309
316
*/
310
317
private List cropResult (List result , int startRank , int endRank ) {
311
318
Boolean croppedDataAfter = Boolean .TRUE ;
312
319
if (endRank >= result .size ()) {
313
320
endRank = result .size ();
314
321
croppedDataAfter = Boolean .FALSE ;
315
322
}
316
- getRequest ().setAttribute ("croppedDataAfter" , croppedDataAfter );
323
+ getRequest ().setAttribute ("croppedDataAfter" , croppedDataAfter );
317
324
getRequest ().setAttribute ("croppedDataBefore" , new Boolean (startRank > 1 ));
318
-
325
+
319
326
320
327
if (result .size () > 0 ) {
321
328
if (startRank <= endRank ) {
@@ -337,7 +344,7 @@ protected void removeDuplicateReasons(List<BasePayment> result) {
337
344
if (result .size () == 0 ) {
338
345
return ;
339
346
}
340
-
347
+
341
348
for (BasePayment bp : result ) {
342
349
if (bp .getCurrentStatus ().getReasons ().contains (AvailableStatusReason .NO_HARD_COPY_AD_REASON .getStatusReason ()) &&
343
350
bp .getCurrentStatus ().getReasons ().contains (AvailableStatusReason .NO_SIGNED_GLOBAL_AD_REASON .getStatusReason ())) {
@@ -348,7 +355,7 @@ protected void removeDuplicateReasons(List<BasePayment> result) {
348
355
349
356
/**
350
357
* <p>Sorts the specified payments against specified column in specified order.</p>
351
- *
358
+ *
352
359
* @param result a list of payments to sort.
353
360
* @param sortCol a number of column to sort against.
354
361
* @param sortAscending true if sorting is to be ascending; false if descending.
@@ -374,10 +381,10 @@ public int compare(Object arg0, Object arg1) {
374
381
public int compare (Object arg0 , Object arg1 ) {
375
382
Date date0 = ((BasePayment ) arg0 ).getCreateDate ();
376
383
Date date1 = ((BasePayment ) arg1 ).getCreateDate ();
377
- if (date0 == null && date1 == null ) return 0 ;
378
- if (date0 == null && date1 != null ) return -1 ;
379
- if (date0 != null && date1 == null ) return 1 ;
380
-
384
+ if (date0 == null && date1 == null ) return 0 ;
385
+ if (date0 == null && date1 != null ) return -1 ;
386
+ if (date0 != null && date1 == null ) return 1 ;
387
+
381
388
return date0 .compareTo (date1 );
382
389
}
383
390
});
@@ -388,7 +395,7 @@ public int compare(Object arg0, Object arg1) {
388
395
if (((BasePayment ) arg0 ).getNetAmount () == ((BasePayment ) arg1 ).getNetAmount ()) {
389
396
return 0 ;
390
397
}
391
-
398
+
392
399
return ((BasePayment ) arg0 ).getNetAmount () < ((BasePayment ) arg1 ).getNetAmount () ? -1 : 1 ;
393
400
}
394
401
});
@@ -414,14 +421,14 @@ public int compare(Object arg0, Object arg1) {
414
421
});
415
422
break ;
416
423
case PAID_DATE_COL :
417
- Collections .sort (result , new Comparator () {
424
+ Collections .sort (result , new Comparator () {
418
425
public int compare (Object arg0 , Object arg1 ) {
419
426
Date date0 = ((BasePayment ) arg0 ).getPaidDate ();
420
427
Date date1 = ((BasePayment ) arg1 ).getPaidDate ();
421
- if (date0 == null && date1 == null ) return 0 ;
422
- if (date0 == null && date1 != null ) return -1 ;
423
- if (date0 != null && date1 == null ) return 1 ;
424
-
428
+ if (date0 == null && date1 == null ) return 0 ;
429
+ if (date0 == null && date1 != null ) return -1 ;
430
+ if (date0 != null && date1 == null ) return 1 ;
431
+
425
432
return date0 .compareTo (date1 );
426
433
}
427
434
});
0 commit comments