Update the edit invoice page for member account selection.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 30 Jan 2018 21:59:46 +0000 (16:59 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 30 Jan 2018 21:59:46 +0000 (16:59 -0500)
When selecting a member account it will update the due date to that
members new anniversary date.

classes/data/dataAccounts.php
views/admin/billing/editInvoice.html

index e7666f5..88f2fb2 100644 (file)
@@ -239,6 +239,19 @@ class GlmDataAccounts extends GlmDataAbstract
      */
     public function entryPostProcessing($r, $a)
     {
+        // Setup the accounts anniversary date
+        if ( $r['anniversary_date'] ) {
+            // Need to find the next (current) date for this account's
+            // anniversary
+            $anniversary_date = new DateTime( $r['anniversary_date']['mysql_date'] );
+            if ( $r['anniversary_date']['timestamp'] > time() ) {
+                $r['next_anniversary_date'] = $r['anniversary_date']['date'];
+            } else {
+                // Add one year to the anniversary date
+                $anniversary_date->modify('+1 year');
+                $r['next_anniversary_date'] = $anniversary_date->format('m-d-Y');
+            }
+        }
         return $r;
     }
 
index bc75fd3..652bf1e 100644 (file)
                         Member Account
                     </div>
                     <div class="glm-columns glm-small-12 glm-large-9">
-                        <select name="account" required>
+                        <select id="member-account" name="account" required>
                             <option value="">Select an Account</option>
                             {foreach $accounts as $account}
-                                <option value="{$account.id}">{$account.ref_name}</option>
+                            <option value="{$account.id}" data-anniversary="{$account.next_anniversary_date}">{$account.ref_name}</option>
                             {/foreach}
                         </select>
                     </div>
@@ -36,7 +36,7 @@
                         Due Date
                     </div>
                     <div class="glm-columns glm-small-12 glm-large-9">
-                        <input type="text" name="due_date" required>
+                        <input id="invoice_due_date" type="text" name="due_date" required>
                     </div>
                 </div>
                 <div class="glm-row">
@@ -266,6 +266,13 @@ jQuery(document).ready(function($){
     // Setup the date picker for the input field with the name due_date
     $('input[name="due_date"]').datepicker();
 
+    /**
+     * Change event listener for member account select.
+     */
+    $('#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);