}
- public function recordInvoice( $invoice_id, $total )
+ /**
+ * recordInvoice
+ *
+ * Record the Invoice in the transaction table.
+ *
+ * @param mixed $invoice_id Id of the Invoice record
+ * @param mixed $total Total amount from Invoice
+
+ * @access public
+ * @return void
+ */
+ public function recordInvoice( $invoice_id, $account, $total )
{
- $this->recordTransaction( $this->config['transaction_numb']['Invoice'], $invoice_id, $total, null );
+ $this->recordTransaction( $this->config['transaction_numb']['Invoice'], $invoice_id, $account, $total, null );
}
+ /**
+ * recordPayment
+ *
+ * Record the Payment in the transaction table.
+ *
+ * @param mixed $invoice_id Id of the Invoice record
+ * @param mixed $payment Total amount of the Payment
+
+ * @access public
+ * @return void
+ */
public function recordPayment( $invoice_id, $payment ) {
$this->recordTransaction( $this->config['transaction_numb']['Payment'], $invoice_id, null, $payment );
}
- public function recordTransaction( $type, $type_id, $current_invoice_total = null, $current_payment_total = null )
+ /**
+ * recordTransaction
+ *
+ * Record the transaction by type.
+ *
+ * @param mixed $type Type of transaction from $this->config['transaction_type']
+ * @param mixed $type_id Id for invoice
+ * @param bool $current_invoice_total Invoice Total if Invoice
+ * @param bool $current_payment_total Payment Total if Payment type
+
+ * @access public
+ * @return void
+ */
+ public function recordTransaction( $type, $type_id, $account, $current_invoice_total = null, $current_payment_total = null )
{
$current_invoice_total = ( $current_invoice_total == null ) ? '0.00': $current_invoice_total;
$current_payment_total = ( $current_payment_total == null ) ? '0.00': $current_payment_total;
$this->wpdb->insert(
GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'transactions',
array(
- 'type' => $type,
- 'type_id' => $type_id,
- 'transaction_time' => date('Y-m-d H:i;s'),
+ 'type' => $type,
+ 'type_id' => $type_id,
+ 'account' => $account,
+ 'transaction_time' => date('Y-m-d H:i;s'),
'current_invoice_total' => $current_invoice_total,
'current_payment_total' => $current_payment_total,
),
);
}
+ /**
+ * getStatements
+ *
+ * Create array that has the set of invoices and payments for an account.
+ * Returns false if nothing is found or array if it finds records.
+ * $results = array(
+ * 'account_data' = array(acountdate...),
+ * 'transactions' => array(
+ * 0 => array(
+ * 'id' => '',
+ * 'type' => '',
+ * 'type_id' => '',
+ * 'account' => '',
+ * 'transaction_time' => '',
+ * 'current_invoice_total' => '',
+ * 'current_payment_total' => '',
+ * 'transaction_data' => array(
+ * (payment or invoice data)...
+ * )
+ * )
+ * ),
+ *
+ * )
+ *
+ * @param mixed $ref_dest Id for the associated entity (member, ?)
+ *
+ * @access public
+ * @return void
+ */
+ public function getStatements( $ref_dest )
+ {
+ // First, need to get the Account id for this ref_dest
+ $account_data = $this->getAccountByRefDest( $ref_dest );
+
+ // If there's no $account_id then return false.
+ if ( !$account_data ) {
+ return false;
+ }
+
+ $account_id = $account_data['id'];
+
+ // Get all transactions for this account.
+ $transactions = $this->getTransactionsByAccount( $account_id );
+
+ // For each transaction get the data (payment_data or invoice_data)
+ foreach ( $transactions as $key => &$transaction ) {
+ $type = $transaction['type'];
+ switch ( $type ){
+ case $this->config['transaction_numb']['Invoice']:
+ $transaction['transaction_data'] = $this->getInvoiceById( $transaction['type_id'] );
+ break;
+ case $this->config['transaction_numb']['Payment']:
+ break;
+ }
+ }
+ // echo '<pre>$transactions: ' . print_r( $transactions, true ) . '</pre>';
+
+ return array(
+ 'account_data' => $account_data,
+ 'transactions' => $transactions,
+ );
+ }
+
+ /**
+ * getAccountByRefDest
+ *
+ * Grab the account data for a refernce.
+ *
+ * @param mixed $ref_dest Id of the refered entity.
+ *
+ * @access public
+ * @return void
+ */
+ public function getAccountByRefDest( $ref_dest )
+ {
+ return $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ WHERE ref_dest = %d",
+ $ref_dest
+ ),
+ ARRAY_A
+ );
+ }
+
+ /**
+ * getTransactionsByAccount
+ *
+ * Get all of the transaction records for a given account.
+ *
+ * @param mixed $account Id of the account record.
+ *
+ * @access public
+ * @return void
+ */
+ public function getTransactionsByAccount( $account )
+ {
+ return $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions
+ WHERE account = %d
+ ORDER BY transaction_time DESC",
+ $account
+ ),
+ ARRAY_A
+ );
+ }
+
+ /**
+ * getInvoiceById
+ *
+ * Get the invoice by it's id.
+ *
+ * @param mixed $invoice_id Id field for the invoice record.
+ *
+ * @access public
+ * @return void
+ */
+ public function getInvoiceById( $invoice_id )
+ {
+ return $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+ WHERE id = %d",
+ $invoice_id
+ ),
+ ARRAY_A
+ );
+ }
+
}
+
$totals = $this->generateInvoiceTotal( $this->invoice_id );
// Now we have a total for the invoice we can record the transaction
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
- $BillingSupport->recordInvoice( $this->invoice_id, $totals['amount_total'] );
+ $BillingSupport->recordInvoice( $this->invoice_id, $_REQUEST['account'], $totals['amount_total'] );
$view = 'editInvoice';
$InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
*/
define('GLM_MEMBERS_BILLING_MEMBER_MENU', true);
require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php';
// Load Billing data abstract
// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataBilling.php';
$accountUpdateError = false;
$accountAdded = false;
$accountInsertError = false;
+ $transactions = false;
+ $account_data = false;
- // For lockedToMember
+ // For lockedToMember.
$lockedToMember = false;
$lockedWhereT = 'true';
$lockedWhere = 'true';
- // Check if there's a logged in user who is locked to their own entity
+ // Check if there's a logged in user who is locked to their own entity.
$lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
if ($lockedToMember) {
$memberID = $lockedToMember;
if ( isset( $_REQUEST['ref_name'] ) ) {
$_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date']));
// echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
- // if there's no id then add account
+ // if there's no id then add account.
if ( !isset( $_REQUEST['id'] ) ) {
$account = $Accounts->insertEntry();
if ( !$account['status'] ) {
$view = 'editAccount';
break;
case 'list':
- // Get the list of invoices for this member
- echo '<pre>$this->memberID: ' . print_r( $this->memberID, true) . '</pre>';
+ $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config);
+ $view = 'statements';
+ // Get the list of invoices for this member.
+ // echo '<pre>$this->memberID: ' . print_r( $this->memberID, true) . '</pre>';
// echo '<pre>$memberData: ' . print_r( $memberData, true) . '</pre>';
- $Invoices = new GlmDataInvoices( $this->wpdb, $this->config );
- // $where = "T."
- // $invoices = $Invoices->getList($where);
+ $statements = $BillingSupport->getStatements( $this->memberID );
+ if ( $statements ) {
+ $transactions = $statements['transactions'];
+ $account_data = $statements['account_data'];
+ }
+
break;
}
+ // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
// Compile template data
$templateData = array(
'accountUpdateError' => $accountUpdateError,
'accountAdded' => $accountAdded,
'accountInsertError' => $accountInsertError,
+ 'transactions' => $transactions,
+ 'account_data' => $account_data,
+ 'transaction_types' => $this->config['transaction_type'],
);
- // echo '<pre>$templateData: ' . print_r( $templateData, true ) . '</pre>';
- // Return status, any suggested view, and any data to controller
+ // Return status, any suggested view, and any data to controller.
return array(
'status' => true,
'modelRedirect' => false,
id INT NOT NULL AUTO_INCREMENT,
type INT NOT NULL, -- type of transaction (payment,invoice,etc)
type_id INT NOT NULL, -- reference to type id
+ account INT NOT NULL, -- reference to account id
transaction_time DATETIME NOT NULL, -- datetime for the transaction
current_invoice_total DECIMAL(8, 2) NOT NULL, -- invoice total
current_payment_total DECIMAL(8, 2) NOT NULL, -- payment total
<script>
jQuery(document).ready(function($){
+ // Setup the date picker for the input field with the name anniversary_date
+ $('input[name="anniversary_date"]').datepicker();
+
// Flash certain elements for a short time after display
$(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
totalInvoice();
});
+ // Setup the date picker for the input field with the name due_date
$('input[name="due_date"]').datepicker();
// Flash certain elements for a short time after display
--- /dev/null
+{if $fromMemberMenu}
+ {include file='admin/member/header.html'}
+ {include file='admin/billing/memberBillingSubHeader.html'}
+{else}
+ {include file='admin/billing/header.html'}
+{/if}
+
+ <table class="glm-admin-table wp-list-table widefat">
+ <thead>
+ <tr>
+ <th>Date</th>
+ <th>Due Date</th>
+ <th>Type</th>
+ <th>Amount</th>
+ <th>Balance</th>
+ </tr>
+ </thead>
+ <tbody>
+ {$alt = 0}
+ {$total_due = 0.00}
+ {$total_balance = 0.00}
+ {foreach $transactions as $transaction}
+ <tr{if $alt % 2 == 0} class="alternate"{/if}>
+ <td>{$transaction.transaction_data.transaction_time|date_format:"%D"}</td>
+ <td>{$transaction.transaction_data.due_date|date_format:"%D"}</td>
+ <td>{$transaction_types[$transaction.type]}</td>
+ <td>{$transaction.transaction_data.amount_total}</td>
+ <td>{$transaction.transaction_data.balance}</td>
+ </tr>
+ {$alt = $alt + 1}
+ {$total_due = $total_due + $transaction.transaction_data.amount_total}
+ {$total_balance = $total_balance + $transaction.transaction_data.balance}
+ {/foreach}
+ <tr>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td>Balance Due</td>
+ <td>{$total_balance|string_format:"%.2f"}</td>
+ </tr>
+ </tbody>
+ </table>
+
+{include file='admin/footer.html'}