Merge pull request #14891 from eileenmcnaughton/saved_search
[civicrm-core.git] / CRM / Contribute / DAO / Contribution.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC (c) 2004-2019
6 *
7 * Generated from xml/schema/CRM/Contribute/Contribution.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:b4e84298d9ba23d3b2fae0768fc5cb58)
10 */
11
12 /**
13 * Database access object for the Contribution entity.
14 */
15 class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
16
17 /**
18 * Static instance to hold the table name.
19 *
20 * @var string
21 */
22 public static $_tableName = 'civicrm_contribution';
23
24 /**
25 * Should CiviCRM log any modifications to this table in the civicrm_log table.
26 *
27 * @var bool
28 */
29 public static $_log = TRUE;
30
31 /**
32 * Contribution ID
33 *
34 * @var int
35 */
36 public $id;
37
38 /**
39 * FK to Contact ID
40 *
41 * @var int
42 */
43 public $contact_id;
44
45 /**
46 * FK to Financial Type for (total_amount - non_deductible_amount).
47 *
48 * @var int
49 */
50 public $financial_type_id;
51
52 /**
53 * The Contribution Page which triggered this contribution
54 *
55 * @var int
56 */
57 public $contribution_page_id;
58
59 /**
60 * FK to Payment Instrument
61 *
62 * @var int
63 */
64 public $payment_instrument_id;
65
66 /**
67 * Date contribution was received - not necessarily the creation date of the record
68 *
69 * @var datetime
70 */
71 public $receive_date;
72
73 /**
74 * Portion of total amount which is NOT tax deductible. Equal to total_amount for non-deductible financial types.
75 *
76 * @var float
77 */
78 public $non_deductible_amount;
79
80 /**
81 * Total amount of this contribution. Use market value for non-monetary gifts.
82 *
83 * @var float
84 */
85 public $total_amount;
86
87 /**
88 * actual processor fee if known - may be 0.
89 *
90 * @var float
91 */
92 public $fee_amount;
93
94 /**
95 * actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount.
96 *
97 * @var float
98 */
99 public $net_amount;
100
101 /**
102 * unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method
103 *
104 * @var string
105 */
106 public $trxn_id;
107
108 /**
109 * unique invoice id, system generated or passed in
110 *
111 * @var string
112 */
113 public $invoice_id;
114
115 /**
116 * Human readable invoice number
117 *
118 * @var string
119 */
120 public $invoice_number;
121
122 /**
123 * 3 character string, value from config setting or input via user.
124 *
125 * @var string
126 */
127 public $currency;
128
129 /**
130 * when was gift cancelled
131 *
132 * @var datetime
133 */
134 public $cancel_date;
135
136 /**
137 * @var text
138 */
139 public $cancel_reason;
140
141 /**
142 * when (if) receipt was sent. populated automatically for online donations w/ automatic receipting
143 *
144 * @var datetime
145 */
146 public $receipt_date;
147
148 /**
149 * when (if) was donor thanked
150 *
151 * @var datetime
152 */
153 public $thankyou_date;
154
155 /**
156 * Origin of this Contribution.
157 *
158 * @var string
159 */
160 public $source;
161
162 /**
163 * @var text
164 */
165 public $amount_level;
166
167 /**
168 * Conditional foreign key to civicrm_contribution_recur id. Each contribution made in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.
169 *
170 * @var int
171 */
172 public $contribution_recur_id;
173
174 /**
175 * @var bool
176 */
177 public $is_test;
178
179 /**
180 * @var bool
181 */
182 public $is_pay_later;
183
184 /**
185 * @var int
186 */
187 public $contribution_status_id;
188
189 /**
190 * Conditional foreign key to civicrm_address.id. We insert an address record for each contribution when we have associated billing name and address data.
191 *
192 * @var int
193 */
194 public $address_id;
195
196 /**
197 * @var string
198 */
199 public $check_number;
200
201 /**
202 * The campaign for which this contribution has been triggered.
203 *
204 * @var int
205 */
206 public $campaign_id;
207
208 /**
209 * unique credit note id, system generated or passed in
210 *
211 * @var string
212 */
213 public $creditnote_id;
214
215 /**
216 * Total tax amount of this contribution.
217 *
218 * @var float
219 */
220 public $tax_amount;
221
222 /**
223 * Stores the date when revenue should be recognized.
224 *
225 * @var datetime
226 */
227 public $revenue_recognition_date;
228
229 /**
230 * Class constructor.
231 */
232 public function __construct() {
233 $this->__table = 'civicrm_contribution';
234 parent::__construct();
235 }
236
237 /**
238 * Returns foreign keys and entity references.
239 *
240 * @return array
241 * [CRM_Core_Reference_Interface]
242 */
243 public static function getReferenceColumns() {
244 if (!isset(Civi::$statics[__CLASS__]['links'])) {
245 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
246 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
247 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
248 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_page_id', 'civicrm_contribution_page', 'id');
249 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
250 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'address_id', 'civicrm_address', 'id');
251 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
252 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
253 }
254 return Civi::$statics[__CLASS__]['links'];
255 }
256
257 /**
258 * Returns all the column names of this table
259 *
260 * @return array
261 */
262 public static function &fields() {
263 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
264 Civi::$statics[__CLASS__]['fields'] = [
265 'contribution_id' => [
266 'name' => 'id',
267 'type' => CRM_Utils_Type::T_INT,
268 'title' => ts('Contribution ID'),
269 'description' => ts('Contribution ID'),
270 'required' => TRUE,
271 'import' => TRUE,
272 'where' => 'civicrm_contribution.id',
273 'export' => TRUE,
274 'table_name' => 'civicrm_contribution',
275 'entity' => 'Contribution',
276 'bao' => 'CRM_Contribute_BAO_Contribution',
277 'localizable' => 0,
278 ],
279 'contribution_contact_id' => [
280 'name' => 'contact_id',
281 'type' => CRM_Utils_Type::T_INT,
282 'title' => ts('Contact ID'),
283 'description' => ts('FK to Contact ID'),
284 'required' => TRUE,
285 'import' => TRUE,
286 'where' => 'civicrm_contribution.contact_id',
287 'headerPattern' => '/contact(.?id)?/i',
288 'dataPattern' => '/^\d+$/',
289 'export' => TRUE,
290 'table_name' => 'civicrm_contribution',
291 'entity' => 'Contribution',
292 'bao' => 'CRM_Contribute_BAO_Contribution',
293 'localizable' => 0,
294 'FKClassName' => 'CRM_Contact_DAO_Contact',
295 'html' => [
296 'type' => 'EntityRef',
297 ],
298 ],
299 'financial_type_id' => [
300 'name' => 'financial_type_id',
301 'type' => CRM_Utils_Type::T_INT,
302 'title' => ts('Financial Type'),
303 'description' => ts('FK to Financial Type for (total_amount - non_deductible_amount).'),
304 'where' => 'civicrm_contribution.financial_type_id',
305 'export' => TRUE,
306 'table_name' => 'civicrm_contribution',
307 'entity' => 'Contribution',
308 'bao' => 'CRM_Contribute_BAO_Contribution',
309 'localizable' => 0,
310 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
311 'html' => [
312 'type' => 'Select',
313 ],
314 'pseudoconstant' => [
315 'table' => 'civicrm_financial_type',
316 'keyColumn' => 'id',
317 'labelColumn' => 'name',
318 ],
319 ],
320 'contribution_page_id' => [
321 'name' => 'contribution_page_id',
322 'type' => CRM_Utils_Type::T_INT,
323 'title' => ts('Contribution Page ID'),
324 'description' => ts('The Contribution Page which triggered this contribution'),
325 'import' => TRUE,
326 'where' => 'civicrm_contribution.contribution_page_id',
327 'export' => TRUE,
328 'table_name' => 'civicrm_contribution',
329 'entity' => 'Contribution',
330 'bao' => 'CRM_Contribute_BAO_Contribution',
331 'localizable' => 0,
332 'FKClassName' => 'CRM_Contribute_DAO_ContributionPage',
333 'html' => [
334 'type' => 'Select',
335 ],
336 'pseudoconstant' => [
337 'table' => 'civicrm_contribution_page',
338 'keyColumn' => 'id',
339 'labelColumn' => 'title',
340 ],
341 ],
342 'payment_instrument_id' => [
343 'name' => 'payment_instrument_id',
344 'type' => CRM_Utils_Type::T_INT,
345 'title' => ts('Payment Method ID'),
346 'description' => ts('FK to Payment Instrument'),
347 'where' => 'civicrm_contribution.payment_instrument_id',
348 'headerPattern' => '/^payment|(p(ayment\s)?instrument)$/i',
349 'export' => TRUE,
350 'table_name' => 'civicrm_contribution',
351 'entity' => 'Contribution',
352 'bao' => 'CRM_Contribute_BAO_Contribution',
353 'localizable' => 0,
354 'html' => [
355 'type' => 'Select',
356 ],
357 'pseudoconstant' => [
358 'optionGroupName' => 'payment_instrument',
359 'optionEditPath' => 'civicrm/admin/options/payment_instrument',
360 ],
361 ],
362 'receive_date' => [
363 'name' => 'receive_date',
364 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
365 'title' => ts('Date Received'),
366 'description' => ts('Date contribution was received - not necessarily the creation date of the record'),
367 'import' => TRUE,
368 'where' => 'civicrm_contribution.receive_date',
369 'headerPattern' => '/receive(.?date)?/i',
370 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
371 'export' => TRUE,
372 'table_name' => 'civicrm_contribution',
373 'entity' => 'Contribution',
374 'bao' => 'CRM_Contribute_BAO_Contribution',
375 'localizable' => 0,
376 'html' => [
377 'type' => 'Select Date',
378 'formatType' => 'activityDateTime',
379 ],
380 ],
381 'non_deductible_amount' => [
382 'name' => 'non_deductible_amount',
383 'type' => CRM_Utils_Type::T_MONEY,
384 'title' => ts('Non-deductible Amount'),
385 'description' => ts('Portion of total amount which is NOT tax deductible. Equal to total_amount for non-deductible financial types.'),
386 'precision' => [
387 20,
388 2,
389 ],
390 'import' => TRUE,
391 'where' => 'civicrm_contribution.non_deductible_amount',
392 'headerPattern' => '/non?.?deduct/i',
393 'dataPattern' => '/^\d+(\.\d{2})?$/',
394 'export' => TRUE,
395 'default' => '0',
396 'table_name' => 'civicrm_contribution',
397 'entity' => 'Contribution',
398 'bao' => 'CRM_Contribute_BAO_Contribution',
399 'localizable' => 0,
400 'html' => [
401 'type' => 'Text',
402 ],
403 ],
404 'total_amount' => [
405 'name' => 'total_amount',
406 'type' => CRM_Utils_Type::T_MONEY,
407 'title' => ts('Total Amount'),
408 'description' => ts('Total amount of this contribution. Use market value for non-monetary gifts.'),
409 'required' => TRUE,
410 'precision' => [
411 20,
412 2,
413 ],
414 'import' => TRUE,
415 'where' => 'civicrm_contribution.total_amount',
416 'headerPattern' => '/^total|(.?^am(ou)?nt)/i',
417 'dataPattern' => '/^\d+(\.\d{2})?$/',
418 'export' => TRUE,
419 'table_name' => 'civicrm_contribution',
420 'entity' => 'Contribution',
421 'bao' => 'CRM_Contribute_BAO_Contribution',
422 'localizable' => 0,
423 'html' => [
424 'type' => 'Text',
425 ],
426 ],
427 'fee_amount' => [
428 'name' => 'fee_amount',
429 'type' => CRM_Utils_Type::T_MONEY,
430 'title' => ts('Fee Amount'),
431 'description' => ts('actual processor fee if known - may be 0.'),
432 'precision' => [
433 20,
434 2,
435 ],
436 'import' => TRUE,
437 'where' => 'civicrm_contribution.fee_amount',
438 'headerPattern' => '/fee(.?am(ou)?nt)?/i',
439 'dataPattern' => '/^\d+(\.\d{2})?$/',
440 'export' => TRUE,
441 'table_name' => 'civicrm_contribution',
442 'entity' => 'Contribution',
443 'bao' => 'CRM_Contribute_BAO_Contribution',
444 'localizable' => 0,
445 'html' => [
446 'type' => 'Text',
447 ],
448 ],
449 'net_amount' => [
450 'name' => 'net_amount',
451 'type' => CRM_Utils_Type::T_MONEY,
452 'title' => ts('Net Amount'),
453 'description' => ts('actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount.'),
454 'precision' => [
455 20,
456 2,
457 ],
458 'import' => TRUE,
459 'where' => 'civicrm_contribution.net_amount',
460 'headerPattern' => '/net(.?am(ou)?nt)?/i',
461 'dataPattern' => '/^\d+(\.\d{2})?$/',
462 'export' => TRUE,
463 'table_name' => 'civicrm_contribution',
464 'entity' => 'Contribution',
465 'bao' => 'CRM_Contribute_BAO_Contribution',
466 'localizable' => 0,
467 'html' => [
468 'type' => 'Text',
469 ],
470 ],
471 'trxn_id' => [
472 'name' => 'trxn_id',
473 'type' => CRM_Utils_Type::T_STRING,
474 'title' => ts('Transaction ID'),
475 'description' => ts('unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method'),
476 'maxlength' => 255,
477 'size' => CRM_Utils_Type::HUGE,
478 'import' => TRUE,
479 'where' => 'civicrm_contribution.trxn_id',
480 'headerPattern' => '/tr(ansactio|x)n(.?id)?/i',
481 'export' => TRUE,
482 'table_name' => 'civicrm_contribution',
483 'entity' => 'Contribution',
484 'bao' => 'CRM_Contribute_BAO_Contribution',
485 'localizable' => 0,
486 'html' => [
487 'type' => 'Text',
488 ],
489 ],
490 'invoice_id' => [
491 'name' => 'invoice_id',
492 'type' => CRM_Utils_Type::T_STRING,
493 'title' => ts('Invoice Reference'),
494 'description' => ts('unique invoice id, system generated or passed in'),
495 'maxlength' => 255,
496 'size' => CRM_Utils_Type::HUGE,
497 'import' => TRUE,
498 'where' => 'civicrm_contribution.invoice_id',
499 'headerPattern' => '/invoice(.?id)?/i',
500 'export' => TRUE,
501 'table_name' => 'civicrm_contribution',
502 'entity' => 'Contribution',
503 'bao' => 'CRM_Contribute_BAO_Contribution',
504 'localizable' => 0,
505 'html' => [
506 'type' => 'Text',
507 ],
508 ],
509 'invoice_number' => [
510 'name' => 'invoice_number',
511 'type' => CRM_Utils_Type::T_STRING,
512 'title' => ts('Invoice Number'),
513 'description' => ts('Human readable invoice number'),
514 'maxlength' => 255,
515 'size' => CRM_Utils_Type::HUGE,
516 'import' => TRUE,
517 'where' => 'civicrm_contribution.invoice_number',
518 'headerPattern' => '/invoice(.?number)?/i',
519 'export' => TRUE,
520 'table_name' => 'civicrm_contribution',
521 'entity' => 'Contribution',
522 'bao' => 'CRM_Contribute_BAO_Contribution',
523 'localizable' => 0,
524 'html' => [
525 'type' => 'Text',
526 ],
527 ],
528 'currency' => [
529 'name' => 'currency',
530 'type' => CRM_Utils_Type::T_STRING,
531 'title' => ts('Currency'),
532 'description' => ts('3 character string, value from config setting or input via user.'),
533 'maxlength' => 3,
534 'size' => CRM_Utils_Type::FOUR,
535 'import' => TRUE,
536 'where' => 'civicrm_contribution.currency',
537 'headerPattern' => '/cur(rency)?/i',
538 'dataPattern' => '/^[A-Z]{3}$/i',
539 'export' => TRUE,
540 'default' => 'NULL',
541 'table_name' => 'civicrm_contribution',
542 'entity' => 'Contribution',
543 'bao' => 'CRM_Contribute_BAO_Contribution',
544 'localizable' => 0,
545 'html' => [
546 'type' => 'Select',
547 ],
548 'pseudoconstant' => [
549 'table' => 'civicrm_currency',
550 'keyColumn' => 'name',
551 'labelColumn' => 'full_name',
552 'nameColumn' => 'name',
553 'abbrColumn' => 'symbol',
554 ],
555 ],
556 'contribution_cancel_date' => [
557 'name' => 'cancel_date',
558 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
559 'title' => ts('Cancelled / Refunded Date'),
560 'description' => ts('when was gift cancelled'),
561 'import' => TRUE,
562 'where' => 'civicrm_contribution.cancel_date',
563 'headerPattern' => '/cancel(.?date)?/i',
564 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
565 'export' => TRUE,
566 'table_name' => 'civicrm_contribution',
567 'entity' => 'Contribution',
568 'bao' => 'CRM_Contribute_BAO_Contribution',
569 'localizable' => 0,
570 'html' => [
571 'type' => 'Select Date',
572 'formatType' => 'activityDateTime',
573 ],
574 ],
575 'cancel_reason' => [
576 'name' => 'cancel_reason',
577 'type' => CRM_Utils_Type::T_TEXT,
578 'title' => ts('Cancellation / Refund Reason'),
579 'import' => TRUE,
580 'where' => 'civicrm_contribution.cancel_reason',
581 'headerPattern' => '/(cancel.?)?reason/i',
582 'export' => TRUE,
583 'table_name' => 'civicrm_contribution',
584 'entity' => 'Contribution',
585 'bao' => 'CRM_Contribute_BAO_Contribution',
586 'localizable' => 0,
587 'html' => [
588 'type' => 'Text',
589 ],
590 ],
591 'receipt_date' => [
592 'name' => 'receipt_date',
593 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
594 'title' => ts('Receipt Date'),
595 'description' => ts('when (if) receipt was sent. populated automatically for online donations w/ automatic receipting'),
596 'import' => TRUE,
597 'where' => 'civicrm_contribution.receipt_date',
598 'headerPattern' => '/receipt(.?date)?/i',
599 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
600 'export' => TRUE,
601 'table_name' => 'civicrm_contribution',
602 'entity' => 'Contribution',
603 'bao' => 'CRM_Contribute_BAO_Contribution',
604 'localizable' => 0,
605 'html' => [
606 'type' => 'Select Date',
607 'formatType' => 'activityDateTime',
608 ],
609 ],
610 'thankyou_date' => [
611 'name' => 'thankyou_date',
612 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
613 'title' => ts('Thank-you Date'),
614 'description' => ts('when (if) was donor thanked'),
615 'import' => TRUE,
616 'where' => 'civicrm_contribution.thankyou_date',
617 'headerPattern' => '/thank(s|(.?you))?(.?date)?/i',
618 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
619 'export' => TRUE,
620 'table_name' => 'civicrm_contribution',
621 'entity' => 'Contribution',
622 'bao' => 'CRM_Contribute_BAO_Contribution',
623 'localizable' => 0,
624 'html' => [
625 'type' => 'Select Date',
626 'formatType' => 'activityDateTime',
627 ],
628 ],
629 'contribution_source' => [
630 'name' => 'source',
631 'type' => CRM_Utils_Type::T_STRING,
632 'title' => ts('Contribution Source'),
633 'description' => ts('Origin of this Contribution.'),
634 'maxlength' => 255,
635 'size' => CRM_Utils_Type::HUGE,
636 'import' => TRUE,
637 'where' => 'civicrm_contribution.source',
638 'headerPattern' => '/source/i',
639 'export' => TRUE,
640 'table_name' => 'civicrm_contribution',
641 'entity' => 'Contribution',
642 'bao' => 'CRM_Contribute_BAO_Contribution',
643 'localizable' => 0,
644 'html' => [
645 'type' => 'Text',
646 ],
647 ],
648 'amount_level' => [
649 'name' => 'amount_level',
650 'type' => CRM_Utils_Type::T_TEXT,
651 'title' => ts('Amount Label'),
652 'import' => TRUE,
653 'where' => 'civicrm_contribution.amount_level',
654 'export' => TRUE,
655 'table_name' => 'civicrm_contribution',
656 'entity' => 'Contribution',
657 'bao' => 'CRM_Contribute_BAO_Contribution',
658 'localizable' => 0,
659 'html' => [
660 'type' => 'Text',
661 ],
662 ],
663 'contribution_recur_id' => [
664 'name' => 'contribution_recur_id',
665 'type' => CRM_Utils_Type::T_INT,
666 'title' => ts('Recurring Contribution ID'),
667 'description' => ts('Conditional foreign key to civicrm_contribution_recur id. Each contribution made in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.'),
668 'where' => 'civicrm_contribution.contribution_recur_id',
669 'export' => TRUE,
670 'table_name' => 'civicrm_contribution',
671 'entity' => 'Contribution',
672 'bao' => 'CRM_Contribute_BAO_Contribution',
673 'localizable' => 0,
674 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
675 ],
676 'is_test' => [
677 'name' => 'is_test',
678 'type' => CRM_Utils_Type::T_BOOLEAN,
679 'title' => ts('Test'),
680 'import' => TRUE,
681 'where' => 'civicrm_contribution.is_test',
682 'export' => TRUE,
683 'default' => '0',
684 'table_name' => 'civicrm_contribution',
685 'entity' => 'Contribution',
686 'bao' => 'CRM_Contribute_BAO_Contribution',
687 'localizable' => 0,
688 'html' => [
689 'type' => 'CheckBox',
690 ],
691 ],
692 'is_pay_later' => [
693 'name' => 'is_pay_later',
694 'type' => CRM_Utils_Type::T_BOOLEAN,
695 'title' => ts('Is Pay Later'),
696 'import' => TRUE,
697 'where' => 'civicrm_contribution.is_pay_later',
698 'export' => TRUE,
699 'default' => '0',
700 'table_name' => 'civicrm_contribution',
701 'entity' => 'Contribution',
702 'bao' => 'CRM_Contribute_BAO_Contribution',
703 'localizable' => 0,
704 'html' => [
705 'type' => 'CheckBox',
706 ],
707 ],
708 'contribution_status_id' => [
709 'name' => 'contribution_status_id',
710 'type' => CRM_Utils_Type::T_INT,
711 'title' => ts('Contribution Status ID'),
712 'import' => TRUE,
713 'where' => 'civicrm_contribution.contribution_status_id',
714 'headerPattern' => '/status/i',
715 'export' => TRUE,
716 'default' => '1',
717 'table_name' => 'civicrm_contribution',
718 'entity' => 'Contribution',
719 'bao' => 'CRM_Contribute_BAO_Contribution',
720 'localizable' => 0,
721 'html' => [
722 'type' => 'Select',
723 ],
724 'pseudoconstant' => [
725 'optionGroupName' => 'contribution_status',
726 'optionEditPath' => 'civicrm/admin/options/contribution_status',
727 ],
728 ],
729 'contribution_address_id' => [
730 'name' => 'address_id',
731 'type' => CRM_Utils_Type::T_INT,
732 'title' => ts('Contribution Address'),
733 'description' => ts('Conditional foreign key to civicrm_address.id. We insert an address record for each contribution when we have associated billing name and address data.'),
734 'where' => 'civicrm_contribution.address_id',
735 'export' => TRUE,
736 'table_name' => 'civicrm_contribution',
737 'entity' => 'Contribution',
738 'bao' => 'CRM_Contribute_BAO_Contribution',
739 'localizable' => 0,
740 'FKClassName' => 'CRM_Core_DAO_Address',
741 ],
742 'contribution_check_number' => [
743 'name' => 'check_number',
744 'type' => CRM_Utils_Type::T_STRING,
745 'title' => ts('Check Number'),
746 'maxlength' => 255,
747 'size' => 6,
748 'import' => TRUE,
749 'where' => 'civicrm_contribution.check_number',
750 'headerPattern' => '/check(.?number)?/i',
751 'export' => TRUE,
752 'table_name' => 'civicrm_contribution',
753 'entity' => 'Contribution',
754 'bao' => 'CRM_Contribute_BAO_Contribution',
755 'localizable' => 0,
756 'html' => [
757 'type' => 'Text',
758 ],
759 ],
760 'contribution_campaign_id' => [
761 'name' => 'campaign_id',
762 'type' => CRM_Utils_Type::T_INT,
763 'title' => ts('Campaign'),
764 'description' => ts('The campaign for which this contribution has been triggered.'),
765 'import' => TRUE,
766 'where' => 'civicrm_contribution.campaign_id',
767 'export' => TRUE,
768 'table_name' => 'civicrm_contribution',
769 'entity' => 'Contribution',
770 'bao' => 'CRM_Contribute_BAO_Contribution',
771 'localizable' => 0,
772 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
773 'html' => [
774 'type' => 'Select',
775 ],
776 'pseudoconstant' => [
777 'table' => 'civicrm_campaign',
778 'keyColumn' => 'id',
779 'labelColumn' => 'title',
780 ],
781 ],
782 'creditnote_id' => [
783 'name' => 'creditnote_id',
784 'type' => CRM_Utils_Type::T_STRING,
785 'title' => ts('Credit Note ID'),
786 'description' => ts('unique credit note id, system generated or passed in'),
787 'maxlength' => 255,
788 'size' => CRM_Utils_Type::HUGE,
789 'import' => TRUE,
790 'where' => 'civicrm_contribution.creditnote_id',
791 'headerPattern' => '/creditnote(.?id)?/i',
792 'export' => TRUE,
793 'table_name' => 'civicrm_contribution',
794 'entity' => 'Contribution',
795 'bao' => 'CRM_Contribute_BAO_Contribution',
796 'localizable' => 0,
797 'html' => [
798 'type' => 'Text',
799 ],
800 ],
801 'tax_amount' => [
802 'name' => 'tax_amount',
803 'type' => CRM_Utils_Type::T_MONEY,
804 'title' => ts('Tax Amount'),
805 'description' => ts('Total tax amount of this contribution.'),
806 'precision' => [
807 20,
808 2,
809 ],
810 'import' => TRUE,
811 'where' => 'civicrm_contribution.tax_amount',
812 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
813 'dataPattern' => '/^\d+(\.\d{2})?$/',
814 'export' => TRUE,
815 'table_name' => 'civicrm_contribution',
816 'entity' => 'Contribution',
817 'bao' => 'CRM_Contribute_BAO_Contribution',
818 'localizable' => 0,
819 'html' => [
820 'type' => 'Text',
821 ],
822 ],
823 'revenue_recognition_date' => [
824 'name' => 'revenue_recognition_date',
825 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
826 'title' => ts('Revenue Recognition Date'),
827 'description' => ts('Stores the date when revenue should be recognized.'),
828 'import' => TRUE,
829 'where' => 'civicrm_contribution.revenue_recognition_date',
830 'headerPattern' => '/revenue(.?date)?/i',
831 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
832 'export' => TRUE,
833 'table_name' => 'civicrm_contribution',
834 'entity' => 'Contribution',
835 'bao' => 'CRM_Contribute_BAO_Contribution',
836 'localizable' => 0,
837 'html' => [
838 'type' => 'Select Date',
839 'formatType' => 'activityDateTime',
840 ],
841 ],
842 ];
843 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
844 }
845 return Civi::$statics[__CLASS__]['fields'];
846 }
847
848 /**
849 * Return a mapping from field-name to the corresponding key (as used in fields()).
850 *
851 * @return array
852 * Array(string $name => string $uniqueName).
853 */
854 public static function &fieldKeys() {
855 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
856 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
857 }
858 return Civi::$statics[__CLASS__]['fieldKeys'];
859 }
860
861 /**
862 * Returns the names of this table
863 *
864 * @return string
865 */
866 public static function getTableName() {
867 return self::$_tableName;
868 }
869
870 /**
871 * Returns if this table needs to be logged
872 *
873 * @return bool
874 */
875 public function getLog() {
876 return self::$_log;
877 }
878
879 /**
880 * Returns the list of fields that can be imported
881 *
882 * @param bool $prefix
883 *
884 * @return array
885 */
886 public static function &import($prefix = FALSE) {
887 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'contribution', $prefix, []);
888 return $r;
889 }
890
891 /**
892 * Returns the list of fields that can be exported
893 *
894 * @param bool $prefix
895 *
896 * @return array
897 */
898 public static function &export($prefix = FALSE) {
899 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'contribution', $prefix, []);
900 return $r;
901 }
902
903 /**
904 * Returns the list of indices
905 *
906 * @param bool $localize
907 *
908 * @return array
909 */
910 public static function indices($localize = TRUE) {
911 $indices = [
912 'UI_contrib_payment_instrument_id' => [
913 'name' => 'UI_contrib_payment_instrument_id',
914 'field' => [
915 0 => 'payment_instrument_id',
916 ],
917 'localizable' => FALSE,
918 'sig' => 'civicrm_contribution::0::payment_instrument_id',
919 ],
920 'index_total_amount_receive_date' => [
921 'name' => 'index_total_amount_receive_date',
922 'field' => [
923 0 => 'total_amount',
924 1 => 'receive_date',
925 ],
926 'localizable' => FALSE,
927 'sig' => 'civicrm_contribution::0::total_amount::receive_date',
928 ],
929 'index_source' => [
930 'name' => 'index_source',
931 'field' => [
932 0 => 'source',
933 ],
934 'localizable' => FALSE,
935 'sig' => 'civicrm_contribution::0::source',
936 ],
937 'UI_contrib_trxn_id' => [
938 'name' => 'UI_contrib_trxn_id',
939 'field' => [
940 0 => 'trxn_id',
941 ],
942 'localizable' => FALSE,
943 'unique' => TRUE,
944 'sig' => 'civicrm_contribution::1::trxn_id',
945 ],
946 'UI_contrib_invoice_id' => [
947 'name' => 'UI_contrib_invoice_id',
948 'field' => [
949 0 => 'invoice_id',
950 ],
951 'localizable' => FALSE,
952 'unique' => TRUE,
953 'sig' => 'civicrm_contribution::1::invoice_id',
954 ],
955 'index_contribution_status' => [
956 'name' => 'index_contribution_status',
957 'field' => [
958 0 => 'contribution_status_id',
959 ],
960 'localizable' => FALSE,
961 'sig' => 'civicrm_contribution::0::contribution_status_id',
962 ],
963 'received_date' => [
964 'name' => 'received_date',
965 'field' => [
966 0 => 'receive_date',
967 ],
968 'localizable' => FALSE,
969 'sig' => 'civicrm_contribution::0::receive_date',
970 ],
971 'check_number' => [
972 'name' => 'check_number',
973 'field' => [
974 0 => 'check_number',
975 ],
976 'localizable' => FALSE,
977 'sig' => 'civicrm_contribution::0::check_number',
978 ],
979 'index_creditnote_id' => [
980 'name' => 'index_creditnote_id',
981 'field' => [
982 0 => 'creditnote_id',
983 ],
984 'localizable' => FALSE,
985 'sig' => 'civicrm_contribution::0::creditnote_id',
986 ],
987 ];
988 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
989 }
990
991 }