);
// find out if this invoice is a renewal.
- $is_renewal = $this->wpdb->get_var(
+ $invoiceData = $this->wpdb->get_var(
$this->wpdb->prepare(
- "SELECT renewal
+ "SELECT renewal,account
FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
WHERE id = %d",
$invoice_id
)
);
+ $account_id = $invoiceData['account'];
+ $is_renewal = $invoiceData['renewal'];
+ $this->updateAccountRenewalDate( $invoiceData['account'] );
// If this is a renewal then get all line items and update their renewal dates.
if ( $is_renewal ) {
);
if ( $line_items ) {
foreach ( $line_items as $account ) {
- $this->updateAccountRenewalDate( $account['account'] );
+ if ( $account['account'] && $account['account'] != $account_id ) {
+ $this->updateAccountRenewalDate( $account['account'] );
+ }
}
}
}
'recurrence' => $new_member_invoice_type['recurrence'],
)
);
- echo '<pre>$invoice_id: ' . print_r( $invoice_id, true ) . '</pre>';
+ // echo '<pre>$invoice_id: ' . print_r( $invoice_id, true ) . '</pre>';
if ( $invoice_id ) {
if ( isset( $employees ) && is_array( $employees ) ) {
// Add line items for each employee.
);
}
// If one of the invoice line items is recurring then mark the invoice as renewal.
- if ( $renewal_invoice ) {
- $this->wpdb->update(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
- array( 'renewal' => 1 ),
- array( 'id' => $this->invoice_id ),
- array( '%s' ),
- array( '%d' )
- );
- // Check the billing account and see if it needs to have invoice_type set.
- $invoice_type_id = $this->wpdb->get_var(
- $this->wpdb->prepare(
- "SELECT invoice_type
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
- WHERE id = %d",
- $_REQUEST['account']
- )
- );
- if ( !$invoice_type_id ) {
- // Then setup the invoice_type id
- $this->wpdb->update(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
- array(
- 'invoice_type' => $line_item,
- 'email_invoice' => true
- ),
- array( 'id' => $_REQUEST['account'] ),
- array(
- '%d',
- '%d'
- ),
- array( '%d' )
- );
- }
- }
+ // if ( $renewal_invoice ) {
+ // $this->wpdb->update(
+ // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+ // array( 'renewal' => 1 ),
+ // array( 'id' => $this->invoice_id ),
+ // array( '%s' ),
+ // array( '%d' )
+ // );
+ // // Check the billing account and see if it needs to have invoice_type set.
+ // $invoice_type_id = $this->wpdb->get_var(
+ // $this->wpdb->prepare(
+ // "SELECT invoice_type
+ // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ // WHERE id = %d",
+ // $_REQUEST['account']
+ // )
+ // );
+ // if ( !$invoice_type_id ) {
+ // // Then setup the invoice_type id
+ // $this->wpdb->update(
+ // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ // array(
+ // 'invoice_type' => $line_item,
+ // 'email_invoice' => true
+ // ),
+ // array( 'id' => $_REQUEST['account'] ),
+ // array(
+ // '%d',
+ // '%d'
+ // ),
+ // array( '%d' )
+ // );
+ // }
+ // }
}
}
$invoiceAdded = true;
}
// If one of the invoice line items is recurring then mark the invoice as renewal.
if ( $renewal_invoice ) {
- $this->wpdb->update(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
- array( 'renewal' => 1 ),
- array( 'id' => $this->invoice_id ),
- array( '%s' ),
- array( '%d' )
- );
+ // $this->wpdb->update(
+ // GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+ // array( 'renewal' => 1 ),
+ // array( 'id' => $this->invoice_id ),
+ // array( '%s' ),
+ // array( '%d' )
+ // );
}
}
}
</label>
<textarea id="notes" name="notes">{if $invoices.fieldData.notes}{$invoices.fieldData.notes}{/if}</textarea>
</div>
+
+ {* Renewal *}
+ {$ui = [
+ 'value' => $invoices.fieldData.renewal.value|default:true,
+ 'field' => 'renewal',
+ 'label' => 'Renewal',
+ 'required' => false,
+ 'errorText' => 'Renewal is Required',
+ 'dataError' => '',
+ 'tip' => 'On will set the accounts renewal date when this invoice is paid'
+ ]}
+ {include file='ui/f6/checkbox.html'}
+
<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>
<th width="80">Due Date</th>
<th width="120">Amount Total</th>
<th width="120">Balance</th>
+ <th width="120">Renewal</th>
</tr>
</thead>
<tbody>
<td> {$t.due_date.date} </td>
<td> {$t.amount_total} </td>
<td> <span id="balance-{$t.id}">{$t.balance}</span> </td>
+ <td> {if $t.renewal.value}Yes{else}No{/if} </td>
</tr>
<tr id="invoice-container-{$t.id}" class="glm-invoice-links hide-for-large {if $t@iteration is div by 2} alternate{/if}">
- <td colspan="7">
+ <td colspan="8">
<span class="account-dashboard-link">
<a href="{$adminUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=edit&id={$t.id}">Edit</a> |
</span>