Skip to content

Commit

Permalink
Merge CIVIQBO-107 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Oct 16, 2023
2 parents 16cafe8 + e3ee5cd commit 970863b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 139 deletions.
26 changes: 11 additions & 15 deletions CRM/Civiquickbooks/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 = [];

Expand All @@ -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;

Expand All @@ -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'] ]),
Expand Down Expand Up @@ -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 {

}
10 changes: 4 additions & 6 deletions CRM/Civiquickbooks/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Civiquickbooks/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions CRM/Civiquickbooks/Page/OAuthQBO.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function run() {
// Successfully tokens and Company details stored in database.
$this->output = [
'message' => 'Access token updated',
'redirect_url' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/quickbooks/settings', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to see new access token expiry date</a>',
'redirect_url' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/admin/setting/quickbooks', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to see new access token expiry date</a>',
];

} catch (\QuickBooksOnline\API\Exception\IdsException $e) {
Expand All @@ -136,7 +136,7 @@ public function run() {

$this->output = [
'message' => $e->getMessage(),
'redirect_url' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/quickbooks/settings', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to try again.</a>',
'redirect_url' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/admin/setting/quickbooks', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to try again.</a>',
];
}
}
Expand All @@ -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' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/quickbooks/settings', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to authorize CiviCRM to sync with QuickBooks.</a>',
'redirect_url' => '<a href="' . str_replace('&amp;', '&', CRM_Utils_System::url('civicrm/admin/setting/quickbooks', NULL, TRUE, NULL)) . '">View the CiviQuickbooks settings page to authorize CiviCRM to sync with QuickBooks.</a>',
];
}
}
Expand Down
27 changes: 0 additions & 27 deletions civiquickbooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*
Expand All @@ -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.
*
Expand Down
87 changes: 0 additions & 87 deletions library/CustomException.php

This file was deleted.

0 comments on commit 970863b

Please sign in to comment.