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

Completed and non-test only? #3

Open
timatidg opened this issue Jan 4, 2024 · 2 comments
Open

Completed and non-test only? #3

timatidg opened this issue Jan 4, 2024 · 2 comments

Comments

@timatidg
Copy link

timatidg commented Jan 4, 2024

I was thrilled to find this extension.
I am wondering if the table (and total) can be filters to eliminate both test and pending/incomplete transaction records. Right now all records are included. I would like to have only Completed records of type non-test.
Something like:
"is_test = 0";
"contribution_status" = "Completed";

@timatidg
Copy link
Author

Something like this from the API:
$contributions = \Civi\Api4\Contribution::get(TRUE)
->addSelect('contact_id', 'receive_date', 'total_amount')
->addWhere('is_test', '=', FALSE)
->addWhere('contribution_status_id', '=', 1)
->addWhere('financial_type_id:label', '=', 'Donation')
->addWhere('receive_date', '>=', '2023-01-01')
->addWhere('receive_date', '<=', '2023-12-31')
->setLimit(25)
->addGroupBy('contact_id')
->execute();
foreach ($contributions as $contribution) {
// do something
}

or in Traditional PHP form:
$contributions = civicrm_api4('Contribution', 'get', [
'select' => [
'contact_id',
'receive_date',
'total_amount',
],
'where' => [
['is_test', '=', FALSE],
['contribution_status_id', '=', 1],
['financial_type_id:label', '=', 'Donation'],
['receive_date', '>=', '2023-01-01'],
['receive_date', '<=', '2023-12-31'],
],
'limit' => 25,
'groupBy' => [
'contact_id',
],
'checkPermissions' => TRUE,
]);

@timatidg
Copy link
Author

I added two lines starting on line 28 and I think it worked:
foreach ($cids as $cid) {
$dao = &CRM_Core_DAO::executeQuery("
SELECT con.total_amount, (con.total_amount - con.non_deductible_amount) as deductible_amount, con.total_amount, con.receive_date, cc.display_name
FROM civicrm_contribution con
LEFT JOIN civicrm_contact cc on con.contact_id=cc.id
LEFT JOIN civicrm_financial_type ft on con.financial_type_id=ft.id
WHERE contact_id = ".$cid
.
" AND con.receive_date BETWEEN '".$last_year."-01-01' AND '".$year."-01-01'
AND ft.is_deductible=1
AND con.is_test = FALSE
AND con.contribution_status_id = 1
;"
);

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

1 participant