From 424e9e05305990450f5de9c069c75ac9a62b980c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 20 Dec 2017 16:48:42 -0500 Subject: [PATCH] WIP for invoice view and print version. Had to add some fields to the database for accounts table. Figure this would be the best place to put in billing address. This way I can pull this data to put in the invoice. --- classes/billingSupport.php | 12 +- classes/data/dataAccounts.php | 48 ++++++ index.php | 2 +- models/admin/billing/invoices.php | 8 +- ..._V0.0.3.sql => create_database_V0.0.4.sql} | 6 + setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.4.sql | 34 +++++ views/admin/billing/editAccount.html | 48 ++++++ views/admin/billing/invoiceStore.html | 138 +++++++++++++++--- views/admin/billing/viewInvoice.html | 7 + 10 files changed, 276 insertions(+), 28 deletions(-) rename setup/databaseScripts/{create_database_V0.0.3.sql => create_database_V0.0.4.sql} (95%) create mode 100644 setup/databaseScripts/update_database_V0.0.4.sql create mode 100644 views/admin/billing/viewInvoice.html diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 9c2a15c..3df6d56 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -458,16 +458,24 @@ class GlmBillingSupport $line_items = $this->getLineItemsForInvoice( $invoice_id ); // echo '
$line_items: ' . print_r( $line_items, true ) . '
'; // echo '
$this->config: ' . print_r( $this->config['settings'], true ) . '
'; + $account = $this->getAccountById( $invoice['account'] ); + // echo '
$account: ' . print_r( $account, true ) . '
'; $templateData = array( 'settings' => $this->config['settings'], 'invoice' => $invoice, 'line_items' => $line_items, - 'member' => array( 'member_name' => 'Member Name here' ) + 'account' => $account, ); $invoiceHtml = $this->generateInvoiceHtml( $templateData, 'admin/billing/invoiceStore.html' ); - echo '
$invoiceHtml: ' . print_r( $invoiceHtml, true ) . '
'; + // echo '
$invoiceHtml: ' . print_r( $invoiceHtml, true ) . '
'; + return $invoiceHtml; + } + + public function getMemberInfo() + { + } /** diff --git a/classes/data/dataAccounts.php b/classes/data/dataAccounts.php index 4ce220a..7c9c60a 100644 --- a/classes/data/dataAccounts.php +++ b/classes/data/dataAccounts.php @@ -161,6 +161,54 @@ class GlmDataAccounts extends GlmDataAbstract 'required' => true, ), + // Billing Address 1 + 'billing_addr1' => array( + 'field' => 'billing_addr1', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + + // Billing Address 2 + 'billing_addr2' => array( + 'field' => 'billing_addr2', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + + // Billing City + 'billing_city' => array( + 'field' => 'billing_city', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + + // Billing State + 'billing_state' => array( + 'field' => 'billing_state', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + + // Billing Zip + 'billing_zip' => array( + 'field' => 'billing_zip', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + + // Billing Phone + 'billing_phone' => array( + 'field' => 'billing_phone', + 'type' => 'text', + 'use' => 'a', + 'required' => false, + ), + ); diff --git a/index.php b/index.php index 622908a..3546b29 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.3'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.4'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 861cb30..e834ea6 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -118,6 +118,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoiceTypes = false; $invoiceTypeJSON = ''; $accounts = false; + $invoiceHtml = ''; // Get any provided option if (isset($_REQUEST['option'])) { @@ -248,11 +249,11 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // 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 ) . '
'; + $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] ); - $BillingSupport->viewInvoice( $_REQUEST['id'] ); + // Set the file name for the view file. + $view = 'viewInvoice'; - wp_die( 'fun' ); break; case 'delete': @@ -374,6 +375,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'invoiceTypeJSON' => $invoiceTypeJSON, 'invoiceTypes' => $invoiceTypes, 'accounts' => $accounts, + 'invoiceHtml' => $invoiceHtml, ); // Return status, any suggested view, and any data to controller diff --git a/setup/databaseScripts/create_database_V0.0.3.sql b/setup/databaseScripts/create_database_V0.0.4.sql similarity index 95% rename from setup/databaseScripts/create_database_V0.0.3.sql rename to setup/databaseScripts/create_database_V0.0.4.sql index 95dc181..83b78c2 100644 --- a/setup/databaseScripts/create_database_V0.0.3.sql +++ b/setup/databaseScripts/create_database_V0.0.4.sql @@ -14,6 +14,12 @@ CREATE TABLE {prefix}accounts ( id INT NOT NULL AUTO_INCREMENT, ref_dest INT NOT NULL, -- reference to member id ref_name TINYTEXT NOT NULL, -- Name of reference member + billing_addr1 TINYTEXT NULL, -- Billing Address 1 + billing_addr2 TINYTEXT NULL, -- Billing Address 2 + billing_city TINYTEXT NULL, -- Billing City + billing_state TINYTEXT NULL, -- Billing State + billing_zip TINYTEXT NULL, -- Billing Zip + billing_phone TINYTEXT NULL, -- Billing Phone anniversary_date DATE NOT NULL, -- anniversary date - used for main invoice generation payment_data TEXT NULL, -- stored payment data email TINYTEXT NULL, -- billing email diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index cd4f632..499a3e1 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -17,5 +17,6 @@ $glmMembersBillingDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 10), '0.0.2' => array('version' => '0.0.2', 'tables' => 11), '0.0.3' => array('version' => '0.0.3', 'tables' => 12), + '0.0.4' => array('version' => '0.0.4', 'tables' => 12), ); diff --git a/setup/databaseScripts/update_database_V0.0.4.sql b/setup/databaseScripts/update_database_V0.0.4.sql new file mode 100644 index 0000000..7696512 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.4.sql @@ -0,0 +1,34 @@ +-- Gaslight Media Billing Database +-- File Created: 12/20/2017 +-- Database Version: 0.0.4 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Add fields for billing addr1 +ALTER TABLE {prefix}accounts ADD billing_addr1 TINYTEXT NULL; + +---- + +-- Add fields for billing addr2 +ALTER TABLE {prefix}accounts ADD billing_addr2 TINYTEXT NULL; + +---- + +-- Add fields for billing city +ALTER TABLE {prefix}accounts ADD billing_city TINYTEXT NULL; + +---- + +-- Add fields for billing state +ALTER TABLE {prefix}accounts ADD billing_state TINYTEXT NULL; + +---- + +-- Add fields for billing zip +ALTER TABLE {prefix}accounts ADD billing_zip TINYTEXT NULL; + +---- + +-- Add fields for billing phone +ALTER TABLE {prefix}accounts ADD billing_phone TINYTEXT NULL; diff --git a/views/admin/billing/editAccount.html b/views/admin/billing/editAccount.html index 43cb672..436c942 100644 --- a/views/admin/billing/editAccount.html +++ b/views/admin/billing/editAccount.html @@ -47,6 +47,54 @@ + + Billing Address 1 + + + {if $account.fieldFail.billing_addr1}

