Updating the billing import scripts for uptra
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 22 Mar 2019 19:40:41 +0000 (15:40 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 22 Mar 2019 19:40:41 +0000 (15:40 -0400)
Also this includes the script for verifying the billing data.

models/admin/management/billing.php
models/admin/management/importBillingData.php
models/admin/management/verifyBillingData.php

index 1bd76c3..12164f7 100644 (file)
@@ -153,10 +153,10 @@ class GlmMembersAdmin_management_billing extends GlmDataBillingManagement
                 $regSettings = $this->updateEntry( $id );
 
                 // Check if we were successful
-                if ($regSettings['status']) {
+                if ( $regSettings['status'] ) {
 
                     $settingsUpdated = true;
-                    $regSettings = $this->editEntry( $id );
+                    $regSettings     = $this->editEntry( $id );
 
                 } else {
                     $settingsUpdateError = true;
@@ -191,7 +191,7 @@ class GlmMembersAdmin_management_billing extends GlmDataBillingManagement
                     $option2 = '';
                 }
                 switch ( $option2 ) {
-                case 'verify':
+                case 'import':
                     require_once GLM_MEMBERS_BILLING_PLUGIN_PATH.'/models/admin/management/importBillingData.php';
                     // die('here');
                     break;
index c433674..63f329b 100644 (file)
@@ -5,6 +5,8 @@
 // For billing support functions
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
 $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+$limit = 10;
 // Connect to their live database.
 $dbh = new PDO(
     'pgsql: host=ds5 dbname=uptravel user=postgres',
@@ -15,10 +17,7 @@ $dbh = new PDO(
     )
 );
 
-$dbh->setAttribute(
-    PDO::ATTR_ERRMODE,
-    PDO::ERRMODE_EXCEPTION
-);
+$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
 
 if ( isset( $_REQUEST['start'] ) && $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ) ) {
 } else {
@@ -43,7 +42,7 @@ SELECT *
   FROM members.billing
 $sqlWhere
  ORDER BY transaction_date,transaction_time
- LIMIT 10
+ LIMIT $limit
 OFFSET $start";
 
 $statsSql = "SELECT count(*)
@@ -240,4 +239,4 @@ if ( $billingRecords ) {
     }
 }
 
-$numberProcessed = $start + 10;
+$numberProcessed = $start + $limit;
index 75b180d..0a37d9e 100644 (file)
@@ -15,10 +15,7 @@ $dbh = new PDO(
     )
 );
 
-$dbh->setAttribute(
-    PDO::ATTR_ERRMODE,
-    PDO::ERRMODE_EXCEPTION
-);
+$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
 
 if ( isset( $_REQUEST['start'] ) && $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ) ) {
 } else {
@@ -31,16 +28,26 @@ $importResults = '';
 $query = "
 SELECT id,name
   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
- WHERE id in ( SELECT DISTINCT ref_dest
-                 FROM  " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts )
+ WHERE id in (
+    SELECT DISTINCT ref_dest
+      FROM  " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts )
+   AND old_member_id IN ( 17484, 4799, 17035, 6040, 5442, 5434, 18660 )
 LIMIT 20 OFFSET 0";
 
 $results = $this->wpdb->get_results( $query, ARRAY_A );
 
-$importResults .= '<pre>$results: ' . print_r( $results, true ) . '</pre>';
+// $importResults .= '<pre>$results: ' . print_r( $results, true ) . '</pre>';
 
 
 foreach ( $results as $row ) {
-    $account_id = $BillingSupport->getAccountByRefDest( $row['id'] );
-    echo '<pre>$account_id: ' . print_r( $account_id, true ) . '</pre>';
+    // Get balance due
+    $account    = $BillingSupport->getAccountByRefDest( $row['id'] );
+    if ( !$account ) {
+        $importResults .= '<p>No account</p>';
+    } else {
+        $importResults .= '<p>Account: ' . $account['id'] . '</p>';
+    }
+    $balanceDue = $BillingSupport->getBalanceDueByAccount( $account['id'] );
+    $importResults .= '<pre>$balanceDue: ' . print_r( $balanceDue, true ) . '</pre>';
+    // $importResults .= '<pre>$account_id: ' . print_r( $account_id, true ) . '</pre>';
 }