Can now send invoice from invoice page.
Can now select email for send email page in invoicing.
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 );
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
{
$counties = false;
$paymentTypes = false;
$invoiceTypes = false;
+ $invoiceSent = false;
// Get any provided option
if (isset($_REQUEST['option'])) {
// Do selected option
switch ($option) {
+
case 'bulkadd':
$view = 'bulkAddInvoices';
$wParts = array();
$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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $invoiceSent = true;
+
case 'list':
default:
'counties' => $counties,
'paymentTypes' => $paymentTypes,
'billing_settings' => $this->config['billing_settings'],
+ 'invoiceSent' => $invoiceSent,
);
// Return status, any suggested view, and any data to controller
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'] ) ) {
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 (
$type = $this->config['transaction_numb']['Invoice'];
if ( $option2 ) {
- $where = implode( ' AND ', $wParts );
- $accounts = $Accounts->getSimpleAccountList( $where );
- // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
- foreach ( $accounts as $account ) {
- $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['id'] );
- // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
- 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 '<pre>$notices: ' . print_r( $notices, true ) . '</pre>';
- if ( isset( $notices ) && is_array( $notices ) && !empty( $notices ) ) {
- foreach ( $notices as $notice ) {
- $Notifications->sendEmailNotification( $notice['id'], $account['id'], $data );
- echo '<p>Sending emails</p>';
- }
+ $notification_id = false;
+ if ( isset( $_REQUEST['notification_id'] ) && $notification_id = filter_var( $_REQUEST['notification_id'], FILTER_VALIDATE_INT ) ) {
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $where = implode( ' AND ', $wParts );
+ $accounts = $Accounts->getSimpleAccountList( $where );
+ // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+ foreach ( $accounts as $account ) {
+ $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['id'] );
+ // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
+ 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;
$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
<h2>Invoices</h2>
+{if $invoiceSent}<p><span class="glm-notice glm-flash-updated">Invoice Sent</span></p>{/if}
+
<form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
<input type="hidden" name="glm_action" value="invoices">
<input type="hidden" name="option" value="list">
{/if}
<br clear="all">
+ {debug}
<div class="glm-admin-table-inner">
<table class="wp-list-table widefat fixed posts glm-admin-table">
<thead>
{if $t.paid.value}
{else}
+ <a class="send-invoice-link" href="#"
+ data-id="{$t.id}"
+ data-member="{$t.member_id}"
+ data-account="{$t.account.value}"
+ data-member_name="{$t.member_name}"
+ >Send Invoice</a> |
{if isset( $settings.uptravel_payment_form ) && $settings.uptravel_payment_form}
<a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&option=makepaymentadjustment&member={$t.member_id}">Make A Payment</a> |
{else}
<input type="Submit" name="pageSelect" value="Next {$limit} Invoices" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
{/if}
+</form>
+
+<div id="send-invoice-form" title="Send Invoice">
+ <form id="invoice-form" action="{$thisUrl}?page={$thisPage}" method="post">
+ <input type="hidden" name="glm_action" value="invoices" />
+ <input type="hidden" name="option" value="send_invoice" />
+ <input type="hidden" id="invoice_id" name="invoice_id" value="" />
+ <input type="hidden" id="member_id" name="member_id" value="" />
+ <input type="hidden" id="account_id" name="account_id" value="" />
+ Send an invoice to <span id="member_name"></span><br>
+ Email Invoice Status <span id="email_invoice"></span><br>
</form>
+</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
+ function sendInvoice() {
+ var valid = true;
+
+ if ( valid ) {
+ $('#invoice-form').submit();
+ }
+
+ return valid;
+ }
+
+ dialog = $('#send-invoice-form').dialog({
+ autoOpen: false,
+ height: 200,
+ width: 350,
+ modal: true,
+ buttons: {
+ "Send Invoice": sendInvoice,
+ Cancel: function () {
+ dialog.dialog( 'close' );
+ }
+ },
+ close: function() {
+ // $('#send-invoice-form').reset();
+ }
+ });
+
+ $('.send-invoice-link').on('click', function(e){
+ e.preventDefault();
+
+ var invoice_id = $(this).data( 'id' );
+ var member_id = $(this).data( 'member' );
+ var account_id = $(this).data( 'account' );
+ var member_name = $(this).data( 'member_name' );
+
+ $('#invoice_id').val( invoice_id );
+ $('#member_id').val( member_id );
+ $('#account_id').val( account_id );
+ $('#member_name').html( '<b>' + member_name + '</b>' );
+
+ // Call ajax invoice api to see if this member has email_invoice set
+ $.ajax({
+ url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=invoices&option=invoice_methods',
+ cache: false,
+ type: 'POST',
+ data: {
+ member_id: member_id,
+ account_id: account_id,
+ invoice_id: invoice_id
+ },
+ encode: true,
+ dataType: 'json'
+ }).done(function(msg){
+ if ( msg === '0' ) {
+ $('#email_invoice').html( '<b style="color: red;">Off</b>' );
+ } else {
+ $('#email_invoice').html( '<b style="color: green;">On</b>' );
+ }
+ });
+
+
+ dialog.dialog( 'open' );
+ });
+
var invoiceHoverId = false;
$('.glm-invoice-row').mouseenter( function(){
$('#account_name').autocomplete().val('{$selected}');
{/if}
+ // Flash certain elements for a short time after display
+ $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
});
</script>
</label>
</div>
{/if}
+ {if $option == 'sendEmails'}
+ <div style="width:300px;float:left;">
+ <label>Email Notification:</label><br>
+ {if $notification_types}
+ {foreach $notification_types as $notice}
+ <label>
+ <input class="labelOption" type="radio" name="notification_id" value="{$notice.id}" required>
+ {$notice.name}<br>
+ </label>
+ {/foreach}
+ {/if}
+ </div>
+ {/if}
<div style="width:400px; height: 30px;">
<input type="submit" value="Filter">
{if $option == 'createInvoices'}