WIP for add account on add invoice page.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 5 Feb 2018 21:25:31 +0000 (16:25 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 5 Feb 2018 21:25:31 +0000 (16:25 -0500)
Setup adding an account for members that have non when adding an
invoice.

models/admin/billing/invoices.php
views/admin/billing/editInvoice.html

index c2cef43..c1c7979 100644 (file)
@@ -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 '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+
+            // 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 '<pre>$nonAccountMembers: ' . print_r( $nonAccountMembers, true ) . '</pre>';
+
             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,
index 652bf1e..16848d0 100644 (file)
@@ -20,7 +20,7 @@
 
                 <div class="glm-row">
                     <div class="glm-columns glm-small-12 glm-large-3 glm-required">
-                        Member Account
+                        Billing Account
                     </div>
                     <div class="glm-columns glm-small-12 glm-large-9">
                         <select id="member-account" name="account" required>
@@ -29,6 +29,7 @@
                             <option value="{$account.id}" data-anniversary="{$account.next_anniversary_date}">{$account.ref_name}</option>
                             {/foreach}
                         </select>
+                        <a id="newAccountButton" href="#">New Account</a>
                     </div>
                 </div>
                 <div class="glm-row">
@@ -36,7 +37,7 @@
                         Due Date
                     </div>
                     <div class="glm-columns glm-small-12 glm-large-9">
-                        <input id="invoice_due_date" type="text" name="due_date" required>
+                        <input class="datepicker" id="invoice_due_date" type="text" name="due_date" required>
                     </div>
                 </div>
                 <div class="glm-row">
         </div>
     </form>
 </div>
+<div id="newAccountDialog" class="glm-dialog-box" title="New Account">
+    <p class="validateAccountTips">* required.</p>
+    <form id="addAccountForm">
+        <input type="hidden" name="glm_action" value="invoices">
+        <input type="hidden" name="option" value="addAccount">
+        <table>
+            <tr>
+                <th class="glm-required">Member</th>
+                <td>
+                    <select name="ref_dest" style="width: 300px;">
+                        <option value="">Select Member</option>
+                        {foreach $nonAccountMembers as $m}
+                        <option value="{$m.id}">{$m.name}</option>
+                        {/foreach}
+                    </select>
+                </td>
+            </tr>
+            <tr>
+                <th class="glm-required">Anniversary Date</th>
+                <td>
+                    <input class="datepicker" type="text" name="anniversary_date" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Renewal Date</th>
+                <td>
+                    <input class="datepicker" type="text" name="renewal_date" value="">
+                </td>
+            </tr>
+            <tr>
+                <th class="glm-required">Billing Email</th>
+                <td>
+                    <input type="text" name="email" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing Address 1</th>
+                <td>
+                    <input type="text" name="billing_addr1" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing Address 2</th>
+                <td>
+                    <input type="text" name="billing_addr2" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing City</th>
+                <td>
+                    <input type="text" name="billing_city" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing State</th>
+                <td>
+                    <input type="text" name="billing_state" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing Zip</th>
+                <td>
+                    <input type="text" name="billing_zip" value="">
+                </td>
+            </tr>
+            <tr>
+                <th>Billing Phone</th>
+                <td>
+                    <input type="text" name="billing_phone" value="">
+                </td>
+            </tr>
+        </table>
+    </form>
+</div>
 <div id="newLineItemDialog" class="glm-dialog-box" title="Enter a Line Item">
+    <p class="validateTips">* Required!</p>
     <form id="addLineItemForm">
         <input type="hidden" name="glm_action" value="invoices">
         <input type="hidden" name="option" value="addLineItem">
 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.