forked from Project60/org.project60.banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
banking.php
executable file
·310 lines (274 loc) · 9.86 KB
/
banking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/*-------------------------------------------------------+
| Project 60 - CiviBanking |
| Copyright (C) 2013-2022 SYSTOPIA |
| Author: B. Endres (endres -at- systopia.de) |
| http://www.systopia.de/ |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL v3 license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'banking.civix.php';
require_once 'banking_options.php';
use Symfony\Component\DependencyInjection\ContainerBuilder;
use CRM_Banking_ExtensionUtil as E;
/**
* Implements hook_civicrm_container().
*
* @param ContainerBuilder $container
*/
function banking_civicrm_container(ContainerBuilder $container) {
if (class_exists('Civi\Banking\CompilerPass')) {
$container->addCompilerPass(new Civi\Banking\CompilerPass());
}
}
/**
* Implementation of hook_civicrm_config
*/
function banking_civicrm_config(&$config) {
_banking_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_install
*/
function banking_civicrm_install() {
$config = CRM_Core_Config::singleton();
//create the tables
$sqlfile = dirname(__FILE__) . '/sql/banking.sql';
CRM_Utils_File::sourceSQLFile($config->dsn, $sqlfile, NULL, false);
//add the required option groups
banking_civicrm_install_options(_banking_options());
// Set the bank account reference probability to 100%.
CRM_Core_BAO_Setting::setItem('1.0', 'CiviBanking', 'reference_matching_probability');
return _banking_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_uninstall
*/
function banking_civicrm_uninstall() {
return _banking_civix_civicrm_uninstall();
}
/**
* Implementation of hook_civicrm_enable
*/
function banking_civicrm_enable() {
//add the required option groups
banking_civicrm_install_options(_banking_options());
return _banking_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_disable
*/
function banking_civicrm_disable() {
return _banking_civix_civicrm_disable();
}
/**
* Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function banking_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _banking_civix_civicrm_upgrade($op, $queue);
}
function banking_civicrm_angularModules(&$angularModules) {
return;
}
/**
* Implements hook_civicrm_postInstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function banking_civicrm_postInstall() {
_banking_civix_civicrm_postInstall();
}
/**
* Inject contribution - transaction link
*/
function banking_civicrm_pageRun(&$page) {
$pageName = $page->getVar('_name');
if ($pageName == 'CRM_Contribute_Page_Tab') {
CRM_Banking_BAO_BankTransactionContribution::injectLinkedTransactions($page);
}
}
/**
* Replace (some of) the summary blocks on the banking review page
*
* @param CRM_Banking_BAO_BankTransaction $banking_transaction
* @param array $summary_blocks
*/
function banking_civicrm_banking_transaction_summary($banking_transaction, &$summary_blocks)
{
// Add rule match indicators:
$ruleMatchIndicators = new CRM_Banking_RuleMatchIndicators($banking_transaction, $summary_blocks);
$ruleMatchIndicators->addContactMatchIndicator();
$ruleMatchIndicators->addIbanMatchIndicator();
}
/**
* alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
*/
function banking_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
$permissions['banking_account']['create'] = array('delete contacts');
$permissions['banking_account']['delete'] = array('delete contacts');
$permissions['banking_account_reference']['create'] = array('delete contacts');
$permissions['banking_account_reference']['check'] = array('access CiviCRM');
$permissions['banking_transaction']['analyselist'] = array('edit contributions');
}
/* bank accounts in merge operations
*/
function banking_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL ) {
switch ($type) {
case 'relTables':
// Offer user to merge bank accounts
$data['rel_table_bankaccounts'] = array(
'title' => E::ts('Bank Accounts'),
'tables' => array('civicrm_bank_account'),
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=$cid&selectedChild=bank_accounts'), // '$cid' will be automatically replaced
);
break;
case 'cidRefs':
// this is the only field that needs to be modified
$data['civicrm_bank_account'] = array('contact_id');
break;
}
}
/**
* Implements hook_civicrm_tabset()
*
* Will inject the "Banking Accounts" tab
*/
function banking_civicrm_tabset($tabsetName, &$tabs, $context) {
if ($tabsetName == 'civicrm/contact/view' && !empty($context['contact_id'])) {
$contactID = (int) $context['contact_id'];
$count = CRM_Core_DAO::singleValueQuery("SELECT COUNT(id) FROM civicrm_bank_account WHERE contact_id={$contactID};");
$tabs[] = [
'id' => 'bank_accounts',
'url' => CRM_Utils_System::url('civicrm/banking/accounts_tab', "snippet=1&cid=$contactID"),
'title' => E::ts("Bank Accounts"),
'count' => $count,
'weight' => 95
];
}
}
function banking_civicrm_entityTypes(&$entityTypes) {
// add my DAO's
$entityTypes[] = array(
'name' => 'BankAccount',
'class' => 'CRM_Banking_DAO_BankAccount',
'table' => 'civicrm_bank_account',
);
$entityTypes[] = array(
'name' => 'BankAccountReference',
'class' => 'CRM_Banking_DAO_BankAccountReference',
'table' => 'civicrm_bank_account_reference',
);
$entityTypes[] = array(
'name' => 'BankTransaction',
'class' => 'CRM_Banking_DAO_BankTransaction',
'table' => 'civicrm_bank_tx',
);
$entityTypes[] = array(
'name' => 'BankTransactionBatch',
'class' => 'CRM_Banking_DAO_BankTransactionBatch',
'table' => 'civicrm_bank_tx_batch',
);
$entityTypes[] = array(
'name' => 'PluginInstance',
'class' => 'CRM_Banking_DAO_PluginInstance',
'table' => 'civicrm_bank_plugin_instance',
);
}
/**
* Implements hook_civicrm_navigationMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*/
function banking_civicrm_navigationMenu(&$menu) {
// check if we want the menu to be built at all
$menu_position = (int) CRM_Core_BAO_Setting::getItem('CiviBanking', 'menu_position');
switch ($menu_position) {
case 2:
// menu is off, see CRM_Admin_Form_Setting_BankingSettings
$separator = 0;
return;
default:
case 0:
// top level menu
$anchor = NULL;
$separator = 0;
break;
case 1:
// contribution menu
$anchor = 'Contributions/';
$separator = 1;
break;
}
// Determine the url for the statements/payments (new ui or old ui).
$statementUrl = 'civicrm/banking/statements';
if (!CRM_Core_BAO_Setting::getItem('CiviBanking', 'new_ui')) {
$statementUrl = 'civicrm/banking/payments';
}
_banking_civix_insert_navigation_menu($menu, $anchor, array(
'label' => E::ts('CiviBanking'),
'name' => 'CiviBanking',
'icon' => (version_compare(CRM_Utils_System::version(), '5.6', '>=')) ? 'fa fa-btc' : '',
'permission' => 'access CiviContribute',
'operator' => 'OR',
'separator' => $separator,
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Dashboard'),
'name' => 'Dashboard',
'url' => 'civicrm/banking/dashboard',
'permission' => 'access CiviContribute',
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Import Transactions'),
'name' => 'Import Transactions',
'url' => 'civicrm/banking/import',
'permission' => 'access CiviContribute',
'separator' => 1,
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Show Transactions'),
'name' => 'Transactions',
'url' => $statementUrl,
'permission' => 'access CiviContribute',
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Find Transactions'),
'name' => 'Find Transactions',
'url' => 'civicrm/banking/statements/search',
'permission' => 'access CiviContribute',
'separator' => 1,
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Find Accounts'),
'name' => 'Find Accounts',
'url' => 'civicrm/banking/search',
'permission' => 'access CiviContribute',
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Dedupe Accounts'),
'name' => 'Dedupe Accounts',
'url' => 'civicrm/banking/dedupe',
'permission' => 'access CiviContribute',
'separator' => 1,
));
_banking_civix_insert_navigation_menu($menu, "{$anchor}CiviBanking", array(
'label' => E::ts('Configuration Manager'),
'name' => 'CiviBanking Configuration',
'url' => 'civicrm/banking/manager',
'permission' => 'administer CiviCRM',
));
_banking_civix_navigationMenu($menu);
}