-
Notifications
You must be signed in to change notification settings - Fork 28
/
cdntaxreceipts.php
237 lines (202 loc) · 7.42 KB
/
cdntaxreceipts.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
<?php
require_once 'cdntaxreceipts.civix.php';
require_once 'cdntaxreceipts.functions.inc';
require_once 'cdntaxreceipts.db.inc';
function cdntaxreceipts_civicrm_buildForm( $formName, &$form ) {
if ( is_a( $form, 'CRM_Contribute_Form_ContributionView' ) ) {
// add "Issue Tax Receipt" button to the "View Contribution" page
// if the Tax Receipt has NOT yet been issued -> display a white maple leaf icon
// if the Tax Receipt has already been issued -> display a red maple leaf icon
CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.cdntaxreceipts', 'css/civicrm_cdntaxreceipts.css');
$contributionId = $form->get( 'id' );
if ( isset($contributionId) && cdntaxreceipts_eligibleForReceipt($contributionId) ) {
list($issued_on, $receipt_id) = cdntaxreceipts_issued_on($contributionId);
$is_original_receipt = empty($issued_on);
if ($is_original_receipt) {
$buttons = array(array('type' => 'submit',
'subName' => 'issue_tax_receipt',
'name' => ts('Tax Receipt'),
'isDefault' => FALSE ), );
}
else {
// this is essentially the same button - but it has a different
// subName -> which is used (css) to display the red maple leaf instead.
$buttons = array(array('type' => 'submit',
'subName' => 'view_tax_receipt',
'name' => ts('Tax Receipt'),
'isDefault' => FALSE ), );
}
$form->addButtons( $buttons );
}
}
}
/**
* Implementation of hook_civicrm_postProcess().
*
* Called when a form comes back for processing. Basically, we want to process
* the button we added in cdntaxreceipts_civicrm_buildForm().
*/
function cdntaxreceipts_civicrm_postProcess( $formName, &$form ) {
// first check whether I really need to process this form
if ( ! is_a( $form, 'CRM_Contribute_Form_ContributionView' ) ) {
return;
}
$types = array('issue_tax_receipt','view_tax_receipt');
$action = '';
foreach($types as $type) {
$post = '_qf_ContributionView_submit_'.$type;
if (isset($_POST[$post])) {
if ($_POST[$post] == ts('Tax Receipt')) {
$action = $post;
}
}
}
if (empty($action)) {
return;
}
// the tax receipt button has been pressed. redirect to the tax receipt 'view' screen, preserving context.
$contributionId = $form->get( 'id' );
$contactId = $form->get( 'cid' );
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution',
"reset=1&id=$contributionId&cid=$contactId&action=view&context=contribution&selectedChild=contribute"
));
$urlParams = array('reset=1', 'id='.$contributionId, 'cid='.$contactId);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/cdntaxreceipts/view', implode('&',$urlParams)));
}
/**
* Implementation of hook_civicrm_searchTasks().
*
* For users with permission to issue tax receipts, give them the ability to do it
* as a batch of search results.
*/
function cdntaxreceipts_civicrm_searchTasks($objectType, &$tasks ) {
if ( $objectType == 'contribution' && CRM_Core_Permission::check( 'issue cdn tax receipts' ) ) {
$alreadyinlist = FALSE;
foreach ($tasks as $key => $task) {
if($task['class'] == 'CRM_Cdntaxreceipts_Task_IssueSingleTaxReceipts') {
$alreadyinlist = TRUE;
}
}
if (!$alreadyinlist) {
$tasks[] = array (
'title' => ts('Issue Tax Receipts'),
'class' => 'CRM_Cdntaxreceipts_Task_IssueSingleTaxReceipts',
'result' => TRUE);
}
}
elseif ( $objectType == 'contact' && CRM_Core_Permission::check( 'issue cdn tax receipts' ) ) {
$alreadyinlist = FALSE;
foreach ($tasks as $key => $task) {
if($task['class'] == 'CRM_Cdntaxreceipts_Task_IssueAnnualTaxReceipts') {
$alreadyinlist = TRUE;
}
}
if (!$alreadyinlist) {
$tasks[] = array (
'title' => ts('Issue Annual Tax Receipts'),
'class' => 'CRM_Cdntaxreceipts_Task_IssueAnnualTaxReceipts',
'result' => TRUE);
}
}
}
/**
* JAKE -- not working
* Implementation of hook_civicrm_permission().
*/
function cdntaxreceipts_civicrm_permission( &$permissions ) {
$prefix = ts('CiviCRM CDN Tax Receipts') . ': ';
$permissions = array(
'issue cdn tax receipts' => $prefix . ts('Issue Tax Receipts'),
);
}
/**
* Implementation of hook_civicrm_config
*/
function cdntaxreceipts_civicrm_config(&$config) {
_cdntaxreceipts_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function cdntaxreceipts_civicrm_xmlMenu(&$files) {
_cdntaxreceipts_civix_civicrm_xmlMenu($files);
}
/**
* Implementation of hook_civicrm_install
*/
function cdntaxreceipts_civicrm_install() {
// copy tables civicrm_cdntaxreceipts_log and civicrm_cdntaxreceipts_log_contributions IF they already exist
// Issue: #1
return _cdntaxreceipts_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_uninstall
*/
function cdntaxreceipts_civicrm_uninstall() {
return _cdntaxreceipts_civix_civicrm_uninstall();
}
/**
* Implementation of hook_civicrm_enable
*/
function cdntaxreceipts_civicrm_enable() {
// add a menu item to the Administer > CiviContribute menu
require_once 'CRM/Core/BAO/Navigation.php';
// check there is no admin item
$cdntax_search = array('url' => 'civicrm/cdntaxreceipts/settings?reset=1');
$cdntax_item = array();
CRM_Core_BAO_Navigation::retrieve($cdntax_search, $cdntax_item);
if ( ! empty($cdntax_item) ) {
return;
}
// get path to Administer > CiviContribute and place admin item there
$administer_search = array('label' => 'Administer');
$administer_item = array();
CRM_Core_BAO_Navigation::retrieve($administer_search, $administer_item);
if ($administer_item) {
$contribute_search = array('label' => 'CiviContribute', 'parent_id' => $administer_item['id']);
$contribute_item = array();
CRM_Core_BAO_Navigation::retrieve($contribute_search, $contribute_item);
if ($contribute_item) {
$new_item = array(
'name' => 'CDN Tax Receipts',
'label' => 'CDN Tax Receipts',
'url' => 'civicrm/cdntaxreceipts/settings?reset=1',
'permission' => 'administer CiviCRM',
'parent_id' => $contribute_item['id'],
'is_active' => TRUE,
);
CRM_Core_BAO_Navigation::add($new_item);
}
}
return _cdntaxreceipts_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_disable
*/
function cdntaxreceipts_civicrm_disable() {
return _cdntaxreceipts_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 cdntaxreceipts_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _cdntaxreceipts_civix_civicrm_upgrade($op, $queue);
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function cdntaxreceipts_civicrm_managed(&$entities) {
return _cdntaxreceipts_civix_civicrm_managed($entities);
}