commit WIP
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 15 May 2019 17:47:25 +0000 (13:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 15 May 2019 17:47:25 +0000 (13:47 -0400)
Commiting changes for billing.
working on some issues with uptra billing.

classes/billingSupport.php
models/admin/ajax/printInvoices.php
models/admin/billing/invoicing.php
models/admin/billing/reports.php
models/admin/member/billing.php
views/admin/billing/memberBillingSubHeader.html

index 651e6df..7616128 100644 (file)
@@ -417,7 +417,7 @@ class GlmBillingSupport
      * @access public
      * @return void
      */
-    public function getStatementsByRefDest( $ref_dest )
+    public function getStatementsByRefDest( $ref_dest, $all = false )
     {
         $balance_due = (float)0.00;
         $invoice     = false;
@@ -442,23 +442,39 @@ class GlmBillingSupport
             switch ( $type ){
             case $this->config['transaction_numb']['Invoice']:
                 $invoice     = $this->getInvoiceById( $transaction['type_id'] );
-                $line_items  = $this->getLineItemsForInvoice( $transaction['type_id'] );
-                $balance_due = $balance_due + $invoice['amount_total'];
-                // add to the $transaction array
-                $transaction['transaction_data'] = $invoice;
-                $transaction['line_items']       = $line_items;
+                // echo '<pre>$invoice: ' . print_r( $invoice, true ) . '</pre>';
+                if ( !$all && $invoice['paid'] ) {
+                    unset( $transactions[$key] );
+                    continue;
+                } else {
+                    $line_items  = $this->getLineItemsForInvoice( $transaction['type_id'] );
+                    $balance_due = $balance_due + $invoice['amount_total'];
+                    // add to the $transaction array
+                    $transaction['transaction_data'] = $invoice;
+                    $transaction['line_items']       = $line_items;
+                }
                 break;
             case $this->config['transaction_numb']['Payment']:
-                $payment = $this->getPaymentById( $transaction['type_id'] );
-                $balance_due = $balance_due - $payment['amount'];
-                // add to the $transaction array
-                $transaction['transaction_data'] = $payment;
+                if ( !$all ) {
+                    unset( $transactions[$key] );
+                    continue;
+                } else {
+                    $payment = $this->getPaymentById( $transaction['type_id'] );
+                    $balance_due = $balance_due - $payment['amount'];
+                    // add to the $transaction array
+                    $transaction['transaction_data'] = $payment;
+                }
                 break;
             case $this->config['transaction_numb']['Adjustment']:
-                $payment = $this->getPaymentById( $transaction['type_id'] );
-                $balance_due = $balance_due - $payment['amount'];
-                // add to the $transaction array
-                $transaction['transaction_data'] = $payment;
+                if ( !$all ) {
+                    unset( $transactions[$key] );
+                    continue;
+                } else {
+                    $payment = $this->getPaymentById( $transaction['type_id'] );
+                    $balance_due = $balance_due - $payment['amount'];
+                    // add to the $transaction array
+                    $transaction['transaction_data'] = $payment;
+                }
                 break;
             }
         }
@@ -526,8 +542,9 @@ class GlmBillingSupport
      * @access public
      * @return void
      */
-    public function getTransactionsByAccount( $account )
+    public function getTransactionsByAccount( $account, $unpaid = false )
     {
+        $where = ( $unpaid ) ? " AND " : '';
         return $this->wpdb->get_results(
             $this->wpdb->prepare(
                 "SELECT *
index f7042ab..6a32d89 100644 (file)
@@ -95,14 +95,18 @@ class GlmMembersAdmin_ajax_printInvoices
 
         }
 
+        $notPaid = " ( paid <> true OR paid IS NULL ) AND balance != 0.00";
+
         $wParts[] = " T.id IN (
             SELECT account
               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX  . "invoices
-             WHERE paid <> true ) ";
-        $wParts[] = " ( T.usmail_invoice OR T.fax_invoice ) ";
+             WHERE $notPaid ) ";
+        $wParts[] = " ( T.usmail_invoice = true OR T.fax_invoice = true ) ";
+        $wParts[] = " $notPaid ";
 
         // $where used in all places.
         $where = implode( ' AND ', $wParts );
+        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
 
         // Get all invoices
         $invoiceData = $this->wpdb->get_results(
@@ -114,6 +118,7 @@ class GlmMembersAdmin_ajax_printInvoices
             ARRAY_A
         );
         // echo '<pre>$invoiceData: ' . print_r( $invoiceData, true ) . '</pre>';
+        // exit;
         foreach ( $invoiceData as $inv ) {
             $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] );
             if ( $fullInvoice ) {
index 154418e..d1c4e4d 100644 (file)
@@ -116,7 +116,7 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts
         $Accounts       = new GlmDataAccounts( $this->wpdb, $this->config );
 
         // Not paid query
-        $notPaid = "( paid <> true ) AND balance != 0.00";
+        $notPaid = "( paid <> true OR paid IS NULL ) AND balance != 0.00";
 
         if ( isset( $_REQUEST['invoice_types'] ) ) {
             $invoiceTypes = $_REQUEST['invoice_types'];
@@ -255,7 +255,6 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts
 
         // $where used in all places.
         $where = implode( ' AND ', $wParts );
-        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
 
         // Check if Counties is enabled and fetch counties
         if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) {
@@ -287,6 +286,7 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts
         $orderBy                = 'ref_name';
         $Accounts->paymentTypes = true;
         $Accounts->balanceDue   = true;
+        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
         $accountsResult         = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit );
         $totalAccounts          = $Accounts->getStats( $where );
         $Accounts->paymentTypes = false;
index c7e4feb..1bff06a 100644 (file)
@@ -225,7 +225,9 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
             $wParts[] = "T.id IN (
                 SELECT account
                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
-                 WHERE balance > 0 AND balance IS NOT NULL
+                 WHERE balance > 0
+                   AND balance IS NOT NULL
+                   AND ( paid <> true OR paid IS NULL )
                 )";
             $view = 'reports';
             break;
@@ -252,6 +254,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
             }
         }
         if ( !in_array( $option, array( 'reportGenerator', 'noAccounts' ) ) ) {
+            echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
             // Getting the account listings
             $orderBy                = 'member_name';
             $Accounts->paymentTypes = true;
index ba53e49..133b1aa 100644 (file)
@@ -131,6 +131,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         $errors             = false;
         $invoiceTypes       = false;
         $renewalFormSession = false;
+        $allStatements      = false;
 
         // For lockedToMember.
         $lockedToMember = false;
@@ -956,12 +957,15 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
         case 'list':
             $view = 'statements';
+            if ( isset( $_REQUEST['all'] ) && $all = filter_var( $_REQUEST['all'], FILTER_VALIDATE_BOOLEAN ) ) {
+                $allStatements = true;
+            }
             // echo '<pre>$test: ' . print_r( $test, true ) . '</pre>';
             break;
         }
 
         // Get the list of invoices for this member.
-        $statements = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        $statements = $BillingSupport->getStatementsByRefDest( $this->memberID, $allStatements );
         // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
         if ( $statements ) {
             $transactions      = $statements['transactions'];
index 972392c..2f94d74 100644 (file)
@@ -20,7 +20,7 @@
                 <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=account" class="">Billing Info</a>
             </li>
             <li>
-                <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}" class="">All Statements</a>
+                <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&all=1" class="">All Statements</a>
             </li>
             {if ($account_status == 'Pending' || $account_status == 'Expired') && !apply_filters('glm-billing-account-has-renewal', true, $accountID )}
                 <li>