Merge pull request #15881 from civicrm/5.20
[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:a9f83aa612e82ee87ace74e75fe23466)
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 * Shows this is a template for recurring contributions.
231 *
232 * @var bool
233 */
234 public $is_template;
235
236 /**
237 * Class constructor.
238 */
239 public function __construct() {
240 $this->__table = 'civicrm_contribution';
241 parent::__construct();
242 }
243
244 /**
245 * Returns foreign keys and entity references.
246 *
247 * @return array
248 * [CRM_Core_Reference_Interface]
249 */
250 public static function getReferenceColumns() {
251 if (!isset(Civi::$statics[__CLASS__]['links'])) {
252 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
253 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
254 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
255 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_page_id', 'civicrm_contribution_page', 'id');
256 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
257 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'address_id', 'civicrm_address', 'id');
258 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
259 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
260 }
261 return Civi::$statics[__CLASS__]['links'];
262 }
263
264 /**
265 * Returns all the column names of this table
266 *
267 * @return array
268 */
269 public static function &fields() {
270 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
271 Civi::$statics[__CLASS__]['fields'] = [
272 'contribution_id' => [
273 'name' => 'id',
274 'type' => CRM_Utils_Type::T_INT,
275 'title' => ts('Contribution ID'),
276 'description' => ts('Contribution ID'),
277 'required' => TRUE,
278 'import' => TRUE,
279 'where' => 'civicrm_contribution.id',
280 'export' => TRUE,
281 'table_name' => 'civicrm_contribution',
282 'entity' => 'Contribution',
283 'bao' => 'CRM_Contribute_BAO_Contribution',
284 'localizable' => 0,
285 ],
286 'contribution_contact_id' => [
287 'name' => 'contact_id',
288 'type' => CRM_Utils_Type::T_INT,
289 'title' => ts('Contact ID'),
290 'description' => ts('FK to Contact ID'),
291 'required' => TRUE,
292 'import' => TRUE,
293 'where' => 'civicrm_contribution.contact_id',
294 'headerPattern' => '/contact(.?id)?/i',
295 'dataPattern' => '/^\d+$/',
296 'export' => TRUE,
297 'table_name' => 'civicrm_contribution',
298 'entity' => 'Contribution',
299 'bao' => 'CRM_Contribute_BAO_Contribution',
300 'localizable' => 0,
301 'FKClassName' => 'CRM_Contact_DAO_Contact',
302 'html' => [
303 'type' => 'EntityRef',
304 ],
305 ],
306 'financial_type_id' => [
307 'name' => 'financial_type_id',
308 'type' => CRM_Utils_Type::T_INT,
309 'title' => ts('Financial Type'),
310 'description' => ts('FK to Financial Type for (total_amount - non_deductible_amount).'),
311 'where' => 'civicrm_contribution.financial_type_id',
312 'export' => TRUE,
313 'table_name' => 'civicrm_contribution',
314 'entity' => 'Contribution',
315 'bao' => 'CRM_Contribute_BAO_Contribution',
316 'localizable' => 0,
317 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
318 'html' => [
319 'type' => 'Select',
320 ],
321 'pseudoconstant' => [
322 'table' => 'civicrm_financial_type',
323 'keyColumn' => 'id',
324 'labelColumn' => 'name',
325 ],
326 ],
327 'contribution_page_id' => [
328 'name' => 'contribution_page_id',
329 'type' => CRM_Utils_Type::T_INT,
330 'title' => ts('Contribution Page ID'),
331 'description' => ts('The Contribution Page which triggered this contribution'),
332 'import' => TRUE,
333 'where' => 'civicrm_contribution.contribution_page_id',
334 'export' => TRUE,
335 'table_name' => 'civicrm_contribution',
336 'entity' => 'Contribution',
337 'bao' => 'CRM_Contribute_BAO_Contribution',
338 'localizable' => 0,
339 'FKClassName' => 'CRM_Contribute_DAO_ContributionPage',
340 'html' => [
341 'type' => 'Select',
342 ],
343 'pseudoconstant' => [
344 'table' => 'civicrm_contribution_page',
345 'keyColumn' => 'id',
346 'labelColumn' => 'title',
347 ],
348 ],
349 'payment_instrument_id' => [
350 'name' => 'payment_instrument_id',
351 'type' => CRM_Utils_Type::T_INT,
352 'title' => ts('Payment Method ID'),
353 'description' => ts('FK to Payment Instrument'),
354 'where' => 'civicrm_contribution.payment_instrument_id',
355 'headerPattern' => '/^payment|(p(ayment\s)?instrument)$/i',
356 'export' => TRUE,
357 'table_name' => 'civicrm_contribution',
358 'entity' => 'Contribution',
359 'bao' => 'CRM_Contribute_BAO_Contribution',
360 'localizable' => 0,
361 'html' => [
362 'type' => 'Select',
363 ],
364 'pseudoconstant' => [
365 'optionGroupName' => 'payment_instrument',
366 'optionEditPath' => 'civicrm/admin/options/payment_instrument',
367 ],
368 ],
369 'receive_date' => [
370 'name' => 'receive_date',
371 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
372 'title' => ts('Date Received'),
373 'description' => ts('Date contribution was received - not necessarily the creation date of the record'),
374 'import' => TRUE,
375 'where' => 'civicrm_contribution.receive_date',
376 'headerPattern' => '/receive(.?date)?/i',
377 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
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 Date',
385 'formatType' => 'activityDateTime',
386 ],
387 ],
388 'non_deductible_amount' => [
389 'name' => 'non_deductible_amount',
390 'type' => CRM_Utils_Type::T_MONEY,
391 'title' => ts('Non-deductible Amount'),
392 'description' => ts('Portion of total amount which is NOT tax deductible. Equal to total_amount for non-deductible financial types.'),
393 'precision' => [
394 20,
395 2,
396 ],
397 'import' => TRUE,
398 'where' => 'civicrm_contribution.non_deductible_amount',
399 'headerPattern' => '/non?.?deduct/i',
400 'dataPattern' => '/^\d+(\.\d{2})?$/',
401 'export' => TRUE,
402 'default' => '0',
403 'table_name' => 'civicrm_contribution',
404 'entity' => 'Contribution',
405 'bao' => 'CRM_Contribute_BAO_Contribution',
406 'localizable' => 0,
407 'html' => [
408 'type' => 'Text',
409 ],
410 ],
411 'total_amount' => [
412 'name' => 'total_amount',
413 'type' => CRM_Utils_Type::T_MONEY,
414 'title' => ts('Total Amount'),
415 'description' => ts('Total amount of this contribution. Use market value for non-monetary gifts.'),
416 'required' => TRUE,
417 'precision' => [
418 20,
419 2,
420 ],
421 'import' => TRUE,
422 'where' => 'civicrm_contribution.total_amount',
423 'headerPattern' => '/^total|(.?^am(ou)?nt)/i',
424 'dataPattern' => '/^\d+(\.\d{2})?$/',
425 'export' => TRUE,
426 'table_name' => 'civicrm_contribution',
427 'entity' => 'Contribution',
428 'bao' => 'CRM_Contribute_BAO_Contribution',
429 'localizable' => 0,
430 'html' => [
431 'type' => 'Text',
432 ],
433 ],
434 'fee_amount' => [
435 'name' => 'fee_amount',
436 'type' => CRM_Utils_Type::T_MONEY,
437 'title' => ts('Fee Amount'),
438 'description' => ts('actual processor fee if known - may be 0.'),
439 'precision' => [
440 20,
441 2,
442 ],
443 'import' => TRUE,
444 'where' => 'civicrm_contribution.fee_amount',
445 'headerPattern' => '/fee(.?am(ou)?nt)?/i',
446 'dataPattern' => '/^\d+(\.\d{2})?$/',
447 'export' => TRUE,
448 'table_name' => 'civicrm_contribution',
449 'entity' => 'Contribution',
450 'bao' => 'CRM_Contribute_BAO_Contribution',
451 'localizable' => 0,
452 'html' => [
453 'type' => 'Text',
454 ],
455 ],
456 'net_amount' => [
457 'name' => 'net_amount',
458 'type' => CRM_Utils_Type::T_MONEY,
459 'title' => ts('Net Amount'),
460 'description' => ts('actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount.'),
461 'precision' => [
462 20,
463 2,
464 ],
465 'import' => TRUE,
466 'where' => 'civicrm_contribution.net_amount',
467 'headerPattern' => '/net(.?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 ],
478 'trxn_id' => [
479 'name' => 'trxn_id',
480 'type' => CRM_Utils_Type::T_STRING,
481 'title' => ts('Transaction ID'),
482 'description' => ts('unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method'),
483 'maxlength' => 255,
484 'size' => CRM_Utils_Type::HUGE,
485 'import' => TRUE,
486 'where' => 'civicrm_contribution.trxn_id',
487 'headerPattern' => '/tr(ansactio|x)n(.?id)?/i',
488 'export' => TRUE,
489 'table_name' => 'civicrm_contribution',
490 'entity' => 'Contribution',
491 'bao' => 'CRM_Contribute_BAO_Contribution',
492 'localizable' => 0,
493 'html' => [
494 'type' => 'Text',
495 ],
496 ],
497 'invoice_id' => [
498 'name' => 'invoice_id',
499 'type' => CRM_Utils_Type::T_STRING,
500 'title' => ts('Invoice Reference'),
501 'description' => ts('unique invoice id, system generated or passed in'),
502 'maxlength' => 255,
503 'size' => CRM_Utils_Type::HUGE,
504 'import' => TRUE,
505 'where' => 'civicrm_contribution.invoice_id',
506 'headerPattern' => '/invoice(.?id)?/i',
507 'export' => TRUE,
508 'table_name' => 'civicrm_contribution',
509 'entity' => 'Contribution',
510 'bao' => 'CRM_Contribute_BAO_Contribution',
511 'localizable' => 0,
512 'html' => [
513 'type' => 'Text',
514 ],
515 ],
516 'invoice_number' => [
517 'name' => 'invoice_number',
518 'type' => CRM_Utils_Type::T_STRING,
519 'title' => ts('Invoice Number'),
520 'description' => ts('Human readable invoice number'),
521 'maxlength' => 255,
522 'size' => CRM_Utils_Type::HUGE,
523 'import' => TRUE,
524 'where' => 'civicrm_contribution.invoice_number',
525 'headerPattern' => '/invoice(.?number)?/i',
526 'export' => TRUE,
527 'table_name' => 'civicrm_contribution',
528 'entity' => 'Contribution',
529 'bao' => 'CRM_Contribute_BAO_Contribution',
530 'localizable' => 0,
531 'html' => [
532 'type' => 'Text',
533 ],
534 ],
535 'currency' => [
536 'name' => 'currency',
537 'type' => CRM_Utils_Type::T_STRING,
538 'title' => ts('Currency'),
539 'description' => ts('3 character string, value from config setting or input via user.'),
540 'maxlength' => 3,
541 'size' => CRM_Utils_Type::FOUR,
542 'import' => TRUE,
543 'where' => 'civicrm_contribution.currency',
544 'headerPattern' => '/cur(rency)?/i',
545 'dataPattern' => '/^[A-Z]{3}$/i',
546 'export' => TRUE,
547 'default' => 'NULL',
548 'table_name' => 'civicrm_contribution',
549 'entity' => 'Contribution',
550 'bao' => 'CRM_Contribute_BAO_Contribution',
551 'localizable' => 0,
552 'html' => [
553 'type' => 'Select',
554 ],
555 'pseudoconstant' => [
556 'table' => 'civicrm_currency',
557 'keyColumn' => 'name',
558 'labelColumn' => 'full_name',
559 'nameColumn' => 'name',
560 'abbrColumn' => 'symbol',
561 ],
562 ],
563 'contribution_cancel_date' => [
564 'name' => 'cancel_date',
565 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
566 'title' => ts('Cancelled / Refunded Date'),
567 'description' => ts('when was gift cancelled'),
568 'import' => TRUE,
569 'where' => 'civicrm_contribution.cancel_date',
570 'headerPattern' => '/cancel(.?date)?/i',
571 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
572 'export' => TRUE,
573 'table_name' => 'civicrm_contribution',
574 'entity' => 'Contribution',
575 'bao' => 'CRM_Contribute_BAO_Contribution',
576 'localizable' => 0,
577 'html' => [
578 'type' => 'Select Date',
579 'formatType' => 'activityDateTime',
580 ],
581 ],
582 'cancel_reason' => [
583 'name' => 'cancel_reason',
584 'type' => CRM_Utils_Type::T_TEXT,
585 'title' => ts('Cancellation / Refund Reason'),
586 'import' => TRUE,
587 'where' => 'civicrm_contribution.cancel_reason',
588 'headerPattern' => '/(cancel.?)?reason/i',
589 'export' => TRUE,
590 'table_name' => 'civicrm_contribution',
591 'entity' => 'Contribution',
592 'bao' => 'CRM_Contribute_BAO_Contribution',
593 'localizable' => 0,
594 'html' => [
595 'type' => 'Text',
596 ],
597 ],
598 'receipt_date' => [
599 'name' => 'receipt_date',
600 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
601 'title' => ts('Receipt Date'),
602 'description' => ts('when (if) receipt was sent. populated automatically for online donations w/ automatic receipting'),
603 'import' => TRUE,
604 'where' => 'civicrm_contribution.receipt_date',
605 'headerPattern' => '/receipt(.?date)?/i',
606 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
607 'export' => TRUE,
608 'table_name' => 'civicrm_contribution',
609 'entity' => 'Contribution',
610 'bao' => 'CRM_Contribute_BAO_Contribution',
611 'localizable' => 0,
612 'html' => [
613 'type' => 'Select Date',
614 'formatType' => 'activityDateTime',
615 ],
616 ],
617 'thankyou_date' => [
618 'name' => 'thankyou_date',
619 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
620 'title' => ts('Thank-you Date'),
621 'description' => ts('when (if) was donor thanked'),
622 'import' => TRUE,
623 'where' => 'civicrm_contribution.thankyou_date',
624 'headerPattern' => '/thank(s|(.?you))?(.?date)?/i',
625 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
626 'export' => TRUE,
627 'table_name' => 'civicrm_contribution',
628 'entity' => 'Contribution',
629 'bao' => 'CRM_Contribute_BAO_Contribution',
630 'localizable' => 0,
631 'html' => [
632 'type' => 'Select Date',
633 'formatType' => 'activityDateTime',
634 ],
635 ],
636 'contribution_source' => [
637 'name' => 'source',
638 'type' => CRM_Utils_Type::T_STRING,
639 'title' => ts('Contribution Source'),
640 'description' => ts('Origin of this Contribution.'),
641 'maxlength' => 255,
642 'size' => CRM_Utils_Type::HUGE,
643 'import' => TRUE,
644 'where' => 'civicrm_contribution.source',
645 'headerPattern' => '/source/i',
646 'export' => TRUE,
647 'table_name' => 'civicrm_contribution',
648 'entity' => 'Contribution',
649 'bao' => 'CRM_Contribute_BAO_Contribution',
650 'localizable' => 0,
651 'html' => [
652 'type' => 'Text',
653 ],
654 ],
655 'amount_level' => [
656 'name' => 'amount_level',
657 'type' => CRM_Utils_Type::T_TEXT,
658 'title' => ts('Amount Label'),
659 'import' => TRUE,
660 'where' => 'civicrm_contribution.amount_level',
661 'export' => TRUE,
662 'table_name' => 'civicrm_contribution',
663 'entity' => 'Contribution',
664 'bao' => 'CRM_Contribute_BAO_Contribution',
665 'localizable' => 0,
666 'html' => [
667 'type' => 'Text',
668 ],
669 ],
670 'contribution_recur_id' => [
671 'name' => 'contribution_recur_id',
672 'type' => CRM_Utils_Type::T_INT,
673 'title' => ts('Recurring Contribution ID'),
674 '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.'),
675 'where' => 'civicrm_contribution.contribution_recur_id',
676 'export' => TRUE,
677 'table_name' => 'civicrm_contribution',
678 'entity' => 'Contribution',
679 'bao' => 'CRM_Contribute_BAO_Contribution',
680 'localizable' => 0,
681 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
682 ],
683 'is_test' => [
684 'name' => 'is_test',
685 'type' => CRM_Utils_Type::T_BOOLEAN,
686 'title' => ts('Test'),
687 'import' => TRUE,
688 'where' => 'civicrm_contribution.is_test',
689 'export' => TRUE,
690 'default' => '0',
691 'table_name' => 'civicrm_contribution',
692 'entity' => 'Contribution',
693 'bao' => 'CRM_Contribute_BAO_Contribution',
694 'localizable' => 0,
695 'html' => [
696 'type' => 'CheckBox',
697 ],
698 ],
699 'is_pay_later' => [
700 'name' => 'is_pay_later',
701 'type' => CRM_Utils_Type::T_BOOLEAN,
702 'title' => ts('Is Pay Later'),
703 'import' => TRUE,
704 'where' => 'civicrm_contribution.is_pay_later',
705 'export' => TRUE,
706 'default' => '0',
707 'table_name' => 'civicrm_contribution',
708 'entity' => 'Contribution',
709 'bao' => 'CRM_Contribute_BAO_Contribution',
710 'localizable' => 0,
711 'html' => [
712 'type' => 'CheckBox',
713 ],
714 ],
715 'contribution_status_id' => [
716 'name' => 'contribution_status_id',
717 'type' => CRM_Utils_Type::T_INT,
718 'title' => ts('Contribution Status ID'),
719 'import' => TRUE,
720 'where' => 'civicrm_contribution.contribution_status_id',
721 'headerPattern' => '/status/i',
722 'export' => TRUE,
723 'default' => '1',
724 'table_name' => 'civicrm_contribution',
725 'entity' => 'Contribution',
726 'bao' => 'CRM_Contribute_BAO_Contribution',
727 'localizable' => 0,
728 'html' => [
729 'type' => 'Select',
730 ],
731 'pseudoconstant' => [
732 'optionGroupName' => 'contribution_status',
733 'optionEditPath' => 'civicrm/admin/options/contribution_status',
734 ],
735 ],
736 'contribution_address_id' => [
737 'name' => 'address_id',
738 'type' => CRM_Utils_Type::T_INT,
739 'title' => ts('Contribution Address'),
740 '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.'),
741 'where' => 'civicrm_contribution.address_id',
742 'export' => TRUE,
743 'table_name' => 'civicrm_contribution',
744 'entity' => 'Contribution',
745 'bao' => 'CRM_Contribute_BAO_Contribution',
746 'localizable' => 0,
747 'FKClassName' => 'CRM_Core_DAO_Address',
748 ],
749 'contribution_check_number' => [
750 'name' => 'check_number',
751 'type' => CRM_Utils_Type::T_STRING,
752 'title' => ts('Check Number'),
753 'maxlength' => 255,
754 'size' => 6,
755 'import' => TRUE,
756 'where' => 'civicrm_contribution.check_number',
757 'headerPattern' => '/check(.?number)?/i',
758 'export' => TRUE,
759 'table_name' => 'civicrm_contribution',
760 'entity' => 'Contribution',
761 'bao' => 'CRM_Contribute_BAO_Contribution',
762 'localizable' => 0,
763 'html' => [
764 'type' => 'Text',
765 ],
766 ],
767 'contribution_campaign_id' => [
768 'name' => 'campaign_id',
769 'type' => CRM_Utils_Type::T_INT,
770 'title' => ts('Campaign'),
771 'description' => ts('The campaign for which this contribution has been triggered.'),
772 'import' => TRUE,
773 'where' => 'civicrm_contribution.campaign_id',
774 'export' => TRUE,
775 'table_name' => 'civicrm_contribution',
776 'entity' => 'Contribution',
777 'bao' => 'CRM_Contribute_BAO_Contribution',
778 'localizable' => 0,
779 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
780 'html' => [
781 'type' => 'Select',
782 ],
783 'pseudoconstant' => [
784 'table' => 'civicrm_campaign',
785 'keyColumn' => 'id',
786 'labelColumn' => 'title',
787 ],
788 ],
789 'creditnote_id' => [
790 'name' => 'creditnote_id',
791 'type' => CRM_Utils_Type::T_STRING,
792 'title' => ts('Credit Note ID'),
793 'description' => ts('unique credit note id, system generated or passed in'),
794 'maxlength' => 255,
795 'size' => CRM_Utils_Type::HUGE,
796 'import' => TRUE,
797 'where' => 'civicrm_contribution.creditnote_id',
798 'headerPattern' => '/creditnote(.?id)?/i',
799 'export' => TRUE,
800 'table_name' => 'civicrm_contribution',
801 'entity' => 'Contribution',
802 'bao' => 'CRM_Contribute_BAO_Contribution',
803 'localizable' => 0,
804 'html' => [
805 'type' => 'Text',
806 ],
807 ],
808 'tax_amount' => [
809 'name' => 'tax_amount',
810 'type' => CRM_Utils_Type::T_MONEY,
811 'title' => ts('Tax Amount'),
812 'description' => ts('Total tax amount of this contribution.'),
813 'precision' => [
814 20,
815 2,
816 ],
817 'import' => TRUE,
818 'where' => 'civicrm_contribution.tax_amount',
819 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
820 'dataPattern' => '/^\d+(\.\d{2})?$/',
821 'export' => TRUE,
822 'table_name' => 'civicrm_contribution',
823 'entity' => 'Contribution',
824 'bao' => 'CRM_Contribute_BAO_Contribution',
825 'localizable' => 0,
826 'html' => [
827 'type' => 'Text',
828 ],
829 ],
830 'revenue_recognition_date' => [
831 'name' => 'revenue_recognition_date',
832 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
833 'title' => ts('Revenue Recognition Date'),
834 'description' => ts('Stores the date when revenue should be recognized.'),
835 'import' => TRUE,
836 'where' => 'civicrm_contribution.revenue_recognition_date',
837 'headerPattern' => '/revenue(.?date)?/i',
838 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
839 'export' => TRUE,
840 'table_name' => 'civicrm_contribution',
841 'entity' => 'Contribution',
842 'bao' => 'CRM_Contribute_BAO_Contribution',
843 'localizable' => 0,
844 'html' => [
845 'type' => 'Select Date',
846 'formatType' => 'activityDateTime',
847 ],
848 ],
849 'is_template' => [
850 'name' => 'is_template',
851 'type' => CRM_Utils_Type::T_BOOLEAN,
852 'title' => ts('Is a Template Contribution'),
853 'description' => ts('Shows this is a template for recurring contributions.'),
854 'import' => TRUE,
855 'where' => 'civicrm_contribution.is_template',
856 'export' => TRUE,
857 'default' => '0',
858 'table_name' => 'civicrm_contribution',
859 'entity' => 'Contribution',
860 'bao' => 'CRM_Contribute_BAO_Contribution',
861 'localizable' => 0,
862 'html' => [
863 'type' => 'CheckBox',
864 ],
865 ],
866 ];
867 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
868 }
869 return Civi::$statics[__CLASS__]['fields'];
870 }
871
872 /**
873 * Return a mapping from field-name to the corresponding key (as used in fields()).
874 *
875 * @return array
876 * Array(string $name => string $uniqueName).
877 */
878 public static function &fieldKeys() {
879 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
880 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
881 }
882 return Civi::$statics[__CLASS__]['fieldKeys'];
883 }
884
885 /**
886 * Returns the names of this table
887 *
888 * @return string
889 */
890 public static function getTableName() {
891 return self::$_tableName;
892 }
893
894 /**
895 * Returns if this table needs to be logged
896 *
897 * @return bool
898 */
899 public function getLog() {
900 return self::$_log;
901 }
902
903 /**
904 * Returns the list of fields that can be imported
905 *
906 * @param bool $prefix
907 *
908 * @return array
909 */
910 public static function &import($prefix = FALSE) {
911 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'contribution', $prefix, []);
912 return $r;
913 }
914
915 /**
916 * Returns the list of fields that can be exported
917 *
918 * @param bool $prefix
919 *
920 * @return array
921 */
922 public static function &export($prefix = FALSE) {
923 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'contribution', $prefix, []);
924 return $r;
925 }
926
927 /**
928 * Returns the list of indices
929 *
930 * @param bool $localize
931 *
932 * @return array
933 */
934 public static function indices($localize = TRUE) {
935 $indices = [
936 'UI_contrib_payment_instrument_id' => [
937 'name' => 'UI_contrib_payment_instrument_id',
938 'field' => [
939 0 => 'payment_instrument_id',
940 ],
941 'localizable' => FALSE,
942 'sig' => 'civicrm_contribution::0::payment_instrument_id',
943 ],
944 'index_total_amount_receive_date' => [
945 'name' => 'index_total_amount_receive_date',
946 'field' => [
947 0 => 'total_amount',
948 1 => 'receive_date',
949 ],
950 'localizable' => FALSE,
951 'sig' => 'civicrm_contribution::0::total_amount::receive_date',
952 ],
953 'index_source' => [
954 'name' => 'index_source',
955 'field' => [
956 0 => 'source',
957 ],
958 'localizable' => FALSE,
959 'sig' => 'civicrm_contribution::0::source',
960 ],
961 'UI_contrib_trxn_id' => [
962 'name' => 'UI_contrib_trxn_id',
963 'field' => [
964 0 => 'trxn_id',
965 ],
966 'localizable' => FALSE,
967 'unique' => TRUE,
968 'sig' => 'civicrm_contribution::1::trxn_id',
969 ],
970 'UI_contrib_invoice_id' => [
971 'name' => 'UI_contrib_invoice_id',
972 'field' => [
973 0 => 'invoice_id',
974 ],
975 'localizable' => FALSE,
976 'unique' => TRUE,
977 'sig' => 'civicrm_contribution::1::invoice_id',
978 ],
979 'index_contribution_status' => [
980 'name' => 'index_contribution_status',
981 'field' => [
982 0 => 'contribution_status_id',
983 ],
984 'localizable' => FALSE,
985 'sig' => 'civicrm_contribution::0::contribution_status_id',
986 ],
987 'received_date' => [
988 'name' => 'received_date',
989 'field' => [
990 0 => 'receive_date',
991 ],
992 'localizable' => FALSE,
993 'sig' => 'civicrm_contribution::0::receive_date',
994 ],
995 'check_number' => [
996 'name' => 'check_number',
997 'field' => [
998 0 => 'check_number',
999 ],
1000 'localizable' => FALSE,
1001 'sig' => 'civicrm_contribution::0::check_number',
1002 ],
1003 'index_creditnote_id' => [
1004 'name' => 'index_creditnote_id',
1005 'field' => [
1006 0 => 'creditnote_id',
1007 ],
1008 'localizable' => FALSE,
1009 'sig' => 'civicrm_contribution::0::creditnote_id',
1010 ],
1011 ];
1012 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
1013 }
1014
1015 }