From 98a94cb18d032b42df26609ecf49fd28a7c1a4fd Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Sun, 12 May 2019 12:36:32 -0400 Subject: [PATCH] Updating create labels. Labels should be grabbing the account data and creating labels even if they don't have invoices. --- lib/GlmPDFLabel.php | 10 ++-- models/admin/ajax/createPDFLabels.php | 53 ++++++++++++------- models/admin/billing/invoicing.php | 8 ++- models/admin/management/importBillingData.php | 2 +- models/admin/management/verifyBillingData.php | 2 +- views/admin/dashboard/billing.html | 18 ++++++- 6 files changed, 60 insertions(+), 33 deletions(-) diff --git a/lib/GlmPDFLabel.php b/lib/GlmPDFLabel.php index dd71e44..6197734 100644 --- a/lib/GlmPDFLabel.php +++ b/lib/GlmPDFLabel.php @@ -45,20 +45,20 @@ class GlmPDFLabel extends Cezpdf * * Printing for Avery 5161 labels. * - * @param $invoices array Invoices is an array of billing invoices. + * @param $accounts array Accounts is an array of billing accounts. * * @return mixed */ - public function createPdf( $invoices, $noContactNames = false ) + public function createPdf( $accounts, $noContactNames = false ) { $addresses = array(); - if ( $invoices ) { + if ( $accounts && is_array( $accounts ) && !empty( $accounts ) ) { $columnCount = 0; $rowCount = 0; - foreach ( $invoices as $invData ) { - $account = $invData['account']; + foreach ( $accounts as $account ) { + // $account = $invData['account']; $columnCount++; $colName = ( $columnCount % 2 == 0 ) ? 'col2' : 'col1'; $addressLine = ''; diff --git a/models/admin/ajax/createPDFLabels.php b/models/admin/ajax/createPDFLabels.php index fc00f47..15d8feb 100644 --- a/models/admin/ajax/createPDFLabels.php +++ b/models/admin/ajax/createPDFLabels.php @@ -95,34 +95,49 @@ class GlmMembersAdmin_ajax_createPDFLabels FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices WHERE paid <> true ) "; } else { - $wParts[] = " T.id IN ( - SELECT account - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices) "; + // $wParts[] = " T.id IN ( + // SELECT account + // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices) "; } - $wParts[] = " ( T.usmail_invoice OR T.fax_invoice ) "; + $wParts[] = " ( T.usmail_invoice = true OR T.fax_invoice = true ) "; // $where used in all places. $where = implode( ' AND ', $wParts ); + // echo '
$where: ' . print_r( $where, true ) . '
'; // Get all invoices - $invoiceData = $this->wpdb->get_results( - "SELECT I.id - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices I - LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts T ON (T.id = I.account) - WHERE $where - ORDER BY T.ref_name", - ARRAY_A - ); + // $invoiceData = $this->wpdb->get_results( + // "SELECT I.id + // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices I + // LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts T ON (T.id = I.account) + // WHERE $where + // ORDER BY T.ref_name", + // ARRAY_A + // ); // echo '
$invoiceData: ' . print_r( $invoiceData, true ) . '
'; - foreach ( $invoiceData as $inv ) { - $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); - if ( $fullInvoice ) { - $invoices[] = $fullInvoice; - } - } + + // Need to get accounts not invoices + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + + $orderBy = 'ref_name'; + $Accounts->paymentTypes = true; + $Accounts->balanceDue = true; + $accounts = $Accounts->getList( $where, $orderBy ); + $Accounts->paymentTypes = false; + $Accounts->balanceDue = false; + + // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; + // exit; + // foreach ( $invoiceData as $inv ) { + // $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); + // if ( $fullInvoice ) { + // $invoices[] = $fullInvoice; + // } + // } $pdf = new GlmPDFLabel( $this->config, 'LETTER', 'portrait' ); - $pdf->createPdf( $invoices, $noContactNames ); + $pdf->createPdf( $accounts, $noContactNames ); wp_die(); } diff --git a/models/admin/billing/invoicing.php b/models/admin/billing/invoicing.php index 0b9e619..154418e 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 OR paid IS NULL )"; + $notPaid = "( paid <> true ) AND balance != 0.00"; if ( isset( $_REQUEST['invoice_types'] ) ) { $invoiceTypes = $_REQUEST['invoice_types']; @@ -270,7 +270,6 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $paymentTypes = $BillingSupport->getAllInvoiceTypes(); - if (isset($_REQUEST['pageSelect'])) { // If request is for Next if ($_REQUEST['pageSelect'][0] == 'N') { @@ -285,13 +284,14 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $start = $newStart; } } - $orderBy = 'member_name'; + $orderBy = 'ref_name'; $Accounts->paymentTypes = true; $Accounts->balanceDue = true; $accountsResult = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit ); $totalAccounts = $Accounts->getStats( $where ); $Accounts->paymentTypes = false; $Accounts->balanceDue = false; + // Get paging results $numbDisplayed = $accountsResult['returned']; $lastDisplayed = $accountsResult['last']; @@ -314,8 +314,6 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $haveAccounts = true; } - - $templateData = array( 'option' => $option, 'paymentTypes' => $paymentTypes, diff --git a/models/admin/management/importBillingData.php b/models/admin/management/importBillingData.php index b6f9dc0..5191399 100644 --- a/models/admin/management/importBillingData.php +++ b/models/admin/management/importBillingData.php @@ -7,7 +7,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $limit = 10; -$dbConn = 'pgsql: host=ds5 dbname=uptravel user=postgres'; +$dbConn = 'pgsql: host=ds5.gaslightmedia.com dbname=uptravel user=postgres'; // $dbConn = 'pgsql: dbname=uptravel user=postgres'; // Connect to their live database. $dbh = new PDO( diff --git a/models/admin/management/verifyBillingData.php b/models/admin/management/verifyBillingData.php index a1c1ee8..82cbf1f 100644 --- a/models/admin/management/verifyBillingData.php +++ b/models/admin/management/verifyBillingData.php @@ -6,7 +6,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); // Connect to their live database. -$dbConn = 'pgsql: host=ds5 dbname=uptravel user=postgres'; +$dbConn = 'pgsql: host=ds5.gaslightmedia.com dbname=uptravel user=postgres'; // $dbConn = 'pgsql: dbname=uptravel user=postgres'; $dbh = new PDO( $dbConn, diff --git a/views/admin/dashboard/billing.html b/views/admin/dashboard/billing.html index cf2da4c..dc213c0 100644 --- a/views/admin/dashboard/billing.html +++ b/views/admin/dashboard/billing.html @@ -4,8 +4,22 @@ Billing Dashboard
- Membership Status: {$account_status} - {$billing_label} + {if $settings.member_types_enabled} + Membership Status: {$account_status} + {$billing_label} + {else} + + {/if}
-- 2.17.1