4343 * <p>
4444 * Version 1.1 (Member Payments Automation Assembly 1.0) Change notes:
4545 * <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
4747 * 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
5050 * {@link DataAccessConstants#END_RANK} parameters.</li>
5151 * <li>Added {@link #USER_PAYMENT_METHOD} constant.</li>
5252 * <li>Added {@link #PAYMENT_CONFIRMATION_TEMPLATE} constant.</li>
@@ -67,7 +67,7 @@ public class PaymentHistory extends BaseProcessor implements PactsConstants {
6767 /**
6868 * <p>A <code>String</code> providing the name for request attribute holding the ID of a payment method preferred by
6969 * current user.</p>
70- *
70+ *
7171 * @since 1.1
7272 */
7373 public static final String USER_PAYMENT_METHOD = "userPaymentMethod" ;
@@ -81,29 +81,29 @@ public class PaymentHistory extends BaseProcessor implements PactsConstants {
8181 public static final String PAYMENT_CONFIRMATION_TEMPLATE = "paymentConfirmationTemplate" ;
8282
8383 /**
84- *
84+ *
8585 */
8686 public static final String PAYMENT_ID = "paymentId" ;
87-
87+
8888 public static final String CODER = "cr" ;
8989 private static final int DESCRIPTION_COL = 1 ;
9090 private static final int TYPE_COL = 2 ;
9191 private static final int CREATE_DATE_COL = 3 ;
9292 private static final int NET_PAYMENT_COL = 4 ;
9393 private static final int STATUS_COL = 5 ;
94-
94+
9595 /**
9696 * <p>An <code>int</code> referencing the column with release dates for payments.</p>
97- *
97+ *
9898 * @since 1.1
9999 */
100100 private static final int RELEASE_DATE_COL = 6 ;
101-
101+
102102 private static final int PAID_DATE_COL = 7 ;
103103
104104 /**
105105 * <p>Processes the incoming request. Retrieves user payments and binds them to request.</p>
106- *
106+ *
107107 * @throws TCWebException if an unexpected error occurs.
108108 */
109109 protected void businessProcessing () throws TCWebException {
@@ -113,14 +113,14 @@ protected void businessProcessing() throws TCWebException {
113113 String sortColStr = StringUtils .checkNull (getRequest ().getParameter (DataAccessConstants .SORT_COLUMN ));
114114 boolean exportToExcel = "true" .equals (getRequest ().getParameter (XLS_FORMAT ));
115115 String numRecords = StringUtils .checkNull (getRequest ().getParameter (DataAccessConstants .NUMBER_RECORDS ));
116-
116+
117117 boolean sortAscending = "asc" .equals (getRequest ().getParameter (DataAccessConstants .SORT_DIRECTION ));
118118 int sortCol = 3 ;
119-
119+
120120 if (sortColStr .trim ().length () > 0 ) {
121121 sortCol = Integer .parseInt (sortColStr );
122122 }
123-
123+
124124 // Normalizes optional parameters and sets defaults
125125 if ("" .equals (numRecords )) {
126126 numRecords = "10" ;
@@ -137,27 +137,27 @@ protected void businessProcessing() throws TCWebException {
137137 String endRank = String .valueOf (Integer .parseInt (startRank ) + Integer .parseInt (numRecords ) - 1 );
138138 setDefault (DataAccessConstants .END_RANK , endRank );
139139
140-
140+
141141 DataInterfaceBean dib = new DataInterfaceBean ();
142-
142+
143143 Map criteria = new HashMap ();
144144 long userId = getUser ().getId ();
145145 criteria .put (PactsConstants .USER_ID , String .valueOf (userId ));
146146
147147 List <BasePayment > payments = dib .findCoderPayments (criteria );
148-
148+
149149 List <BasePayment > removePayments = new ArrayList <BasePayment >();
150150
151+ List <BasePayment > removeNonPending = new ArrayList <BasePayment >();
152+
151153 for (BasePayment payment : payments ) {
152154 if (payment .getPaymentType () == 3 || payment .getPaymentType () == 5 ) {
153155 removePayments .add (payment );
154156 } 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 );
161161 }
162162
163163 // Deleted payments should not be shown either way.
@@ -166,36 +166,43 @@ protected void businessProcessing() throws TCWebException {
166166 }
167167 }
168168 }
169-
169+
170170 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+
172182 // sort the result in the first place
173183 sortResult (payments , sortCol , sortAscending );
174-
184+
175185 if ("on" .equalsIgnoreCase (com .topcoder .web .tc .Constants .GLOBAL_AD_FLAG )) {
176186 removeDuplicateReasons (payments );
177187 }
178188
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 );
184193 }
185-
186- getRequest ().setAttribute ("NUM_TOTAL" , payments .size ());
187194 getRequest ().setAttribute ("NUM_PER_PAGE" , numRecords );
188- getRequest ().setAttribute ("NUM_PENDING" , paymentPendings . size () );
195+ getRequest ().setAttribute ("NUM_PENDING" , PaymentsPending );
189196
190197 if (exportToExcel ) {
191198 produceXLS (payments );
192199 } else {
193200 // now crop
194201 payments = cropResult (payments , Integer .parseInt (startRank ), Integer .parseInt (endRank ));
195-
202+
196203 setDefault (DataAccessConstants .SORT_COLUMN , sortCol + "" );
197204 setDefault (DataAccessConstants .SORT_DIRECTION , getRequest ().getParameter (DataAccessConstants .SORT_DIRECTION ));
198-
205+
199206 getRequest ().setAttribute (PAYMENTS , payments );
200207 getRequest ().setAttribute (CODER , userId + "" );
201208 getRequest ().setAttribute (FULL_LIST , Boolean .valueOf (fullList ));
@@ -209,22 +216,22 @@ protected void businessProcessing() throws TCWebException {
209216 s .addDefault (RELEASE_DATE_COL , "desc" );
210217 s .addDefault (PAID_DATE_COL , "desc" );
211218 getRequest ().setAttribute (SortInfo .REQUEST_KEY , s );
212-
219+
213220 // Get user's payment method preferences
214221 Long userPaymentMethod = dib .getUserPaymentMethod (userId );
215222 getRequest ().setAttribute (USER_PAYMENT_METHOD , userPaymentMethod );
216223 if (userPaymentMethod != null ) {
217224 if (userPaymentMethod == PAYPAL_PAYMENT_METHOD_ID ) {
218225 getRequest ()
219- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
226+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
220227 Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_PAYPAL );
221228 } else if (userPaymentMethod == PAYONEER_PAYMENT_METHOD_ID ) {
222229 getRequest ()
223- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
230+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
224231 Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_PAYONEER );
225232 } else if (userPaymentMethod == WESTERN_UNION_PAYMENT_METHOD_ID ) {
226233 getRequest ()
227- .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
234+ .setAttribute (PAYMENT_CONFIRMATION_TEMPLATE ,
228235 Constants .PAYME_CONFIRMATION_MESSAGE_TEMPLATE_WESTERN_UNION );
229236 }
230237 }
@@ -300,22 +307,22 @@ private void insertSheetData(Sheet sheet, List<BasePayment> payments) {
300307 }
301308
302309 /**
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.
306313 * @param startRank an <code>int</code> providing the index of starting item.
307314 * @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.
309316 */
310317 private List cropResult (List result , int startRank , int endRank ) {
311318 Boolean croppedDataAfter = Boolean .TRUE ;
312319 if (endRank >= result .size ()) {
313320 endRank = result .size ();
314321 croppedDataAfter = Boolean .FALSE ;
315322 }
316- getRequest ().setAttribute ("croppedDataAfter" , croppedDataAfter );
323+ getRequest ().setAttribute ("croppedDataAfter" , croppedDataAfter );
317324 getRequest ().setAttribute ("croppedDataBefore" , new Boolean (startRank > 1 ));
318-
325+
319326
320327 if (result .size () > 0 ) {
321328 if (startRank <= endRank ) {
@@ -337,7 +344,7 @@ protected void removeDuplicateReasons(List<BasePayment> result) {
337344 if (result .size () == 0 ) {
338345 return ;
339346 }
340-
347+
341348 for (BasePayment bp : result ) {
342349 if (bp .getCurrentStatus ().getReasons ().contains (AvailableStatusReason .NO_HARD_COPY_AD_REASON .getStatusReason ()) &&
343350 bp .getCurrentStatus ().getReasons ().contains (AvailableStatusReason .NO_SIGNED_GLOBAL_AD_REASON .getStatusReason ())) {
@@ -348,7 +355,7 @@ protected void removeDuplicateReasons(List<BasePayment> result) {
348355
349356 /**
350357 * <p>Sorts the specified payments against specified column in specified order.</p>
351- *
358+ *
352359 * @param result a list of payments to sort.
353360 * @param sortCol a number of column to sort against.
354361 * @param sortAscending true if sorting is to be ascending; false if descending.
@@ -374,10 +381,10 @@ public int compare(Object arg0, Object arg1) {
374381 public int compare (Object arg0 , Object arg1 ) {
375382 Date date0 = ((BasePayment ) arg0 ).getCreateDate ();
376383 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+
381388 return date0 .compareTo (date1 );
382389 }
383390 });
@@ -388,7 +395,7 @@ public int compare(Object arg0, Object arg1) {
388395 if (((BasePayment ) arg0 ).getNetAmount () == ((BasePayment ) arg1 ).getNetAmount ()) {
389396 return 0 ;
390397 }
391-
398+
392399 return ((BasePayment ) arg0 ).getNetAmount () < ((BasePayment ) arg1 ).getNetAmount () ? -1 : 1 ;
393400 }
394401 });
@@ -414,14 +421,14 @@ public int compare(Object arg0, Object arg1) {
414421 });
415422 break ;
416423 case PAID_DATE_COL :
417- Collections .sort (result , new Comparator () {
424+ Collections .sort (result , new Comparator () {
418425 public int compare (Object arg0 , Object arg1 ) {
419426 Date date0 = ((BasePayment ) arg0 ).getPaidDate ();
420427 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+
425432 return date0 .compareTo (date1 );
426433 }
427434 });
0 commit comments