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 $now = $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
::processContribution(
127 $form->_params
['contributionID'] = $contribution->id
;
130 $form->_params
['contributionTypeID'] = $contributionTypeId;
131 $form->_params
['item_name'] = $form->_params
['description'];
133 if ($contribution && $form->_values
['is_recur'] &&
134 $contribution->contribution_recur_id
136 $form->_params
['contributionRecurID'] = $contribution->contribution_recur_id
;
139 $form->set('params', $form->_params
);
140 $form->postProcessPremium($premiumParams, $contribution);
142 if ($isPaymentTransaction) {
143 // add qfKey so we can send to paypal
144 $form->_params
['qfKey'] = $form->controller
->_key
;
145 if ($component == 'membership') {
146 $membershipResult = array(1 => $contribution);
147 return $membershipResult;
151 if (is_object($payment)) {
152 // call postProcess hook before leaving
153 $form->postProcessHook();
154 // this does not return
155 $result = $payment->doTransferCheckout($form->_params
, 'contribute');
158 CRM_Core_Error
::fatal($paymentObjError);
162 // follow similar flow as IPN
163 // send the receipt mail
164 $form->set('params', $form->_params
);
165 if ($contributionType->is_deductible
) {
166 $form->assign('is_deductible', TRUE);
167 $form->set('is_deductible', TRUE);
169 if (isset($paymentParams['contribution_source'])) {
170 $form->_params
['source'] = $paymentParams['contribution_source'];
173 // get the price set values for receipt.
174 if ($form->_priceSetId
&& $form->_lineItem
) {
175 $form->_values
['lineItem'] = $form->_lineItem
;
176 $form->_values
['priceSetID'] = $form->_priceSetId
;
179 $form->_values
['contribution_id'] = $contribution->id
;
180 $form->_values
['contribution_page_id'] = $contribution->contribution_page_id
;
182 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
184 $contribution->is_test
191 elseif ($form->_contributeMode
== 'express') {
192 if ($form->_values
['is_monetary'] && $form->_amount
> 0.0) {
193 // determine if express + recurring and direct accordingly
194 if (!empty($paymentParams['is_recur']) && $paymentParams['is_recur'] == 1) {
195 if (is_object($payment)) {
196 $result = $payment->createRecurringPayments($paymentParams);
199 CRM_Core_Error
::fatal($paymentObjError);
203 if (is_object($payment)) {
204 $result = $payment->doExpressCheckout($paymentParams);
207 CRM_Core_Error
::fatal($paymentObjError);
212 elseif ($isPaymentTransaction) {
213 if (!empty($paymentParams['is_recur']) &&
214 $form->_contributeMode
== 'direct'
217 // For recurring contribution, create Contribution Record first.
218 // Contribution ID, Recurring ID and Contact ID needed
219 // When we get a callback from the payment processor
221 $paymentParams['contactID'] = $contactID;
223 // Fix for CRM-14354. If the membership is recurring, don't create a
224 // civicrm_contribution_recur record for the additional contribution
225 // (i.e., the amount NOT associated with the membership). Temporarily
226 // cache the is_recur values so we can process the additional gift as a
229 if ($form->_membershipBlock
['is_separate_payment']) {
230 if (!empty($form->_params
['auto_renew'])) {
231 $cachedFormValue = CRM_Utils_Array
::value('is_recur', $form->_values
);
232 $cachedParamValue = CRM_Utils_Array
::value('is_recur', $paymentParams);
233 unset($form->_values
['is_recur']);
234 unset($paymentParams['is_recur']);
241 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution(
252 // restore cached values (part of fix for CRM-14354)
253 if (!empty($cachedFormValue)) {
254 $form->_values
['is_recur'] = $cachedFormValue;
255 $paymentParams['is_recur'] = $cachedParamValue;
258 $paymentParams['contributionID'] = $contribution->id
;
259 //CRM-15297 deprecate contributionTypeID
260 $paymentParams['financialTypeID'] = $paymentParams['contributionTypeID'] = $contribution->financial_type_id
;
261 $paymentParams['contributionPageID'] = $contribution->contribution_page_id
;
263 if ($form->_values
['is_recur'] && $contribution->contribution_recur_id
) {
264 $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id
;
267 if (is_object($payment)) {
268 $result = $payment->doDirectPayment($paymentParams);
271 CRM_Core_Error
::fatal($paymentObjError);
275 if ($component == 'membership') {
276 $membershipResult = array();
279 if (is_a($result, 'CRM_Core_Error')) {
280 //make sure to cleanup db for recurring case.
281 //@todo this clean up has always been controversial as many orgs prefer to see failed transactions.
282 // most recent discussion has been that they should be retained and this could be altered
283 if (!empty($paymentParams['contributionID'])) {
284 CRM_Contribute_BAO_Contribution
::deleteContribution($paymentParams['contributionID']);
286 if (!empty($paymentParams['contributionRecurID'])) {
287 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($paymentParams['contributionRecurID']);
290 if ($component !== 'membership') {
291 CRM_Core_Error
::displaySessionError($result);
292 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact',
293 "_qf_Main_display=true&qfKey={$form->_params['qfKey']}"
296 $membershipResult[1] = $result;
298 elseif ($result ||
($form->_amount
== 0.0 && !$form->_params
['is_pay_later'])) {
300 $form->_params
= array_merge($form->_params
, $result);
302 $form->set('params', $form->_params
);
303 $form->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $result));
305 // result has all the stuff we need
306 // lets archive it to a financial transaction
307 //@todo - this is done in 2 places - can't we just do it once straight after retrieving contribution type -
308 // when would this be a bad thing?
309 if ($contributionType->is_deductible
) {
310 $form->assign('is_deductible', TRUE);
311 $form->set('is_deductible', TRUE);
314 if (isset($paymentParams['contribution_source'])) {
315 $form->_params
['source'] = $paymentParams['contribution_source'];
318 // check if pending was set to true by payment processor
320 if (!empty($form->_params
['contribution_status_pending'])) {
323 if (!(!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct')) {
324 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution($form,
325 $form->_params
, $result,
326 $contactID, $contributionType,
332 $form->postProcessPremium($premiumParams, $contribution);
333 if (is_array($result) && !empty($result['trxn_id'])) {
334 $contribution->trxn_id
= $result['trxn_id'];
336 $membershipResult[1] = $contribution;
339 if ($component == 'membership') {
340 return $membershipResult;
343 //Do not send an email if Recurring contribution is done via Direct Mode
344 //We will send email once the IPN is received.
345 if (!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct') {
349 // get the price set values for receipt.
350 if ($form->_priceSetId
&& $form->_lineItem
) {
351 $form->_values
['lineItem'] = $form->_lineItem
;
352 $form->_values
['priceSetID'] = $form->_priceSetId
;
355 // finally send an email receipt
357 $form->_values
['contribution_id'] = $contribution->id
;
358 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
359 $form->_values
, $contribution->is_test
,
366 * Is a payment being made.
367 * Note that setting is_monetary on the form is somewhat legacy and the behaviour around this setting is confusing. It would be preferable
368 * to look for the amount only (assuming this cannot refer to payment in goats or other non-monetary currency
369 * @param CRM_Core_Form $form
373 static protected function isPaymentTransaction($form) {
374 if (!empty($form->_values
['is_monetary']) && $form->_amount
>= 0.0) {
382 * Get the contribution details by month
392 public static function contributionChartMonthly($param) {
394 $param = array(1 => array($param, 'Integer'));
398 $param = array(1 => array($param, 'Integer'));
402 SELECT sum(contrib.total_amount) AS ctAmt,
403 MONTH( contrib.receive_date) AS contribMonth
404 FROM civicrm_contribution AS contrib
405 INNER JOIN civicrm_contact AS contact ON ( contact.id = contrib.contact_id )
406 WHERE contrib.contact_id = contact.id
407 AND ( contrib.is_test = 0 OR contrib.is_test IS NULL )
408 AND contrib.contribution_status_id = 1
409 AND date_format(contrib.receive_date,'%Y') = %1
410 AND contact.is_deleted = 0
411 GROUP BY contribMonth
412 ORDER BY month(contrib.receive_date)";
414 $dao = CRM_Core_DAO
::executeQuery($query, $param);
417 while ($dao->fetch()) {
418 if ($dao->contribMonth
) {
419 $params['By Month'][$dao->contribMonth
] = $dao->ctAmt
;
426 * Get the contribution details by year.
432 public static function contributionChartYearly() {
433 $config = CRM_Core_Config
::singleton();
434 $yearClause = "year(contrib.receive_date) as contribYear";
435 if (!empty($config->fiscalYearStart
) && ($config->fiscalYearStart
['M'] != 1 ||
$config->fiscalYearStart
['d'] != 1)) {
437 WHEN (MONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['M'] . "
438 && DAYOFMONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['d'] . " )
440 concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
442 concat(YEAR(contrib.receive_date)-1,'-', YEAR(contrib.receive_date))
447 SELECT sum(contrib.total_amount) AS ctAmt,
449 FROM civicrm_contribution AS contrib
450 INNER JOIN civicrm_contact contact ON ( contact.id = contrib.contact_id )
451 WHERE ( contrib.is_test = 0 OR contrib.is_test IS NULL )
452 AND contrib.contribution_status_id = 1
453 AND contact.is_deleted = 0
455 ORDER BY contribYear";
456 $dao = CRM_Core_DAO
::executeQuery($query);
459 while ($dao->fetch()) {
460 if (!empty($dao->contribYear
)) {
461 $params['By Year'][$dao->contribYear
] = $dao->ctAmt
;
468 * @param array $params
469 * @param int $contactID
472 public static function createCMSUser(&$params, $contactID, $mail) {
473 // lets ensure we only create one CMS user
474 static $created = FALSE;
481 if (!empty($params['cms_create_account'])) {
482 $params['contactID'] = $contactID;
483 if (!CRM_Core_BAO_CMSUser
::create($params, $mail)) {
484 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
490 * @param array $params
491 * @param string $type
495 public static function _fillCommonParams(&$params, $type = 'paypal') {
496 if (array_key_exists('transaction', $params)) {
497 $transaction = &$params['transaction'];
500 $transaction = &$params;
503 $params['contact_type'] = 'Individual';
505 $billingLocTypeId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
506 if (!$billingLocTypeId) {
507 $billingLocTypeId = 1;
509 if (!CRM_Utils_System
::isNull($params['address'])) {
510 $params['address'][1]['is_primary'] = 1;
511 $params['address'][1]['location_type_id'] = $billingLocTypeId;
513 if (!CRM_Utils_System
::isNull($params['email'])) {
514 $params['email'] = array(
516 'email' => $params['email'],
517 'location_type_id' => $billingLocTypeId,
522 if (isset($transaction['trxn_id'])) {
523 // set error message if transaction has already been processed.
524 $contribution = new CRM_Contribute_DAO_Contribution();
525 $contribution->trxn_id
= $transaction['trxn_id'];
526 if ($contribution->find(TRUE)) {
527 $params['error'][] = ts('transaction already processed.');
531 // generate a new transaction id, if not already exist
532 $transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
535 if (!isset($transaction['financial_type_id'])) {
536 $contributionTypes = array_keys(CRM_Contribute_PseudoConstant
::financialType());
537 $transaction['financial_type_id'] = $contributionTypes[0];
540 if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
541 $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array
::value('fee_amount', $transaction, 0);
544 if (!isset($transaction['invoice_id'])) {
545 $transaction['invoice_id'] = $transaction['trxn_id'];
548 $source = ts('ContributionProcessor: %1 API',
549 array(1 => ucfirst($type))
551 if (isset($transaction['source'])) {
552 $transaction['source'] = $source . ':: ' . $transaction['source'];
555 $transaction['source'] = $source;
562 * @param array $apiParams
564 * @param string $type
565 * @param bool $category
569 public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE) {
570 $type = strtolower($type);
572 if (!in_array($type, array(
578 // return the params as is
581 $params = $transaction = array();
583 if ($type == 'paypal') {
584 foreach ($apiParams as $detail => $val) {
585 if (isset($mapper['contact'][$detail])) {
586 $params[$mapper['contact'][$detail]] = $val;
588 elseif (isset($mapper['location'][$detail])) {
589 $params['address'][1][$mapper['location'][$detail]] = $val;
591 elseif (isset($mapper['transaction'][$detail])) {
594 // Sadly, PayPal seems to send two distinct data elements in a single field,
595 // so we break them out here. This is somewhat ugly and tragic.
602 list($frequency_interval, $frequency_unit) = explode(' ', $val);
603 $transaction['frequency_interval'] = $frequency_interval;
604 $transaction['frequency_unit'] = $freqUnits[$frequency_unit];
607 case 'subscriptiondate':
609 // PayPal dates are in ISO-8601 format. We need a format that
611 $unix_timestamp = strtotime($val);
612 $transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
619 $val = "[PayPal_field:{$detail}] {$val}";
620 $transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ?
$transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
625 $transaction[$mapper['transaction'][$detail]] = $val;
630 if (!empty($transaction) && $category) {
631 $params['transaction'] = $transaction;
634 $params +
= $transaction;
637 self
::_fillCommonParams($params, $type);
642 if ($type == 'csv') {
643 $header = $apiParams['header'];
644 unset($apiParams['header']);
645 foreach ($apiParams as $key => $val) {
646 if (isset($mapper['contact'][$header[$key]])) {
647 $params[$mapper['contact'][$header[$key]]] = $val;
649 elseif (isset($mapper['location'][$header[$key]])) {
650 $params['address'][1][$mapper['location'][$header[$key]]] = $val;
652 elseif (isset($mapper['transaction'][$header[$key]])) {
653 $transaction[$mapper['transaction'][$header[$key]]] = $val;
656 $params[$header[$key]] = $val;
660 if (!empty($transaction) && $category) {
661 $params['transaction'] = $transaction;
664 $params +
= $transaction;
667 self
::_fillCommonParams($params, $type);
672 if ($type == 'google') {
673 // return if response smell invalid
674 if (!array_key_exists('risk-information-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
677 $riskInfo = &$apiParams[1][$apiParams[0]]['notifications']['risk-information-notification'];
679 if (array_key_exists('new-order-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
680 $newOrder = &$apiParams[1][$apiParams[0]]['notifications']['new-order-notification'];
683 if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
684 foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
685 if (!empty($mapper['location'][$field])) {
686 $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
688 elseif (!empty($mapper['contact'][$field])) {
689 if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
690 foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
691 $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
695 $params[$mapper['contact'][$field]] = $info['VALUE'];
698 elseif (!empty($mapper['transaction'][$field])) {
699 $transaction[$mapper['transaction'][$field]] = $info['VALUE'];
703 // Response is an huge array. Lets pickup only those which we ineterested in
704 // using a local mapper, rather than traversing the entire array.
705 $localMapper = array(
706 'google-order-number' => $riskInfo['google-order-number']['VALUE'],
707 'total-charge-amount' => $apiParams[2]['total-charge-amount']['VALUE'],
708 'currency' => $apiParams[2]['total-charge-amount']['currency'],
709 'item-name' => $newOrder['shopping-cart']['items']['item']['item-name']['VALUE'],
710 'timestamp' => $apiParams[2]['timestamp']['VALUE'],
712 if (array_key_exists('latest-charge-fee', $apiParams[2])) {
713 $localMapper['latest-charge-fee'] = $apiParams[2]['latest-charge-fee']['total']['VALUE'];
714 $localMapper['net-amount'] = $localMapper['total-charge-amount'] - $localMapper['latest-charge-fee'];
717 // This is a subscription (recurring) donation.
718 if (array_key_exists('subscription', $newOrder['shopping-cart']['items']['item'])) {
719 $subscription = $newOrder['shopping-cart']['items']['item']['subscription'];
720 $localMapper['amount'] = $newOrder['order-total']['VALUE'];
721 $localMapper['times'] = $subscription['payments']['subscription-payment']['times'];
722 // Convert Google's period to one compatible with the CiviCRM db field.
726 'MONHTLY' => 'month',
729 $localMapper['period'] = $freqUnits[$subscription['period']];
730 // Unlike PayPal, Google has no concept of freq. interval, it is always 1.
731 $localMapper['frequency_interval'] = '1';
732 // Google Checkout dates are in ISO-8601 format. We need a format that
734 $unix_timestamp = strtotime($localMapper['timestamp']);
735 $mysql_date = date('YmdHis', $unix_timestamp);
736 $localMapper['modified_date'] = $mysql_date;
737 $localMapper['start_date'] = $mysql_date;
738 // This is PayPal's nomenclature, but just use it for Google as well since
739 // we act on the value of trxn_type in processAPIContribution().
740 $localMapper['trxn_type'] = 'subscrpayment';
743 foreach ($localMapper as $localKey => $localVal) {
744 if (!empty($mapper['transaction'][$localKey])) {
745 $transaction[$mapper['transaction'][$localKey]] = $localVal;
749 if (empty($params) && empty($transaction)) {
753 if (!empty($transaction) && $category) {
754 $params['transaction'] = $transaction;
757 $params +
= $transaction;
760 self
::_fillCommonParams($params, $type);
767 * @param array $params
771 public static function processAPIContribution($params) {
772 if (empty($params) ||
array_key_exists('error', $params)) {
776 // add contact using dedupe rule
777 $dedupeParams = CRM_Dedupe_Finder
::formatParams($params, 'Individual');
778 $dedupeParams['check_permission'] = FALSE;
779 $dupeIds = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
780 // if we find more than one contact, use the first one
781 if (!empty($dupeIds[0])) {
782 $params['contact_id'] = $dupeIds[0];
784 $contact = CRM_Contact_BAO_Contact
::create($params);
789 // only pass transaction params to contribution::create, if available
790 if (array_key_exists('transaction', $params)) {
791 $params = $params['transaction'];
792 $params['contact_id'] = $contact->id
;
795 // handle contribution custom data
796 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
799 CRM_Utils_Array
::value('financial_type_id',
803 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
805 CRM_Utils_Array
::value('id', $params, NULL),
808 // create contribution
810 // if this is a recurring contribution then process it first
811 if ($params['trxn_type'] == 'subscrpayment') {
812 // see if a recurring record already exists
813 $recurring = new CRM_Contribute_BAO_ContributionRecur();
814 $recurring->processor_id
= $params['processor_id'];
815 if (!$recurring->find(TRUE)) {
816 $recurring = new CRM_Contribute_BAO_ContributionRecur();
817 $recurring->invoice_id
= $params['invoice_id'];
818 $recurring->find(TRUE);
821 // This is the same thing the CiviCRM IPN handler does to handle
822 // subsequent recurring payments to avoid duplicate contribution
823 // errors due to invoice ID. See:
824 // ./CRM/Core/Payment/PayPalIPN.php:200
825 if ($recurring->id
) {
826 $params['invoice_id'] = md5(uniqid(rand(), TRUE));
829 $recurring->copyValues($params);
831 if (is_a($recurring, 'CRM_Core_Error')) {
835 $params['contribution_recur_id'] = $recurring->id
;
839 $contribution = &CRM_Contribute_BAO_Contribution
::create($params,
840 CRM_Core_DAO
::$_nullArray
842 if (!$contribution->id
) {
850 * @param int $contactID
854 public static function getFirstLastDetails($contactID) {
861 if (!isset($_cache[$contactID])) {
863 SELECT total_amount, receive_date
864 FROM civicrm_contribution c
865 WHERE contact_id = %1
866 ORDER BY receive_date ASC
869 $params = array(1 => array($contactID, 'Integer'));
871 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
877 $details['first'] = array(
878 'total_amount' => $dao->total_amount
,
879 'receive_date' => $dao->receive_date
,
883 // flip asc and desc to get the last query
884 $sql = str_replace('ASC', 'DESC', $sql);
885 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
887 $details['last'] = array(
888 'total_amount' => $dao->total_amount
,
889 'receive_date' => $dao->receive_date
,
893 $_cache[$contactID] = $details;
895 return $_cache[$contactID];
899 * Calculate the tax amount based on given tax rate.
901 * @param float $amount
903 * @param float $taxRate
904 * Tax rate of selected financial account for field.
907 * array of tax amount
910 public static function calculateTaxAmount($amount, $taxRate) {
911 $taxAmount = array();
912 $taxAmount['tax_amount'] = ($taxRate / 100) * CRM_Utils_Rule
::cleanMoney($amount);