Update for database and dashboard
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 17 Apr 2019 20:09:39 +0000 (16:09 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 17 Apr 2019 20:09:39 +0000 (16:09 -0400)
Adding options for the main billing dashboard.
New dashboard list of accounts that have overdue invoices.
Adding invoice number search on invoices tab.
Fix issue with payment form to get the card type with test card.

16 files changed:
classes/billingSupport.php
classes/data/dataInvoices.php
classes/data/dataManagement.php
index.php
models/admin/billing/index.php
models/admin/billing/invoices.php
models/admin/dashboard/billing.php
setup/databaseScripts/create_database_V0.0.38.sql [deleted file]
setup/databaseScripts/create_database_V0.0.39.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.38.sql
setup/databaseScripts/update_database_V0.0.39.sql [new file with mode: 0644]
views/admin/billing/index.html
views/admin/billing/invoices.html
views/admin/management/billing.html
views/common/billing/paymentForm.html

index 6f14d2d..fd6878b 100644 (file)
@@ -1360,7 +1360,7 @@ class GlmBillingSupport
         // If we need to check for proper credit card data
         if ($checkCC) {
             // Check all credit card input
-            if ( $cardData['cc_type'] && $cardData['cc_type'] > 0
+            if ( $cardData['cc_type'] && $cardData['cc_type'] != ''
                 && $cardData['cc_name'] && $cardData['cc_name'] != ''
                 && $cardData['cc_numb'] && $cardData['cc_numb'] > 0
                 && $cardData['cc_exp'] && $cardData['cc_exp'] != ''
@@ -1553,7 +1553,7 @@ class GlmBillingSupport
                 $lastFour  = '';
                 if ( isset( $_REQUEST['cc_type'] ) && $_REQUEST['cc_type'] ) {
                     // need to know number to card type
-                    $cardBrand = $_REQUEST['cc_type'];
+                    $cardBrand = $this->config['credit_card'][$_REQUEST['cc_type']];
                 }
                 if ( isset( $_REQUEST['cc_numb'] ) && $_REQUEST['cc_numb'] ) {
                     // Get last four numbers
index 39382c7..0eeddca 100644 (file)
@@ -277,5 +277,29 @@ class GlmDataInvoices extends GlmDataAbstract
         );
     }
 
+    public function getSimpleInvoiceList(
+        $where = '',
+        $order = '',
+        $fieldVals = true,
+        $idField = 'id',
+        $start = false,
+        $limit = false
+    ) {
+        // Save the current fields array and make a copy
+        $fSave = $this->fields;
+
+        // Remove what we don't want from the copy and get the list
+        $this->fields = array(
+            'id'   => $fSave['id'],
+            'name' => $fSave['ref_name'],
+        );
+
+        $invoiceList = $this->getList($where, $order, $fieldVals, $idField, $start, $limit);
+
+        // Restore the fields list
+        $this->fields = $fSave;
+
+        return $invoiceList;
+    }
 
 }
index be74e04..0fe6be6 100644 (file)
@@ -283,6 +283,30 @@ class GlmDataBillingManagement extends GlmDataAbstract
                 'default' => 0,
             ),
 
+            // Show pending renewals
+            'dashboard_pending_renewals' => array (
+                'field'   => 'dashboard_pending_renewals',
+                'type'    => 'checkbox',
+                'use'     => 'a',
+                'default' => 0,
+            ),
+
+            // Show overdue renewals
+            'dashboard_overdue_renewals' => array (
+                'field'   => 'dashboard_overdue_renewals',
+                'type'    => 'checkbox',
+                'use'     => 'a',
+                'default' => 0,
+            ),
+
+            // Show overdue invoices
+            'dashboard_overdue_invoices' => array (
+                'field'   => 'dashboard_overdue_invoices',
+                'type'    => 'checkbox',
+                'use'     => 'a',
+                'default' => 0,
+            ),
+
         );
 
     }
index 8a91e54..bca4230 100644 (file)
--- a/index.php
+++ b/index.php
@@ -38,7 +38,7 @@
  *  version from this plugin.
  */
 define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.26');
-define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.38');
+define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.39');
 
 // 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');
index 53e5e0c..f20ddc4 100644 (file)
@@ -183,105 +183,75 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts
         }
 
         switch ( $option ) {
-        // case 'account':
-        //     require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
-        //     $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
-        //
-        //     // Check to see if we're adding an account or editing one.
-        //     if ( isset( $_REQUEST['ref_name'] ) ) {
-        //         $_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date']));
-        //         // if there's no id then add account
-        //         if ( !isset( $_REQUEST['id'] ) ) {
-        //             $account = $Accounts->insertEntry();
-        //             if ( !$account['status'] ) {
-        //                 $accountInsertError = true;
-        //             } else {
-        //                 $accountAdded = true;
-        //             }
-        //         } else {
-        //             $account = $Accounts->updateEntry( $_REQUEST['id'] );
-        //             if ( !$account['status'] ) {
-        //                 $accountUpdateError = true;
-        //             } else {
-        //                 $accountUpdated = true;
-        //             }
-        //         }
-        //     }
-        //
-        //     // Need to see if there's an account for this member.
-        //     $accountID = $this->wpdb->get_var(
-        //         $this->wpdb->prepare(
-        //             "SELECT id
-        //                FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
-        //               WHERE ref_dest = %d",
-        //             $this->memberID
-        //         )
-        //     );
-        //     if ( !$account ) {
-        //         if ( $accountID ) {
-        //             $account     = $Accounts->editEntry( $accountID );
-        //             $haveAccount = true;
-        //         } else {
-        //             $accountID   = 0;
-        //             $account     = $Accounts->newEntry();
-        //             // Set the ref_name from memberData
-        //             $account['fieldData']['ref_name'] = $memberData['name'];
-        //             $haveAccount = false;
-        //         }
-        //     } else {
-        //         $haveAccount = true;
-        //         // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
-        //     }
-        //
-        //     // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
-        //     $view = 'editAccount';
-        //     break;
         case 'list':
-            // Dash board list should be getting list of members Accounts. (based on renewal_date)
-            // Expired
-            // Pass Due
-            // Pending
-            // Active
-            // Get list of pending invoices ( not overdue )
+            // Dashboard could show invoices or accounts.
+            //   Overdue invoices
+            // MiGCSA shows accounts (based on renewal_date)
+            //   Expired
+            //   Pass Due
+            //   Pending
+            //   Active
+
+            //   Get list of pending renewals ( not overdue )
             $days_before_renewal = $this->config['settings']['days_before_renewal'];
             $days_after_expired  = $this->config['settings']['days_after_expired'];
             $orderBy             = 'renewal_date ASC';
             $curDate             = date( 'Y-m-d' );
-            $pendingWhere        = "T.archived <> true AND invoice_type != 0 ";
-            $pendingWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR - INTERVAL $days_before_renewal DAY  <= '$curDate'" ;
-            $pendingWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY >= '$curDate'";
-            $start               = 1;
-            $this->postEmployees = true;
-            $pending             = $this->getList( $pendingWhere, $orderBy, true, 'id', $start, $limit );
-            $this->postEmployees = false;
-            // echo '<pre>$pending: ' . print_r( $pending, true ) . '</pre>';
-            $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 );
-
-            // Get the number of over due invoices
-            $overDueWhere        = "T.archived <> true AND invoice_type != 0";
-            $overDueWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'";
-            $start               = 1;
-            $this->postEmployees = true;
-            $overdue             = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit );
-            $this->postEmployees = false;
-            if ( isset( $overdue['returned'] ) ) {
-                $numberOverdue = $overdue['returned'];
-            }
 
             // Get list of accounts for autocomplete
             $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
             $accounts = $Accounts->getSimpleAccountList();
 
