From 1421b3de652a870e20d10ad0964473cb3bfcebb6 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 28 Nov 2022 23:52:09 +0000 Subject: [PATCH 1/2] Update for latest version of accountsync --- CRM/Civiquickbooks/Invoice.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php index 1f05325..3b0eb9d 100644 --- a/CRM/Civiquickbooks/Invoice.php +++ b/CRM/Civiquickbooks/Invoice.php @@ -344,7 +344,7 @@ protected function saveToCiviCRM($invoice, $record) { } $record['accounts_needs_update'] = 0; - $record['accounts_status_id'] = 3; + $record['accounts_status_id'] = 'cancelled'; CRM_Core_DAO::setFieldValue( 'CRM_Accountsync_DAO_AccountInvoice', @@ -937,7 +937,7 @@ protected function findPushContributions($params, $limit) { 'accounts_needs_update' => 1, 'plugin' => $this->plugin, 'connector_id' => 0, - 'accounts_status_id' => ['NOT IN', 3], + 'accounts_status_id' => ['NOT IN', 'completed'], 'options' => [ 'sort' => 'error_data ASC', 'limit' => $limit, @@ -964,7 +964,7 @@ protected function findPullContributions($params, $limit) { $criteria = [ 'plugin' => $this->plugin, 'connector_id' => 0, - 'accounts_status_id' => ['NOT IN', [1, 3]], + 'accounts_status_id' => ['NOT IN', ['completed', 'cancelled']], 'accounts_invoice_id' => ['IS NOT NULL' => 1], 'accounts_data' => ['IS NOT NULL' => 1], 'error_data' => ['IS NULL' => 1], From c5b83221c7d7e991229096eff015682bfda1ad98 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 29 Nov 2022 11:08:09 +0000 Subject: [PATCH 2/2] Convert findPush/PullContributions to API4 --- CRM/Civiquickbooks/Invoice.php | 75 ++++++++++++---------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php index 3b0eb9d..2659ce9 100644 --- a/CRM/Civiquickbooks/Invoice.php +++ b/CRM/Civiquickbooks/Invoice.php @@ -1,6 +1,8 @@ getMessage()); } - foreach ($records['values'] as $i => $record) { + foreach ($records as $i => $record) { try { $accountsInvoice = $this->getAccountsInvoice($record); @@ -166,7 +168,7 @@ public function pull($params = [], $limit = PHP_INT_MAX) { throw new CRM_Core_Exception('Could not get DataService Object: ' . $e->getMessage()); } - foreach ($records['values'] as $i => $record) { + foreach ($records as $i => $record) { try { //double check if the record has been synced or not if (!isset($record['accounts_invoice_id']) || !isset($record['accounts_data'])) { @@ -933,61 +935,38 @@ protected function generateTaxDetails($line_items) { * @throws \CiviCRM_API3_Exception */ protected function findPushContributions($params, $limit) { - $criteria = [ - 'accounts_needs_update' => 1, - 'plugin' => $this->plugin, - 'connector_id' => 0, - 'accounts_status_id' => ['NOT IN', 'completed'], - 'options' => [ - 'sort' => 'error_data ASC', - 'limit' => $limit, - ], - ]; + $accountInvoices = AccountInvoice::get() + ->addWhere('plugin', '=', $this->plugin) + ->addWhere('connector_id', '=', 0) + ->addWhere('accounts_status_id:name', 'NOT IN', ['completed']) + ->addOrderBy('error_data', 'ASC') + ->setLimit($limit); if (isset($params['contribution_id'])) { - $criteria['contribution_id'] = $params['contribution_id']; - unset($criteria['accounts_needs_update']); + $accountInvoices->addWhere('contribution_id', '=', $params['contribution_id']); } - - $records = civicrm_api3('AccountInvoice', 'get', $criteria); - - if (!isset($params['contribution_id'])) { - $criteria['accounts_status_id'] = ['IS NULL' => 1]; - - $nullrec = civicrm_api3('AccountInvoice', 'get', $criteria); - $records['values'] = array_merge($records['values'], $nullrec['values']); + else { + $accountInvoices->addWhere('accounts_needs_update', '=', TRUE); } - - return $records; + return $accountInvoices->execute()->getArrayCopy(); } protected function findPullContributions($params, $limit) { - $criteria = [ - 'plugin' => $this->plugin, - 'connector_id' => 0, - 'accounts_status_id' => ['NOT IN', ['completed', 'cancelled']], - 'accounts_invoice_id' => ['IS NOT NULL' => 1], - 'accounts_data' => ['IS NOT NULL' => 1], - 'error_data' => ['IS NULL' => 1], - 'options' => [ - 'sort' => 'error_data', - 'limit' => $limit, - ], - ]; + $accountInvoices = AccountInvoice::get() + ->addWhere('plugin', '=', $this->plugin) + ->addWhere('connector_id', '=', 0) + ->addWhere('accounts_status_id:name', 'NOT IN', ['completed', 'cancelled']) + ->addWhere('accounts_invoice_id', 'IS NOT NULL') + ->addWhere('accounts_data', 'IS NOT NULL') + ->addWhere('error_data', 'IS NULL') + ->addOrderBy('error_data', 'ASC') + ->setLimit($limit); if (isset($params['contribution_id'])) { - $criteria['contribution_id'] = $params['contribution_id']; - unset($criteria['accounts_needs_update']); + $accountInvoices->addWhere('contribution_id', '=', $params['contribution_id']); } - - $records = civicrm_api3('AccountInvoice', 'get', $criteria); - - if (!isset($params['contribution_id'])) { - $criteria['accounts_status_id'] = ['IS NULL' => 1]; - - $nullrec = civicrm_api3('AccountInvoice', 'get', $criteria); - $records['values'] = array_merge($records['values'], $nullrec['values']); + else { + $accountInvoices->addWhere('accounts_needs_update', '=', TRUE); } - - return $records; + return $accountInvoices->execute()->getArrayCopy(); } /**