Changeset 2632 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
- Timestamp:
- 02/26/2016 12:56:15 AM (10 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
includes/payment-requests-dashboard.php (modified) (24 diffs)
-
includes/payment-requests-list-table.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
-
Property
svn:mergeinfo
set to
/sites/branches/wcb-payment-request-statuses/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network merged eligible
-
Property
svn:mergeinfo
set to
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php
r2597 r2632 3 3 class Payment_Requests_Dashboard { 4 4 public static $list_table; 5 public static $db_version = 6;5 public static $db_version = 7; 6 6 public static $import_results = null; 7 7 … … 20 20 add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) ); 21 21 add_action( 'init', array( __CLASS__, 'upgrade' ) ); 22 add_action( 'init', array( __CLASS__, 'process_approval' ) ); 22 23 add_action( 'init', array( __CLASS__, 'process_export_request' ) ); 23 24 add_action( 'init', array( __CLASS__, 'process_import_request' ) ); … … 61 62 post_id int(11) unsigned NOT NULL default '0', 62 63 created int(11) unsigned NOT NULL default '0', 64 updated int(11) unsigned NOT NULL default '0', 63 65 paid int(11) unsigned NOT NULL default '0', 64 66 category varchar(255) NOT NULL default '', … … 99 101 while ( $requests = get_posts( array( 100 102 'paged' => $paged++, 101 'post_status' => array( 'paid', 'unpaid', 'incomplete' ),103 'post_status' => 'any', 102 104 'post_type' => 'wcp_payment_request', 103 105 'posts_per_page' => 20, … … 142 144 } 143 145 146 $back_compat_statuses = array( 147 'unpaid' => 'draft', 148 'incomplete' => 'wcb-incomplete', 149 'paid' => 'wcb-paid', 150 ); 151 152 // Map old statuses to new statuses. 153 if ( array_key_exists( $request->post_status, $back_compat_statuses ) ) { 154 $request->post_status = $back_compat_statuses[ $request->post_status ]; 155 } 156 157 // One of these timestamps. 158 while ( true ) { 159 $updated_timestamp = absint( get_post_meta( $request->ID, '_wcb_updated_timestamp', time() ) ); 160 if ( $updated_timestamp ) break; 161 162 $updated_timestamp = strtotime( $request->post_modified_gmt ); 163 if ( $updated_timestamp ) break; 164 165 $updated_timestamp = strtotime( $request->post_date_gmt ); 166 if ( $updated_timestamp ) break; 167 168 $updated_timestamp = strtotime( $request->post_date ); 169 break; 170 } 171 144 172 return array( 145 173 'blog_id' => get_current_blog_id(), 146 174 'post_id' => $request->ID, 147 175 'created' => get_post_time( 'U', true, $request->ID ), 176 'updated' => $updated_timestamp, 148 177 'paid' => absint( get_post_meta( $request->ID, '_camppayments_date_vendor_paid', true ) ), 149 178 'due' => absint( get_post_meta( $request->ID, '_camppayments_due_by', true ) ), … … 228 257 <h1>Vendor Payments</h1> 229 258 259 <?php do_action( 'admin_notices' ); ?> 230 260 <?php settings_errors(); ?> 231 261 … … 268 298 269 299 <?php 300 } 301 302 /** 303 * Process Approve button in network admin 304 */ 305 public static function process_approval() { 306 if ( ! current_user_can( 'network_admin' ) ) 307 return; 308 309 if ( empty( $_GET['wcb-approve'] ) || empty( $_GET['_wpnonce'] ) ) 310 return; 311 312 list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-approve'] ); 313 314 if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-approve-%d-%d', $blog_id, $post_id ) ) ) { 315 add_action( 'admin_notices', function() { 316 ?><div class="notice notice-error is-dismissible"> 317 <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p> 318 </div><?php 319 }); 320 return; 321 } 322 323 switch_to_blog( $blog_id ); 324 $post = get_post( $post_id ); 325 if ( $post->post_type == 'wcp_payment_request' ) { 326 $post->post_status = 'wcb-approved'; 327 wp_insert_post( $post ); 328 329 WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request approved via Network Admin', array( 330 'action' => 'approved', 331 ) ); 332 333 add_action( 'admin_notices', function() { 334 ?><div class="notice notice-success is-dismissible"> 335 <p><?php _e( 'Success! Request has been marked as approved.', 'wordcamporg' ); ?></p> 336 </div><?php 337 }); 338 } 339 restore_current_blog(); 270 340 } 271 341 … … 324 394 } 325 395 396 $status = $_POST['wcpn_export_status']; 397 if ( ! in_array( $status, array( 'wcb-approved', 'wcb-paid' ) ) ) 398 $status = 'wcb-approved'; 399 326 400 $start_date = strtotime( $_POST['wcpn_export_start_date'] . ' 00:00:00' ); 327 401 $end_date = strtotime( $_POST['wcpn_export_end_date'] . ' 23:59:59' ); … … 329 403 $filename = sanitize_file_name( $filename ); 330 404 331 $report = self::generate_payment_report( $ _POST['wcpn_date_type'], $start_date, $end_date, $export_type );405 $report = self::generate_payment_report( $status, $start_date, $end_date, $export_type ); 332 406 333 407 if ( is_wp_error( $report ) ) { … … 355 429 * @return string | WP_Error 356 430 */ 357 protected static function generate_payment_report( $ date_type, $start_date, $end_date, $export_type ) {431 protected static function generate_payment_report( $status, $start_date, $end_date, $export_type ) { 358 432 global $wpdb; 359 360 if ( ! in_array( $date_type, array( 'paid', 'created' ), true ) ) {361 return new WP_Error( 'wcpn_bad_date_type', 'Invalid date type.' );362 }363 433 364 434 if ( ! is_int( $start_date ) || ! is_int( $end_date ) ) { … … 367 437 368 438 $table_name = self::get_table_name(); 439 $date_type = 'updated'; 440 441 if ( $status == 'wcb-paid' ) 442 $date_type = 'paid'; 369 443 370 444 $request_indexes = $wpdb->get_results( $wpdb->prepare( " … … 381 455 $args = array( 382 456 'request_indexes' => $request_indexes, 383 'date_type' => $date_type,384 457 'start_date' => $start_date, 385 458 'end_date' => $end_date, 386 459 'export_type' => $export_type, 460 'status' => $status, 387 461 ); 388 462 … … 400 474 $args = wp_parse_args( $args, array( 401 475 'request_indexes' => array(), 476 'status' => '', 402 477 ) ); 403 478 … … 414 489 415 490 foreach( $args['request_indexes'] as $index ) { 416 fputcsv( $report, self::get_report_row( $index ) ); 491 $row = self::get_report_row( $index, $args ); 492 if ( ! empty( $row ) ) { 493 fputcsv( $report, $row ); 494 } 417 495 } 418 496 … … 431 509 $args = wp_parse_args( $args, array( 432 510 'request_indexes' => array(), 511 'status' => '', 433 512 ) ); 434 513 … … 452 531 switch_to_blog( $index->blog_id ); 453 532 $post = get_post( $index->post_id ); 533 534 if ( $args['status'] && $post->post_status != $args['status'] ) 535 continue; 454 536 455 537 if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Check' ) … … 539 621 $args = wp_parse_args( $args, array( 540 622 'request_indexes' => array(), 623 'status' => '', 541 624 ) ); 542 625 … … 605 688 $post = get_post( $index->post_id ); 606 689 690 if ( $args['status'] && $post->post_status != $args['status'] ) 691 continue; 692 607 693 if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' ) 608 694 continue; … … 738 824 $args = wp_parse_args( $args, array( 739 825 'request_indexes' => array(), 826 'status' => '', 740 827 ) ); 741 828 … … 752 839 switch_to_blog( $index->blog_id ); 753 840 $post = get_post( $index->post_id ); 841 842 if ( $args['status'] && $post->post_status != $args['status'] ) 843 continue; 754 844 755 845 // Only wires here. … … 955 1045 * 956 1046 * @param stdClass $index 1047 * @param array $args 957 1048 * 958 1049 * @return array 959 1050 */ 960 protected static function get_report_row( $index ) {1051 protected static function get_report_row( $index, $args ) { 961 1052 switch_to_blog( $index->blog_id ); 962 1053 963 $request = get_post( $index->post_id ); 1054 $request = get_post( $index->post_id ); 1055 1056 $back_compat_statuses = array( 1057 'unpaid' => 'draft', 1058 'incomplete' => 'wcb-incomplete', 1059 'paid' => 'wcb-paid', 1060 ); 1061 1062 // Map old statuses to new statuses. 1063 if ( array_key_exists( $request->post_status, $back_compat_statuses ) ) { 1064 $request->post_status = $back_compat_statuses[ $request->post_status ]; 1065 } 1066 1067 if ( $args['status'] && $request->post_status != $args['status'] ) { 1068 return null; 1069 } 1070 964 1071 $currency = get_post_meta( $index->post_id, '_camppayments_currency', true ); 965 1072 $category = get_post_meta( $index->post_id, '_camppayments_payment_category', true ); … … 1032 1139 <?php wp_nonce_field( 'export', 'wcpn_request_export' ); ?> 1033 1140 1034 <p> 1035 This form will supply a CSV file with payment requests matching the parameters you select below. 1036 For example, all requests that were <code>paid</code> between <code><?php echo esc_html( $last_month ); ?></code> and <code><?php echo esc_html( $today ); ?></code>. 1037 </p> 1038 1039 <p> 1040 <label> 1041 Date type: 1042 <select name="wcpn_date_type"> 1043 <option value="created">created</option> 1044 <option value="paid" selected>paid</option> 1045 </select> 1046 </label> 1047 </p> 1048 1049 <p> 1050 <label> 1051 Start date: 1052 <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" /> 1053 </label> 1054 </p> 1055 1056 <p> 1057 <label> 1058 End date: 1059 <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" /> 1060 </label> 1061 </p> 1062 1063 <p> 1064 <label>Export Type: 1065 <select name="wcpn_export_type"> 1066 <?php foreach ( self::get_export_types() as $key => $export_type ) : ?> 1067 <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option> 1068 <?php endforeach; ?> 1069 </select> 1070 </label> 1071 1072 <?php submit_button( 'Export' ); ?> 1141 <h2>Export Settings</h2> 1142 1143 <table class="form-table"> 1144 <tr> 1145 <th><label>Status</label></th> 1146 <td> 1147 <select name="wcpn_export_status"> 1148 <option value="wcb-approved"><?php _e( 'Approved', 'wordcamporg' ); ?></option> 1149 <option value="wcb-paid"><?php _e( 'Paid', 'wordcamporg' ); ?></option> 1150 </select> 1151 </td> 1152 </tr> 1153 <tr> 1154 <th><label>Date Range</label></th> 1155 <td> 1156 <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" /> to 1157 <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" /> 1158 </td> 1159 </tr> 1160 <tr> 1161 <th><label>Format</label></th> 1162 <td> 1163 <select name="wcpn_export_type"> 1164 <?php foreach ( self::get_export_types() as $key => $export_type ) : ?> 1165 <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option> 1166 <?php endforeach; ?> 1167 </select> 1168 </td> 1169 </tr> 1170 </table> 1171 1172 <?php submit_button( 'Download Export' ); ?> 1073 1173 </form> 1074 1174 … … 1230 1330 $tab = 'overdue'; 1231 1331 $tabs = array( 1232 'pending',1233 1332 'overdue', 1333 1334 'pending-approval', 1335 'approved', 1336 'pending-payment', 1234 1337 'paid', 1338 'cancelled-failed', 1235 1339 'incomplete', 1340 1236 1341 'export', 1237 1342 'import', … … 1251 1356 $current_section = self::get_current_tab(); 1252 1357 $sections = array( 1253 'overdue' => 'Overdue', 1254 'pending' => 'Pending', 1255 'paid' => 'Paid', 1256 'incomplete' => __( 'Incomplete', 'wordcamporg' ), 1257 'export' => __( 'Export', 'wordcamporg' ), 1258 'import' => __( 'Import', 'wordcamporg' ), 1358 'overdue' => __( 'Overdue', 'wordcamporg' ), // pending-approval + after due date 1359 'pending-approval' => __( 'Pending Approval', 'wordcamporg' ), 1360 'approved' => __( 'Approved', 'wordcamporg' ), 1361 'pending-payment' => __( 'Pending Payment', 'wordcamporg' ), 1362 'paid' => __( 'Paid', 'wordcamporg' ), 1363 'cancelled-failed' => __( 'Cancelled/Failed', 'wordcamporg' ), 1364 'incomplete' => __( 'Incomplete', 'wordcamporg' ), 1365 'export' => __( 'Export', 'wordcamporg' ), 1366 'import' => __( 'Import', 'wordcamporg' ), 1259 1367 ); 1260 1368 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-list-table.php
r2538 r2632 77 77 78 78 if ( 'overdue' == $view ) { 79 $where .= $wpdb->prepare( " AND `status` = 'unpaid' AND `due` > 0 AND `due` <= %d ", time() ); 80 } elseif ( 'pending' == $view ) { 81 $where .= " AND `status` = 'unpaid' "; 79 $where .= $wpdb->prepare( " AND `status` = 'wcb-pending-approval' AND `due` > 0 AND `due` <= %d ", time() ); 80 } elseif ( 'pending-approval' == $view ) { 81 $where .= " AND `status` = 'wcb-pending-approval' "; 82 } elseif ( 'approved' == $view ) { 83 $where .= " AND `status` = 'wcb-approved' "; 84 } elseif ( 'pending-payment' == $view ) { 85 $where .= " AND `status` = 'wcb-pending-payment' "; 82 86 } elseif ( 'paid' == $view ) { 83 $where .= " AND `status` = ' paid' ";84 $orderby = ' created';87 $where .= " AND `status` = 'wcb-paid' "; 88 $orderby = 'updated'; 85 89 $order = 'desc'; 86 } elseif( 'incomplete' == $view ) { 87 $where .= " AND `status` = 'incomplete' "; 90 } elseif ( 'incomplete' == $view ) { 91 $where .= " AND `status` = 'wcb-incomplete' "; 92 } elseif ( 'cancelled-failed' == $view ) { 93 $where .= " AND `status` IN ( 'wcb-failed', 'wcb-cancelled' ) "; 88 94 } 89 95 … … 136 142 */ 137 143 public function column_payment( $request ) { 138 $title = empty( $request->post_title ) ? '(no title)' : $request->post_title; 144 $blog_id = get_current_blog_id(); 145 $title = empty( $request->post_title ) ? '(no title)' : $request->post_title; 139 146 $edit_post_link = add_query_arg( array( 'post' => $request->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ); 140 147 $actions = array( 141 148 'view-all' => sprintf( '<a href="%s" target="_blank">View All</a>', esc_url( admin_url( 'edit.php?post_type=wcp_payment_request' ) ) ), 142 149 ); 150 151 if ( $request->post_status == 'wcb-pending-approval' ) { 152 $approve_url = wp_nonce_url( add_query_arg( array( 153 'wcb-approve' => sprintf( '%d-%d', $blog_id, $request->ID ), 154 ) ), sprintf( 'wcb-approve-%d-%d', $blog_id, $request->ID ) ); 155 156 $actions['wcb-approve'] = sprintf( '<a style="color: green;" onclick="return confirm(\'Approve this payment request?\');" href="%s">Approve</a>', esc_url( $approve_url ) ); 157 } 143 158 144 159 return sprintf( '<a href="%s" class="row-title" target="_blank">%s</a>%s', … … 153 168 */ 154 169 public function column_status( $request ) { 155 return esc_html( ucwords( $request->post_status ) ); 170 $status = get_post_status_object( $request->post_status ); 171 return esc_html( $status->label ); 156 172 } 157 173
Note: See TracChangeset
for help on using the changeset viewer.