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