From c2c4fecb02a3d8816104060cf8df25c6e4c00b5e Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 5 Feb 2018 16:25:31 -0500 Subject: [PATCH] WIP for add account on add invoice page. Setup adding an account for members that have non when adding an invoice. --- models/admin/billing/invoices.php | 15 +++ views/admin/billing/editInvoice.html | 189 +++++++++++++++++++++++++-- 2 files changed, 194 insertions(+), 10 deletions(-) diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index c2cef43..c1c7979 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -118,6 +118,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoiceTypes = false; $invoiceTypeJSON = ''; $accounts = false; + $nonAccountMembers = false; $invoiceHtml = ''; $fromDate = ''; $toDate = ''; @@ -142,6 +143,19 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getList(); // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; + + // Need a list of members that don't have an account. + $nonAccountMembers = $this->wpdb->get_results( + "SELECT id,name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id NOT IN ( + SELECT distinct ref_dest + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts ) + ORDER BY name", + ARRAY_A + ); + // echo '
$nonAccountMembers: ' . print_r( $nonAccountMembers, true ) . '
'; + if ( isset( $invoiceTypes ) ) { foreach ( $invoiceTypes as $invoiceType ) { $invTypes[$invoiceType['id']] = array( @@ -359,6 +373,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'option' => $option, 'invoice_id' => $this->invoice_id, 'invoices' => $invoices, + 'nonAccountMembers' => $nonAccountMembers, 'haveInvoices' => $haveInvoices, 'invoiceUpdated' => $invoiceUpdated, 'invoiceUpdateError' => $invoiceUpdateError, diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index 652bf1e..16848d0 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -20,7 +20,7 @@
- Member Account + Billing Account
+ New Account
@@ -36,7 +37,7 @@ Due Date
- +
@@ -73,7 +74,82 @@
+
+

* required.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Member + +
Anniversary Date + +
Renewal Date + +
Billing Email + +
Billing Address 1 + +
Billing Address 2 + +
Billing City + +
Billing State + +
Billing Zip + +
Billing Phone + +
+
+
+

* Required!

@@ -106,11 +182,29 @@ jQuery(document).ready(function($){ // Initialize variables for this page. var dialog, // Dialog for the add line_item form + newAccountDialog, // Dialog for the add new account form, // The add line_item form - line_item_type = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form - line_items = [], // Array holding line_items json objects - allFields = $( [] ).add( line_item_type ), // Array holding the form fields - add line_item form - invoiceTypeJSON = $.parseJSON( '{$invoiceTypeJSON}' ); // Json object with all of the invoices types + newAccountForm, // New Account Form + line_item_type = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form + line_items = [], // Array holding line_items json objects + allFields = $( [] ).add( line_item_type ), // Array holding the form fields - add line_item form + ref_dest = $( 'select[name="ref_dest"' ), + anniversary_date = $( 'input[name="anniversary_date"' ), + renewal_date = $( 'input[name="renewal_date"' ), + email = $( 'input[name="email"' ), + billing_addr1 = $( 'input[name="billing_addr1"' ), + billing_addr2 = $( 'input[name="billing_addr2"' ), + billing_city = $( 'input[name="billing_city"' ), + billing_state = $( 'input[name="billing_state"' ), + billing_zip = $( 'input[name="billing_zip"' ), + billing_phone = $( 'input[name="billing_phone"' ), + lineTips = $('.validateTips'), + accountTips = $('.validateAccountTips'), + allAccountFields = $( [] ).add( ref_dest ) .add( anniversary_date ) .add( renewal_date ) + .add( email ) .add( billing_addr1 ) .add( billing_addr2 ) .add( billing_city ) + .add( billing_state ) .add( billing_zip ) + .add( billing_phone ) , // Array holding the form fields - add line_item form + invoiceTypeJSON = $.parseJSON( '{$invoiceTypeJSON}' ); // Json object with all of the invoices types /** * totalInvoice @@ -160,7 +254,7 @@ jQuery(document).ready(function($){ var valid = true; allFields.removeClass( 'ui-state-error' ); - valid = valid && checkRequired( line_item_type ); + valid = valid && checkRequired( line_item_type, lineTips, 'Invoice Type is required!' ); if ( valid ) { var selectedLineItem = invoiceTypeJSON[line_item_type.val()]; @@ -189,6 +283,27 @@ jQuery(document).ready(function($){ return valid; } + /** + * addNewAccount + * + * Callback function to add a new account. + */ + function addNewAccount(){ + var valid = true; + allAccountFields.removeClass( 'ui-state-error' ); + + valid = valid && checkRequired( ref_dest, accountTips, 'Member is required!' ); + valid = valid && checkRequired( anniversary_date, accountTips, 'Anniversary Date is required!' ); + valid = valid && checkRequired( email, accountTips, 'Email is required!' ); + + if ( valid ) { + + } else { + } + + return valid; + } + /** * checkRequired * @@ -198,14 +313,26 @@ jQuery(document).ready(function($){ * @access public * @return void */ - function checkRequired( fieldName ) { + function checkRequired( fieldName, tips, message ) { if ( fieldName.val() ) { return true; } else { + fieldName.addClass( 'ui-state-error' ); + updateTips( tips, message ); return false; } } + + function updateTips( tips, t ) { + tips + .text( t ) + .addClass( 'ui-state-highlight' ); + setTimeout(function(){ + tips.removeClass( 'ui-state-highlight', 1500 ); + }, 500); + } + /** * dialog * @@ -223,8 +350,9 @@ jQuery(document).ready(function($){ }, }, close: function() { - form[0 ].reset(); + form[0].reset(); allFields.removeClass( 'ui-state-error' ); + updateTips( lineTips, '* required!' ); }, }); @@ -248,6 +376,47 @@ jQuery(document).ready(function($){ return false; }); + /** + * dialog for the New Account Form + */ + newAccountDialog = $('#newAccountDialog').dialog({ + autoOpen: false, + minWidth: 500, + dialogClass: 'glm-dialog-no-close', + modal: true, + buttons: { + "Add New Account": addNewAccount, + Cancel: function(){ + newAccountDialog.dialog( 'close' ); + }, + }, + close: function() { + newAccountForm[0].reset(); + allAccountFields.removeClass( 'ui-state-error' ); + updateTips( accountTips, '* required!' ); + }, + }); + + /** + * Add Account Form + * + * form with id of #addAccountForm + */ + newAccountForm = newAccountDialog.find( '#addAccountForm' ).on( 'submit', function(){ + event.preventDefault(); + console.log('Adding new Account'); + }); + + /** + * Click event for the id of #newLineItemButton. + * + * Activates the dialog for adding line items. + */ + $('#newAccountButton').click( function() { + $("#newAccountDialog").dialog("open"); + return false; + }); + /** * Onchange event for the qty fields. * So the line_items array gets updated with the qty number. @@ -264,7 +433,7 @@ jQuery(document).ready(function($){ }); // Setup the date picker for the input field with the name due_date - $('input[name="due_date"]').datepicker(); + $('.datepicker').datepicker(); /** * Change event listener for member account select. -- 2.17.1