3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Contribute_Form_AdditionalInfo
{
38 * Function to build the form for Premium Information.
44 static function buildPremium(&$form) {
46 $form->add('hidden', 'hidden_Premium', 1);
47 $sel1 = $sel2 = array();
49 $dao = new CRM_Contribute_DAO_Product();
52 $min_amount = array();
53 $sel1[0] = '-select product-';
54 while ($dao->fetch()) {
55 $sel1[$dao->id
] = $dao->name
. " ( " . $dao->sku
. " )";
56 $min_amount[$dao->id
] = $dao->min_contribution
;
57 $options = explode(',', $dao->options
);
58 foreach ($options as $k => $v) {
59 $options[$k] = trim($v);
61 if ($options[0] != '') {
62 $sel2[$dao->id
] = $options;
64 $form->assign('premiums', TRUE);
66 $form->_options
= $sel2;
67 $form->assign('mincontribution', $min_amount);
68 $sel = & $form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"');
69 $js = "<script type='text/javascript'>\n";
70 $formName = 'document.forms.' . $form->getName();
72 for ($k = 1; $k < 2; $k++
) {
73 if (!isset($defaults['product_name'][$k]) ||
(!$defaults['product_name'][$k])) {
74 $js .= "{$formName}['product_name[$k]'].style.display = 'none';\n";
78 $sel->setOptions(array($sel1, $sel2));
80 $form->assign('initHideBoxes', $js);
82 $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate'));
83 $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount'));
87 * Function to build the form for Additional Details.
93 static function buildAdditionalDetail(&$form) {
94 //Additional information section
95 $form->add('hidden', 'hidden_AdditionalDetail', 1);
97 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution');
99 $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
101 // add various amounts
102 $nonDeductAmount = & $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'),
103 $attributes['non_deductible_amount']
105 $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money');
107 if ($form->_online
) {
108 $nonDeductAmount->freeze();
110 $feeAmount = & $form->add('text', 'fee_amount', ts('Fee Amount'),
111 $attributes['fee_amount']
113 $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
114 if ($form->_online
) {
115 $feeAmount->freeze();
118 $netAmount = & $form->add('text', 'net_amount', ts('Net Amount'),
119 $attributes['net_amount']
121 $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
122 if ($form->_online
) {
123 $netAmount->freeze();
125 $element = & $form->add('text', 'invoice_id', ts('Invoice ID'),
126 $attributes['invoice_id']
128 if ($form->_online
) {
132 $form->addRule('invoice_id',
133 ts('This Invoice ID already exists in the database.'),
135 array('CRM_Contribute_DAO_Contribution', $form->_id
, 'invoice_id')
139 $form->add('select', 'contribution_page_id',
140 ts('Online Contribution Page'),
142 '' => ts('- select -')
144 CRM_Contribute_PseudoConstant
::contributionPage()
147 $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
149 $statusName = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
150 if ($form->_id
&& $form->_values
['contribution_status_id'] == array_search('Cancelled', $statusName)) {
151 $netAmount->freeze();
152 $feeAmount->freeze();
158 * This function is used by CRM/Pledge/Form/Pledge.php
160 * Function to build the form for PaymentReminders Information.
167 static function buildPaymentReminders(&$form) {
168 //PaymentReminders section
169 $form->add('hidden', 'hidden_PaymentReminders', 1);
170 $form->add('text', 'initial_reminder_day', ts('Send Initial Reminder'), array('size' => 3));
171 $form->addRule('initial_reminder_day', ts('Please enter a valid reminder day.'), 'positiveInteger');
172 $form->add('text', 'max_reminders', ts('Send up to'), array('size' => 3));
173 $form->addRule('max_reminders', ts('Please enter a valid No. of reminders.'), 'positiveInteger');
174 $form->add('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
175 $form->addRule('additional_reminder_day', ts('Please enter a valid additional reminder day.'), 'positiveInteger');
179 * Function to process the Premium Information
185 static function processPremium(&$params, $contributionID, $premiumID = NULL, &$options = NULL) {
186 $dao = new CRM_Contribute_DAO_ContributionProduct();
187 $dao->contribution_id
= $contributionID;
188 $dao->product_id
= $params['product_name'][0];
189 $dao->fulfilled_date
= CRM_Utils_Date
::processDate($params['fulfilled_date'], NULL, TRUE);
192 $premiumParams = array(
193 'id' => $params['product_name'][0],
195 $productDetails = array();
196 CRM_Contribute_BAO_ManagePremiums
::retrieve($premiumParams, $productDetails);
197 $dao->financial_type_id
= CRM_Utils_Array
::value('financial_type_id', $productDetails);
198 if (!empty($options[$params['product_name'][0]])) {
199 $dao->product_option
= $options[$params['product_name'][0]][$params['product_name'][1]];
202 $premoumDAO = new CRM_Contribute_DAO_ContributionProduct();
203 $premoumDAO->id
= $premiumID;
204 $premoumDAO->find(TRUE);
205 if ($premoumDAO->product_id
== $params['product_name'][0]) {
206 $dao->id
= $premiumID;
207 $premium = $dao->save();
210 $premoumDAO->delete();
212 $premium = $dao->save();
216 $premium = $dao->save();
219 if ($premiumID == NULL ||
$isDeleted) {
221 'cost' => CRM_Utils_Array
::value('cost', $productDetails),
222 'currency' => CRM_Utils_Array
::value('currency', $productDetails),
223 'financial_type_id' => CRM_Utils_Array
::value('financial_type_id', $productDetails),
224 'contributionId' => $contributionID
227 $params['oldPremium']['product_id'] = $premoumDAO->product_id
;
228 $params['oldPremium']['contribution_id'] = $premoumDAO->contribution_id
;
230 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($params);
235 * Function to process the Note
241 static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) {
244 'entity_table' => 'civicrm_contribution',
245 'note' => $params['note'],
246 'entity_id' => $contributionID,
247 'contact_id' => $contactID,
250 if ($contributionNoteID) {
251 $noteID = array("id" => $contributionNoteID);
252 $noteParams['note'] = $noteParams['note'] ?
$noteParams['note'] : "null";
254 CRM_Core_BAO_Note
::add($noteParams, $noteID);
258 * Function to process the Common data
264 static function postProcessCommon(&$params, &$formatted, &$form) {
266 'non_deductible_amount',
273 'contribution_page_id',
275 foreach ($fields as $f) {
276 $formatted[$f] = CRM_Utils_Array
::value($f, $params);
279 if (!empty($params['thankyou_date']) && !CRM_Utils_System
::isNull($params['thankyou_date'])) {
280 $formatted['thankyou_date'] = CRM_Utils_Date
::processDate($params['thankyou_date'], $params['thankyou_date_time']);
283 $formatted['thankyou_date'] = 'null';
286 if (!empty($params['is_email_receipt'])) {
287 $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis');
290 //special case to handle if all checkboxes are unchecked
291 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
294 CRM_Utils_Array
::value('financial_type_id',
298 $formatted['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
300 CRM_Utils_Array
::value('id', $params, NULL),
306 * Function to send email receipt.
308 * @form object of Contribution form.
310 * @param array $params (reference ) an assoc array of name/value pairs.
311 * @$ccContribution boolen, is it credit card contribution.
316 static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {
317 $form->assign('receiptType', 'contribution');
318 // Retrieve Financial Type Name from financial_type_id
319 $params['contributionType_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
320 $params['financial_type_id']);
321 if (!empty($params['payment_instrument_id'])) {
322 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
323 $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
326 // retrieve individual prefix value for honoree
327 if (!empty($params['hidden_Honoree'])) {
328 $individualPrefix = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'prefix_id');
329 $honor = CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
330 $params['honor_prefix'] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('honor_prefix_id',
335 $params["honor_type"] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('honor_type_id',
342 // retrieve premium product name and assigned fulfilled
344 if (!empty($params['hidden_Premium'])) {
345 if (isset($params['product_name']) &&
346 is_array($params['product_name']) &&
347 !empty($params['product_name'])
349 $productDAO = new CRM_Contribute_DAO_Product();
350 $productDAO->id
= $params['product_name'][0];
351 $productDAO->find(TRUE);
352 $params['product_name'] = $productDAO->name
;
353 $params['product_sku'] = $productDAO->sku
;
355 if (empty($params['product_option']) && !empty($form->_options
356 [$params['product_name'][0]])) {
357 $params['product_option'] = $form->_options
[$params['product_name'][0]][$params['product_name'][1]];
361 if (!empty($params['fulfilled_date'])) {
362 $form->assign('fulfilled_date', CRM_Utils_Date
::processDate($params['fulfilled_date']));
366 $form->assign('ccContribution', $ccContribution);
367 if ($ccContribution) {
369 $name = CRM_Utils_Array
::value('billing_first_name', $params);
370 if (!empty($params['billing_middle_name'])) {
371 $name .= " {$params['billing_middle_name']}";
373 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
375 $form->assign('billingName', $name);
377 //assign the address formatted up for display
378 $addressParts = array(
379 "street_address" => "billing_street_address-{$form->_bltID}",
380 "city" => "billing_city-{$form->_bltID}",
381 "postal_code" => "billing_postal_code-{$form->_bltID}",
382 "state_province" => "state_province-{$form->_bltID}",
383 "country" => "country-{$form->_bltID}",
386 $addressFields = array();
387 foreach ($addressParts as $name => $field) {
388 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
390 $form->assign('address', CRM_Utils_Address
::format($addressFields));
392 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
393 $date = CRM_Utils_Date
::mysqlToIso($date);
394 $form->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
395 $form->assign('credit_card_exp_date', $date);
396 $form->assign('credit_card_number',
397 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
401 //offline contribution
402 // assigned various dates to the templates
403 $form->assign('receipt_date', CRM_Utils_Date
::processDate($params['receipt_date']));
405 if (!empty($params['cancel_date'])) {
406 $form->assign('cancel_date', CRM_Utils_Date
::processDate($params['cancel_date']));
408 if (!empty($params['thankyou_date'])) {
409 $form->assign('thankyou_date', CRM_Utils_Date
::processDate($params['thankyou_date']));
411 if ($form->_action
& CRM_Core_Action
::UPDATE
) {
412 $form->assign('lineItem', empty($form->_lineItems
) ?
FALSE : $form->_lineItems
);
417 if (!empty($params['hidden_custom'])) {
418 $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
419 if ($form->_mode
== 'test') {
420 $contribParams[] = array('contribution_test', '=', 1, 0, 0);
423 //retrieve custom data
424 $customGroup = array();
426 foreach ($form->_groupTree
as $groupID => $group) {
427 $customFields = $customValues = array();
428 if ($groupID == 'info') {
431 foreach ($group['fields'] as $k => $field) {
432 $field['title'] = $field['label'];
433 $customFields["custom_{$k}"] = $field;
436 //build the array of customgroup contain customfields.
437 CRM_Core_BAO_UFGroup
::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
438 $customGroup[$group['title']] = $customValues;
440 //assign all custom group and corresponding fields to template.
441 $form->assign('customGroup', $customGroup);
444 $form->assign_by_ref('formValues', $params);
445 list($contributorDisplayName,
447 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($params['contact_id']);
448 $form->assign('contactID', $params['contact_id']);
449 $form->assign('contributionID', $params['contribution_id']);
451 if (!empty($params['currency'])) {
452 $form->assign('currency', $params['currency']);
455 if (!empty($params['receive_date'])) {
456 $form->assign('receive_date', CRM_Utils_Date
::processDate($params['receive_date']));
459 list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
461 'groupName' => 'msg_tpl_workflow_contribution',
462 'valueName' => 'contribution_offline_receipt',
463 'contactId' => $params['contact_id'],
464 'contributionId' => $params['contribution_id'],
465 'from' => $params['from_email_address'],
466 'toName' => $contributorDisplayName,
467 'toEmail' => $contributorEmail,
468 'isTest' => $form->_mode
== 'test',
469 'PDFFilename' => ts('receipt').'.pdf',