This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIWEMB-56: Set and Enforce Owner Organisation field on batch transact…
…ions screen
- Loading branch information
1 parent
ef52363
commit dde303c
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
CRM/Multicompanyaccounting/Hook/AlterContent/BatchTransaction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
class CRM_Multicompanyaccounting_Hook_AlterContent_BatchTransaction { | ||
|
||
private $content; | ||
|
||
public function __construct(&$content) { | ||
$this->content = &$content; | ||
} | ||
|
||
public function run() { | ||
$this->enforceSearchFiltersInBatchScreen(); | ||
} | ||
|
||
/** | ||
* When loading the batch transactions screen | ||
* CiviCRM ignores the filters to prevent running | ||
* more complex query that is often not needed, and | ||
* assumes the user can do further filtration manually if | ||
* needed from the same screen. | ||
* | ||
* But given We've added the owner organisation field | ||
* as a filter and that we must enforce it even without | ||
* the user manual intervention, we update the page template | ||
* here to make sure the filter are always enforce. | ||
* | ||
* @return void | ||
*/ | ||
private function enforceSearchFiltersInBatchScreen() { | ||
$this->content = str_replace('buildTransactionSelectorAssign( false )', 'buildTransactionSelectorAssign( true )', $this->content); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
CRM/Multicompanyaccounting/Hook/BuildForm/BatchTransaction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
class CRM_Multicompanyaccounting_Hook_BuildForm_BatchTransaction { | ||
|
||
private $form; | ||
|
||
public function __construct($form) { | ||
$this->form = $form; | ||
} | ||
|
||
public function run() { | ||
$this->setTransactionsOwnerOrganisationFilterValue(); | ||
} | ||
|
||
/** | ||
* Sets the Owner Organisation filter value | ||
* for the transactions, based on the batch | ||
* owner organisations. | ||
* | ||
* @return void | ||
* @throws CRM_Core_Exception | ||
*/ | ||
private function setTransactionsOwnerOrganisationFilterValue() { | ||
$batchId = CRM_Utils_Request::retrieve('bid', 'Int'); | ||
if (empty($batchId)){ | ||
return; | ||
} | ||
|
||
$batchOwnerOrganisationIds = CRM_Multicompanyaccounting_BAO_BatchOwnerOrganisation::getByBatchId($batchId); | ||
|
||
$fieldName = 'custom_' . $this->getContributionOwnerOrganisationFieldId(); | ||
$defaults[$fieldName] = $batchOwnerOrganisationIds; | ||
$this->form->setDefaults($defaults); | ||
} | ||
|
||
private function getContributionOwnerOrganisationFieldId() { | ||
return civicrm_api3('CustomField', 'getvalue', [ | ||
'return' => 'id', | ||
'custom_group_id' => 'multicompanyaccounting_contribution_owner', | ||
'name' => 'owner_organization', | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters