}
+ public function removeInvoiceById( $invoice_id )
+ {
+ $this->wpdb->delete(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
+ array( 'invoice' => $invoice_id ),
+ array( '%d' )
+ );
+ $this->wpdb->delete(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
+ array( 'id' => $invoice_id ),
+ array( '%d' )
+ );
+ $this->wpdb->delete(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'transactions',
+ array( 'type' => $this->config['transaction_numb']['Invoice'], 'type_id' => $invoice_id ),
+ array( '%d', '%d' )
+ );
+ }
+
}
'due_date' => date( 'Y-m-d' ),
'member_invoice' => $member_invoice,
'employee_data' => $employees,
- 'employees' => $_REQUEST['employees']
+ 'employees' => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(),
);
if ( !$invoice_data ) {
$error = true;
// If there's any errors then re-show the form.
if ( $error ) {
- // TODO: Here we'll need to remove the invoice created if any.
+ // Remove the invoice created.
+ if ( $invoice_id ) {
+ $BillingSupport->removeInvoiceById( $invoice_id );
+ }
+
$view = 'renew';
// Get list of payable invoice_types
// Do the Payment Processing.
$errors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
// echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+ if ( $errors ) {
+ // $messages[] = '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+ if ( count( $errors ) > 0 ) {
+ $BillingSupport->removeInvoiceById( $invoice_id );
+ foreach ( $errors as $error ) {
+ $messages[] = '<span style="color: red;">'.$error.'</span>';
+ }
+ }
+ $view = 'renew';
+
+ // Get list of payable invoice_types
+ $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+
+ $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+ if ( $member_invoice_id ) {
+ $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+ }
+
+ // Get a list of this accounts employees. If they have any.
+ $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+ // Load DataClass for Management.
+ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';
+ $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+ $management = $Management->getEntry( 1 );
+
+ // Need to see if there's an account for this member.
+ $account = $Accounts->editEntry( $accountID );
+ }
}