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