Merge pull request #14059 from Stoob/patch-2
[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
e380ee3b 9 * (GenCodeChecksum:99cdf75ae6e6bf73bc5ff6871a3baf82)
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 *
34 * @var int unsigned
35 */
36 public $id;
c3fc2621 37
e501603b
TO
38 /**
39 * FK to Contact ID
40 *
41 * @var int unsigned
42 */
43 public $contact_id;
c3fc2621 44
e501603b
TO
45 /**
46 * FK to Financial Type for (total_amount - non_deductible_amount).
47 *
48 * @var int unsigned
49 */
50 public $financial_type_id;
c3fc2621 51
e501603b
TO
52 /**
53 * The Contribution Page which triggered this contribution
54 *
55 * @var int unsigned
56 */
57 public $contribution_page_id;
c3fc2621 58
e501603b
TO
59 /**
60 * FK to Payment Instrument
61 *
62 * @var int unsigned
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 *
170 * @var int unsigned
171 */
172 public $contribution_recur_id;
c3fc2621 173
e501603b 174 /**
e501603b
TO
175 * @var boolean
176 */
177 public $is_test;
c3fc2621 178
e501603b 179 /**
e501603b
TO
180 * @var boolean
181 */
182 public $is_pay_later;
c3fc2621 183
e501603b 184 /**
e501603b
TO
185 * @var int unsigned
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 *
192 * @var int unsigned
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 *
204 * @var int unsigned
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',
c3fc2621
CW
318 ]
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',
c3fc2621
CW
340 ]
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',
c3fc2621
CW
360 ]
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
TO
387 20,
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
TO
411 20,
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
TO
433 20,
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
TO
455 20,
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',
c3fc2621
CW
553 ]
554 ],
555 'cancel_date' => [
e501603b
TO
556 'name' => 'cancel_date',
557 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
c3fc2621 558 'title' => ts('Cancel Date'),
215b423e 559 'description' => ts('when was gift cancelled'),
c3fc2621 560 'import' => TRUE,
e501603b
TO
561 'where' => 'civicrm_contribution.cancel_date',
562 'headerPattern' => '/cancel(.?date)?/i',
563 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
c3fc2621 564 'export' => TRUE,
522a26c9 565 'table_name' => 'civicrm_contribution',
566 'entity' => 'Contribution',
567 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 568 'localizable' => 0,
c3fc2621 569 'html' => [
e501603b 570 'type' => 'Select Date',
24317d89 571 'formatType' => 'activityDateTime',
c3fc2621
CW
572 ],
573 ],
574 'cancel_reason' => [
e501603b
TO
575 'name' => 'cancel_reason',
576 'type' => CRM_Utils_Type::T_TEXT,
927898c5 577 'title' => ts('Cancellation / Refund Reason'),
c3fc2621 578 'import' => TRUE,
e501603b
TO
579 'where' => 'civicrm_contribution.cancel_reason',
580 'headerPattern' => '/(cancel.?)?reason/i',
c3fc2621 581 'export' => TRUE,
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' => 'Text',
c3fc2621
CW
588 ],
589 ],
590 'receipt_date' => [
e501603b
TO
591 'name' => 'receipt_date',
592 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
c3fc2621 593 'title' => ts('Receipt Date'),
215b423e 594 'description' => ts('when (if) receipt was sent. populated automatically for online donations w/ automatic receipting'),
c3fc2621 595 'import' => TRUE,
e501603b
TO
596 'where' => 'civicrm_contribution.receipt_date',
597 'headerPattern' => '/receipt(.?date)?/i',
598 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
c3fc2621 599 'export' => TRUE,
522a26c9 600 'table_name' => 'civicrm_contribution',
601 'entity' => 'Contribution',
602 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 603 'localizable' => 0,
c3fc2621 604 'html' => [
e501603b 605 'type' => 'Select Date',
24317d89 606 'formatType' => 'activityDateTime',
c3fc2621
CW
607 ],
608 ],
609 'thankyou_date' => [
e501603b
TO
610 'name' => 'thankyou_date',
611 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
c3fc2621 612 'title' => ts('Thank-you Date'),
215b423e 613 'description' => ts('when (if) was donor thanked'),
c3fc2621 614 'import' => TRUE,
e501603b
TO
615 'where' => 'civicrm_contribution.thankyou_date',
616 'headerPattern' => '/thank(s|(.?you))?(.?date)?/i',
617 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
c3fc2621 618 'export' => TRUE,
522a26c9 619 'table_name' => 'civicrm_contribution',
620 'entity' => 'Contribution',
621 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 622 'localizable' => 0,
c3fc2621 623 'html' => [
e501603b 624 'type' => 'Select Date',
24317d89 625 'formatType' => 'activityDateTime',
c3fc2621
CW
626 ],
627 ],
628 'contribution_source' => [
e501603b
TO
629 'name' => 'source',
630 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 631 'title' => ts('Contribution Source'),
215b423e 632 'description' => ts('Origin of this Contribution.'),
e501603b
TO
633 'maxlength' => 255,
634 'size' => CRM_Utils_Type::HUGE,
c3fc2621 635 'import' => TRUE,
e501603b
TO
636 'where' => 'civicrm_contribution.source',
637 'headerPattern' => '/source/i',
c3fc2621 638 'export' => TRUE,
522a26c9 639 'table_name' => 'civicrm_contribution',
640 'entity' => 'Contribution',
641 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 642 'localizable' => 0,
c3fc2621 643 'html' => [
e501603b 644 'type' => 'Text',
c3fc2621
CW
645 ],
646 ],
647 'amount_level' => [
e501603b
TO
648 'name' => 'amount_level',
649 'type' => CRM_Utils_Type::T_TEXT,
c3fc2621
CW
650 'title' => ts('Amount Label'),
651 'import' => TRUE,
e501603b 652 'where' => 'civicrm_contribution.amount_level',
c3fc2621 653 'export' => TRUE,
522a26c9 654 'table_name' => 'civicrm_contribution',
655 'entity' => 'Contribution',
656 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 657 'localizable' => 0,
c3fc2621 658 'html' => [
e501603b 659 'type' => 'Text',
c3fc2621
CW
660 ],
661 ],
662 'contribution_recur_id' => [
e501603b
TO
663 'name' => 'contribution_recur_id',
664 'type' => CRM_Utils_Type::T_INT,
c3fc2621 665 'title' => ts('Recurring Contribution ID'),
215b423e 666 'description' => ts('Conditional foreign key to civicrm_contribution_recur id. Each contribution made in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.'),
3123273f 667 'where' => 'civicrm_contribution.contribution_recur_id',
a36434b9 668 'export' => TRUE,
522a26c9 669 'table_name' => 'civicrm_contribution',
670 'entity' => 'Contribution',
671 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 672 'localizable' => 0,
e501603b 673 'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
c3fc2621
CW
674 ],
675 'is_test' => [
e501603b
TO
676 'name' => 'is_test',
677 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
678 'title' => ts('Test'),
679 'import' => TRUE,
e501603b 680 'where' => 'civicrm_contribution.is_test',
c3fc2621 681 'export' => TRUE,
45a83e42 682 'default' => '0',
522a26c9 683 'table_name' => 'civicrm_contribution',
684 'entity' => 'Contribution',
685 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 686 'localizable' => 0,
c3fc2621 687 'html' => [
e501603b 688 'type' => 'CheckBox',
c3fc2621
CW
689 ],
690 ],
691 'is_pay_later' => [
e501603b
TO
692 'name' => 'is_pay_later',
693 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621
CW
694 'title' => ts('Is Pay Later'),
695 'import' => TRUE,
e501603b 696 'where' => 'civicrm_contribution.is_pay_later',
c3fc2621 697 'export' => TRUE,
45a83e42 698 'default' => '0',
522a26c9 699 'table_name' => 'civicrm_contribution',
700 'entity' => 'Contribution',
701 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 702 'localizable' => 0,
c3fc2621 703 'html' => [
e501603b 704 'type' => 'CheckBox',
c3fc2621
CW
705 ],
706 ],
707 'contribution_status_id' => [
e501603b
TO
708 'name' => 'contribution_status_id',
709 'type' => CRM_Utils_Type::T_INT,
c3fc2621
CW
710 'title' => ts('Contribution Status ID'),
711 'import' => TRUE,
e501603b
TO
712 'where' => 'civicrm_contribution.contribution_status_id',
713 'headerPattern' => '/status/i',
c3fc2621 714 'export' => TRUE,
e501603b 715 'default' => '1',
522a26c9 716 'table_name' => 'civicrm_contribution',
717 'entity' => 'Contribution',
718 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 719 'localizable' => 0,
c3fc2621 720 'html' => [
e501603b 721 'type' => 'Select',
c3fc2621
CW
722 ],
723 'pseudoconstant' => [
e501603b
TO
724 'optionGroupName' => 'contribution_status',
725 'optionEditPath' => 'civicrm/admin/options/contribution_status',
c3fc2621
CW
726 ]
727 ],
728 'contribution_address_id' => [
e501603b
TO
729 'name' => 'address_id',
730 'type' => CRM_Utils_Type::T_INT,
c3fc2621 731 'title' => ts('Contribution Address'),
215b423e 732 'description' => ts('Conditional foreign key to civicrm_address.id. We insert an address record for each contribution when we have associated billing name and address data.'),
3123273f 733 'where' => 'civicrm_contribution.address_id',
a36434b9 734 'export' => TRUE,
522a26c9 735 'table_name' => 'civicrm_contribution',
736 'entity' => 'Contribution',
737 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 738 'localizable' => 0,
e501603b 739 'FKClassName' => 'CRM_Core_DAO_Address',
c3fc2621
CW
740 ],
741 'contribution_check_number' => [
e501603b
TO
742 'name' => 'check_number',
743 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 744 'title' => ts('Check Number'),
e501603b
TO
745 'maxlength' => 255,
746 'size' => 6,
c3fc2621 747 'import' => TRUE,
e501603b
TO
748 'where' => 'civicrm_contribution.check_number',
749 'headerPattern' => '/check(.?number)?/i',
c3fc2621 750 'export' => TRUE,
522a26c9 751 'table_name' => 'civicrm_contribution',
752 'entity' => 'Contribution',
753 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 754 'localizable' => 0,
c3fc2621 755 'html' => [
e501603b 756 'type' => 'Text',
c3fc2621
CW
757 ],
758 ],
759 'contribution_campaign_id' => [
e501603b
TO
760 'name' => 'campaign_id',
761 'type' => CRM_Utils_Type::T_INT,
c3fc2621 762 'title' => ts('Campaign'),
215b423e 763 'description' => ts('The campaign for which this contribution has been triggered.'),
c3fc2621 764 'import' => TRUE,
e501603b 765 'where' => 'civicrm_contribution.campaign_id',
c3fc2621 766 'export' => TRUE,
522a26c9 767 'table_name' => 'civicrm_contribution',
768 'entity' => 'Contribution',
769 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 770 'localizable' => 0,
e501603b 771 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
c3fc2621 772 'html' => [
e501603b 773 'type' => 'Select',
c3fc2621
CW
774 ],
775 'pseudoconstant' => [
e501603b
TO
776 'table' => 'civicrm_campaign',
777 'keyColumn' => 'id',
778 'labelColumn' => 'title',
c3fc2621
CW
779 ]
780 ],
781 'creditnote_id' => [
e501603b
TO
782 'name' => 'creditnote_id',
783 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 784 'title' => ts('Credit Note ID'),
215b423e 785 'description' => ts('unique credit note id, system generated or passed in'),
e501603b
TO
786 'maxlength' => 255,
787 'size' => CRM_Utils_Type::HUGE,
c3fc2621 788 'import' => TRUE,
e501603b
TO
789 'where' => 'civicrm_contribution.creditnote_id',
790 'headerPattern' => '/creditnote(.?id)?/i',
c3fc2621 791 'export' => TRUE,
522a26c9 792 'table_name' => 'civicrm_contribution',
793 'entity' => 'Contribution',
794 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 795 'localizable' => 0,
c3fc2621 796 'html' => [
e501603b 797 'type' => 'Text',
c3fc2621
CW
798 ],
799 ],
800 'tax_amount' => [
e501603b
TO
801 'name' => 'tax_amount',
802 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 803 'title' => ts('Tax Amount'),
215b423e 804 'description' => ts('Total tax amount of this contribution.'),
c3fc2621 805 'precision' => [
e501603b
TO
806 20,
807 2
c3fc2621
CW
808 ],
809 'import' => TRUE,
e501603b
TO
810 'where' => 'civicrm_contribution.tax_amount',
811 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
812 'dataPattern' => '/^\d+(\.\d{2})?$/',
c3fc2621 813 'export' => TRUE,
522a26c9 814 'table_name' => 'civicrm_contribution',
815 'entity' => 'Contribution',
816 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 817 'localizable' => 0,
c3fc2621 818 'html' => [
e501603b 819 'type' => 'Text',
c3fc2621
CW
820 ],
821 ],
822 'revenue_recognition_date' => [
e501603b
TO
823 'name' => 'revenue_recognition_date',
824 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
c3fc2621 825 'title' => ts('Revenue Recognition Date'),
215b423e 826 'description' => ts('Stores the date when revenue should be recognized.'),
c3fc2621 827 'import' => TRUE,
e501603b
TO
828 'where' => 'civicrm_contribution.revenue_recognition_date',
829 'headerPattern' => '/revenue(.?date)?/i',
830 'dataPattern' => '/^\d{4}-?\d{2}-?\d{2} ?(\d{2}:?\d{2}:?(\d{2})?)?$/',
c3fc2621 831 'export' => TRUE,
522a26c9 832 'table_name' => 'civicrm_contribution',
833 'entity' => 'Contribution',
834 'bao' => 'CRM_Contribute_BAO_Contribution',
6a7e5e5d 835 'localizable' => 0,
c3fc2621 836 'html' => [
e501603b 837 'type' => 'Select Date',
24317d89 838 'formatType' => 'activityDateTime',
c3fc2621
CW
839 ],
840 ],
841 ];
346aaaba 842 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 843 }
346aaaba 844 return Civi::$statics[__CLASS__]['fields'];
e501603b 845 }
c3fc2621 846
e501603b 847 /**
bd8e0b14 848 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
849 *
850 * @return array
bd8e0b14 851 * Array(string $name => string $uniqueName).
e501603b 852 */
c3fc2621 853 public static function &fieldKeys() {
bd8e0b14
TO
854 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
855 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 856 }
bd8e0b14 857 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 858 }
c3fc2621 859
e501603b
TO
860 /**
861 * Returns the names of this table
862 *
863 * @return string
864 */
c3fc2621 865 public static function getTableName() {
e501603b
TO
866 return self::$_tableName;
867 }
c3fc2621 868
e501603b
TO
869 /**
870 * Returns if this table needs to be logged
871 *
c3fc2621 872 * @return bool
e501603b 873 */
c3fc2621 874 public function getLog() {
e501603b
TO
875 return self::$_log;
876 }
c3fc2621 877
e501603b
TO
878 /**
879 * Returns the list of fields that can be imported
880 *
881 * @param bool $prefix
882 *
883 * @return array
884 */
c3fc2621
CW
885 public static function &import($prefix = FALSE) {
886 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'contribution', $prefix, []);
60808919 887 return $r;
e501603b 888 }
c3fc2621 889
e501603b
TO
890 /**
891 * Returns the list of fields that can be exported
892 *
893 * @param bool $prefix
894 *
895 * @return array
896 */
c3fc2621
CW
897 public static function &export($prefix = FALSE) {
898 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'contribution', $prefix, []);
60808919 899 return $r;
e501603b 900 }
c3fc2621 901
e7a6b91a
AS
902 /**
903 * Returns the list of indices
c3fc2621
CW
904 *
905 * @param bool $localize
906 *
907 * @return array
e7a6b91a
AS
908 */
909 public static function indices($localize = TRUE) {
c3fc2621
CW
910 $indices = [
911 'UI_contrib_payment_instrument_id' => [
e7a6b91a 912 'name' => 'UI_contrib_payment_instrument_id',
c3fc2621 913 'field' => [
e7a6b91a 914 0 => 'payment_instrument_id',
c3fc2621
CW
915 ],
916 'localizable' => FALSE,
e7a6b91a 917 'sig' => 'civicrm_contribution::0::payment_instrument_id',
c3fc2621
CW
918 ],
919 'index_total_amount_receive_date' => [
e7a6b91a 920 'name' => 'index_total_amount_receive_date',
c3fc2621 921 'field' => [
e7a6b91a
AS
922 0 => 'total_amount',
923 1 => 'receive_date',
c3fc2621
CW
924 ],
925 'localizable' => FALSE,
e7a6b91a 926 'sig' => 'civicrm_contribution::0::total_amount::receive_date',
c3fc2621
CW
927 ],
928 'index_source' => [
e7a6b91a 929 'name' => 'index_source',
c3fc2621 930 'field' => [
e7a6b91a 931 0 => 'source',
c3fc2621
CW
932 ],
933 'localizable' => FALSE,
e7a6b91a 934 'sig' => 'civicrm_contribution::0::source',
c3fc2621
CW
935 ],
936 'UI_contrib_trxn_id' => [
e7a6b91a 937 'name' => 'UI_contrib_trxn_id',
c3fc2621 938 'field' => [
e7a6b91a 939 0 => 'trxn_id',
c3fc2621
CW
940 ],
941 'localizable' => FALSE,
942 'unique' => TRUE,
e7a6b91a 943 'sig' => 'civicrm_contribution::1::trxn_id',
c3fc2621
CW
944 ],
945 'UI_contrib_invoice_id' => [
e7a6b91a 946 'name' => 'UI_contrib_invoice_id',
c3fc2621 947 'field' => [
e7a6b91a 948 0 => 'invoice_id',
c3fc2621
CW
949 ],
950 'localizable' => FALSE,
951 'unique' => TRUE,
e7a6b91a 952 'sig' => 'civicrm_contribution::1::invoice_id',
c3fc2621
CW
953 ],
954 'index_contribution_status' => [
e7a6b91a 955 'name' => 'index_contribution_status',
c3fc2621 956 'field' => [
e7a6b91a 957 0 => 'contribution_status_id',
c3fc2621
CW
958 ],
959 'localizable' => FALSE,
e7a6b91a 960 'sig' => 'civicrm_contribution::0::contribution_status_id',
c3fc2621
CW
961 ],
962 'received_date' => [
e7a6b91a 963 'name' => 'received_date',
c3fc2621 964 'field' => [
e7a6b91a 965 0 => 'receive_date',
c3fc2621
CW
966 ],
967 'localizable' => FALSE,
e7a6b91a 968 'sig' => 'civicrm_contribution::0::receive_date',
c3fc2621
CW
969 ],
970 'check_number' => [
e7a6b91a 971 'name' => 'check_number',
c3fc2621 972 'field' => [
e7a6b91a 973 0 => 'check_number',
c3fc2621
CW
974 ],
975 'localizable' => FALSE,
e7a6b91a 976 'sig' => 'civicrm_contribution::0::check_number',
c3fc2621
CW
977 ],
978 'index_creditnote_id' => [
e7a6b91a 979 'name' => 'index_creditnote_id',
c3fc2621 980 'field' => [
e7a6b91a 981 0 => 'creditnote_id',
c3fc2621
CW
982 ],
983 'localizable' => FALSE,
e7a6b91a 984 'sig' => 'civicrm_contribution::0::creditnote_id',
c3fc2621
CW
985 ],
986 ];
e7a6b91a
AS
987 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
988 }
c3fc2621 989
e501603b 990}