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