From: Steve Sutton Date: Thu, 21 Mar 2019 20:37:54 +0000 (-0400) Subject: Send email working X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=712a7a3d303e8a4ab5ad4c7a8b6b32f49a8dae16;p=WP-Plugins%2Fglm-member-db-billing.git Send email working Can now send invoice from invoice page. Can now select email for send email page in invoicing. --- diff --git a/models/admin/ajax/invoices.php b/models/admin/ajax/invoices.php index 16b0e99..ebbb377 100644 --- a/models/admin/ajax/invoices.php +++ b/models/admin/ajax/invoices.php @@ -84,6 +84,34 @@ class GlmMembersAdmin_ajax_invoices extends GlmDataInvoices trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) ); switch ( $option ) { + + case 'invoice_methods': + $invoice_id = false; + $member_id = false; + $account_id = false; + // Get invoice method for a member account + if ( isset( $_REQUEST['invoice_id'] ) ) { + $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT ); + } + if ( isset( $_REQUEST['member_id'] ) ) { + $member_id = filter_var( $_REQUEST['member_id'], FILTER_VALIDATE_INT ); + } + if ( isset( $_REQUEST['account_id'] ) ) { + $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ); + } + + $email_invoice_method = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT email_invoice + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE id = %d", + $account_id + ) + ); + $return = $email_invoice_method; + + break; + case 'list': default: $account = filter_var( $_REQUEST['account'], FILTER_VALIDATE_INT ); diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index f281205..31a003f 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -18,6 +18,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoiceTypes.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php'; class GlmMembersAdmin_billing_invoices extends GlmDataInvoices { @@ -133,6 +134,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $counties = false; $paymentTypes = false; $invoiceTypes = false; + $invoiceSent = false; // Get any provided option if (isset($_REQUEST['option'])) { @@ -141,6 +143,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // Do selected option switch ($option) { + case 'bulkadd': $view = 'bulkAddInvoices'; $wParts = array(); @@ -512,6 +515,45 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoiceDeleteError = true; } + case 'send_invoice': + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + + $invoice_id = false; + $member_id = false; + $account_id = false; + + $type = $this->config['transaction_numb']['Invoice']; + + // Get invoice method for a member account + if ( isset( $_REQUEST['invoice_id'] ) ) { + $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT ); + } + if ( isset( $_REQUEST['member_id'] ) ) { + $member_id = filter_var( $_REQUEST['member_id'], FILTER_VALIDATE_INT ); + } + if ( isset( $_REQUEST['account_id'] ) ) { + $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ); + } + + if ( $invoice_id && $member_id && $account_id ) { + $Notifications = new GlmNotifications( $this->wpdb, $this->config ); + $invoice = $BillingSupport->getInvoiceById( $invoice_id ); + $invoice_total = $invoice['balance']; + $data = array( + 'type' => $type, + 'type_id' => $invoice_id, + 'account' => $account_id, + 'amount' => $invoice_total, + 'payment' => 0, + ); + $notices = $Notifications->getNotificationsWithSendByAction( $type ); + foreach ( $notices as $notice ) { + $Notifications->sendEmailNotification( $notice['id'], $account_id, $data ); + } + } + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + $invoiceSent = true; + case 'list': default: @@ -667,6 +709,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'counties' => $counties, 'paymentTypes' => $paymentTypes, 'billing_settings' => $this->config['billing_settings'], + 'invoiceSent' => $invoiceSent, ); // Return status, any suggested view, and any data to controller diff --git a/models/admin/billing/invoicing.php b/models/admin/billing/invoicing.php index e52c622..0de351f 100644 --- a/models/admin/billing/invoicing.php +++ b/models/admin/billing/invoicing.php @@ -88,23 +88,24 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts public function modelAction($actionData = false) { - $haveAccounts = false; - $option = 'list'; - $view = 'invoicing'; - $wParts = array( 'true' ); - $paymentTypes = false; - $counties = false; - $accounts = false; - $paging = true; - $prevStart = false; - $nextStart = false; - $start = 1; - $limit = 20; // Set to the number of listings per page - $numbDisplayed = false; - $lastDisplayed = false; - $totalAccounts = false; - $option2 = false; - $successMsg = false; + $haveAccounts = false; + $option = 'list'; + $view = 'invoicing'; + $wParts = array( 'true' ); + $paymentTypes = false; + $counties = false; + $accounts = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $numbDisplayed = false; + $lastDisplayed = false; + $totalAccounts = false; + $option2 = false; + $successMsg = false; + $notification_types = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -196,7 +197,9 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts case 'sendEmails': // Create Notification Object - $Notifications = new GlmNotifications( $this->wpdb, $this->config ); + $Notifications = new GlmNotifications( $this->wpdb, $this->config ); + $NotificationTypes = new GlmDataNotificationTypes( $this->wpdb, $this->config ); + $notification_types = $NotificationTypes->getList(); $view = 'invoicing'; $wParts[] = " T.id IN ( @@ -208,30 +211,34 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $type = $this->config['transaction_numb']['Invoice']; if ( $option2 ) { - $where = implode( ' AND ', $wParts ); - $accounts = $Accounts->getSimpleAccountList( $where ); - // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; - foreach ( $accounts as $account ) { - $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['id'] ); - // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; - if ( isset( $invoices ) && is_array( $invoices ) && !empty( $invoices ) ) { - foreach ( $invoices as $invoice ) { - $data = array( - 'type' => $type, - 'type_id' => $invoice['id'] - ); - $notices = $Notifications->getNotificationsWithSendByAction( $this->config['send_action_numb']['Send Emails'] ); - // echo '
$notices: ' . print_r( $notices, true ) . '
'; - if ( isset( $notices ) && is_array( $notices ) && !empty( $notices ) ) { - foreach ( $notices as $notice ) { - $Notifications->sendEmailNotification( $notice['id'], $account['id'], $data ); - echo '

Sending emails

'; - } + $notification_id = false; + if ( isset( $_REQUEST['notification_id'] ) && $notification_id = filter_var( $_REQUEST['notification_id'], FILTER_VALIDATE_INT ) ) { + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + $where = implode( ' AND ', $wParts ); + $accounts = $Accounts->getSimpleAccountList( $where ); + // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; + foreach ( $accounts as $account ) { + $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['id'] ); + // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; + if ( isset( $invoices ) && is_array( $invoices ) && !empty( $invoices ) ) { + foreach ( $invoices as $invoice ) { + $data = array( + 'type' => $type, + 'type_id' => $invoice['id'], + 'account' => account['id'], + 'amount' => $invoice['balance'], + 'payment' => 0, + ); + + $Notifications->sendEmailNotification( $notification_id, $account['id'], $data ); + } } } + $successMsg = 'Invoices Sent'; + } else { + $successMsg = 'Nothing Sent'; } - $successMsg = 'Invoices Sent'; } break; @@ -307,20 +314,21 @@ class GlmMembersAdmin_billing_invoicing //extends GlmDataAccounts $templateData = array( - 'option' => $option, - 'paymentTypes' => $paymentTypes, - 'counties' => $counties, - 'accounts' => $accounts, - 'paging' => $paging, - 'prevStart' => $prevStart, - 'nextStart' => $nextStart, - 'start' => $start = 1, - 'limit' => $limit, - 'haveAccounts' => $haveAccounts, - 'numbDisplayed' => $numbDisplayed, - 'lastDisplayed' => $lastDisplayed, - 'totalAccounts' => $totalAccounts, - 'successMsg' => $successMsg, + 'option' => $option, + 'paymentTypes' => $paymentTypes, + 'counties' => $counties, + 'accounts' => $accounts, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start = 1, + 'limit' => $limit, + 'haveAccounts' => $haveAccounts, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'totalAccounts' => $totalAccounts, + 'successMsg' => $successMsg, + 'notification_types' => $notification_types, ); // Return status, any suggested view, and any data to controller diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index 25aef87..260399c 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -5,6 +5,8 @@

Invoices

+{if $invoiceSent}

Invoice Sent

{/if} +
@@ -47,6 +49,7 @@ {/if}
+ {debug}
@@ -90,6 +93,12 @@ {if $t.paid.value}   {else} + Send Invoice | {if isset( $settings.uptravel_payment_form ) && $settings.uptravel_payment_form} Make A Payment | {else} @@ -115,11 +124,86 @@ {/if} + + +
+
+ + + + + + Send an invoice to
+ Email Invoice Status
+
diff --git a/views/admin/billing/invoicing.html b/views/admin/billing/invoicing.html index a8f2bdd..988f4e0 100644 --- a/views/admin/billing/invoicing.html +++ b/views/admin/billing/invoicing.html @@ -47,6 +47,19 @@ {/if} + {if $option == 'sendEmails'} +
+
+ {if $notification_types} + {foreach $notification_types as $notice} + + {/foreach} + {/if} +
+ {/if}
{if $option == 'createInvoices'}