3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
34 class CRM_Contribute_BAO_Contribution_Utils
{
37 * Process payment after confirmation.
39 * @param CRM_Core_Form $form
41 * @param array $paymentParams
42 * Array with payment related key.
44 * @param array $premiumParams
45 * Array with premium related key.
47 * @param int $contactID
49 * @param int $contributionTypeId
51 * @param int|string $component component id
52 * @param array $fieldTypes
53 * Presumably relates to custom field types - used when building data for sendMail.
57 * @throws CRM_Core_Exception
63 public static function processConfirm(
69 $component = 'contribution',
74 CRM_Core_Payment_Form
::mapParams($form->_bltID
, $form->_params
, $paymentParams, TRUE);
75 $lineItems = $form->_lineItem
;
76 $isPaymentTransaction = self
::isPaymentTransaction($form);
78 $contributionType = new CRM_Financial_DAO_FinancialType();
79 $contributionType->id
= $contributionTypeId;
80 if (!$contributionType->find(TRUE)) {
81 //@todo - surely this check was part of the 4.3 upgrade & can go now?
82 CRM_Core_Error
::fatal('Could not find a system table');
85 // add some financial type details to the params list
86 // if folks need to use it
87 //CRM-15297 - contributionType is obsolete - pass financial type as well so people can deprecate it
88 $paymentParams['financialType_name'] = $paymentParams['contributionType_name'] = $form->_params
['contributionType_name'] = $contributionType->name
;
90 $paymentParams['financialType_accounting_code'] = $paymentParams['contributionType_accounting_code'] = $form->_params
['contributionType_accounting_code'] = CRM_Financial_BAO_FinancialAccount
::getAccountingCode($contributionTypeId);
91 $paymentParams['contributionPageID'] = $form->_params
['contributionPageID'] = $form->_values
['id'];
94 $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
96 if ($isPaymentTransaction) {
97 $payment = CRM_Core_Payment
::singleton($form->_mode
, $form->_paymentProcessor
, $form);
103 $form->_params
['receive_date'] = date('YmdHis');
104 $form->assign('receive_date',
105 CRM_Utils_Date
::mysqlToIso($form->_params
['receive_date'])
108 if ($form->_contributeMode
== 'notify' ||
111 // this is not going to come back, i.e. we fill in the other details
112 // when we get a callback from the payment processor
113 // also add the contact ID and contribution ID to the params list
114 $paymentParams['contactID'] = $form->_params
['contactID'] = $contactID;
115 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processFormContribution(
128 $form->_params
['contributionID'] = $contribution->id
;
131 $form->_params
['contributionTypeID'] = $contributionTypeId;
132 $form->_params
['item_name'] = $form->_params
['description'];
134 if ($contribution && $form->_values
['is_recur'] &&
135 $contribution->contribution_recur_id
137 $form->_params
['contributionRecurID'] = $contribution->contribution_recur_id
;
140 $form->set('params', $form->_params
);
141 $form->postProcessPremium($premiumParams, $contribution);
143 if ($isPaymentTransaction) {
144 // add qfKey so we can send to paypal
145 $form->_params
['qfKey'] = $form->controller
->_key
;
146 if ($component == 'membership') {
147 $membershipResult = array(1 => $contribution);
148 return $membershipResult;
152 if (is_object($payment)) {
153 // call postProcess hook before leaving
154 $form->postProcessHook();
155 // this does not return
156 $result = $payment->doTransferCheckout($form->_params
, 'contribute');
159 CRM_Core_Error
::fatal($paymentObjError);
163 // follow similar flow as IPN
164 // send the receipt mail
165 $form->set('params', $form->_params
);
166 if ($contributionType->is_deductible
) {
167 $form->assign('is_deductible', TRUE);
168 $form->set('is_deductible', TRUE);
170 if (isset($paymentParams['contribution_source'])) {
171 $form->_params
['source'] = $paymentParams['contribution_source'];
174 // get the price set values for receipt.
175 if ($form->_priceSetId
&& $form->_lineItem
) {
176 $form->_values
['lineItem'] = $form->_lineItem
;
177 $form->_values
['priceSetID'] = $form->_priceSetId
;
180 $form->_values
['contribution_id'] = $contribution->id
;
181 $form->_values
['contribution_page_id'] = $contribution->contribution_page_id
;
183 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
185 $contribution->is_test
192 elseif ($form->_contributeMode
== 'express') {
193 if ($form->_values
['is_monetary'] && $form->_amount
> 0.0) {
194 // determine if express + recurring and direct accordingly
195 if (!empty($paymentParams['is_recur']) && $paymentParams['is_recur'] == 1) {
196 if (is_object($payment)) {
197 $result = $payment->createRecurringPayments($paymentParams);
200 CRM_Core_Error
::fatal($paymentObjError);
204 if (is_object($payment)) {
205 $result = $payment->doExpressCheckout($paymentParams);
208 CRM_Core_Error
::fatal($paymentObjError);
213 elseif ($isPaymentTransaction) {
214 if (!empty($paymentParams['is_recur']) &&
215 $form->_contributeMode
== 'direct'
218 // For recurring contribution, create Contribution Record first.
219 // Contribution ID, Recurring ID and Contact ID needed
220 // When we get a callback from the payment processor
222 $paymentParams['contactID'] = $contactID;
224 // Fix for CRM-14354. If the membership is recurring, don't create a
225 // civicrm_contribution_recur record for the additional contribution
226 // (i.e., the amount NOT associated with the membership). Temporarily
227 // cache the is_recur values so we can process the additional gift as a
230 if ($form->_membershipBlock
['is_separate_payment']) {
231 if (!empty($form->_params
['auto_renew'])) {
232 $cachedFormValue = CRM_Utils_Array
::value('is_recur', $form->_values
);
233 $cachedParamValue = CRM_Utils_Array
::value('is_recur', $paymentParams);
234 unset($form->_values
['is_recur']);
235 unset($paymentParams['is_recur']);
242 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processFormContribution(
254 // restore cached values (part of fix for CRM-14354)
255 if (!empty($cachedFormValue)) {
256 $form->_values
['is_recur'] = $cachedFormValue;
257 $paymentParams['is_recur'] = $cachedParamValue;
260 $paymentParams['contributionID'] = $contribution->id
;
261 //CRM-15297 deprecate contributionTypeID
262 $paymentParams['financialTypeID'] = $paymentParams['contributionTypeID'] = $contribution->financial_type_id
;
263 $paymentParams['contributionPageID'] = $contribution->contribution_page_id
;
265 if ($form->_values
['is_recur'] && $contribution->contribution_recur_id
) {
266 $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id
;
269 if (is_object($payment)) {
270 $result = $payment->doDirectPayment($paymentParams);
273 CRM_Core_Error
::fatal($paymentObjError);
277 if ($component == 'membership') {
278 $membershipResult = array();
281 if (is_a($result, 'CRM_Core_Error')) {
282 //make sure to cleanup db for recurring case.
283 //@todo this clean up has always been controversial as many orgs prefer to see failed transactions.
284 // most recent discussion has been that they should be retained and this could be altered
285 if (!empty($paymentParams['contributionID'])) {
286 CRM_Contribute_BAO_Contribution
::deleteContribution($paymentParams['contributionID']);
288 if (!empty($paymentParams['contributionRecurID'])) {
289 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($paymentParams['contributionRecurID']);
292 if ($component !== 'membership') {
293 CRM_Core_Error
::displaySessionError($result);
294 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact',
295 "_qf_Main_display=true&qfKey={$form->_params['qfKey']}"
298 $membershipResult[1] = $result;
300 elseif ($result ||
($form->_amount
== 0.0 && !$form->_params
['is_pay_later'])) {
302 $form->_params
= array_merge($form->_params
, $result);
304 $form->set('params', $form->_params
);
305 $form->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $result));
307 // result has all the stuff we need
308 // lets archive it to a financial transaction
309 //@todo - this is done in 2 places - can't we just do it once straight after retrieving contribution type -
310 // when would this be a bad thing?
311 if ($contributionType->is_deductible
) {
312 $form->assign('is_deductible', TRUE);
313 $form->set('is_deductible', TRUE);
316 if (isset($paymentParams['contribution_source'])) {
317 $form->_params
['source'] = $paymentParams['contribution_source'];
320 // check if pending was set to true by payment processor
322 if (!empty($form->_params
['contribution_status_pending'])) {
325 if (!(!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct')) {
326 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processFormContribution($form,
327 $form->_params
, $result,
328 $contactID, $contributionType,
335 $form->postProcessPremium($premiumParams, $contribution);
336 if (is_array($result) && !empty($result['trxn_id'])) {
337 $contribution->trxn_id
= $result['trxn_id'];
339 $membershipResult[1] = $contribution;
342 if ($component == 'membership') {
343 return $membershipResult;
346 //Do not send an email if Recurring contribution is done via Direct Mode
347 //We will send email once the IPN is received.
348 if (!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct') {
352 // get the price set values for receipt.
353 if ($form->_priceSetId
&& $form->_lineItem
) {
354 $form->_values
['lineItem'] = $form->_lineItem
;
355 $form->_values
['priceSetID'] = $form->_priceSetId
;
358 // finally send an email receipt
360 $form->_values
['contribution_id'] = $contribution->id
;
361 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
362 $form->_values
, $contribution->is_test
,
369 * Is a payment being made.
370 * Note that setting is_monetary on the form is somewhat legacy and the behaviour around this setting is confusing. It would be preferable
371 * to look for the amount only (assuming this cannot refer to payment in goats or other non-monetary currency
372 * @param CRM_Core_Form $form
376 static protected function isPaymentTransaction($form) {
377 if (!empty($form->_values
['is_monetary']) && $form->_amount
>= 0.0) {
385 * Get the contribution details by month
395 public static function contributionChartMonthly($param) {
397 $param = array(1 => array($param, 'Integer'));
401 $param = array(1 => array($param, 'Integer'));
405 SELECT sum(contrib.total_amount) AS ctAmt,
406 MONTH( contrib.receive_date) AS contribMonth
407 FROM civicrm_contribution AS contrib
408 INNER JOIN civicrm_contact AS contact ON ( contact.id = contrib.contact_id )
409 WHERE contrib.contact_id = contact.id
410 AND ( contrib.is_test = 0 OR contrib.is_test IS NULL )
411 AND contrib.contribution_status_id = 1
412 AND date_format(contrib.receive_date,'%Y') = %1
413 AND contact.is_deleted = 0
414 GROUP BY contribMonth
415 ORDER BY month(contrib.receive_date)";
417 $dao = CRM_Core_DAO
::executeQuery($query, $param);
420 while ($dao->fetch()) {
421 if ($dao->contribMonth
) {
422 $params['By Month'][$dao->contribMonth
] = $dao->ctAmt
;
429 * Get the contribution details by year.
435 public static function contributionChartYearly() {
436 $config = CRM_Core_Config
::singleton();
437 $yearClause = "year(contrib.receive_date) as contribYear";
438 if (!empty($config->fiscalYearStart
) && ($config->fiscalYearStart
['M'] != 1 ||
$config->fiscalYearStart
['d'] != 1)) {
440 WHEN (MONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['M'] . "
441 && DAYOFMONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['d'] . " )
443 concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
445 concat(YEAR(contrib.receive_date)-1,'-', YEAR(contrib.receive_date))
450 SELECT sum(contrib.total_amount) AS ctAmt,
452 FROM civicrm_contribution AS contrib
453 INNER JOIN civicrm_contact contact ON ( contact.id = contrib.contact_id )
454 WHERE ( contrib.is_test = 0 OR contrib.is_test IS NULL )
455 AND contrib.contribution_status_id = 1
456 AND contact.is_deleted = 0
458 ORDER BY contribYear";
459 $dao = CRM_Core_DAO
::executeQuery($query);
462 while ($dao->fetch()) {
463 if (!empty($dao->contribYear
)) {
464 $params['By Year'][$dao->contribYear
] = $dao->ctAmt
;
471 * @param array $params
472 * @param int $contactID
475 public static function createCMSUser(&$params, $contactID, $mail) {
476 // lets ensure we only create one CMS user
477 static $created = FALSE;
484 if (!empty($params['cms_create_account'])) {
485 $params['contactID'] = $contactID;
486 if (!CRM_Core_BAO_CMSUser
::create($params, $mail)) {
487 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
493 * @param array $params
494 * @param string $type
498 public static function _fillCommonParams(&$params, $type = 'paypal') {
499 if (array_key_exists('transaction', $params)) {
500 $transaction = &$params['transaction'];
503 $transaction = &$params;
506 $params['contact_type'] = 'Individual';
508 $billingLocTypeId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
509 if (!$billingLocTypeId) {
510 $billingLocTypeId = 1;
512 if (!CRM_Utils_System
::isNull($params['address'])) {
513 $params['address'][1]['is_primary'] = 1;
514 $params['address'][1]['location_type_id'] = $billingLocTypeId;
516 if (!CRM_Utils_System
::isNull($params['email'])) {
517 $params['email'] = array(
519 'email' => $params['email'],
520 'location_type_id' => $billingLocTypeId,
525 if (isset($transaction['trxn_id'])) {
526 // set error message if transaction has already been processed.
527 $contribution = new CRM_Contribute_DAO_Contribution();
528 $contribution->trxn_id
= $transaction['trxn_id'];
529 if ($contribution->find(TRUE)) {
530 $params['error'][] = ts('transaction already processed.');
534 // generate a new transaction id, if not already exist
535 $transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
538 if (!isset($transaction['financial_type_id'])) {
539 $contributionTypes = array_keys(CRM_Contribute_PseudoConstant
::financialType());
540 $transaction['financial_type_id'] = $contributionTypes[0];
543 if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
544 $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array
::value('fee_amount', $transaction, 0);
547 if (!isset($transaction['invoice_id'])) {
548 $transaction['invoice_id'] = $transaction['trxn_id'];
551 $source = ts('ContributionProcessor: %1 API',
552 array(1 => ucfirst($type))
554 if (isset($transaction['source'])) {
555 $transaction['source'] = $source . ':: ' . $transaction['source'];
558 $transaction['source'] = $source;
565 * @param array $apiParams
567 * @param string $type
568 * @param bool $category
572 public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE) {
573 $type = strtolower($type);
575 if (!in_array($type, array(
581 // return the params as is
584 $params = $transaction = array();
586 if ($type == 'paypal') {
587 foreach ($apiParams as $detail => $val) {
588 if (isset($mapper['contact'][$detail])) {
589 $params[$mapper['contact'][$detail]] = $val;
591 elseif (isset($mapper['location'][$detail])) {
592 $params['address'][1][$mapper['location'][$detail]] = $val;
594 elseif (isset($mapper['transaction'][$detail])) {
597 // Sadly, PayPal seems to send two distinct data elements in a single field,
598 // so we break them out here. This is somewhat ugly and tragic.
605 list($frequency_interval, $frequency_unit) = explode(' ', $val);
606 $transaction['frequency_interval'] = $frequency_interval;
607 $transaction['frequency_unit'] = $freqUnits[$frequency_unit];
610 case 'subscriptiondate':
612 // PayPal dates are in ISO-8601 format. We need a format that
614 $unix_timestamp = strtotime($val);
615 $transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
622 $val = "[PayPal_field:{$detail}] {$val}";
623 $transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ?
$transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
628 $transaction[$mapper['transaction'][$detail]] = $val;
633 if (!empty($transaction) && $category) {
634 $params['transaction'] = $transaction;
637 $params +
= $transaction;
640 self
::_fillCommonParams($params, $type);
645 if ($type == 'csv') {
646 $header = $apiParams['header'];
647 unset($apiParams['header']);
648 foreach ($apiParams as $key => $val) {
649 if (isset($mapper['contact'][$header[$key]])) {
650 $params[$mapper['contact'][$header[$key]]] = $val;
652 elseif (isset($mapper['location'][$header[$key]])) {
653 $params['address'][1][$mapper['location'][$header[$key]]] = $val;
655 elseif (isset($mapper['transaction'][$header[$key]])) {
656 $transaction[$mapper['transaction'][$header[$key]]] = $val;
659 $params[$header[$key]] = $val;
663 if (!empty($transaction) && $category) {
664 $params['transaction'] = $transaction;
667 $params +
= $transaction;
670 self
::_fillCommonParams($params, $type);
675 if ($type == 'google') {
676 // return if response smell invalid
677 if (!array_key_exists('risk-information-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
680 $riskInfo = &$apiParams[1][$apiParams[0]]['notifications']['risk-information-notification'];
682 if (array_key_exists('new-order-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
683 $newOrder = &$apiParams[1][$apiParams[0]]['notifications']['new-order-notification'];
686 if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
687 foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
688 if (!empty($mapper['location'][$field])) {
689 $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
691 elseif (!empty($mapper['contact'][$field])) {
692 if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
693 foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
694 $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
698 $params[$mapper['contact'][$field]] = $info['VALUE'];
701 elseif (!empty($mapper['transaction'][$field])) {
702 $transaction[$mapper['transaction'][$field]] = $info['VALUE'];
706 // Response is an huge array. Lets pickup only those which we ineterested in
707 // using a local mapper, rather than traversing the entire array.
708 $localMapper = array(
709 'google-order-number' => $riskInfo['google-order-number']['VALUE'],
710 'total-charge-amount' => $apiParams[2]['total-charge-amount']['VALUE'],
711 'currency' => $apiParams[2]['total-charge-amount']['currency'],
712 'item-name' => $newOrder['shopping-cart']['items']['item']['item-name']['VALUE'],
713 'timestamp' => $apiParams[2]['timestamp']['VALUE'],
715 if (array_key_exists('latest-charge-fee', $apiParams[2])) {
716 $localMapper['latest-charge-fee'] = $apiParams[2]['latest-charge-fee']['total']['VALUE'];
717 $localMapper['net-amount'] = $localMapper['total-charge-amount'] - $localMapper['latest-charge-fee'];
720 // This is a subscription (recurring) donation.
721 if (array_key_exists('subscription', $newOrder['shopping-cart']['items']['item'])) {
722 $subscription = $newOrder['shopping-cart']['items']['item']['subscription'];
723 $localMapper['amount'] = $newOrder['order-total']['VALUE'];
724 $localMapper['times'] = $subscription['payments']['subscription-payment']['times'];
725 // Convert Google's period to one compatible with the CiviCRM db field.
729 'MONHTLY' => 'month',
732 $localMapper['period'] = $freqUnits[$subscription['period']];
733 // Unlike PayPal, Google has no concept of freq. interval, it is always 1.
734 $localMapper['frequency_interval'] = '1';
735 // Google Checkout dates are in ISO-8601 format. We need a format that
737 $unix_timestamp = strtotime($localMapper['timestamp']);
738 $mysql_date = date('YmdHis', $unix_timestamp);
739 $localMapper['modified_date'] = $mysql_date;
740 $localMapper['start_date'] = $mysql_date;
741 // This is PayPal's nomenclature, but just use it for Google as well since
742 // we act on the value of trxn_type in processAPIContribution().
743 $localMapper['trxn_type'] = 'subscrpayment';
746 foreach ($localMapper as $localKey => $localVal) {
747 if (!empty($mapper['transaction'][$localKey])) {
748 $transaction[$mapper['transaction'][$localKey]] = $localVal;
752 if (empty($params) && empty($transaction)) {
756 if (!empty($transaction) && $category) {
757 $params['transaction'] = $transaction;
760 $params +
= $transaction;
763 self
::_fillCommonParams($params, $type);
770 * @param array $params
774 public static function processAPIContribution($params) {
775 if (empty($params) ||
array_key_exists('error', $params)) {
779 // add contact using dedupe rule
780 $dedupeParams = CRM_Dedupe_Finder
::formatParams($params, 'Individual');
781 $dedupeParams['check_permission'] = FALSE;
782 $dupeIds = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
783 // if we find more than one contact, use the first one
784 if (!empty($dupeIds[0])) {
785 $params['contact_id'] = $dupeIds[0];
787 $contact = CRM_Contact_BAO_Contact
::create($params);
792 // only pass transaction params to contribution::create, if available
793 if (array_key_exists('transaction', $params)) {
794 $params = $params['transaction'];
795 $params['contact_id'] = $contact->id
;
798 // handle contribution custom data
799 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
802 CRM_Utils_Array
::value('financial_type_id',
806 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
807 CRM_Utils_Array
::value('id', $params, NULL),
810 // create contribution
812 // if this is a recurring contribution then process it first
813 if ($params['trxn_type'] == 'subscrpayment') {
814 // see if a recurring record already exists
815 $recurring = new CRM_Contribute_BAO_ContributionRecur();
816 $recurring->processor_id
= $params['processor_id'];
817 if (!$recurring->find(TRUE)) {
818 $recurring = new CRM_Contribute_BAO_ContributionRecur();
819 $recurring->invoice_id
= $params['invoice_id'];
820 $recurring->find(TRUE);
823 // This is the same thing the CiviCRM IPN handler does to handle
824 // subsequent recurring payments to avoid duplicate contribution
825 // errors due to invoice ID. See:
826 // ./CRM/Core/Payment/PayPalIPN.php:200
827 if ($recurring->id
) {
828 $params['invoice_id'] = md5(uniqid(rand(), TRUE));
831 $recurring->copyValues($params);
833 if (is_a($recurring, 'CRM_Core_Error')) {
837 $params['contribution_recur_id'] = $recurring->id
;
841 $contribution = &CRM_Contribute_BAO_Contribution
::create($params,
842 CRM_Core_DAO
::$_nullArray
844 if (!$contribution->id
) {
852 * @param int $contactID
856 public static function getFirstLastDetails($contactID) {
863 if (!isset($_cache[$contactID])) {
865 SELECT total_amount, receive_date
866 FROM civicrm_contribution c
867 WHERE contact_id = %1
868 ORDER BY receive_date ASC
871 $params = array(1 => array($contactID, 'Integer'));
873 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
879 $details['first'] = array(
880 'total_amount' => $dao->total_amount
,
881 'receive_date' => $dao->receive_date
,
885 // flip asc and desc to get the last query
886 $sql = str_replace('ASC', 'DESC', $sql);
887 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
889 $details['last'] = array(
890 'total_amount' => $dao->total_amount
,
891 'receive_date' => $dao->receive_date
,
895 $_cache[$contactID] = $details;
897 return $_cache[$contactID];
901 * Calculate the tax amount based on given tax rate.
903 * @param float $amount
905 * @param float $taxRate
906 * Tax rate of selected financial account for field.
909 * array of tax amount
912 public static function calculateTaxAmount($amount, $taxRate) {
913 $taxAmount = array();
914 $taxAmount['tax_amount'] = ($taxRate / 100) * CRM_Utils_Rule
::cleanMoney($amount);