From: Steve Sutton Date: Mon, 18 Dec 2017 21:54:16 +0000 (-0500) Subject: WIP billing invoice template X-Git-Tag: v1.0.0^2~190 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=b493fa4721c0dd48bfca666699c9626514d147bc;p=WP-Plugins%2Fglm-member-db-billing.git WIP billing invoice template Working on the billing invoice template. Creating method in support class to generate the html. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index a81a8d4..9c2a15c 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -202,7 +202,7 @@ class GlmBillingSupport } /** - * 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. @@ -367,6 +367,16 @@ class GlmBillingSupport ); } + /** + * 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( @@ -405,6 +415,16 @@ class GlmBillingSupport } + /** + * 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. @@ -417,5 +437,134 @@ class GlmBillingSupport 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 '
$invoice: ' . print_r( $invoice, true ) . '
'; + $line_items = $this->getLineItemsForInvoice( $invoice_id ); + // echo '
$line_items: ' . print_r( $line_items, true ) . '
'; + // echo '
$this->config: ' . print_r( $this->config['settings'], true ) . '
'; + + $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 '
$invoiceHtml: ' . print_r( $invoiceHtml, true ) . '
'; + } + + /** + * 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; + + } + } diff --git a/classes/data/dataInvoices.php b/classes/data/dataInvoices.php index cf342ef..07b21f3 100644 --- a/classes/data/dataInvoices.php +++ b/classes/data/dataInvoices.php @@ -207,12 +207,15 @@ class GlmDataInvoices extends GlmDataAbstract */ public function entryPostProcessing($r, $a) { - $sql = " - SELECT A.ref_name - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices I - LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts A ON ( I.account = A.id ) - WHERE I.id = " . $r['id']; - $r['member_name'] = $this->wpdb->get_var( $sql ); + $r['member_name'] = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT A.ref_name + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices I + LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts A ON ( I.account = A.id ) + WHERE I.id = %d", + $r['id'] + ) + ); return $r; } diff --git a/classes/data/dataPayments.php b/classes/data/dataPayments.php index 5746ea8..cb0d548 100644 --- a/classes/data/dataPayments.php +++ b/classes/data/dataPayments.php @@ -190,6 +190,15 @@ class GlmDataPayments extends GlmDataAbstract */ public function entryPostProcessing($r, $a) { + $r['member_name'] = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT A.ref_name + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "payments P + LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts A ON ( P.account = A.id ) + WHERE P.id = %d", + $r['id'] + ) + ); return $r; } diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 9b8cc03..861cb30 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -129,6 +129,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices case 'add': $invoices = $this->newEntry(); + // Set the view file to editInvoice $view = 'editInvoice'; $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); $invoiceTypes = $InvoiceTypesObj->getList(); @@ -183,11 +184,14 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices } } } + // 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(); @@ -218,6 +222,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoices = false; } + // Set the view file to editInvoice $view = 'editInvoice'; break; @@ -235,9 +240,20 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $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 '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + + $BillingSupport->viewInvoice( $_REQUEST['id'] ); + + wp_die( 'fun' ); + break; case 'delete': // Need to remove any line items for the invoice alse diff --git a/views/admin/billing/invoiceStore.html b/views/admin/billing/invoiceStore.html new file mode 100644 index 0000000..11e946e --- /dev/null +++ b/views/admin/billing/invoiceStore.html @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + +
+ Bill To: + +
+ + + + + + + + + + + + + + + + +
DateDescriptionAmountBalance
+ + + + diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index 02112e4..d08d59e 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -13,6 +13,7 @@ Time Due Date Balance + View @@ -29,6 +30,7 @@ {$t.transaction_time.datetime} {$t.due_date.date} {$t.balance} + View {/foreach} {else} diff --git a/views/admin/billing/payments.html b/views/admin/billing/payments.html index 4624e6e..3779a6f 100644 --- a/views/admin/billing/payments.html +++ b/views/admin/billing/payments.html @@ -24,7 +24,7 @@ {/if} {$t.id} - + {$t.member_name} {$t.transaction_time.datetime} {$t.amount|string_format:"%.2f"}