Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | class CRM_Contribute_Form_AdditionalInfo { | |
34 | ||
35 | /** | |
c490a46a | 36 | * Build the form object for Premium Information. |
6a488035 | 37 | * |
3e6a1f4a | 38 | * Called from the CRM_Contribute_Form_Contribute function and seemingly nowhere else. |
6a488035 | 39 | * |
3e6a1f4a | 40 | * Probably this should be on the form that uses it since it is not used on multiple forms. |
dd244018 | 41 | * |
3e6a1f4a EM |
42 | * Putting it on this class doesn't seem to reduce complexity. |
43 | * | |
44 | * @param CRM_Core_Form $form | |
6a488035 | 45 | */ |
00be9182 | 46 | public static function buildPremium(&$form) { |
6a488035 TO |
47 | //premium section |
48 | $form->add('hidden', 'hidden_Premium', 1); | |
49 | $sel1 = $sel2 = array(); | |
50 | ||
51 | $dao = new CRM_Contribute_DAO_Product(); | |
52 | $dao->is_active = 1; | |
53 | $dao->find(); | |
54 | $min_amount = array(); | |
55 | $sel1[0] = '-select product-'; | |
56 | while ($dao->fetch()) { | |
57 | $sel1[$dao->id] = $dao->name . " ( " . $dao->sku . " )"; | |
58 | $min_amount[$dao->id] = $dao->min_contribution; | |
59 | $options = explode(',', $dao->options); | |
60 | foreach ($options as $k => $v) { | |
61 | $options[$k] = trim($v); | |
62 | } | |
63 | if ($options[0] != '') { | |
64 | $sel2[$dao->id] = $options; | |
65 | } | |
66 | $form->assign('premiums', TRUE); | |
67 | } | |
68 | $form->_options = $sel2; | |
69 | $form->assign('mincontribution', $min_amount); | |
353ffa53 | 70 | $sel = &$form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"'); |
6a488035 TO |
71 | $js = "<script type='text/javascript'>\n"; |
72 | $formName = 'document.forms.' . $form->getName(); | |
73 | ||
74 | for ($k = 1; $k < 2; $k++) { | |
75 | if (!isset($defaults['product_name'][$k]) || (!$defaults['product_name'][$k])) { | |
76 | $js .= "{$formName}['product_name[$k]'].style.display = 'none';\n"; | |
77 | } | |
78 | } | |
79 | ||
80 | $sel->setOptions(array($sel1, $sel2)); | |
81 | $js .= "</script>\n"; | |
82 | $form->assign('initHideBoxes', $js); | |
83 | ||
84 | $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate')); | |
85 | $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount')); | |
86 | } | |
87 | ||
88 | /** | |
c490a46a | 89 | * Build the form object for Additional Details. |
6a488035 | 90 | * |
6a488035 | 91 | * |
c490a46a | 92 | * @param CRM_Core_Form $form |
6c8f6e67 | 93 | * |
6a488035 TO |
94 | * @return void |
95 | */ | |
00be9182 | 96 | public static function buildAdditionalDetail(&$form) { |
6a488035 TO |
97 | //Additional information section |
98 | $form->add('hidden', 'hidden_AdditionalDetail', 1); | |
99 | ||
100 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution'); | |
101 | ||
102 | $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime')); | |
103 | ||
104 | // add various amounts | |
353ffa53 TO |
105 | $nonDeductAmount = &$form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), |
106 | $attributes['non_deductible_amount'] | |
6a488035 TO |
107 | ); |
108 | $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money'); | |
109 | ||
110 | if ($form->_online) { | |
111 | $nonDeductAmount->freeze(); | |
112 | } | |
353ffa53 TO |
113 | $feeAmount = &$form->add('text', 'fee_amount', ts('Fee Amount'), |
114 | $attributes['fee_amount'] | |
6a488035 TO |
115 | ); |
116 | $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money'); | |
117 | if ($form->_online) { | |
118 | $feeAmount->freeze(); | |
119 | } | |
0e6e8724 | 120 | |
353ffa53 TO |
121 | $netAmount = &$form->add('text', 'net_amount', ts('Net Amount'), |
122 | $attributes['net_amount'] | |
6a488035 TO |
123 | ); |
124 | $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money'); | |
125 | if ($form->_online) { | |
126 | $netAmount->freeze(); | |
127 | } | |
353ffa53 TO |
128 | $element = &$form->add('text', 'invoice_id', ts('Invoice ID'), |
129 | $attributes['invoice_id'] | |
6a488035 TO |
130 | ); |
131 | if ($form->_online) { | |
132 | $element->freeze(); | |
133 | } | |
134 | else { | |
135 | $form->addRule('invoice_id', | |
136 | ts('This Invoice ID already exists in the database.'), | |
137 | 'objectExists', | |
138 | array('CRM_Contribute_DAO_Contribution', $form->_id, 'invoice_id') | |
139 | ); | |
140 | } | |
933c5f44 | 141 | $element = $form->add('text', 'creditnote_id', ts('Credit Note ID'), |
142 | $attributes['creditnote_id'] | |
143 | ); | |
144 | if ($form->_online) { | |
145 | $element->freeze(); | |
146 | } | |
147 | else { | |
148 | $form->addRule('creditnote_id', | |
149 | ts('This Credit Note ID already exists in the database.'), | |
150 | 'objectExists', | |
151 | array('CRM_Contribute_DAO_Contribution', $form->_id, 'creditnote_id') | |
152 | ); | |
153 | } | |
6a488035 TO |
154 | |
155 | $form->add('select', 'contribution_page_id', | |
156 | ts('Online Contribution Page'), | |
157 | array( | |
21dfd5f5 | 158 | '' => ts('- select -'), |
6a488035 TO |
159 | ) + |
160 | CRM_Contribute_PseudoConstant::contributionPage() | |
161 | ); | |
162 | ||
163 | $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60)); | |
0e6e8724 | 164 | |
6a488035 TO |
165 | $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); |
166 | if ($form->_id && $form->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) { | |
167 | $netAmount->freeze(); | |
168 | $feeAmount->freeze(); | |
169 | } | |
0e6e8724 | 170 | |
6a488035 TO |
171 | } |
172 | ||
6a488035 | 173 | /** |
dc195289 | 174 | * used by CRM/Pledge/Form/Pledge.php |
6a488035 | 175 | * |
c490a46a | 176 | * Build the form object for PaymentReminders Information. |
6a488035 | 177 | * |
6a488035 | 178 | * |
c490a46a | 179 | * @param CRM_Core_Form $form |
6a488035 | 180 | * |
da6b46f4 | 181 | * @return void |
6a488035 | 182 | */ |
00be9182 | 183 | public static function buildPaymentReminders(&$form) { |
6a488035 TO |
184 | //PaymentReminders section |
185 | $form->add('hidden', 'hidden_PaymentReminders', 1); | |
186 | $form->add('text', 'initial_reminder_day', ts('Send Initial Reminder'), array('size' => 3)); | |
3f4b742c | 187 | $form->addRule('initial_reminder_day', ts('Please enter a valid reminder day.'), 'positiveInteger'); |
6a488035 | 188 | $form->add('text', 'max_reminders', ts('Send up to'), array('size' => 3)); |
3f4b742c | 189 | $form->addRule('max_reminders', ts('Please enter a valid No. of reminders.'), 'positiveInteger'); |
6a488035 | 190 | $form->add('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3)); |
3f4b742c | 191 | $form->addRule('additional_reminder_day', ts('Please enter a valid additional reminder day.'), 'positiveInteger'); |
6a488035 TO |
192 | } |
193 | ||
194 | /** | |
fe482240 | 195 | * Process the Premium Information. |
6a488035 | 196 | * |
c490a46a | 197 | * @param array $params |
100fef9d CW |
198 | * @param int $contributionID |
199 | * @param int $premiumID | |
d6412fc1 | 200 | * @param array $options |
6a488035 | 201 | */ |
3e6a1f4a EM |
202 | public static function processPremium($params, $contributionID, $premiumID = NULL, $options = array()) { |
203 | $selectedProductID = $params['product_name'][0]; | |
204 | $selectedProductOptionID = $params['product_name'][1]; | |
205 | ||
6a488035 TO |
206 | $dao = new CRM_Contribute_DAO_ContributionProduct(); |
207 | $dao->contribution_id = $contributionID; | |
3e6a1f4a | 208 | $dao->product_id = $selectedProductID; |
6a488035 | 209 | $dao->fulfilled_date = CRM_Utils_Date::processDate($params['fulfilled_date'], NULL, TRUE); |
353ffa53 | 210 | $isDeleted = FALSE; |
3e6a1f4a | 211 | |
6a488035 TO |
212 | //CRM-11106 |
213 | $premiumParams = array( | |
3e6a1f4a | 214 | 'id' => $selectedProductID, |
6a488035 | 215 | ); |
3e6a1f4a | 216 | |
6a488035 TO |
217 | $productDetails = array(); |
218 | CRM_Contribute_BAO_ManagePremiums::retrieve($premiumParams, $productDetails); | |
219 | $dao->financial_type_id = CRM_Utils_Array::value('financial_type_id', $productDetails); | |
3e6a1f4a EM |
220 | if (!empty($options[$selectedProductID])) { |
221 | $dao->product_option = $options[$selectedProductID][$selectedProductOptionID]; | |
6a488035 TO |
222 | } |
223 | if ($premiumID) { | |
3e6a1f4a EM |
224 | $ContributionProduct = new CRM_Contribute_DAO_ContributionProduct(); |
225 | $ContributionProduct->id = $premiumID; | |
226 | $ContributionProduct->find(TRUE); | |
227 | if ($ContributionProduct->product_id == $selectedProductID) { | |
6a488035 | 228 | $dao->id = $premiumID; |
6a488035 TO |
229 | } |
230 | else { | |
3e6a1f4a | 231 | $ContributionProduct->delete(); |
6a488035 | 232 | $isDeleted = TRUE; |
6a488035 TO |
233 | } |
234 | } | |
3e6a1f4a EM |
235 | |
236 | $dao->save(); | |
6a488035 TO |
237 | //CRM-11106 |
238 | if ($premiumID == NULL || $isDeleted) { | |
3e6a1f4a | 239 | $premiumParams = array( |
6a488035 TO |
240 | 'cost' => CRM_Utils_Array::value('cost', $productDetails), |
241 | 'currency' => CRM_Utils_Array::value('currency', $productDetails), | |
242 | 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $productDetails), | |
21dfd5f5 | 243 | 'contributionId' => $contributionID, |
6a488035 TO |
244 | ); |
245 | if ($isDeleted) { | |
3e6a1f4a EM |
246 | $premiumParams['oldPremium']['product_id'] = $ContributionProduct->product_id; |
247 | $premiumParams['oldPremium']['contribution_id'] = $ContributionProduct->contribution_id; | |
6a488035 | 248 | } |
3e6a1f4a | 249 | CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($premiumParams); |
6a488035 TO |
250 | } |
251 | } | |
252 | ||
253 | /** | |
fe482240 | 254 | * Process the Note. |
6a488035 | 255 | * |
6a488035 | 256 | * |
c490a46a | 257 | * @param array $params |
100fef9d CW |
258 | * @param int $contactID |
259 | * @param int $contributionID | |
260 | * @param int $contributionNoteID | |
fd31fa4c | 261 | * |
355ba699 | 262 | * @return void |
6a488035 | 263 | */ |
945f423d | 264 | public static function processNote($params, $contactID, $contributionID, $contributionNoteID = NULL) { |
6a488035 TO |
265 | //process note |
266 | $noteParams = array( | |
267 | 'entity_table' => 'civicrm_contribution', | |
268 | 'note' => $params['note'], | |
269 | 'entity_id' => $contributionID, | |
270 | 'contact_id' => $contactID, | |
271 | ); | |
272 | $noteID = array(); | |
273 | if ($contributionNoteID) { | |
274 | $noteID = array("id" => $contributionNoteID); | |
275 | $noteParams['note'] = $noteParams['note'] ? $noteParams['note'] : "null"; | |
276 | } | |
277 | CRM_Core_BAO_Note::add($noteParams, $noteID); | |
278 | } | |
279 | ||
280 | /** | |
fe482240 | 281 | * Process the Common data. |
6a488035 | 282 | * |
6a488035 | 283 | * |
c490a46a | 284 | * @param array $params |
da6b46f4 | 285 | * @param $formatted |
c490a46a | 286 | * @param CRM_Core_Form $form |
355ba699 | 287 | * @return void |
6a488035 | 288 | */ |
00be9182 | 289 | public static function postProcessCommon(&$params, &$formatted, &$form) { |
6a488035 TO |
290 | $fields = array( |
291 | 'non_deductible_amount', | |
292 | 'total_amount', | |
293 | 'fee_amount', | |
294 | 'net_amount', | |
295 | 'trxn_id', | |
296 | 'invoice_id', | |
933c5f44 | 297 | 'creditnote_id', |
6a488035 | 298 | 'campaign_id', |
6a488035 TO |
299 | 'contribution_page_id', |
300 | ); | |
301 | foreach ($fields as $f) { | |
302 | $formatted[$f] = CRM_Utils_Array::value($f, $params); | |
303 | } | |
304 | ||
a7488080 | 305 | if (!empty($params['thankyou_date']) && !CRM_Utils_System::isNull($params['thankyou_date'])) { |
6a488035 TO |
306 | $formatted['thankyou_date'] = CRM_Utils_Date::processDate($params['thankyou_date'], $params['thankyou_date_time']); |
307 | } | |
308 | else { | |
309 | $formatted['thankyou_date'] = 'null'; | |
310 | } | |
311 | ||
a7488080 | 312 | if (!empty($params['is_email_receipt'])) { |
6a488035 TO |
313 | $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis'); |
314 | } | |
315 | ||
6a488035 TO |
316 | //special case to handle if all checkboxes are unchecked |
317 | $customFields = CRM_Core_BAO_CustomField::getFields('Contribution', | |
318 | FALSE, | |
319 | FALSE, | |
320 | CRM_Utils_Array::value('financial_type_id', | |
321 | $params | |
322 | ) | |
323 | ); | |
324 | $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($params, | |
6a488035 TO |
325 | CRM_Utils_Array::value('id', $params, NULL), |
326 | 'Contribution' | |
327 | ); | |
328 | } | |
329 | ||
330 | /** | |
100fef9d | 331 | * Send email receipt. |
6a488035 | 332 | * |
c490a46a | 333 | * @param CRM_Core_Form $form |
76e7a76c | 334 | * instance of Contribution form. |
014c4014 TO |
335 | * @param array $params |
336 | * (reference ) an assoc array of name/value pairs. | |
da6b46f4 | 337 | * @param bool $ccContribution |
76e7a76c | 338 | * is it credit card contribution. |
6a488035 | 339 | * |
d77a0a58 | 340 | * @return array |
6a488035 | 341 | */ |
00be9182 | 342 | public static function emailReceipt(&$form, &$params, $ccContribution = FALSE) { |
3f4b742c | 343 | $form->assign('receiptType', 'contribution'); |
6a488035 TO |
344 | // Retrieve Financial Type Name from financial_type_id |
345 | $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', | |
346 | $params['financial_type_id']); | |
a7488080 | 347 | if (!empty($params['payment_instrument_id'])) { |
6a488035 TO |
348 | $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); |
349 | $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']]; | |
350 | } | |
351 | ||
352 | // retrieve individual prefix value for honoree | |
1421174e | 353 | if (isset($params['soft_credit'])) { |
354 | $softCreditTypes = $softCredits = array(); | |
355 | foreach ($params['soft_credit'] as $key => $softCredit) { | |
356 | $softCredits[$key] = array( | |
357 | 'Name' => $softCredit['contact_name'], | |
21dfd5f5 | 358 | 'Amount' => CRM_Utils_Money::format($softCredit['amount'], $softCredit['currency']), |
1421174e | 359 | ); |
360 | $softCreditTypes[$key] = $softCredit['soft_credit_type_label']; | |
361 | } | |
362 | $form->assign('softCreditTypes', $softCreditTypes); | |
363 | $form->assign('softCredits', $softCredits); | |
6a488035 TO |
364 | } |
365 | ||
366 | // retrieve premium product name and assigned fulfilled | |
367 | // date to template | |
a7488080 | 368 | if (!empty($params['hidden_Premium'])) { |
6a488035 TO |
369 | if (isset($params['product_name']) && |
370 | is_array($params['product_name']) && | |
371 | !empty($params['product_name']) | |
372 | ) { | |
373 | $productDAO = new CRM_Contribute_DAO_Product(); | |
374 | $productDAO->id = $params['product_name'][0]; | |
43bf07d6 | 375 | $productOptionID = $params['product_name'][1]; |
6a488035 TO |
376 | $productDAO->find(TRUE); |
377 | $params['product_name'] = $productDAO->name; | |
378 | $params['product_sku'] = $productDAO->sku; | |
379 | ||
43bf07d6 EM |
380 | if (empty($params['product_option']) && !empty($form->_options[$productDAO->id])) { |
381 | $params['product_option'] = $form->_options[$productDAO->id][$productOptionID]; | |
6a488035 TO |
382 | } |
383 | } | |
384 | ||
a7488080 | 385 | if (!empty($params['fulfilled_date'])) { |
3f4b742c | 386 | $form->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date'])); |
6a488035 TO |
387 | } |
388 | } | |
389 | ||
3f4b742c | 390 | $form->assign('ccContribution', $ccContribution); |
6a488035 TO |
391 | if ($ccContribution) { |
392 | //build the name. | |
393 | $name = CRM_Utils_Array::value('billing_first_name', $params); | |
a7488080 | 394 | if (!empty($params['billing_middle_name'])) { |
6a488035 TO |
395 | $name .= " {$params['billing_middle_name']}"; |
396 | } | |
397 | $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params); | |
398 | $name = trim($name); | |
3f4b742c | 399 | $form->assign('billingName', $name); |
6a488035 TO |
400 | |
401 | //assign the address formatted up for display | |
402 | $addressParts = array( | |
403 | "street_address" => "billing_street_address-{$form->_bltID}", | |
404 | "city" => "billing_city-{$form->_bltID}", | |
405 | "postal_code" => "billing_postal_code-{$form->_bltID}", | |
406 | "state_province" => "state_province-{$form->_bltID}", | |
407 | "country" => "country-{$form->_bltID}", | |
408 | ); | |
409 | ||
410 | $addressFields = array(); | |
411 | foreach ($addressParts as $name => $field) { | |
412 | $addressFields[$name] = CRM_Utils_Array::value($field, $params); | |
413 | } | |
3f4b742c | 414 | $form->assign('address', CRM_Utils_Address::format($addressFields)); |
6a488035 TO |
415 | |
416 | $date = CRM_Utils_Date::format($params['credit_card_exp_date']); | |
417 | $date = CRM_Utils_Date::mysqlToIso($date); | |
3f4b742c KJ |
418 | $form->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params)); |
419 | $form->assign('credit_card_exp_date', $date); | |
420 | $form->assign('credit_card_number', | |
6a488035 TO |
421 | CRM_Utils_System::mungeCreditCard($params['credit_card_number']) |
422 | ); | |
423 | } | |
424 | else { | |
425 | //offline contribution | |
426 | // assigned various dates to the templates | |
427 | $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date'])); | |
428 | ||
a7488080 | 429 | if (!empty($params['cancel_date'])) { |
6a488035 TO |
430 | $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date'])); |
431 | } | |
a7488080 | 432 | if (!empty($params['thankyou_date'])) { |
6a488035 TO |
433 | $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date'])); |
434 | } | |
435 | if ($form->_action & CRM_Core_Action::UPDATE) { | |
436 | $form->assign('lineItem', empty($form->_lineItems) ? FALSE : $form->_lineItems); | |
437 | } | |
438 | } | |
439 | ||
440 | //handle custom data | |
a7488080 | 441 | if (!empty($params['hidden_custom'])) { |
6a488035 TO |
442 | $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0)); |
443 | if ($form->_mode == 'test') { | |
444 | $contribParams[] = array('contribution_test', '=', 1, 0, 0); | |
445 | } | |
446 | ||
447 | //retrieve custom data | |
448 | $customGroup = array(); | |
449 | ||
450 | foreach ($form->_groupTree as $groupID => $group) { | |
451 | $customFields = $customValues = array(); | |
452 | if ($groupID == 'info') { | |
453 | continue; | |
454 | } | |
455 | foreach ($group['fields'] as $k => $field) { | |
456 | $field['title'] = $field['label']; | |
457 | $customFields["custom_{$k}"] = $field; | |
458 | } | |
459 | ||
460 | //build the array of customgroup contain customfields. | |
461 | CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams); | |
462 | $customGroup[$group['title']] = $customValues; | |
463 | } | |
464 | //assign all custom group and corresponding fields to template. | |
465 | $form->assign('customGroup', $customGroup); | |
466 | } | |
467 | ||
468 | $form->assign_by_ref('formValues', $params); | |
469 | list($contributorDisplayName, | |
470 | $contributorEmail | |
471 | ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); | |
3f4b742c KJ |
472 | $form->assign('contactID', $params['contact_id']); |
473 | $form->assign('contributionID', $params['contribution_id']); | |
6a488035 | 474 | |
a7488080 | 475 | if (!empty($params['currency'])) { |
3f4b742c | 476 | $form->assign('currency', $params['currency']); |
6a488035 TO |
477 | } |
478 | ||
a7488080 | 479 | if (!empty($params['receive_date'])) { |
3f4b742c | 480 | $form->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date'])); |
6a488035 TO |
481 | } |
482 | ||
353ffa53 TO |
483 | $template = CRM_Core_Smarty::singleton(); |
484 | $taxAmt = $template->get_template_vars('dataArray'); | |
485 | $eventTaxAmt = $template->get_template_vars('totalTaxAmount'); | |
486 | $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); | |
487 | $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); | |
488 | if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) { | |
489 | $isEmailPdf = TRUE; | |
490 | } | |
491 | else { | |
492 | $isEmailPdf = FALSE; | |
493 | } | |
d75f2f47 | 494 | |
c6327d7d | 495 | list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate( |
6a488035 TO |
496 | array( |
497 | 'groupName' => 'msg_tpl_workflow_contribution', | |
498 | 'valueName' => 'contribution_offline_receipt', | |
499 | 'contactId' => $params['contact_id'], | |
500 | 'contributionId' => $params['contribution_id'], | |
501 | 'from' => $params['from_email_address'], | |
502 | 'toName' => $contributorDisplayName, | |
503 | 'toEmail' => $contributorEmail, | |
504 | 'isTest' => $form->_mode == 'test', | |
92fcb95f | 505 | 'PDFFilename' => ts('receipt') . '.pdf', |
9161952c | 506 | 'isEmailPdf' => $isEmailPdf, |
6a488035 TO |
507 | ) |
508 | ); | |
509 | ||
510 | return $sendReceipt; | |
511 | } | |
512 | ||
513 | } |