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 * 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 * @param CRM_Core_Form $form
334 * instance of Contribution form.
335 * @param array $params
336 * (reference ) an assoc array of name/value pairs.
337 * @param bool $ccContribution
338 * is it credit card contribution.
342 public static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {
343 $form->assign('receiptType', 'contribution');
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']);
347 if (!empty($params['payment_instrument_id'])) {
348 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
349 $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
352 // retrieve individual prefix value for honoree
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'],
358 'Amount' => CRM_Utils_Money
::format($softCredit['amount'], $softCredit['currency']),
360 $softCreditTypes[$key] = $softCredit['soft_credit_type_label'];
362 $form->assign('softCreditTypes', $softCreditTypes);
363 $form->assign('softCredits', $softCredits);
366 // retrieve premium product name and assigned fulfilled
368 if (!empty($params['hidden_Premium'])) {
369 if (isset($params['product_name']) &&
370 is_array($params['product_name']) &&
371 !empty($params['product_name'])
373 $productDAO = new CRM_Contribute_DAO_Product();
374 $productDAO->id
= $params['product_name'][0];
375 $productDAO->find(TRUE);
376 $params['product_name'] = $productDAO->name
;
377 $params['product_sku'] = $productDAO->sku
;
379 if (empty($params['product_option']) && !empty($form->_options
[$params['product_name'][0]])) {
380 $params['product_option'] = $form->_options
[$params['product_name'][0]][$params['product_name'][1]];
384 if (!empty($params['fulfilled_date'])) {
385 $form->assign('fulfilled_date', CRM_Utils_Date
::processDate($params['fulfilled_date']));
389 $form->assign('ccContribution', $ccContribution);
390 if ($ccContribution) {
392 $name = CRM_Utils_Array
::value('billing_first_name', $params);
393 if (!empty($params['billing_middle_name'])) {
394 $name .= " {$params['billing_middle_name']}";
396 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
398 $form->assign('billingName', $name);
400 //assign the address formatted up for display
401 $addressParts = array(
402 "street_address" => "billing_street_address-{$form->_bltID}",
403 "city" => "billing_city-{$form->_bltID}",
404 "postal_code" => "billing_postal_code-{$form->_bltID}",
405 "state_province" => "state_province-{$form->_bltID}",
406 "country" => "country-{$form->_bltID}",
409 $addressFields = array();
410 foreach ($addressParts as $name => $field) {
411 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
413 $form->assign('address', CRM_Utils_Address
::format($addressFields));
415 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
416 $date = CRM_Utils_Date
::mysqlToIso($date);
417 $form->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
418 $form->assign('credit_card_exp_date', $date);
419 $form->assign('credit_card_number',
420 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
424 //offline contribution
425 // assigned various dates to the templates
426 $form->assign('receipt_date', CRM_Utils_Date
::processDate($params['receipt_date']));
428 if (!empty($params['cancel_date'])) {
429 $form->assign('cancel_date', CRM_Utils_Date
::processDate($params['cancel_date']));
431 if (!empty($params['thankyou_date'])) {
432 $form->assign('thankyou_date', CRM_Utils_Date
::processDate($params['thankyou_date']));
434 if ($form->_action
& CRM_Core_Action
::UPDATE
) {
435 $form->assign('lineItem', empty($form->_lineItems
) ?
FALSE : $form->_lineItems
);
440 if (!empty($params['hidden_custom'])) {
441 $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
442 if ($form->_mode
== 'test') {
443 $contribParams[] = array('contribution_test', '=', 1, 0, 0);
446 //retrieve custom data
447 $customGroup = array();
449 foreach ($form->_groupTree
as $groupID => $group) {
450 $customFields = $customValues = array();
451 if ($groupID == 'info') {
454 foreach ($group['fields'] as $k => $field) {
455 $field['title'] = $field['label'];
456 $customFields["custom_{$k}"] = $field;
459 //build the array of customgroup contain customfields.
460 CRM_Core_BAO_UFGroup
::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
461 $customGroup[$group['title']] = $customValues;
463 //assign all custom group and corresponding fields to template.
464 $form->assign('customGroup', $customGroup);
467 $form->assign_by_ref('formValues', $params);
468 list($contributorDisplayName,
470 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($params['contact_id']);
471 $form->assign('contactID', $params['contact_id']);
472 $form->assign('contributionID', $params['contribution_id']);
474 if (!empty($params['currency'])) {
475 $form->assign('currency', $params['currency']);
478 if (!empty($params['receive_date'])) {
479 $form->assign('receive_date', CRM_Utils_Date
::processDate($params['receive_date']));
482 $template = CRM_Core_Smarty
::singleton();
483 $taxAmt = $template->get_template_vars('dataArray');
484 $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
485 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
486 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
487 if ((!empty($taxAmt) ||
isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
494 list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
496 'groupName' => 'msg_tpl_workflow_contribution',
497 'valueName' => 'contribution_offline_receipt',
498 'contactId' => $params['contact_id'],
499 'contributionId' => $params['contribution_id'],
500 'from' => $params['from_email_address'],
501 'toName' => $contributorDisplayName,
502 'toEmail' => $contributorEmail,
503 'isTest' => $form->_mode
== 'test',
504 'PDFFilename' => ts('receipt') . '.pdf',
505 'isEmailPdf' => $isEmailPdf,