From: Steve Sutton Date: Fri, 28 Dec 2018 20:56:50 +0000 (-0500) Subject: Testing billing X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=7155b5fe1a55c615b08ef418ed63949a01166237;p=WP-Plugins%2Fglm-member-db-billing.git Testing billing Working on the import of uptra data. Fix for quicken file exporter. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 319c1ee..18a7fa3 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -76,9 +76,9 @@ class GlmBillingSupport * @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 ); } /** @@ -98,7 +98,7 @@ class GlmBillingSupport * @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 ) { @@ -106,7 +106,7 @@ class GlmBillingSupport } 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. @@ -337,7 +337,7 @@ class GlmBillingSupport * @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; @@ -347,7 +347,7 @@ class GlmBillingSupport '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, ), diff --git a/classes/data/dataTransactions.php b/classes/data/dataTransactions.php index 9da515c..3a535d1 100644 --- a/classes/data/dataTransactions.php +++ b/classes/data/dataTransactions.php @@ -143,6 +143,14 @@ class GlmDataTransactions extends GlmDataAbstract 'use' => 'a' ), + 'account_id' => array( + 'field' => 'account', + 'type' => 'integer', + 'as' => 'account_id', + 'required' => false, + 'use' => 'a' + ), + // Transaction time 'transaction_time' => array( 'field' => 'transaction_time', diff --git a/models/admin/ajax/exportQIF.php b/models/admin/ajax/exportQIF.php index bbb8c7c..1374d4e 100644 --- a/models/admin/ajax/exportQIF.php +++ b/models/admin/ajax/exportQIF.php @@ -164,7 +164,8 @@ class GlmMembersAdmin_ajax_exportQIF extends GlmDataTransactions // echo '
$record: ' . print_r( $record, true ) . '
'; switch ( $record['type'] ) { case $this->config['transaction_numb']['Payment']: - $account = $BillingSupport->getAccountById( $record['type_id'] ); + $account = $BillingSupport->getAccountById( $record['account_id'] ); + // echo '
$account: ' . print_r( $account, true ) . '
'; if ( $account ) { $paymentType = $paymentTypes[$account['invoice_type']]; // echo '
$paymentType: ' . print_r( $paymentType, true ) . '
'; diff --git a/models/admin/billing/reports.php b/models/admin/billing/reports.php index f6a656b..0ae8d46 100644 --- a/models/admin/billing/reports.php +++ b/models/admin/billing/reports.php @@ -258,7 +258,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions } else { switch ( $option ) { case 'reportGenerator': - $orderBy = 'transaction_time'; + $orderBy = 'transaction_time DESC'; $this->member_data = true; $this->notes = true; $accountsResult = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit ); diff --git a/models/admin/management/importBillingData.php b/models/admin/management/importBillingData.php index 6b095fc..ad58300 100644 --- a/models/admin/management/importBillingData.php +++ b/models/admin/management/importBillingData.php @@ -8,7 +8,7 @@ $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); // 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( @@ -28,21 +28,20 @@ if ( isset( $_REQUEST['start'] ) && $start = filter_var( $_REQUEST['start'], FIL $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"; @@ -72,11 +71,11 @@ if ( $billingRecords ) { ) ); if ( $refDest ) { - $accountId = $BillingSupport->getAccountByRefDest( $refDest ); - // $importResults .= '
$accountId: ' . print_r( $accountId, true ) . '
'; - if ( $accountId ) { + $account = $BillingSupport->getAccountByRefDest( $refDest ); + // $importResults .= '
$account: ' . print_r( $account, true ) . '
'; + if ( $account ) { // Get the invoice Type - $invoiceType = $BillingSupport->getInvoiceTypeById( $accountId['invoice_type'] ); + $invoiceType = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] ); // $importResults .= '
$invoiceType: ' . print_r( $invoiceType, true ) . '
'; if ( $invoiceType ) { // Check the type (1 = invoice, 2 = payment, 3 = Adjustment, 4 = Comment) @@ -87,7 +86,7 @@ if ( $billingRecords ) { 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'], @@ -114,19 +113,38 @@ if ( $billingRecords ) { ); $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; @@ -165,7 +183,7 @@ if ( $billingRecords ) { 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'], @@ -182,10 +200,11 @@ if ( $billingRecords ) { 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'] ); } }