From: Steve Sutton Date: Fri, 7 Dec 2018 19:00:38 +0000 (-0500) Subject: Updating invoice labels X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d5ffa2f29456eab0264d7b931cad9901cb879fd3;p=WP-Plugins%2Fglm-member-db-billing.git Updating invoice labels Invoice labels now printing. Invoice labels now export csv file. Adding todo.txt to keep track on work. --- diff --git a/lib/GlmPDFLabel.php b/lib/GlmPDFLabel.php index ca63c80..c66647d 100644 --- a/lib/GlmPDFLabel.php +++ b/lib/GlmPDFLabel.php @@ -29,7 +29,7 @@ class GlmPDFLabel extends Cezpdf public $config; public $pdf_top_y = 765; public $pdf_bottom_y = 30; - public $pdf_font_size = 11; + public $pdf_font_size = 10; public $pdf_header_font_1 = 24; public $color_white = array( 1, 1, 1 ); public $label_width = 270; @@ -47,8 +47,9 @@ class GlmPDFLabel extends Cezpdf * * @return mixed */ - public function createPdf( $invoices ) + public function createPdf( $invoices, $noContactNames = false ) { + $addresses = array(); if ( $invoices ) { @@ -57,30 +58,33 @@ class GlmPDFLabel extends Cezpdf foreach ( $invoices as $invData ) { $account = $invData['account']; $columnCount++; - if ( $columnCount % 2 == 0 ) { - $addresses[$rowCount][0]['col2'] = sprintf( - "%s\n%s\n%s, %s %s\n", - ''.$account['ref_name'].'', - $account['billing_addr1'], - $account['billing_city'], - $account['billing_state'], - $account['billing_zip'] + $colName = ( $columnCount % 2 == 0 ) ? 'col2' : 'col1'; + $addressLine = ''; + if ( $noContactNames || ( !$noContactNames && !$account['billing_contact_name'] ) ) { + $addressLine = $account['billing_addr1']; + } else if ( $account['billing_contact_name'] ) { + $addressLine = sprintf( + "%s\n%s", + $account['billing_contact_name'], + $account['billing_addr1'] ); + } + $addresses[$rowCount][0][$colName] = sprintf( + "%s\n%s\n%s, %s %s\n", + ''.$account['ref_name'].'', + $addressLine, + $account['billing_city'], + $account['billing_state'], + $account['billing_zip'] + ); + if ( $columnCount % 2 == 0 ) { $rowCount++; $columnCount = 0; - } else { - $addresses[$rowCount][0]['col1'] = sprintf( - "%s\n%s\n%s, %s %s\n", - ''.$account['ref_name'].'', - $account['billing_addr1'], - $account['billing_city'], - $account['billing_state'], - $account['billing_zip'] - ); } } } + // var_dump( $addresses[15][0]['col2'] ); // echo '
$addresses: ' . print_r( $addresses, true ) . '
'; // exit; diff --git a/models/admin/ajax/createCSVLabels.php b/models/admin/ajax/createCSVLabels.php new file mode 100644 index 0000000..45b53c0 --- /dev/null +++ b/models/admin/ajax/createCSVLabels.php @@ -0,0 +1,168 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; + +/** + * Steve Note + * + * You can get to this using the following URL. + * + * + {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue + * + * You should be able to do this as POST or GET and should be able to add and read additional parameters. + * I added a "mystuff" parameter to the URL above and it does output from the code in the + * modelAction() function below. + * + * To add another model under models/admin/ajax all you need to do is create it and add it to the + * setup/validActions.php file. + * + */ + +/** + * This class handles the work of creating new invoices based on. + * 1) Member Type of member matching a paid invoiceType + * 2) Member renewal date past + * 3) Member has Billing Account + * 4) Member has no active Invoice + * 5) Renewal date is within the next 30 Days + * + */ +class GlmMembersAdmin_ajax_createCSVLabels +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + public function modelAction( $actionData = false ) { + + $addresses = array(); + $fileHeaders = array( + 'Name', + 'Contact', + 'Address', + 'City', + 'State', + 'ZIP', + ); + + $noContactNames = false; + if ( isset( $_REQUEST['no_contact_name'] ) && filter_var( $_REQUEST['no_contact_name'], FILTER_VALIDATE_BOOLEAN ) ) { + $noContactNames = true; + } + + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + if ( isset( $_REQUEST['invoice_types'] ) ) { + $invoiceTypes = $_REQUEST['invoice_types']; + $wParts[] = " T.invoice_type IN (" . implode(',', $invoiceTypes) . ") "; + } + if ( isset( $_REQUEST['counties'] ) ) { + $countiesSelected = $_REQUEST['counties']; + $wParts[] = "T.billing_county IN (" . implode(',', $countiesSelected ) . ")"; + } + if ( isset( $_REQUEST['only_payment_due'] ) && filter_var( $_REQUEST['only_payment_due'], FILTER_VALIDATE_BOOLEAN ) ) { + $wParts[] = " T.id IN ( + SELECT account + 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.usmail_invoice OR T.fax_invoice ) "; + + // $where used in all places. + $where = implode( ' AND ', $wParts ); + + // 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 + ); + foreach ( $invoiceData as $inv ) { + $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); + if ( $fullInvoice ) { + $invoices[] = $fullInvoice; + } + } + + // Pull out only the address nifo for the file export. + if ( $invoices && is_array( $invoices ) && !empty( $invoices ) ) { + foreach ( $invoices as $invData ) { + $account = $invData['account']; + $addresses[] = array( + 'Name' => $account['ref_name'], + 'Contact' => ( $noContactNames ) ? '' : $account['billing_contact_name'], + 'Address' => $account['billing_addr1'], + 'City' => $account['billing_city'], + 'State' => $account['billing_state'], + 'ZIP' => $account['billing_zip'], + ); + } + } + + $fp = fopen( 'php://output', 'w' ); + fputcsv( $fp, $fileHeaders, ',', '"' ); + foreach ( $addresses as $address ) { + fputcsv( $fp, $address, ',', '"' ); + } + + // Setup headers for forcing a file download. + if (ini_get('zlib.output_compression')) { + ini_set('zlib.output_compression', 'Off'); + } + header("Content-Type: application/force-download\n"); + /* Correction for the stupid MSIE thing */ + $fileName = 'memberLabels-'.date('m-d-Y').'.csv'; + if (strstr(getenv('HTTP_USER_AGENT'), 'MSIE')) { + header("Content-Disposition: inline; filename=\"$fileName\""); + } else { + header("Content-Disposition: attachment; filename=\"$fileName\""); + } + fclose( $fp ); + + wp_die(); + } + +} diff --git a/models/admin/ajax/createPDFLabels.php b/models/admin/ajax/createPDFLabels.php index 6209f0e..dbcc961 100644 --- a/models/admin/ajax/createPDFLabels.php +++ b/models/admin/ajax/createPDFLabels.php @@ -73,25 +73,30 @@ class GlmMembersAdmin_ajax_createPDFLabels public function modelAction( $actionData = false ) { + $noContactNames = false; + if ( isset( $_REQUEST['no_contact_name'] ) && filter_var( $_REQUEST['no_contact_name'], FILTER_VALIDATE_BOOLEAN ) ) { + $noContactNames = true; + } + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); if ( isset( $_REQUEST['invoice_types'] ) ) { - $invoiceTypes = $_REQUEST['invoice_types']; $wParts[] = " T.invoice_type IN (" . implode(',', $invoiceTypes) . ") "; - } - if ( isset( $_REQUEST['counties'] ) ) { - $countiesSelected = $_REQUEST['counties']; $wParts[] = "T.billing_county IN (" . implode(',', $countiesSelected ) . ")"; - } - - $wParts[] = " T.id IN ( - SELECT account - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices - WHERE paid <> true ) "; + if ( isset( $_REQUEST['only_payment_due'] ) && filter_var( $_REQUEST['only_payment_due'], FILTER_VALIDATE_BOOLEAN ) ) { + $wParts[] = " T.id IN ( + SELECT account + 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.usmail_invoice OR T.fax_invoice ) "; // $where used in all places. @@ -115,7 +120,7 @@ class GlmMembersAdmin_ajax_createPDFLabels } $pdf = new GlmPDFLabel( $this->config, 'LETTER', 'portrait' ); - $pdf->createPdf( $invoices ); + $pdf->createPdf( $invoices, $noContactNames ); wp_die(); } diff --git a/models/admin/billing/invoicing.php b/models/admin/billing/invoicing.php index fa34864..863eb0f 100644 --- a/models/admin/billing/invoicing.php +++ b/models/admin/billing/invoicing.php @@ -147,10 +147,16 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts break; case 'createLabels': - $wParts[] = " T.id IN ( - SELECT account - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices - WHERE paid <> true ) "; + if ( isset( $_REQUEST['only_payment_due'] ) && filter_var( $_REQUEST['only_payment_due'], FILTER_VALIDATE_BOOLEAN ) ) { + $wParts[] = " T.id IN ( + SELECT account + 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.usmail_invoice OR T.fax_invoice ) "; break; diff --git a/setup/validActions.php b/setup/validActions.php index 9adf8bc..783dcf9 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -69,6 +69,7 @@ $glmMembersBillingAddOnValidActions = array( 'createPDFInvoice' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'printInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createPDFLabels' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'createCSVLabels' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'paymentsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'billingFlagExpiredUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..d726948 --- /dev/null +++ b/todo.txt @@ -0,0 +1,32 @@ +Uptra additions for Billing + +Additional features that need to be added to our billing plugin. + +Invoice type payment type with Dynamic amount. See how this was used. + +QIF (quickbooks) export? +qcode entry for payment type (numeric) + +Invoicing: +[x] Create Invoices (batch) +[x] - Filter by county and category or member type +[x] -Print Invoices (batch) +[x] -- Filter by county and category or member type +[x]-Create labels +[ ] -Send Email (invoices) + +Reports: +-Open Accounts +-Closed Accounts +-Account by Age +-Report Generator +-No Accounts +-All Accounts + +[x] Make Payment:(might already be done) +Donna used the payment form from the member edit section. + +NOTES: +Update the account list pages so they show what number and total results are being shown. +Maybe sortable by the headers. +[x] Column for boss/employees should check the employee option from management first. diff --git a/views/admin/billing/invoicing.html b/views/admin/billing/invoicing.html index 65fc3f7..c4de3d2 100644 --- a/views/admin/billing/invoicing.html +++ b/views/admin/billing/invoicing.html @@ -1,24 +1,17 @@ {include file='admin/billing/header.html'} -

Invoicing

- {include file='admin/billing/invoicingSubHeader.html'} -
- -
{if $paymentTypes}
-
-
{/if} - {if $counties}
-
- -
{/if} - + {if $option == 'createLabels'} +
+
+ + + +
+ {/if}
- - {if $option == 'createInvoices'} {elseif $option == 'printInvoices'} @@ -52,23 +55,17 @@ {elseif $option == 'createLabels'} {/if} - -
-


Total found: {$totalAccounts}

- {* Paging *} {if $paging} {/if} -
-
@@ -93,15 +90,12 @@ {/foreach}
- {* Paging *} {if $paging} {/if} -
- - {include file='admin/footer.html'}