From 8f20f42a0e64ca4190d87b6cb864f783c77703f2 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 13 Oct 2023 15:58:36 +1100 Subject: [PATCH 1/9] CIVIQBO-107 Remove CustomException class with PHP 8.1 compatibility issue --- CRM/Civiquickbooks/Contact.php | 8 +--- library/CustomException.php | 87 ---------------------------------- 2 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 library/CustomException.php diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php index a7b2e02..a3b308f 100644 --- a/CRM/Civiquickbooks/Contact.php +++ b/CRM/Civiquickbooks/Contact.php @@ -7,8 +7,6 @@ require E::path('vendor/autoload.php'); -require_once 'library/CustomException.php'; - /** * @class CRM_Civiquickbooks_Contact * Class for operating on Customers in Quickbooks Online. These are known as @@ -604,10 +602,6 @@ protected function getQBOContactByName($name, $givenName = NULL) { } -/** - * it uses Class declared in library/CustomException.php - * Class ContactPullGetQBCustomersException - */ -class CRM_Civiquickbooks_Contact_Exception extends CustomException { +class CRM_Civiquickbooks_Contact_Exception extends CRM_Core_Exception { } diff --git a/library/CustomException.php b/library/CustomException.php deleted file mode 100644 index 85572a5..0000000 --- a/library/CustomException.php +++ /dev/null @@ -1,87 +0,0 @@ -message}' in {$this->file}({$this->line})\n" - . "{$this->getTraceAsString()}"; - } - -} From ddcd525290e5790408507ba225ec8f738a91eea0 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 13 Oct 2023 15:59:40 +1100 Subject: [PATCH 2/9] CIVIQBO-107 import AccountContact entity to CRM_Civiquickbooks_Contact --- CRM/Civiquickbooks/Contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php index a3b308f..f903cc5 100644 --- a/CRM/Civiquickbooks/Contact.php +++ b/CRM/Civiquickbooks/Contact.php @@ -2,7 +2,7 @@ /** Load CiviX ExtensionUtil class and bundled autoload resolver. **/ -use Civi\Api4\EntityTag; +use Civi\Api4\{EntityTag,AccountContact}; use CRM_Civiquickbooks_ExtensionUtil as E; require E::path('vendor/autoload.php'); From b734d9fbbade42e42a76a70273630fe3ee9cd64d Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 13 Oct 2023 16:00:15 +1100 Subject: [PATCH 3/9] CIVIQBO-107 Remove obsolete civix hooks --- civiquickbooks.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/civiquickbooks.php b/civiquickbooks.php index b233acb..f15b8db 100644 --- a/civiquickbooks.php +++ b/civiquickbooks.php @@ -30,15 +30,6 @@ function civiquickbooks_civicrm_postInstall() { _civiquickbooks_civix_civicrm_postInstall(); } -/** - * Implements hook_civicrm_uninstall(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall - */ -function civiquickbooks_civicrm_uninstall() { - _civiquickbooks_civix_civicrm_uninstall(); -} - /** * Implements hook_civicrm_enable(). * @@ -48,24 +39,6 @@ function civiquickbooks_civicrm_enable() { _civiquickbooks_civix_civicrm_enable(); } -/** - * Implements hook_civicrm_disable(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable - */ -function civiquickbooks_civicrm_disable() { - _civiquickbooks_civix_civicrm_disable(); -} - -/** - * Implements hook_civicrm_upgrade(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade - */ -function civiquickbooks_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { - return _civiquickbooks_civix_civicrm_upgrade($op, $queue); -} - /** * Map quickbooks accounts data to generic data. * From bf91714997107cb4c79f046c9c6a78945d9875a7 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 13 Oct 2023 16:14:52 +1100 Subject: [PATCH 4/9] CIVIQBO-107 Correct URLs referring back to settings page --- CRM/Civiquickbooks/Page/OAuthQBO.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Civiquickbooks/Page/OAuthQBO.php b/CRM/Civiquickbooks/Page/OAuthQBO.php index 5c27c64..9a9e99f 100644 --- a/CRM/Civiquickbooks/Page/OAuthQBO.php +++ b/CRM/Civiquickbooks/Page/OAuthQBO.php @@ -127,7 +127,7 @@ public function run() { // Successfully tokens and Company details stored in database. $this->output = [ 'message' => 'Access token updated', - 'redirect_url' => 'View the CiviQuickbooks settings page to see new access token expiry date', + 'redirect_url' => 'View the CiviQuickbooks settings page to see new access token expiry date', ]; } catch (\QuickBooksOnline\API\Exception\IdsException $e) { @@ -136,7 +136,7 @@ public function run() { $this->output = [ 'message' => $e->getMessage(), - 'redirect_url' => 'View the CiviQuickbooks settings page to try again.', + 'redirect_url' => 'View the CiviQuickbooks settings page to try again.', ]; } } @@ -150,7 +150,7 @@ public function run() { // Output error if User denied the access. $this->output = [ 'message' => 'Unauthorized request. Please authorize CiviCRM to sync with QuickBooks', - 'redirect_url' => 'View the CiviQuickbooks settings page to authorize CiviCRM to sync with QuickBooks.', + 'redirect_url' => 'View the CiviQuickbooks settings page to authorize CiviCRM to sync with QuickBooks.', ]; } } From 8c88c02d8387a58bbc58029c624c33437dd66bd9 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 11:46:34 +1100 Subject: [PATCH 5/9] CIVIQBO-107 Fix syntax error in CRM_Civiquickbooks_Page_AJAX --- CRM/Civiquickbooks/Page/AJAX.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Civiquickbooks/Page/AJAX.php b/CRM/Civiquickbooks/Page/AJAX.php index d847b15..3dc44e6 100644 --- a/CRM/Civiquickbooks/Page/AJAX.php +++ b/CRM/Civiquickbooks/Page/AJAX.php @@ -33,7 +33,7 @@ public static function invoiceSyncErrors() { $contributions = _civiquickbooks_getContactContributions($contactid); $invoices = _civiquickbooks_getErroredInvoicesOfContributions($contributions); foreach ($invoices['values'] as $invoice) { - $syncerrors = array_merge($syncerrors, json_decode($invoice['error_data"], TRUE)); + $syncerrors = array_merge($syncerrors, json_decode($invoice['error_data'], TRUE)); } } CRM_Utils_JSON::output($syncerrors); From b057ce6f6970ad0e99f87e7cac3a90fa5ef9bee3 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 11:53:02 +1100 Subject: [PATCH 6/9] CIVIQBO-107 Correct accounts status for completed invoices This fixes a regression introduced in 66ee833 --- CRM/Civiquickbooks/Invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php index 2659ce9..7a65a5a 100644 --- a/CRM/Civiquickbooks/Invoice.php +++ b/CRM/Civiquickbooks/Invoice.php @@ -346,7 +346,7 @@ protected function saveToCiviCRM($invoice, $record) { } $record['accounts_needs_update'] = 0; - $record['accounts_status_id'] = 'cancelled'; + $record['accounts_status_id'] = 'completed'; CRM_Core_DAO::setFieldValue( 'CRM_Accountsync_DAO_AccountInvoice', From 4bf559dc4cdca4927b95d1c7856d804f11756085 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 13:41:17 +1100 Subject: [PATCH 7/9] CIVIQBO-105 Remove incorrect accounts_needs_update condition on invoicePull. --- CRM/Civiquickbooks/Invoice.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php index 7a65a5a..fbd10f1 100644 --- a/CRM/Civiquickbooks/Invoice.php +++ b/CRM/Civiquickbooks/Invoice.php @@ -958,14 +958,12 @@ protected function findPullContributions($params, $limit) { ->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'])) { $accountInvoices->addWhere('contribution_id', '=', $params['contribution_id']); } - else { - $accountInvoices->addWhere('accounts_needs_update', '=', TRUE); - } + return $accountInvoices->execute()->getArrayCopy(); } From 189e6c3d05d87ab3dd686009477a32a6c252c7ed Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 13:49:44 +1100 Subject: [PATCH 8/9] CIVIQBO-107 Prevent undefined index warning for account_type_code --- CRM/Civiquickbooks/Invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php index fbd10f1..9a0c8d3 100644 --- a/CRM/Civiquickbooks/Invoice.php +++ b/CRM/Civiquickbooks/Invoice.php @@ -553,7 +553,7 @@ protected function mapToAccounts($db_contribution, $accountsID, $SyncToken, $qb_ // We will use account type code to get state tax code id for US companies $tax_types[$line_item['financial_type_id']] = [ 'sale_tax_acctgCode' => $tmp, - 'sale_tax_account_type_code' => htmlspecialchars_decode($entityFinancialAccount['financial_account_id.account_type_code']), + 'sale_tax_account_type_code' => htmlspecialchars_decode($entityFinancialAccount['financial_account_id.account_type_code'] ?? NULL), ]; $tax_codes[] = $tmp; From e3ee5cd7968d5b4134e731f6c4a8292c738e0915 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 17:10:30 +1100 Subject: [PATCH 9/9] CIVIQBO-105 fix contact fetching for AccountSync API4 --- CRM/Civiquickbooks/Contact.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php index f903cc5..06e6143 100644 --- a/CRM/Civiquickbooks/Contact.php +++ b/CRM/Civiquickbooks/Contact.php @@ -172,7 +172,6 @@ public function pull($params) { */ public function push($params) { $abort_loop = FALSE; - $params['limit'] = $params['limit'] ?? PHP_INT_MAX; try { $accountContacts = AccountContact::get(FALSE) @@ -189,14 +188,19 @@ public function push($params) { // If we specified a CiviCRM contact ID just push that contact. if (!empty($params['contact_id'])) { $accountContacts - ->addWhere('contact_id', '=', $params['contact_id']) - ->addWhere('accounts_needs_update', '=', FALSE); + ->addWhere('contact_id', '=', $params['contact_id']); } else { $accountContacts ->addWhere('contact_id', 'IS NOT NULL') ->addWhere('accounts_needs_update', '=', TRUE); } + + if(!empty($params['limit'])) { + $accountContacts + ->setLimit($params['limit']); + } + $records = $accountContacts->execute()->getArrayCopy(); $errors = []; @@ -209,7 +213,7 @@ public function push($params) { throw new CRM_Core_Exception('Could not get DataService Object: ' . $e->getMessage()); } - foreach (array_slice($records, 0, $params['limit']) as $account_contact) { + foreach ($records as $account_contact) { if($abort_loop) break; @@ -220,9 +224,7 @@ public function push($params) { try { $id = isset($account_contact['accounts_contact_id']) ? $account_contact['accounts_contact_id'] : NULL; - // NOTE if we store the json string in the response directly using Accountsync API, it will serialized it for us automatically. - // And when we get it out using api, it will deserialize automatically for us. - $accounts_data = isset($account_contact['accounts_contact_id']) ? $account_contact['accounts_data'] : NULL; + $accounts_data = isset($account_contact['accounts_data']) ? json_decode($account_contact['accounts_data'], TRUE) : []; $QBOContact = $this->mapToCustomer( civicrm_api3('contact', 'getsingle', [ 'id' => $account_contact['contact_id'] ]),