Import accounts.
Setting up account for specific uptravel version.
);
}
+ /**
+ * getAllInvoiceTypes
+ *
+ * Get all invoice types that have amounts
+ *
+ * @access public
+ * @return array
+ */
+ public function getAllInvoiceTypes()
+ {
+ return $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+ ORDER BY name",
+ ARRAY_A
+ );
+ }
+
/**
* getListOfAccountEmployees
*
'use' => 'a',
),
+ // Dynamic Amount
+ 'dynamic_amount' => array(
+ 'field' => 'dynamic_amount',
+ 'type' => 'checkbox',
+ 'use' => 'a',
+ ),
+
// Recurring
'recurring' => array(
'field' => 'recurring',
'type' => 'checkbox',
- // 'default' => false,
'use' => 'a',
),
'type' => 'text',
'use' => 'a',
),
+
+ // QCode
+ 'qcode' => array(
+ 'field' => 'qcode',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Category
+ 'category' => array(
+ 'field' => 'category',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
);
);
}
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
- $paymentTypes = $BillingSupport->getAllPayableInvoiceTypes();
+ $paymentTypes = $BillingSupport->getAllInvoiceTypes();
break;
case 'add':
break;
+ case 'importAccounts':
+ $view = 'importAccounts';
+ if ( isset( $_REQUEST['option2'] ) ) {
+ $option2 = $_REQUEST['option2'];
+ }
+ if ( !isset( $option2 ) ) {
+ $option2 = '';
+ }
+ switch ( $option2 ) {
+ case 'import':
+ require_once GLM_MEMBERS_BILLING_PLUGIN_PATH.'/models/admin/management/importAccounts.php';
+ break;
+ default:
+ break;
+ }
+ break;
+
case 'createInvoices':
$view = 'createInvoices';
if ( isset( $_REQUEST['option2'] ) ) {
--- /dev/null
+<?php
+/**
+ * Create Invoices (MiGCSA)
+ */
+// For billing support functions
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+// For invoices
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php';
+$Invoice = new GlmDataInvoices( $this->wpdb, $this->config );
+
+// For Accounts
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+$Account = new GlmDataAccounts( $this->wpdb, $this->config );
+
+// Get all Invoice Types
+// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoiceTypes.php';
+// $InvoiceTypes = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+// $invoiceTypes = $InvoiceTypes->getList();
+// $importResults = '<pre>$invoice_line_items: ' . print_r( $invoice_line_items, true ) . '</pre>';
+
+function getPaymentTypeId( $wpdb, $name )
+{
+ // Look up the name
+ return $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+ WHERE name = %s",
+ $name
+ )
+ );
+}
+
+function addPaymentType( $wpdb, $data )
+{
+ // Look up the name
+ $id = getPaymentTypeId( $wpdb, $data['name'] );
+ if ( $id ) {
+ $wpdb->update(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoice_types',
+ array(
+ 'parent' => 0,
+ 'name' => $data['name'],
+ 'qcode' => $data['qcode'],
+ 'category' => $data['category'],
+ 'amount' => $data['amount'],
+ 'dynamic_amount' => $data['dynamic_amount'],
+ 'recurring' => true,
+ 'recurrence' => 20,
+ ),
+ array( 'id' => $id ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ )
+ );
+ return $id;
+ } else {
+ $wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoice_types',
+ array(
+ 'parent' => 0,
+ 'name' => $data['name'],
+ 'qcode' => $data['qcode'],
+ 'category' => $data['category'],
+ 'amount' => $data['amount'],
+ 'dynamic_amount' => $data['dynamic_amount'],
+ 'recurring' => true,
+ 'recurrence' => 20,
+ ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ )
+ );
+ return $wpdb->insert_id;
+ }
+}
+
+// Connect to their live database.
+$dbh = new PDO(
+ 'pgsql: host=ds4.gaslightmedia.com dbname=uptravel user=nobody',
+ null,
+ null,
+ array(
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
+ )
+);
+
+$dbh->setAttribute(
+ PDO::ATTR_ERRMODE,
+ PDO::ERRMODE_EXCEPTION
+);
+
+if ( isset( $_REQUEST['start'] ) && $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ) ) {
+} else {
+ $start = 0;
+}
+
+$importResults = '';
+
+// Get all payment types here.
+// $sql = "
+// SELECT *
+// FROM members.payment_types
+// ORDER BY id";
+//
+// $paymentTypes = $dbh->query( $sql )->fetchAll();
+// foreach ( $paymentTypes as $pType ) {
+// $pid = addPaymentType( $this->wpdb, $pType );
+// $importResults .= '<pre>$pid: ' . print_r( $pid, true ) . '</pre>';
+// }
+// $importResults .= '<pre>$paymentTypes: ' . print_r( $paymentTypes, true ) . '</pre>';
+
+// Get total number of members.
+$sql = "
+SELECT count(M.member_id) as total
+ 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 )
+ WHERE PT.name != ''
+ AND PT.name IS NOT NULL
+ AND (M.type = 'full' OR M.type = 'enhanced')
+";
+$totalStmt = $dbh->query( $sql );
+$totalMembers = $totalStmt->fetchColumn();
+$importResults .= 'Total Members: ' . $totalMembers . "<br>";
+
+$sql = "
+SELECT M.member_id,M.billing_contact,M.account_number,
+ PT.name as payment_type,M.process_email as email, M.member_name
+ 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 )
+ WHERE PT.name != ''
+ AND PT.name IS NOT NULL
+ AND (M.type = 'full' OR M.type = 'enhanced')
+ORDER BY M.member_id";
+
+//LIMIT 10
+//OFFSET $start";
+$stmt = $dbh->query( $sql );
+$members = $stmt->fetchAll();
+$numberMembers = count( $members );
+
+$importResults .= 'Total Members this round: ' . count( $members ) . "<br>";
+
+// $importResults .= '<pre>$members: ' . print_r( $members, true ) . '</pre>';
+
+if ( $start === 0 ) {
+ // Clear the invoices,line_items and transactions
+ // $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices" );
+ // $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "line_items" );
+ // $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions" );
+}
+
+foreach ( $members as $member ) {
+
+ $importResults .= '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+
+ // Get the new id of member (old_member_id).
+ $newMemberId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d",
+ $member['member_id']
+ )
+ );
+ $importResults .= '<pre>$newMemberId: ' . print_r( $newMemberId, true ) . '</pre>';
+
+ if ( $newMemberId ) {
+
+ $paymentTypeId = getPaymentTypeId( $this->wpdb, $member['payment_type'] );
+
+ $refName = ( $member['billing_contact'] ) ? $member['billing_contact'] : $member['member_name'];
+
+ $accountData = array(
+ 'ref_dest' => $newMemberId,
+ 'ref_name' => $refName,
+ 'invoice_type' => $paymentTypeId,
+ 'email' => $member['email'],
+ 'account_number' => $member['account_number'],
+ 'renewal_date' => '2018-07-01',
+ );
+ $accountDataFormat = array(
+ '%d', // ref_dest
+ '%s', // ref_name
+ '%d', // invoice_type
+ '%s', // email
+ '%s', // account_number
+ '%s', // renewal_date
+ );
+
+ $importResults .= '<pre>$accountData: ' . print_r( $accountData, true ) . '</pre>';
+
+ // Check if member has an account.
+ $accountId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ WHERE ref_dest = %d",
+ $newMemberId
+ )
+ );
+ $importResults .= '<pre>$accountId: ' . print_r( $accountId, true ) . '</pre>';
+
+ // If not create one.
+ if ( !$accountId ) {
+
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ $accountData,
+ $accountDataFormat
+ );
+
+ } else {
+
+ // Else update account.
+ $this->wpdb->update(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ $accountData,
+ array( 'id' => $accountId ),
+ $accountDataFormat,
+ array( '%d' )
+ );
+
+ }
+
+ }
+
+}
+
+$numberProcessed = $start + 10;
case 'account':
+ $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+ $invoiceTypes = $InvoiceTypesObj->getList();
+
+ // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
+
// Need to see if there's an account for this member.
$accountID = $this->wpdb->get_var(
<input type="hidden" name="member" value="{$memberID}" />
<input type="hidden" name="ref_dest" value="{$memberID}" />
<input type="hidden" name="option" value="account" />
+ {if $settings.member_types_enabled}
<input type="hidden" name="invoice_type" value="{$account.fieldData.invoice_type}" />
+ {/if}
{if $lockedToMember}
<input type="hidden" name="anniversary_date" value="{$account.fieldData.anniversary_date.date}" />
<input type="hidden" name="renewal_date" value="{$account.fieldData.renewal_date.date}" />
<fieldset>
<legend>Account Information</legend>
-
<div class="glm-billing-field">
<div class="glm-billing-label{if $account.fieldRequired.ref_name} glm-required{/if}">Name</div>
<div class="glm-billing-input{if $account.fieldFail.ref_name} glm-form-bad-input{/if}" data-tabid="glm-name">
</div>
{if !$lockedToMember}
+
+
+ {if !$settings.member_types_enabled}
+
+ <div class="glm-billing-field">
+ <div class="glm-billing-label{if $account.fieldRequired.invoice_type} glm-required{/if}">Payment Type</div>
+ <div class="glm-billing-input{if $account.fieldFail.invoice_type} glm-form-bad-input{/if}" data-tabid="glm-invoice-type">
+ <select name="invoice_type" required>
+ <option value="0"></option>
+ {foreach $invoiceTypes as $type}
+ <option value="{$type.id}"{if $type.id == $account.fieldData.invoice_type} selected{/if}>{$type.name} (${$type.amount})</option>
+ {/foreach}
+ </select>
+ {if $account.fieldFail.invoice_type}<p>{$account.fieldFail.invoice_type}</p>{/if}<br>
+ </div>
+ </div>
+
+ {/if}
+
+
<div class="glm-billing-field glm-billing-left-half">
<div class="glm-billing-label{if $account.fieldRequired.anniversary_date} glm-required{/if}">Anniversary Date</div>
<div class="glm-billing-input{if $account.fieldFail.anniversary_date} glm-form-bad-input{/if}" data-tabid="glm-anniversary-date">
<div><strong>Member Name:</strong> {$memberData.name}</div>
<div>{$memberData.member_type_short}</div>
{if $account_data}
- <div><strong>Renewal date:</strong> {$account_data.renewal_date|strtotime|date_format}</div>
- <div><strong>Membership Status:</strong> {$account_status}</div>
+ {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
+ {/if}
{/if}
</div>
class="">All Statements</a>
</li>
{if ($account_status == 'Pending' || $account_status == 'Expired') && !apply_filters('glm-billing-account-has-renewal', true, $accountID )}
- <li>
- <a
- href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=renew"
- class="">Membership Renewal</a>
- </li>
+ <li>
+ <a
+ href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=renew"
+ class="">Membership Renewal</a>
+ </li>
{/if}
<li>
<a
--- /dev/null
+{include file='admin/management/header.html'}
+
+{include file='admin/management/subHeader.html'}
+
+{if $importResults}
+ {$importResults}
+{else}
+ <form action="{$thisUrl}?page={$thisPage}" method="post">
+
+ <input type="hidden" name="glm_action" value="billing" />
+ <input type="hidden" name="option" value="importAccounts" />
+ <input type="hidden" name="option2" value="import" />
+
+ <table class="glm-admin-table glm-settings-table">
+
+ <tr>
+ <td><input type="submit" value="Import Accounts" /></td>
+ </tr>
+
+ </table>
+ </form>
+{/if}
+
+Number processed: {$numberProcessed}
+
+{*
+{if $numberProcessed < $totalMembers}
+
+<script>
+jQuery(document).ready(function($){
+
+ //window.location.href = '{$thisUrl}?page={$thisPage}&glm_action=billing&option=createInvoices&option2=create&start={$numberProcessed}';
+
+});
+
+</script>
+{/if}
+*}
+
+{include file='admin/management/footer.html'}
<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
<a href="{$thisUrl}?page=glm-members-admin-menu-management&glm_action=billing"
class="glm-settings-tab nav-tab{if $option == ''} nav-tab-active{/if}">General Settings</a>
- <!-- <a href="{$thisUrl}?page=glm-members-admin-menu-management&glm_action=billing&option=createInvoices" -->
- <!-- class="glm-settings-tab nav-tab{if $option == 'createInvoices'} nav-tab-active{/if}">Create Invoices</a> -->
+ <a href="{$thisUrl}?page=glm-members-admin-menu-management&glm_action=billing&option=importAccounts"
+ class="glm-settings-tab nav-tab{if $option == 'importAccounts'} nav-tab-active{/if}">Import Accounts</a>
</h2>
<input type="text" name="amount" class="glm-form-text-input" required>
</td>
</tr>
+ <tr>
+ <th style="text-align: right;">Dynamic Amount:</th>
+ <td>
+ <input type="hidden" name="dynamic_amount" class="glm-form-text-input" value="0">
+ <input type="checkbox" name="dynamic_amount" class="glm-form-text-input" value="1">
+ Ask for the amount on Invoice Forms
+ </td>
+ </tr>
<tr>
<th style="text-align: right;">Recurring:</th>
<td>
</select>
</td>
</tr>
+ <tr>
+ <th style="text-align: right;">Code:</th>
+ <td>
+ <input type="text" name="qcode" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">Category:</th>
+ <td>
+ <input type="text" name="category" class="glm-form-text-input">
+ </td>
+ </tr>
</table>
<p><span class="glm-required">*</span> Required</p>
<a id="newInvoiceTypeCancel" class="button button-primary glm-right">Cancel</a>
<input id="edit-amount" type="text" name="amount" class="glm-form-text-input" required>
</td>
</tr>
+ <tr>
+ <th style="text-align: right;">Dynamic Amount:</th>
+ <td>
+ <input type="hidden" name="dynamic_amount" class="glm-form-text-input" value="0">
+ <input id="edit-dynamic-amount" type="checkbox" name="dynamic_amount" class="glm-form-text-input" value="1">
+ Ask for the amount on Invoice Forms
+ </td>
+ </tr>
<tr>
<th style="text-align: right;">Recurring:</th>
<td>
</select>
</td>
</tr>
+ <tr>
+ <th style="text-align: right;">Code:</th>
+ <td>
+ <input id="edit-qcode" type="text" name="qcode" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">Category:</th>
+ <td>
+ <input id="edit-category" type="text" name="category" class="glm-form-text-input">
+ </td>
+ </tr>
</table>
<p><span class="glm-required">*</span> Required</p>
<a id="editInvoiceTypeCancel" class="button button-primary glm-right">Cancel</a>
<th style="width: 50px;">ID</th>
<th style="width: 850px;">InvoiceType</th>
<th>Amount</th>
+ <th>Dynamic Amount</th>
<th>Recurring</th>
<th>Recurrence</th>
<th> </th>
<div{if $t.parent.value} class="glm-indent"{/if}>
<a class="editInvoiceType"
data-invoice-id="{$t.id}"
- data-invoice-name="{$t.name}"
+ data-invoice-name="{$t.name|escape}"
data-invoice-parent="{$t.parent.value}"
data-invoice-member_type="{$t.member_type.value}"
data-invoice-amount="{$t.amount}"
+ data-invoice-dynamic-amount="{$t.dynamic_amount.value}"
data-invoice-recurring="{$t.recurring.value}"
- data-invoice-recurrence="{$t.recurrence}">{$t.name}</a>
+ data-invoice-recurrence="{$t.recurrence}"
+ data-invoice-qcode="{$t.qcode}"
+ data-invoice-category="{$t.category|escape}">{$t.name}</a>
</div>
</td>
<td>{$t.amount}</td>
+ <td>{if $t.dynamic_amount.value}Yes{else}No{/if}</td>
<td>{if $t.recurring.value}Yes{else}No{/if}</td>
<td>{if $t.recurrence}{$recurrenceTypes[$t.recurrence]}{/if}</td>
<td>
});
$('.editInvoiceType').click( function() {
$('#edit-recurring').prop( 'checked', false );
+ $('#edit-dynamic-amount').prop( 'checked', false );
- var invoiceID = $(this).data('invoice-id');
- var invoiceName = $(this).data('invoice-name');
- var invoiceParent = $(this).data('invoice-parent');
- var invoiceType = $(this).data('invoice-member_type');
- var invoiceAmount = $(this).data('invoice-amount');
- var invoiceRecurring = $(this).data('invoice-recurring');
- var invoiceRecurrence = $(this).data('invoice-recurrence');
-
- //console.log( 'invoiceRecurring: ', invoiceRecurring );
+ var invoiceID = $(this).data('invoice-id');
+ var invoiceName = $(this).data('invoice-name');
+ var invoiceParent = $(this).data('invoice-parent');
+ var invoiceType = $(this).data('invoice-member_type');
+ var invoiceAmount = $(this).data('invoice-amount');
+ var invoiceDynamicAmount = $(this).data('invoice-dynamic-amount');
+ var invoiceRecurring = $(this).data('invoice-recurring');
+ var invoiceRecurrence = $(this).data('invoice-recurrence');
+ var invoiceQcode = $(this).data('invoice-qcode');
+ var invoiceCategory = $(this).data('invoice-category');
// Set the values of the edit form for the selected invoiceType
$('#edit-id').val( invoiceID );
$('#edit-parent').val( invoiceParent );
$('#edit-member_type').val( invoiceType );
$('#edit-amount').val( invoiceAmount );
+ $('#edit-qcode').val( invoiceQcode );
+ $('#edit-category').val( invoiceCategory );
+ if ( invoiceDynamicAmount === 1 ) {
+ $('#edit-dynamic-amount').prop( 'checked', true );
+ }
if ( invoiceRecurring === 1 ) {
$('#edit-recurring').prop( 'checked', true );
}