Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CiviAccountSync Cancel Contributions is now too enthusiastic #38

Open
kenwest opened this issue Aug 14, 2018 · 4 comments
Open

CiviAccountSync Cancel Contributions is now too enthusiastic #38

kenwest opened this issue Aug 14, 2018 · 4 comments

Comments

@kenwest
Copy link
Contributor

kenwest commented Aug 14, 2018

Since the PR for CIVIXERO-15 the CiviAccountSync Cancel Contributions job is too enthusiastic

  1. It cancels contributions that are already cancelled
  2. It fails trying to cancel deleted contributions

Cancelling already-cancelled contributions
The job should not do this. It's harmless while the data set is small but will kill the job on larger sets

Deleted contributions
The job uses the CiviCRM API for contribution/create which assumes that if you pass in the contribution Id then it will exist. But if the contribution was deleted in CiviCRM the job fails.

Proposal
Update the query as follows ...

    */
   public static function cancelContributionFromAccountsStatus($params) {
     //get pending registrations
     $sql = "SELECT  cas.contribution_id
       FROM civicrm_account_invoice cas
-       LEFT JOIN civicrm_contribution  civi ON cas.contribution_id = civi.id
+       JOIN civicrm_contribution  civi ON cas.contribution_id = civi.id
       WHERE accounts_status_id =3
+      AND civi.contribution_status_id <> 3
     ";
     $dao = CRM_Core_DAO::executeQuery($sql);
 
@kenwest
Copy link
Contributor Author

kenwest commented Aug 14, 2018

You might consider this overkill but here's a bonus suggestion

Use a job parameter to select the Contributions on which to act
Add a job parameter "current_contribution_status" ...

current_contribution_status=!3
would select Contributions that are not Cancelled ie civi.contribution_status_id not in (3)

current_contribution_status=2
would reproduce the "classic" behaviour and select Contributions that are Pending ie civi.contribution_status_id in (2)

current_contribution_status=2,4,5
would translate to civi.contribution_status_id in (2,4,5)

@eileenmcnaughton
Copy link
Owner

@kenwest is that before or after this one - 5bae5ac

@kenwest
Copy link
Contributor Author

kenwest commented Aug 14, 2018

@eileenmcnaughton it is after (note I have the WHERE keyword in my proposed change.)

@eileenmcnaughton
Copy link
Owner

@kenwest I think excluding cancelled statuses makes sense & I think an optional job param of contribution_status_id makes sense too- it should use the api formats which can be handled with

  $whereClause = CRM_Core_DAO::createSQLFilter('contribution_status_id', $params[''contribution_status_id'], CRM_Utils_Type::T_INT);

(e.g then IN, NOT IN etc are supported & if the spec function declares the contribution_status_id field with the 'pseudoconstant' field then it will support words like 'Cancelled'

kenwest added a commit to kenwest/nz.co.fuzion.civixero that referenced this issue Aug 24, 2018
…Contributions' job.

See [1] for the corresponding PR in nz.co.fuzion.accountsync.
See [2] and []3 for descriptions of the issue
[1] kenwest/nz.co.fuzion.accountsync@d3ba735
[2] eileenmcnaughton/nz.co.fuzion.accountsync#38
[3] eileenmcnaughton#43
kenwest added a commit to kenwest/nz.co.fuzion.civixero that referenced this issue Sep 7, 2020
…Contributions' job.

See [1] for the corresponding PR in nz.co.fuzion.accountsync.
See [2] and []3 for descriptions of the issue
[1] kenwest/nz.co.fuzion.accountsync@d3ba735
[2] eileenmcnaughton/nz.co.fuzion.accountsync#38
[3] eileenmcnaughton#43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants