Making WordPress.org

Changeset 2771


Ignore:
Timestamp:
03/21/2016 06:24:04 PM (10 years ago)
Author:
kovshenin
Message:

WordCamp Budgets: Process imports from JPM export files.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
Files:
2 edited

Legend:

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

    r2356 r2771  
    2121        display: none;
    2222}
     23
     24.wcb-import-message svg {
     25        width: 18px;
     26        height: 18px;
     27        float: left;
     28}
     29
     30.wcb-import-message svg.sucess {
     31        fill: #46b450;
     32}
     33
     34.wcb-import-message svg.error {
     35        fill: #dc3232;
     36}
     37
     38.wcb-import-message span {
     39        display: block;
     40        margin-left: 24px;
     41}
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php

    r2770 r2771  
    134134        <?php if ( isset( WCB_Import_Results::$data ) ) : ?>
    135135        <h2>Import Results</h2>
    136         <pre><?php echo esc_html( print_r( WCB_Import_Results::$data, true ) ); ?></pre>
     136        <table class="wp-list-table widefat">
     137                <thead>
     138                        <tr>
     139                                <th>Request</th>
     140                                <th>Amount</th>
     141                                <th>Blog ID</th>
     142                                <th>Post ID</th>
     143                                <th>Message</th>
     144                        </tr>
     145                </thead>
     146                <tbody>
     147                <?php foreach ( WCB_Import_Results::$data as $entry ) : ?>
     148                        <tr>
     149                                <td><?php
     150                                        $labels = array(
     151                                                'wcp_payment_request' => 'Vendor',
     152                                                'wcb_reimbursement' => 'Reimbursement',
     153                                        );
     154                                        $label = ! empty( $labels[ $entry['post_type'] ] ) ? $labels[ $entry['post_type'] ] : 'Unknown';
     155                                        printf( '%s: %s', $label, esc_html( $entry['post_title'] ) );
     156                                ?></td>
     157                                <td><?php
     158                                        printf( '%s %s', number_format( $entry['amount'], 2 ), esc_html( $entry['currency'] ) );
     159                                ?></td>
     160                                <td><?php
     161                                        if ( ! empty( $entry['blog_id'] ) ) {
     162                                                printf( '<a href="%s" target="_blank">%d</a>', esc_url( $entry['edit_all_url'] ), $entry['blog_id'] );
     163                                        }
     164                                ?></td>
     165                                <td><?php
     166                                        if ( ! empty( $entry['post_id'] ) ) {
     167                                                printf( '<a href="%s" target="_blank">%d</a>', esc_url( $entry['edit_post_url'] ), $entry['post_id'] );
     168                                        }
     169                                ?></td>
     170                                <td class="wcb-import-message">
     171                                        <?php if ( $entry['processed'] ) : ?>
     172                                                <svg class="success" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1472 930v318q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q63 0 117 25 15 7 18 23 3 17-9 29l-49 49q-10 10-23 10-3 0-9-2-23-6-45-6h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113v-254q0-13 9-22l64-64q10-10 23-10 6 0 12 3 20 8 20 29zm231-489l-814 814q-24 24-57 24t-57-24l-430-430q-24-24-24-57t24-57l110-110q24-24 57-24t57 24l263 263 647-647q24-24 57-24t57 24l110 110q24 24 24 57t-24 57z"/></svg>
     173                                        <?php else : ?>
     174                                                <svg class="error" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M896 128q209 0 385.5 103t279.5 279.5 103 385.5-103 385.5-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103zm128 1247v-190q0-14-9-23.5t-22-9.5h-192q-13 0-23 10t-10 23v190q0 13 10 23t23 10h192q13 0 22-9.5t9-23.5zm-2-344l18-621q0-12-10-18-10-8-24-8h-220q-14 0-24 8-10 6-10 18l17 621q0 10 10 17.5t24 7.5h185q14 0 23.5-7.5t10.5-17.5z"/></svg>
     175                                        <?php endif; ?>
     176                                        <span><?php echo esc_html( $entry['message'] ); ?></span>
     177                                </td>
     178                        </tr>
     179                <?php endforeach; ?>
     180                </tbody>
     181        </table>
    137182        <?php endif; ?>
    138183
     
    474519                plugins_url( 'css/wordcamp-budgets-dashboard.css', __DIR__ ),
    475520                array(),
    476                 1
     521                2
    477522        );
    478523
     
    672717                $entry = array(
    673718                        'type' => strtolower( $line[11] ),
    674                         'status' => strtolower( $line[7] ),
    675                         'amount' => round( floatval( $line[13] ), 2 ),
    676                         'currency' => strtoupper( $line[14] ),
     719                        'title' => null,
     720                        'post_type' => null,
     721                        'post_title' => null,
     722                        'status' => null,
     723                        'amount' => null,
     724                        'currency' => null,
    677725                        'blog_id' => null,
    678726                        'post_id' => null,
    679727                        'processed' => false,
    680                         'data' => null,
     728                        'message' => null,
     729
     730                        'edit_all_url' => null,
     731                        'edit_post_url' => null,
    681732                );
    682733
     
    686737                                        $entry['blog_id'] = $matches[1];
    687738                                        $entry['post_id'] = $matches[2];
     739                                        $entry['status'] = strtolower( $line[7] );
     740                                        $entry['amount'] = round( floatval( $line[13] ), 2 );
     741                                        $entry['currency'] = strtoupper( $line[14] );
    688742                                }
    689743                                break;
     
    692746                                        $entry['blog_id'] = $matches[1];
    693747                                        $entry['post_id'] = $matches[2];
     748                                        $entry['status'] = strtolower( $line[7] );
     749                                        $entry['amount'] = round( floatval( $line[13] ), 2 );
     750                                        $entry['currency'] = strtoupper( $line[14] );
    694751                                }
    695752                                break;
     753                        default:
     754                                $entry['message'] = 'Unknown payment type.';
     755                                $results[] = $entry;
     756                                continue;
    696757                }
    697758
    698759                if ( empty( $entry['blog_id'] ) || empty( $entry['post_id'] ) ) {
     760                        $entry['message'] = 'Blog ID or post ID is empty.';
    699761                        $results[] = $entry;
    700762                        continue;
     
    727789        $post = get_post( $entry['post_id'] );
    728790        if ( ! $post || ! in_array( $post->post_type, array( 'wcp_payment_request', 'wcb_reimbursement' ) ) ) {
    729                 $entry['data'] = 'Post not found or post type mismatch';
     791                $entry['message'] = 'Post not found or post type mismatch';
    730792                return $entry;
    731793        }
     794
     795        $entry['title'] = $post->post_title;
     796        $entry['post_type'] = $post->post_type;
     797        $entry['edit_all_url'] = admin_url( 'edit.php?post_type=' . $post->post_type );
     798        $entry['edit_post_url'] = get_edit_post_link( $post->ID );
    732799
    733800        $currency = false;
     
    749816
    750817        if ( empty( $entry['currency'] ) || $entry['currency'] != $currency ) {
    751                 $entry['data'] = 'Currency mismatch';
     818                $entry['message'] = 'Currency mismatch';
    752819                return $entry;
    753820        }
     
    757824
    758825        if ( $entry['amount'] !== $amount ) {
    759                 $entry['data'] = 'Payment amount mismatch';
     826                $entry['message'] = 'Payment amount mismatch';
    760827                return $entry;
    761828        }
    762829
    763         // @todo Do some magic here.
     830        if ( $entry['type'] == 'wire' ) {
     831
     832                if ( $entry['status'] != 'completed' ) {
     833                        $entry['message'] = 'Unknown wire status.';
     834                        return $entry;
     835                }
     836
     837                $post->post_status = 'wcb-paid';
     838                wp_insert_post( $post );
     839                $entry['message'] = 'Wire request marked as paid.';
     840
     841                \WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Wire marked as paid via an import in Network Admin', array(
     842                        'action' => 'paid-via-import',
     843                ) );
     844
     845        } elseif ( $entry['type'] == 'ach' ) {
     846
     847                if ( $entry['status'] != 'delivered' ) {
     848                        $entry['message'] = 'Unknown ACH status.';
     849                        return $entry;
     850                }
     851
     852                $post->post_status = 'wcb-paid';
     853                wp_insert_post( $post );
     854                $entry['message'] = 'ACH request marked as paid.';
     855
     856                \WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'ACH marked as paid via an import in Network Admin', array(
     857                        'action' => 'paid-via-import',
     858                ) );
     859
     860        } else {
     861                $entry['message'] = 'Unknown payment method.';
     862                return $entry;
     863        }
    764864
    765865        // All good.
Note: See TracChangeset for help on using the changeset viewer.