-            $dashboards = array(
-                'Pending Accounts' => array(
+            $dashboards = array();
+            if ( $this->config['billing_settings']['dashboard_pending_renewals'] ) {
+                $pendingWhere        = "T.archived <> true AND invoice_type != 0 ";
+                $pendingWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR - INTERVAL $days_before_renewal DAY  <= '$curDate'" ;
+                $pendingWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY >= '$curDate'";
+                $start               = 1;
+                $this->postEmployees = true;
+                $pending             = $this->getList( $pendingWhere, $orderBy, true, 'id', $start, $limit );
+                $this->postEmployees = false;
+                $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 );
+                $dashboards['Accounts with Pending Renewals'] = array(
                     'number' => $numberPending,
                     'data'   => $pending,
-                ),
-                'Overdue Accounts' => array(
+                );
+            }
+            if ( $this->config['billing_settings']['dashboard_overdue_renewals'] ) {
+                // Get the number of over due renewals
+                $overDueWhere        = "T.archived <> true AND invoice_type != 0";
+                $overDueWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'";
+                $start               = 1;
+                $this->postEmployees = true;
+                $overdue             = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit );
+                $this->postEmployees = false;
+                $numberOverdue = ( isset( $overdue['returned'] ) ? $overdue['returned'] : 0 );
+                $dashboards['Accounts with Overdue Renewals'] = array(
                     'number' => $numberOverdue,
                     'data'   => $overdue,
-                )
-            );
+                );
+            }
+            if ( $this->config['billing_settings']['dashboard_overdue_invoices'] ) {
+                // Get the number of over due renewals
+                $overDueWhere        = "T.archived <> true AND invoice_type != 0";
+                // $overDueWhere       .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'";
+                $overDueWhere       .= " AND T.id IN (
+                    SELECT account
+                      FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+                     WHERE due_date < '$curDate'
+                       AND ( paid <> true OR paid IS NULL )
+                )";
+                $start               = 1;
+                $this->postEmployees = true;
+                $overdue             = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit );
+                $this->postEmployees = false;
+                $numberOverdue = ( isset( $overdue['returned'] ) ? $overdue['returned'] : 0 );
+                $dashboards['Accounts with Overdue Invoices'] = array(
+                    'number' => $numberOverdue,
+                    'data'   => $overdue,
+                );
+            }
+
 
             break;
         default:
@@ -316,7 +286,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts
             'toDate'             => $toDate,
             'haveInvoices'       => $haveInvoices,
             'accounts'           => $accounts,
-            'allAccounts'           => $accounts,
+            'allAccounts'        => $accounts,
             'filterAccounts'     => $filterAccounts,
             'totalInvoices'      => $totalInvoices,
             'filterPending'      => $filterPending,
@@ -326,7 +296,6 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts
             'filterArchived'     => $filterArchived,
             'searchName'         => $searchName,
         );
