Give ability to delete an account.
'recurrence' => $new_member_invoice_type['recurrence'],
)
);
- echo '<pre>$invoice_id: ' . print_r( $invoice_id, true ) . '</pre>';
+ // echo '<pre>$invoice_id: ' . print_r( $invoice_id, true ) . '</pre>';
if ( $invoice_id ) {
if ( isset( $employees ) && is_array( $employees ) ) {
// Add line items for each employee.
return $accountList;
}
+
+ public function deleteAccount( $id )
+ {
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_payments WHERE invoice IN
+ (SELECT id FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices WHERE account = $id)" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "line_items WHERE account = $id" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices WHERE account = $id" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "payments WHERE account = $id" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions WHERE account = $id" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notifications WHERE account = $id" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue WHERE account = $id" );
+ $ret = $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts WHERE id = $id" );
+ return $ret;
+ }
}
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/models/admin/billing/accounts.php';
+
+/**
+ * Steve Note
+ *
+ * You can get to this using the following URL.
+ *
+ *
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+/**
+ * This class handles the work of creating new invoices based on.
+ * 1) Member Type of member matching a paid invoiceType
+ * 2) Member renewal date past
+ * 3) Member has Billing Account
+ * 4) Member has no active Invoice
+ * 5) Renewal date is within the next 30 Days
+ *
+ */
+class GlmMembersAdmin_ajax_ajaxBillingAccounts extends GlmMembersAdmin_billing_accounts
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ public $ajaxSide = true;
+
+
+}
break;
case 'delete':
- // Need to remove any line items for the invoice also
- // $accounts = $this->deleteTransactions($this->account_id);
-
- if ( $accounts ) {
- $invoiceDeleted = true;
- } else {
- $invoiceDeleteError = true;
+ $success = false;
+ // This is done by ajax call only
+ $account_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
+ if ( $account_id ) {
+ // Remove the account and any related data
+ // Need to remove any line items for the invoice also
+ $success = $this->deleteAccount( $account_id );
}
+ header( 'Content-type:application/json;charset=utf-8', true );
+ echo json_encode( [ 'success' => $success ], true );
+ exit;
+ break;
+
case 'list':
default:
$where_params = array( 'true' );
$sub_where_parts = array();
- // Check for paging
- // if ( isset( $_REQUEST['pageSelect'] ) ) {
- // $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
- // } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
- // unset( $_SESSION['search']['pageSelect'] );
- // }
- // if ( isset( $_REQUEST['nextStart'] ) ) {
- // $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
- // } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
- // unset( $_SESSION['search']['nextStart'] );
- // }
- // if ( isset( $_REQUEST['prevStart'] ) ) {
- // $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
- // } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
- // unset( $_SESSION['search']['prevStart'] );
- // }
-
// Check if we're doing paging
if (isset($_REQUEST['pageSelect'])) {
// If request is for Next
}
}
- // if( isset($_SESSION['search']['pageSelect']) ){
- // // If request is for Next
- // if ($_SESSION['search']['pageSelect'][0] == 'N') {
- // $newStart = $_SESSION['search']['nextStart'] - 0;
- //
- // // Otherwise it must be Previous
- // } else {
- // $newStart = $_SESSION['search']['prevStart'] - 0;
- // }
- // if ($newStart > 0) {
- // $start = $newStart;
- // }
- // }
// Get any search parameters.
$reg_options = array(
'options' => array(
*/
// Common to both admin and front-end
-$smarty->templateAssign( 'glmPluginName', GLM_MEMBERS_BILLING_PLUGIN_NAME );
$smarty->templateAssign( 'pluginAssetsUrl', GLM_MEMBERS_BILLING_PLUGIN_BASE_URL . '/assets/' );
if ( current_user_can( 'glm_members_management' ) ) {
'billingFlagExpiredUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
'billingFixActiveUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
'ajaxBillingInfo' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'ajaxBillingAccounts' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
'ajaxBillingSettings' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
'ajaxNotificationPreview' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
{* Search Form *}
{include file='admin/billing/accountSearchForm.html'}
-<p>Total found: <span class="label">{$totalAccounts}</span></p>
+<p>Total found: <span class="label" id="glm-billing-account-total" data-total="{$totalAccounts}">{$totalAccounts}</span></p>
{if $paging}
<input type="Submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
<tbody>
{if $haveAccounts}
{foreach $accounts as $t}
- <tr class="glm-account-row{if $t@iteration is div by 2} alternate{/if}" data-id="{$t.id}">
+ <tr class="glm-account-row{if $t@iteration is div by 2} alternate{/if}" data-id="{$t.id}" id="glm-account-{$t.id}">
<td> {$t.id} </td>
<td> <b id="account-ref-dest-{$t.id}">{$t.ref_name}</b> </td>
{if $settings.allow_employees}
<a class="account-member-statements" data-member="{$t.ref_dest}" href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$t.ref_dest}">View Statements</a> |
</span>
<span class="account-dashboard-link">
- <a class="account-billing" href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&option=account&member={$t.ref_dest}" data-member="{$t.ref_dest}">Billing Info</a>
+ <a class="account-billing" href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&option=account&member={$t.ref_dest}" data-member="{$t.ref_dest}">Billing Info</a> |
+ </span>
+ <span>
+ <a class="account-delete" href="#" data-id="{$t.id}">Delete Account</a>
</span>
{if $t.boss.value}
<span class="account-dashboard-link">
$( '#account-container-' + accountHoverId ).addClass( 'hide-for-large' );
});
+ $('.account-delete').on( 'click', function(e){
+ e.preventDefault();
+ var answer = confirm( 'This account will be deleted! Are you sure?' );
+ if ( answer ) {
+ var id = $(this).data('id');
+ $.ajax({
+ url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=ajaxBillingAccounts&option=delete&id=' + id,
+ cache: false,
+ dataType: 'json',
+ }).done(function(resp){
+ //console.log(resp);
+ if ( resp.success ) {
+ //console.log( 'Success: Good', resp.success );
+ $('#glm-account-' + id).remove();
+ alert( 'Account ' + id + ' Deleted' );
+ decreaseTotal();
+ } else {
+ //console.log( 'Success: Bad', resp.success );
+ }
+ });
+ }
+ });
+
+ function decreaseTotal() {
+ var totalObj = $('#glm-billing-account-total');
+ var total = parseInt(totalObj.data('total'));
+ total = total - 1;
+ totalObj.html( total );
+ totalObj.data('total', total);
+ }
+
$('.account-employees').on( 'click', function(e){
e.preventDefault();
accountLinksEmployeesSelected();