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

dev/financial#6 Added is template to search screen #20451

Merged
merged 6 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CRM/Contact/Form/Search/Custom/ContribSYBNT.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function all(
$from
WHERE contrib_1.contact_id = contact_a.id
AND contrib_1.is_test = 0
AND contrib_1.is_template = 0
$where
GROUP BY contact_a.id
$having
Expand Down Expand Up @@ -237,6 +238,7 @@ public function where($includeContactIDs = FALSE) {

if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
$clauses[] = "contrib_2.is_test = 0";
$clauses[] = "contrib_2.is_template = 0";

if (!empty($this->start_date_2)) {
$clauses[] = CRM_Core_DAO::composeQuery('contrib_2.receive_date >= %1', [1 => [$this->start_date_2, 'String']]);
Expand Down Expand Up @@ -293,7 +295,7 @@ public function where($includeContactIDs = FALSE) {
REPLACE INTO {$this->_xgTableName}
SELECT DISTINCT contact_id AS contact_id
FROM civicrm_contribution c
WHERE c.is_test = 0
WHERE c.is_test = 0 AND c.is_template = 0
$excludeClause
GROUP BY c.contact_id
$havingClause
Expand All @@ -308,7 +310,7 @@ public function where($includeContactIDs = FALSE) {
REPLACE INTO {$this->_xgTableName}
SELECT DISTINCT contact_id AS contact_id
FROM civicrm_contribution c
WHERE c.is_test = 0
WHERE c.is_test = 0 AND c.is_template = 0
AND c.receive_date < {$this->start_date_1}
";
CRM_Core_DAO::executeQuery($query);
Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/Form/Search/Custom/ContributionAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public function where($includeContactIDs = FALSE) {
$clauses = [
"contrib.contact_id = contact_a.id",
"contrib.is_test = 0",
"contrib.is_template = 0",
"contrib.contribution_status_id = " . intval($contributionCompletedStatusId),
];

Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/Form/Search/Custom/EventAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function where($includeContactIDs = FALSE) {

$clauses[] = "civicrm_participant.status_id in ( 1 )";
$clauses[] = "civicrm_contribution.is_test = 0";
$clauses[] = "civicrm_contribution.is_template = 0";
$onLine = CRM_Utils_Array::value('paid_online',
$this->_formValues
);
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ public static function buildSearchForm(&$form) {
$form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE);

$form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE);
$form->addYesNo('is_template', ts('Contribution is Template?'), TRUE);
// Add field for transaction ID search
$form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
$form->addElement('text', 'contribution_check_number', ts('Check Number'));
Expand Down Expand Up @@ -1029,6 +1030,7 @@ public static function buildSearchForm(&$form) {

$form->assign('validCiviContribute', TRUE);
$form->setDefaults(['contribution_test' => 0]);
$form->setDefaults(['is_template' => 0]);

CRM_Contribute_BAO_ContributionRecur::recurringContribution($form);
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Contribute/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
'contribution_cancel_date',
'product_name',
'is_test',
'is_template',
'contribution_recur_id',
'receipt_date',
'membership_id',
Expand Down
9 changes: 9 additions & 0 deletions templates/CRM/Contact/Form/Search/Advanced.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
<p>{ts}Once you have finished your testing, it is a good idea to clean up by finding your test records and deleting them.{/ts}</p>
{/htxt}


{htxt id="is-template-title"}
{ts}Template Records{/ts}
{/htxt}
{htxt id="is-template"}
<p>{ts}Template contributions are used with recurring contribution to generate follow up contributions.{/ts}</p>
<p>{ts}You can change the template contribution and the changes will occur as soon as new contribution is generated within the recurring series.{/ts}</p>
{/htxt}

{htxt id="processor-id-title"}
{ts}Processor ID{/ts}
{/htxt}
Expand Down
6 changes: 6 additions & 0 deletions templates/CRM/Contribute/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
{$form.contribution_recurring.html}
</td>
</tr>
<tr>
<td>{$form.is_template.label} {help id="is-template" file="CRM/Contact/Form/Search/Advanced"}</td>
<td>
{$form.is_template.html}
</td>
</tr>
</tbody>
</table>
</td>
Expand Down
6 changes: 5 additions & 1 deletion templates/CRM/Contribute/Form/Selector.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
&nbsp; {$row.total_amount|crmMoney:$row.currency}
</a>
{if $row.amount_level }<br/>({$row.amount_level}){/if}
{if $row.contribution_recur_id}<br/>{ts}(Recurring){/ts}{/if}
{if $row.contribution_recur_id && $row.is_template}
<br/>{ts}(Recurring Template){/ts}
{elseif $row.contribution_recur_id }
<br/>{ts}(Recurring){/ts}
{/if}
</td>
{foreach from=$columnHeaders item=column}
{assign var='columnName' value=$column.field_name}
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/CRM/Contribute/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,28 @@ protected function setUpRecurringContributions() {
'contribution_status_id' => 5,
'financial_type_id' => "Donation",
]);
// Create a template contribution.
$TemplateContribution = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 'Donation',
'total_amount' => 11,
'receive_date' => date('Ymd'),
'receive_date_time' => NULL,
'payment_instrument_id' => 1,
'contribution_status_id' => 1,
'contact_id' => $this->ids['Contact']['contactID1'],
'contribution_recur_id' => $ContributionRecur1['id'],
'is_template' => 1,
]);
$params = [
'to_financial_account_id' => 1,
'status_id' => 1,
'contribution_id' => $TemplateContribution['id'],
'payment_instrument_id' => 1,
'card_type_id' => 1,
'total_amount' => 11,
];
CRM_Core_BAO_FinancialTrxn::create($params);
// Create a normal contribution
$Contribution1 = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 'Donation',
'total_amount' => 11,
Expand Down Expand Up @@ -592,6 +614,13 @@ public function getSearchData() {
'expected_contact' => [],
'expected_qill' => "Recurring Contribution Status = 'Cancelled'",
],
// Case 4: Search for contributions with is_template = 1
'in_progress_search' => [
'form_value' => ['contribution_is_template' => 1],
'expected_count' => 1,
'expected_contact' => ['Mr. Joe Miller II'],
'expected_qill' => "Is a Template Contribution = \"1\"",
],
'trxn_id_search' => [
'form_value' => ['contribution_recur_trxn_id' => 'a transaction'],
'expected_count' => 1,
Expand Down