Making WordPress.org

Changeset 2713


Ignore:
Timestamp:
03/08/2016 05:21:37 PM (10 years ago)
Author:
kovshenin
Message:

WordCamp Budgets: Move wire exports to vendor/reimbursement files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php

    r2712 r2713  
    388388function _generate_payment_report_jpm_wires( $args ) {
    389389    $args = wp_parse_args( $args, array(
    390         'request_indexes' => array(),
     390        'data' => array(),
    391391        'status' => '',
    392     ) );
    393 
    394     ob_start();
    395     $report = fopen( 'php://output', 'w' );
    396 
    397     // JPM Header
    398     fputcsv( $report, array( 'HEADER', gmdate( 'YmdHis' ), '1' ) );
    399 
    400     $total = 0;
    401     $count = 0;
    402 
    403     foreach ( $args['request_indexes'] as $index ) {
    404         switch_to_blog( $index->blog_id );
    405         $post = get_post( $index->post_id );
    406 
    407         if ( $args['status'] && $post->post_status != $args['status'] ) {
    408             restore_current_blog();
    409             continue;
    410         }
    411 
    412         // Only wires here.
    413         if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Wire' ) {
    414             restore_current_blog();
    415             continue;
    416         }
    417 
    418         $amount = round( floatval( get_post_meta( $post->ID, '_camppayments_payment_amount', true ) ), 2);
    419         $total += $amount;
    420         $count += 1;
    421 
    422         // If account starts with two letters, it's most likely an IBAN
    423         $account = get_post_meta( $post->ID, '_camppayments_beneficiary_account_number', true );
    424         $account = \WCP_Encryption::maybe_decrypt( $account );
    425         $account = preg_replace( '#\s#','', $account );
    426         $account_type = preg_match( '#^[a-z]{2}#i', $account ) ? 'IBAN' : 'ACCT';
    427 
    428         $row = array(
    429             '1-input-type' => 'P',
    430             '2-payment-method' => 'WIRES',
    431             '3-debit-bank-id' => apply_filters( 'wcb_payment_req_bank_id', '' ), // external file
    432             '4-account-number' => apply_filters( 'wcb_payment_req_bank_number', '' ), // external file
    433             '5-bank-to-bank' => 'N',
    434             '6-txn-currency' => get_post_meta( $post->ID, '_camppayments_currency', true ),
    435             '7-txn-amount' => number_format( $amount, 2, '.', '' ),
    436             '8-equiv-amount' => '',
    437             '9-clearing' => '',
    438             '10-ben-residence' => '',
    439             '11-rate-type' => '',
    440             '12-blank' => '',
    441             '13-value-date' => '',
    442 
    443             '14-id-type' => $account_type,
    444             '15-id-value' => $account,
    445             '16-ben-name' => substr( \WCP_Encryption::maybe_decrypt(
    446                 get_post_meta( $post->ID, '_camppayments_beneficiary_name', true ) ), 0, 35 ),
    447             '17-address-1' => substr( \WCP_Encryption::maybe_decrypt(
    448                 get_post_meta( $post->ID, '_camppayments_beneficiary_street_address', true ) ), 0, 35 ),
    449             '18-address-2' => '',
    450             '19-city-state-zip' => substr( sprintf( '%s %s %s',
    451                     \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_camppayments_beneficiary_city', true ) ),
    452                     \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_camppayments_beneficiary_state', true ) ),
    453                     \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_camppayments_beneficiary_zip_code', true ) )
    454                 ), 0, 32 ),
    455             '20-blank' => '',
    456             '21-country' => \WCP_Encryption::maybe_decrypt(
    457                 get_post_meta( $post->ID, '_camppayments_beneficiary_country_iso3166', true ) ),
    458             '22-blank' => '',
    459             '23-blank' => '',
    460 
    461             '24-id-type' => 'SWIFT',
    462             '25-id-value' => get_post_meta( $post->ID, '_camppayments_bank_bic', true ),
    463             '26-ben-bank-name' => substr( get_post_meta( $post->ID, '_camppayments_bank_name', true ), 0, 35 ),
    464             '27-ben-bank-address-1' => substr( get_post_meta( $post->ID, '_camppayments_bank_street_address', true ), 0, 35 ),
    465             '28-ben-bank-address-2' => '',
    466             '29-ben-bank-address-3' => substr( sprintf( '%s %s %s',
    467                     get_post_meta( $post->ID, '_camppayments_bank_city', true ),
    468                     get_post_meta( $post->ID, '_camppayments_bank_state', true ),
    469                     get_post_meta( $post->ID, '_camppayments_bank_zip_code', true )
    470                  ), 0, 35 ),
    471             '30-ben-bank-country' => get_post_meta( $post->ID, '_camppayments_bank_country_iso3166', true ),
    472             '31-supl-id-type' => '',
    473             '32-supl-id-value' => '',
    474 
    475             '33-blank' => '',
    476             '34-blank' => '',
    477             '35-blank' => '',
    478             '36-blank' => '',
    479             '37-blank' => '',
    480             '38-blank' => '',
    481             '39-blank' => '',
    482 
    483             // Filled out later if not empty.
    484             '40-id-type' => '',
    485             '41-id-value' => '',
    486             '42-interm-bank-name' => '',
    487             '43-interm-bank-address-1' => '',
    488             '44-interm-bank-address-2' => '',
    489             '45-interm-bank-address-3' => '',
    490             '46-interm-bank-country' => '',
    491             '47-supl-id-type' => '',
    492             '48-supl-id-value' => '',
    493 
    494             '49-id-type' => '',
    495             '50-id-value' => '',
    496             '51-party-name' => '',
    497             '52-party-address-1' => '',
    498             '53-party-address-2' => '',
    499             '54-party-address-3' => '',
    500             '55-party-country' => '',
    501 
    502             '56-blank' => '',
    503             '57-blank' => '',
    504             '58-blank' => '',
    505             '59-blank' => '',
    506             '60-blank' => '',
    507             '61-blank' => '',
    508             '62-blank' => '',
    509             '63-blank' => '',
    510             '64-blank' => '',
    511             '65-blank' => '',
    512             '66-blank' => '',
    513             '67-blank' => '',
    514             '68-blank' => '',
    515             '69-blank' => '',
    516             '70-blank' => '',
    517             '71-blank' => '',
    518             '72-blank' => '',
    519             '73-blank' => '',
    520 
    521             '74-ref-text' => substr( get_post_meta( $post->ID, '_camppayments_invoice_number', true ), 0, 16 ),
    522             '75-internal-ref' => '',
    523             '76-on-behalf-of' => '',
    524 
    525             '77-detial-1' => '',
    526             '78-detial-2' => '',
    527             '79-detial-3' => '',
    528             '80-detail-4' => '',
    529 
    530             '81-blank' => '',
    531             '82-blank' => '',
    532             '83-blank' => '',
    533             '84-blank' => '',
    534             '85-blank' => '',
    535             '86-blank' => '',
    536             '87-blank' => '',
    537             '88-blank' => '',
    538 
    539             '89-reporting-code' => '',
    540             '90-country' => '',
    541             '91-inst-1' => '',
    542             '92-inst-2' => '',
    543             '93-inst-3' => '',
    544             '94-inst-code-1' => '',
    545             '95-inst-text-1' => '',
    546             '96-inst-code-2' => '',
    547             '97-inst-text-2' => '',
    548             '98-inst-code-3' => '',
    549             '99-inst-text-3' => '',
    550 
    551             '100-stor-code-1' => '',
    552             '101-stor-line-2' => '', // Hmm?
    553             '102-stor-code-2' => '',
    554             '103-stor-line-2' => '',
    555             '104-stor-code-3' => '',
    556             '105-stor-line-3' => '',
    557             '106-stor-code-4' => '',
    558             '107-stor-line-4' => '',
    559             '108-stor-code-5' => '',
    560             '109-stor-line-5' => '',
    561             '110-stor-code-6' => '',
    562             '111-stor-line-6' => '',
    563 
    564             '112-priority' => '',
    565             '113-blank' => '',
    566             '114-charges' => '',
    567             '115-blank' => '',
    568             '116-details' => '',
    569             '117-note' => substr( sprintf( 'wcb-%d-%d', $index->blog_id, $index->post_id ), 0, 70 ),
    570         );
    571 
    572         // If an intermediary bank is given.
    573         $interm_swift = get_post_meta( $post->ID, '_camppayments_interm_bank_swift', true );
    574         if ( ! empty( $iterm_swift ) ) {
    575             $row['40-id-type'] = 'SWIFT';
    576             $row['41-id-value'] = $interm_swift;
    577 
    578             $row['42-interm-bank-name'] = substr( get_post_meta( $post->ID, '_camppayments_interm_bank_name', true ), 0, 35 );
    579             $row['43-interm-bank-address-1'] = substr( get_post_meta( $post->ID, '_camppayments_interm_bank_street_address', true ), 0, 35 );
    580 
    581             $row['44-interm-bank-address-2'] = '';
    582             $row['45-interm-bank-address-3'] = substr( sprintf( '%s %s %s',
    583                 get_post_meta( $post->ID, '_camppayments_interm_bank_city', true ),
    584                 get_post_meta( $post->ID, '_camppayments_interm_bank_state', true ),
    585                 get_post_meta( $post->ID, '_camppayments_interm_bank_zip_code', true )
    586             ), 0, 32 );
    587 
    588             $row['46-interm-bank-country'] = get_post_meta( $post->ID, '_camppayments_interm_bank_country_iso3166', true );
    589 
    590             $row['47-supl-id-type'] = 'ACCT';
    591             $row['48-supl-id-value'] = get_post_meta( $post->ID, '_camppayments_interm_bank_account', true );
    592         }
    593 
    594         // Use for debugging.
    595         // print_r( $row );
    596 
    597         fputcsv( $report, array_values( $row ) );
    598         restore_current_blog();
    599     }
    600 
    601     // JPM Trailer
    602     fputcsv( $report, array( 'TRAILER', $count, $total ) );
    603 
    604     fclose( $report );
    605     $results = ob_get_clean();
    606 
    607     // JPM chokes on accents and non-latin characters.
    608     $results = remove_accents( $results );
    609     return $results;
     392        'post_type' => '',
     393    ) );
     394
     395    if ( $args['post_type'] == 'wcp_payment_request' ) {
     396        return \WCP_Payment_Request::_generate_payment_report_jpm_wires( $args );
     397    } elseif ( $args['post_type'] == 'wcb_reimbursement' ) {
     398        return \WordCamp\Budgets\Reimbursement_Requests\_generate_payment_report_jpm_wires( $args );
     399    }
    610400}
    611401
Note: See TracChangeset for help on using the changeset viewer.