From 0fc1225107394b8e9faed3a0dce8e57febd07620 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 2 Apr 2018 16:46:02 -0400 Subject: [PATCH] WIP working on generic payment page. Working on pulling in the unpaid invoices for an account when they look up by account name. Getting the list of invoices. Need to put into the payment form. --- models/admin/ajax/invoices.php | 105 +++++++++++++++++++++++++++ models/admin/billing/payments.php | 8 +- setup/validActions.php | 1 + views/admin/billing/editInvoice.html | 21 +----- views/admin/billing/editPayment.html | 82 ++++++++++++++------- 5 files changed, 171 insertions(+), 46 deletions(-) create mode 100644 models/admin/ajax/invoices.php diff --git a/models/admin/ajax/invoices.php b/models/admin/ajax/invoices.php new file mode 100644 index 0000000..d586de3 --- /dev/null +++ b/models/admin/ajax/invoices.php @@ -0,0 +1,105 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Members data abstract +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php'; + +/** + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_invoices extends GlmDataInvoices +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This constructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for data class + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This model checks to see if the credentials passed in are correct. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Output JSON string as response and does not return + */ + public function modelAction( $actionData = false ) + { + $return = false; + + $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ); + trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) ); + + switch ( $option ) { + case 'list': + default: + $account = filter_var( $_REQUEST['account'], FILTER_VALIDATE_INT ); + $invoices = $this->getList( "T.paid <> true AND T.account = $account" ); + $return = array(); + foreach ( $invoices as $invoice ) { + $return[] = array( + 'id' => $invoice['id'], + 'transaction_time' => $invoice['transaction_time'], + 'balance' => $invoice['balance'], + 'due_date' => $invoice['due_date'] + ); + } + + break; + } + + header( 'Content-type:application/json;charset=utf-8', true ); + echo json_encode( $return, true ); + exit(); + } +} diff --git a/models/admin/billing/payments.php b/models/admin/billing/payments.php index d3eabe8..04e23f8 100644 --- a/models/admin/billing/payments.php +++ b/models/admin/billing/payments.php @@ -129,7 +129,13 @@ class GlmMembersAdmin_billing_payments extends GlmDataPayments $view = 'editPayment'; // Need to get the accounts $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); - $accounts = $Accounts->getSimpleAccountList(); + + // Get only accounts that have invoices + $accounts = $Accounts->getSimpleAccountList( + "T.id IN ( SELECT DISTINCT account + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices + WHERE paid <> true )" + ); break; case 'insert': diff --git a/setup/validActions.php b/setup/validActions.php index 52a36df..7407416 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -63,6 +63,7 @@ $glmMembersBillingAddOnValidActions = array( 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'invoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index 1c9c5f4..99f4d6d 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -234,8 +234,7 @@ jQuery(document).ready(function($){ { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", - id: '{$m.id}', - anniversary: '{$m.next_anniversary_date}' + id: '{$m.id}' }, {/foreach} ]; @@ -255,8 +254,6 @@ jQuery(document).ready(function($){ change: function( event, ui ) { // If not in select option then empty the field $(this).val((ui.item ? ui.item.label : "")); - // Update the anniversary date - $('#invoice_due_date').val( ui.item.anniversary ); }, }); // Setup autocomplete for the non member input. @@ -549,8 +546,7 @@ jQuery(document).ready(function($){ availableAccountMembers.push( { label: obj.name, value: obj.name, - id: obj.id, - anniversary: obj.ann + id: obj.id } ); } // console.log( 'availableAccountMembers', availableAccountMembers ); @@ -692,7 +688,8 @@ jQuery(document).ready(function($){ data: { name: customFieldName.val(), amount: customFieldAmount.val(), - parent: customFieldParent.val() + parent: customFieldParent.val(), + member_type: 0 }, encode: true, dataType: 'json' @@ -819,16 +816,6 @@ jQuery(document).ready(function($){ dateFormat: 'mm/dd/yy' }); - /** - * Change event listener for member account select. - * When the member account is selected it should set the - * invoice due_date to the current year based on the anniversary date. - * Todo: Update this for the changes for adding in the autocomplete. - */ - $('#member-account').change(function(){ - $('#invoice_due_date').val( $(this).find('option:selected').data('anniversary') ); - }); - // 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); diff --git a/views/admin/billing/editPayment.html b/views/admin/billing/editPayment.html index c426d20..b0d7ad3 100644 --- a/views/admin/billing/editPayment.html +++ b/views/admin/billing/editPayment.html @@ -7,7 +7,7 @@ {if $paymentInsertError}Notification Insert Error{/if} {if $paymentAdded}Notification Added{/if} -
+
{if $payment_id} @@ -15,52 +15,78 @@ {else} {/if} -
-
- -
-
- Member Account +
+
+ Lookup Member Invoices By Account +
+
+ + +
+
+
+
+ Select Invoices
-
- +
-
-
+
+
Amount
-
- +
+
+
-
-
+
+
Notes
-
+
-
-
-
-
- -
-
+