}
+ /**
+ * getInvoiceTotal
+ *
+ * Get total for all invoices given the $where clause
+ *
+ * @param string $where Where clause
+ *
+ * @return mixed
+ */
+ public function getInvoiceTotal( $where )
+ {
+ $totalInvoices = $this->wpdb->get_var(
+ "SELECT SUM(current_invoice_total)
+ FROM " . $this->table . " T
+ WHERE $where"
+ );
+ return $totalInvoices;
+ }
+
+ /**
+ * getPaymentTotal
+ *
+ * Get total payments given the $where clause
+ *
+ * @param string $where Where clause
+ *
+ * @return mixed
+ */
+ public function getPaymentTotal( $where )
+ {
+ $totalInvoices = $this->wpdb->get_var(
+ "SELECT SUM(current_payment_total)
+ FROM " . $this->table . " T
+ WHERE $where"
+ );
+ return $totalInvoices;
+ }
+
}
$totalAccounts = false;
$option2 = false;
$transactions = false;
+ $totalInvoices = 0;
+ $totalPayments = 0;
// Get any provided option
if ( isset( $_REQUEST['option'] ) ) {
$this->notes = true;
$accountsResult = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit );
$totalAccounts = $this->getStats( $reportWhere );
+ $totalInvoices = $this->getInvoiceTotal( $reportWhere );
+ $totalPayments = $this->getPaymentTotal( $reportWhere );
+
$this->member_data = false;
$this->notes = false;
break;
// since we're doing paging, we have to break out just the accounts data
$accounts = $accountsResult['list'];
// echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
- if ( count( $accounts ) > 0 ) {
+ if ( isset( $accounts ) && is_array( $accounts ) && count( $accounts ) > 0 ) {
$haveAccounts = true;
}
} else {
// since we're doing paging, we have to break out just the transactions data
$transactions = $accountsResult['list'];
- // echo '<pre>$transactions: ' . print_r( $transactions, true ) . '</pre>';
if ( count( $transactions ) > 0 ) {
$haveAccounts = true;
}
'numbDisplayed' => $numbDisplayed,
'lastDisplayed' => $lastDisplayed,
'totalAccounts' => $totalAccounts,
+ 'totalInvoices' => $totalInvoices,
+ 'totalPayments' => $totalPayments,
);
// Return status, any suggested view, and any data to controller
<input type="submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
{/if}
</form>
+<div class="report-totals">
+ <div class="total-invoices">Total Invoices: <span>{$totalInvoices}</span></div>
+ <div class="total-payments">Total Payments: <span>{$totalPayments}</span></div>
+</div>
<script>
jQuery(document).ready(function($) {
// Date Input