Re Sending email notifications from log page
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 20 Mar 2019 20:41:56 +0000 (16:41 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 20 Mar 2019 20:41:56 +0000 (16:41 -0400)
Log page has link to re-send notification.
two new fields for notifications are type and type_id which help to
re-create the send email notification call with same parameters for
sending out the exact same email. (with invoice or payment data)

13 files changed:
classes/data/dataNotifications.php
classes/notifications.php
index.php
models/admin/ajax/invoices.php
models/admin/billing/logs.php
models/admin/billing/payments.php
setup/databaseScripts/create_database_V0.0.34.sql [deleted file]
setup/databaseScripts/create_database_V0.0.35.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.35.sql [new file with mode: 0644]
views/admin/billing/editPayment.html
views/admin/billing/logs.html
views/admin/settings/editNotificationType.html

index c24fea0..64ef542 100644 (file)
@@ -169,6 +169,20 @@ class GlmDataNotifications extends GlmDataAbstract
                 'use'     => 'a',
             ),
 
+            // type
+            'type' => array(
+                'field'   => 'type',
+                'type'    => 'integer',
+                'use'     => 'a',
+            ),
+
+            // type id
+            'type_id' => array(
+                'field'   => 'type_id',
+                'type'    => 'integer',
+                'use'     => 'a',
+            ),
+
          );
 
 
index 51a512e..5ac1743 100644 (file)
@@ -200,9 +200,6 @@ class GlmNotifications
             wp_mail( $to_email, $subject, $message, $header );
         } else {
             wp_mail( $to_email, $subject, $message, $header, $attachments );
-            // wp_mail( 'steve@localhost', $subject, $message, $header, $attachments );
-            // Remove the temp file now
-            // unlink( $fileName );
         }
 
         // remove the filter to avoid conflicts
@@ -217,7 +214,13 @@ class GlmNotifications
             'message'           => $message,
             'email_sent'        => $to_email,
         );
-        $this->recordNotification( $notice_data );
+        $type    = 0;
+        $type_id = 0;
+        if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] ) {
+            $type    = $data['type'];
+            $type_id = $data['type_id'];
+        }
+        $this->recordNotification( $notice_data, $type, $type_id );
     }
 
     /**
@@ -259,7 +262,7 @@ class GlmNotifications
      * @access public
      * @return void
      */
-    public function recordNotification( $notification )
+    public function recordNotification( $notification, $type = 0, $type_id = 0 )
     {
         if ( !$notification['notification_type'] || !$notification['account']
             || !$notification['from_replyto'] || !$notification['subject']
@@ -277,6 +280,8 @@ class GlmNotifications
                 'message'           => $notification['message'],
                 'date_sent'         => date('Y-m-d H:i;s'),
                 'email_sent'        => $notification['email_sent'],
+                'type'              => $type,
+                'type_id'           => $type_id,
             ),
             array(
                 '%d', // notification_type
@@ -286,11 +291,51 @@ class GlmNotifications
                 '%s', // message
                 '%s', // date_sent
                 '%s', // email_sent
+                '%d', // type
+                '%d', // type_id
             )
         );
         return true;
     }
 
+    public function resendNotificationById( $id )
+    {
+        $notification = $this->wpdb->get_row(
+            $this->wpdb->prepare(
+                "SELECT *
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notifications
+                  WHERE id = %d",
+                $id
+            ),
+            ARRAY_A
+        );
+        $notify_type_id = $notification['notification_type'];
+        $account        = $notification['account'];
+        $invoice_total  = 0;
+        $payment_total  = 0;
+        // Get amounts
+        $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+        switch ( $notification['type'] ) {
+        case $this->config['transaction_numb']['Invoice']:
+            $invoice       = $BillingSupport->getInvoiceById( $notification['type_id'] );
+            $invoice_total = $invoice['balance'];
+            break;
+        case $this->config['transaction_numb']['Payment']:
+            $payment       = $BillingSupport->getInvoiceById( $notification['type_id'] );
+            $payment_total = $payment['amount'];
+            break;
+        }
+        $data = array(
+            'type'    => $notification['type'],
+            'type_id' => $notification['type_id'],
+            'account' => $notification['account'],
+            'amount'  => $invoice_total,
+            'payment' => $payment_total,
+        );
+        $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+        $Notifications->sendEmailNotification( $notify_type_id, $account, $data );
+    }
+
     /**
      * getNotificationsByType
      *
index a490a00..9f53a5e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -38,7 +38,7 @@
  *  version from this plugin.
  */
 define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.25');
