Changeset 2707 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php
- Timestamp:
- 03/08/2016 03:00:51 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php
r2706 r2707 164 164 <th>Types</th> 165 165 <td> 166 < label><input type="checkbox" name="wcb-export-types-vendor-payments"167 value="1" checked disabled /> Vendor Payments</label><br />168 <label><input type="checkbox" name="wcb-export-types-reimbursements"169 value="1" disabled /> Reimbursements</label>166 <select name="wcb-export-post-type"> 167 <option value="wcp_payment_request">Vendor Payments</option> 168 <option value="wcb_reimbursement">Reimbursements</option> 169 </select> 170 170 </td> 171 171 <tr> … … 217 217 return; 218 218 219 if ( empty( $_POST['wcb-export-post-type'] ) ) 220 return; 221 219 222 if ( ! current_user_can( 'manage_network' ) || ! check_admin_referer( 'export', 'wcb-request-export' ) ) 220 223 return; … … 236 239 $filename = sprintf( $export_type['filename'], date( 'Ymd', $start_date ), date( 'Ymd', $end_date ) ); 237 240 $filename = sanitize_file_name( $filename ); 241 242 $post_type = $_POST['wcb-export-post-type']; 243 if ( ! in_array( $post_type, array( 'wcp_payment_request', 'wcb_reimbursement' ) ) ) { 244 add_settings_error( 'wcb-dashboard', 'bad_post_type', 'Invalid post type selected.' ); 245 return; 246 } 238 247 239 248 $report = generate_payment_report( array( … … 242 251 'end_date' => $end_date, 243 252 'export_type' => $export_type, 253 'post_type' => $post_type, 244 254 ) ); 245 255 … … 273 283 'end_date' => '', 274 284 'export_type' => '', 285 'post_type' => '', 275 286 ) ); 276 287 … … 279 290 } 280 291 281 // todo: support other index tables. 282 $table_name = $wpdb->get_blog_prefix(0) . 'wordcamp_payments_index'; 283 $date_type = 'updated'; 284 285 if ( $args['status'] == 'wcb-paid' ) 286 $date_type = 'paid'; 292 if ( $args['post_type'] == 'wcp_payment_request' ) { 293 $table_name = $wpdb->get_blog_prefix(0) . 'wordcamp_payments_index'; 294 $date_type = $args['status'] == 'wcb-paid' ? 'paid' : 'updated'; 295 } elseif ( $args['post_type'] == 'wcb_reimbursement' ) { 296 $table_name = $wpdb->get_blog_prefix(0) . 'wcbd_reimbursement_requests_index'; 297 $date_type = $args['status'] == 'wcb-paid' ? 'date_paid' : 'date_requested'; // todo date_updated 298 } else { 299 return new \WP_Error( 'wcb-invalid-post-type', 'Invalid post type.' ); 300 } 287 301 288 302 $request_indexes = $wpdb->get_results( $wpdb->prepare( " … … 297 311 return new \WP_Error( 'wcb-invalid-type', 'The export type is invalid.' ); 298 312 299 $args[' request_indexes'] = $request_indexes;313 $args['data'] = $request_indexes; 300 314 301 315 return call_user_func( $args['export_type']['callback'], $args ); … … 311 325 function _generate_payment_report_default( $args ) { 312 326 $args = wp_parse_args( $args, array( 313 ' request_indexes' => array(),327 'data' => array(), 314 328 'status' => '', 329 'post_type' => '', 315 330 ) ); 316 331 317 $column_headings = array( 318 'WordCamp', 'ID', 'Title', 'Status', 'Date Vendor was Paid', 'Creation Date', 'Due Date', 'Amount', 319 'Currency', 'Category', 'Payment Method','Vendor Name', 'Vendor Contact Person', 'Vendor Country', 320 'Check Payable To', 'URL', 'Supporting Documentation Notes', 321 ); 322 323 ob_start(); 324 $report = fopen( 'php://output', 'w' ); 325 326 fputcsv( $report, $column_headings ); 327 328 foreach( $args['request_indexes'] as $index ) { 329 switch_to_blog( $index->blog_id ); 330 331 $request = get_post( $index->post_id ); 332 333 $back_compat_statuses = array( 334 'unpaid' => 'draft', 335 'incomplete' => 'wcb-incomplete', 336 'paid' => 'wcb-paid', 337 ); 338 339 // Map old statuses to new statuses. 340 if ( array_key_exists( $request->post_status, $back_compat_statuses ) ) { 341 $request->post_status = $back_compat_statuses[ $request->post_status ]; 342 } 343 344 if ( $args['status'] && $request->post_status != $args['status'] ) { 345 restore_current_blog(); 346 continue; 347 } 348 349 $currency = get_post_meta( $index->post_id, '_camppayments_currency', true ); 350 $category = get_post_meta( $index->post_id, '_camppayments_payment_category', true ); 351 $date_vendor_paid = get_post_meta( $index->post_id, '_camppayments_date_vendor_paid', true ); 352 353 if ( $date_vendor_paid ) { 354 $date_vendor_paid = date( 'Y-m-d', $date_vendor_paid ); 355 } 356 357 if ( 'null-select-one' === $currency ) { 358 $currency = ''; 359 } 360 361 if ( 'null' === $category ) { 362 $category = ''; 363 } 364 365 $country_name = \WordCamp_Budgets::get_country_name( 366 get_post_meta( $index->post_id, '_camppayments_vendor_country_iso3166', true ) 367 ); 368 369 $row = array( 370 get_wordcamp_name(), 371 sprintf( '%d-%d', $index->blog_id, $index->post_id ), 372 html_entity_decode( $request->post_title ), 373 $index->status, 374 $date_vendor_paid, 375 date( 'Y-m-d', $index->created ), 376 date( 'Y-m-d', $index->due ), 377 get_post_meta( $index->post_id, '_camppayments_payment_amount', true ), 378 $currency, 379 $category, 380 get_post_meta( $index->post_id, '_camppayments_payment_method', true ), 381 get_post_meta( $index->post_id, '_camppayments_vendor_name', true ), 382 get_post_meta( $index->post_id, '_camppayments_vendor_contact_person', true ), 383 $country_name, 384 \WCP_Encryption::maybe_decrypt( get_post_meta( $index->post_id, '_camppayments_payable_to', true ) ), 385 get_edit_post_link( $index->post_id ), 386 get_post_meta( $index->post_id, '_camppayments_file_notes', true ), 387 ); 388 389 restore_current_blog(); 390 391 if ( ! empty( $row ) ) { 392 fputcsv( $report, $row ); 393 } 394 } 395 396 fclose( $report ); 397 return ob_get_clean(); 332 if ( $args['post_type'] == 'wcp_payment_request' ) { 333 return \WCP_Payment_Request::_generate_payment_report_default( $args ); 334 } elseif ( $args['post_type'] == 'wcb_reimbursement' ) { 335 return \WordCamp\Budgets\Reimbursement_Requests\_generate_payment_report_default( $args ); 336 } 398 337 } 399 338
Note: See TracChangeset
for help on using the changeset viewer.