3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 * Function to build the form for Premium Information.
46 static function buildPremium(&$form) {
48 $form->add('hidden', 'hidden_Premium', 1);
49 $sel1 = $sel2 = array();
51 $dao = new CRM_Contribute_DAO_Product();
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);
63 if ($options[0] != '') {
64 $sel2[$dao->id
] = $options;
66 $form->assign('premiums', TRUE);
68 $form->_options
= $sel2;
69 $form->assign('mincontribution', $min_amount);
70 $sel = & $form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"');
71 $js = "<script type='text/javascript'>\n";
72 $formName = 'document.forms.' . $form->getName();
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";
80 $sel->setOptions(array($sel1, $sel2));
82 $form->assign('initHideBoxes', $js);
84 $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate'));
85 $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount'));
89 * Function to build the form for Additional Details.
97 static function buildAdditionalDetail(&$form) {
98 //Additional information section
99 $form->add('hidden', 'hidden_AdditionalDetail', 1);
101 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution');
103 $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
105 // add various amounts
106 $nonDeductAmount = & $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'),
107 $attributes['non_deductible_amount']
109 $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money');
111 if ($form->_online
) {
112 $nonDeductAmount->freeze();
114 $feeAmount = & $form->add('text', 'fee_amount', ts('Fee Amount'),
115 $attributes['fee_amount']
117 $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
118 if ($form->_online
) {
119 $feeAmount->freeze();
122 $netAmount = & $form->add('text', 'net_amount', ts('Net Amount'),
123 $attributes['net_amount']
125 $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
126 if ($form->_online
) {
127 $netAmount->freeze();
129 $element = & $form->add('text', 'invoice_id', ts('Invoice ID'),
130 $attributes['invoice_id']
132 if ($form->_online
) {
136 $form->addRule('invoice_id',
137 ts('This Invoice ID already exists in the database.'),
139 array('CRM_Contribute_DAO_Contribution', $form->_id
, 'invoice_id')
143 $form->add('select', 'contribution_page_id',
144 ts('Online Contribution Page'),
146 '' => ts('- select -')
148 CRM_Contribute_PseudoConstant
::contributionPage()
151 $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
153 $statusName = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
154 if ($form->_id
&& $form->_values
['contribution_status_id'] == array_search('Cancelled', $statusName)) {
155 $netAmount->freeze();
156 $feeAmount->freeze();
162 * This function is used by CRM/Pledge/Form/Pledge.php
164 * Function to build the form for PaymentReminders Information.
172 static function buildPaymentReminders(&$form) {
173 //PaymentReminders section
174 $form->add('hidden', 'hidden_PaymentReminders', 1);
175 $form->add('text', 'initial_reminder_day', ts('Send Initial Reminder'), array('size' => 3));
176 $form->addRule('initial_reminder_day', ts('Please enter a valid reminder day.'), 'positiveInteger');
177 $form->add('text', 'max_reminders', ts('Send up to'), array('size' => 3));
178 $form->addRule('max_reminders', ts('Please enter a valid No. of reminders.'), 'positiveInteger');
179 $form->add('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
180 $form->addRule('additional_reminder_day', ts('Please enter a valid additional reminder day.'), 'positiveInteger');
184 * Function to process the Premium Information
189 * @param $contributionID
190 * @param null $premiumID
191 * @param null $options
194 static function processPremium(&$params, $contributionID, $premiumID = NULL, &$options = NULL) {
195 $dao = new CRM_Contribute_DAO_ContributionProduct();
196 $dao->contribution_id
= $contributionID;
197 $dao->product_id
= $params['product_name'][0];
198 $dao->fulfilled_date
= CRM_Utils_Date
::processDate($params['fulfilled_date'], NULL, TRUE);
201 $premiumParams = array(
202 'id' => $params['product_name'][0],
204 $productDetails = array();
205 CRM_Contribute_BAO_ManagePremiums
::retrieve($premiumParams, $productDetails);
206 $dao->financial_type_id
= CRM_Utils_Array
::value('financial_type_id', $productDetails);
207 if (!empty($options[$params['product_name'][0]])) {
208 $dao->product_option
= $options[$params['product_name'][0]][$params['product_name'][1]];
211 $premoumDAO = new CRM_Contribute_DAO_ContributionProduct();
212 $premoumDAO->id
= $premiumID;
213 $premoumDAO->find(TRUE);
214 if ($premoumDAO->product_id
== $params['product_name'][0]) {
215 $dao->id
= $premiumID;
216 $premium = $dao->save();
219 $premoumDAO->delete();
221 $premium = $dao->save();
225 $premium = $dao->save();
228 if ($premiumID == NULL ||
$isDeleted) {
230 'cost' => CRM_Utils_Array
::value('cost', $productDetails),
231 'currency' => CRM_Utils_Array
::value('currency', $productDetails),
232 'financial_type_id' => CRM_Utils_Array
::value('financial_type_id', $productDetails),
233 'contributionId' => $contributionID
236 $params['oldPremium']['product_id'] = $premoumDAO->product_id
;
237 $params['oldPremium']['contribution_id'] = $premoumDAO->contribution_id
;
239 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($params);
244 * Function to process the Note
250 * @param $contributionID
251 * @param null $contributionNoteID
255 static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) {
258 'entity_table' => 'civicrm_contribution',
259 'note' => $params['note'],
260 'entity_id' => $contributionID,
261 'contact_id' => $contactID,
264 if ($contributionNoteID) {
265 $noteID = array("id" => $contributionNoteID);
266 $noteParams['note'] = $noteParams['note'] ?
$noteParams['note'] : "null";
268 CRM_Core_BAO_Note
::add($noteParams, $noteID);
272 * Function to process the Common data
281 static function postProcessCommon(&$params, &$formatted, &$form) {
283 'non_deductible_amount',
290 'contribution_page_id',
292 foreach ($fields as $f) {
293 $formatted[$f] = CRM_Utils_Array
::value($f, $params);
296 if (!empty($params['thankyou_date']) && !CRM_Utils_System
::isNull($params['thankyou_date'])) {
297 $formatted['thankyou_date'] = CRM_Utils_Date
::processDate($params['thankyou_date'], $params['thankyou_date_time']);
300 $formatted['thankyou_date'] = 'null';
303 if (!empty($params['is_email_receipt'])) {
304 $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis');
307 //special case to handle if all checkboxes are unchecked
308 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
311 CRM_Utils_Array
::value('financial_type_id',
315 $formatted['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
317 CRM_Utils_Array
::value('id', $params, NULL),
323 * Function to send email receipt.
325 * @form object of Contribution form.
328 * @param array $params (reference ) an assoc array of name/value pairs.
329 * @$ccContribution boolen, is it credit card contribution.
330 * @param bool $ccContribution
335 static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {
336 $form->assign('receiptType', 'contribution');
337 // Retrieve Financial Type Name from financial_type_id
338 $params['contributionType_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
339 $params['financial_type_id']);
340 if (!empty($params['payment_instrument_id'])) {
341 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
342 $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
345 // retrieve individual prefix value for honoree
346 if (isset($params['soft_credit'])) {
347 $softCreditTypes = $softCredits = array();
348 foreach ($params['soft_credit'] as $key => $softCredit) {
349 $softCredits[$key] = array(
350 'Name' => $softCredit['contact_name'],
351 'Amount' => CRM_Utils_Money
::format($softCredit['amount'], $softCredit['currency'])
353 $softCreditTypes[$key] = $softCredit['soft_credit_type_label'];
355 $form->assign('softCreditTypes', $softCreditTypes);
356 $form->assign('softCredits', $softCredits);
359 // retrieve premium product name and assigned fulfilled
361 if (!empty($params['hidden_Premium'])) {
362 if (isset($params['product_name']) &&
363 is_array($params['product_name']) &&
364 !empty($params['product_name'])
366 $productDAO = new CRM_Contribute_DAO_Product();
367 $productDAO->id
= $params['product_name'][0];
368 $productDAO->find(TRUE);
369 $params['product_name'] = $productDAO->name
;
370 $params['product_sku'] = $productDAO->sku
;
372 if (empty($params['product_option']) && !empty($form->_options
373 [$params['product_name'][0]])) {
374 $params['product_option'] = $form->_options
[$params['product_name'][0]][$params['product_name'][1]];
378 if (!empty($params['fulfilled_date'])) {
379 $form->assign('fulfilled_date', CRM_Utils_Date
::processDate($params['fulfilled_date']));
383 $form->assign('ccContribution', $ccContribution);
384 if ($ccContribution) {
386 $name = CRM_Utils_Array
::value('billing_first_name', $params);
387 if (!empty($params['billing_middle_name'])) {
388 $name .= " {$params['billing_middle_name']}";
390 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
392 $form->assign('billingName', $name);
394 //assign the address formatted up for display
395 $addressParts = array(
396 "street_address" => "billing_street_address-{$form->_bltID}",
397 "city" => "billing_city-{$form->_bltID}",
398 "postal_code" => "billing_postal_code-{$form->_bltID}",
399 "state_province" => "state_province-{$form->_bltID}",
400 "country" => "country-{$form->_bltID}",
403 $addressFields = array();
404 foreach ($addressParts as $name => $field) {
405 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
407 $form->assign('address', CRM_Utils_Address
::format($addressFields));
409 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
410 $date = CRM_Utils_Date
::mysqlToIso($date);
411 $form->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
412 $form->assign('credit_card_exp_date', $date);
413 $form->assign('credit_card_number',
414 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
418 //offline contribution
419 // assigned various dates to the templates
420 $form->assign('receipt_date', CRM_Utils_Date
::processDate($params['receipt_date']));
422 if (!empty($params['cancel_date'])) {
423 $form->assign('cancel_date', CRM_Utils_Date
::processDate($params['cancel_date']));
425 if (!empty($params['thankyou_date'])) {
426 $form->assign('thankyou_date', CRM_Utils_Date
::processDate($params['thankyou_date']));
428 if ($form->_action
& CRM_Core_Action
::UPDATE
) {
429 $form->assign('lineItem', empty($form->_lineItems
) ?
FALSE : $form->_lineItems
);
434 if (!empty($params['hidden_custom'])) {
435 $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
436 if ($form->_mode
== 'test') {
437 $contribParams[] = array('contribution_test', '=', 1, 0, 0);
440 //retrieve custom data
441 $customGroup = array();
443 foreach ($form->_groupTree
as $groupID => $group) {
444 $customFields = $customValues = array();
445 if ($groupID == 'info') {
448 foreach ($group['fields'] as $k => $field) {
449 $field['title'] = $field['label'];
450 $customFields["custom_{$k}"] = $field;
453 //build the array of customgroup contain customfields.
454 CRM_Core_BAO_UFGroup
::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
455 $customGroup[$group['title']] = $customValues;
457 //assign all custom group and corresponding fields to template.
458 $form->assign('customGroup', $customGroup);
461 $form->assign_by_ref('formValues', $params);
462 list($contributorDisplayName,
464 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($params['contact_id']);
465 $form->assign('contactID', $params['contact_id']);
466 $form->assign('contributionID', $params['contribution_id']);
468 if (!empty($params['currency'])) {
469 $form->assign('currency', $params['currency']);
472 if (!empty($params['receive_date'])) {
473 $form->assign('receive_date', CRM_Utils_Date
::processDate($params['receive_date']));
476 list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
478 'groupName' => 'msg_tpl_workflow_contribution',
479 'valueName' => 'contribution_offline_receipt',
480 'contactId' => $params['contact_id'],
481 'contributionId' => $params['contribution_id'],
482 'from' => $params['from_email_address'],
483 'toName' => $contributorDisplayName,
484 'toEmail' => $contributorEmail,
485 'isTest' => $form->_mode
== 'test',
486 'PDFFilename' => ts('receipt').'.pdf',