Making WordPress.org

Changeset 3303


Ignore:
Timestamp:
06/06/2016 08:43:19 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Budgets: Break Reimbursement expenses into line items in CSV export.

File:
1 edited

Legend:

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

    r3155 r3303  
    780780            if ( ! empty( $expense['_wcbrr_amount'] ) ) {
    781781                $amount += floatval( $expense['_wcbrr_amount'] );
    782             }
    783 
    784             if ( ! empty( $expense['_wcbrr_category'] ) ) {
    785                 $categories[] = $expense['_wcbrr_category'];
    786782            }
    787783        }
     
    811807            fputcsv( $report, $row );
    812808        }
     809
     810        // Break out expenses into individual line items
     811        foreach ( $expenses as $expense ) {
     812            fputcsv( $report, _generate_payment_report_default_line_items( $expense, $row ) );
     813        }
    813814    }
    814815
    815816    fclose( $report );
    816817    return ob_get_clean();
     818}
     819
     820/**
     821 * Generate a CSV row for an expense line item
     822 *
     823 * @param array $expense
     824 * @param array $row
     825 *
     826 * @return array
     827 */
     828function _generate_payment_report_default_line_items( $expense, $row ) {
     829    /*
     830     * Empty out fields we're not going to re-use for the line-item
     831     *
     832     * The ID field is left in, so it can be used to keep line-item fields grouped with their parent when the rows
     833     * are sorted.
     834     */
     835    $empty_fields = array( 0, 3, 4, 7, 9, 10, 11, 12 );
     836    foreach ( $empty_fields as $index ) {
     837        $row[ $index ] = '';
     838    }
     839
     840    // Fill in line-item fields
     841    $row[2] = $expense['_wcbrr_vendor_name'] .' - '. $expense['_wcbrr_description'];
     842    $row[5] = $expense['_wcbrr_date'];
     843    $row[6] = $expense['_wcbrr_amount'];
     844    $row[8] = $expense['_wcbrr_category'];
     845
     846    return $row;
    817847}
    818848
Note: See TracChangeset for help on using the changeset viewer.