{$account.fieldFail.billing_addr1}

{/if}
+ + + + + Billing Address2 + + + {if $account.fieldFail.billing_addr2}

{$account.fieldFail.billing_addr2}

{/if}
+ + + + + Billing City + + + {if $account.fieldFail.billing_city}

{$account.fieldFail.billing_city}

{/if}
+ + + + + Billing State + + + {if $account.fieldFail.billing_state}

{$account.fieldFail.billing_state}

{/if}
+ + + + + Billing Zip + + + {if $account.fieldFail.billing_zip}

{$account.fieldFail.billing_zip}

{/if}
+ + + + + Billing Phone + + + {if $account.fieldFail.billing_phone}

{$account.fieldFail.billing_phone}

{/if}
+ + + diff --git a/views/admin/billing/invoiceStore.html b/views/admin/billing/invoiceStore.html index 11e946e..d8c6db8 100644 --- a/views/admin/billing/invoiceStore.html +++ b/views/admin/billing/invoiceStore.html @@ -1,43 +1,137 @@ - +
- - + + - + -
LOGO + + + + + + + + + +
Date: {$invoice.transaction_time|date_format:"%D"}
Billing #: {$invoice.account}
+ +
+ + {$settings.company_name}
+ {if $settings.company_name2}{$settings.company_name2}
{/if} + {if $settings.company_addr1}{$settings.company_addr1}
{/if} + {if $settings.company_addr2}{$settings.company_addr2}
{/if} + {if $settings.company_city}{$settings.company_city} {$settings.company_state}, {$settings.company_zip}
{/if} + {if $settings.company_phone}{$settings.company_phone}
{/if} + {if $settings.company_email}{$settings.company_email}
{/if} + {if $settings.company_url}{$settings.company_url}
{/if} +
- Bill To: + Bill To:
+ {if $account.billing_name2}{$account.billing_name2}
{/if} + {if $account.billing_addr1}{$account.billing_addr1}
{/if} + {if $account.billing_addr2}{$account.billing_addr2}
{/if} + {if $account.billing_city}{$account.billing_city} {$account.billing_state}, {$account.billing_zip}
{/if} + {if $account.billing_phone}{$account.billing_phone}
{/if} +
- - - - - - - - - + + + + + + + + + + + + +
DateDescriptionAmountBalance
+ + + + + + + + + + + + {foreach $line_items as $item} + + + + + {/foreach} + + +
DateDescriptionQtyAmount
{$invoice.transaction_time|date_format:"%D"}{$item.name}{$item.quantity}{$item.amount}
+
+ Payment Terms: blah blah blah +
Please return Coupon Below with Payment

+ - - - - + + - -
+ {$settings.company_name}
+ {if $settings.company_name2}{$settings.company_name2}
{/if} + {if $settings.company_addr1}{$settings.company_addr1}
{/if} + {if $settings.company_addr2}{$settings.company_addr2}
{/if} + {if $settings.company_city}{$settings.company_city} {$settings.company_state}, {$settings.company_zip}
{/if} + {if $settings.company_phone}{$settings.company_phone}
{/if} + {if $settings.company_email}{$settings.company_email}
{/if} + {if $settings.company_url}{$settings.company_url}
{/if} +
+ {if $account.billing_name2}{$account.billing_name2}
{/if} + {if $account.billing_addr1}{$account.billing_addr1}
{/if} + {if $account.billing_addr2}{$account.billing_addr2}
{/if} + {if $account.billing_city}{$account.billing_city} {$account.billing_state}, {$account.billing_zip}
{/if} + {if $account.billing_phone}{$account.billing_phone}
{/if} +
+ + + + + + + + + + + + + +
Please Pay:{$invoice.balance}
Payment Amount:
Billing #: {$invoice.account}
+
+
+ diff --git a/views/admin/billing/viewInvoice.html b/views/admin/billing/viewInvoice.html new file mode 100644 index 0000000..d320c7e --- /dev/null +++ b/views/admin/billing/viewInvoice.html @@ -0,0 +1,7 @@ +{include file='admin/billing/header.html'} + +{include file='admin/billing/subHeader.html'} + +{$invoiceHtml} + +{include file='admin/footer.html'} -- 2.17.1