Merge pull request #7959 from JMAConsulting/CRM-18163
[civicrm-core.git] / CRM / Report / Form / Contribute / Bookkeeping.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35 class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
36 protected $_addressField = FALSE;
37
38 protected $_emailField = FALSE;
39
40 protected $_summary = NULL;
41
42 protected $_customGroupExtends = array(
43 'Contact',
44 'Individual',
45 'Contribution',
46 'Membership',
47 );
48
49 /**
50 */
51 public function __construct() {
52 $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
53 $this->_columns = array(
54 'civicrm_contact' => array(
55 'dao' => 'CRM_Contact_DAO_Contact',
56 'fields' => array(
57 'sort_name' => array(
58 'title' => ts('Contact Name'),
59 'required' => TRUE,
60 'no_repeat' => TRUE,
61 ),
62 'first_name' => array(
63 'title' => ts('First Name'),
64 ),
65 'middle_name' => array(
66 'title' => ts('Middle Name'),
67 ),
68 'last_name' => array(
69 'title' => ts('Last Name'),
70 ),
71 'id' => array(
72 'no_display' => TRUE,
73 'required' => TRUE,
74 ),
75 'gender_id' => array(
76 'title' => ts('Gender'),
77 ),
78 'birth_date' => array(
79 'title' => ts('Birth Date'),
80 ),
81 'age' => array(
82 'title' => ts('Age'),
83 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
84 ),
85 'contact_type' => array(
86 'title' => ts('Contact Type'),
87 ),
88 'contact_sub_type' => array(
89 'title' => ts('Contact Subtype'),
90 ),
91 ),
92 'grouping' => 'contact-fields',
93 'order_bys' => array(
94 'sort_name' => array(
95 'title' => ts('Last Name, First Name'),
96 'default' => '1',
97 'default_weight' => '0',
98 'default_order' => 'ASC',
99 ),
100 'first_name' => array(
101 'name' => 'first_name',
102 'title' => ts('First Name'),
103 ),
104 'gender_id' => array(
105 'name' => 'gender_id',
106 'title' => ts('Gender'),
107 ),
108 'birth_date' => array(
109 'name' => 'birth_date',
110 'title' => ts('Birth Date'),
111 ),
112 'contact_type' => array(
113 'title' => ts('Contact Type'),
114 ),
115 'contact_sub_type' => array(
116 'title' => ts('Contact Subtype'),
117 ),
118 ),
119 'filters' => array(
120 'sort_name' => array(
121 'title' => ts('Contact Name'),
122 'operator' => 'like',
123 ),
124 'id' => array(
125 'title' => ts('Contact ID'),
126 'no_display' => TRUE,
127 ),
128 'gender_id' => array(
129 'title' => ts('Gender'),
130 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
131 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'),
132 ),
133 'birth_date' => array(
134 'title' => ts('Birth Date'),
135 'operatorType' => CRM_Report_Form::OP_DATE,
136 ),
137 'contact_type' => array(
138 'title' => ts('Contact Type'),
139 ),
140 'contact_sub_type' => array(
141 'title' => ts('Contact Subtype'),
142 ),
143 ),
144 ),
145 'civicrm_membership' => array(
146 'dao' => 'CRM_Member_DAO_Membership',
147 'fields' => array(
148 'id' => array(
149 'title' => ts('Membership #'),
150 'no_display' => TRUE,
151 'required' => TRUE,
152 ),
153 ),
154 ),
155 'civicrm_financial_account' => array(
156 'dao' => 'CRM_Financial_DAO_FinancialAccount',
157 'fields' => array(
158 'debit_accounting_code' => array(
159 'title' => ts('Financial Account Code - Debit'),
160 'name' => 'accounting_code',
161 'alias' => 'financial_account_civireport_debit',
162 'default' => TRUE,
163 ),
164 'credit_accounting_code' => array(
165 'title' => ts('Financial Account Code - Credit'),
166 'name' => 'accounting_code',
167 'alias' => 'financial_account_civireport_credit',
168 'default' => TRUE,
169 ),
170 'debit_name' => array(
171 'title' => ts('Financial Account Name - Debit'),
172 'name' => 'name',
173 'alias' => 'financial_account_civireport_debit',
174 'default' => TRUE,
175 ),
176 'credit_name' => array(
177 'title' => ts('Financial Account Name - Credit'),
178 'name' => 'name',
179 'alias' => 'financial_account_civireport_credit',
180 'default' => TRUE,
181 ),
182 ),
183 'filters' => array(
184 'debit_accounting_code' => array(
185 'title' => ts('Financial Account Code - Debit'),
186 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
187 'options' => CRM_Contribute_PseudoConstant::financialAccount(NULL, NULL, 'accounting_code', 'accounting_code'),
188 'name' => 'accounting_code',
189 'alias' => 'financial_account_civireport_debit',
190 ),
191 'credit_accounting_code' => array(
192 'title' => ts('Financial Account Code - Credit'),
193 'type' => CRM_Utils_Type::T_INT,
194 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
195 'options' => CRM_Contribute_PseudoConstant::financialAccount(NULL, NULL, 'accounting_code', 'accounting_code'),
196 ),
197 'debit_name' => array(
198 'title' => ts('Financial Account Name - Debit'),
199 'type' => CRM_Utils_Type::T_STRING,
200 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
201 'options' => CRM_Contribute_PseudoConstant::financialAccount(),
202 'name' => 'id',
203 'alias' => 'financial_account_civireport_debit',
204 ),
205 'credit_name' => array(
206 'title' => ts('Financial Account Name - Credit'),
207 'type' => CRM_Utils_Type::T_STRING,
208 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
209 'options' => CRM_Contribute_PseudoConstant::financialAccount(),
210 ),
211 ),
212 ),
213 'civicrm_line_item' => array(
214 'dao' => 'CRM_Price_DAO_LineItem',
215 'fields' => array(
216 'financial_type_id' => array(
217 'title' => ts('Financial Type'),
218 'default' => TRUE,
219 ),
220 ),
221 'filters' => array(
222 'financial_type_id' => array(
223 'title' => ts('Financial Type'),
224 'type' => CRM_Utils_Type::T_INT,
225 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
226 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(),
227 ),
228 ),
229 'order_bys' => array(
230 'financial_type_id' => array('title' => ts('Financial Type')),
231 ),
232 ),
233 'civicrm_batch' => array(
234 'dao' => 'CRM_Batch_DAO_Batch',
235 'fields' => array(
236 'title' => array(
237 'title' => ts('Batch Title'),
238 'alias' => 'batch',
239 'default' => FALSE,
240 ),
241 'name' => array(
242 'title' => ts('Batch Name'),
243 'alias' => 'batch',
244 'default' => TRUE,
245 ),
246 ),
247 ),
248 'civicrm_contribution' => array(
249 'dao' => 'CRM_Contribute_DAO_Contribution',
250 'fields' => array(
251 'receive_date' => array(
252 'default' => TRUE,
253 ),
254 'invoice_id' => array(
255 'title' => ts('Invoice ID'),
256 'default' => TRUE,
257 ),
258 'contribution_status_id' => array(
259 'title' => ts('Contribution Status'),
260 'default' => TRUE,
261 ),
262 'id' => array(
263 'title' => ts('Contribution #'),
264 'default' => TRUE,
265 ),
266 ),
267 'filters' => array(
268 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE),
269 'contribution_status_id' => array(
270 'title' => ts('Contribution Status'),
271 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
272 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
273 'default' => array(1),
274 ),
275 ),
276 'order_bys' => array(
277 'contribution_id' => array('title' => ts('Contribution #')),
278 'contribution_status_id' => array('title' => ts('Contribution Status')),
279 ),
280 'grouping' => 'contri-fields',
281 ),
282 'civicrm_financial_trxn' => array(
283 'dao' => 'CRM_Financial_DAO_FinancialTrxn',
284 'fields' => array(
285 'check_number' => array(
286 'title' => ts('Cheque #'),
287 'default' => TRUE,
288 ),
289 'payment_instrument_id' => array(
290 'title' => ts('Payment Method'),
291 'default' => TRUE,
292 ),
293 'currency' => array(
294 'required' => TRUE,
295 'no_display' => TRUE,
296 ),
297 'trxn_date' => array(
298 'title' => ts('Transaction Date'),
299 'default' => TRUE,
300 'type' => CRM_Utils_Type::T_DATE,
301 ),
302 'trxn_id' => array(
303 'title' => ts('Trans #'),
304 'default' => TRUE,
305 ),
306 ),
307 'filters' => array(
308 'payment_instrument_id' => array(
309 'title' => ts('Payment Method'),
310 'type' => CRM_Utils_Type::T_INT,
311 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
312 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
313 ),
314 'currency' => array(
315 'title' => 'Currency',
316 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
317 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
318 'default' => NULL,
319 'type' => CRM_Utils_Type::T_STRING,
320 ),
321 'trxn_date' => array(
322 'title' => ts('Transaction Date'),
323 'operatorType' => CRM_Report_Form::OP_DATE,
324 'type' => CRM_Utils_Type::T_DATE,
325 ),
326 ),
327 'order_bys' => array(
328 'payment_instrument_id' => array('title' => ts('Payment Method')),
329 ),
330 ),
331 'civicrm_entity_financial_trxn' => array(
332 'dao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
333 'fields' => array(
334 'amount' => array(
335 'title' => ts('Amount'),
336 'default' => TRUE,
337 'type' => CRM_Utils_Type::T_STRING,
338 ),
339 ),
340 'filters' => array(
341 'amount' => array('title' => ts('Amount')),
342 ),
343 ),
344 );
345
346 $this->_groupFilter = TRUE;
347 $this->_tagFilter = TRUE;
348 parent::__construct();
349 }
350
351 public function preProcess() {
352 parent::preProcess();
353 }
354
355 public function select() {
356 $select = array();
357
358 $this->_columnHeaders = array();
359 foreach ($this->_columns as $tableName => $table) {
360 if (array_key_exists('fields', $table)) {
361 foreach ($table['fields'] as $fieldName => $field) {
362 if (!empty($field['required']) ||
363 !empty($this->_params['fields'][$fieldName])
364 ) {
365 switch ($fieldName) {
366 case 'credit_accounting_code':
367 $select[] = " CASE
368 WHEN {$this->_aliases['civicrm_financial_trxn']}.from_financial_account_id IS NOT NULL
369 THEN {$this->_aliases['civicrm_financial_account']}_credit_1.accounting_code
370 ELSE {$this->_aliases['civicrm_financial_account']}_credit_2.accounting_code
371 END AS civicrm_financial_account_credit_accounting_code ";
372 break;
373
374 case 'amount':
375 $select[] = " CASE
376 WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
377 THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
378 ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
379 END AS civicrm_entity_financial_trxn_amount ";
380 break;
381
382 case 'credit_name':
383 $select[] = " CASE
384 WHEN {$this->_aliases['civicrm_financial_trxn']}.from_financial_account_id IS NOT NULL
385 THEN {$this->_aliases['civicrm_financial_account']}_credit_1.name
386 ELSE {$this->_aliases['civicrm_financial_account']}_credit_2.name
387 END AS civicrm_financial_account_credit_name ";
388 break;
389
390 default:
391 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
392 break;
393 }
394 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
395 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
396 }
397 }
398 }
399 }
400
401 $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
402 }
403
404 public function from() {
405 $this->_from = NULL;
406
407 $this->_from = "FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
408 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
409 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND
410 {$this->_aliases['civicrm_contribution']}.is_test = 0
411 LEFT JOIN civicrm_membership_payment payment
412 ON ( {$this->_aliases['civicrm_contribution']}.id = payment.contribution_id )
413 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
414 ON payment.membership_id = {$this->_aliases['civicrm_membership']}.id
415 LEFT JOIN civicrm_entity_financial_trxn {$this->_aliases['civicrm_entity_financial_trxn']}
416 ON ({$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_entity_financial_trxn']}.entity_id AND
417 {$this->_aliases['civicrm_entity_financial_trxn']}.entity_table = 'civicrm_contribution')
418 LEFT JOIN civicrm_financial_trxn {$this->_aliases['civicrm_financial_trxn']}
419 ON {$this->_aliases['civicrm_financial_trxn']}.id = {$this->_aliases['civicrm_entity_financial_trxn']}.financial_trxn_id
420 LEFT JOIN civicrm_financial_account {$this->_aliases['civicrm_financial_account']}_debit
421 ON {$this->_aliases['civicrm_financial_trxn']}.to_financial_account_id = {$this->_aliases['civicrm_financial_account']}_debit.id
422 LEFT JOIN civicrm_financial_account {$this->_aliases['civicrm_financial_account']}_credit_1
423 ON {$this->_aliases['civicrm_financial_trxn']}.from_financial_account_id = {$this->_aliases['civicrm_financial_account']}_credit_1.id
424 LEFT JOIN civicrm_entity_financial_trxn {$this->_aliases['civicrm_entity_financial_trxn']}_item
425 ON ({$this->_aliases['civicrm_financial_trxn']}.id = {$this->_aliases['civicrm_entity_financial_trxn']}_item.financial_trxn_id AND
426 {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_table = 'civicrm_financial_item')
427 LEFT JOIN civicrm_financial_item fitem
428 ON fitem.id = {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id
429 LEFT JOIN civicrm_financial_account {$this->_aliases['civicrm_financial_account']}_credit_2
430 ON fitem.financial_account_id = {$this->_aliases['civicrm_financial_account']}_credit_2.id
431 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
432 ON fitem.entity_id = {$this->_aliases['civicrm_line_item']}.id AND fitem.entity_table = 'civicrm_line_item' ";
433 if ($this->isTableSelected('civicrm_batch')) {
434 $this->_from .= "LEFT JOIN civicrm_entity_batch ent_batch
435 ON {$this->_aliases['civicrm_financial_trxn']}.id = ent_batch.entity_id AND ent_batch.entity_table = 'civicrm_financial_trxn'
436 LEFT JOIN civicrm_batch batch
437 ON ent_batch.batch_id = batch.id";
438 }
439
440 $this->getPermissionedFTQuery($this, "civicrm_line_item_1");
441 }
442
443 public function orderBy() {
444 parent::orderBy();
445
446 // please note this will just add the order-by columns to select query, and not display in column-headers.
447 // This is a solution to not throw fatal errors when there is a column in order-by, not present in select/display columns.
448 foreach ($this->_orderByFields as $orderBy) {
449 if (!array_key_exists($orderBy['name'], $this->_params['fields']) &&
450 empty($orderBy['section'])
451 ) {
452 $this->_select .= ", {$orderBy['dbAlias']} as {$orderBy['tplField']}";
453 }
454 }
455 }
456
457 public function where() {
458 foreach ($this->_columns as $tableName => $table) {
459 if (array_key_exists('filters', $table)) {
460 foreach ($table['filters'] as $fieldName => $field) {
461 $clause = NULL;
462 if ($fieldName == 'credit_accounting_code') {
463 $field['dbAlias'] = "CASE
464 WHEN financial_trxn_civireport.from_financial_account_id IS NOT NULL
465 THEN financial_account_civireport_credit_1.accounting_code
466 ELSE financial_account_civireport_credit_2.accounting_code
467 END";
468 }
469 elseif ($fieldName == 'credit_name') {
470 $field['dbAlias'] = "CASE
471 WHEN financial_trxn_civireport.from_financial_account_id IS NOT NULL
472 THEN financial_account_civireport_credit_1.id
473 ELSE financial_account_civireport_credit_2.id
474 END";
475 }
476 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
477 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
478 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
479 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
480
481 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
482 }
483 else {
484 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
485 if ($op) {
486 $clause = $this->whereClause($field,
487 $op,
488 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
489 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
490 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
491 );
492 }
493 }
494 if (!empty($clause)) {
495 $clauses[] = $clause;
496 }
497 }
498 }
499 }
500 if (empty($clauses)) {
501 $this->_where = 'WHERE ( 1 )';
502 }
503 else {
504 $this->_where = 'WHERE ' . implode(' AND ', $clauses);
505 }
506 }
507
508 public function postProcess() {
509 // get the acl clauses built before we assemble the query
510 $this->buildACLClause($this->_aliases['civicrm_contact']);
511 parent::postProcess();
512 }
513
514 public function groupBy() {
515 $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_entity_financial_trxn']}.id, {$this->_aliases['civicrm_line_item']}.id ";
516 }
517
518 /**
519 * @param $rows
520 *
521 * @return array
522 */
523 public function statistics(&$rows) {
524 $statistics = parent::statistics($rows);
525 $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_contribution');
526 $select = "SELECT {$this->_aliases['civicrm_contribution']}.id, {$this->_aliases['civicrm_entity_financial_trxn']}.id as trxnID, {$this->_aliases['civicrm_contribution']}.currency,
527 CASE
528 WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
529 THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
530 ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
531 END as amount
532 ";
533
534 $tempQuery = "CREATE TEMPORARY TABLE {$tempTableName} CHARACTER SET utf8 COLLATE utf8_unicode_ci AS
535 {$select} {$this->_from} {$this->_where} {$this->_groupBy} ";
536 CRM_Core_DAO::executeQuery($tempQuery);
537
538 $sql = "SELECT COUNT(trxnID) as count, SUM(amount) as amount, currency
539 FROM {$tempTableName}
540 GROUP BY currency";
541 $dao = CRM_Core_DAO::executeQuery($sql);
542 $amount = $avg = array();
543 while ($dao->fetch()) {
544 $amount[] = CRM_Utils_Money::format($dao->amount, $dao->currency);
545 $avg[] = CRM_Utils_Money::format(round(($dao->amount /
546 $dao->count), 2), $dao->currency);
547 }
548
549 $statistics['counts']['amount'] = array(
550 'value' => implode(', ', $amount),
551 'title' => 'Total Amount',
552 'type' => CRM_Utils_Type::T_STRING,
553 );
554 $statistics['counts']['avg'] = array(
555 'value' => implode(', ', $avg),
556 'title' => 'Average',
557 'type' => CRM_Utils_Type::T_STRING,
558 );
559 return $statistics;
560 }
561
562 /**
563 * Alter display of rows.
564 *
565 * Iterate through the rows retrieved via SQL and make changes for display purposes,
566 * such as rendering contacts as links.
567 *
568 * @param array $rows
569 * Rows generated by SQL, with an array for each row.
570 */
571 public function alterDisplay(&$rows) {
572 $contributionTypes = CRM_Contribute_PseudoConstant::financialType();
573 $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
574 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
575 foreach ($rows as $rowNum => $row) {
576 // convert display name to links
577 if (array_key_exists('civicrm_contact_sort_name', $row) &&
578 !empty($rows[$rowNum]['civicrm_contact_sort_name']) &&
579 array_key_exists('civicrm_contact_id', $row)
580 ) {
581 $url = CRM_Utils_System::url('civicrm/contact/view',
582 'reset=1&cid=' . $row['civicrm_contact_id'],
583 $this->_absoluteUrl
584 );
585 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
586 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Summary for this Contact.');
587 }
588
589 // handle contribution status id
590 if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
591 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
592 }
593
594 // handle payment instrument id
595 if ($value = CRM_Utils_Array::value('civicrm_financial_trxn_payment_instrument_id', $row)) {
596 $rows[$rowNum]['civicrm_financial_trxn_payment_instrument_id'] = $paymentInstruments[$value];
597 }
598
599 // handle financial type id
600 if ($value = CRM_Utils_Array::value('civicrm_line_item_financial_type_id', $row)) {
601 $rows[$rowNum]['civicrm_line_item_financial_type_id'] = $contributionTypes[$value];
602 }
603 if ($value = CRM_Utils_Array::value('civicrm_entity_financial_trxn_amount', $row)) {
604 $rows[$rowNum]['civicrm_entity_financial_trxn_amount'] = CRM_Utils_Money::format($rows[$rowNum]['civicrm_entity_financial_trxn_amount'], $rows[$rowNum]['civicrm_financial_trxn_currency']);
605 }
606
607 //handle gender
608 if (array_key_exists('civicrm_contact_gender_id', $row)) {
609 if ($value = $row['civicrm_contact_gender_id']) {
610 $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
611 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
612 }
613 $entryFound = TRUE;
614 }
615
616 // display birthday in the configured custom format
617 if (array_key_exists('civicrm_contact_birth_date', $row)) {
618 $birthDate = $row['civicrm_contact_birth_date'];
619 if ($birthDate) {
620 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d');
621 }
622 $entryFound = TRUE;
623 }
624
625 }
626 }
627
628 }