3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Contribute_Form_AdditionalInfo
{
38 * Build the form object for Premium Information.
41 * @param CRM_Core_Form $form
45 public static function buildPremium(&$form) {
47 $form->add('hidden', 'hidden_Premium', 1);
48 $sel1 = $sel2 = array();
50 $dao = new CRM_Contribute_DAO_Product();
53 $min_amount = array();
54 $sel1[0] = '-select product-';
55 while ($dao->fetch()) {
56 $sel1[$dao->id
] = $dao->name
. " ( " . $dao->sku
. " )";
57 $min_amount[$dao->id
] = $dao->min_contribution
;
58 $options = explode(',', $dao->options
);
59 foreach ($options as $k => $v) {
60 $options[$k] = trim($v);
62 if ($options[0] != '') {
63 $sel2[$dao->id
] = $options;
65 $form->assign('premiums', TRUE);
67 $form->_options
= $sel2;
68 $form->assign('mincontribution', $min_amount);
69 $sel = & $form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"');
70 $js = "<script type='text/javascript'>\n";
71 $formName = 'document.forms.' . $form->getName();
73 for ($k = 1; $k < 2; $k++
) {
74 if (!isset($defaults['product_name'][$k]) ||
(!$defaults['product_name'][$k])) {
75 $js .= "{$formName}['product_name[$k]'].style.display = 'none';\n";
79 $sel->setOptions(array($sel1, $sel2));
81 $form->assign('initHideBoxes', $js);
83 $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate'));
84 $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount'));
88 * Build the form object for Additional Details.
91 * @param CRM_Core_Form $form
95 public static function buildAdditionalDetail(&$form) {
96 //Additional information section
97 $form->add('hidden', 'hidden_AdditionalDetail', 1);
99 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution');
101 $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
103 // add various amounts
104 $nonDeductAmount = & $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'),
105 $attributes['non_deductible_amount']
107 $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money');
109 if ($form->_online
) {
110 $nonDeductAmount->freeze();
112 $feeAmount = & $form->add('text', 'fee_amount', ts('Fee Amount'),
113 $attributes['fee_amount']
115 $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
116 if ($form->_online
) {
117 $feeAmount->freeze();
120 $netAmount = & $form->add('text', 'net_amount', ts('Net Amount'),
121 $attributes['net_amount']
123 $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
124 if ($form->_online
) {
125 $netAmount->freeze();
127 $element = & $form->add('text', 'invoice_id', ts('Invoice ID'),
128 $attributes['invoice_id']
130 if ($form->_online
) {
134 $form->addRule('invoice_id',
135 ts('This Invoice ID already exists in the database.'),
137 array('CRM_Contribute_DAO_Contribution', $form->_id
, 'invoice_id')
140 $element = $form->add('text', 'creditnote_id', ts('Credit Note ID'),
141 $attributes['creditnote_id']
143 if ($form->_online
) {
147 $form->addRule('creditnote_id',
148 ts('This Credit Note ID already exists in the database.'),
150 array('CRM_Contribute_DAO_Contribution', $form->_id
, 'creditnote_id')
154 $form->add('select', 'contribution_page_id',
155 ts('Online Contribution Page'),
157 '' => ts('- select -')
159 CRM_Contribute_PseudoConstant
::contributionPage()
162 $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
164 $statusName = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
165 if ($form->_id
&& $form->_values
['contribution_status_id'] == array_search('Cancelled', $statusName)) {
166 $netAmount->freeze();
167 $feeAmount->freeze();
173 * This function is used by CRM/Pledge/Form/Pledge.php
175 * Build the form object for PaymentReminders Information.
178 * @param CRM_Core_Form $form
182 public static function buildPaymentReminders(&$form) {
183 //PaymentReminders section
184 $form->add('hidden', 'hidden_PaymentReminders', 1);
185 $form->add('text', 'initial_reminder_day', ts('Send Initial Reminder'), array('size' => 3));
186 $form->addRule('initial_reminder_day', ts('Please enter a valid reminder day.'), 'positiveInteger');
187 $form->add('text', 'max_reminders', ts('Send up to'), array('size' => 3));
188 $form->addRule('max_reminders', ts('Please enter a valid No. of reminders.'), 'positiveInteger');
189 $form->add('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
190 $form->addRule('additional_reminder_day', ts('Please enter a valid additional reminder day.'), 'positiveInteger');
194 * Process the Premium Information
197 * @param array $params
198 * @param int $contributionID
199 * @param int $premiumID
200 * @param null $options
203 public static function processPremium(&$params, $contributionID, $premiumID = NULL, &$options = NULL) {
204 $dao = new CRM_Contribute_DAO_ContributionProduct();
205 $dao->contribution_id
= $contributionID;
206 $dao->product_id
= $params['product_name'][0];
207 $dao->fulfilled_date
= CRM_Utils_Date
::processDate($params['fulfilled_date'], NULL, TRUE);
210 $premiumParams = array(
211 'id' => $params['product_name'][0],
213 $productDetails = array();
214 CRM_Contribute_BAO_ManagePremiums
::retrieve($premiumParams, $productDetails);
215 $dao->financial_type_id
= CRM_Utils_Array
::value('financial_type_id', $productDetails);
216 if (!empty($options[$params['product_name'][0]])) {
217 $dao->product_option
= $options[$params['product_name'][0]][$params['product_name'][1]];
220 $premoumDAO = new CRM_Contribute_DAO_ContributionProduct();
221 $premoumDAO->id
= $premiumID;
222 $premoumDAO->find(TRUE);
223 if ($premoumDAO->product_id
== $params['product_name'][0]) {
224 $dao->id
= $premiumID;
225 $premium = $dao->save();
228 $premoumDAO->delete();
230 $premium = $dao->save();
234 $premium = $dao->save();
237 if ($premiumID == NULL ||
$isDeleted) {
239 'cost' => CRM_Utils_Array
::value('cost', $productDetails),
240 'currency' => CRM_Utils_Array
::value('currency', $productDetails),
241 'financial_type_id' => CRM_Utils_Array
::value('financial_type_id', $productDetails),
242 'contributionId' => $contributionID
245 $params['oldPremium']['product_id'] = $premoumDAO->product_id
;
246 $params['oldPremium']['contribution_id'] = $premoumDAO->contribution_id
;
248 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($params);
256 * @param array $params
257 * @param int $contactID
258 * @param int $contributionID
259 * @param int $contributionNoteID
263 public static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) {
266 'entity_table' => 'civicrm_contribution',
267 'note' => $params['note'],
268 'entity_id' => $contributionID,
269 'contact_id' => $contactID,
272 if ($contributionNoteID) {
273 $noteID = array("id" => $contributionNoteID);
274 $noteParams['note'] = $noteParams['note'] ?
$noteParams['note'] : "null";
276 CRM_Core_BAO_Note
::add($noteParams, $noteID);
280 * Process the Common data
283 * @param array $params
285 * @param CRM_Core_Form $form
288 public static function postProcessCommon(&$params, &$formatted, &$form) {
290 'non_deductible_amount',
298 'contribution_page_id',
300 foreach ($fields as $f) {
301 $formatted[$f] = CRM_Utils_Array
::value($f, $params);
304 if (!empty($params['thankyou_date']) && !CRM_Utils_System
::isNull($params['thankyou_date'])) {
305 $formatted['thankyou_date'] = CRM_Utils_Date
::processDate($params['thankyou_date'], $params['thankyou_date_time']);
308 $formatted['thankyou_date'] = 'null';
311 if (!empty($params['is_email_receipt'])) {
312 $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis');
315 //special case to handle if all checkboxes are unchecked
316 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
319 CRM_Utils_Array
::value('financial_type_id',
323 $formatted['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
325 CRM_Utils_Array
::value('id', $params, NULL),
331 * Send email receipt.
333 * @form object of Contribution form.
335 * @param CRM_Core_Form $form
336 * @param array $params
337 * (reference ) an assoc array of name/value pairs.
338 * @$ccContribution boolen, is it credit card contribution.
339 * @param bool $ccContribution
343 public static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {
344 $form->assign('receiptType', 'contribution');
345 // Retrieve Financial Type Name from financial_type_id
346 $params['contributionType_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
347 $params['financial_type_id']);
348 if (!empty($params['payment_instrument_id'])) {
349 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
350 $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
353 // retrieve individual prefix value for honoree
354 if (isset($params['soft_credit'])) {
355 $softCreditTypes = $softCredits = array();
356 foreach ($params['soft_credit'] as $key => $softCredit) {
357 $softCredits[$key] = array(
358 'Name' => $softCredit['contact_name'],
359 'Amount' => CRM_Utils_Money
::format($softCredit['amount'], $softCredit['currency'])
361 $softCreditTypes[$key] = $softCredit['soft_credit_type_label'];
363 $form->assign('softCreditTypes', $softCreditTypes);
364 $form->assign('softCredits', $softCredits);
367 // retrieve premium product name and assigned fulfilled
369 if (!empty($params['hidden_Premium'])) {
370 if (isset($params['product_name']) &&
371 is_array($params['product_name']) &&
372 !empty($params['product_name'])
374 $productDAO = new CRM_Contribute_DAO_Product();
375 $productDAO->id
= $params['product_name'][0];
376 $productDAO->find(TRUE);
377 $params['product_name'] = $productDAO->name
;
378 $params['product_sku'] = $productDAO->sku
;
380 if (empty($params['product_option']) && !empty($form->_options
381 [$params['product_name'][0]])) {
382 $params['product_option'] = $form->_options
[$params['product_name'][0]][$params['product_name'][1]];
386 if (!empty($params['fulfilled_date'])) {
387 $form->assign('fulfilled_date', CRM_Utils_Date
::processDate($params['fulfilled_date']));
391 $form->assign('ccContribution', $ccContribution);
392 if ($ccContribution) {
394 $name = CRM_Utils_Array
::value('billing_first_name', $params);
395 if (!empty($params['billing_middle_name'])) {
396 $name .= " {$params['billing_middle_name']}";
398 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
400 $form->assign('billingName', $name);
402 //assign the address formatted up for display
403 $addressParts = array(
404 "street_address" => "billing_street_address-{$form->_bltID}",
405 "city" => "billing_city-{$form->_bltID}",
406 "postal_code" => "billing_postal_code-{$form->_bltID}",
407 "state_province" => "state_province-{$form->_bltID}",
408 "country" => "country-{$form->_bltID}",
411 $addressFields = array();
412 foreach ($addressParts as $name => $field) {
413 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
415 $form->assign('address', CRM_Utils_Address
::format($addressFields));
417 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
418 $date = CRM_Utils_Date
::mysqlToIso($date);
419 $form->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
420 $form->assign('credit_card_exp_date', $date);
421 $form->assign('credit_card_number',
422 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
426 //offline contribution
427 // assigned various dates to the templates
428 $form->assign('receipt_date', CRM_Utils_Date
::processDate($params['receipt_date']));
430 if (!empty($params['cancel_date'])) {
431 $form->assign('cancel_date', CRM_Utils_Date
::processDate($params['cancel_date']));
433 if (!empty($params['thankyou_date'])) {
434 $form->assign('thankyou_date', CRM_Utils_Date
::processDate($params['thankyou_date']));
436 if ($form->_action
& CRM_Core_Action
::UPDATE
) {
437 $form->assign('lineItem', empty($form->_lineItems
) ?
FALSE : $form->_lineItems
);
442 if (!empty($params['hidden_custom'])) {
443 $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
444 if ($form->_mode
== 'test') {
445 $contribParams[] = array('contribution_test', '=', 1, 0, 0);
448 //retrieve custom data
449 $customGroup = array();
451 foreach ($form->_groupTree
as $groupID => $group) {
452 $customFields = $customValues = array();
453 if ($groupID == 'info') {
456 foreach ($group['fields'] as $k => $field) {
457 $field['title'] = $field['label'];
458 $customFields["custom_{$k}"] = $field;
461 //build the array of customgroup contain customfields.
462 CRM_Core_BAO_UFGroup
::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
463 $customGroup[$group['title']] = $customValues;
465 //assign all custom group and corresponding fields to template.
466 $form->assign('customGroup', $customGroup);
469 $form->assign_by_ref('formValues', $params);
470 list($contributorDisplayName,
472 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($params['contact_id']);
473 $form->assign('contactID', $params['contact_id']);
474 $form->assign('contributionID', $params['contribution_id']);
476 if (!empty($params['currency'])) {
477 $form->assign('currency', $params['currency']);
480 if (!empty($params['receive_date'])) {
481 $form->assign('receive_date', CRM_Utils_Date
::processDate($params['receive_date']));
484 $template = CRM_Core_Smarty
::singleton();
485 $taxAmt = $template->get_template_vars('dataArray');
486 $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
487 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
488 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
489 if ((!empty($taxAmt) ||
isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
496 list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
498 'groupName' => 'msg_tpl_workflow_contribution',
499 'valueName' => 'contribution_offline_receipt',
500 'contactId' => $params['contact_id'],
501 'contributionId' => $params['contribution_id'],
502 'from' => $params['from_email_address'],
503 'toName' => $contributorDisplayName,
504 'toEmail' => $contributorEmail,
505 'isTest' => $form->_mode
== 'test',
506 'PDFFilename' => ts('receipt') . '.pdf',
507 'isEmailPdf' => $isEmailPdf,