Updating the billing account page for contact name field.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Dec 2018 13:26:02 +0000 (08:26 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Dec 2018 13:26:02 +0000 (08:26 -0500)
Adding the contact name field into billing account edit page.
Add to import contact name field.

classes/data/dataAccounts.php
lib/GlmPDFInvoice.php
lib/GlmPDFLabel.php
models/admin/management/importAccounts.php
views/admin/billing/editAccount.html

index 632baae..c1d7044 100644 (file)
@@ -258,6 +258,14 @@ class GlmDataAccounts extends GlmDataAbstract
                 'required' => false,
             ),
 
+            // Billing First Name
+            'billing_contact_name' => array(
+                'field'    => 'billing_contact_name',
+                'type'     => 'text',
+                'use'      => 'a',
+                'required' => $billingFieldsRequired,
+            ),
+
             // Billing First Name
             'billing_fname' => array(
                 'field'    => 'billing_fname',
index 7ca115f..e12fa2e 100644 (file)
@@ -116,7 +116,7 @@ class GlmPDFInvoice extends Cezpdf
                 array( 'header' => '', 'value' => '' ),
                 '',
                 array(
-                    'fontSize'     => 12,
+                    'fontSize'     => $this->pdf_font_size,
                     'showHeadings' => 0,
                     'showLines'    => 0,
                     'width'        => 200,
@@ -133,7 +133,7 @@ class GlmPDFInvoice extends Cezpdf
             $this->ezText(
                 sprintf(
                     "%s\n%s\n%s, %s %s",
-                    $account['ref_name'],
+                    ( $account['billing_contact_name'] ) ? $account['ref_name'] . "\n" . $account['billing_contact_name'] : $account['ref_name'],
                     $account['billing_addr1'],
                     $account['billing_city'],
                     $account['billing_state'],
@@ -141,7 +141,7 @@ class GlmPDFInvoice extends Cezpdf
                 ),
                 $this->pdf_font_size
             );
-            $this->ezText( '', $this->pdf_font_size );
+            // $this->ezText( '', $this->pdf_font_size );
 
             $invoiceLineItems = array();
             // Line Items (charges).
@@ -227,7 +227,7 @@ class GlmPDFInvoice extends Cezpdf
                     array( 'terms' => '<b>Payment Terms</b>' ),
                     '',
                     array(
-                        'fontSize'     => 12,
+                        'fontSize'     => $this->pdf_font_size,
                         'showHeadings' => 1,
                         'showLines'    => 4,
                         'width'        => 530,
@@ -297,7 +297,7 @@ class GlmPDFInvoice extends Cezpdf
                 array( 'content' => 'barcode' ),
                 '',
                 array(
-                    'fontSize'     => 12,
+                    'fontSize'     => $this->pdf_font_size,
                     'showHeadings' => 0,
                     'showLines'    => 0,
                     'width'        => 250,
@@ -317,7 +317,7 @@ class GlmPDFInvoice extends Cezpdf
                 array( 'header' => 'Header', 'value' => 'Value' ),
                 '',
                 array(
-                    'fontSize'     => 12,
+                    'fontSize'     => $this->pdf_font_size,
                     'showHeadings' => 0,
                     'showLines'    => 0,
                     'width'        => 230,
@@ -340,7 +340,7 @@ class GlmPDFInvoice extends Cezpdf
                     array( 'header' => 'Header', 'value' => 'Value' ),
                     '',
                     array(
-                        'fontSize'     => 12,
+                        'fontSize'     => $this->pdf_font_size,
                         'showHeadings' => 0,
                         'showLines'    => 0,
                         'width'        => 230,
@@ -361,7 +361,7 @@ class GlmPDFInvoice extends Cezpdf
                 array( 'header' => 'Header', 'value' => 'Value' ),
                 '',
                 array(
-                    'fontSize'     => 12,
+                    'fontSize'     => $this->pdf_font_size,
                     'showHeadings' => 0,
                     'showLines'    => 0,
                     'width'        => 230,
index dc5b02e..ca63c80 100644 (file)
@@ -27,11 +27,12 @@ class GlmPDFLabel extends Cezpdf
      * @access public
      */
     public $config;
-    public $pdf_top_y         = 790;
+    public $pdf_top_y         = 765;
     public $pdf_bottom_y      = 30;
-    public $pdf_font_size     = 12;
+    public $pdf_font_size     = 11;
     public $pdf_header_font_1 = 24;
     public $color_white       = array( 1, 1, 1 );
+    public $label_width       = 270;
 
     public function __construct( $config, $p, $o ) {
         // Save plugin configuration object
@@ -48,48 +49,81 @@ class GlmPDFLabel extends Cezpdf
      */
     public function createPdf( $invoices )
     {
-        $this->setupPages();
+        $addresses = array();
 
-        $y = $this->pdf_top_y;
-        $this->ezSetY( $this->pdf_top_y );
+        if ( $invoices ) {
+            $columnCount = 0;
+            $rowCount    = 0;
+            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",
+                        '<b>'.$account['ref_name'].'</b>',
+                        $account['billing_addr1'],
+                        $account['billing_city'],
+                        $account['billing_state'],
+                        $account['billing_zip']
+                    );
+                    $rowCount++;
+                    $columnCount = 0;
+                } else {
+                    $addresses[$rowCount][0]['col1'] = sprintf(
+                        "%s\n%s\n%s, %s %s\n",
+                        '<b>'.$account['ref_name'].'</b>',
+                        $account['billing_addr1'],
+                        $account['billing_city'],
+                        $account['billing_state'],
+                        $account['billing_zip']
+                    );
+                }
+            }
+        }
+
+        // echo '<pre>$addresses: ' . print_r( $addresses, true ) . '</pre>';
+        // exit;
+
+        $labelPages = array_chunk( $addresses, 10 );
+        // echo '<pre>$labelPages: ' . print_r( $labelPages, true ) . '</pre>';
+        // exit;
 
-        $counter = 0;
-        foreach ( $invoices as $fullInvoice ) {
+        $this->setupPages();
 
-            $invoice = $fullInvoice['invoice'];
-            $account = $fullInvoice['account'];
+        $y = $this->pdf_top_y;
 
-            $counter++;
-            if ( $counter % 2 == 0 ) {
-                $y = $y += 45;
+        $pageData   = array();
+        $totalPages = count( $labelPages );
+        for ( $pageIndex = 0; $pageIndex < $totalPages; $pageIndex++ ) {
+            $totalOnPage = count( $labelPages[$pageIndex] );
+            $this->ezSetY( $y );
+            for ( $rowIndex = 0; $rowIndex < $totalOnPage; $rowIndex++ ) {
+                if ( $rowIndex == 0 ) {
+                    $y = $this->pdf_top_y;
+                } else {
+                    $y -= 75;
+                }
                 $this->ezSetY( $y );
-                $option = array(
-                    'aleft' => 330,
+                $this->ezTable(
+                    $labelPages[$pageIndex][$rowIndex],
+                    array( 'col1' => '', 'col2' => '' ),
+                    '',
+                    array(
+                        'fontSize'     => $this->pdf_font_size,
+                        'showHeadings' => 0,
+                        'showLines'    => 0,
+                        'rowGap'       => 2,
+                        'colGap'       => 5,
+                        'cols'         => array(
+                            'col1' => array( 'width' => $this->label_width + 15  ),
+                            'col2' => array( 'width' => $this->label_width  )
+                        )
+                    )
                 );
-            } else {
-                $y = $y -= 35;
-                $this->ezSetY( $y );
-                $option = '';
             }
-
-            $y = $this->ezText(
-                sprintf(
-                    "<b>%s</b>\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 ) {
+            if ( $pageIndex < $totalPages - 1 ) {
                 $this->ezNewPage();
-                $y =$this->pdf_top_y;
-                $this->ezSetY( $y );
             }
-
         }
 
         // Output PDF
index 9fedbb5..24b0764 100644 (file)
@@ -261,21 +261,22 @@ foreach ( $members as $member ) {
         }
 
         $accountData = array(
-            'ref_dest'        => $newMemberId,
-            'ref_name'        => $refName,
-            'invoice_type'    => $paymentTypeId,
-            'email'           => $member['email'],
-            'account_number'  => $member['account_number'],
-            'renewal_date'    => '2018-07-01',
-            'email_invoice'   => $member['email_invoice'],
-            'usmail_invoice'  => $member['usmail_invoice'],
-            'fax_invoice'     => $member['fax_invoice'],
-            'billing_company' => $member['member_name'],
-            'billing_addr1'   => $addr1,
-            'billing_city'    => $city,
-            'billing_state'   => $state,
-            'billing_zip'     => $zip,
-            'billing_county'  => $county,
+            'ref_dest'             => $newMemberId,
+            'ref_name'             => $refName,
+            'invoice_type'         => $paymentTypeId,
+            'email'                => $member['email'],
+            'account_number'       => $member['account_number'],
+            'renewal_date'         => '2018-07-01',
+            'email_invoice'        => $member['email_invoice'],
+            'usmail_invoice'       => $member['usmail_invoice'],
+            'fax_invoice'          => $member['fax_invoice'],
+            'billing_company'      => $member['member_name'],
+            'billing_contact_name' => $member['billing_contact'],
+            'billing_addr1'        => $addr1,
+            'billing_city'         => $city,
+            'billing_state'        => $state,
+            'billing_zip'          => $zip,
+            'billing_county'       => $county,
         );
         $accountDataFormat = array(
             '%d', // ref_dest
@@ -288,6 +289,7 @@ foreach ( $members as $member ) {
             '%d', // usmail_invoice
             '%d', // fax_invoice
             '%s', // billing_company
+            '%s', // billing_contact_name
             '%s', // billing_addr1
             '%s', // billing_city
             '%s', // billing_state
index b64012c..93bb167 100644 (file)
         </div>
 
 
-        <div class="glm-billing-field glm-billing-left-half">
-            <div class="glm-billing-label{if $account.fieldRequired.billing_fname} glm-required{/if}">Billing First Name</div>
-            <div class="glm-billing-input{if $account.fieldFail.billing_fname} glm-form-bad-input{/if}" data-tabid="glm-billing-fname">
-                <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" class="glm-form-text-input-medium"{if $account.fieldRequired.billing_fname} required{/if}>
-            {if $account.fieldFail.billing_fname}<p>{$account.fieldFail.billing_fname}</p>{/if}<br>
+        {if $settings.billing_contact_name_enabled}
+            <div class="glm-billing-field">
+                <div class="glm-billing-label{if $account.fieldRequired.billing_contact_name} glm-required{/if}">Billing Contact Name</div>
+                <div class="glm-billing-input{if $account.fieldFail.billing_contact_name} glm-form-bad-input{/if}" data-tabid="glm-billing-fname">
+                    <input type="text" name="billing_contact_name" value="{$account.fieldData.billing_contact_name}" class="glm-form-text-input-medium"{if $account.fieldRequired.billing_contact_name} required{/if}>
+                {if $account.fieldFail.billing_contact_name}<p>{$account.fieldFail.billing_contact_name}</p>{/if}<br>
+                </div>
+            </div>
+        {else}
+            <div class="glm-billing-field glm-billing-left-half">
+                <div class="glm-billing-label{if $account.fieldRequired.billing_fname} glm-required{/if}">Billing First Name</div>
+                <div class="glm-billing-input{if $account.fieldFail.billing_fname} glm-form-bad-input{/if}" data-tabid="glm-billing-fname">
+                    <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" class="glm-form-text-input-medium"{if $account.fieldRequired.billing_fname} required{/if}>
+                {if $account.fieldFail.billing_fname}<p>{$account.fieldFail.billing_fname}</p>{/if}<br>
+                </div>
             </div>
-        </div>
 
-        <div class="glm-billing-field glm-billing-right-half">
-            <div class="glm-billing-label{if $account.fieldRequired.billing_lname} glm-required{/if}">Billing Last Name</div>
-            <div class="glm-billing-input{if $account.fieldFail.billing_lname} glm-form-bad-input{/if}" data-tabid="glm-billing-lname">
-                <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" class="glm-form-text-input-medium"{if $account.fieldRequired.billing_lname} required{/if}>
-            {if $account.fieldFail.billing_lname}<p>{$account.fieldFail.billing_lname}</p>{/if}<br>
+            <div class="glm-billing-field glm-billing-right-half">
+                <div class="glm-billing-label{if $account.fieldRequired.billing_lname} glm-required{/if}">Billing Last Name</div>
+                <div class="glm-billing-input{if $account.fieldFail.billing_lname} glm-form-bad-input{/if}" data-tabid="glm-billing-lname">
+                    <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" class="glm-form-text-input-medium"{if $account.fieldRequired.billing_lname} required{/if}>
+                {if $account.fieldFail.billing_lname}<p>{$account.fieldFail.billing_lname}</p>{/if}<br>
+                </div>
             </div>
-        </div>
+        {/if}
 
         <div class="glm-billing-field glm-billing-left-half">
             <div class="glm-billing-label{if $account.fieldRequired.billing_addr1} glm-required{/if}">Billing Address 1</div>