Testing billing
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 28 Dec 2018 20:56:50 +0000 (15:56 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 28 Dec 2018 20:56:50 +0000 (15:56 -0500)
Working on the import of uptra data.
Fix for quicken file exporter.

classes/billingSupport.php
classes/data/dataTransactions.php
models/admin/ajax/exportQIF.php
models/admin/billing/reports.php
models/admin/management/importBillingData.php

index 319c1ee..18a7fa3 100644 (file)
@@ -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,
             ),
index 9da515c..3a535d1 100644 (file)
@@ -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',
index bbb8c7c..1374d4e 100644 (file)
@@ -164,7 +164,8 @@ class GlmMembersAdmin_ajax_exportQIF extends GlmDataTransactions
             // echo '<pre>$record: ' . print_r( $record, true ) . '</pre>';
             switch ( $record['type'] ) {
             case $this->config['transaction_numb']['Payment']:
-                $account     = $BillingSupport->getAccountById( $record['type_id'] );
+                $account = $BillingSupport->getAccountById( $record['account_id'] );
+                // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
                 if ( $account ) {
                     $paymentType = $paymentTypes[$account['invoice_type']];
                     // echo '<pre>$paymentType: ' . print_r( $paymentType, true ) . '</pre>';
index f6a656b..0ae8d46 100644 (file)
@@ -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 );
index 6b095fc..ad58300 100644 (file)
@@ -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 .= '<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)
@@ -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']
                                 );
                             }
                         }