-define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.34');
+define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.35');
 
 // 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 d586de3..16b0e99 100644 (file)
@@ -76,22 +76,28 @@ class GlmMembersAdmin_ajax_invoices extends GlmDataInvoices
     public function modelAction( $actionData = false )
     {
         $return = false;
+        $option = false;
 
-        $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING );
+        if ( isset( $_REQUEST['option'] ) ) {
+            $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING );
+        }
         trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
 
         switch ( $option ) {
         case 'list':
         default:
             $account  = filter_var( $_REQUEST['account'], FILTER_VALIDATE_INT );
+            $this->line_items_post = true;
             $invoices = $this->getList( "T.paid <> true AND T.account = $account" );
+            $this->line_items_post = false;
             $return   = array();
             foreach ( $invoices as $invoice ) {
                 $return[] = array(
                     'id'               => $invoice['id'],
                     'transaction_time' => $invoice['transaction_time'],
                     'balance'          => $invoice['balance'],
-                    'due_date'         => $invoice['due_date']
+                    'due_date'         => $invoice['due_date'],
+                    'line_items'       => $invoice['line_items']
                 );
             }
 
index 425ce34..8263f93 100644 (file)
@@ -16,6 +16,8 @@
 // Load Contacts data class
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataNotifications.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
 
 class GlmMembersAdmin_billing_logs extends GlmDataNotifications
 {
@@ -82,20 +84,22 @@ class GlmMembersAdmin_billing_logs extends GlmDataNotifications
     public function modelAction($actionData = false)
     {
 
-        $option        = 'list';
-        $haveLogs      = false;
-        $view          = 'logs';
-        $fromDate      = false;
-        $toDate        = false;
-        $numbDisplayed = false;
-        $lastDisplayed = false;
-        $paging        = true;
-        $prevStart     = false;
-        $nextStart     = false;
-        $start         = 1;
-        $limit         = 20;        // Set to the number of listings per page
-        $invTypes      = array();
-        $accounts      = false;
+        $option         = 'list';
+        $haveLogs       = false;
+        $view           = 'logs';
+        $fromDate       = false;
+        $toDate         = false;
+        $numbDisplayed  = false;
+        $lastDisplayed  = false;
+        $paging         = true;
+        $prevStart      = false;
+        $nextStart      = false;
+        $start          = 1;
+        $limit          = 20;        // Set to the number of listings per page
+        $invTypes       = array();
+        $accounts       = false;
+        $emailSent      = false;
+        $emailSentError = false;
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
@@ -105,104 +109,114 @@ class GlmMembersAdmin_billing_logs extends GlmDataNotifications
         // Do selected option
         switch ($option) {
 
+        case 'resend':
+            // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+            if ( isset( $_REQUEST['notification_id'] ) && $notification_id = filter_var( $_REQUEST['notification_id'], FILTER_VALIDATE_INT ) ) {
+
+                $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+                $Notifications->resendNotificationById( $notification_id );
+                $emailSent = true;
+            } else {
+                $emailSentError = true;
+            }
+            // pull the notification and re send it.
+            break;
+
         case 'list':
         default:
+            break;
 
-            $where = 'true';
+        }
 
-            // Check for paging
-            if ( isset( $_REQUEST['pageSelect'] ) ) {
-                $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
-            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
-                unset( $_SESSION['search']['pageSelect'] );
-            }
-            if ( isset( $_REQUEST['nextStart'] ) ) {
-                $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
-            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
-                unset( $_SESSION['search']['nextStart'] );
-            }
-            if ( isset( $_REQUEST['prevStart'] ) ) {
-                $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
-            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
-                unset( $_SESSION['search']['prevStart'] );
-            }
+        $where = 'true';
 
-            // Check if we're doing paging
-            if (isset($_REQUEST['pageSelect'])) {
-                // If request is for Next
-                if ($_REQUEST['pageSelect'][0] == 'N') {
-                    $newStart = $_REQUEST['nextStart'] - 0;
+        // Check for paging
+        if ( isset( $_REQUEST['pageSelect'] ) ) {
+            $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
+        } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
+            unset( $_SESSION['search']['pageSelect'] );
+        }
+        if ( isset( $_REQUEST['nextStart'] ) ) {
+            $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
+        } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
+            unset( $_SESSION['search']['nextStart'] );
+        }
+        if ( isset( $_REQUEST['prevStart'] ) ) {
+            $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
+        } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
+            unset( $_SESSION['search']['prevStart'] );
+        }
 
-                // Otherwise it must be Previous
-                } else {
-                    $newStart = $_REQUEST['prevStart'] - 0;
-                }
+        // Check if we're doing paging
+        if (isset($_REQUEST['pageSelect'])) {
+            // If request is for Next
+            if ($_REQUEST['pageSelect'][0] == 'N') {
+                $newStart = $_REQUEST['nextStart'] - 0;
 
-                if ($newStart > 0) {
-                    $start = $newStart;
-                }
+            // Otherwise it must be Previous
+            } else {
+                $newStart = $_REQUEST['prevStart'] - 0;
             }
 
-            if( isset($_SESSION['search']['pageSelect']) ){
-                 // If request is for Next
-                if ($_SESSION['search']['pageSelect'][0] == 'N') {
-                    $newStart = $_SESSION['search']['nextStart'] - 0;
-
-                // Otherwise it must be Previous
-                } else {
-                    $newStart = $_SESSION['search']['prevStart'] - 0;
-                }
-                if ($newStart > 0) {
-                    $start = $newStart;
-                }
+            if ($newStart > 0) {
+                $start = $newStart;
             }
+        }
 
-            // Get the list of logs and determine number of logs in list
-            $orderBy = 'date_sent asc';
-            $logsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
-            // echo '<pre>$logsResult: ' . print_r( $logsResult, true ) . '</pre>';
+        if( isset($_SESSION['search']['pageSelect']) ){
+             // If request is for Next
+            if ($_SESSION['search']['pageSelect'][0] == 'N') {
+                $newStart = $_SESSION['search']['nextStart'] - 0;
 
-            // Get paging results
-            $numbDisplayed = $logsResult['returned'];
-            $lastDisplayed = $logsResult['last'];
-            if ($start == 1) {
-                $prevStart = false;
+            // Otherwise it must be Previous
             } else {
-                $prevStart = $start - $limit;
-                if ($start < 1) {
-                    $start = 1;
-                }
+                $newStart = $_SESSION['search']['prevStart'] - 0;
             }
-            if ($logsResult['returned'] == $limit) {
-                $nextStart = $start + $limit;
+            if ($newStart > 0) {
+                $start = $newStart;
             }
+        }
 
-            // since we're doing paging, we have to break out just the logs data
-            $logs = $logsResult['list'];
-            if (count($logs)>0) {
-                $haveLogs = true;
+        // Get the list of logs and determine number of logs in list
+        $orderBy = 'date_sent desc';
+        $logsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
+
+        // Get paging results
+        $numbDisplayed = $logsResult['returned'];
+        $lastDisplayed = $logsResult['last'];
+        if ($start == 1) {
+            $prevStart = false;
+        } else {
+            $prevStart = $start - $limit;
+            if ($start < 1) {
+                $start = 1;
             }
-            unset($logsResult);
-
-            // echo '<pre>$logs: ' . print_r( $logs, true ) . '</pre>';
-
-            break;
-
+        }
+        if ($logsResult['returned'] == $limit) {
+            $nextStart = $start + $limit;
         }
 
+        // since we're doing paging, we have to break out just the logs data
+        $logs = $logsResult['list'];
+        if (count($logs)>0) {
+            $haveLogs = true;
+        }
+        unset($logsResult);
 
         $templateData = array(
-            'option'        => $option,
-            'logs'          => $logs,
-            'haveLogs'      => $haveLogs,
-            'numbDisplayed' => $numbDisplayed,
-            'lastDisplayed' => $lastDisplayed,
-            'paging'        => $paging,
-            'prevStart'     => $prevStart,
-            'nextStart'     => $nextStart,
-            'start'         => $start = 1,
-            'limit'         => $limit,
-            'accounts'      => $accounts,
+            'option'         => $option,
+            'logs'           => $logs,
+            'haveLogs'       => $haveLogs,
+            'numbDisplayed'  => $numbDisplayed,
+            'lastDisplayed'  => $lastDisplayed,
+            'paging'         => $paging,
+            'prevStart'      => $prevStart,
+            'nextStart'      => $nextStart,
+            'start'          => $start = 1,
+            'limit'          => $limit,
+            'accounts'       => $accounts,
+            'emailSent'      => $emailSent,
+            'emailSentError' => $emailSentError,
         );
 
         // Return status, any suggested view, and any data to controller
index f85d884..9a6041b 100644 (file)
@@ -135,9 +135,10 @@ class GlmMembersAdmin_billing_payments extends GlmDataPayments
 
             // Get only accounts that have invoices
             $accounts = $Accounts->getSimpleAccountList(
-                "T.id IN ( SELECT DISTINCT account
-                             FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
-                            WHERE paid <> true )"
+                "T.id IN (
+                    SELECT DISTINCT account
+                      FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+                     WHERE paid <> true )"
             );
             break;
 
diff --git a/setup/databaseScripts/create_database_V0.0.34.sql b/setup/databaseScripts/create_database_V0.0.34.sql
deleted file mode 100644 (file)
index b4027f9..0000000
+++ /dev/null
@@ -1,373 +0,0 @@
--- Gaslight Media Billing Module
--- File Created: 02/19/2019
--- Database Version: 0.0.33
--- 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
-    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
-    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
-    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
-    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.35.sql b/setup/databaseScripts/create_database_V0.0.35.sql
new file mode 100644 (file)
index 0000000..2e3c361
--- /dev/null
@@ -0,0 +1,375 @@
+-- Gaslight Media Billing Module
+-- File Created: 02/19/2019
+-- Database Version: 0.0.33
+-- 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
+    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
+    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
+    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'
+    );
index df2274b..3c80121 100644 (file)
@@ -48,5 +48,6 @@ $glmMembersBillingDbVersions = array(
     '0.0.32' => array('version' => '0.0.32', 'tables' => 15, 'date' => '12/26/2018'),
     '0.0.33' => array('version' => '0.0.33', 'tables' => 15, 'date' => '02/19/2019'),
     '0.0.34' => array('version' => '0.0.34', 'tables' => 16, 'date' => '03/19/2019'),
+    '0.0.35' => array('version' => '0.0.35', 'tables' => 16, 'date' => '03/20/2019'),
 );
 
diff --git a/setup/databaseScripts/update_database_V0.0.35.sql b/setup/databaseScripts/update_database_V0.0.35.sql
new file mode 100644 (file)
index 0000000..cd56fc3
--- /dev/null
@@ -0,0 +1,14 @@
+-- Gaslight Media Billing Database
+-- File Created: 3/19/2019
+-- Database Version: 0.0.35
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+-- Update the notification table
+ALTER TABLE {prefix}notifications ADD type INT NULL;            -- Invoice Type
+
+----
+
+ALTER TABLE {prefix}notifications ADD type_id INT NULL;         -- type id (invoice or payment)
+
index b280bc8..4e2a90a 100644 (file)
@@ -74,9 +74,19 @@ jQuery(document).ready(function($){
         // Clear the invoices
         $('#glm-payment-invoices').html('');
         for ( var i = 0; i < invoices.length; i++ ) {
-            $('#glm-payment-invoices').append( '<label>' +
-            '<input type="checkbox" class="glm-invoice-item" name="invoices[' + invoices[i].id + ']" data-amount="' + invoices[i].balance + '" />$' +
-            invoices[i].balance + '</label><br />' );
+            var invoice = invoices[i];
+            var rowHtml = '<label>' +
+            '<input type="checkbox" class="glm-invoice-item" name="invoices[' + invoices[i].id + ']" data-amount="' + invoices[i].balance + '" />';
+            rowHtml += '$' + invoices[i].balance;
+            for ( index = 0; index < invoice.line_items.length; ++index ) {
+                var line_item = invoice.line_items[index];
+                rowHtml += ' ' + line_item.name;
+                if ( line_item.recurring ) {
+                   rowHtml += ' ( ' + line_item.recurrence_string + ' )';
+                }
+            }
+            rowHtml += '</label><br />';
+            $('#glm-payment-invoices').append( rowHtml );
         }
     }
 
@@ -112,7 +122,7 @@ jQuery(document).ready(function($){
                 },
                 success: function( results ) {
                     updateInvoiceList( results );
-                    //console.log( results );
+                    console.log( results );
                 },
             });
         },
