diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php
index a7b2e02..06e6143 100644
--- a/CRM/Civiquickbooks/Contact.php
+++ b/CRM/Civiquickbooks/Contact.php
@@ -2,13 +2,11 @@
/** 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');
-require_once 'library/CustomException.php';
-
/**
* @class CRM_Civiquickbooks_Contact
* Class for operating on Customers in Quickbooks Online. These are known as
@@ -174,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)
@@ -191,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 = [];
@@ -211,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;
@@ -222,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'] ]),
@@ -604,10 +604,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/CRM/Civiquickbooks/Invoice.php b/CRM/Civiquickbooks/Invoice.php
index 2659ce9..9a0c8d3 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',
@@ -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;
@@ -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();
}
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);
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.',
];
}
}
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.
*
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()}";
- }
-
-}