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