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