3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Page for displaying list of financial type accounts
21 class CRM_Financial_Page_FinancialTypeAccount
extends CRM_Core_Page
{
23 * The action links that we need to display for the browse screen.
27 public static $_links = NULL;
30 * The account id that we need to display for the browse screen.
34 protected $_aid = NULL;
42 public function getBAOName() {
43 return 'CRM_Financial_BAO_FinancialTypeAccount';
50 * (reference) of action links
52 public function &links() {
53 if (!(self
::$_links)) {
55 CRM_Core_Action
::UPDATE
=> [
57 'url' => 'civicrm/admin/financial/financialType/accounts',
58 'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
59 'title' => ts('Edit Financial Type Account'),
61 CRM_Core_Action
::DELETE
=> [
62 'name' => ts('Delete'),
63 'url' => 'civicrm/admin/financial/financialType/accounts',
64 'qs' => 'action=delete&id=%%id%%&aid=%%aid%%',
65 'title' => ts('Delete Financial Type Account'),
75 * This method is called after the page is created. It checks for the
76 * type of action and executes that action.
77 * Finally it calls the parent's run method.
79 public function run() {
80 // get the requested action
81 // default to 'browse'
82 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
84 // assign vars to templates
85 $this->assign('action', $action);
86 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
87 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this, FALSE, 0);
89 // what action to take ?
90 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
91 $this->edit($action, $id);
94 $this->browse($action, $id);
102 * Browse all Financial Type Account data.
104 public function browse() {
105 // get all Financial Type Account data sorted by weight
108 $dao = new CRM_Financial_DAO_EntityFinancialAccount();
109 $params['entity_id'] = $this->_aid
;
110 $params['entity_table'] = 'civicrm_financial_type';
112 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
113 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid
, 'name');
114 CRM_Utils_System
::setTitle($this->_title
. ' - ' . ts('Assigned Financial Accounts'));
115 $financialAccountType = CRM_Core_PseudoConstant
::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
116 $accountRelationship = CRM_Core_PseudoConstant
::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
117 $dao->copyValues($params);
119 while ($dao->fetch()) {
120 $financialType[$dao->id
] = [];
121 CRM_Core_DAO
::storeValues($dao, $financialType[$dao->id
]);
123 $params = ['id' => $dao->financial_account_id
];
125 $financialAccount = CRM_Financial_BAO_FinancialAccount
::retrieve($params, $defaults);
126 if (!empty($financialAccount)) {
127 $financialType[$dao->id
]['financial_account'] = $financialAccount->name
;
128 $financialType[$dao->id
]['accounting_code'] = $financialAccount->accounting_code
;
129 $financialType[$dao->id
]['account_type_code'] = $financialAccount->account_type_code
;
130 $financialType[$dao->id
]['is_active'] = $financialAccount->is_active
;
131 if (!empty($financialAccount->contact_id
)) {
132 $financialType[$dao->id
]['owned_by'] = CRM_Contact_BAO_Contact
::displayName($financialAccount->contact_id
);
134 if (!empty($financialAccount->financial_account_type_id
)) {
135 $optionGroupName = 'financial_account_type';
136 $financialType[$dao->id
]['financial_account_type'] = $financialAccountType[$financialAccount->financial_account_type_id
] ??
NULL;
139 if (!empty($dao->account_relationship
)) {
140 $optionGroupName = 'account_relationship';
141 $financialType[$dao->id
]['account_relationship'] = $accountRelationship[$dao->account_relationship
] ??
NULL;
144 // form all action links
145 $action = array_sum(array_keys($this->links()));
146 $links = self
::links();
149 if ($dao->account_relationship
== $relationTypeId) {
150 unset($links[CRM_Core_Action
::DELETE
]);
152 $financialType[$dao->id
]['action'] = CRM_Core_Action
::formLink($links, $action,
155 'aid' => $dao->entity_id
,
159 'financialTypeAccount.manage.action',
160 'FinancialTypeAccount',
164 $this->assign('rows', $financialType);
165 $this->assign('aid', $this->_aid
);
166 $this->assign('financialTypeTitle', $this->_title
);
169 CRM_Core_Error
::statusBounce(ts('No Financial Accounts found for the Financial Type'));
174 * Edit CiviCRM Financial Type Account data.
176 * editing would involved modifying existing financial Account Type + adding data
177 * to new financial Account Type.
179 * @param string $action
180 * The action to be invoked.
182 public function edit($action) {
183 // create a simple controller for editing CiviCRM Profile data
184 $controller = new CRM_Core_Controller_Simple('CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action);
186 // set the userContext stack
187 $session = CRM_Core_Session
::singleton();
188 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/financial/financialType/accounts',
189 'reset=1&action=browse&aid=' . $this->_aid
));
190 $controller->set('aid', $this->_aid
);
192 $controller->setEmbedded(TRUE);
193 $controller->process();