index 482d07f..659d38e 100644 (file)
@@ -3,41 +3,72 @@
 
 <h2>Notification Logs</h2>
 
-<table class="wp-list-table widefat fixed posts glm-admin-table">
-    <thead>
-        <tr>
-            <th>ID</th>
-            <th>Date Sent</th>
-            <th>Subject</th>
-            <th>Member Name</th>
-            <th>Email</th>
-        </tr>
-    </thead>
-    <tbody>
-        {if $haveLogs}
-            {assign var="i" value="0"}
-            {foreach $logs as $t}
-                {if $i++ is odd by 1}
-                    <tr>
-                {else}
-                    <tr class="alternate">
-                {/if}
-                    <td> {$t.id} </td>
-                    <td> {$t.date_sent.date} </td>
-                    <td> {$t.subject} </td>
-                    <td> {$t.member_name} </td>
-                    <td> {$t.email_sent} </td>
-                </tr>
-            {/foreach}
-        {else}
-            <tr class="alternate"><td colspan="2">(no Invoice Types listed)</td></tr>
-        {/if}
-    </tbody>
-</table>
+{if $emailSent}<span class="glm-notice glm-flash-updated">Email Sent</span>{/if}
+{if $emailSentError}<span class="glm-notice glm-flash-updated">There was an error sending out the email</span>{/if}
+
+<br clear="all">
+
+<form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
+    <input type="hidden" name="glm_action" value="logs">
+    <input type="hidden" name="option" value="list">
+    <input type="hidden" name="searched" value="1">
+    <input type="hidden" name="prevStart" value="{$prevStart}">
+    <input type="hidden" name="nextStart" value="{$nextStart}">
+    <input type="hidden" name="limit" value="{$limit}">
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Invoices" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Invoices" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+    <br clear="all">
+
+    <table class="wp-list-table widefat fixed posts glm-admin-table">
+        <thead>
+            <tr>
+                <th>ID</th>
+                <th>Date Sent</th>
+                <th>Subject</th>
+                <th>Member Name</th>
+                <th>Email</th>
+                <th>&nbsp;</th>
+            </tr>
+        </thead>
+        <tbody>
+            {if $haveLogs}
+                {assign var="i" value="0"}
+                {foreach $logs as $t}
+                    <tr class="{if $t@iteration is div by 2} alternate{/if}">
+                        <td> {$t.id} </td>
+                        <td> {$t.date_sent.date} </td>
+                        <td> {$t.subject} </td>
+                        <td> {$t.member_name} </td>
+                        <td> {$t.email_sent} </td>
+                        <td>
+                            {if $t.type_id}
+                                <a href="{$thisUrl}?page={$thisPage}&glm_action=logs&option=resend&notification_id={$t.id}" date-id="{$t.id}">Re Send</a>
+                            {/if}
+                        </td>
+                    </tr>
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="2">(no Invoice Types listed)</td></tr>
+            {/if}
+        </tbody>
+    </table>
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Invoices" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Invoices" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
+</form>
 
 <script type="text/javascript">
     jQuery(document).ready(function($) {
 
+        // 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);
+
     });
 </script>
 
