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