From 6b9eb05af5b91f4261aac38ae397b9e335a523ab Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 15 May 2019 13:47:25 -0400 Subject: [PATCH] commit WIP Commiting changes for billing. working on some issues with uptra billing. --- classes/billingSupport.php | 47 +++++++++++++------ models/admin/ajax/printInvoices.php | 9 +++- models/admin/billing/invoicing.php | 4 +- models/admin/billing/reports.php | 5 +- models/admin/member/billing.php | 6 ++- .../admin/billing/memberBillingSubHeader.html | 2 +- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 651e6df..7616128 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -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 '
$invoice: ' . print_r( $invoice, true ) . '
'; + 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 * diff --git a/models/admin/ajax/printInvoices.php b/models/admin/ajax/printInvoices.php index f7042ab..6a32d89 100644 --- a/models/admin/ajax/printInvoices.php +++ b/models/admin/ajax/printInvoices.php @@ -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 '
$where: ' . print_r( $where, true ) . '
'; // Get all invoices $invoiceData = $this->wpdb->get_results( @@ -114,6 +118,7 @@ class GlmMembersAdmin_ajax_printInvoices ARRAY_A ); // echo '
$invoiceData: ' . print_r( $invoiceData, true ) . '
'; + // exit; foreach ( $invoiceData as $inv ) { $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); if ( $fullInvoice ) { diff --git a/models/admin/billing/invoicing.php b/models/admin/billing/invoicing.php index 154418e..d1c4e4d 100644 --- a/models/admin/billing/invoicing.php +++ b/models/admin/billing/invoicing.php @@ -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 '
$where: ' . print_r( $where, true ) . '
'; // 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 '
$where: ' . print_r( $where, true ) . '
'; $accountsResult = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit ); $totalAccounts = $Accounts->getStats( $where ); $Accounts->paymentTypes = false; diff --git a/models/admin/billing/reports.php b/models/admin/billing/reports.php index c7e4feb..1bff06a 100644 --- a/models/admin/billing/reports.php +++ b/models/admin/billing/reports.php @@ -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 '
$where: ' . print_r( $where, true ) . '
'; // Getting the account listings $orderBy = 'member_name'; $Accounts->paymentTypes = true; diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index ba53e49..133b1aa 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -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 '
$test: ' . print_r( $test, true ) . '
'; break; } // Get the list of invoices for this member. - $statements = $BillingSupport->getStatementsByRefDest( $this->memberID ); + $statements = $BillingSupport->getStatementsByRefDest( $this->memberID, $allStatements ); // echo '
$statements: ' . print_r( $statements, true ) . '
'; if ( $statements ) { $transactions = $statements['transactions']; diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index 972392c..2f94d74 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -20,7 +20,7 @@ Billing Info
  • - All Statements + All Statements
  • {if ($account_status == 'Pending' || $account_status == 'Expired') && !apply_filters('glm-billing-account-has-renewal', true, $accountID )}
  • -- 2.17.1