--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoiceTypes.php';
+// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberTypes.php';
+
+/**
+ * Steve Note
+ *
+ * You can get to this using the following URL.
+ *
+ *
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+/**
+ * This class handles the work of creating new invoices based on.
+ * 1) Member Type of member matching a paid invoiceType
+ * 2) Member renewal date past
+ * 3) Member has Billing Account
+ * 4) Member has no active Invoice
+ * 5) Renewal date is within the next 30 Days
+ *
+ */
+class GlmMembersAdmin_ajax_createNewInvoices
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ public function modelAction( $actionData = false ) {
+ // Get list of member billing accounts based on memberTypes that match invoiceTypes
+ // InvoiceTypes
+ $invoiceTypes = $this->getInvoiceTypes();
+
+ // MemberTypes
+ $memberTypes = $this->getMemberTypes();
+
+ // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
+
+ // echo '<pre>$memberTypes: ' . print_r( $memberTypes, true ) . '</pre>';
+
+ $accounts = $this->getListOfAccountsPayable();
+
+ echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+
+ wp_die();
+ }
+
+ public function getInvoiceTypes()
+ {
+ return $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+ ORDER BY name",
+ ARRAY_A
+ );
+ }
+
+ public function getMemberTypes()
+ {
+ return $this->wpdb->get_results(
+ "SELECT IT.id,MT.id as member_type,IT.name,IT.amount,IT.recurrence
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_type MT
+ LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types IT
+ ON (MT.id = IT.member_type)
+ WHERE IT.amount > 0
+ AND IT.recurring = true
+ AND IT.recurrence = 20",
+ ARRAY_A
+ );
+ }
+
+ public function getListOfAccountsPayable()
+ {
+ $types = $this->getMemberTypes();
+ $memberTypes = array();
+ foreach ( $types as $type ) {
+ $memberTypes[] = $type['member_type'];
+ }
+ return $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ WHERE ref_dest IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE member_type IN ( " . implode( ',', $memberTypes ) . " )
+ )
+ AND renewal_date >= '2017-01-01'
+ AND renewal_date <= '2018-04-19'
+ AND id NOT IN (
+ SELECT distinct account
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+ )",
+ ARRAY_A
+ );
+ }
+
+}
$glmMembersBillingAddOnValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
'management' => array(
'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,