wip for discount
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Apr 2019 20:54:02 +0000 (16:54 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Apr 2019 20:54:02 +0000 (16:54 -0400)
Adding script to do discount price on invoice.

views/admin/billing/editInvoice.html

index 2029ca5..58e2e46 100644 (file)
@@ -59,6 +59,7 @@
             <div class="glm-columns glm-small-12 glm-large-2">
                 <a id="newLineItemButton" class="glm-billing-add-line-item">Add Line Item</a><br>
                 <a id="newCustomLineItemButton" class="glm-billing-add-line-item">Create New Line Item</a>
+                <a id="newDiscountLineItemButton" class="glm-billing-add-line-item">Add Discount</a>
             </div>
             <div class="glm-columns glm-small-12 glm-large-10" id="invoice-line-items">
             </div>
         </tr>
     </table>
 </div>
+{* Add Discount Form *}
+<div id="newDiscountLineItemDialog" class="glm-dialog-box" title="Add Discount">
+    <p class="validateCustomTips glm-required">* Required!</p>
+    <table>
+        <tr>
+            <th class="glm-required" align="right">Discount Amount <br> Numbers only (999.99)</th>
+            <td><input name="discount_amount" /></td>
+        </tr>
+    </table>
+</div>
 
 <script>
 jQuery(document).ready(function($){
@@ -316,6 +327,7 @@ jQuery(document).ready(function($){
     var dialog,                                                // Dialog for the add line_item form
         newAccountDialog,                                      // Dialog for the add new account
         customLineItemDialog,                                  // Dialog for the custom line item
+        discountLineItemDialog,                                // Dialog for Discount line item
         form,                                                  // The add line_item form
         newAccountForm,                                        // New Account Form
         line_item_type    = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form
@@ -340,6 +352,7 @@ jQuery(document).ready(function($){
         billing_zip       = $( 'input[name="billing_zip"' ),
         billing_phone     = $( 'input[name="billing_phone"' ),
         customFieldName   = $( 'input[name="cf_name"]' ),
+        discountAmount    = $( 'input[name="discount_amount"]' ),
         customFieldAmount = $( 'input[name="cf_amount"]' ),
         customFieldParent = $( 'select[name="cf_parent"]' ),
         lineTips          = $( '.validateTips' ),
@@ -454,6 +467,14 @@ jQuery(document).ready(function($){
         '</div>');
     }
 
+    /**
+     * Add discount line item to invoice
+     */
+    function addDiscountToInvoice( discount )
+    {
+        lineItem.qty = parseInt(1);
+    }
+
     // Setup if doing edit
     {if $invoice_id && isset($lineItems)}
         {foreach $lineItems as $item}
@@ -721,6 +742,27 @@ jQuery(document).ready(function($){
         },
     });
 
+    /**
+     * dialog for discount line item
+     */
+    discountLineItemDialog = $('#newDiscountLineItemDialog').dialog({
+        autoOpen: false,
+        minWidth: 550,
+        dialogClass: 'glm-dialog-no-close',
+        modal: true,
+        buttons: {
+            "Add Discount Line Item": addDiscountLineItem,
+            Cancel: function(){
+                discountLineItemDialog.dialog( 'close' );
+            },
+        },
+        close: function(){
+            discountAmount.val('');
+            allCustomFields.removeClass( 'ui-state-error' );
+            updateTips( customTips, '* required!' );
+        },
+    });
+
     /**
      * Custom Line Item form callback.
      *
@@ -771,6 +813,25 @@ jQuery(document).ready(function($){
         return valid;
     }
 
+    function addDiscountLineItem()
+    {
+        // Need to validate the form
+        var valid = true;
+
+        // Clear allCustomFields
+        allCustomFields.removeClass( 'ui-state-error' );
+
+        // Check fields for a value.
+        valid = valid && checkRequired( discountAmount, customTips, 'Amount is required!' );
+
+        if ( valid ) {
+            addDiscountToInvoice();
+            dialog.dialog( 'close' );
+        }
+
+        return valid;
+    }
+
     /**
      * form
      *
@@ -817,6 +878,11 @@ jQuery(document).ready(function($){
         return false;
     });
 
+    $('#newDiscountLineItemButton').click( function(){
+        $('#newDiscountLineItemDialog').dialog( 'open' );
+        return false;
+    });
+
     /**
      * dialog for the New Account Form
      */