index 9512be7..a566710 100644 (file)
@@ -20,7 +20,7 @@
         <tr>
             <th style="text-align: right;" {if $notification.fieldRequired.name} class="glm-required"}{/if}>Name</th>
             <td {if $notification.fieldFail.name}class="glm-form-bad-input" data-tabid="glm-name"{/if}>
-                <input type="text" name="name" value="{$notification.fieldData.name}" class="glm-form-text-input-medium">
+                <input type="text" name="name" value="{$notification.fieldData.name}" class="glm-form-text-input-medium"{if $notification.fieldRequired.name} required{/if}>
                 {if $notification.fieldFail.name}<p>{$notification.fieldFail.name}</p>{/if}<br>
             </td>
         </tr>
         <tr>
             <th style="text-align: right;" {if $notification.fieldRequired.subject} class="glm-required"}{/if}>Subject</th>
             <td {if $notification.fieldFail.subject}class="glm-form-bad-input" data-tabid="glm-subject"{/if}>
-                <input type="text" name="subject" value="{$notification.fieldData.subject}" class="glm-form-text-input-medium">
+                <input type="text" name="subject" value="{$notification.fieldData.subject}" class="glm-form-text-input-medium"{if $notification.fieldRequired.subject} required{/if}>
             {if $notification.fieldFail.subject}<p>{$notification.fieldFail.subject}</p>{/if}<br>
             </td>
         </tr>
 
         <tr>
-            <th style="text-align: right;" {if $notification.fieldRequired.from_header} class="glm-required"}{/if}>From</th>
+            <th style="text-align: right;" {if $notification.fieldRequired.from_header} class="glm-required"}{/if}>From (email address)</th>
             <td {if $notification.fieldFail.from_header}class="glm-form-bad-input" data-tabid="glm-fromheader"{/if}>
-                <input type="text" name="from_header" value="{$notification.fieldData.from_header}" class="glm-form-text-input-medium">
+                <input type="email" name="from_header" value="{$notification.fieldData.from_header}" class="glm-form-text-input-medium"{if $notification.fieldRequired.from_header} required{/if}>
             {if $notification.fieldFail.from_header}<p>{$notification.fieldFail.from_header}</p>{/if}<br>
             </td>
         </tr>