From: Steve Sutton Date: Wed, 7 Mar 2018 19:56:03 +0000 (-0500) Subject: DB Update, work on add invoice page. X-Git-Tag: v1.0.0^2~163 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=bd50651ff0b92783579559fdc196de5d6beeb6a3;p=WP-Plugins%2Fglm-member-db-billing.git DB Update, work on add invoice page. Update db table line_item. - Add three date fields Working on being able to delete a line item once on the add invoice form. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 534ecce..ec82396 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -129,6 +129,7 @@ class GlmBillingSupport } } } + public function createPayment( $account, $payment ) { // Insert the payment @@ -439,7 +440,7 @@ class GlmBillingSupport * Get all unpaid invoices given an account id. * * @param mixed $account Id of the account. - * + * * @access public * @return array */ @@ -606,7 +607,6 @@ class GlmBillingSupport return $line_items; } - /** * Merge template and data to produce HTML * diff --git a/classes/data/dataAccounts.php b/classes/data/dataAccounts.php index ab2977e..763ce68 100644 --- a/classes/data/dataAccounts.php +++ b/classes/data/dataAccounts.php @@ -267,7 +267,7 @@ class GlmDataAccounts extends GlmDataAbstract } else { // Add one year to the anniversary date $anniversary_date->modify('+1 year'); - $r['next_anniversary_date'] = $anniversary_date->format('m-d-Y'); + $r['next_anniversary_date'] = $anniversary_date->format('m/d/Y'); } } return $r; diff --git a/index.php b/index.php index 8d0c8f7..6d7b784 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.10'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.11'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 9bda0b7..3046426 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -172,6 +172,8 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices break; case 'insert': + // Get Data Class for Invoice Types + $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); // Set transaction_time to current time. $_REQUEST['transaction_time'] = date('Y-m-d H:i:s'); $_REQUEST['due_date'] = date('Y-m-d', strtotime($_REQUEST['due_date'])); @@ -183,6 +185,9 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $line_items = $_REQUEST['line_items']; if ( is_array( $line_items ) && !empty( $line_items ) ) { foreach ( $line_items as $key => $line_item ) { + // Get the invoice type + $invoiceType = $InvoiceTypesObj->getEntry( $line_item ); + // // Add individual line item record $this->wpdb->insert( GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items', @@ -193,6 +198,9 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'amount' => $_REQUEST['line_item_amount'][$line_item], 'quantity' => $_REQUEST['line_item_qty'][$line_item], 'total' => (float)$_REQUEST['line_item_qty'][$line_item] * (float)$_REQUEST['line_item_amount'][$line_item], + 'created' => date('Y-m-d'), + 'first_due_date' => $_REQUEST['due_date'], + 'next_due_date' => $_REQUEST['due_date'], ), array( '%d', @@ -200,7 +208,10 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices '%s', '%s', '%d', - '%d' + '%d', + '%s', + '%s', + '%s', ) ); } diff --git a/setup/databaseScripts/create_database_V0.0.10.sql b/setup/databaseScripts/create_database_V0.0.10.sql index 729ef67..e4ca9cf 100644 --- a/setup/databaseScripts/create_database_V0.0.10.sql +++ b/setup/databaseScripts/create_database_V0.0.10.sql @@ -86,6 +86,9 @@ CREATE TABLE {prefix}line_items ( total DECIMAL(8,2) DEFAULT '0.00', -- line item total recurring BOOLEAN DEFAULT '0', -- true/false if recurring recurrence INT NULL DEFAULT 0, -- recurrence type + created DATE NULL, -- Date this line item was first created + first_due_date DATE NULL, -- The first due date for this item + next_due_date DATE NULL, -- Next Due Date for this item PRIMARY KEY (id) ); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 4a7b504..9db6ea9 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -24,5 +24,6 @@ $glmMembersBillingDbVersions = array( '0.0.8' => array('version' => '0.0.8', 'tables' => 14), '0.0.9' => array('version' => '0.0.9', 'tables' => 14), '0.0.10' => array('version' => '0.0.10', 'tables' => 14), + '0.0.11' => array('version' => '0.0.11', 'tables' => 14), ); diff --git a/setup/databaseScripts/update_database_V0.0.11.sql b/setup/databaseScripts/update_database_V0.0.11.sql new file mode 100644 index 0000000..423c9a7 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.11.sql @@ -0,0 +1,20 @@ +-- Gaslight Media Billing Database +-- File Created: 03/07/2018 +-- Database Version: 0.0.11 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Add created to line_items +ALTER TABLE {prefix}line_items ADD created DATE NULL; + +---- + +-- Add first_due_date to line_items +ALTER TABLE {prefix}line_items ADD first_due_date DATE NULL; + +---- + +-- Add next_due_date to line_items +ALTER TABLE {prefix}line_items ADD next_due_date DATE NULL; + diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index ef8c37e..3f2fc3e 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -8,7 +8,7 @@ {if $invoiceAdded}Notification Added{/if}
-
+ {if $invoice_id} @@ -58,7 +58,10 @@
-
Total Amount:   
+
+ Total Amount:    + +
$0.00
@@ -147,7 +150,7 @@ Invoice Type - {$parent = 0} {foreach $invoiceTypes as $inv} @@ -155,7 +158,7 @@ {/if} {if $inv.amount != '0.00'} - + {/if} {if $inv.parent.value == 0} @@ -163,6 +166,7 @@ {/foreach} +

@@ -174,7 +178,12 @@ jQuery(document).ready(function($){ // List of Billing Accounts. var availableAccounts = [ {foreach $accounts as $m} - { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' }, + { + label: "{$m.ref_name|unescape:'html'|replace:'"':''}", + value: "{$m.ref_name|unescape:'html'|replace:'"':''}", + id: '{$m.id}', + anniversary: '{$m.next_anniversary_date}' + }, {/foreach} ]; @@ -193,6 +202,8 @@ 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. @@ -253,6 +264,7 @@ jQuery(document).ready(function($){ totalAmount += parseFloat( line_items[i].amount ) * line_items[i].qty; } $('#invoice-total').html('$' + totalAmount.toFixed( 2 ) ); + $('#invoice-total-amount').val( totalAmount.toFixed( 2 ) ); } /** @@ -296,9 +308,10 @@ jQuery(document).ready(function($){ selectedLineItem.qty = parseInt(1); line_items.push( selectedLineItem ); $( '#invoice-line-items' ). append( '
' + - '
' + selectedLineItem.name + '
' + + '
' + + '
' + selectedLineItem.name + '
' + '
' + - '' + + '' + '
' + '' + '' + @@ -310,12 +323,31 @@ jQuery(document).ready(function($){ selectedLineItem.qty++; $('input[name="line_item_qty\\[' + selectedLineItem.id + '\\]').val(selectedLineItem.qty); } + $('#line_item_price').html( '' ); dialog.dialog( 'close' ); } totalInvoice(); return valid; } + // Add the price to the right of the new selection for add line item. + $('#line_item_type').change(function(){ + $('#line_item_price').html( '$' + $('#line_item_type option:selected').data( 'price') ); + }); + + // Here we delete a line_item from the form. + $('body').on( 'click', '.line-item-delete', function(){ + $('#line-item-type-' + $(this).data( 'id' ) ).remove(); + // Need to remove from line_items also. + // Loop through the line_items and remove the one with matching id. + for ( i = 0; i < line_items.length; i++ ) { + if ( line_items[i].id == $(this).data('id') ) { + line_items.splice( i, 1 ); + } + } + totalInvoice(); + } ); + /** * addNewAccount * @@ -399,31 +431,6 @@ jQuery(document).ready(function($){ }, 500); } - /** - * Ajax call to get the list of billing accounts and update the select - * for the Billing account drop down. - */ - // function updateBillingAccountSelect(selected_id = null) { - // $.ajax({ - // url: '{$ajaxUrl}', - // cache: false, - // type: 'GET', - // data: 'action=glm_members_admin_ajax&glm_action=account&option=list', - // encode: true, - // dataType: 'json' - // }).done(function(msg){ - // // console.log( msg.length ); - // var memberAccount = document.getElementById('member-account'); - // memberAccount.options.length = 0; - // memberAccount.options[memberAccount.options.length] = new Option( 'Select an Account', '' ); - // for ( index in msg ) { - // var obj = msg[index]; - // memberAccount.options[memberAccount.options.length] = new Option( obj.ref_name, obj.id ); - // } - // memberAccount.value = selected_id; - // }); - // } - /** * Ajax call to get the list of members with accounts. * Updating the account list used for the autocomplete. @@ -490,6 +497,7 @@ jQuery(document).ready(function($){ buttons: { "Add Line Item": addLineItem, Cancel: function(){ + $('#line_item_price').html( '' ); dialog.dialog( 'close' ); }, }, @@ -510,6 +518,20 @@ jQuery(document).ready(function($){ addLineItem(); }); + // Need to make sure something is added to the form. + // Should not be making empty invoices. + $('#create-invoice-form').submit(function(e){ + // Check if there's a total amount. + // If it is empty then don't submit form. + if ( !$('#invoice-total-amount').val() || $('#invoice-total-amount').val() == '0.00' ) { + alert( 'Empty invoice. Please add something!' ); + return false; + } else { + return true; + } + return false; + }); + /** * Click event for the id of #newLineItemButton. * @@ -590,13 +612,6 @@ jQuery(document).ready(function($){ $('#invoice_due_date').val( $(this).find('option:selected').data('anniversary') ); }); - /** - * Update the member name field when you select a member from the add account form. - */ - $('#non-member-account').change(function(){ - $('#glm_member_name').val( $(this).find('option:selected').text() ); - }); - // 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);