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_BAO_Contribution_Utils
{
38 * Function to process payment after confirmation
40 * @param object $form form object
41 * @param array $paymentParams array with payment related key
43 * @param array $premiumParams array with premium related key
45 * @param int $contactID contact id
46 * @param int $contributionTypeId financial type id
47 * @param int|string $component component id
49 * @param null $fieldTypes
51 * @return array associated array
56 static function processConfirm(&$form,
61 $component = 'contribution',
64 CRM_Core_Payment_Form
::mapParams($form->_bltID
, $form->_params
, $paymentParams, TRUE);
65 $isTest = ($form->_mode
== 'test') ?
1 : 0;
66 $lineItems = $form->_lineItem
;
68 $contributionType = new CRM_Financial_DAO_FinancialType();
69 if (isset($paymentParams['financial_type'])) {
70 $contributionType->id
= $paymentParams['financial_type'];
72 elseif (!empty($form->_values
['pledge_id'])) {
73 $contributionType->id
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
74 $form->_values
['pledge_id'],
79 $contributionType->id
= $contributionTypeId;
81 if (!$contributionType->find(TRUE)) {
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 $paymentParams['contributionType_name'] = $form->_params
['contributionType_name'] = $contributionType->name
;
89 $paymentParams['contributionType_accounting_code'] = $form->_params
['contributionType_accounting_code'] = CRM_Financial_BAO_FinancialAccount
::getAccountingCode($contributionType->id
);
90 $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.');
95 if ($form->_values
['is_monetary'] && $form->_amount
> 0.0 && is_array($form->_paymentProcessor
)) {
96 $payment = CRM_Core_Payment
::singleton($form->_mode
, $form->_paymentProcessor
, $form);
100 $now = date('YmdHis');
103 if ($form->_contributeMode
== 'notify' ||
104 $form->_params
['is_pay_later']
106 // this is not going to come back, i.e. we fill in the other details
107 // when we get a callback from the payment processor
108 // also add the contact ID and contribution ID to the params list
109 $paymentParams['contactID'] = $form->_params
['contactID'] = $contactID;
110 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution(
122 $form->_params
['contributionID'] = $contribution->id
;
125 $form->_params
['contributionTypeID'] = $contributionType->id
;
126 $form->_params
['item_name'] = $form->_params
['description'];
127 $form->_params
['receive_date'] = $now;
129 if ($contribution && $form->_values
['is_recur'] &&
130 $contribution->contribution_recur_id
132 $form->_params
['contributionRecurID'] = $contribution->contribution_recur_id
;
135 $form->set('params', $form->_params
);
136 $form->postProcessPremium($premiumParams, $contribution);
138 if ($form->_values
['is_monetary'] && $form->_amount
> 0.0) {
139 // add qfKey so we can send to paypal
140 $form->_params
['qfKey'] = $form->controller
->_key
;
141 if ($component == 'membership') {
142 $membershipResult = array(1 => $contribution);
143 return $membershipResult;
146 if (!$form->_params
['is_pay_later']) {
147 if (is_object($payment)) {
148 // call postprocess hook before leaving
149 $form->postProcessHook();
150 // this does not return
151 $result = &$payment->doTransferCheckout($form->_params
, 'contribute');
154 CRM_Core_Error
::fatal($paymentObjError);
158 // follow similar flow as IPN
159 // send the receipt mail
160 $form->set('params', $form->_params
);
161 if ($contributionType->is_deductible
) {
162 $form->assign('is_deductible', TRUE);
163 $form->set('is_deductible', TRUE);
165 if (isset($paymentParams['contribution_source'])) {
166 $form->_params
['source'] = $paymentParams['contribution_source'];
169 // get the price set values for receipt.
170 if ($form->_priceSetId
&& $form->_lineItem
) {
171 $form->_values
['lineItem'] = $form->_lineItem
;
172 $form->_values
['priceSetID'] = $form->_priceSetId
;
175 $form->_values
['contribution_id'] = $contribution->id
;
176 $form->_values
['contribution_page_id'] = $contribution->contribution_page_id
;
178 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
180 $contribution->is_test
187 elseif ($form->_contributeMode
== 'express') {
188 if ($form->_values
['is_monetary'] && $form->_amount
> 0.0) {
189 // determine if express + recurring and direct accordingly
190 if ($paymentParams['is_recur'] == 1) {
191 if (is_object($payment)) {
192 $result = $payment->createRecurringPayments($paymentParams);
195 CRM_Core_Error
::fatal($paymentObjError);
199 if (is_object($payment)) {
200 $result = $payment->doExpressCheckout($paymentParams);
203 CRM_Core_Error
::fatal($paymentObjError);
208 elseif ($form->_values
['is_monetary'] && $form->_amount
> 0.0) {
209 if (!empty($paymentParams['is_recur']) &&
210 $form->_contributeMode
== 'direct'
213 // For recurring contribution, create Contribution Record first.
214 // Contribution ID, Recurring ID and Contact ID needed
215 // When we get a callback from the payment processor
217 $paymentParams['contactID'] = $contactID;
219 // Fix for CRM-14354. If the membership is recurring, don't create a
220 // civicrm_contribution_recur record for the additional contribution
221 // (i.e., the amount NOT associated with the membership). Temporarily
222 // cache the is_recur values so we can process the additional gift as a
224 if ($form->_membershipBlock
['is_separate_payment']) {
225 $cachedFormValue = CRM_Utils_Array
::value('is_recur', $form->_values
);
226 unset($form->_values
['is_recur']);
227 $cachedParamValue = CRM_Utils_Array
::value('is_recur', $paymentParams);
228 unset($paymentParams['is_recur']);
231 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution(
242 // restore cached values (part of fix for CRM-14354)
243 if ($form->_membershipBlock
['is_separate_payment']) {
244 $form->_values
['is_recur'] = $cachedFormValue;
245 $paymentParams['is_recur'] = $cachedParamValue;
248 $paymentParams['contributionID'] = $contribution->id
;
249 $paymentParams['contributionTypeID'] = $contribution->financial_type_id
;
250 $paymentParams['contributionPageID'] = $contribution->contribution_page_id
;
252 if ($form->_values
['is_recur'] && $contribution->contribution_recur_id
) {
253 $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id
;
256 if (is_object($payment)) {
257 $result = $payment->doDirectPayment($paymentParams);
260 CRM_Core_Error
::fatal($paymentObjError);
264 if ($component == 'membership') {
265 $membershipResult = array();
268 if (is_a($result, 'CRM_Core_Error')) {
269 //make sure to cleanup db for recurring case.
270 if (!empty($paymentParams['contributionID'])) {
271 CRM_Contribute_BAO_Contribution
::deleteContribution($paymentParams['contributionID']);
273 if (!empty($paymentParams['contributionRecurID'])) {
274 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($paymentParams['contributionRecurID']);
277 if ($component !== 'membership') {
278 CRM_Core_Error
::displaySessionError($result);
279 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact',
280 "_qf_Main_display=true&qfKey={$form->_params['qfKey']}"
283 $membershipResult[1] = $result;
285 elseif ($result ||
($form->_amount
== 0.0 && !$form->_params
['is_pay_later'])) {
287 $form->_params
= array_merge($form->_params
, $result);
289 $form->_params
['receive_date'] = $now;
290 $form->set('params', $form->_params
);
291 $form->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $result));
292 $form->assign('receive_date',
293 CRM_Utils_Date
::mysqlToIso($form->_params
['receive_date'])
296 // result has all the stuff we need
297 // lets archive it to a financial transaction
298 if ($contributionType->is_deductible
) {
299 $form->assign('is_deductible', TRUE);
300 $form->set('is_deductible', TRUE);
303 if (isset($paymentParams['contribution_source'])) {
304 $form->_params
['source'] = $paymentParams['contribution_source'];
307 // check if pending was set to true by payment processor
309 if (!empty($form->_params
['contribution_status_pending'])) {
312 if (!(!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct')) {
313 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution($form,
314 $form->_params
, $result,
315 $contactID, $contributionType,
321 $form->postProcessPremium($premiumParams, $contribution);
323 $membershipResult[1] = $contribution;
326 if ($component == 'membership') {
327 return $membershipResult;
330 //Do not send an email if Recurring contribution is done via Direct Mode
331 //We will send email once the IPN is received.
332 if (!empty($paymentParams['is_recur']) && $form->_contributeMode
== 'direct') {
336 // get the price set values for receipt.
337 if ($form->_priceSetId
&& $form->_lineItem
) {
338 $form->_values
['lineItem'] = $form->_lineItem
;
339 $form->_values
['priceSetID'] = $form->_priceSetId
;
342 // finally send an email receipt
344 $form->_values
['contribution_id'] = $contribution->id
;
345 CRM_Contribute_BAO_ContributionPage
::sendMail($contactID,
346 $form->_values
, $contribution->is_test
,
353 * Function to get the contribution details by month
356 * @param int $param year
358 * @return array associated array
363 static function contributionChartMonthly($param) {
365 $param = array(1 => array($param, 'Integer'));
369 $param = array(1 => array($param, 'Integer'));
373 SELECT sum(contrib.total_amount) AS ctAmt,
374 MONTH( contrib.receive_date) AS contribMonth
375 FROM civicrm_contribution AS contrib
376 INNER JOIN civicrm_contact AS contact ON ( contact.id = contrib.contact_id )
377 WHERE contrib.contact_id = contact.id
378 AND ( contrib.is_test = 0 OR contrib.is_test IS NULL )
379 AND contrib.contribution_status_id = 1
380 AND date_format(contrib.receive_date,'%Y') = %1
381 AND contact.is_deleted = 0
382 GROUP BY contribMonth
383 ORDER BY month(contrib.receive_date)";
385 $dao = CRM_Core_DAO
::executeQuery($query, $param);
388 while ($dao->fetch()) {
389 if ($dao->contribMonth
) {
390 $params['By Month'][$dao->contribMonth
] = $dao->ctAmt
;
397 * Function to get the contribution details by year
399 * @return array associated array
404 static function contributionChartYearly() {
405 $config = CRM_Core_Config
::singleton();
406 $yearClause = "year(contrib.receive_date) as contribYear";
407 if (!empty($config->fiscalYearStart
) && ($config->fiscalYearStart
['M'] != 1 ||
$config->fiscalYearStart
['d'] != 1)) {
409 WHEN (MONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['M'] . "
410 && DAYOFMONTH(contrib.receive_date)>= " . $config->fiscalYearStart
['d'] . " )
412 concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
414 concat(YEAR(contrib.receive_date)-1,'-', YEAR(contrib.receive_date))
419 SELECT sum(contrib.total_amount) AS ctAmt,
421 FROM civicrm_contribution AS contrib
422 INNER JOIN civicrm_contact contact ON ( contact.id = contrib.contact_id )
423 WHERE ( contrib.is_test = 0 OR contrib.is_test IS NULL )
424 AND contrib.contribution_status_id = 1
425 AND contact.is_deleted = 0
427 ORDER BY contribYear";
428 $dao = CRM_Core_DAO
::executeQuery($query);
431 while ($dao->fetch()) {
432 if (!empty($dao->contribYear
)) {
433 $params['By Year'][$dao->contribYear
] = $dao->ctAmt
;
444 static function createCMSUser(&$params, $contactID, $mail) {
445 // lets ensure we only create one CMS user
446 static $created = FALSE;
453 if (!empty($params['cms_create_account'])) {
454 $params['contactID'] = $contactID;
455 if (!CRM_Core_BAO_CMSUser
::create($params, $mail)) {
456 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
463 * @param string $type
467 static function _fillCommonParams(&$params, $type = 'paypal') {
468 if (array_key_exists('transaction', $params)) {
469 $transaction = &$params['transaction'];
472 $transaction = &$params;
475 $params['contact_type'] = 'Individual';
477 $billingLocTypeId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
478 if (!$billingLocTypeId) {
479 $billingLocTypeId = 1;
481 if (!CRM_Utils_System
::isNull($params['address'])) {
482 $params['address'][1]['is_primary'] = 1;
483 $params['address'][1]['location_type_id'] = $billingLocTypeId;
485 if (!CRM_Utils_System
::isNull($params['email'])) {
486 $params['email'] = array(
487 1 => array('email' => $params['email'],
488 'location_type_id' => $billingLocTypeId,
492 if (isset($transaction['trxn_id'])) {
493 // set error message if transaction has already been processed.
494 $contribution = new CRM_Contribute_DAO_Contribution();
495 $contribution->trxn_id
= $transaction['trxn_id'];
496 if ($contribution->find(TRUE)) {
497 $params['error'][] = ts('transaction already processed.');
501 // generate a new transaction id, if not already exist
502 $transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
505 if (!isset( $transaction['financial_type_id'])) {
506 $contributionTypes = array_keys(CRM_Contribute_PseudoConstant
::financialType());
507 $transaction['financial_type_id'] = $contributionTypes[0];
510 if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
511 $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array
::value('fee_amount', $transaction, 0);
514 if (!isset($transaction['invoice_id'])) {
515 $transaction['invoice_id'] = $transaction['trxn_id'];
518 $source = ts('ContributionProcessor: %1 API',
519 array(1 => ucfirst($type))
521 if (isset($transaction['source'])) {
522 $transaction['source'] = $source . ':: ' . $transaction['source'];
525 $transaction['source'] = $source;
534 * @param string $type
535 * @param bool $category
539 static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE) {
540 $type = strtolower($type);
542 if (!in_array($type, array(
543 'paypal', 'google', 'csv'))) {
544 // return the params as is
547 $params = $transaction = array();
549 if ($type == 'paypal') {
550 foreach ($apiParams as $detail => $val) {
551 if (isset($mapper['contact'][$detail])) {
552 $params[$mapper['contact'][$detail]] = $val;
554 elseif (isset($mapper['location'][$detail])) {
555 $params['address'][1][$mapper['location'][$detail]] = $val;
557 elseif (isset($mapper['transaction'][$detail])) {
560 // Sadly, PayPal seems to send two distinct data elements in a single field,
561 // so we break them out here. This is somewhat ugly and tragic.
568 list($frequency_interval, $frequency_unit) = explode(' ', $val);
569 $transaction['frequency_interval'] = $frequency_interval;
570 $transaction['frequency_unit'] = $freqUnits[$frequency_unit];
573 case 'subscriptiondate':
575 // PayPal dates are in ISO-8601 format. We need a format that
577 $unix_timestamp = strtotime($val);
578 $transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
585 $val = "[PayPal_field:{$detail}] {$val}";
586 $transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ?
$transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
591 $transaction[$mapper['transaction'][$detail]] = $val;
596 if (!empty($transaction) && $category) {
597 $params['transaction'] = $transaction;
600 $params +
= $transaction;
603 self
::_fillCommonParams($params, $type);
608 if ($type == 'csv') {
609 $header = $apiParams['header'];
610 unset($apiParams['header']);
611 foreach ($apiParams as $key => $val) {
612 if (isset($mapper['contact'][$header[$key]])) {
613 $params[$mapper['contact'][$header[$key]]] = $val;
615 elseif (isset($mapper['location'][$header[$key]])) {
616 $params['address'][1][$mapper['location'][$header[$key]]] = $val;
618 elseif (isset($mapper['transaction'][$header[$key]])) {
619 $transaction[$mapper['transaction'][$header[$key]]] = $val;
622 $params[$header[$key]] = $val;
626 if (!empty($transaction) && $category) {
627 $params['transaction'] = $transaction;
630 $params +
= $transaction;
633 self
::_fillCommonParams($params, $type);
638 if ($type == 'google') {
639 // return if response smell invalid
640 if (!array_key_exists('risk-information-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
643 $riskInfo = &$apiParams[1][$apiParams[0]]['notifications']['risk-information-notification'];
645 if (array_key_exists('new-order-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
646 $newOrder = &$apiParams[1][$apiParams[0]]['notifications']['new-order-notification'];
649 if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
650 foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
651 if (!empty($mapper['location'][$field])) {
652 $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
654 elseif (!empty($mapper['contact'][$field])) {
655 if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
656 foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
657 $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
661 $params[$mapper['contact'][$field]] = $info['VALUE'];
664 elseif (!empty($mapper['transaction'][$field])) {
665 $transaction[$mapper['transaction'][$field]] = $info['VALUE'];
669 // Response is an huge array. Lets pickup only those which we ineterested in
670 // using a local mapper, rather than traversing the entire array.
671 $localMapper = array(
672 'google-order-number' => $riskInfo['google-order-number']['VALUE'],
673 'total-charge-amount' => $apiParams[2]['total-charge-amount']['VALUE'],
674 'currency' => $apiParams[2]['total-charge-amount']['currency'],
675 'item-name' => $newOrder['shopping-cart']['items']['item']['item-name']['VALUE'],
676 'timestamp' => $apiParams[2]['timestamp']['VALUE'],
678 if (array_key_exists('latest-charge-fee', $apiParams[2])) {
679 $localMapper['latest-charge-fee'] = $apiParams[2]['latest-charge-fee']['total']['VALUE'];
680 $localMapper['net-amount'] = $localMapper['total-charge-amount'] - $localMapper['latest-charge-fee'];
683 // This is a subscription (recurring) donation.
684 if (array_key_exists('subscription', $newOrder['shopping-cart']['items']['item'])) {
685 $subscription = $newOrder['shopping-cart']['items']['item']['subscription'];
686 $localMapper['amount'] = $newOrder['order-total']['VALUE'];
687 $localMapper['times'] = $subscription['payments']['subscription-payment']['times'];
688 // Convert Google's period to one compatible with the CiviCRM db field.
692 'MONHTLY' => 'month',
695 $localMapper['period'] = $freqUnits[$subscription['period']];
696 // Unlike PayPal, Google has no concept of freq. interval, it is always 1.
697 $localMapper['frequency_interval'] = '1';
698 // Google Checkout dates are in ISO-8601 format. We need a format that
700 $unix_timestamp = strtotime($localMapper['timestamp']);
701 $mysql_date = date('YmdHis', $unix_timestamp);
702 $localMapper['modified_date'] = $mysql_date;
703 $localMapper['start_date'] = $mysql_date;
704 // This is PayPal's nomenclature, but just use it for Google as well since
705 // we act on the value of trxn_type in processAPIContribution().
706 $localMapper['trxn_type'] = 'subscrpayment';
709 foreach ($localMapper as $localKey => $localVal) {
710 if (!empty($mapper['transaction'][$localKey])) {
711 $transaction[$mapper['transaction'][$localKey]] = $localVal;
715 if (empty($params) && empty($transaction)) {
719 if (!empty($transaction) && $category) {
720 $params['transaction'] = $transaction;
723 $params +
= $transaction;
726 self
::_fillCommonParams($params, $type);
737 static function processAPIContribution($params) {
738 if (empty($params) ||
array_key_exists('error', $params)) {
742 // add contact using dedupe rule
743 $dedupeParams = CRM_Dedupe_Finder
::formatParams($params, 'Individual');
744 $dedupeParams['check_permission'] = FALSE;
745 $dupeIds = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
746 // if we find more than one contact, use the first one
747 if (!empty($dupeIds[0])) {
748 $params['contact_id'] = $dupeIds[0];
750 $contact = CRM_Contact_BAO_Contact
::create($params);
755 // only pass transaction params to contribution::create, if available
756 if (array_key_exists('transaction', $params)) {
757 $params = $params['transaction'];
758 $params['contact_id'] = $contact->id
;
761 // handle contribution custom data
762 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
765 CRM_Utils_Array
::value('financial_type_id',
769 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
771 CRM_Utils_Array
::value('id', $params, NULL),
774 // create contribution
776 // if this is a recurring contribution then process it first
777 if ($params['trxn_type'] == 'subscrpayment') {
778 // see if a recurring record already exists
779 $recurring = new CRM_Contribute_BAO_ContributionRecur
;
780 $recurring->processor_id
= $params['processor_id'];
781 if (!$recurring->find(TRUE)) {
782 $recurring = new CRM_Contribute_BAO_ContributionRecur
;
783 $recurring->invoice_id
= $params['invoice_id'];
784 $recurring->find(TRUE);
787 // This is the same thing the CiviCRM IPN handler does to handle
788 // subsequent recurring payments to avoid duplicate contribution
789 // errors due to invoice ID. See:
790 // ./CRM/Core/Payment/PayPalIPN.php:200
791 if ($recurring->id
) {
792 $params['invoice_id'] = md5(uniqid(rand(), TRUE));
795 $recurring->copyValues($params);
797 if (is_a($recurring, 'CRM_Core_Error')) {
801 $params['contribution_recur_id'] = $recurring->id
;
805 $contribution = &CRM_Contribute_BAO_Contribution
::create($params,
806 CRM_Core_DAO
::$_nullArray
808 if (!$contribution->id
) {
820 static function getFirstLastDetails($contactID) {
827 if (!isset($_cache[$contactID])) {
829 SELECT total_amount, receive_date
830 FROM civicrm_contribution c
831 WHERE contact_id = %1
832 ORDER BY receive_date ASC
835 $params = array(1 => array($contactID, 'Integer'));
837 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
843 $details['first'] = array(
844 'total_amount' => $dao->total_amount
,
845 'receive_date' => $dao->receive_date
,
849 // flip asc and desc to get the last query
850 $sql = str_replace('ASC', 'DESC', $sql);
851 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
853 $details['last'] = array(
854 'total_amount' => $dao->total_amount
,
855 'receive_date' => $dao->receive_date
,
859 $_cache[$contactID] = $details;
861 return $_cache[$contactID];