Adding additional merge tags for the email notifications.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2019 19:14:39 +0000 (15:14 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2019 19:14:39 +0000 (15:14 -0400)
Adding Contacts fields.
Adding new billing fields.

classes/notifications.php
models/admin/member/billing.php
models/admin/settings/invoiceTypes.php
models/admin/settings/notificationTypes.php
views/admin/billing/memberBillingSubHeader.html
views/admin/billing/testNotice.html [new file with mode: 0644]
views/admin/settings/editNotificationType.html

index 5ecf746..f59bf92 100644 (file)
@@ -68,7 +68,7 @@ class GlmNotifications
      * @access public
      * @return void
      */
-    public function sendEmailNotification( $notification_id, $account_id, $data = null )
+    public function sendEmailNotification( $notification_id, $account_id, $data = null, $test = false )
     {
         // Support Class
         $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
@@ -79,6 +79,12 @@ class GlmNotifications
             return false;
         }
 
+        $currentAmount = false;
+        if ( $account['invoice_type'] ) {
+            $invTypeData   = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] );
+            $currentAmount = $invTypeData['amount'];
+        }
+
         // get the Notification type
         $notification_type = $this->getNotificationTypeById( $notification_id );
         if ( !$notification_type ) {
@@ -117,20 +123,44 @@ class GlmNotifications
         require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
         $viewFile = 'admin/notifications/notification.html';
 
+        $contactData = apply_filters( 'glm-member-db-contacts-get-contact-data-by-refdest', $account['ref_dest'] );
+
         $account_data = array(
-            'account' => array(
-                'name'       => $account['ref_name'],
-                'email'      => $account['email'],
-                'first_name' => $account['billing_fname'],
-                'last_name'  => $account['billing_lname'],
-                'addr1'      => $account['billing_addr1'],
-                'addr2'      => $account['billing_addr2'],
-                'city'       => $account['billing_city'],
-                'state'      => $account['billing_state'],
-                'zip'        => $account['billing_zip'],
-                'phone'      => $account['billing_phone'],
-            )
+            'account'          => array(
+                'name'         => $account['ref_name'],
+                'email'        => $account['email'],
+                'first_name'   => $account['billing_fname'],
+                'last_name'    => $account['billing_lname'],
+                'addr1'        => $account['billing_addr1'],
+                'addr2'        => $account['billing_addr2'],
+                'city'         => $account['billing_city'],
+                'state'        => $account['billing_state'],
+                'zip'          => $account['billing_zip'],
+                'phone'        => $account['billing_phone'],
+                'company'      => $account['billing_company'],
+                'position'     => $account['billing_position'],
+                'renewal_date' => isset( $account['renewal_date'] )
+                                    ? date( 'm/d/Y', strtotime( $account['renewal_date'] ) )
+                                    : '',
+                'current_due'  => $currentAmount,
+            ),
+            'contact' => array(
+                'company'      => $contactData['org'],
+                'fname'        => $contactData['business_fname'],
+                'lname'        => $contactData['business_lname'],
+                'position'     => $contactData['title'],
+                'addr1'        => $contactData['business_addr1'],
+                'addr2'        => $contactData['business_addr2'],
+                'city'         => $contactData['business_city'],
+                'state'        => $contactData['business_state']['value'],
+                'email'        => $contactData['business_email'],
+                'phone'        => $contactData['business_phone'],
+                'office_phone' => $contactData['office_phone'],
+                'mobile_phone' => $contactData['business_mobile'],
+                'fax'          => $contactData['fax'],
+            ),
         );
+        echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
         // Merge any data passed into this method
         $account_data['data'] = $data;
 
@@ -153,39 +183,45 @@ class GlmNotifications
         // Generate output from model data and view
         $htmlMessage = $smarty->template->fetch( $viewFile );
 
+        if ( $test ) {
+            echo $htmlMessage;
+        } else {
 
-        // change the default wordpress from name when sending mail
-        add_filter(
-            'wp_mail_from_name',
-            function ( $name ) {
-                $siteName = get_bloginfo( 'name' );
-                return $siteName;
+            // change the default wordpress from name when sending mail
+            add_filter(
+                'wp_mail_from_name',
+                function ( $name ) {
+                    $siteName = get_bloginfo( 'name' );
+                    return $siteName;
+                }
+            );
+            // Send confirmation email, set the content type to allow html by using this filter
+            add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+            $message  = $htmlMessage;
+            $header[] = 'From:' . $from_header;
+            if ( $replyto ) {
+                $header[] = 'Reply-To:' . $replyto;
             }
-        );
-        // Send confirmation email, set the content type to allow html by using this filter
-        add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
 
-        $message  = $htmlMessage;
-        $header[] = 'From:' . $from_header;
-        if ( $replyto ) {
-            $header[] = 'Reply-To:' . $replyto;
-        }
+            wp_mail( $to_email, $subject, $message, $header );
 
-        wp_mail( $to_email, $subject, $message, $header );
+            // remove the filter to avoid conflicts
+            remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
 
-        // remove the filter to avoid conflicts
-        remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+            // Send notification to recordNotification
+            $notice_data = array(
+                'notification_type' => $notification_id,
+                'account'           => $account_id,
+                'from_replyto'      => $from_header,
+                'subject'           => $subject,
+                'message'           => $message,
+                'email_sent'        => $to_email,
+            );
+            $this->recordNotification( $notice_data );
+
+        }
 
-        // Send notification to recordNotification
-        $notice_data = array(
-            'notification_type' => $notification_id,
-            'account'           => $account_id,
-            'from_replyto'      => $from_header,
-            'subject'           => $subject,
-            'message'           => $message,
-            'email_sent'        => $to_email,
-        );
-        $this->recordNotification( $notice_data );
     }
 
     /**
index 390a760..29cd5fb 100644 (file)
@@ -196,6 +196,21 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID );
 
         switch ( $option ) {
+        case 'testNotice':
+            $view = 'testNotice';
+            $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+            $accountID = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                       FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                      WHERE ref_dest = %d",
+                    $this->memberID
+                )
+            );
+            $Notifications->sendEmailNotification( 17, $accountID, null, true );
+
+            break;
+
         case 'renew':
             $view = 'renew';
 
index f31de07..3832f5d 100644 (file)
@@ -179,6 +179,8 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
             );
         }
 
+
+
         // Compile template data
         $templateData = array(
             'action'           => $_REQUEST['glm_action'],
index b596bd4..706fa2b 100644 (file)
@@ -242,7 +242,40 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType
                 'data'             => false
             );
         }
-
+        $mergeTagsBilling = array(
+            'Name of Account', '{$account.name}',
+            'Billing First Name', '{$account.fname}',
+            'Billing Last Name', '{$account.lname}',
+            'Billing Address Line 1', '{$account.addr1}',
+            'Billing Address Line 2', '{$account.addr2}',
+            'Billing City', '{$account.city}',
+            'Billing State', '{$account.state}',
+            'Billing Zip', '{$account.zip}',
+            'Billing Email', '{$account.email}',
+            'Billing Phone', '{$account.phone}',
+            'Billing Company', '{$account.company}',
+            'Billing Position', '{$account.position}',
+        );
+        $mergeTagsInvoice = array(
+            'Invoice Amount', '{$data.amount}',
+        );
+        $mergeTagsPayment = array(
+            'Payment Amount', '{$data.payment}',
+        );
+        $mergeTagsContact = array(
+            'Contact First Name', '{$contact.fname}',
+            'Contact Last Name', '{$contact.lname}',
+            'Contact Address Line 1', '{$contact.addr1}',
+            'Contact Address Line 2', '{$contact.addr2}',
+            'Contact City', '{$contact.city}',
+            'Contact State', '{$contact.state}',
+            'Contact Zip', '{$contact.zip}',
+            'Contact Company', '{$contact.company}',
+            'Contact Position', '{$contact.position}',
+            'Contact Email', '{$contact.email}',
+            'Contact Phone', '{$contact.office_phone}',
+            'Contact Mobile Phone', '{$contact.mobile_phone}',
+        );
         // Compile template data
         $templateData = array(
             'notification_id'         => $id,
@@ -258,6 +291,10 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType
             'send_date_period'        => $this->config['send_date_period'],
             'send_date_when'          => $this->config['send_date_when'],
             'send_action'             => $this->config['send_action'],
+            'mergeTagsBilling'        => $mergeTagsBilling,
+            'mergeTagsInvoice'        => $mergeTagsInvoice,
+            'mergeTagsPayment'        => $mergeTagsPayment,
+            'mergeTagsContact'        => $mergeTagsContact,
         );
 
         // Return status, suggested view, and data to controller
index e36a06b..14bbd41 100644 (file)
@@ -32,6 +32,9 @@
                     href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=makepayment"
                     class="">Pay Invoices</a>
             </li>
+            <li>
+                <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=testNotice" class="">Test Notices</a>
+            </li>
         </ul>
     </div>
 </div>
diff --git a/views/admin/billing/testNotice.html b/views/admin/billing/testNotice.html
new file mode 100644 (file)
index 0000000..7ea76d9
--- /dev/null
@@ -0,0 +1 @@
+<h2>Test Notices</h2>
index 5aa1b6b..26e5080 100644 (file)
@@ -1,3 +1,8 @@
+<style>
+    .merge-tags table caption {
+        font-weight: bold;
+    }
+</style>
 {include file='admin/settings/header.html'}
 
 {include file='admin/settings/subHeader.html'}
         </tr>
 
         <tr>
-            <td colspan="2">
+            <td colspan="2" class="merge-tags">
                 <h4>Merge Tags</h4>
                 <p>The "merge tags" listed below may be used in the E-Mail message content
                 to include certain information about the Account or Invoice. Be sure to
                 include the "{literal}{{/literal}" and "{literal}}{/literal}" and "$" characters exactly as show.</p>
-                <table>
-                    <tr>
-                        <th>{literal}{$account.name}{/literal}</th>
-                        <td>Name of Account</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.first_name}{/literal}</th>
-                        <td>Billing First Name</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.last_name}{/literal}</th>
-                        <td>Billing Last Name</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.addr1}{/literal}</th>
-                        <td>Billing Address 1</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.addr2}{/literal}</th>
-                        <td>Billing Address 2</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.city}{/literal}</th>
-                        <td>Billing City</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.state}{/literal}</th>
-                        <td>Billing State</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.zip}{/literal}</th>
-                        <td>Billing Zip</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.email}{/literal}</th>
-                        <td>Billing Email</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$account.phone}{/literal}</th>
-                        <td>Billing Phone</td>
-                    </tr>
-                    <tr>
-                        <td colspan="2">Only available using Immediate Action - Create Invoice</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$data.amount}{/literal}</th>
-                        <td>Invoice Amount</td>
-                    </tr>
-                    <tr>
-                        <td colspan="2">Only available using Immediate Action - Received Payment</td>
-                    </tr>
-                    <tr>
-                        <th>{literal}{$data.payment}{/literal}</th>
-                        <td>Payment Amount</td>
-                    </tr>
-                </table>
+
+                {html_table loop=$mergeTagsBilling cols=2 table_attr='border=0 width=400' caption='Billing Examples'}
+
+                {html_table loop=$mergeTagsContact cols=2 table_attr='border=0 width=400' caption='Contact Examples'}
+
+                {html_table loop=$mergeTagsInvoice cols=2 table_attr='border=0 width=400' caption='Only available using Immediate Action - Create Invoice'}
+
+                {html_table loop=$mergeTagsPayment cols=2 table_attr='border=0 width=400' caption='Only available using Immediate Action - Received Payment'}
+
+
             </td>
         </tr>