Minor code cleanups around invoicing assignment
[civicrm-core.git] / CRM / Financial / Page / FinancialAccount.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
35 * Page for displaying list of financial types
36 */
37class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic {
96f50de2
CW
38
39 public $useLivePageJS = TRUE;
6a488035 40 /**
fe482240 41 * The action links that we need to display for the browse screen.
6a488035
TO
42 *
43 * @var array
6a488035 44 */
045f52a3 45 static $_links = NULL;
6a488035
TO
46
47 /**
fe482240 48 * Get BAO Name.
6a488035 49 *
a6c01b45
CW
50 * @return string
51 * Classname of BAO.
6a488035 52 */
00be9182 53 public function getBAOName() {
6a488035
TO
54 return 'CRM_Financial_BAO_FinancialAccount';
55 }
56
57 /**
fe482240 58 * Get action Links.
6a488035 59 *
a6c01b45
CW
60 * @return array
61 * (reference) of action links
6a488035 62 */
00be9182 63 public function &links() {
6a488035
TO
64 if (!(self::$_links)) {
65 self::$_links = array(
353ffa53
TO
66 CRM_Core_Action::UPDATE => array(
67 'name' => ts('Edit'),
68 'url' => 'civicrm/admin/financial/financialAccount',
69 'qs' => 'action=update&id=%%id%%&reset=1',
6a488035
TO
70 'title' => ts('Edit Financial Type'),
71 ),
72 CRM_Core_Action::DISABLE => array(
353ffa53 73 'name' => ts('Disable'),
134bc82c 74 'ref' => 'crm-enable-disable',
6a488035
TO
75 'title' => ts('Disable Financial Type'),
76 ),
353ffa53
TO
77 CRM_Core_Action::ENABLE => array(
78 'name' => ts('Enable'),
134bc82c 79 'ref' => 'crm-enable-disable',
6a488035
TO
80 'title' => ts('Enable Financial Type'),
81 ),
353ffa53
TO
82 CRM_Core_Action::DELETE => array(
83 'name' => ts('Delete'),
84 'url' => 'civicrm/admin/financial/financialAccount',
85 'qs' => 'action=delete&id=%%id%%',
6a488035
TO
86 'title' => ts('Delete Financial Type'),
87 ),
88 );
89 }
90 return self::$_links;
91 }
92
6a488035
TO
93 /**
94 * Browse all custom data groups.
6a488035 95 */
00be9182 96 public function browse() {
6a488035
TO
97 // get all custom groups sorted by weight
98 $contributionType = array();
99 $dao = new CRM_Financial_DAO_FinancialAccount();
100 $dao->orderBy('financial_account_type_id, name');
101 $dao->find();
7611ae71 102 $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
6a488035
TO
103
104 while ($dao->fetch()) {
105 $contributionType[$dao->id] = array();
481a74f4 106 CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]);
045f52a3 107 $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
6a488035
TO
108 // form all action links
109 $action = array_sum(array_keys($this->links()));
110
111 // update enable/disable links depending on if it is is_reserved or is_active
112 if ($dao->is_reserved) {
113 continue;
114 }
115 else {
116 if ($dao->is_active) {
117 $action -= CRM_Core_Action::ENABLE;
118 }
119 else {
120 $action -= CRM_Core_Action::DISABLE;
121 }
122 }
123
124 $contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
87dab4a4
AH
125 array('id' => $dao->id),
126 ts('more'),
127 FALSE,
128 'financialAccount.manage.action',
129 'FinancialAccount',
130 $dao->id
131 );
6a488035
TO
132 }
133 $this->assign('rows', $contributionType);
134 }
135
136 /**
fe482240 137 * Get name of edit form.
6a488035 138 *
a6c01b45
CW
139 * @return string
140 * Classname of edit form.
6a488035 141 */
00be9182 142 public function editForm() {
6a488035
TO
143 return 'CRM_Financial_Form_FinancialAccount';
144 }
145
146 /**
fe482240 147 * Get edit form name.
6a488035 148 *
a6c01b45
CW
149 * @return string
150 * name of this page.
6a488035 151 */
00be9182 152 public function editName() {
6a488035
TO
153 return 'Financial Types';
154 }
155
156 /**
157 * Get user context.
158 *
da6b46f4
EM
159 * @param null $mode
160 *
a6c01b45
CW
161 * @return string
162 * user context.
6a488035 163 */
045f52a3 164 public function userContext($mode = NULL) {
6a488035
TO
165 return 'civicrm/admin/financial/financialAccount';
166 }
96025800 167
6a488035 168}