require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
$viewFile = 'admin/notifications/notification.html';
+ // Get Contact Data
+ $contactData = apply_filters( 'glm-member-db-contacts-get-contact-data-by-refdest', $account['ref_dest'] );
+ if ( !$contactData ) {
+ $contactData = array(
+ 'org' => '',
+ 'business_fname' => '',
+ 'business_lname' => '',
+ 'title' => '',
+ 'business_addr1' => '',
+ 'business_addr2' => '',
+ 'business_city' => '',
+ 'business_state' => array( 'value' => '' ),
+ 'business_zip' => '',
+ 'business_email' => '',
+ 'business_phone' => '',
+ 'office_phone' => '',
+ 'business_mobile' => '',
+ 'fax' => '',
+ );
+ }
+
$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'],
+ 'zip' => $contactData['business_zip'],
+ '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>';
+ if ( $this->config['settings']['billing_contact_name_enabled'] ) {
+ $account_data['account']['contact_name'] = $account['billing_contact_name'];
+ } else {
+ $account_data['account']['first_name'] = $account['billing_fname'];
+ $account_data['account']['last_name'] = $account['billing_lname'];
+ }
// Merge any data passed into this method
$account_data['data'] = $data;
// 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;
- }
- );
- // 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' ) );
+ // 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;
- }
+ $message = $htmlMessage;
+ $header[] = 'From:' . $from_header;
+ if ( $replyto ) {
+ $header[] = 'Reply-To:' . $replyto;
+ }
- if ( !$attachments ) {
wp_mail( $to_email, $subject, $message, $header );
- } else {
- wp_mail( $to_email, $subject, $message, $header, $attachments );
- }
- // 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,
- );
- $type = 0;
- $type_id = 0;
- if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] ) {
- $type = $data['type'];
- $type_id = $data['type_id'];
++ if ( !$attachments ) {
++ wp_mail( $to_email, $subject, $message, $header );
++ } else {
++ wp_mail( $to_email, $subject, $message, $header, $attachments );
++ }
+ // 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 );
-
++ $type = 0;
++ $type_id = 0;
++ if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] ) {
++ $type = $data['type'];
++ $type_id = $data['type_id'];
++ }
++ $this->recordNotification( $notice_data, $type, $type_id );
}
- $this->recordNotification( $notice_data, $type, $type_id );
-
}
/**
$account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID );
switch ( $option ) {
+ case 'createInvoice':
+
+ $view = 'createInvoice';
+ $nextInvoiceDate = $BillingSupport->getNextInvoiceDate();
+ if ( $nextInvoiceDate ) {
+ $nextInvoiceDate = date( 'm/d/Y', $nextInvoiceDate );
+ }
+
+ // Get list of payable invoice_types
+ $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+
+ // Load DataClass for Management.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';
+ $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+ $management = $Management->getEntry( 1 );
+
+ // Need to see if there's an account for this member.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+ $account = $Accounts->editEntry( $accountID );
+ if ( $account && $account['fieldData'] ) {
+ $invoiceTypeId = $account['fieldData']['invoice_type'];
+
+ if ( $invoiceTypeId ) {
+ $member_invoice = $BillingSupport->getInvoiceTypeById( $invoiceTypeId );
+ }
+ }
+
+ $invoiceTypes = $BillingSupport->getAllPayableInvoiceTypes();
+
+ break;
+
+ case 'createNewInvoice':
+ $view = 'createInvoice';
+ $memberId = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
+ $accountId = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT );
+ $dynamicAmount = filter_var( $_REQUEST['dynamic_amount'], FILTER_VALIDATE_FLOAT );
+ $invoiceDate = filter_var( $_REQUEST['invoice_date'], FILTER_SANITIZE_STRING );
+
+ // Get tho account data
+ $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+ $account = $Accounts->editEntry( $accountID );
+ if ( $account && $account['fieldData']['invoice_type'] ) {
+ $invoiceTypeId = $account['fieldData']['invoice_type'];
+ } else {
+ $invoiceError = true;
+ $messages[] = 'No account Payment Type set!';
+ }
+
+ // Create an invoice w/line item for this accounts payment type
+ if ( $invoiceTypeId && $memberId && $accountId ) {
+ $invoiceData = $BillingSupport->getInvoiceTypeById( $invoiceTypeId );
+ // Amount maybe pro-rated
+ $amount = $BillingSupport->getProRatedPrice( $invoiceData, $invoiceDate, $dynamicAmount );
+ // Create invoice.
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+ array(
+ 'transaction_time' => date( 'Y-m-d H:i:s' ),
+ 'account' => $accountId,
+ 'amount_total' => $amount,
+ 'balance' => $amount,
+ 'due_date' => date( 'Y-m-d', strtotime( $invoiceDate ) ),
+ 'paid' => 0,
+ 'notes' => '',
+ 'renewal' => true,
+ 'recurring' => true,
+ 'recurrence' => 20
+ ),
+ array(
+ '%s', // transaction_time
+ '%d', // account
+ '%s', // amount
+ '%s', // balance
+ '%s', // due_date
+ '%s', // paid
+ '%s', // notes
+ '%s', // renewal
+ '%s', // recurring
+ '%s', // recurrence
+ )
+ );
+ $invoiceId = $this->wpdb->insert_id;
+ if ( $invoiceId && $accountId && $amount && $invoiceData && $invoiceDate ) {
+ $BillingSupport->createLineItemForInvoice(
+ array(
+ 'invoice_id' => $invoiceId,
+ 'line_item_type' => $invoiceData['id'],
+ 'account' => $accountId,
+ 'name' => $invoiceData['name'],
+ 'amount' => $amount,
+ 'due_date' => date( 'Y-m-d', strtotime( $invoiceDate ) ),
+ 'recurring' => $invoiceData['recurring'],
+ 'recurrence' => $invoiceData['recurrence'],
+ )
+ );
+ $BillingSupport->recordInvoice( $invoiceId, $accountId, $amount );
+ $invoiceSuccess = true;
+ }
+ } else {
+ $invoiceError = true;
+ $messages[] = 'Missing Invoice Data';
+ if ( !$invoiceTypeId ) {
+ $messages[] = 'Missing: Payment Type';
+ }
+ if ( !$memberId ) {
+ $messages[] = 'Missing: Member Id';
+ }
+ if ( !$accountId ) {
+ $messages[] = 'Missing: Account Id';
+ }
+ }
+
+ if ( $invoiceError ) {
+ $view = 'createInvoice';
+ $nextInvoiceDate = $BillingSupport->getNextInvoiceDate();
+ if ( $nextInvoiceDate ) {
+ $nextInvoiceDate = date( 'm/d/Y', $nextInvoiceDate );
+ }
+
+ // Get list of payable invoice_types
+ $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+
+ // Load DataClass for Management.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';
+ $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+ $management = $Management->getEntry( 1 );
+
+ // Need to see if there's an account for this member.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+ $account = $Accounts->editEntry( $accountID );
+ if ( $account && $account['fieldData'] ) {
+ $invoiceTypeId = $account['fieldData']['invoice_type'];
+
+ if ( $invoiceTypeId ) {
+ $member_invoice = $BillingSupport->getInvoiceTypeById( $invoiceTypeId );
+ }
+ }
+
+ $invoiceTypes = $BillingSupport->getAllPayableInvoiceTypes();
+ }
+
+ break;
+
+ 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';