* @access public
* @return void
*/
- public function sendEmailNotification( $notification_id, $account_id, $data = null, $test = false )
+ public function sendEmailNotification( $notification_id, $account_id, $data = null, $test = false, $test_data = false )
{
// Support Class
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
- // get the Account
- $account = $BillingSupport->getAccountById( $account_id );
- if ( !$account ) {
- // If there's no account then return false.
- return false;
- }
+ if ( !$test ) {
+ // get the Account
+ $account = $BillingSupport->getAccountById( $account_id );
+ if ( !$account ) {
+ // If there's no account then return false.
+ return false;
+ }
- $currentAmount = false;
- if ( $account['invoice_type'] ) {
- $invTypeData = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] );
- $currentAmount = $invTypeData['amount'];
+ $currentAmount = false;
+ if ( $account['invoice_type'] ) {
+ $invTypeData = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] );
+ $currentAmount = $invTypeData['amount'];
+ }
}
// get the Notification type
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' => '',
- );
- }
+ if ( !$test ) {
+ // 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'],
- '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'],
- ),
- );
- 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'];
+ $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'],
+ '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'],
+ ),
+ );
+ 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;
}
$fileName = false;
$attachments = false;
- if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] && $this->config['settings']['invoice_pdf_enabled'] ) {
- // Need to get the invoice and output to a file.
- require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/GlmPDFInvoice.php';
- $fullInvoice = $BillingSupport->getFullInvoiceData( $data['type_id'] );
- $pdf = new GlmPDFInvoice( $this->config, 'LETTER', 'portrait' );
- $fileData = $pdf->createPdf( array( $fullInvoice ), 'file' );
- $origName = tempnam( '/tmp', 'PDF' );
- $fp = fopen( $origName, 'w' );
- fwrite( $fp, $fileData );
- fclose( $fp );
- $fileName = $origName.'.pdf';
- rename( $origName, $fileName );
-
- $attachments = array( $fileName );
+ if ( !$test ) {
+ if ( isset( $data['type'] ) && $data['type'] == $this->config['transaction_numb']['Invoice'] && $this->config['settings']['invoice_pdf_enabled'] ) {
+ // Need to get the invoice and output to a file.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/lib/GlmPDFInvoice.php';
+ $fullInvoice = $BillingSupport->getFullInvoiceData( $data['type_id'] );
+ $pdf = new GlmPDFInvoice( $this->config, 'LETTER', 'portrait' );
+ $fileData = $pdf->createPdf( array( $fullInvoice ), 'file' );
+ $origName = tempnam( '/tmp', 'PDF' );
+ $fp = fopen( $origName, 'w' );
+ fwrite( $fp, $fileData );
+ fclose( $fp );
+ $fileName = $origName.'.pdf';
+ rename( $origName, $fileName );
+
+ $attachments = array( $fileName );
+ }
}
$smarty->templateAssign( 'invoice_html', $invoice_html );
$htmlMessage = $smarty->template->fetch( $viewFile );
if ( $test ) {
- echo $htmlMessage;
+ return $htmlMessage;
} else {
// change the default wordpress from name when sending mail
+{* Edit Invoice *}
+
+{* Header *}
{include file='admin/billing/header.html'}
-<div class="callout grid-container">
-
- {if $invoiceUpdated}<span class="glm-notice glm-flash-updated">Invoice Updated</span>{/if}
- {if $invoiceUpdateError}<span class="glm-notice glm-flash-updated">Invoice Update Error</span>{/if}
- {if $invoiceInsertError}<span class="glm-notice glm-flash-updated">Invoice Insert Error</span>{/if}
- {if $invoiceAdded}<span class="glm-notice glm-flash-updated">Invoice Added</span>{/if}
-
- <div id="billing-invoice-form" style="max-width: 750px;">
- <form id="create-invoice-form" action="{$thisUrl}?page={$thisPage}&glm_action=invoices" method="post">
- {if $invoice_id}
- <input type="hidden" name="option" value="update">
- <input type="hidden" name="id" value="{$invoice_id}">
- <input type="hidden" name="account" value="{$invoices.fieldData.account.value}">
- <input type="hidden" name="transaction_time" value="{$invoices.fieldData.transaction_time.mysql_datetime}">
- <input type="hidden" name="balance" value="{$invoices.fieldData.balance}">
- <input type="hidden" name="paid" value="{$invoices.fieldData.paid.value}">
- <input type="hidden" name="recurring" value="{$invoices.fieldData.recurring.value}">
- <input type="hidden" name="recurrence" value="{$invoices.fieldData.recurrence}">
- {else}
- <input type="hidden" name="option" value="insert">
- {/if}
- <div class="grid-container">
- <div class="grid-x grid-padding-x">
- <div class="cell small-12">
- {if !$invoice_id}
- <label for="glm_member_accounts" class="glm-required">
- Billing Account
- </label>
- <input id="glm_member_accounts_hidden" type="hidden" name="account" />
- <input id="glm_member_accounts" type="text" name="account_input" required />
- <a id="newAccountButton" href="#">New Account</a>
- {/if}
- </div>
- <div class="cell small-12">
- <label for="invoice_due_date" class="glm-required">
- Due Date
- </label>
- <input class="datepicker" id="invoice_due_date" type="text" name="due_date" {if $invoice_id}value="{$invoices.fieldData.due_date.date}"{/if} required>
- </div>
- <div class="cell small-12">
- <label for="notes">
- Notes
- </label>
- <textarea id="notes" name="notes">{if $invoices.fieldData.notes}{$invoices.fieldData.notes}{/if}</textarea>
- </div>
- </div>
+{* Grid Start *}
+{$ui = [
+ 'nowrap' => false,
+ 'backgroundColor' => '',
+ 'sectionColor' => ''
+]}
+{include file='ui/f6/grid-start.html'}
+
+{* Set $data to $invoiceType *}
+{* This is for using the UI elements *}
+{$data = $invoices}
+
+{* Invoice Updated *}
+{$ui = [
+ 'label' => 'Invoice Updated',
+ 'active' => $invoiceUpdated,
+ 'type' => 'success'
+]}
+{include file='ui/f6/callout.html'}
+{* Invoice Update Error *}
+{$ui = [
+ 'label' => 'Invoice Update Error',
+ 'active' => $invoiceUpdateError,
+ 'type' => 'alert'
+]}
+{include file='ui/f6/callout.html'}
+{* Invoice Insert Error *}
+{$ui = [
+ 'label' => 'Invoice Insert Error',
+ 'active' => $invoiceInsertError,
+ 'type' => 'alert'
+]}
+{include file='ui/f6/callout.html'}
+{* Invoice Added *}
+{$ui = [
+ 'label' => 'Invoice Added',
+ 'active' => $invoiceAdded,
+ 'type' => 'success'
+]}
+{include file='ui/f6/callout.html'}
+
+{* Form Start *}
+{$ui = [
+ 'id' => 'create-invoice-form',
+ 'action' => "{$thisUrl}?page={$thisPage}&glm_action=invoices",
+ 'method' => 'post',
+ 'file' => false
+]}
+{include file='ui/f6/form-start.html'}
+
+{if $invoice_id}
+ <input type="hidden" name="option" value="update">
+ <input type="hidden" name="id" value="{$invoice_id}">
+ <input type="hidden" name="account" value="{$invoices.fieldData.account.value}">
+ <input type="hidden" name="transaction_time" value="{$invoices.fieldData.transaction_time.mysql_datetime}">
+ <input type="hidden" name="balance" value="{$invoices.fieldData.balance}">
+ <input type="hidden" name="paid" value="{$invoices.fieldData.paid.value}">
+ <input type="hidden" name="recurring" value="{$invoices.fieldData.recurring.value}">
+ <input type="hidden" name="recurrence" value="{$invoices.fieldData.recurrence}">
+{else}
+ <input type="hidden" name="option" value="insert">
+{/if}
+
+<div class="grid-x grid-margin-x">
+
+ <fieldset class="fieldset small-12 medium-8">
+ <legend>Invoice</legend>
+
+ <div class="grid-x grid-margin-x">
+
+ <div class="cell small-12">
+ <label for="glm_member_accounts" class="glm-required">
+ Billing Account
+ </label>
+ {if !$invoice_id}
+ <input id="glm_member_accounts_hidden" type="hidden" name="account" />
+ <input id="glm_member_accounts" type="text" name="account_input" required />
+ <a id="newAccountButton" href="#">New Account</a>
+ {else}
+ <strong>{$invoices.fieldData.member_name}</strong>
+ {/if}
</div>
- <div class="grid-container">
- <div class="grid-x grid-padding-x">
- <div class="cell small-12 large-4">
- <a id="newLineItemButton" class="glm-billing-add-line-item">Add Line Item</a><br>
- <a id="newCustomLineItemButton" class="glm-billing-add-line-item">Create New Line Item</a>
- </div>
- <div id="invoice-line-items"> </div>
- <div class="cell small-12 large-8">
- <div class="glm-row">
- <div class="glm-columns glm-small-8" style="text-align: right;">
- Total Amount:
- <input type="hidden" id="invoice-total-amount" value="" />
- </div>
- <div class="glm-columns glm-small-4" id="invoice-total"> $0.00 </div>
- </div>
+ <div class="cell small-12">
+ <label for="invoice_due_date" class="glm-required">
+ Due Date
+ </label>
+ <input class="datepicker" id="invoice_due_date" type="text" name="due_date" {if $invoice_id}value="{$invoices.fieldData.due_date.date}"{/if} required>
+ </div>
+ <div class="cell small-12">
+ <label for="notes">
+ Notes
+ </label>
+ <textarea id="notes" name="notes">{if $invoices.fieldData.notes}{$invoices.fieldData.notes}{/if}</textarea>
+ </div>
+ <div class="cell small-12 medium-4">
+ <a id="newLineItemButton" class="glm-billing-add-line-item">Add Line Item</a><br>
+ <a id="newCustomLineItemButton" class="glm-billing-add-line-item">Create New Line Item</a>
+ </div>
+ <div id="invoice-line-items" class="cell small-12 medium-8"> </div>
+ <div class="cell small-12 large-8">
+ <div class="glm-row">
+ <div class="glm-columns glm-small-8" style="text-align: right;">
+ Total Amount:
+ <input type="hidden" id="invoice-total-amount" value="" />
</div>
+ <div class="glm-columns glm-small-4" id="invoice-total"> $0.00 </div>
</div>
</div>
- <div class="glm-row">
- <div class="glm-columns glm-small-12 glm-large-8">
- <input class="button button-primary" type="submit" value="{if $invoice_id}Save{else}Create{/if} Invoice">
- </div>
+
+ <div class="cell small-12 medium-8">
+ <input class="button button-primary" type="submit" value="{if $invoice_id}Save{else}Create{/if} Invoice">
</div>
- </form>
- </div>
- {* New Account Form - Dialog *}
- <div id="newAccountDialog" class="glm-dialog-box" title="New Account">
- <p class="validateAccountTips" style="color:red">* required</p>
- <form id="addAccountForm">
- <input id="non-member-account" type="hidden" name="ref_dest" value="">
- <input id="non-member-account" type="hidden" name="invoice_type" value="0">
- <div class="grid-container">
- <div class="grid-x grid-padding-x">
- <div class="cell small-12">
- <label class="glm-required">Member Name</label>
- <input id="glm_member_name" type="text" name="ref_name" value="">
- </div>
- <div class="cell small-12">
- <label class="glm-required">Account Number</label>
- <input type="text" name="account_number" value="">
- </div>
- <div class="cell small-12">
- <label class="glm-required">Anniversary Date</label>
- <input class="datepicker" type="text" name="anniversary_date" value="">
- </div>
- <div class="cell small-12">
- <label>Renewal Date</label>
- <input class="datepicker" type="text" name="renewal_date" value="">
- </div>
- <div class="cell small-12">
- <label class="glm-required">Billing Email</label>
- <input type="text" name="email" value="">
- </div>
- {if $settings.billing_contact_name_enabled}
- <div class="cell small-12">
- <label class="glm-required">Billing Contact Name</label>
- <input type="text" name="billing_contact_name" value="">
- </div>
- {else}
- <div class="cell small-12">
- <label class="glm-required">Billing First Name</label>
- <input type="text" name="billing_fname" value="">
- </div>
- <div class="cell small-12">
- <label class="glm-required">Billing Last Name</label>
- <input type="text" name="billing_lname" value="">
- </div>
- {/if}
+ </div>
+ {* Form End *}
+ {include file='ui/f6/form-end.html'}
+ </fieldset>
+</div>
+{* New Account Form - Dialog *}
+<div id="newAccountDialog" class="glm-dialog-box" title="New Account">
+ <p class="validateAccountTips" style="color:red">* required</p>
+ <form id="addAccountForm">
+ <input id="non-member-account" type="hidden" name="ref_dest" value="">
+ <input id="non-member-account" type="hidden" name="invoice_type" value="0">
+ <div class="grid-container">
+ <div class="grid-x grid-padding-x">
+ <div class="cell small-12">
+ <label class="glm-required">Member Name</label>
+ <input id="glm_member_name" type="text" name="ref_name" value="">
+ </div>
+ <div class="cell small-12">
+ <label class="glm-required">Account Number</label>
+ <input type="text" name="account_number" value="">
+ </div>
+ <div class="cell small-12">
+ <label class="glm-required">Anniversary Date</label>
+ <input class="datepicker" type="text" name="anniversary_date" value="">
+ </div>
+ <div class="cell small-12">
+ <label>Renewal Date</label>
+ <input class="datepicker" type="text" name="renewal_date" value="">
+ </div>
+ <div class="cell small-12">
+ <label class="glm-required">Billing Email</label>
+ <input type="text" name="email" value="">
+ </div>
+ {if $settings.billing_contact_name_enabled}
<div class="cell small-12">
- <label class="glm-required">Billing Address 1</label>
- <input type="text" name="billing_addr1" value="">
+ <label class="glm-required">Billing Contact Name</label>
+ <input type="text" name="billing_contact_name" value="">
</div>
+ {else}
<div class="cell small-12">
- <label>Billing Address 2</label>
- <input type="text" name="billing_addr2" value="">
+ <label class="glm-required">Billing First Name</label>
+ <input type="text" name="billing_fname" value="">
</div>
<div class="cell small-12">
- <label class="glm-required">Billing City</label>
- <input type="text" name="billing_city" value="">
+ <label class="glm-required">Billing Last Name</label>
+ <input type="text" name="billing_lname" value="">
</div>
- {if $settings.billing_county_enabled}
- <div class="cell small-12">
- <label class="glm-required">Billing County</label>
- <select name="billing_county">
- <option value=""></option>
- {foreach $billingAccount.fieldData.billing_county.list as $s}
- <option value="{$s.value}">
- {$s.name}
- </option>
- {/foreach}
- </select>
- </div>
- {else}
- <input type="hidden" name="billing_county" value="{$account.fieldData.billing_county.value}">
- {/if}
+ {/if}
+
+ <div class="cell small-12">
+ <label class="glm-required">Billing Address 1</label>
+ <input type="text" name="billing_addr1" value="">
+ </div>
+ <div class="cell small-12">
+ <label>Billing Address 2</label>
+ <input type="text" name="billing_addr2" value="">
+ </div>
+ <div class="cell small-12">
+ <label class="glm-required">Billing City</label>
+ <input type="text" name="billing_city" value="">
+ </div>
+ {if $settings.billing_county_enabled}
<div class="cell small-12">
- <label class="glm-required">Billing State</label>
- <select name="billing_state">
+ <label class="glm-required">Billing County</label>
+ <select name="billing_county">
<option value=""></option>
- {foreach $billingAccount.fieldData.billing_state.list as $s}
+ {foreach $billingAccount.fieldData.billing_county.list as $s}
<option value="{$s.value}">
{$s.name}
</option>
{/foreach}
</select>
</div>
- <div class="cell small-12">
- <label class="glm-required">Billing Zip</label>
- <input type="text" name="billing_zip" value="">
- </div>
- <div class="cell small-12">
- <label>Billing Phone</label>
- <input type="text" name="billing_phone" value="">
- </div>
-
+ {else}
+ <input type="hidden" name="billing_county" value="{$account.fieldData.billing_county.value}">
+ {/if}
+ <div class="cell small-12">
+ <label class="glm-required">Billing State</label>
+ <select name="billing_state">
+ <option value=""></option>
+ {foreach $billingAccount.fieldData.billing_state.list as $s}
+ <option value="{$s.value}">
+ {$s.name}
+ </option>
+ {/foreach}
+ </select>
</div>
- </div>
- </form>
- </div>
- {* Enter a Line Item Form - jQueryUI dialog *}
- <div id="newLineItemDialog" class="glm-dialog-box" title="Enter a Line Item">
- <p class="validateTips glm-required">* Required!</p>
- <form id="addLineItemForm">
- <input type="hidden" name="glm_action" value="invoices">
- <input type="hidden" name="option" value="addLineItem">
- <div class="grid-container">
- <div class="grid-x grid-padding-x">
- <div class="cell small-12 medium-5">
- <label for="" class="glm-required">Invoice Type </label>
- <select id="line_item_type" name="line_item_type">
- <option value="">Select Invoice Type</option>
- {$parent = 0}
- {foreach $invoiceTypes as $inv}
- {if $inv.parent.value == 0 && $parent != 0 && $inv.amount != '0.00'}
- <optgroup label="---"> </optgroup>
- {/if}
- {$parent = $inv.parent.value}
- {if $inv.parent.value == 0 && $inv.amount != '0.00'}
- <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
- {else if ($inv.parent.value == 0 && $inv.amount == '0.00' && $inv.dynamic_amount.value == 0)}
- <optgroup label="{$inv.name}"></optgroup>
- {else if ($inv.parent.value == 0 && $inv.amount == '0.00')}
- <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
- {else if ($inv.parent.value != 0)}
- <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
- {/if}
- {/foreach}
- </select>
- </div>
- <div class="cell small-12 medium-3">
- <p id="line_item_price"></p>
- </div>
- <div class="cell small-12 medium-4">
- <label>Discount</label>
- <div class="input-group">
- <input class="input-group-field" id="discount-amount" type="text" min="0" max"100" name="discount_amount" value="0" />
- <span class="input-group-label">%</span>
- </div>
- </div>
+ <div class="cell small-12">
+ <label class="glm-required">Billing Zip</label>
+ <input type="text" name="billing_zip" value="">
+ </div>
+ <div class="cell small-12">
+ <label>Billing Phone</label>
+ <input type="text" name="billing_phone" value="">
</div>
+
</div>
- </form>
- </div>
- {* Add new Invoice Type (Custom Line Item) Form *}
- <div id="newCustomLineItemDialog" class="glm-dialog-box" title="Enter Custom Line Item">
- <p class="validateCustomTips glm-required">* Required!</p>
- <table class="unstriped">
- <tr>
- <th class="glm-required" align="right">Parent</th>
- <td>
- <select id="cf_parent_select" name="cf_parent" required>
- <option value="0">No Parent</option>
+ </div>
+ </form>
+</div>
+{* Enter a Line Item Form - jQueryUI dialog *}
+<div id="newLineItemDialog" class="glm-dialog-box" title="Enter a Line Item">
+ <p class="validateTips glm-required">* Required!</p>
+ <form id="addLineItemForm">
+ <input type="hidden" name="glm_action" value="invoices">
+ <input type="hidden" name="option" value="addLineItem">
+ <div class="grid-container">
+ <div class="grid-x grid-padding-x">
+ <div class="cell small-12 medium-5">
+ <label for="" class="glm-required">Invoice Type </label>
+ <select id="line_item_type" name="line_item_type">
+ <option value="">Select Invoice Type</option>
+ {$parent = 0}
{foreach $invoiceTypes as $inv}
- {if $inv.parent.value == 0}
- <option value="{$inv.id}">{$inv.name}</option>
+ {if $inv.parent.value == 0 && $parent != 0 && $inv.amount != '0.00'}
+ <optgroup label="---"> </optgroup>
+ {/if}
+ {$parent = $inv.parent.value}
+ {if $inv.parent.value == 0 && $inv.amount != '0.00'}
+ <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
+ {else if ($inv.parent.value == 0 && $inv.amount == '0.00' && $inv.dynamic_amount.value == 0)}
+ <optgroup label="{$inv.name}"></optgroup>
+ {else if ($inv.parent.value == 0 && $inv.amount == '0.00')}
+ <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
+ {else if ($inv.parent.value != 0)}
+ <option value="{$inv.id}" data-id="{$inv.id}" data-price="{$inv.amount}" data-dynamic="{$inv.dynamic_amount.value}">{$inv.name}</option>
{/if}
{/foreach}
</select>
- </td>
- </tr>
- <tr>
- <th class="glm-required" align="right">Line Item Name</th>
- <td><input name="cf_name" /></td>
- </tr>
- <tr>
- <th class="glm-required" align="right">Amount <br> Numbers only (999.99)</th>
- <td><input name="cf_amount" /></td>
- </tr>
- </table>
- </div>
-
+ </div>
+ <div class="cell small-12 medium-3">
+ <p id="line_item_price"></p>
+ </div>
+ <div class="cell small-12 medium-4">
+ <label>Discount</label>
+ <div class="input-group">
+ <input class="input-group-field" id="discount-amount" type="text" min="0" max"100" name="discount_amount" value="0" />
+ <span class="input-group-label">%</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </form>
+</div>
+{* Add new Invoice Type (Custom Line Item) Form *}
+<div id="newCustomLineItemDialog" class="glm-dialog-box" title="Enter Custom Line Item">
+ <p class="validateCustomTips glm-required">* Required!</p>
+ <table class="unstriped">
+ <tr>
+ <th class="glm-required" align="right">Parent</th>
+ <td>
+ <select id="cf_parent_select" name="cf_parent" required>
+ <option value="0">No Parent</option>
+ {foreach $invoiceTypes as $inv}
+ {if $inv.parent.value == 0}
+ <option value="{$inv.id}">{$inv.name}</option>
+ {/if}
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required" align="right">Line Item Name</th>
+ <td><input name="cf_name" /></td>
+ </tr>
+ <tr>
+ <th class="glm-required" align="right">Amount <br> Numbers only (999.99)</th>
+ <td><input name="cf_amount" /></td>
+ </tr>
+ </table>
</div>
+
+{* Grid End *}
+{include file='ui/f6/grid-end.html'}
+
+
<script>
jQuery(document).ready(function($){
line_items.push( lineItem );
var uid = line_items.length - 1;
$( '#invoice-line-items' ). append(
- '<div class="glm-row" id="line-item-type-' + lineItem.id + '">' +
- '<div class="glm-columns glm-small-1 line-item-delete dashicons dashicons-trash" data-id="' + lineItem.id + '"></div>' +
- '<div class="glm-columns glm-small-6">' + lineItem.name + '</div>' +
- '<div class="glm-columns glm-small-2">' +
+ '<div class="grid-x grid-margin-x" id="line-item-type-' + lineItem.id + '">' +
+ '<div class="cell small-1 line-item-delete dashicons dashicons-trash" data-id="' + lineItem.id + '"></div>' +
+ '<div class="cell small-4">' + lineItem.name + '</div>' +
+ '<div class="cell small-3">' +
'Discount ' + lineItem.discount + '%' +
'</div>' +
- '<div class="glm-columns glm-small-1">' +
+ '<div class="cell small-2">' +
'<input type="number" min="1" data-id="' + lineItem.id + '" data-uid="' + uid + '" name="line_item_qty[' + lineItem.id + ']" value="1">' +
'</div>' +
- '<div class="glm-columns glm-small-2">' +
+ '<div class="cell small-2">' +
'<input type="hidden" name="line_items[]" value="' + lineItem.id + '">' +
'<input type="hidden" name="line_item_amount[' + lineItem.id + ']" value="' + lineItem.amount + '">' +
'<input type="hidden" name="line_item_name[' + lineItem.id + ']" value="' + lineItem.name + '">' +
// Flash certain elements for a short time after display
$(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+ /*
+ * Check for input changes
+ */
+ var glmSubmitRequired = false;
+ $('input, textarea, select').on( 'change', function() {
+ glmSubmitRequired = true;
+ });
+
+ /*
+ * Checks for leaving the page
+ */
+
+ // When submit button is clicked, disable the beforeunload message
+ $('#create-invoice-form').on('click', function() {
+ glmSubmitRequired = false;
+ return true;
+ });
+
+ // If submit is required and we're laving the page, alert the user
+ $(window).bind('beforeunload', function() {
+ if (glmSubmitRequired) {
+ return true;
+ }
+ });
});
</script>