Making WordPress.org


Ignore:
Timestamp:
03/08/2016 05:22:20 PM (9 years ago)
Author:
kovshenin
Message:

WordCamp Budgets: Move wire exports to vendor/reimbursement files. (part 2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php

    r2711 r2714  
    11451145    return ob_get_clean();
    11461146}
     1147
     1148/**
     1149 * Wires via JP Morgan
     1150 *
     1151 * @param array $args
     1152 *
     1153 * @return string
     1154 */
     1155function _generate_payment_report_jpm_wires( $args ) {
     1156    $args = wp_parse_args( $args, array(
     1157        'data' => array(),
     1158        'status' => '',
     1159        'post_type' => '',
     1160    ) );
     1161
     1162    ob_start();
     1163    $report = fopen( 'php://output', 'w' );
     1164
     1165    // JPM Header
     1166    fputcsv( $report, array( 'HEADER', gmdate( 'YmdHis' ), '1' ) );
     1167
     1168    $total = 0;
     1169    $count = 0;
     1170
     1171    foreach ( $args['data'] as $entry ) {
     1172        switch_to_blog( $entry->blog_id );
     1173        $post = get_post( $entry->request_id );
     1174
     1175        if ( $args['status'] && $post->post_status != $args['status'] ) {
     1176            restore_current_blog();
     1177            continue;
     1178        } elseif ( $post->post_type != POST_TYPE ) {
     1179            restore_current_blog();
     1180            continue;
     1181        } elseif ( get_post_meta( $post->ID, '_wcbrr_payment_method', true ) != 'Wire' ) {
     1182            restore_current_blog();
     1183            continue;
     1184        }
     1185
     1186        $amount = 0;
     1187        $expenses = get_post_meta( $post->ID, '_wcbrr_expenses', true );
     1188        foreach ( $expenses as $expense ) {
     1189            if ( ! empty( $expense['_wcbrr_amount'] ) ) {
     1190                $amount += floatval( $expense['_wcbrr_amount'] );
     1191            }
     1192        }
     1193
     1194        $amount = round( $amount, 2 );
     1195        $total += $amount;
     1196        $count += 1;
     1197
     1198        // If account starts with two letters, it's most likely an IBAN
     1199        $account = get_post_meta( $post->ID, '_wcbrr_beneficiary_account_number', true );
     1200        $account = \WCP_Encryption::maybe_decrypt( $account );
     1201        $account = preg_replace( '#\s#','', $account );
     1202        $account_type = preg_match( '#^[a-z]{2}#i', $account ) ? 'IBAN' : 'ACCT';
     1203
     1204        $row = array(
     1205            '1-input-type' => 'P',
     1206            '2-payment-method' => 'WIRES',
     1207            '3-debit-bank-id' => apply_filters( 'wcb_payment_req_bank_id', '' ), // external file
     1208            '4-account-number' => apply_filters( 'wcb_payment_req_bank_number', '' ), // external file
     1209            '5-bank-to-bank' => 'N',
     1210            '6-txn-currency' => get_post_meta( $post->ID, '_wcbrr_currency', true ),
     1211            '7-txn-amount' => number_format( $amount, 2, '.', '' ),
     1212            '8-equiv-amount' => '',
     1213            '9-clearing' => '',
     1214            '10-ben-residence' => '',
     1215            '11-rate-type' => '',
     1216            '12-blank' => '',
     1217            '13-value-date' => '',
     1218
     1219            '14-id-type' => $account_type,
     1220            '15-id-value' => $account,
     1221            '16-ben-name' => substr( \WCP_Encryption::maybe_decrypt(
     1222                get_post_meta( $post->ID, '_wcbrr_beneficiary_name', true ) ), 0, 35 ),
     1223            '17-address-1' => substr( \WCP_Encryption::maybe_decrypt(
     1224                get_post_meta( $post->ID, '_wcbrr_beneficiary_street_address', true ) ), 0, 35 ),
     1225            '18-address-2' => '',
     1226            '19-city-state-zip' => substr( sprintf( '%s %s %s',
     1227                    \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_wcbrr_beneficiary_city', true ) ),
     1228                    \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_wcbrr_beneficiary_state', true ) ),
     1229                    \WCP_Encryption::maybe_decrypt( get_post_meta( $post->ID, '_wcbrr_beneficiary_zip_code', true ) )
     1230                ), 0, 32 ),
     1231            '20-blank' => '',
     1232            '21-country' => \WCP_Encryption::maybe_decrypt(
     1233                get_post_meta( $post->ID, '_wcbrr_beneficiary_country_iso3166', true ) ),
     1234            '22-blank' => '',
     1235            '23-blank' => '',
     1236
     1237            '24-id-type' => 'SWIFT',
     1238            '25-id-value' => get_post_meta( $post->ID, '_wcbrr_bank_bic', true ),
     1239            '26-ben-bank-name' => substr( get_post_meta( $post->ID, '_wcbrr_bank_name', true ), 0, 35 ),
     1240            '27-ben-bank-address-1' => substr( get_post_meta( $post->ID, '_wcbrr_bank_street_address', true ), 0, 35 ),
     1241            '28-ben-bank-address-2' => '',
     1242            '29-ben-bank-address-3' => substr( sprintf( '%s %s %s',
     1243                    get_post_meta( $post->ID, '_wcbrr_bank_city', true ),
     1244                    get_post_meta( $post->ID, '_wcbrr_bank_state', true ),
     1245                    get_post_meta( $post->ID, '_wcbrr_bank_zip_code', true )
     1246                 ), 0, 35 ),
     1247            '30-ben-bank-country' => get_post_meta( $post->ID, '_wcbrr_bank_country_iso3166', true ),
     1248            '31-supl-id-type' => '',
     1249            '32-supl-id-value' => '',
     1250
     1251            '33-blank' => '',
     1252            '34-blank' => '',
     1253            '35-blank' => '',
     1254            '36-blank' => '',
     1255            '37-blank' => '',
     1256            '38-blank' => '',
     1257            '39-blank' => '',
     1258
     1259            // Filled out later if not empty.
     1260            '40-id-type' => '',
     1261            '41-id-value' => '',
     1262            '42-interm-bank-name' => '',
     1263            '43-interm-bank-address-1' => '',
     1264            '44-interm-bank-address-2' => '',
     1265            '45-interm-bank-address-3' => '',
     1266            '46-interm-bank-country' => '',
     1267            '47-supl-id-type' => '',
     1268            '48-supl-id-value' => '',
     1269
     1270            '49-id-type' => '',
     1271            '50-id-value' => '',
     1272            '51-party-name' => '',
     1273            '52-party-address-1' => '',
     1274            '53-party-address-2' => '',
     1275            '54-party-address-3' => '',
     1276            '55-party-country' => '',
     1277
     1278            '56-blank' => '',
     1279            '57-blank' => '',
     1280            '58-blank' => '',
     1281            '59-blank' => '',
     1282            '60-blank' => '',
     1283            '61-blank' => '',
     1284            '62-blank' => '',
     1285            '63-blank' => '',
     1286            '64-blank' => '',
     1287            '65-blank' => '',
     1288            '66-blank' => '',
     1289            '67-blank' => '',
     1290            '68-blank' => '',
     1291            '69-blank' => '',
     1292            '70-blank' => '',
     1293            '71-blank' => '',
     1294            '72-blank' => '',
     1295            '73-blank' => '',
     1296
     1297            '74-ref-text' => 'Reimbursement',
     1298            '75-internal-ref' => '',
     1299            '76-on-behalf-of' => '',
     1300
     1301            '77-detial-1' => '',
     1302            '78-detial-2' => '',
     1303            '79-detial-3' => '',
     1304            '80-detail-4' => '',
     1305
     1306            '81-blank' => '',
     1307            '82-blank' => '',
     1308            '83-blank' => '',
     1309            '84-blank' => '',
     1310            '85-blank' => '',
     1311            '86-blank' => '',
     1312            '87-blank' => '',
     1313            '88-blank' => '',
     1314
     1315            '89-reporting-code' => '',
     1316            '90-country' => '',
     1317            '91-inst-1' => '',
     1318            '92-inst-2' => '',
     1319            '93-inst-3' => '',
     1320            '94-inst-code-1' => '',
     1321            '95-inst-text-1' => '',
     1322            '96-inst-code-2' => '',
     1323            '97-inst-text-2' => '',
     1324            '98-inst-code-3' => '',
     1325            '99-inst-text-3' => '',
     1326
     1327            '100-stor-code-1' => '',
     1328            '101-stor-line-2' => '', // Hmm?
     1329            '102-stor-code-2' => '',
     1330            '103-stor-line-2' => '',
     1331            '104-stor-code-3' => '',
     1332            '105-stor-line-3' => '',
     1333            '106-stor-code-4' => '',
     1334            '107-stor-line-4' => '',
     1335            '108-stor-code-5' => '',
     1336            '109-stor-line-5' => '',
     1337            '110-stor-code-6' => '',
     1338            '111-stor-line-6' => '',
     1339
     1340            '112-priority' => '',
     1341            '113-blank' => '',
     1342            '114-charges' => '',
     1343            '115-blank' => '',
     1344            '116-details' => '',
     1345            '117-note' => substr( sprintf( 'wcb-%d-%d', $entry->blog_id, $entry->request_id ), 0, 70 ),
     1346        );
     1347
     1348        // If an intermediary bank is given.
     1349        $interm_swift = get_post_meta( $post->ID, '_wcbrr_interm_bank_swift', true );
     1350        if ( ! empty( $iterm_swift ) ) {
     1351            $row['40-id-type'] = 'SWIFT';
     1352            $row['41-id-value'] = $interm_swift;
     1353
     1354            $row['42-interm-bank-name'] = substr( get_post_meta( $post->ID, '_wcbrr_interm_bank_name', true ), 0, 35 );
     1355            $row['43-interm-bank-address-1'] = substr( get_post_meta( $post->ID, '_wcbrr_interm_bank_street_address', true ), 0, 35 );
     1356
     1357            $row['44-interm-bank-address-2'] = '';
     1358            $row['45-interm-bank-address-3'] = substr( sprintf( '%s %s %s',
     1359                get_post_meta( $post->ID, '_wcbrr_interm_bank_city', true ),
     1360                get_post_meta( $post->ID, '_wcbrr_interm_bank_state', true ),
     1361                get_post_meta( $post->ID, '_wcbrr_interm_bank_zip_code', true )
     1362            ), 0, 32 );
     1363
     1364            $row['46-interm-bank-country'] = get_post_meta( $post->ID, '_wcbrr_interm_bank_country_iso3166', true );
     1365
     1366            $row['47-supl-id-type'] = 'ACCT';
     1367            $row['48-supl-id-value'] = get_post_meta( $post->ID, '_wcbrr_interm_bank_account', true );
     1368        }
     1369
     1370        // Use for debugging.
     1371        // print_r( $row );
     1372
     1373        fputcsv( $report, array_values( $row ) );
     1374        restore_current_blog();
     1375    }
     1376
     1377    // JPM Trailer
     1378    fputcsv( $report, array( 'TRAILER', $count, $total ) );
     1379
     1380    fclose( $report );
     1381    $results = ob_get_clean();
     1382
     1383    // JPM chokes on accents and non-latin characters.
     1384    $results = remove_accents( $results );
     1385    return $results;
     1386}
Note: See TracChangeset for help on using the changeset viewer.