From: Steve Sutton Date: Wed, 5 Dec 2018 21:50:25 +0000 (-0500) Subject: Invoicing WIP pdf's label's X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8a3f2dad43b8db9757dc38ff89fb57fd6ca5d57a;p=WP-Plugins%2Fglm-member-db-billing.git Invoicing WIP pdf's label's WIP: create pdf in bulk create labels (WIP) Adding sub header to the invoicing for: create invoices print invoices create labels. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d183f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.phpcs.xml.dist +.travis.yml +bin/ +phpunit.xml.dist +tests/ diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 0853ffc..9a68719 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -730,6 +730,9 @@ class GlmBillingSupport public function getFullInvoiceData( $invoice_id ) { $invoice = $this->getInvoiceById( $invoice_id ); + if ( !$invoice ) { + return false; + } return array( 'invoice' => $invoice, 'line_items' => $this->getLineItemsForInvoice( $invoice_id ), diff --git a/lib/GlmPDFInvoice.php b/lib/GlmPDFInvoice.php index 8c8b403..7ca115f 100644 --- a/lib/GlmPDFInvoice.php +++ b/lib/GlmPDFInvoice.php @@ -1,15 +1,52 @@ + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/pdf-php/Cezpdf.php'; +/** + * This class extends the Cezpdf Ros PDF-PHP class + * + */ class GlmPDFInvoice extends Cezpdf { + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + public $pdf_top_y = 680; + public $pdf_lft_col_x = 20; + public $pdf_rgt_col_x = 380; + public $pdf_bottom_y = 130; + public $pdf_font_size = 12; + public $pdf_header_font_1 = 24; + public $pdf_header_font_2 = 20; + public $color_white = array( 1, 1, 1 ); - public function __construct( $p, $o ) { + public function __construct( $config, $p, $o ) { + // Save plugin configuration object + $this->config = $config; parent::__construct( $p, $o, 'none', array() ); } - // Rectangle Callback function for Text output + /** + * Rectangle Callback function for Text output + * + * @param $info mixed Array of data for the content + */ public function rect( $info ) { // this callback records all of the table of contents entries, it also places a destination marker there @@ -22,4 +59,400 @@ class GlmPDFInvoice extends Cezpdf } } + /** + * createPdf + * + * @param $invoices array Invoices is an array of billing invoices. + * + * @return mixed + */ + public function createPdf( $invoices ) + { + $this->setupPages(); + + $totalPdfs = count( $invoices ); + $pdfCounter = 0; + + foreach ( $invoices as $fullInvoice ) { + + $pdfCounter++; + + $invoice = $fullInvoice['invoice']; + $account = $fullInvoice['account']; + + $this->ezSetY( 745 ); + $this->ezText( 'INVOICE', $this->pdf_header_font_1, array( 'aright' => 550, 'justification' => 'right' ) ); + + $this->ezSetY( $this->pdf_top_y ); + + // Company Name + $companyNameSaveY = $this->ezText( '' . $this->config['settings']['company_name'] . '', $this->pdf_font_size ); + // Company Address + $this->ezText( + sprintf( + "%s\n%s, %s %s", + $this->config['settings']['company_addr1'], + $this->config['settings']['company_city'], + $this->config['settings']['company_state'], + $this->config['settings']['company_zip'] + ), + $this->pdf_font_size + ); + // Company Phone + $this->ezText( $this->config['settings']['company_phone'], $this->pdf_font_size ); + // Company Email + $endAddressSaveY = $this->ezText( $this->config['settings']['company_email'], $this->pdf_font_size ); + + // Right header for date and account # + $this->ezSetY( $companyNameSaveY ); + + // Add the Date of invoice and the member account number using ezTable. + $invoiceData = array( + array( 'header' => 'Date:', 'value' => date( 'm/d/Y', strtotime( $invoice['due_date'] ) ), 'headerFill' => $this->color_white, 'valueFill' => $this->color_white ), + array( 'header' => 'Member Billing #:', 'value' => $account['account_number'], 'headerFill' => $this->color_white, 'valueFill' => $this->color_white ) + ); + $this->ezTable( + $invoiceData, + array( 'header' => '', 'value' => '' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 0, + 'showLines' => 0, + 'width' => 200, + 'xPos' => 350, + 'xOrientation' => 'right', + ) + ); + + // Bill To header part. + $this->ezSetY( $endAddressSaveY ); + $this->ezText( '', $this->pdf_font_size ); + $this->ezText( 'Bill To:', $this->pdf_header_font_2 ); + // Billing Information. + $this->ezText( + sprintf( + "%s\n%s\n%s, %s %s", + $account['ref_name'], + $account['billing_addr1'], + $account['billing_city'], + $account['billing_state'], + $account['billing_zip'] + ), + $this->pdf_font_size + ); + $this->ezText( '', $this->pdf_font_size ); + + $invoiceLineItems = array(); + // Line Items (charges). + $lineItems = $fullInvoice['line_items']; + $item = false; + foreach ( $lineItems as &$item ) { + $invoiceLineItems[] = array( + 'created' => date( 'm/d/Y', strtotime( $item['created'] ) ), + 'name' => $item['name'], + 'amount' => '$'.$item['amount'], + 'createdFill' => $this->color_white, + 'nameFill' => $this->color_white, + 'amountFill' => $this->color_white, + ); + } + // Payments. + $payments = $fullInvoice['payments']; + $item = false; + foreach ( $payments as &$item ) { + $invoiceLineItems[] = array( + 'created' => date( 'm/d/Y', strtotime( $item['transaction_time'] ) ), + 'name' => 'Payment', + 'amount' => '-$'.$item['amount'], + 'createdFill' => $this->color_white, + 'nameFill' => $this->color_white, + 'amountFill' => $this->color_white, + ); + } + $this->ezText( '', $this->pdf_font_size ); + $this->ezText( '', $this->pdf_font_size ); + $this->ezTable( + $invoiceLineItems, + array( 'created' => 'Date', 'name' => 'Description', 'amount' => 'Rate' ), + '', + array( + 'showHeadings' => 1, + 'showLines' => 4, + 'width' => 560, + 'xPos' => 0, + 'xOrientation' => 'right', + 'cols' => array( + 'created' => array( 'width' => 100 ), + 'name' => array( 'width' => 380 ), + 'amount' => array( 'width' => 50, 'justification' => 'right' ), + ), + ) + ); + $invoiceTotal = array( + array( + 'created' => '', + 'name' => 'Total Amount Due', + 'amount' => '$'.$invoice['balance'] + ) + ); + $this->ezTable( + $invoiceTotal, + array( 'created' => 'Date', 'name' => 'Description', 'amount' => 'Rate' ), + '', + array( + 'showHeadings' => 0, + 'showLines' => 4, + 'width' => 560, + 'xPos' => 0, + 'xOrientation' => 'right', + 'cols' => array( + 'created' => array( 'width' => 100 ), + 'name' => array( 'width' => 380, 'justification' => 'right' ), + 'amount' => array( 'width' => 50, 'justification' => 'right' ), + ), + ) + ); + + // Payment Terms + $this->ezSetY( 220 ); + if ( $this->config['settings']['payment_terms'] ) { + $paymentTerms = array( + array( + 'terms' => $this->config['settings']['payment_terms'] + ) + ); + $this->ezTable( + $paymentTerms, + array( 'terms' => 'Payment Terms' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 1, + 'showLines' => 4, + 'width' => 530, + 'xPos' => 0, + 'xOrientation' => 'right', + ) + ); + } + + // Footer section. + $this->ezSetY( 165 ); + $this->ezText( 'Please return this coupon below with your payment', 10, array( 'justification' => 'center' ) ); + // Draw a dashed line + $this->setLineStyle( 1, '', '', array( 5, 10 ) ); + $this->line( 20, 150, 550, 150 ); + $this->setLineStyle( 1, null, null, array() ); + $this->ezSetY( 150 ); + $this->setColor( 1, 0, 0 ); + $this->ezText( 'Make checks payable to:', 10 ); + $this->setColor( 0, 0, 0, 1 ); + // Company Name + // Company Address + $this->ezText( + sprintf( + "%s\n%s, %s, %s %s\n%s - %s", + $this->config['settings']['company_name2'], + $this->config['settings']['company_addr1'], + $this->config['settings']['company_city'], + $this->config['settings']['company_state'], + $this->config['settings']['company_zip'], + $this->config['settings']['company_phone'], + $this->config['settings']['company_email'] + ), + $this->pdf_font_size + ); + $this->ezText( '', $this->pdf_font_size ); + // Billing Information. + $this->ezText( + sprintf( + "%s\n%s\n%s, %s %s", + $account['ref_name'], + $account['billing_addr1'], + $account['billing_city'], + $account['billing_state'], + $account['billing_zip'] + ), + $this->pdf_font_size + ); + $barCodeText = $account['account_number'] . '-' . $invoice['id']; + // $barCodeText = $account['account_number'] . '-3013'; + $code39RECT = $this->code39($barCodeText, 1, 30, 0, -5); + $barcode = ''; + foreach ($code39RECT as $v) { + $barcode .= ''; + // x position + width + if (($v['x'] + $v['b']) > $MAXcodeWidth) { + $MAXcodeWidth = $v['x'] + $v['b']; + } + } + $this->ezSetY( 130 ); + // $this->ezText( $barcode, $this->pdf_font_size, array( 'aright' => 335, 'justification' => 'right' ) ); + $barCode = array( + array( 'content' => $barcode ), + ); + $this->ezTable( + $barCode, + array( 'content' => 'barcode' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 0, + 'showLines' => 0, + 'width' => 250, + 'xPos' => 300, + 'xOrientation' => 'right', + 'cols' => array( + 'content' => array( 'width' => 250 ) + ), + ) + ); + $this->ezText( '', $this->pdf_font_size ); + $paymentForm1 = array( + array( 'header' => 'Please Pay:', 'value' => '$'.$invoice['balance'] ), + ); + $newY = $this->ezTable( + $paymentForm1, + array( 'header' => 'Header', 'value' => 'Value' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 0, + 'showLines' => 0, + 'width' => 230, + 'xPos' => 320, + 'xOrientation' => 'right', + 'cols' => array( 'header' => array( 'width' => 120,'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), + ) + ); + if ( $invoice['balance'] != '0.00' ) { + $paymentForm2 = array( + array( + 'header' => 'Payment Amount:', + 'value' => '___________', + 'headerFill' => $this->color_white, + 'valueFill' => $this->color_white, + ) + ); + $newY = $this->ezTable( + $paymentForm2, + array( 'header' => 'Header', 'value' => 'Value' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 0, + 'showLines' => 0, + 'width' => 230, + 'xPos' => 320, + 'xOrientation' => 'right', + 'cols' => array( 'header' => array( 'width' => 120,'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), + ) + ); + } else { + $newY = $this->ezText( '', $this->pdf_font_size ); + $newY = $this->addText( 375, $newY, 14, 'NO PAYMENT REQUIRED' ); + } + $paymentForm3 = array( + array( 'header' => 'Member Billing #:', 'value' => $account['account_number'] ), + ); + $this->ezTable( + $paymentForm3, + array( 'header' => 'Header', 'value' => 'Value' ), + '', + array( + 'fontSize' => 12, + 'showHeadings' => 0, + 'showLines' => 0, + 'width' => 230, + 'xPos' => 320, + 'xOrientation' => 'right', + 'cols' => array( 'header' => array( 'width' => 120, 'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), + ) + ); + + + + if ( $pdfCounter < $totalPdfs ) { + $this->ezNewPage(); + } + } + + // Output PDF + $this->ezStream(); + + } + + /** + * Setup the invoice graphic on top of all pages. + */ + public function setupPages() + { + $this->allowedTags .= '|rect:.*?'; + $this->setLineStyle( 1 ); + $this->ezSetMargins( 20, 20, 20, 20 ); + $this->selectFont( 'Helvetica' ); + + // Set header/footer of all pages + $all = $this->openObject(); + $this->saveState(); + $this->ezSetY( 775 ); + if ( $this->config['settings']['company_logo'] ) { + $this->ezImage( + GLM_MEMBERS_PLUGIN_MEDIA_PATH . '/images/large/' . $this->config['settings']['company_logo'], // image + 0, // padding + 260, // width + 'none', // resize + 'left', // justification + '', // angle + '' // array border + ); + } + $this->restoreState(); + $this->closeObject(); + $this->addObject( $all, 'all' ); + } + function code39( $text, $barcodethinwidth = 2, $barcodeheight = 40, $xpos = 0, $ypos = 0 ) + { + $barcodethickwidth = $barcodethinwidth * 3; + $codingmap = array( + '0' => '000110100', '1' => '100100001', + '2' => '001100001', '3' => '101100000', '4' => '000110001', + '5' => '100110000', '6' => '001110000', '7' => '000100101', + '8' => '100100100', '9' => '001100100', 'A' => '100001001', + 'B' => '001001001', 'C' => '101001000', 'D' => '000011001', + 'E' => '100011000', 'F' => '001011000', 'G' => '000001101', + 'H' => '100001100', 'I' => '001001100', 'J' => '000011100', + 'K' => '100000011', 'L' => '001000011', 'M' => '101000010', + 'N' => '000010011', 'O' => '100010010', 'P' => '001010010', + 'Q' => '000000111', 'R' => '100000110', 'S' => '001000110', + 'T' => '000010110', 'U' => '110000001', 'V' => '011000001', + 'W' => '111000000', 'X' => '010010001', 'Y' => '110010000', + 'Z' => '011010000', ' ' => '011000100', '$' => '010101000', + '%' => '000101010', '*' => '010010100', '+' => '010001010', + '-' => '010000101', '.' => '110000100', '/' => '010100010', + ); + $text = strtoupper( $text ); + $text = "*$text*"; // add start/stop chars. + $textlen = strlen( $text ); + $barcodewidth = ( $textlen ) * ( 7 * $barcodethinwidth + 3 * $barcodethickwidth ) - $barcodethinwidth; + for ( $idx = 0; $idx < $textlen; ++$idx ) { + $char = substr( $text, $idx, 1 ); + // make unknown chars a '-'; + if ( !isset( $codingmap[$char] ) ) { + $char = '-'; + } + for ( $baridx = 0; $baridx <= 8; ++$baridx ) { + $elementwidth = ( substr( $codingmap[$char], $baridx, 1 ) ) ? $barcodethickwidth : $barcodethinwidth; + if ( ( $baridx + 1 ) % 2 ) { + $rectangle[] = array( 'x' => $xpos, 'y' => $ypos, 'b' => $elementwidth, 'h' => $barcodeheight ); + } + $xpos += $elementwidth; + } + $xpos += $barcodethinwidth; + } + + return $rectangle; + } + } diff --git a/lib/GlmPDFLabel.php b/lib/GlmPDFLabel.php new file mode 100644 index 0000000..dc5b02e --- /dev/null +++ b/lib/GlmPDFLabel.php @@ -0,0 +1,111 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ +require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/pdf-php/Cezpdf.php'; + +/** + * This class extends the Cezpdf Ros PDF-PHP class + * + */ +class GlmPDFLabel extends Cezpdf +{ + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + public $pdf_top_y = 790; + public $pdf_bottom_y = 30; + public $pdf_font_size = 12; + public $pdf_header_font_1 = 24; + public $color_white = array( 1, 1, 1 ); + + public function __construct( $config, $p, $o ) { + // Save plugin configuration object + $this->config = $config; + parent::__construct( $p, $o, 'none', array() ); + } + + /** + * createPdf + * + * @param $invoices array Invoices is an array of billing invoices. + * + * @return mixed + */ + public function createPdf( $invoices ) + { + $this->setupPages(); + + $y = $this->pdf_top_y; + $this->ezSetY( $this->pdf_top_y ); + + $counter = 0; + foreach ( $invoices as $fullInvoice ) { + + $invoice = $fullInvoice['invoice']; + $account = $fullInvoice['account']; + + $counter++; + if ( $counter % 2 == 0 ) { + $y = $y += 45; + $this->ezSetY( $y ); + $option = array( + 'aleft' => 330, + ); + } else { + $y = $y -= 35; + $this->ezSetY( $y ); + $option = ''; + } + + $y = $this->ezText( + sprintf( + "%s\n%s\n%s, %s %s", + $account['ref_name'], + $account['billing_addr1'], + $account['billing_city'], + $account['billing_state'], + $account['billing_zip'] + ), + 12, + $option + ); + if ( $y <= $this->pdf_bottom_y && $counter % 2 == 0 ) { + $this->ezNewPage(); + $y =$this->pdf_top_y; + $this->ezSetY( $y ); + } + + } + + // Output PDF + $this->ezStream(); + + } + + /** + * Setup the invoice graphic on top of all pages. + */ + public function setupPages() + { + // $this->allowedTags .= '|rect:.*?'; + $this->setLineStyle( 1 ); + $this->ezSetMargins( 20, 20, 20, 20 ); + $this->selectFont( 'Helvetica' ); + + } +} diff --git a/models/admin/ajax/createPDFInvoice.php b/models/admin/ajax/createPDFInvoice.php index 7bb20b0..c3b99e3 100644 --- a/models/admin/ajax/createPDFInvoice.php +++ b/models/admin/ajax/createPDFInvoice.php @@ -88,380 +88,16 @@ class GlmMembersAdmin_ajax_createPDFInvoice echo 'failed to get invoice'; return false; } - // Get the account information. - $account = $fullInvoice['account']; - // PDF settings - $this->pdf_top_y = 725; - $this->pdf_width = 570; - $this->line_height = 10; - $this->pdf_lft_col_x = 20; - $this->pdf_rgt_col_x = 380; - $this->pdf_bottom_y = 130; - $this->pdf_font_size = 12; - $this->pdf_header_font_1 = 24; - $this->pdf_header_font_2 = 20; - $this->color_white = array( 1, 1, 1 ); - $this->color_red = array( 1, 0, 0 ); - $this->color_black = array( 0, 0, 0 ); + $invoices = array( $fullInvoice ); // Create pdf object - $pdf = new GlmPDFInvoice( 'a4', 'portrait' ); - $pdf->allowedTags .= '|rect:.*?'; - $pdf->setLineStyle( 1 ); - $pdf->ezSetMargins( 20, 20, 20, 20 ); - $pdf->selectFont( 'Helvetica' ); + $pdf = new GlmPDFInvoice( $this->config, 'LETTER', 'portrait' ); + $pdf->createPdf( $invoices ); - // Set header/footer of all pages - $all = $pdf->openObject(); - $pdf->saveState(); - $pdf->ezSetY( 827 ); - if ( $this->config['settings']['company_logo'] ) { - $pdf->ezImage( - GLM_MEMBERS_PLUGIN_MEDIA_PATH . '/images/large/' . $this->config['settings']['company_logo'], // image - 0, // padding - 260, // width - 'none', // resize - 'left', // justification - '', // angle - '' // array border - ); - } - $pdf->restoreState(); - $pdf->closeObject(); - $pdf->addObject( $all, 'all' ); - - $pdf->ezSetY( 785 ); - $pdf->ezText( 'INVOICE', $this->pdf_header_font_1, array( 'aright' => 550, 'justification' => 'right' ) ); - - $pdf->ezSetY( $this->pdf_top_y ); - - // Company Name - $companyNameSaveY = $pdf->ezText( '' . $this->config['settings']['company_name'] . '', $this->pdf_font_size ); - // Company Address - $pdf->ezText( - sprintf( - "%s\n%s, %s %s", - $this->config['settings']['company_addr1'], - $this->config['settings']['company_city'], - $this->config['settings']['company_state'], - $this->config['settings']['company_zip'] - ), - $this->pdf_font_size - ); - // Company Phone - $pdf->ezText( $this->config['settings']['company_phone'], $this->pdf_font_size ); - // Company Email - $endAddressSaveY = $pdf->ezText( $this->config['settings']['company_email'], $this->pdf_font_size ); - - // Right header for date and account # - $pdf->ezSetY( $companyNameSaveY ); - - // Add the Date of invoice and the member account number using ezTable. - $invoiceData = array( - array( 'header' => 'Date:', 'value' => date( 'm/d/Y', strtotime( $invoice['due_date'] ) ), 'headerFill' => $this->color_white, 'valueFill' => $this->color_white ), - array( 'header' => 'Member Billing #:', 'value' => $account['account_number'], 'headerFill' => $this->color_white, 'valueFill' => $this->color_white ) - ); - $pdf->ezTable( - $invoiceData, - array( 'header' => '', 'value' => '' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 0, - 'showLines' => 0, - 'width' => 200, - 'xPos' => 350, - 'xOrientation' => 'right', - ) - ); - - // Bill To header part. - $pdf->ezSetY( $endAddressSaveY ); - $pdf->ezText( '', $this->pdf_font_size ); - $pdf->ezText( 'Bill To:', $this->pdf_header_font_2 ); - // Billing Information. - $pdf->ezText( - sprintf( - "%s\n%s\n%s, %s %s", - $account['ref_name'], - $account['billing_addr1'], - $account['billing_city'], - $account['billing_state'], - $account['billing_zip'] - ), - $this->pdf_font_size - ); - - $invoiceLineItems = array(); - // Line Items (charges). - $lineItems = $fullInvoice['line_items']; - $item = false; - foreach ( $lineItems as &$item ) { - $invoiceLineItems[] = array( - 'created' => date( 'm/d/Y', strtotime( $item['created'] ) ), - 'name' => $item['name'], - 'amount' => $item['amount'], - ); - } - // Payments. - $payments = $fullInvoice['payments']; - $item = false; - foreach ( $payments as &$item ) { - $invoiceLineItems[] = array( - 'created' => date( 'm/d/Y', strtotime( $item['transaction_time'] ) ), - 'name' => 'Payment', - 'amount' => '-'.$item['amount'], - ); - } - $pdf->ezText( '', $this->pdf_font_size ); - $pdf->ezText( '', $this->pdf_font_size ); - $pdf->ezTable( - $invoiceLineItems, - array( 'created' => 'Date', 'name' => 'Description', 'amount' => 'Rate' ), - '', - array( - 'showHeadings' => 1, - 'showLines' => 4, - 'width' => 560, - 'xPos' => 0, - 'xOrientation' => 'right', - 'cols' => array( - 'created' => array( 'width' => 100 ), - 'name' => array( 'width' => 380 ), - 'amount' => array( 'width' => 50, 'justification' => 'right' ), - ), - ) - ); - $invoiceTotal = array( - array( - 'created' => '', - 'name' => 'Total Amount Due', - 'amount' => $invoice['balance'] - ) - ); - $pdf->ezTable( - $invoiceTotal, - array( 'created' => 'Date', 'name' => 'Description', 'amount' => 'Rate' ), - '', - array( - 'showHeadings' => 0, - 'showLines' => 4, - 'width' => 560, - 'xPos' => 0, - 'xOrientation' => 'right', - 'cols' => array( - 'created' => array( 'width' => 100 ), - 'name' => array( 'width' => 380, 'justification' => 'right' ), - 'amount' => array( 'width' => 50, 'justification' => 'right' ), - ), - ) - ); - - // Payment Terms - $pdf->ezSetY( 220 ); - if ( $this->config['settings']['payment_terms'] ) { - $paymentTerms = array( - array( - 'terms' => $this->config['settings']['payment_terms'] - ) - ); - $pdf->ezTable( - $paymentTerms, - array( 'terms' => 'Payment Terms' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 1, - 'showLines' => 4, - 'width' => 530, - 'xPos' => 0, - 'xOrientation' => 'right', - ) - ); - } - - // Footer section. - $pdf->ezSetY( 165 ); - $pdf->ezText( 'Please return this coupon below with your payment', 9, array( 'justification' => 'center' ) ); - // Draw a dashed line - $pdf->setLineStyle( 1, '', '', array( 5, 10 ) ); - $pdf->line( 20, 150, 550, 150 ); - $pdf->setLineStyle( 1, null, null, array() ); - $pdf->ezSetY( 150 ); - $pdf->setColor( 1, 0, 0 ); - $pdf->ezText( 'Make checks payable to:', 9 ); - $pdf->setColor( 0, 0, 0, 1 ); - // Company Name - // Company Address - $pdf->ezText( - sprintf( - "%s\n%s, %s, %s %s\n%s - %s", - $this->config['settings']['company_name2'], - $this->config['settings']['company_addr1'], - $this->config['settings']['company_city'], - $this->config['settings']['company_state'], - $this->config['settings']['company_zip'], - $this->config['settings']['company_phone'], - $this->config['settings']['company_email'] - ), - $this->pdf_font_size - ); - $pdf->ezText( '', $this->pdf_font_size ); - // Billing Information. - $pdf->ezText( - sprintf( - "%s\n%s\n%s, %s %s", - $account['ref_name'], - $account['billing_addr1'], - $account['billing_city'], - $account['billing_state'], - $account['billing_zip'] - ), - $this->pdf_font_size - ); - $barCodeText = $account['account_number'] . '-' . $invoice['id']; - // $barCodeText = $account['account_number'] . '-3013'; - $code39RECT = $this->code39($barCodeText, 1, 30, 0, -5); - $barcode = ''; - foreach ($code39RECT as $v) { - $barcode .= ''; - // x position + width - if (($v['x'] + $v['b']) > $MAXcodeWidth) { - $MAXcodeWidth = $v['x'] + $v['b']; - } - } - $pdf->ezSetY( 130 ); - // $pdf->ezText( $barcode, $this->pdf_font_size, array( 'aright' => 335, 'justification' => 'right' ) ); - $barCode = array( - array( 'content' => $barcode ), - ); - $pdf->ezTable( - $barCode, - array( 'content' => 'barcode' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 0, - 'showLines' => 0, - 'width' => 250, - 'xPos' => 300, - 'xOrientation' => 'right', - 'cols' => array( - 'content' => array( 'width' => 250 ) - ), - ) - ); - $pdf->ezText( '', $this->pdf_font_size ); - $paymentForm1 = array( - array( 'header' => 'Please Pay:', 'value' => $invoice['balance'] ), - ); - $newY = $pdf->ezTable( - $paymentForm1, - array( 'header' => 'Header', 'value' => 'Value' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 0, - 'showLines' => 0, - 'width' => 230, - 'xPos' => 320, - 'xOrientation' => 'right', - 'cols' => array( 'header' => array( 'width' => 120,'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), - ) - ); - if ( $invoice['balance'] != '0.00' ) { - $paymentForm2 = array( - array( - 'header' => 'Payment Amount:', - 'value' => '___________', - 'headerFill' => $this->color_white, - 'valueFill' => $this->color_white, - ) - ); - $newY = $pdf->ezTable( - $paymentForm2, - array( 'header' => 'Header', 'value' => 'Value' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 0, - 'showLines' => 0, - 'width' => 230, - 'xPos' => 320, - 'xOrientation' => 'right', - 'cols' => array( 'header' => array( 'width' => 120,'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), - ) - ); - } else { - $newY = $pdf->ezText( '', $this->pdf_font_size ); - $newY = $pdf->addText( 375, $newY, 14, 'NO PAYMENT REQUIRED' ); - } - $paymentForm3 = array( - array( 'header' => 'Member Billing #:', 'value' => $account['account_number'] ), - ); - $pdf->ezTable( - $paymentForm3, - array( 'header' => 'Header', 'value' => 'Value' ), - '', - array( - 'fontSize' => 12, - 'showHeadings' => 0, - 'showLines' => 0, - 'width' => 230, - 'xPos' => 320, - 'xOrientation' => 'right', - 'cols' => array( 'header' => array( 'width' => 120, 'justification' => 'right' ), 'value' => array( 'justification' => 'right' ) ), - ) - ); - - $pdf->ezStream(); } wp_die(); } - function code39( $text, $barcodethinwidth = 2, $barcodeheight = 40, $xpos = 0, $ypos = 0 ) - { - $barcodethickwidth = $barcodethinwidth * 3; - $codingmap = array( - '0' => '000110100', '1' => '100100001', - '2' => '001100001', '3' => '101100000', '4' => '000110001', - '5' => '100110000', '6' => '001110000', '7' => '000100101', - '8' => '100100100', '9' => '001100100', 'A' => '100001001', - 'B' => '001001001', 'C' => '101001000', 'D' => '000011001', - 'E' => '100011000', 'F' => '001011000', 'G' => '000001101', - 'H' => '100001100', 'I' => '001001100', 'J' => '000011100', - 'K' => '100000011', 'L' => '001000011', 'M' => '101000010', - 'N' => '000010011', 'O' => '100010010', 'P' => '001010010', - 'Q' => '000000111', 'R' => '100000110', 'S' => '001000110', - 'T' => '000010110', 'U' => '110000001', 'V' => '011000001', - 'W' => '111000000', 'X' => '010010001', 'Y' => '110010000', - 'Z' => '011010000', ' ' => '011000100', '$' => '010101000', - '%' => '000101010', '*' => '010010100', '+' => '010001010', - '-' => '010000101', '.' => '110000100', '/' => '010100010', - ); - $text = strtoupper( $text ); - $text = "*$text*"; // add start/stop chars. - $textlen = strlen( $text ); - $barcodewidth = ( $textlen ) * ( 7 * $barcodethinwidth + 3 * $barcodethickwidth ) - $barcodethinwidth; - for ( $idx = 0; $idx < $textlen; ++$idx ) { - $char = substr( $text, $idx, 1 ); - // make unknown chars a '-'; - if ( !isset( $codingmap[$char] ) ) { - $char = '-'; - } - for ( $baridx = 0; $baridx <= 8; ++$baridx ) { - $elementwidth = ( substr( $codingmap[$char], $baridx, 1 ) ) ? $barcodethickwidth : $barcodethinwidth; - if ( ( $baridx + 1 ) % 2 ) { - $rectangle[] = array( 'x' => $xpos, 'y' => $ypos, 'b' => $elementwidth, 'h' => $barcodeheight ); - } - $xpos += $elementwidth; - } - $xpos += $barcodethinwidth; - } - - return $rectangle; - } - } diff --git a/models/admin/ajax/createPDFLabels.php b/models/admin/ajax/createPDFLabels.php index 8eb36bc..6209f0e 100644 --- a/models/admin/ajax/createPDFLabels.php +++ b/models/admin/ajax/createPDFLabels.php @@ -14,7 +14,7 @@ */ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; -require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/GlmPDFInvoice.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/GlmPDFLabel.php'; /** * Steve Note @@ -74,77 +74,48 @@ class GlmMembersAdmin_ajax_createPDFLabels public function modelAction( $actionData = false ) { $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + if ( isset( $_REQUEST['invoice_types'] ) ) { - // Expect an array of member data with addresses. - - // PDF settings - $this->pdf_top_y = 725; - $this->pdf_width = 570; - $this->line_height = 10; - $this->pdf_lft_col_x = 20; - $this->pdf_rgt_col_x = 380; - $this->pdf_bottom_y = 130; - $this->pdf_font_size = 12; - $this->pdf_header_font_1 = 24; - $this->pdf_header_font_2 = 20; - $this->color_white = array( 1, 1, 1 ); - $this->color_red = array( 1, 0, 0 ); - $this->color_black = array( 0, 0, 0 ); - - // Create pdf object - $pdf = new GlmPDFInvoice( 'a4', 'portrait' ); - $pdf->allowedTags .= '|rect:.*?'; - $pdf->setLineStyle( 1 ); - $pdf->ezSetMargins( 20, 20, 20, 20 ); - $pdf->selectFont( 'Helvetica' ); - - $Invoice = new GlmDataInvoices( $this->wpdb, $this->config ); - $invoices = $Invoice->getList(); - - // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; - - $y = 830; - $pdf->ezSetY( $y ); - - $counter = 0; - foreach ( $invoices as $invoice ) { - $counter++; - if ( $counter % 2 == 0 ) { - $y = $y += 40; - $pdf->ezSetY( $y ); - $option = array( - 'aleft' => 330, - ); - } else { - $y = $y -= 30; - $pdf->ezSetY( $y ); - $option = ''; - } + $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 ) . ")"; + + } - // echo '
$invoice: ' . print_r( $invoice['account']['value'], true ) . '
'; - // Get account - $account = $BillingSupport->getAccountById( $invoice['account']['value'] ); - // echo '
$account: ' . print_r( $account, true ) . '
'; - $y = $pdf->ezText( - sprintf( - "%s\n%s\n%s, %s %s", - $account['ref_name'], - $account['billing_addr1'], - $account['billing_city'], - $account['billing_state'], - $account['billing_zip'] - ), - 12, - $option - ); - if ( $y <= 80 && $counter % 2 == 0 ) { - $pdf->ezNewPage(); - $y = 830; - $pdf->ezSetY( $y ); + $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 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 + ); + // echo '
$invoiceData: ' . print_r( $invoiceData, true ) . '
'; + foreach ( $invoiceData as $inv ) { + $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); + if ( $fullInvoice ) { + $invoices[] = $fullInvoice; } } - $pdf->ezStream(); + $pdf = new GlmPDFLabel( $this->config, 'LETTER', 'portrait' ); + $pdf->createPdf( $invoices ); wp_die(); } diff --git a/models/admin/ajax/printInvoices.php b/models/admin/ajax/printInvoices.php new file mode 100644 index 0000000..f7042ab --- /dev/null +++ b/models/admin/ajax/printInvoices.php @@ -0,0 +1,130 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/GlmPDFInvoice.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=printInvoices + * + * 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_printInvoices +{ + + /** + * 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 ) { + + $wParts = array( 'true' ); + + // $invoices + $invoices = array(); + + // Create Billing Support Object. + $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 ) "; + $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 + ); + // echo '
$invoiceData: ' . print_r( $invoiceData, true ) . '
'; + foreach ( $invoiceData as $inv ) { + $fullInvoice = $BillingSupport->getFullInvoiceData( $inv['id'] ); + if ( $fullInvoice ) { + $invoices[] = $fullInvoice; + } + } + // Create pdf object + $pdf = new GlmPDFInvoice( $this->config, 'LETTER', 'portrait' ); + $pdf->createPdf( $invoices ); + + wp_die(); + } + +} diff --git a/models/admin/billing/invoicing.php b/models/admin/billing/invoicing.php index 653cca1..fa34864 100644 --- a/models/admin/billing/invoicing.php +++ b/models/admin/billing/invoicing.php @@ -103,6 +103,7 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $numbDisplayed = false; $lastDisplayed = false; $totalAccounts = false; + $option2 = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -128,15 +129,35 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts } - // $where used in all places. - $where = implode( ' AND ', $wParts ); - if ( isset( $_REQUEST['submitType'] ) ) { $option2 = filter_var( $_REQUEST['submitType'], FILTER_SANITIZE_STRING ); - switch( $option2 ) { - case 'Create Invoices': + } + + // Do selected option + switch ($option) { + + case 'printInvoices': + $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 ) "; + break; + + case 'createLabels': + $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 ) "; + break; + + case 'createInvoices': + $view = 'invoicing'; + + if ( $option2 ) { $accounts = $Accounts->getSimpleAccountList( $where ); // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; foreach ( $accounts as $account ) { @@ -156,87 +177,79 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts ) ); } - - break; - case 'Print Invoices': - break; - case 'Send Invoices': - break; - default: - break; } - } - - // Do selected option - switch ($option) { + break; case 'list': default: $view = 'invoicing'; + break; - // Check if Counties is enabled and fetch counties - if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) { - // Grab counties - $counties = $this->wpdb->get_results( - "SELECT * - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties - ORDER BY name", - ARRAY_A - ); - } + } + + // $where used in all places. + $where = implode( ' AND ', $wParts ); - $paymentTypes = $BillingSupport->getAllInvoiceTypes(); + // Check if Counties is enabled and fetch counties + if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) { + // Grab counties + $counties = $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties + ORDER BY name", + ARRAY_A + ); + } + $paymentTypes = $BillingSupport->getAllInvoiceTypes(); - if (isset($_REQUEST['pageSelect'])) { - // If request is for Next - if ($_REQUEST['pageSelect'][0] == 'N') { - $newStart = $_REQUEST['nextStart'] - 0; - // Otherwise it must be Previous - } else { - $newStart = $_REQUEST['prevStart'] - 0; - } + if (isset($_REQUEST['pageSelect'])) { + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; - if ($newStart > 0) { - $start = $newStart; - } - } - $orderBy = 'member_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']; - if ( $start == 1 ) { - $prevStart = false; + // Otherwise it must be Previous } else { - $prevStart = $start - $limit; - if ( $start < 1 ) { - $start = 1; - } - } - if ( $accountsResult['returned'] == $limit ) { - $nextStart = $start + $limit; + $newStart = $_REQUEST['prevStart'] - 0; } - // since we're doing paging, we have to break out just the accounts data - $accounts = $accountsResult['list']; - // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; - if ( count( $accounts ) > 0 ) { - $haveAccounts = true; + if ($newStart > 0) { + $start = $newStart; } + } + $orderBy = 'member_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']; + if ( $start == 1 ) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ( $start < 1 ) { + $start = 1; + } + } + if ( $accountsResult['returned'] == $limit ) { + $nextStart = $start + $limit; + } - break; - + // since we're doing paging, we have to break out just the accounts data + $accounts = $accountsResult['list']; + // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; + if ( count( $accounts ) > 0 ) { + $haveAccounts = true; } + $templateData = array( 'option' => $option, 'paymentTypes' => $paymentTypes, diff --git a/setup/validActions.php b/setup/validActions.php index 4238fa3..9adf8bc 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -67,6 +67,7 @@ $glmMembersBillingAddOnValidActions = array( 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createPDFInvoice' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'printInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createPDFLabels' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'paymentsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/billing/invoicing.html b/views/admin/billing/invoicing.html index 16d4931..65fc3f7 100644 --- a/views/admin/billing/invoicing.html +++ b/views/admin/billing/invoicing.html @@ -1,13 +1,14 @@ {include file='admin/billing/header.html'} -{* include file='admin/billing/invoicingSubHeader.html' *} -

Invoicing

-
+{include file='admin/billing/invoicingSubHeader.html'} + + + - + @@ -41,8 +42,18 @@ {/if}
+ - + + {if $option == 'createInvoices'} + + {elseif $option == 'printInvoices'} + + {elseif $option == 'createLabels'} + + {/if} + +
@@ -70,7 +81,11 @@ {foreach $accounts as $t} - {$t.member_name} + + + {$t.member_name} + + {$t.account_number} {$t.payment_type} {$t.balance_due|string_format:"%.2f"} @@ -87,4 +102,21 @@
+ + {include file='admin/footer.html'} diff --git a/views/admin/billing/invoicingSubHeader.html b/views/admin/billing/invoicingSubHeader.html new file mode 100644 index 0000000..21296ec --- /dev/null +++ b/views/admin/billing/invoicingSubHeader.html @@ -0,0 +1,5 @@ + diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index 1076829..1b441da 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -120,13 +120,16 @@ Message: - {php} - wp_editor('{$notification.fieldData.message|escape:quotes}', 'glm_descr', array( - 'media_buttons' => false, - 'textarea_name' => 'message', - 'editor_height' => 200, - )); - {/php} + {wp_editor( + $notification.fieldData.message|escape:quotes, + 'glm_descr', + json_decode('{ + "media_buttons": false, + "quicktags": false, + "textarea_name": "message", + "editor_height": 200 + }', true) + )} {if $notification.fieldFail.message}

{$notification.fieldFail.message}

{/if}