From: Steve Sutton Date: Wed, 21 Nov 2018 21:38:03 +0000 (-0500) Subject: Import account setup for Uptravel. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c71cc4dd346678435a2cac721492086a29edadb1;p=WP-Plugins%2Fglm-member-db-billing.git Import account setup for Uptravel. Import accounts. Setting up account for specific uptravel version. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 0bcd233..2a44049 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -894,6 +894,24 @@ class GlmBillingSupport ); } + /** + * 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 * diff --git a/classes/data/dataInvoiceTypes.php b/classes/data/dataInvoiceTypes.php index 19a9ed2..07b6e49 100644 --- a/classes/data/dataInvoiceTypes.php +++ b/classes/data/dataInvoiceTypes.php @@ -153,11 +153,17 @@ class GlmDataInvoiceTypes extends GlmDataAbstract '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', ), @@ -167,6 +173,21 @@ class GlmDataInvoiceTypes extends GlmDataAbstract 'type' => 'text', 'use' => 'a', ), + + // QCode + 'qcode' => array( + 'field' => 'qcode', + 'type' => 'text', + 'use' => 'a', + ), + + // Category + 'category' => array( + 'field' => 'category', + 'type' => 'text', + 'use' => 'a', + ), + ); diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 21da272..5150865 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -153,7 +153,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices ); } $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - $paymentTypes = $BillingSupport->getAllPayableInvoiceTypes(); + $paymentTypes = $BillingSupport->getAllInvoiceTypes(); break; case 'add': diff --git a/models/admin/management/billing.php b/models/admin/management/billing.php index 2bbf0f1..03452ee 100644 --- a/models/admin/management/billing.php +++ b/models/admin/management/billing.php @@ -164,6 +164,23 @@ class GlmMembersAdmin_management_billing extends GlmDataBillingManagement 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'] ) ) { diff --git a/models/admin/management/importAccounts.php b/models/admin/management/importAccounts.php new file mode 100644 index 0000000..56673ec --- /dev/null +++ b/models/admin/management/importAccounts.php @@ -0,0 +1,248 @@ +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 = '
$invoice_line_items: ' . print_r( $invoice_line_items, true ) . '
'; + +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 .= '
$pid: ' . print_r( $pid, true ) . '
'; +// } +// $importResults .= '
$paymentTypes: ' . print_r( $paymentTypes, true ) . '
'; + +// 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 . "
"; + +$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 ) . "
"; + +// $importResults .= '
$members: ' . print_r( $members, true ) . '
'; + +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 .= '
$member: ' . print_r( $member, true ) . '
'; + + // 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 .= '
$newMemberId: ' . print_r( $newMemberId, true ) . '
'; + + 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 .= '
$accountData: ' . print_r( $accountData, true ) . '
'; + + // 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 .= '
$accountId: ' . print_r( $accountId, true ) . '
'; + + // 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; diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 2395c8f..c205823 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -405,6 +405,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling case 'account': + $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); + $invoiceTypes = $InvoiceTypesObj->getList(); + + // echo '
$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '
'; + // Need to see if there's an account for this member. $accountID = $this->wpdb->get_var( diff --git a/views/admin/billing/editAccount.html b/views/admin/billing/editAccount.html index 614d11d..a8a3032 100644 --- a/views/admin/billing/editAccount.html +++ b/views/admin/billing/editAccount.html @@ -18,7 +18,9 @@ + {if $settings.member_types_enabled} + {/if} {if $lockedToMember} @@ -31,7 +33,6 @@
Account Information -
Name
@@ -41,6 +42,26 @@
{if !$lockedToMember} + + + {if !$settings.member_types_enabled} + +
+
Payment Type
+
+ + {if $account.fieldFail.invoice_type}

{$account.fieldFail.invoice_type}

{/if}
+
+
+ + {/if} + +
Anniversary Date
diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index e36a06b..01fb837 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -3,8 +3,12 @@
Member Name: {$memberData.name}
{$memberData.member_type_short}
{if $account_data} -
Renewal date: {$account_data.renewal_date|strtotime|date_format}
-
Membership Status: {$account_status}
+ {if $settings.member_types_enabled} +
Renewal date: {$account_data.renewal_date|strtotime|date_format}
+
Membership Status: {$account_status}
+ {else} + Uptra stuff here + {/if} {/if}
@@ -21,11 +25,11 @@ class="">All Statements {if ($account_status == 'Pending' || $account_status == 'Expired') && !apply_filters('glm-billing-account-has-renewal', true, $accountID )} -
  • - Membership Renewal -
  • +
  • + Membership Renewal +
  • {/if}
  • + + + + + + + + + + + +
    + +{/if} + +Number processed: {$numberProcessed} + +{* +{if $numberProcessed < $totalMembers} + + +{/if} +*} + +{include file='admin/management/footer.html'} diff --git a/views/admin/management/subHeader.html b/views/admin/management/subHeader.html index 47c62fe..aa049cb 100644 --- a/views/admin/management/subHeader.html +++ b/views/admin/management/subHeader.html @@ -2,6 +2,6 @@
    diff --git a/views/admin/settings/invoiceTypes.html b/views/admin/settings/invoiceTypes.html index 76d46a6..2c9da65 100644 --- a/views/admin/settings/invoiceTypes.html +++ b/views/admin/settings/invoiceTypes.html @@ -49,6 +49,14 @@ + + Dynamic Amount: + + + + Ask for the amount on Invoice Forms + + Recurring: @@ -67,6 +75,18 @@ + + Code: + + + + + + Category: + + + +

    * Required

    Cancel @@ -130,6 +150,14 @@ + + Dynamic Amount: + + + + Ask for the amount on Invoice Forms + + Recurring: @@ -148,6 +176,18 @@ + + Code: + + + + + + Category: + + + +

    * Required

    Cancel @@ -163,6 +203,7 @@ ID InvoiceType Amount + Dynamic Amount Recurring Recurrence   @@ -182,15 +223,19 @@ {$t.name} + data-invoice-recurrence="{$t.recurrence}" + data-invoice-qcode="{$t.qcode}" + data-invoice-category="{$t.category|escape}">{$t.name}
  • {$t.amount} + {if $t.dynamic_amount.value}Yes{else}No{/if} {if $t.recurring.value}Yes{else}No{/if} {if $t.recurrence}{$recurrenceTypes[$t.recurrence]}{/if} @@ -229,16 +274,18 @@ jQuery(document).ready(function($) { }); $('.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 ); @@ -246,6 +293,11 @@ jQuery(document).ready(function($) { $('#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 ); }