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