* @access public
* @return void
*/
- public function recordInvoice( $invoice_id, $account, $total )
+ public function recordInvoice( $invoice_id, $account, $total, $transaction_time = null )
{
- $this->recordTransaction( $this->config['transaction_numb']['Invoice'], $invoice_id, $account, $total, null );
+ $this->recordTransaction( $this->config['transaction_numb']['Invoice'], $invoice_id, $account, $total, null, $transaction_time );
}
/**
* @access public
* @return void
*/
- public function recordPayment( $payment_id, $account, $payment, $invoices = null, $method = null )
+ public function recordPayment( $payment_id, $account, $payment, $invoices = null, $method = null, $transaction_time = null )
{
// record into the transaction table
if ( $method ) {
} else {
$paymentMethod = $this->config['transaction_numb']['Payment'];
}
- $this->recordTransaction( $paymentMethod, $payment_id, $account, null, $payment );
+ $this->recordTransaction( $paymentMethod, $payment_id, $account, null, $payment, $transaction_time );
// If there's an invoice_id
// If the payment amount is over then go through the other invoices.
* @access public
* @return void
*/
- public function recordTransaction( $type, $type_id, $account, $current_invoice_total = null, $current_payment_total = null )
+ public function recordTransaction( $type, $type_id, $account, $current_invoice_total = null, $current_payment_total = null, $transaction_time )
{
$current_invoice_total = ( $current_invoice_total == null ) ? '0.00': $current_invoice_total;
$current_payment_total = ( $current_payment_total == null ) ? '0.00': $current_payment_total;
'type' => $type,
'type_id' => $type_id,
'account' => $account,
- 'transaction_time' => date('Y-m-d H:i;s'),
+ 'transaction_time' => ( $transaction_time ) ? $transaction_time: date('Y-m-d H:i;s'),
'current_invoice_total' => $current_invoice_total,
'current_payment_total' => $current_payment_total,
),
// Connect to their live database.
$dbh = new PDO(
- 'pgsql: host=ds4.gaslightmedia.com dbname=uptravel user=nobody',
+ 'pgsql: host=localhost dbname=uptravel user=postgres password=tweety',
null,
null,
array(
$importResults = '';
-// Get total number of records.
+// Get records.
$sql = "
SELECT *
FROM members.billing
WHERE invoice_id IN (
SELECT invoice_id
FROM members.billing
- WHERE transaction_date >= '2018-01-01'
- AND billing_type = 1
- ORDER BY transaction_date,transaction_time
- LIMIT 10 OFFSET 0)
- AND billing_type IN (1, 2)
- ORDER BY transaction_date,transaction_time
- LIMIT 20
-OFFSET 0";
+ WHERE billing_type = 1
+ AND transaction_time >= '2017-01-01'
+ ORDER BY transaction_date,transaction_time)
+ AND billing_type IN (1,2,3)
+ ORDER BY transaction_date,transaction_time";
+// LIMIT 20
+//OFFSET 0";
//LIMIT 10
//OFFSET $start";
)
);
if ( $refDest ) {
- $accountId = $BillingSupport->getAccountByRefDest( $refDest );
- // $importResults .= '<pre>$accountId: ' . print_r( $accountId, true ) . '</pre>';
- if ( $accountId ) {
+ $account = $BillingSupport->getAccountByRefDest( $refDest );
+ // $importResults .= '<pre>$account: ' . print_r( $account, true ) . '</pre>';
+ if ( $account ) {
// Get the invoice Type
- $invoiceType = $BillingSupport->getInvoiceTypeById( $accountId['invoice_type'] );
+ $invoiceType = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] );
// $importResults .= '<pre>$invoiceType: ' . print_r( $invoiceType, true ) . '</pre>';
if ( $invoiceType ) {
// Check the type (1 = invoice, 2 = payment, 3 = Adjustment, 4 = Comment)
GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
array(
'transaction_time' => $billingRecord['transaction_time'],
- 'account' => $accountId['id'],
+ 'account' => $account['id'],
'old_invoice_id' => $billingRecord['invoice_id'],
'amount_total' => $billingRecord['amount'],
'balance' => $billingRecord['balance'],
);
$newInvoiceId = $this->wpdb->insert_id;
if ( $newInvoiceId ) {
- $BillingSupport->createLineItemForInvoice(
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
array(
- 'invoice_id' => $newInvoiceId,
+ 'invoice' => $newInvoiceId,
'line_item_type' => $invoiceType['id'],
- 'account' => $accountId['id'],
+ 'account' => $account['id'],
'name' => $invoiceType['name'],
'amount' => $billingRecord['amount'],
- 'due_date' => $billingRecord['transaction_date'],
+ 'quantity' => 1,
+ 'total' => $billingRecord['amount'],
+ 'created' => $billingRecord['transaction_time'],
+ 'first_due_date' => $billingRecord['transaction_date'],
+ 'next_due_date' => $billingRecord['transaction_date'],
'recurring' => $invoiceType['recurring'],
- 'recurrence' => $invoiceType['recurrence'],
+ 'recurrence' => $invoiceType['recurrence']
+ ),
+ array(
+ '%d', // invoice
+ '%d', // line_item_type (invoiceType id)
+ '%d', // account
+ '%s', // name
+ '%s', // amount
+ '%d', // quantity
+ '%d', // total
+ '%s', // created
+ '%s', // first_due_date
+ '%s', // next_due_date
+ '%s', // recurring
+ '%d', // recurrence
)
);
- $BillingSupport->recordInvoice( $newInvoiceId, $accountId['id'], $billingRecord['amount'] );
+ $BillingSupport->recordInvoice( $newInvoiceId, $account['id'], $billingRecord['amount'], $billingRecord['transaction_time'] );
}
break;
GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'payments',
array(
'transaction_time' => $billingRecord['transaction_time'],
- 'account' => $accountId['id'],
+ 'account' => $account['id'],
'amount' => $billingRecord['amount'],
'payment_method' => $paymentMethod,
'payment_data' => $billingRecord['payment_data'],
if ( $paymentId ) {
$BillingSupport->recordPayment(
$paymentId,
- $accountId['id'],
+ $account['id'],
$billingRecord['amount'],
array( $newInvoiceId ),
- $this->config['transaction_numb']['Payment']
+ $this->config['transaction_numb']['Payment'],
+ $billingRecord['transaction_time']
);
}
}