-        // echo '<pre>$templateData: ' . print_r( $templateData, true ) . '</pre>';
 
         // Return status, any suggested view, and any data to controller
         return array(
index eebe5eb..55fd69b 100644 (file)
@@ -120,12 +120,13 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
         $invoiceTypes       = false;
         $invoiceTypeJSON    = '';
         $accounts           = false;
+        $invoices           = false;
         $billingAccount     = false;
         $nonAccountMembers  = false;
         $invoiceHtml        = '';
         $fromDate           = '';
         $toDate             = '';
-        $invoices           = false;
+        $invoiceList        = false;
         $fromMemberMenu     = false;
         $filterAccounts     = '';
         $totalInvoices      = false;
@@ -186,7 +187,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             if ( isset( $_REQUEST['id'] ) ) {
                 $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
                 $this->invoice_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
-                $invoices         = $this->editEntry( $this->invoice_id );
+                $nvoices         = $this->editEntry( $this->invoice_id );
                 // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
                 $view            = 'editInvoice';
                 $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
@@ -478,14 +479,14 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
                     // Here we're going to generate the invoice total.
                     $totals = $this->generateInvoiceTotal( $this->invoice_id );
                     // echo '<pre>' . print_r( $totals, true ) . '</pre>';
-                    // Now we have a total for the invoice we can record the transaction
+                    // Now we have a total for the invoice we can record the transaction.
                     $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
                     // Calling the support class to save the invoice to transaction table.
-                    // Reset for the edit form
+                    // Reset for the edit form.
                     $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
                     $invoiceTypes    = $InvoiceTypesObj->getList();
                     $lineItems       = $BillingSupport->getLineItemsForInvoice( $this->invoice_id );
-                    // Sort the types by parent child
+                    // Sort the types by parent child.
                     $invoiceTypes    = $InvoiceTypesObj->sortParentChild($invoiceTypes);
                     if ( isset( $invoiceTypes ) ) {
                         foreach ( $invoiceTypes as $invoiceType ) {
@@ -585,10 +586,15 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
         case 'list':
         default:
 
+        // echo '<pre>'.print_r( $_REQUEST, true ).'</pre>';
             // Need to get the accounts
             $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
             $accounts = $Accounts->getSimpleAccountList();
 
+            // Get list of invoices for invoice # search
+            $Invoices    = new GlmDataInvoices( $this->wpdb, $this->config );
+            $invoiceList = $Invoices->getSimpleInvoiceList();
+
             $where_params = array( 'true' );
 
             // Check if we're doing paging
@@ -648,6 +654,18 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
                     $where_params[] = "T.paid <> true";
                 }
             }
+            if ( isset( $_REQUEST['filterInvoice'] ) && $_REQUEST['filterInvoice'] ) {
+                $filterInvoice = filter_var( $_REQUEST['filterInvoice'], FILTER_VALIDATE_INT );
+                if ( $filterInvoice ) {
+                    $where_params[] = "T.id = $filterInvoice";
+                }
+            }
+            if ( isset( $_REQUEST['searchInvoice'] ) && $_REQUEST['searchInvoice'] ) {
+                $searchInvoice = filter_var( $_REQUEST['searchInvoice'], FILTER_VALIDATE_INT );
+                if ( $searchInvoice ) {
+                    $where_params[] = "T.id = $searchInvoice";
+                }
+            }
             if ( isset( $_REQUEST['filterPending'] ) ) {
                 $filterPending = filter_var( $_REQUEST['filterPending'], FILTER_VALIDATE_BOOLEAN );
                 $where_params[] = "T.paid <> true";
@@ -726,6 +744,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             'lineItemJSON'        => $lineItemJSON,
             'invoiceTypes'        => $invoiceTypes,
             'accounts'            => $accounts,
+            'invoiceList'         => $invoiceList,
             'billingAccount'      => $billingAccount,
             'invoiceHtml'         => $invoiceHtml,
             'fromDate'            => $fromDate,
index b7e8aa9..6870f50 100644 (file)
@@ -21,7 +21,7 @@
  * Each Add-On can have one or more dashboards.
  */
 
-class GlmMembersAdmin_dashboard_billing //extends GlmDataBilling
+class GlmMembersAdmin_dashboard_billing
 {
     /**
      * Word Press Database Object
diff --git a/setup/databaseScripts/create_database_V0.0.38.sql b/setup/databaseScripts/create_database_V0.0.38.sql
deleted file mode 100644 (file)
index 64e88cf..0000000
+++ /dev/null
@@ -1,386 +0,0 @@
--- Gaslight Media Billing Module
--- File Created: 02/19/2019
--- Database Version: 0.0.37
--- Database Creation Script
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
---
--- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES ****
---
-
--- Billing Accounts
-CREATE TABLE {prefix}accounts (
-    id INT NOT NULL AUTO_INCREMENT,
-    archived BOOLEAN DEFAULT '0',                          -- Marks account as archived
-    ref_dest INT NOT NULL,                                 -- reference to member id
-    ref_name TINYTEXT NOT NULL,                            -- Name of reference member
-    invoice_type INT NOT NULL DEFAULT '0',                 -- Ref to Invoice Type id
-    billing_contact_name TINYTEXT NULL,                    -- Billing Contact Name
-    billing_fname TINYTEXT NULL,                           -- Billing First Name
-    billing_lname TINYTEXT NULL,                           -- Billing Last Name
-    billing_company TINYTEXT NULL,                         -- Billing Company Name
-    billing_position TINYTEXT NULL,                        -- Billing Title/Position
-    billing_addr1 TINYTEXT NULL,                           -- Billing Address 1
-    billing_addr2 TINYTEXT NULL,                           -- Billing Address 2
-    billing_city TINYTEXT NULL,                            -- Billing City
-    billing_county INT NULL,                               -- Billing County
-    billing_state TINYTEXT NULL,                           -- Billing State
-    billing_zip TINYTEXT NULL,                             -- Billing Zip
-    billing_country TINYTEXT NULL,                         -- Billing Country
-    billing_phone TINYTEXT NULL,                           -- Billing Phone
-    billing_fax TINYTEXT NULL,                             -- Billing Fax
-    anniversary_date DATE NULL,                            -- anniversary date
-    renewal_date DATE NULL,                                -- renewal date of account
-    payment_data TEXT NULL,                                -- stored payment data
-    customer_profile_id TINYTEXT NULL,                     -- Customer Profile Id (Authorize.net)
-    payment_profile_id TINYTEXT NULL,                      -- Payment Profile Id (Authorize.net)
-    payment_profile_card TINYTEXT NULL,                    -- Payment Profile Card (Authorize.net)
-    email TINYTEXT NULL,                                   -- billing email
-    boss BOOLEAN DEFAULT '0',                              -- Boss flag
-    account_number TINYTEXT NULL,                          -- Account Number
-    email_invoice BOOLEAN DEFAULT '0',                     -- Invoice by email
-    usmail_invoice BOOLEAN DEFAULT '0',                    -- Invoice by US Mail
-    fax_invoice BOOLEAN DEFAULT '0',                       -- Invoice by Fax
-    PRIMARY KEY (id),
-    INDEX(ref_dest),
-    INDEX(ref_name(20)),
-    INDEX(email(20)),
-    INDEX(invoice_type),
-    INDEX(renewal_date),
-    INDEX(billing_county)
-);
-
-----
-
--- transactions
-CREATE TABLE {prefix}transactions (
-    id INT NOT NULL AUTO_INCREMENT,
-    type INT NOT NULL,                                     -- type of transaction (payment,invoice,etc)
-    type_id INT NOT NULL,                                  -- reference to type id
-    account INT NOT NULL,                                  -- reference to account id
-    transaction_time DATETIME NOT NULL,                    -- datetime for the transaction
-    current_invoice_total DECIMAL(8, 2) NOT NULL,          -- invoice total
-    current_payment_total DECIMAL(8, 2) NOT NULL,          -- payment total
-    PRIMARY KEY (id),
-    INDEX(account),
-    INDEX(type_id),
-    INDEX(transaction_time)
-);
-
-----
-
--- Invoices
-CREATE TABLE {prefix}invoices (
-    id INT NOT NULL AUTO_INCREMENT,
-    old_invoice_id INT NULL,                               -- old invoice id from uptra
-    transaction_time DATETIME NOT NULL,                    -- datetime for the invoice
-    account INT NOT NULL,                                  -- ref to account id
-    amount_total DECIMAL(8, 2) NOT NULL,                   -- total amount for invoice
-    balance DECIMAL(8, 2) NOT NULL,                        -- balance for this invoice
-    due_date DATE NOT NULL,                                -- Due date for this invoice
-    paid BOOLEAN DEFAULT '0',                              -- true/false if invoice is paid
-    notes TINYTEXT,                                        -- notes for this invoice
-    renewal BOOLEAN DEFAULT '0',                           -- true/false if a renewal
-    recurring BOOLEAN DEFAULT '0',                         -- true/false if recurring
-    recurrence INT NULL DEFAULT 0,                         -- recurrence type
-    PRIMARY KEY (id),
-    INDEX(account),
-    INDEX(transaction_time),
-    INDEX(due_date)
-);
-
-----
-
--- Line Item Types
-CREATE TABLE {prefix}invoice_types (
-    id INT NOT NULL AUTO_INCREMENT,
-    name TINYTEXT NOT NULL,                                -- name
-    parent INT NOT NULL DEFAULT 0,                         -- 0 if top level otherwise ref to another line_item_type as it's parent
-    member_type INT NOT NULL DEFAULT 0,                    -- Member Type assigned Default 0
-    amount DECIMAL(8,2) NOT NULL DEFAULT '0.00',           -- amount
-    recurring BOOLEAN DEFAULT '0',                         -- true/false if recurring
-    recurrence INT NULL DEFAULT 0,                         -- recurrence type
-    dynamic_amount BOOLEAN DEFAULT '0',                    -- true/false if amount is dynamic
-    qcode TINYTEXT NULL,                                   -- qcode for quickbooks
-    category TINYTEXT NULL,                                -- quickbooks category
-    PRIMARY KEY (id)
-);
-
-----
-
--- Line Items
-CREATE TABLE {prefix}line_items (
-    id INT NOT NULL AUTO_INCREMENT,
-    invoice INT NOT NULL,                                  -- reference to invoice
-    line_item_type INT NOT NULL,                           -- reference to line item type
-    account INT NULL DEFAULT 0,                            -- ref to account id (renewal or employee)
-    name TEXT NOT NULL,                                    -- line item name
-    amount DECIMAL(8,2) DEFAULT '0.00',                    -- line item amount per item
-    quantity INT DEFAULT 1,                                -- quantity
-    discount INT DEFAULT 0,                                -- Discount Percentage
-    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),
-    INDEX(account),
-    INDEX(created),
-    INDEX(first_due_date),
-    INDEX(next_due_date)
-);
-
-----
-
--- payments
-CREATE TABLE {prefix}payments (
-    id INT NOT NULL AUTO_INCREMENT,
-    transaction_time DATETIME NOT NULL,                    -- datetime of payment
-    account INT NOT NULL,                                  -- ref to account table
-    amount DECIMAL(8, 2) NOT NULL,                         -- payment amount
-    payment_method TINYTEXT NOT NULL,                      -- payment method
-    payment_data TINYTEXT NULL,                            -- additional payment info
-    notes TEXT NULL,                                       -- Notes/Comments on the payment
-    PRIMARY KEY (id)
-);
-
-----
-
--- pdfs
-CREATE TABLE {prefix}pdfs (
-    id INT NOT NULL AUTO_INCREMENT,
-    ref_type INT NOT NULL,                                 -- reference type
-    ref_dest INT NOT NULL,                                 -- reference types id
-    pdf MEDIUMTEXT NOT NULL,                               -- saved pdf
-    PRIMARY KEY (id)
-);
-
-----
-
--- Notification Types
-CREATE TABLE {prefix}notification_types (
-    id INT NOT NULL AUTO_INCREMENT,
-    name TINYTEXT NOT NULL,                                -- name
-    to_email TINYTEXT NULL,                                -- To email
-    from_header TINYTEXT NOT NULL,                         -- from headers
-    replyto TINYTEXT NULL,                                 -- reply-to headers
-    subject TINYTEXT NOT NULL,                             -- Subject
-    message TEXT NOT NULL,                                 -- Message
-    send_by_date BOOLEAN NULL DEFAULT '0',                 -- true/false send by date based on due date
-    send_by_action BOOLEAN NULL DEFAULT '0',               -- send notice based on an action
-    send_action INT NULL DEFAULT 0,                        -- (create invoice or receive payment)
-    send_date_number INT NULL DEFAULT 0,                   -- number to apply to send by date
-    send_date_period INT NULL DEFAULT 0,                   -- (days,weeks,months,years)
-    send_date_when INT NULL DEFAULT 0,                     -- (before or after)
-    PRIMARY KEY (id)
-);
-
-----
-
--- Notifications
-CREATE TABLE {prefix}notifications (
-    id INT NOT NULL AUTO_INCREMENT,
-    notification_type INT NOT NULL,                        -- ref to notification type
-    account INT NOT NULL,                                  -- ref to account
-    from_replyto TINYTEXT NOT NULL,                        -- from reply-to header
-    subject TEXT NOT NULL,                                 -- subject
-    message TEXT NOT NULL,                                 -- message
-    date_sent DATETIME NOT NULL,                           -- Date the notice was sent
-    email_sent TINYTEXT NOT NULL,                          -- email used
-    type INT NULL,                                         -- Invoice Type
-    type_id INT NULL,                                      -- type id (invoice or payment)
-    PRIMARY KEY (id)
-);
-
-----
-
--- Notification Queue
-CREATE TABLE {prefix}notification_queue (
-    id INT NOT NULL AUTO_INCREMENT,
-    notification_type INT NOT NULL,                        -- ref to notification type
-    account INT NOT NULL,                                  -- ref to account
-    queued_time DATETIME NOT NULL,                         -- Creation time
-    processed_time DATETIME NULL,                          -- The time this queue was processed. (sent out)
-    PRIMARY KEY (id),
-    INDEX (notification_type),
-    INDEX (account),
-    INDEX (queued_time),
-    INDEX (processed_time)
-);
-
-----
-
--- Gateway Settings
-CREATE TABLE {prefix}gateway_settings (
-    id INT NOT NULL AUTO_INCREMENT,
-    name TEXT NOT NULL,
-    login_id TINYTEXT NOT NULL,
-    transaction_key TINYTEXT NOT NULL,
-    PRIMARY KEY (id)
-);
-
-----
-
--- Invoice Payments
-CREATE TABLE {prefix}invoice_payments (
-    id INT NOT NULL AUTO_INCREMENT,
-    invoice INT NOT NULL,                                  -- reference to invoice id
-    payment INT NOT NULL,                                  -- reference to payment id
-    amount DECIMAL(8, 2) NOT NULL,                         -- payment amount
-    PRIMARY KEY (id),
-    INDEX(invoice)
-);
-
-----
-
--- Settings
-CREATE TABLE {prefix}settings (
-    id INT NOT NULL AUTO_INCREMENT,
-    -- Invoice Options
-    company_logo TINYTEXT NULL,                            -- Image logo
-    company_logo_width INT NULL,                           -- Logo Width (only used if creating pdf)
-    company_name TINYTEXT NULL,                            -- Company Name
-    company_name2 TINYTEXT NULL,                           -- Company Name 2
-    company_addr1 TINYTEXT NULL,                           -- Company Address 1
-    company_addr2 TINYTEXT NULL,                           -- Company Address 2
-    company_city TINYTEXT NULL,                            -- Company City
-    company_state TINYTEXT NULL,                           -- Company State
-    company_zip TINYTEXT NULL,                             -- Company Zip
-    company_phone TINYTEXT NULL,                           -- Company Phone
-    company_email TINYTEXT NULL,                           -- Company Email
-    company_url TINYTEXT NULL,                             -- Company URL
-    payment_terms TEXT NULL,                               -- Payment Terms
-    receipt_text TEXT NULL,                                -- Receipt Text
-    invoice_show_account_number BOOLEAN DEFAULT '0',       -- Show Billing Account number on invoices
-    invoice_show_invoice_number BOOLEAN DEFAULT '1',       -- Show Invoice Number on invoices
-    days_before_renewal INT NULL,                          -- Number of days before renewal date to allow renewals
-    days_after_expired INT NULL,                           -- Number of days after renewal date expired
-    -- Renewal Options
-    allow_membership_choice BOOLEAN DEFAULT '0',           -- If memberships can choose their membership levels when they renew
-    allow_employees BOOLEAN DEFAULT '0',                   -- If memberships have employees
-    member_types_enabled BOOLEAN DEFAULT '1',              -- member types determine invoice types
-    quickbooks_enabled BOOLEAN DEFAULT '0',                -- QuickBooks enabled
-    member_billing_enabled BOOLEAN DEFAULT '1',            -- Member have access to billing info tab
-    billing_fields_required BOOLEAN DEFAULT '1',           -- Require Billing Fields
-    invoice_methods_enabled BOOLEAN DEFAULT '0',           -- Enable Uptra invoice methods
-    renewal_day_static BOOLEAN DEFAULT '0',                -- Renewal dates are same day every year
-    renewal_day INT NULL,                                  -- Day of the month for renewals
-    renewal_month INT NULL,                                -- Month of year for renewals
-    billing_county_enabled BOOLEAN DEFAULT '0',            -- Billing uses county field
-    invoice_pdf_enabled BOOLEAN DEFAULT '0',               -- Create PDF invoices
-    billing_contact_name_enabled BOOLEAN DEFAULT '0',      -- Use billing_contact_name instead of fname lname
-    member_types_requiring_billing TEXT NULL,              -- List of member type id's that require billing
-    -- Account Number
-    account_number_enabled BOOLEAN DEFAULT '0',            -- Enable Disable account_number
-    account_number_required BOOLEAN DEFAULT '0',           -- Require account_number
-    account_number_unique BOOLEAN DEFAULT '0',             -- account_number must be unique
-    PRIMARY KEY (id)
-);
-
-----
-
--- Set default billing Settings entry
-INSERT INTO {prefix}settings
-    ( id, days_before_renewal ,days_after_expired, member_types_enabled, quickbooks_enabled, member_billing_enabled )
-    VALUES
-    ( 1, 90, 30, true, false, true );
-
-----
-
--- Management
-CREATE TABLE {prefix}management (
-    id INT NOT NULL AUTO_INCREMENT,
-    payment_methods SMALLINT NULL,                              -- Payment methods available for all registrations - Bitmap - see payment_method in plugin.ini
-    proc_methods SMALLINT NULL,                                 -- Credit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini
-    cc_accepts SMALLINT NULL,                                   -- Credit Cards Accepted - Bitmap - See credit_card in plugin.ini
-    -- Authorize.net Credentials
-    authorize_net_login TINYTEXT NULL,
-    authorize_net_key TINYTEXT NULL,
-    authorize_net_test TINYINT NULL,                            -- Authorize.net test mode - List - see proc_test_mode in plugin.ini
-    authorize_net_conf BOOLEAN NULL,                            -- Flag to send payment confirmation Email from Authorize.net
-    authorize_net_merchant_email TINYTEXT NULL,                 -- E-Mail Authorize.net will send copy of confirmation E-Mail
-    -- Merchant Solutions Credentials
-    merchant_solutions_acctid TINYTEXT NULL,                    -- Merchant Solutions credentials
-    merchant_solutions_merchantpin TINYTEXT NULL,
-    merchant_solutions_test TINYINT NULL,                       -- Merchant Solutions test mode - List - see proc_test_mode in plugin.ini
-    merchant_solutions_conf BOOLEAN NULL,                       -- Flag to send payment confirmation Email
-    merchant_solutions_merchant_email TINYTEXT NULL,            -- Merchant Solutions will send copy of confirmation E-Mail
-    -- Square Credentials
-    square_prod_access_token TINYTEXT NULL,                     -- Square production access token
-    square_prod_app_id TINYTEXT NULL,                           -- Square production application id
-    square_prod_location_id TINYTEXT NULL,                      -- Square production location id
-    square_sandbox_access_token TINYTEXT NULL,                  -- Square sandbox access token
-    square_sandbox_app_id TINYTEXT NULL,                        -- Square sandbox application id
-    square_sandbox_location_id TINYTEXT NULL,                   -- Square sandbox location id
-    square_use_prod BOOLEAN DEFAULT '0',                        -- If true use Production creds
-    -- Uptravel options
-    uptravel_invoice_template BOOLEAN DEFAULT '0',              -- Use uptravel template for invoices.
-    uptravel_payment_form BOOLEAN DEFAULT '0',                  -- Use uptravel payment form style.
-    PRIMARY KEY (id)
-);
-
-----
-
--- Set default billing Management entry
-INSERT INTO {prefix}management
-    ( id )
-    VALUES
-    ( 1 );
-
-----
-
--- Employees table
-CREATE TABLE {prefix}employees (
-    id INT NOT NULL AUTO_INCREMENT,
-    account INT NOT NULL,                                      -- Account Id
-    employee INT NOT NULL,                                     -- Employee Account Id
-    PRIMARY KEY (id)
-);
-
-----
-
--- Terms
-CREATE TABLE {prefix}settings_terms (
-    id INT NOT NULL AUTO_INCREMENT,
-    invoice_name TINYTEXT NOT NULL,
-    invoice_name_plur TINYTEXT NOT NULL,
-    invoice_name_cap TINYTEXT NOT NULL,
-    invoice_name_plur_cap TINYTEXT NOT NULL,
-    invoice_type TINYTEXT NOT NULL,
-    invoice_type_plur TINYTEXT NOT NULL,
-    invoice_type_cap TINYTEXT NOT NULL,
-    invoice_type_plur_cap TINYTEXT NOT NULL,
-    account_number TINYTEXT NOT NULL,
-    PRIMARY KEY (id)
-);
-
-----
-
-INSERT INTO {prefix}settings_terms
-    (
-    id,
-    invoice_name,
-    invoice_name_plur,
-    invoice_name_cap,
-    invoice_name_plur_cap,
-    invoice_type,
-    invoice_type_plur,
-    invoice_type_cap,
-    invoice_type_plur_cap,
-    account_number
-    )
-    VALUES
-    (
-    1,
-    'invoice',
-    'invoices',
-    'Invoice',
-    'Invoices',
-    'invoice type',
-    'invoice types',
-    'Invoice Type',
-    'Invoice Types',
-    'Account Number'
-    );
diff --git a/setup/databaseScripts/create_database_V0.0.39.sql b/setup/databaseScripts/create_database_V0.0.39.sql
new file mode 100644 (file)
index 0000000..fbbacd9
--- /dev/null
@@ -0,0 +1,390 @@
+-- Gaslight Media Billing Module
+-- File Created: 02/19/2019
+-- Database Version: 0.0.39
+-- Database Creation Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+--
+-- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES ****
+--
+
+-- Billing Accounts
+CREATE TABLE {prefix}accounts (
+    id INT NOT NULL AUTO_INCREMENT,
+    archived BOOLEAN DEFAULT '0',                          -- Marks account as archived
+    ref_dest INT NOT NULL,                                 -- reference to member id
+    ref_name TINYTEXT NOT NULL,                            -- Name of reference member
+    invoice_type INT NOT NULL DEFAULT '0',                 -- Ref to Invoice Type id
+    billing_contact_name TINYTEXT NULL,                    -- Billing Contact Name
+    billing_fname TINYTEXT NULL,                           -- Billing First Name
+    billing_lname TINYTEXT NULL,                           -- Billing Last Name
+    billing_company TINYTEXT NULL,                         -- Billing Company Name
+    billing_position TINYTEXT NULL,                        -- Billing Title/Position
+    billing_addr1 TINYTEXT NULL,                           -- Billing Address 1
+    billing_addr2 TINYTEXT NULL,                           -- Billing Address 2
+    billing_city TINYTEXT NULL,                            -- Billing City
+    billing_county INT NULL,                               -- Billing County
+    billing_state TINYTEXT NULL,                           -- Billing State
+    billing_zip TINYTEXT NULL,                             -- Billing Zip
+    billing_country TINYTEXT NULL,                         -- Billing Country
+    billing_phone TINYTEXT NULL,                           -- Billing Phone
+    billing_fax TINYTEXT NULL,                             -- Billing Fax
+    anniversary_date DATE NULL,                            -- anniversary date
+    renewal_date DATE NULL,                                -- renewal date of account
+    payment_data TEXT NULL,                                -- stored payment data
+    customer_profile_id TINYTEXT NULL,                     -- Customer Profile Id (Authorize.net)
+    payment_profile_id TINYTEXT NULL,                      -- Payment Profile Id (Authorize.net)
+    payment_profile_card TINYTEXT NULL,                    -- Payment Profile Card (Authorize.net)
+    email TINYTEXT NULL,                                   -- billing email
+    boss BOOLEAN DEFAULT '0',                              -- Boss flag
+    account_number TINYTEXT NULL,                          -- Account Number
+    email_invoice BOOLEAN DEFAULT '0',                     -- Invoice by email
+    usmail_invoice BOOLEAN DEFAULT '0',                    -- Invoice by US Mail
+    fax_invoice BOOLEAN DEFAULT '0',                       -- Invoice by Fax
+    PRIMARY KEY (id),
+    INDEX(ref_dest),
+    INDEX(ref_name(20)),
+    INDEX(email(20)),
+    INDEX(invoice_type),
+    INDEX(renewal_date),
+    INDEX(billing_county)
+);
+
+----
+
+-- transactions
+CREATE TABLE {prefix}transactions (
+    id INT NOT NULL AUTO_INCREMENT,
+    type INT NOT NULL,                                     -- type of transaction (payment,invoice,etc)
+    type_id INT NOT NULL,                                  -- reference to type id
+    account INT NOT NULL,                                  -- reference to account id
+    transaction_time DATETIME NOT NULL,                    -- datetime for the transaction
+    current_invoice_total DECIMAL(8, 2) NOT NULL,          -- invoice total
+    current_payment_total DECIMAL(8, 2) NOT NULL,          -- payment total
+    PRIMARY KEY (id),
+    INDEX(account),
+    INDEX(type_id),
+    INDEX(transaction_time)
+);
+
+----
+
+-- Invoices
+CREATE TABLE {prefix}invoices (
+    id INT NOT NULL AUTO_INCREMENT,
+    old_invoice_id INT NULL,                               -- old invoice id from uptra
+    transaction_time DATETIME NOT NULL,                    -- datetime for the invoice
+    account INT NOT NULL,                                  -- ref to account id
+    amount_total DECIMAL(8, 2) NOT NULL,                   -- total amount for invoice
+    balance DECIMAL(8, 2) NOT NULL,                        -- balance for this invoice
+    due_date DATE NOT NULL,                                -- Due date for this invoice
+    paid BOOLEAN DEFAULT '0',                              -- true/false if invoice is paid
+    notes TINYTEXT,                                        -- notes for this invoice
+    renewal BOOLEAN DEFAULT '0',                           -- true/false if a renewal
+    recurring BOOLEAN DEFAULT '0',                         -- true/false if recurring
+    recurrence INT NULL DEFAULT 0,                         -- recurrence type
+    PRIMARY KEY (id),
+    INDEX(account),
+    INDEX(transaction_time),
+    INDEX(due_date)
+);
+
+----
+
+-- Line Item Types
+CREATE TABLE {prefix}invoice_types (
+    id INT NOT NULL AUTO_INCREMENT,
+    name TINYTEXT NOT NULL,                                -- name
+    parent INT NOT NULL DEFAULT 0,                         -- 0 if top level otherwise ref to another line_item_type as it's parent
+    member_type INT NOT NULL DEFAULT 0,                    -- Member Type assigned Default 0
+    amount DECIMAL(8,2) NOT NULL DEFAULT '0.00',           -- amount
+    recurring BOOLEAN DEFAULT '0',                         -- true/false if recurring
+    recurrence INT NULL DEFAULT 0,                         -- recurrence type
+    dynamic_amount BOOLEAN DEFAULT '0',                    -- true/false if amount is dynamic
+    qcode TINYTEXT NULL,                                   -- qcode for quickbooks
+    category TINYTEXT NULL,                                -- quickbooks category
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Line Items
+CREATE TABLE {prefix}line_items (
+    id INT NOT NULL AUTO_INCREMENT,
+    invoice INT NOT NULL,                                  -- reference to invoice
+    line_item_type INT NOT NULL,                           -- reference to line item type
+    account INT NULL DEFAULT 0,                            -- ref to account id (renewal or employee)
+    name TEXT NOT NULL,                                    -- line item name
+    amount DECIMAL(8,2) DEFAULT '0.00',                    -- line item amount per item
+    quantity INT DEFAULT 1,                                -- quantity
+    discount INT DEFAULT 0,                                -- Discount Percentage
+    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),
+    INDEX(account),
+    INDEX(created),
+    INDEX(first_due_date),
+    INDEX(next_due_date)
+);
+
+----
+
+-- payments
+CREATE TABLE {prefix}payments (
+    id INT NOT NULL AUTO_INCREMENT,
+    transaction_time DATETIME NOT NULL,                    -- datetime of payment
+    account INT NOT NULL,                                  -- ref to account table
+    amount DECIMAL(8, 2) NOT NULL,                         -- payment amount
+    payment_method TINYTEXT NOT NULL,                      -- payment method
+    payment_data TINYTEXT NULL,                            -- additional payment info
+    notes TEXT NULL,                                       -- Notes/Comments on the payment
+    PRIMARY KEY (id)
+);
+
+----
+
+-- pdfs
+CREATE TABLE {prefix}pdfs (
+    id INT NOT NULL AUTO_INCREMENT,
+    ref_type INT NOT NULL,                                 -- reference type
+    ref_dest INT NOT NULL,                                 -- reference types id
+    pdf MEDIUMTEXT NOT NULL,                               -- saved pdf
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Notification Types
+CREATE TABLE {prefix}notification_types (
+    id INT NOT NULL AUTO_INCREMENT,
+    name TINYTEXT NOT NULL,                                -- name
+    to_email TINYTEXT NULL,                                -- To email
+    from_header TINYTEXT NOT NULL,                         -- from headers
+    replyto TINYTEXT NULL,                                 -- reply-to headers
+    subject TINYTEXT NOT NULL,                             -- Subject
+    message TEXT NOT NULL,                                 -- Message
+    send_by_date BOOLEAN NULL DEFAULT '0',                 -- true/false send by date based on due date
+    send_by_action BOOLEAN NULL DEFAULT '0',               -- send notice based on an action
+    send_action INT NULL DEFAULT 0,                        -- (create invoice or receive payment)
+    send_date_number INT NULL DEFAULT 0,                   -- number to apply to send by date
+    send_date_period INT NULL DEFAULT 0,                   -- (days,weeks,months,years)
+    send_date_when INT NULL DEFAULT 0,                     -- (before or after)
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Notifications
+CREATE TABLE {prefix}notifications (
+    id INT NOT NULL AUTO_INCREMENT,
+    notification_type INT NOT NULL,                        -- ref to notification type
+    account INT NOT NULL,                                  -- ref to account
+    from_replyto TINYTEXT NOT NULL,                        -- from reply-to header
+    subject TEXT NOT NULL,                                 -- subject
+    message TEXT NOT NULL,                                 -- message
+    date_sent DATETIME NOT NULL,                           -- Date the notice was sent
+    email_sent TINYTEXT NOT NULL,                          -- email used
+    type INT NULL,                                         -- Invoice Type
+    type_id INT NULL,                                      -- type id (invoice or payment)
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Notification Queue
+CREATE TABLE {prefix}notification_queue (
+    id INT NOT NULL AUTO_INCREMENT,
+    notification_type INT NOT NULL,                        -- ref to notification type
+    account INT NOT NULL,                                  -- ref to account
+    queued_time DATETIME NOT NULL,                         -- Creation time
+    processed_time DATETIME NULL,                          -- The time this queue was processed. (sent out)
+    PRIMARY KEY (id),
+    INDEX (notification_type),
+    INDEX (account),
+    INDEX (queued_time),
+    INDEX (processed_time)
+);
+
+----
+
+-- Gateway Settings
+CREATE TABLE {prefix}gateway_settings (
+    id INT NOT NULL AUTO_INCREMENT,
+    name TEXT NOT NULL,
+    login_id TINYTEXT NOT NULL,
+    transaction_key TINYTEXT NOT NULL,
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Invoice Payments
+CREATE TABLE {prefix}invoice_payments (
+    id INT NOT NULL AUTO_INCREMENT,
+    invoice INT NOT NULL,                                  -- reference to invoice id
+    payment INT NOT NULL,                                  -- reference to payment id
+    amount DECIMAL(8, 2) NOT NULL,                         -- payment amount
+    PRIMARY KEY (id),
+    INDEX(invoice)
+);
+
+----
+
+-- Settings
+CREATE TABLE {prefix}settings (
+    id INT NOT NULL AUTO_INCREMENT,
+    -- Invoice Options
+    company_logo TINYTEXT NULL,                            -- Image logo
+    company_logo_width INT NULL,                           -- Logo Width (only used if creating pdf)
+    company_name TINYTEXT NULL,                            -- Company Name
+    company_name2 TINYTEXT NULL,                           -- Company Name 2
+    company_addr1 TINYTEXT NULL,                           -- Company Address 1
+    company_addr2 TINYTEXT NULL,                           -- Company Address 2
+    company_city TINYTEXT NULL,                            -- Company City
+    company_state TINYTEXT NULL,                           -- Company State
+    company_zip TINYTEXT NULL,                             -- Company Zip
+    company_phone TINYTEXT NULL,                           -- Company Phone
+    company_email TINYTEXT NULL,                           -- Company Email
+    company_url TINYTEXT NULL,                             -- Company URL
+    payment_terms TEXT NULL,                               -- Payment Terms
+    receipt_text TEXT NULL,                                -- Receipt Text
+    invoice_show_account_number BOOLEAN DEFAULT '0',       -- Show Billing Account number on invoices
+    invoice_show_invoice_number BOOLEAN DEFAULT '1',       -- Show Invoice Number on invoices
+    days_before_renewal INT NULL,                          -- Number of days before renewal date to allow renewals
+    days_after_expired INT NULL,                           -- Number of days after renewal date expired
+    -- Renewal Options
+    allow_membership_choice BOOLEAN DEFAULT '0',           -- If memberships can choose their membership levels when they renew
+    allow_employees BOOLEAN DEFAULT '0',                   -- If memberships have employees
+    member_types_enabled BOOLEAN DEFAULT '1',              -- member types determine invoice types
+    quickbooks_enabled BOOLEAN DEFAULT '0',                -- QuickBooks enabled
+    member_billing_enabled BOOLEAN DEFAULT '1',            -- Member have access to billing info tab
+    billing_fields_required BOOLEAN DEFAULT '1',           -- Require Billing Fields
+    invoice_methods_enabled BOOLEAN DEFAULT '0',           -- Enable Uptra invoice methods
+    renewal_day_static BOOLEAN DEFAULT '0',                -- Renewal dates are same day every year
+    renewal_day INT NULL,                                  -- Day of the month for renewals
+    renewal_month INT NULL,                                -- Month of year for renewals
+    billing_county_enabled BOOLEAN DEFAULT '0',            -- Billing uses county field
+    invoice_pdf_enabled BOOLEAN DEFAULT '0',               -- Create PDF invoices
+    billing_contact_name_enabled BOOLEAN DEFAULT '0',      -- Use billing_contact_name instead of fname lname
+    member_types_requiring_billing TEXT NULL,              -- List of member type id's that require billing
+    -- Account Number
+    account_number_enabled BOOLEAN DEFAULT '0',            -- Enable Disable account_number
+    account_number_required BOOLEAN DEFAULT '0',           -- Require account_number
+    account_number_unique BOOLEAN DEFAULT '0',             -- account_number must be unique
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Set default billing Settings entry
+INSERT INTO {prefix}settings
+    ( id, days_before_renewal ,days_after_expired, member_types_enabled, quickbooks_enabled, member_billing_enabled )
+    VALUES
+    ( 1, 90, 30, true, false, true );
+
+----
+
+-- Management
+CREATE TABLE {prefix}management (
+    id INT NOT NULL AUTO_INCREMENT,
+    payment_methods SMALLINT NULL,                              -- Payment methods available for all registrations - Bitmap - see payment_method in plugin.ini
+    proc_methods SMALLINT NULL,                                 -- Credit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini
+    cc_accepts SMALLINT NULL,                                   -- Credit Cards Accepted - Bitmap - See credit_card in plugin.ini
+    -- Authorize.net Credentials
+    authorize_net_login TINYTEXT NULL,
+    authorize_net_key TINYTEXT NULL,
+    authorize_net_test TINYINT NULL,                            -- Authorize.net test mode - List - see proc_test_mode in plugin.ini
+    authorize_net_conf BOOLEAN NULL,                            -- Flag to send payment confirmation Email from Authorize.net
+    authorize_net_merchant_email TINYTEXT NULL,                 -- E-Mail Authorize.net will send copy of confirmation E-Mail
+    -- Merchant Solutions Credentials
+    merchant_solutions_acctid TINYTEXT NULL,                    -- Merchant Solutions credentials
+    merchant_solutions_merchantpin TINYTEXT NULL,
+    merchant_solutions_test TINYINT NULL,                       -- Merchant Solutions test mode - List - see proc_test_mode in plugin.ini
+    merchant_solutions_conf BOOLEAN NULL,                       -- Flag to send payment confirmation Email
+    merchant_solutions_merchant_email TINYTEXT NULL,            -- Merchant Solutions will send copy of confirmation E-Mail
+    -- Square Credentials
+    square_prod_access_token TINYTEXT NULL,                     -- Square production access token
+    square_prod_app_id TINYTEXT NULL,                           -- Square production application id
+    square_prod_location_id TINYTEXT NULL,                      -- Square production location id
+    square_sandbox_access_token TINYTEXT NULL,                  -- Square sandbox access token
+    square_sandbox_app_id TINYTEXT NULL,                        -- Square sandbox application id
+    square_sandbox_location_id TINYTEXT NULL,                   -- Square sandbox location id
+    square_use_prod BOOLEAN DEFAULT '0',                        -- If true use Production creds
+    -- Uptravel options
+    uptravel_invoice_template BOOLEAN DEFAULT '0',              -- Use uptravel template for invoices.
+    uptravel_payment_form BOOLEAN DEFAULT '0',                  -- Use uptravel payment form style.
+    -- Dashboard options
+    dashboard_pending_renewals BOOLEAN DEFAULT '1',             -- Show pending renewals
+    dashboard_overdue_renewals BOOLEAN DEFAULT '1',             -- Show overdue renewals
+    dashboard_overdue_invoices BOOLEAN DEFAULT '1',             -- Show overdue invoices
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Set default billing Management entry
+INSERT INTO {prefix}management
+    ( id )
+    VALUES
+    ( 1 );
+
+----
+
+-- Employees table
+CREATE TABLE {prefix}employees (
+    id INT NOT NULL AUTO_INCREMENT,
+    account INT NOT NULL,                                      -- Account Id
+    employee INT NOT NULL,                                     -- Employee Account Id
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Terms
+CREATE TABLE {prefix}settings_terms (
+    id INT NOT NULL AUTO_INCREMENT,
+    invoice_name TINYTEXT NOT NULL,
+    invoice_name_plur TINYTEXT NOT NULL,
+    invoice_name_cap TINYTEXT NOT NULL,
+    invoice_name_plur_cap TINYTEXT NOT NULL,
+    invoice_type TINYTEXT NOT NULL,
+    invoice_type_plur TINYTEXT NOT NULL,
+    invoice_type_cap TINYTEXT NOT NULL,
+    invoice_type_plur_cap TINYTEXT NOT NULL,
+    account_number TINYTEXT NOT NULL,
+    PRIMARY KEY (id)
+);
+
+----
+
+INSERT INTO {prefix}settings_terms
+    (
+    id,
+    invoice_name,
+    invoice_name_plur,
+    invoice_name_cap,
+    invoice_name_plur_cap,
+    invoice_type,
+    invoice_type_plur,
+    invoice_type_cap,
+    invoice_type_plur_cap,
+    account_number
+    )
+    VALUES
+    (
+    1,
+    'invoice',
+    'invoices',
+    'Invoice',
+    'Invoices',
+    'invoice type',
+    'invoice types',
+    'Invoice Type',
+    'Invoice Types',
+    'Account Number'
+    );
index e03da49..90f6965 100644 (file)
@@ -52,5 +52,6 @@ $glmMembersBillingDbVersions = array(
     '0.0.36' => array('version' => '0.0.36', 'tables' => 16, 'date' => '04/02/2019'),
     '0.0.37' => array('version' => '0.0.37', 'tables' => 16, 'date' => '04/11/2019'),
     '0.0.38' => array('version' => '0.0.38', 'tables' => 16, 'date' => '04/16/2019'),
+    '0.0.39' => array('version' => '0.0.39', 'tables' => 16, 'date' => '04/17/2019'),
 );
 
index c50131f..5d0252b 100644 (file)
@@ -1,6 +1,6 @@
 -- Gaslight Media Billing Database
 -- File Created: 04/11/2019
--- Database Version: 0.0.37
+-- Database Version: 0.0.38
 --
 -- To permit each query below to be executed separately,
 -- all queries must be separated by a line with four dashes
diff --git a/setup/databaseScripts/update_database_V0.0.39.sql b/setup/databaseScripts/update_database_V0.0.39.sql
new file mode 100644 (file)
index 0000000..51c3c08
--- /dev/null
@@ -0,0 +1,19 @@
+-- Gaslight Media Billing Database
+-- File Created: 04/17/2019
+-- Database Version: 0.0.39
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+-- Update the management table
+ALTER TABLE {prefix}management ADD dashboard_pending_renewals BOOLEAN DEFAULT '1';    -- Show invoices on the dashboard
+
+----
+
+-- Update the management table
+ALTER TABLE {prefix}management ADD dashboard_overdue_renewals BOOLEAN DEFAULT '1';    -- Show invoices on the dashboard
+
+----
+
+-- Update the management table
+ALTER TABLE {prefix}management ADD dashboard_overdue_invoices BOOLEAN DEFAULT '1';    -- Show invoices on the dashboard
index 9ceaed1..47f19f1 100644 (file)
@@ -5,12 +5,13 @@
     {include file='admin/billing/header.html'}
 {/if}
 
-    <div id="exportAccountsButton" class="button button-secondary glm-admin-export-button">Accounts Export</div>
+<h2>Accounts</h2>
+<div id="exportAccountsButton" class="button button-secondary glm-admin-export-button">Accounts Export</div>
 
-    <a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=add">Create Invoice</a>
-    <a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments&option=add">Make Payment</a>
+<a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=add">Create Invoice</a>
+<a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments&option=add">Make Payment</a>
 
-    {include file='admin/billing/accountSearchForm.html'}
+{include file='admin/billing/accountSearchForm.html'}
 </form>
 
 {foreach $dashboards as $dashboard_title => $list}
@@ -58,9 +59,7 @@
                             </td>
                         </tr>
                         {if $t.boss.value}
-                            <tr id="account-employees-{$t.id}"
-                                class="{if $t@iteration is div by 2} alternate{/if}"
-                                style="display: none; background-color: #fff;">
+                            <tr id="account-employees-{$t.id}" class="{if $t@iteration is div by 2} alternate{/if}" style="display: none; background-color: #fff;">
                                 <td colspan="5">
                                     <div class="glm-row" style="margin-bottom: 0px !important; margin-top: .5rem;">
                                         {foreach $t.employees as $emp}
index d706699..3a84e78 100644 (file)
                 <input id="member-account" type="hidden" name="filterAccounts" value="{$filterAccounts}">
                 <input id="account_name" name="searchName" value="" />
             </div>
+            <div class="billing-search-form-container">
+                <label>Invoice #:&nbsp;</label>
+                <input id="member-invoice-id" type="hidden" name="filterInvoice" value="{$filterInvoices}">
+                <input id="invoice_id" name="searchInvoice" value="" />
+            </div>
             <div class="billing-search-form-container">
                 <label>
                     <input type="checkbox" name="filterUnpaid"{if isset($smarty.request.filterUnpaid) && $smarty.request.filterUnpaid} checked{/if}>
@@ -57,7 +62,7 @@
                     <th>Member Name</th>
                     <th>Invoice For</th>
                     <th style="width: 150px;">Time</th>
-                    <th style="width: 70px;">Due Date</th>
+                    <th style="width: 80px;">Due Date</th>
                     <th style="width: 100px;">Amount Total</th>
                     <th style="width: 70px;">Balance</th>
                 </tr>
             },
         });
 
+        var availableInvoices = [
+        {foreach $invoiceList as $m}
+            { label: "{$m.id} ( {$m.member_name|unescape:'html'|replace:'"':''} )", value: "{$m.id|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
+        {/foreach}
+        ]
+        $('#invoice_id').autocomplete({
+            source: availableInvoices,
+            select: function( event, ui ){
+                $('#member-invoice-id').val( ui.item.id );
+                $('#searchForm').submit();
+            },
+            change: function( event, ui) {
+                if( ui.item == null ) {
+                    $('#member-invoice-id').val( '' );
+                    $('#searchForm').submit();
+                }
+            },
+        });
         {if $filterAccounts}
             {$selected = 0}
             {foreach $accounts as $m}
index 97fc1de..d9f65c9 100644 (file)
 
                 <table>
 
+                    <tr>
+                        <td></td>
+                        <th><p>Dashboard</p></th>
+                    </tr>
+                    <tr>
+                        <th style="text-align: right;" {if $regSettings.fieldRequired.dashboard_pending_renewals} class="glm-required"}{/if}>
+                        </th>
+                        <td>
+                            <input type="checkbox" name="dashboard_pending_renewals"{if $regSettings.fieldData.dashboard_pending_renewals.value} checked="checked"{/if}>
+                            Show Pending Renewals on the Dashboard
+                        </td>
+                    </tr>
+                    <tr>
+                        <th style="text-align: right;" {if $regSettings.fieldRequired.dashboard_overdue_renewals} class="glm-required"}{/if}>
+                        </th>
+                        <td>
+                            <input type="checkbox" name="dashboard_overdue_renewals"{if $regSettings.fieldData.dashboard_overdue_renewals.value} checked="checked"{/if}>
+                            Show Overdue renewals on the Dashboard
+                        </td>
+                    </tr>
+                    <tr>
+                        <th style="text-align: right;" {if $regSettings.fieldRequired.dashboard_overdue_invoices} class="glm-required"}{/if}>
+                        </th>
+                        <td>
+                            <input type="checkbox" name="dashboard_overdue_invoices"{if $regSettings.fieldData.dashboard_overdue_invoices.value} checked="checked"{/if}>
+                            Show Overdue Invoices on the Dashboard
+                        </td>
+                    </tr>
+
+
+
+
+
                     <tr>
                         <td></td>
                         <th><p>Payment</p></th>
                         </td>
                     </tr>
 
+
+
                 </table>
                 <input type="submit" value="Update Settings" class="button-primary">
 
index 48bcc6e..1d3a60d 100644 (file)
                 <select name="cc_type" class="ccard" required>
                     <option value=""></option>
                     {foreach $management.cc_accepts.names as $cardId => $cardName}
-                        <option value="{$cardName}"
+                        <option value="{$cardId}"
                         {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
                     {/foreach}
                 </select>