}
/**
- * getStatements
+ * getStatementsByRefDest
*
* Create array that has the set of invoices and payments for an account.
* Returns false if nothing is found or array if it finds records.
);
}
+ /**
+ * getUnPaidInvoicesByAccount
+ *
+ * Get all unpaid invoices given an account id.
+ *
+ * @param mixed $account Id of the account.
+ *
+ * @access public
+ * @return void
+ */
public function getUnPaidInvoicesByAccount( $account )
{
return $this->wpdb->get_results(
}
+ /**
+ * getBalanceDueByAccount
+ *
+ * Get the balance due for an account.
+ *
+ * @param mixed $account Id of the account
+ *
+ * @access public
+ * @return void
+ */
public function getBalanceDueByAccount( $account )
{
// Find all invoices for this account that aren't marked as paid.
return $balance_due;
}
+
+ /**
+ * viewInvoice
+ *
+ * Need to get everything here for creating the invoice.
+ * Need billing settings.
+ * Invoice data.
+ * All line items for that invoice.
+ *
+ * @param mixed $invoice_id
+ *
+ * @access public
+ * @return void
+ */
+ public function viewInvoice( $invoice_id )
+ {
+ $invoice = $this->getInvoiceById( $invoice_id );
+ // echo '<pre>$invoice: ' . print_r( $invoice, true ) . '</pre>';
+ $line_items = $this->getLineItemsForInvoice( $invoice_id );
+ // echo '<pre>$line_items: ' . print_r( $line_items, true ) . '</pre>';
+ // echo '<pre>$this->config: ' . print_r( $this->config['settings'], true ) . '</pre>';
+
+ $templateData = array(
+ 'settings' => $this->config['settings'],
+ 'invoice' => $invoice,
+ 'line_items' => $line_items,
+ 'member' => array( 'member_name' => 'Member Name here' )
+ );
+
+ $invoiceHtml = $this->generateInvoiceHtml( $templateData, 'admin/billing/invoiceStore.html' );
+ echo '<pre>$invoiceHtml: ' . print_r( $invoiceHtml, true ) . '</pre>';
+ }
+
+ /**
+ * getLineItemsForInvoice
+ *
+ * Grab all the line_items records for a given invoice.
+ *
+ * @param mixed $invoice_id
+ *
+ * @access public
+ * @return void
+ */
+ public function getLineItemsForInvoice( $invoice_id )
+ {
+ $line_items = $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "line_items
+ WHERE invoice = %d",
+ $invoice_id
+ ),
+ ARRAY_A
+ );
+ return $line_items;
+ }
+
+
+ /**
+ * Merge template and data to produce HTML
+ *
+ * Checks the theme's view directories and the view directories for
+ * this plugin for a matching view file.
+ *
+ * Note that $viewFile needs to have the proper view directory path
+ * includes. (i.e. "/views/admin/billing/invoiceStore.html")
+ *
+ * @param $data array Array of data to merge with the template
+ * @param $view string Path added to
+ *
+ * @access public
+ * @return void
+ */
+ function generateInvoiceHtml( $data, $viewFile )
+ {
+
+ // If a view file is specified
+ if ($viewFile) {
+
+ // Get the specified view file - check theme first
+ $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views";
+ $viewPath2 = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH . "views"; // Save default
+
+ // If the view is not found in the theme, fall back to views in the plugin
+ if (!is_file($viewPath.'/'.$viewFile)) {
+
+ // Next try the plugin/add-on
+ $viewPath = GLM_MEMBERS_BILLING_PLUGIN_PATH . "/views";
+
+ if (!is_file($viewPath.'/'.$viewFile)) {
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$viewFile", E_USER_NOTICE);
+ }
+
+ }
+
+ }
+
+ }
+
+ // Load Smarty Template support
+ $smarty = new smartyTemplateSupport();
+
+ // Add standard parameters
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+
+ // Add data from model to Smarty template
+ if (is_array($data) && count($data) > 0) {
+ foreach ($data as $k => $d) {
+ $smarty->templateAssign($k, $d);
+ }
+ }
+
+ // Update the Smarty view path
+ $smarty->template->setTemplateDir($viewPath);
+
+ // If the view path doesn't match the default, add the default (using theme view)
+ if ($viewPath2 != $viewPath) {
+ $smarty->template->addTemplateDir($viewPath2);
+ }
+
+ // Generate output from model data and view
+ $out = $smarty->template->fetch($viewFile);
+
+ return $out;
+
+ }
+
}
case 'add':
$invoices = $this->newEntry();
+ // Set the view file to editInvoice
$view = 'editInvoice';
$InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
$invoiceTypes = $InvoiceTypesObj->getList();
}
}
}
+ // Here we're going to generate the invoice total.
$totals = $this->generateInvoiceTotal( $this->invoice_id );
// Now we have a total for the invoice we can record the transaction
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+ // Calling the support class to save the invoice to transaction table.
$BillingSupport->recordInvoice( $this->invoice_id, $_REQUEST['account'], $totals['amount_total'] );
+ // Set the view file to editInvoice
$view = 'editInvoice';
$InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
$invoiceTypes = $InvoiceTypesObj->getList();
$invoices = false;
}
+ // Set the view file to editInvoice
$view = 'editInvoice';
break;
$invoiceUpdateError = true;
}
+ // Set the view file to editInvoice
$view = 'editInvoice';
break;
+ case 'view':
+ // Now we have a total for the invoice we can record the transaction
+ $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+ $BillingSupport->viewInvoice( $_REQUEST['id'] );
+
+ wp_die( 'fun' );
+ break;
case 'delete':
// Need to remove any line items for the invoice alse