Skip to content

Commit

Permalink
[REF] Add in CiviCRM Status checks to check for inconsistencies betwe…
Browse files Browse the repository at this point in the history
…en the membership_payment participant_payment and line item tables

Updates As per Dave
  • Loading branch information
seamuslee001 committed Nov 28, 2024
1 parent b3b377c commit 6270c97
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ext/civi_event/civi_event.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<?php

require_once 'civi_event.civix.php';

/**
* Implements hook_civicrm_check().
*
* Check for any legacy data where there is a participant_payment record but not a matching line item
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_check/
*/
function civi_event_civicrm_check(&$messages) :void {
$parcitipantPayments = CRM_Core_DAO::executeQuery("SELECT contribution_id, participant_id FROM civicrm_participant_payment");
$lineItemsMissingPayments = [];
while ($parcitipantPayments->fetch()) {
$lineItemCheck = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_line_item WHERE contribution_id = %1 AND entity_id = %2 AND entity_table = 'civicrm_participant'", [
1 => [$parcitipantPayments->contribution_id, 'Positive'],
2 => [$parcitipantPayments->participant_id, 'Positive'],
]);
if (empty($lineItemCheck)) {
$lineItemsMissingPayments[] = [
'contribution_id' => $parcitipantPayments->contribution_id,
'participant_id' => $parcitipantPayments->participant_id,
];
}
}
if (!empty($lineItemsMissingPayments)) {
$strings = '';
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) {
$strings .= '<tr><td>'. $lineItemsMissingPayment['contribution_id'] . '</td><td>' . $lineItemsMissingPayment['participant_id'] . '</td></tr>';
}
$messages[] = new CRM_Utils_Check_Message(
'civi_event_participant_payments_missing',
ts('The Following Participant Payments do not have a corresponding line item record linking the contribution to participant.') . ts('This should be corrected either by updating the relevant line item record or adding a line item record as appropriate.') . '</p>
<p></p><table><thead><th>Contribution ID</th><th>Participant ID</th></thead><tbody>' . $strings . '</tbody></table></p>',
ts('CiviCRM Participant Payment Records not matching'),
\Psr\Log\LogLevel::WARNING,
'fa-database',
);
}
}
39 changes: 39 additions & 0 deletions ext/civi_member/civi_member.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
<?php

require_once 'civi_member.civix.php';


/**
* Implements hook_civicrm_check().
*
* Check for any legacy data where there is a membership_payment record but not a matching line item
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_check/
*/
function civi_member_civicrm_check(&$messages) :void {
$membershipPayments = CRM_Core_DAO::executeQuery("SELECT contribution_id, membership_id FROM civicrm_membership_payment");
$lineItemsMissingPayments = [];
while ($membershipPayments->fetch()) {
$lineItemCheck = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_line_item WHERE contribution_id = %1 AND entity_id = %2 AND entity_table = 'civicrm_membership'", [
1 => [$membershipPayments->contribution_id, 'Positive'],
2 => [$membershipPayments->membership_id, 'Positive'],
]);
if (empty($lineItemCheck)) {
$lineItemsMissingPayments[] = [
'contribution_id' => $membershipPayments->contribution_id,
'membership_id' => $membershipPayments->membership_id,
];
}
}
if (!empty($lineItemsMissingPayments)) {
$strings = '';
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) {
$strings .= '<tr><td>'. $lineItemsMissingPayment['contribution_id'] . '</td><td>' . $lineItemsMissingPayment['membership_id'] . '</td></tr>';
}
$messages[] = new CRM_Utils_Check_Message(
'civi_member_membership_payments_missing',
ts('The Following Membership Payments do not have a corresponding line item record linking the contribution to membership.') . ts('This should be corrected either by updating the relevant line item record or adding a line item record as appropriate.') . '</p>
<p></p><table><thead><th>Contribution ID</th><th>Membership ID</th></thead><tbody>' . $strings . '</tbody></table></p>',
ts('CiviCRM Membership Payment Records not matching'),
\Psr\Log\LogLevel::WARNING,
'fa-database',
);
}
}

0 comments on commit 6270c97

Please sign in to comment.