<?php
$dataTable = '<table border=1>
<tr>
    <th>UPC</th>
    <th>Vendor ID</th>
    <th>Date Added</th>
    <th>Created By</th>
    <th>Amount</th>
    <th>Currency</th>
    <th>Adjust For Period</th>
    <th>Apply To Period</th>
    <th>Category</th>
    <th>Comment</th>
</tr>
';

foreach ($this->expenses as $expense) {
    /**
     * Attaching a nonbreaking space to the upc
     * in order to stop excel from parsing it
     * as a phone number.
     */
    if (!isset($expense->release->not_for_distribution) ||
        (isset($expense->release->not_for_distribution) && $expense->release->not_for_distribution != 'SMEAnalyticsDummy')) {
      $displayUpc = '="' . $expense->release->display_upc . '"';
      $dataTable .= '<tr>
                  <td>&nbsp;' . $displayUpc . '</td>
                  <td>' . $expense->vendor_id . '</td>
                  <td>' . $expense->date_added . '</td>
                  <td>' . $expense->created_by->first_name . ' '
                        . $expense->created_by->last_name . '</td>
                  <td>' . $expense->amount . '</td>
                  <td>' . $expense->currency->code . '</td>
                  <td>' . $expense->adjust_for_period->year . ' M '
                        . $expense->adjust_for_period->month . '</td>
                  <td>' . $expense->apply_to_period->year . ' M '
                        . $expense->apply_to_period->month . '</td>
                  <td>' . $expense->category->name . '</td>
                  <td>' . $expense->description . '</td>
            </tr>';
    }
}
$dataTable .= '</table>';
echo $dataTable;
?>
