Working on the invoicing section.
Creating invoices
setting up the payment type and counties filter.
more work on the update import for member accounts for uptravel.
{
// Find all invoices for this account that aren't marked as paid.
$balance_due = (float)0.00;
- $results = $this->wpdb->get_results(
- "SELECT *
- FROM ",
- ARRAY_A
- );
+ $invoices = $this->getUnPaidInvoicesByAccount( $account );
+ foreach ( $invoices as $invoice ) {
+ $balance_due += (float)$invoice['balance'];
+ }
return $balance_due;
}
*/
public $postEmployees = false;
+ /**
+ * Pull in the name of the payment type.
+ */
+ public $paymentTypes = false;
+ /**
+ * Pull in the balance due for this account.
+ */
+ public $balanceDue = false;
+
/**
* Constructor
*
'use' => 'a'
),
+ 'member_name' => array(
+ 'field' => 'ref_dest',
+ 'type' => 'pointer',
+ 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+ 'p_field' => 'name',
+ 'p_orderby' => 'name',
+ 'p_blank' => false,
+ 'required' => false,
+ 'use' => 'l',
+ 'as' => 'member_name',
+ ),
+
// Name of red_dest
'ref_name' => array(
'field' => 'ref_name',
$r['employees'] = $employees;
}
+ if ( $this->paymentTypes ) {
+ $r['payment_type'] = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT name
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+ WHERE id = %d",
+ $r['invoice_type']
+ )
+ );
+ }
+
+ if ( $this->balanceDue ) {
+ include_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php';
+ $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+ $r['balance_due'] = $BillingSupport->getBalanceDueByAccount( $r['id'] );
+ }
+
return $r;
}
$filterOverdue = false;
$counties = false;
$paymentTypes = false;
+ $invoiceTypes = false;
// Get any provided option
if (isset($_REQUEST['option'])) {
// Do selected option
switch ($option) {
case 'bulkadd':
- $view = 'bulkAddInvoices';
+ $view = 'bulkAddInvoices';
+ $wParts = array();
// Check if Counties is enabled and fetch counties
if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) {
// Need to get the accounts
$Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
- $accountList = $Accounts->getSimpleAccountList( '', '', true, 'id', 1, 20 );
+
+ if ( isset( $_REQUEST['invoice_types'] ) ) {
+
+ $invoiceTypes = $_REQUEST['invoice_types'];
+
+ $wParts[] = "T.id IN (
+ SELECT invoice
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "line_items
+ WHERE line_item_type IN (" . implode( ',', $invoiceTypes ) . ") )";
+ }
+
+ $where = implode( ' AND ', $wParts );
+
+ $accountList = $Accounts->getSimpleAccountList( $where, '', true, 'id', 1, 20 );
$accounts = $accountList['list'];
break;
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Transactions List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Contacts data class
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+
+class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+ /**
+ * Transactions ID
+ *
+ * @var $account_id
+ * @access public
+ */
+ public $account_id = false;
+
+ /**
+ * Constructor
+ *
+ * This constructor performs the work for this model. This model returns
+ * an array containing the following.
+ *
+ * 'status'
+ *
+ * True if successful and false if there was a fatal failure.
+ *
+ * 'view'
+ *
+ * A suggested view name that the controller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ * @wpdb object WordPress database object
+ *
+ * @return array Array containing status, suggested view, and any data
+ */
+ public function __construct ( $wpdb, $config )
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ /*
+ * Run constructor for the Contacts data class
+ *
+ * Note, the third parameter is a flag that indicates to the Contacts
+ * data class that it should flag a group of fields as 'view_only'.
+ */
+ // parent::__construct( false, false, true );
+
+ }
+
+ public function modelAction($actionData = false)
+ {
+
+ $haveAccounts = false;
+ $option = 'list';
+ $view = 'invoicing';
+ $wParts = array( 'true' );
+ $paymentTypes = false;
+ $counties = false;
+ $accounts = false;
+ $paging = true;
+ $prevStart = false;
+ $nextStart = false;
+ $start = 1;
+ $limit = 20; // Set to the number of listings per page
+ $numbDisplayed = false;
+ $lastDisplayed = false;
+ $totalAccounts = false;
+
+ // Get any provided option
+ if ( isset( $_REQUEST['option'] ) ) {
+ $option = $_REQUEST['option'];
+ }
+
+ $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+ $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+
+ echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+ if ( isset( $_REQUEST['invoice_types'] ) ) {
+
+ $invoiceTypes = $_REQUEST['invoice_types'];
+ $wParts[] = " T.invoice_type IN (" . implode(',', $invoiceTypes) . ") ";
+
+ }
+
+ if ( isset( $_REQUEST['counties'] ) ) {
+
+ // $wParts[] = "T.";
+
+ }
+
+ // $where used in all places.
+ $where = implode( ' AND ', $wParts );
+
+ if ( isset( $_REQUEST['submitType'] ) ) {
+
+ $option2 = filter_var( $_REQUEST['submitType'], FILTER_SANITIZE_STRING );
+
+ switch( $option2 ) {
+ case 'Create Invoices':
+ $accounts = $Accounts->getSimpleAccountList( $where );
+ echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+ foreach ( $accounts as $account ) {
+ // Get the invoice type
+ $invoiceType = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] );
+
+ // Create the invoice for this member account
+ $BillingSupport->createMemberInvoiceWithEmployees(
+ array(
+ 'account_id' => $account['id'],
+ 'renew_type_id' => $account['invoice_type'],
+ 'amount' => $invoiceType['amount'],
+ 'due_date' => date( 'Y-m-d' ),
+ 'member_invoice' => $account['invoice_type'],
+ 'employee_data' => array(),
+ 'employees' => array(),
+ )
+ );
+ }
+
+ break;
+ case 'Print Invoices':
+ break;
+ case 'Send Invoices':
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ // Do selected option
+ switch ($option) {
+
+ case 'list':
+ default:
+ $view = 'invoicing';
+
+ // Check if Counties is enabled and fetch counties
+ if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) {
+ // Grab counties
+ $counties = $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties
+ ORDER BY name",
+ ARRAY_A
+ );
+ }
+
+ $paymentTypes = $BillingSupport->getAllInvoiceTypes();
+
+
+ if (isset($_REQUEST['pageSelect'])) {
+ // If request is for Next
+ if ($_REQUEST['pageSelect'][0] == 'N') {
+ $newStart = $_REQUEST['nextStart'] - 0;
+
+ // Otherwise it must be Previous
+ } else {
+ $newStart = $_REQUEST['prevStart'] - 0;
+ }
+
+ if ($newStart > 0) {
+ $start = $newStart;
+ }
+ }
+ $orderBy = 'member_name';
+ $Accounts->paymentTypes = true;
+ $Accounts->balanceDue = true;
+ $accountsResult = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit );
+ $totalAccounts = $Accounts->getStats( $where );
+ $Accounts->paymentTypes = false;
+ $Accounts->balanceDue = false;
+ // Get paging results
+ $numbDisplayed = $accountsResult['returned'];
+ $lastDisplayed = $accountsResult['last'];
+ if ( $start == 1 ) {
+ $prevStart = false;
+ } else {
+ $prevStart = $start - $limit;
+ if ( $start < 1 ) {
+ $start = 1;
+ }
+ }
+ if ( $accountsResult['returned'] == $limit ) {
+ $nextStart = $start + $limit;
+ }
+
+ // 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 ) {
+ $haveAccounts = true;
+ }
+
+ break;
+
+ }
+
+
+ $templateData = array(
+ 'option' => $option,
+ 'paymentTypes' => $paymentTypes,
+ 'counties' => $counties,
+ 'accounts' => $accounts,
+ 'paging' => $paging,
+ 'prevStart' => $prevStart,
+ 'nextStart' => $nextStart,
+ 'start' => $start = 1,
+ 'limit' => $limit,
+ 'haveAccounts' => $haveAccounts,
+ 'numbDisplayed' => $numbDisplayed,
+ 'lastDisplayed' => $lastDisplayed,
+ 'totalAccounts' => $totalAccounts,
+ );
+
+ // Return status, any suggested view, and any data to controller
+ return array(
+ 'status' => true,
+ 'modelRedirect' => false,
+ 'view' => "admin/billing/$view.html",
+ 'data' => $templateData
+ );
+
+ }
+
+}
$sql = "
SELECT M.member_id,M.billing_contact,M.account_number,
PT.name as payment_type,M.process_email as email, M.member_name,
- MA.email_invoice, MA.usmail_invoice, MA.fax_invoice
+ MA.email_invoice, MA.usmail_invoice, MA.fax_invoice,
+ M.mailing_address,M.mailing_city_id,M.mailing_state_id,M.mailing_zip,
+ M.street,M.city_id,M.state_id,M.zip
FROM members.member M
LEFT OUTER JOIN members.member_account MA ON ( MA.member_id = M.member_id )
LEFT OUTER JOIN members.payment_types PT ON ( MA.payment_type = PT.id )
// $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions" );
}
+$getState = $dbh->prepare(
+ "SELECT state_abb
+ FROM members.state
+ WHERE state_id = :id"
+);
+
+$getCity = $dbh->prepare(
+ "SELECT city_name
+ FROM members.city
+ WHERE city_id = :id"
+);
+
foreach ( $members as $member ) {
$importResults .= '<pre>$member: ' . print_r( $member, true ) . '</pre>';
$paymentTypeId = getPaymentTypeId( $this->wpdb, $member['payment_type'] );
- $refName = ( $member['billing_contact'] ) ? $member['billing_contact'] : $member['member_name'];
+ //$refName = ( $member['billing_contact'] ) ? $member['billing_contact'] : $member['member_name'];
+ $refName = $member['member_name'];
+ $city = $state = '';
+
+ if ( $member['mailing_address'] ) {
+ $addr1 = $member['mailing_address'];
+ if ( $member['mailing_city_id'] ) {
+ $getCity->bindParam( ':id', $member['mailing_city_id'] );
+ $getCity->execute();
+ $city = $getCity->fetchColumn();
+ }
+ if ( $member['mailing_state_id'] ) {
+ $getState->bindParam( ':id', $member['mailing_state_id'] );
+ $getState->execute();
+ $state = $getState->fetchColumn();
+ }
+ $zip = $member['mailing_zip'];
+ } else {
+ $addr1 = $member['street'];
+ $city = $member['city'];
+ $state = $member['state'];
+ if ( $member['city_id'] ) {
+ $getCity->bindParam( ':id', $member['city_id'] );
+ $getCity->execute();
+ $city = $getCity->fetchColumn();
+ }
+ if ( $member['state_id'] ) {
+ $getState->bindParam( ':id', $member['state_id'] );
+ $getState->execute();
+ $state = $getState->fetchColumn();
+ }
+ $zip = $member['zip'];
+ }
$accountData = array(
- 'ref_dest' => $newMemberId,
- 'ref_name' => $refName,
- 'invoice_type' => $paymentTypeId,
- 'email' => $member['email'],
- 'account_number' => $member['account_number'],
- 'renewal_date' => '2018-07-01',
- 'email_invoice' => $member['email_invoice'],
- 'usmail_invoice' => $member['usmail_invoice'],
- 'fax_invoice' => $member['fax_invoice'],
+ 'ref_dest' => $newMemberId,
+ 'ref_name' => $refName,
+ 'invoice_type' => $paymentTypeId,
+ 'email' => $member['email'],
+ 'account_number' => $member['account_number'],
+ 'renewal_date' => '2018-07-01',
+ 'email_invoice' => $member['email_invoice'],
+ 'usmail_invoice' => $member['usmail_invoice'],
+ 'fax_invoice' => $member['fax_invoice'],
+ 'billing_company' => $member['member_name'],
+ 'billing_addr1' => $addr1,
+ 'billing_city' => $city,
+ 'billing_state' => $state,
+ 'billing_zip' => $zip,
);
$accountDataFormat = array(
'%d', // ref_dest
'%d', // email_invoice
'%d', // usmail_invoice
'%d', // fax_invoice
+ '%s', // billing_company
+ '%s', // billing_addr1
+ '%s', // billing_city
+ '%s', // billing_state
+ '%s', // billing_zip
);
$importResults .= '<pre>$accountData: ' . print_r( $accountData, true ) . '</pre>';
'notificationTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
'billing' => array(
- 'index' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'list' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'invoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'payments' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'accounts' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'logs' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'contact' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'index' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'list' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'invoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'payments' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'accounts' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'invoicing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'logs' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'contact' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
'member' => array(
'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+++ /dev/null
-{include file='admin/billing/header.html'}
-
-{include file='admin/billing/subHeader.html'}
-
-<h2>Bulk Create Invoices</h2>
-
-{if $paymentTypes}
-
- <label>Payment Types:</label>
-
- <select multiple size="10">
- {foreach $paymentTypes as $paymentType}
- <option value="{$paymentType.id}">{$paymentType.name}</option>
- {/foreach}
- </select>
-
-{/if}
-
-{if $counties}
-
- <label>Counties:</label>
-
- <select multiple size="10">
- {foreach $counties as $county}
- <option value="{$county.id}">{$county.name}</option>
- {/foreach}
- </select>
-
-{/if}
-
-<button>Filter</button>
-
-<div id="account-list">
-
- {foreach $accounts as $t}
- <div>{$t.ref_name}</div>
- {/foreach}
-
-</div>
-
-{include file='admin/footer.html'}
{/if}
- {if !$settings.member_types_enabled}
+ {if $settings.invoice_methods_enabled}
<div class="">
<div class="glm-billing-label">Invoice Delivery Methods</div>
<a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices" class="nav-tab{if $thisAction==invoices} nav-tab-active{/if}">Invoices</a>
<a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments" class="nav-tab{if $thisAction==payments} nav-tab-active{/if}">Payments</a>
<a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=accounts" class="nav-tab{if $thisAction==accounts} nav-tab-active{/if}">Accounts</a>
+ <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoicing" class="nav-tab{if $thisAction==invoicing} nav-tab-active{/if}">Invoicing</a>
<a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=logs" class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Logs</a>
</h2>
<div id="glm-admin-content-container">
--- /dev/null
+{include file='admin/billing/header.html'}
+
+{* include file='admin/billing/invoicingSubHeader.html' *}
+
+<h2>Invoicing</h2>
+
+<form action="{$thisUrl}?page={$thisPage}" method="post">
+
+ <input type="hidden" name="glm_action" value="invoicing">
+ <input type="hidden" name="option" value="list">
+ <input type="hidden" name="prevStart" value="{$prevStart}">
+ <input type="hidden" name="nextStart" value="{$nextStart}">
+ <input type="hidden" name="limit" value="{$limit}">
+
+ <div class="glm-admin-table-inner">
+ {if $paymentTypes}
+
+ <label>Payment Types:</label>
+
+ <select multiple size="10" name="invoice_types[]">
+ {foreach $paymentTypes as $paymentType}
+ <option value="{$paymentType.id}"{if isset($smarty.request.invoice_types) && in_array( $paymentType.id, $smarty.request.invoice_types )} selected{/if}>{$paymentType.name}</option>
+ {/foreach}
+ </select>
+
+ {/if}
+
+ {if $counties}
+
+ <label>Counties:</label>
+
+ <select multiple size="10" name="counties[]">
+ {foreach $counties as $county}
+ <option value="{$county.id}"{if isset($smarty.request.counties) && in_array( $county.id, $smarty.request.counties )} selected{/if}>{$county.name}</option>
+ {/foreach}
+ </select>
+
+ {/if}
+
+ <input type="submit" value="Filter">
+
+ <input type="submit" name="submitType" value="Create Invoices">
+
+ </div>
+
+ <p>Total found: {$totalAccounts}</p>
+
+ {* Paging *}
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
+
+ <br clear="all">
+
+ <div id="account-list">
+ <table class="wp-list-table widefat fixed posts glm-admin-table">
+ <thead>
+ <tr>
+ <th> Member Name </th>
+ <th> Account Number </th>
+ <th> Payment Type </th>
+ <th> Balance Due </th>
+ </tr>
+ </thead>
+ {foreach $accounts as $t}
+ <tr>
+ <td> {$t.member_name} </td>
+ <td> {$t.account_number} </td>
+ <td> {$t.payment_type} </td>
+ <td> {$t.balance_due|string_format:"%.2f"} </td>
+ </tr>
+ {/foreach}
+ </table>
+ </div>
+
+ {* Paging *}
+ {if $paging}
+ <input type="submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
+
+</form>
+
+{include file='admin/footer.html'}
<div class="glm-grid-container">
<div class="glm-grid-item">
<div><strong>Member Name:</strong> {$memberData.name}</div>
- <div>{$memberData.member_type_short}</div>
+ {if $settings.member_types_enabled}
+ <div>{$memberData.member_type_short}</div>
+ {/if}
{if $account_data}
{if $settings.member_types_enabled}
<div><strong>Renewal date:</strong> {$account_data.renewal_date|strtotime|date_format}</div>
<div><strong>Membership Status:</strong> {$account_status}</div>
{else}
- Uptra stuff here
+ {* Uptra stuff here *}
{/if}
{/if}
</div>
class="nav-tab{if $option == 'list'} nav-tab-active{/if}">Search Invoices</a>
<a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=add"
class="nav-tab{if $option == 'add' || $option == 'edit'} nav-tab-active{/if}">Create Invoice</a>
- <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=bulkadd"
- class="nav-tab{if $option == 'bulkadd'} nav-tab-active{/if}">Create Bulk Invoices</a>
</h2>