5 * @copyright CiviCRM LLC (c) 2004-2019
7 * Generated from xml/schema/CRM/Contribute/ContributionRecur.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:f88b64f09ed0362f6d630038f0a47686)
13 * Database access object for the ContributionRecur entity.
15 class CRM_Contribute_DAO_ContributionRecur
extends CRM_Core_DAO
{
18 * Static instance to hold the table name.
22 public static $_tableName = 'civicrm_contribution_recur';
25 * Should CiviCRM log any modifications to this table in the civicrm_log table.
29 public static $_log = TRUE;
32 * Contribution Recur ID
39 * Foreign key to civicrm_contact.id.
46 * Amount to be contributed or charged each recurrence.
53 * 3 character string, value from config setting or input via user.
60 * Time units for recurrence of payment.
64 public $frequency_unit;
67 * Number of time units for recurrence of payment.
71 public $frequency_interval;
74 * Total number of payments to be made. Set this to 0 if this is an open-ended commitment i.e. no set end date.
81 * The date the first scheduled recurring contribution occurs.
88 * When this recurring contribution record was created.
95 * Last updated date for this record. mostly the last time a payment was received
99 public $modified_date;
102 * Date this recurring contribution was cancelled by contributor- if we can get access to it
109 * Free text field for a reason for cancelling
113 public $cancel_reason;
116 * Date this recurring contribution finished successfully
123 * Possibly needed to store a unique identifier for this recurring payment order - if this is available from the processor??
127 public $processor_id;
130 * Optionally used to store a link to a payment token used for this recurring contribution.
134 public $payment_token_id;
137 * unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method
144 * unique invoice id, system generated or passed in
153 public $contribution_status_id;
161 * Day in the period when the payment should be charged e.g. 1st of month, 15th etc.
168 * Next scheduled date
172 public $next_sched_contribution_date;
175 * Number of failed charge attempts since last success. Business rule could be set to deactivate on more than x failures.
179 public $failure_count;
182 * Date to retry failed attempt
186 public $failure_retry_date;
189 * Some systems allow contributor to set a number of installments - but then auto-renew the subscription or commitment if they do not cancel.
196 * Foreign key to civicrm_payment_processor.id
200 public $payment_processor_id;
203 * FK to Financial Type
207 public $financial_type_id;
210 * FK to Payment Instrument
214 public $payment_instrument_id;
217 * The campaign for which this contribution has been triggered.
224 * if true, receipt is automatically emailed to contact on each successful payment
228 public $is_email_receipt;
233 public function __construct() {
234 $this->__table
= 'civicrm_contribution_recur';
235 parent
::__construct();
239 * Returns foreign keys and entity references.
242 * [CRM_Core_Reference_Interface]
244 public static function getReferenceColumns() {
245 if (!isset(Civi
::$statics[__CLASS__
]['links'])) {
246 Civi
::$statics[__CLASS__
]['links'] = static::createReferenceColumns(__CLASS__
);
247 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'contact_id', 'civicrm_contact', 'id');
248 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'payment_token_id', 'civicrm_payment_token', 'id');
249 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'payment_processor_id', 'civicrm_payment_processor', 'id');
250 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
251 Civi
::$statics[__CLASS__
]['links'][] = new CRM_Core_Reference_Basic(self
::getTableName(), 'campaign_id', 'civicrm_campaign', 'id');
252 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'links_callback', Civi
::$statics[__CLASS__
]['links']);
254 return Civi
::$statics[__CLASS__
]['links'];
258 * Returns all the column names of this table
262 public static function &fields() {
263 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
264 Civi
::$statics[__CLASS__
]['fields'] = [
265 'contribution_recur_id' => [
267 'type' => CRM_Utils_Type
::T_INT
,
268 'title' => ts('Recurring Contribution ID'),
269 'description' => ts('Contribution Recur ID'),
271 'where' => 'civicrm_contribution_recur.id',
272 'table_name' => 'civicrm_contribution_recur',
273 'entity' => 'ContributionRecur',
274 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
278 'name' => 'contact_id',
279 'type' => CRM_Utils_Type
::T_INT
,
280 'title' => ts('Contact'),
281 'description' => ts('Foreign key to civicrm_contact.id.'),
283 'where' => 'civicrm_contribution_recur.contact_id',
284 'table_name' => 'civicrm_contribution_recur',
285 'entity' => 'ContributionRecur',
286 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
288 'FKClassName' => 'CRM_Contact_DAO_Contact',
290 'type' => 'EntityRef',
295 'type' => CRM_Utils_Type
::T_MONEY
,
296 'title' => ts('Amount'),
297 'description' => ts('Amount to be contributed or charged each recurrence.'),
303 'where' => 'civicrm_contribution_recur.amount',
304 'table_name' => 'civicrm_contribution_recur',
305 'entity' => 'ContributionRecur',
306 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
313 'name' => 'currency',
314 'type' => CRM_Utils_Type
::T_STRING
,
315 'title' => ts('Currency'),
316 'description' => ts('3 character string, value from config setting or input via user.'),
318 'size' => CRM_Utils_Type
::FOUR
,
319 'where' => 'civicrm_contribution_recur.currency',
321 'table_name' => 'civicrm_contribution_recur',
322 'entity' => 'ContributionRecur',
323 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
328 'pseudoconstant' => [
329 'table' => 'civicrm_currency',
330 'keyColumn' => 'name',
331 'labelColumn' => 'full_name',
332 'nameColumn' => 'name',
333 'abbrColumn' => 'symbol',
336 'frequency_unit' => [
337 'name' => 'frequency_unit',
338 'type' => CRM_Utils_Type
::T_STRING
,
339 'title' => ts('Frequency Unit'),
340 'description' => ts('Time units for recurrence of payment.'),
342 'size' => CRM_Utils_Type
::EIGHT
,
343 'where' => 'civicrm_contribution_recur.frequency_unit',
344 'default' => 'month',
345 'table_name' => 'civicrm_contribution_recur',
346 'entity' => 'ContributionRecur',
347 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
352 'pseudoconstant' => [
353 'optionGroupName' => 'recur_frequency_units',
354 'keyColumn' => 'name',
355 'optionEditPath' => 'civicrm/admin/options/recur_frequency_units',
358 'frequency_interval' => [
359 'name' => 'frequency_interval',
360 'type' => CRM_Utils_Type
::T_INT
,
361 'title' => ts('Interval (number of units)'),
362 'description' => ts('Number of time units for recurrence of payment.'),
364 'where' => 'civicrm_contribution_recur.frequency_interval',
365 'table_name' => 'civicrm_contribution_recur',
366 'entity' => 'ContributionRecur',
367 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
374 'name' => 'installments',
375 'type' => CRM_Utils_Type
::T_INT
,
376 'title' => ts('Number of Installments'),
377 'description' => ts('Total number of payments to be made. Set this to 0 if this is an open-ended commitment i.e. no set end date.'),
378 'where' => 'civicrm_contribution_recur.installments',
379 'table_name' => 'civicrm_contribution_recur',
380 'entity' => 'ContributionRecur',
381 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
387 'contribution_recur_start_date' => [
388 'name' => 'start_date',
389 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
390 'title' => ts('Start Date'),
391 'description' => ts('The date the first scheduled recurring contribution occurs.'),
393 'where' => 'civicrm_contribution_recur.start_date',
394 'table_name' => 'civicrm_contribution_recur',
395 'entity' => 'ContributionRecur',
396 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
398 'unique_title' => ts('Recurring Contribution Start Date'),
400 'type' => 'Select Date',
401 'formatType' => 'activityDateTime',
404 'contribution_recur_create_date' => [
405 'name' => 'create_date',
406 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
407 'title' => ts('Created Date'),
408 'description' => ts('When this recurring contribution record was created.'),
410 'where' => 'civicrm_contribution_recur.create_date',
411 'table_name' => 'civicrm_contribution_recur',
412 'entity' => 'ContributionRecur',
413 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
415 'unique_title' => ts('Recurring Contribution Create Date'),
417 'type' => 'Select Date',
418 'formatType' => 'activityDateTime',
421 'contribution_recur_modified_date' => [
422 'name' => 'modified_date',
423 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
424 'title' => ts('Modified Date'),
425 'description' => ts('Last updated date for this record. mostly the last time a payment was received'),
426 'where' => 'civicrm_contribution_recur.modified_date',
427 'table_name' => 'civicrm_contribution_recur',
428 'entity' => 'ContributionRecur',
429 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
431 'unique_title' => ts('Recurring Contribution Modified Date'),
433 'type' => 'Select Date',
434 'formatType' => 'activityDateTime',
437 'contribution_recur_cancel_date' => [
438 'name' => 'cancel_date',
439 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
440 'title' => ts('Cancel Date'),
441 'description' => ts('Date this recurring contribution was cancelled by contributor- if we can get access to it'),
442 'where' => 'civicrm_contribution_recur.cancel_date',
443 'table_name' => 'civicrm_contribution_recur',
444 'entity' => 'ContributionRecur',
445 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
447 'unique_title' => ts('Recurring Contribution Cancel Date'),
449 'type' => 'Select Date',
450 'formatType' => 'activityDate',
453 'contribution_recur_cancel_reason' => [
454 'name' => 'cancel_reason',
455 'type' => CRM_Utils_Type
::T_TEXT
,
456 'title' => ts('Cancellation Reason'),
457 'description' => ts('Free text field for a reason for cancelling'),
458 'where' => 'civicrm_contribution_recur.cancel_reason',
459 'table_name' => 'civicrm_contribution_recur',
460 'entity' => 'ContributionRecur',
461 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
463 'unique_title' => ts('Recurring Contribution Cancel Reason'),
468 'contribution_recur_end_date' => [
469 'name' => 'end_date',
470 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
471 'title' => ts('Recurring Contribution End Date'),
472 'description' => ts('Date this recurring contribution finished successfully'),
473 'where' => 'civicrm_contribution_recur.end_date',
474 'table_name' => 'civicrm_contribution_recur',
475 'entity' => 'ContributionRecur',
476 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
478 'unique_title' => ts('Recurring Contribution End Date'),
480 'type' => 'Select Date',
481 'formatType' => 'activityDate',
484 'contribution_recur_processor_id' => [
485 'name' => 'processor_id',
486 'type' => CRM_Utils_Type
::T_STRING
,
487 'title' => ts('Processor ID'),
488 'description' => ts('Possibly needed to store a unique identifier for this recurring payment order - if this is available from the processor??'),
490 'size' => CRM_Utils_Type
::HUGE
,
491 'where' => 'civicrm_contribution_recur.processor_id',
492 'table_name' => 'civicrm_contribution_recur',
493 'entity' => 'ContributionRecur',
494 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
500 'payment_token_id' => [
501 'name' => 'payment_token_id',
502 'type' => CRM_Utils_Type
::T_INT
,
503 'title' => ts('Payment Token ID'),
504 'description' => ts('Optionally used to store a link to a payment token used for this recurring contribution.'),
505 'where' => 'civicrm_contribution_recur.payment_token_id',
506 'table_name' => 'civicrm_contribution_recur',
507 'entity' => 'ContributionRecur',
508 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
510 'FKClassName' => 'CRM_Financial_DAO_PaymentToken',
512 'contribution_recur_trxn_id' => [
514 'type' => CRM_Utils_Type
::T_STRING
,
515 'title' => ts('Transaction ID'),
516 'description' => ts('unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method'),
518 'size' => CRM_Utils_Type
::HUGE
,
519 'where' => 'civicrm_contribution_recur.trxn_id',
520 'table_name' => 'civicrm_contribution_recur',
521 'entity' => 'ContributionRecur',
522 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
529 'name' => 'invoice_id',
530 'type' => CRM_Utils_Type
::T_STRING
,
531 'title' => ts('Invoice ID'),
532 'description' => ts('unique invoice id, system generated or passed in'),
534 'size' => CRM_Utils_Type
::HUGE
,
535 'where' => 'civicrm_contribution_recur.invoice_id',
536 'table_name' => 'civicrm_contribution_recur',
537 'entity' => 'ContributionRecur',
538 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
544 'contribution_recur_contribution_status_id' => [
545 'name' => 'contribution_status_id',
546 'type' => CRM_Utils_Type
::T_INT
,
547 'title' => ts('Status'),
549 'where' => 'civicrm_contribution_recur.contribution_status_id',
552 'table_name' => 'civicrm_contribution_recur',
553 'entity' => 'ContributionRecur',
554 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
559 'pseudoconstant' => [
560 'optionGroupName' => 'contribution_recur_status',
561 'optionEditPath' => 'civicrm/admin/options/contribution_recur_status',
566 'type' => CRM_Utils_Type
::T_BOOLEAN
,
567 'title' => ts('Test'),
569 'where' => 'civicrm_contribution_recur.is_test',
572 'table_name' => 'civicrm_contribution_recur',
573 'entity' => 'ContributionRecur',
574 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
577 'type' => 'CheckBox',
581 'name' => 'cycle_day',
582 'type' => CRM_Utils_Type
::T_INT
,
583 'title' => ts('Cycle Day'),
584 'description' => ts('Day in the period when the payment should be charged e.g. 1st of month, 15th etc.'),
586 'where' => 'civicrm_contribution_recur.cycle_day',
588 'table_name' => 'civicrm_contribution_recur',
589 'entity' => 'ContributionRecur',
590 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
596 'contribution_recur_next_sched_contribution_date' => [
597 'name' => 'next_sched_contribution_date',
598 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
599 'title' => ts('Next Scheduled Contribution Date'),
600 'description' => ts('Next scheduled date'),
601 'where' => 'civicrm_contribution_recur.next_sched_contribution_date',
602 'table_name' => 'civicrm_contribution_recur',
603 'entity' => 'ContributionRecur',
604 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
606 'unique_title' => ts('Next Scheduled Recurring Contribution'),
608 'type' => 'Select Date',
609 'formatType' => 'activityDate',
613 'name' => 'failure_count',
614 'type' => CRM_Utils_Type
::T_INT
,
615 'title' => ts('Number of Failures'),
616 'description' => ts('Number of failed charge attempts since last success. Business rule could be set to deactivate on more than x failures.'),
617 'where' => 'civicrm_contribution_recur.failure_count',
619 'table_name' => 'civicrm_contribution_recur',
620 'entity' => 'ContributionRecur',
621 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
627 'contribution_recur_failure_retry_date' => [
628 'name' => 'failure_retry_date',
629 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
630 'title' => ts('Retry Failed Attempt Date'),
631 'description' => ts('Date to retry failed attempt'),
632 'where' => 'civicrm_contribution_recur.failure_retry_date',
633 'table_name' => 'civicrm_contribution_recur',
634 'entity' => 'ContributionRecur',
635 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
637 'unique_title' => ts('Failed Recurring Contribution Retry Date'),
639 'type' => 'Select Date',
640 'formatType' => 'activityDate',
644 'name' => 'auto_renew',
645 'type' => CRM_Utils_Type
::T_BOOLEAN
,
646 'title' => ts('Auto Renew'),
647 'description' => ts('Some systems allow contributor to set a number of installments - but then auto-renew the subscription or commitment if they do not cancel.'),
649 'where' => 'civicrm_contribution_recur.auto_renew',
651 'table_name' => 'civicrm_contribution_recur',
652 'entity' => 'ContributionRecur',
653 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
656 'type' => 'CheckBox',
659 'contribution_recur_payment_processor_id' => [
660 'name' => 'payment_processor_id',
661 'type' => CRM_Utils_Type
::T_INT
,
662 'title' => ts('Payment Processor'),
663 'description' => ts('Foreign key to civicrm_payment_processor.id'),
664 'where' => 'civicrm_contribution_recur.payment_processor_id',
665 'table_name' => 'civicrm_contribution_recur',
666 'entity' => 'ContributionRecur',
667 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
669 'FKClassName' => 'CRM_Financial_DAO_PaymentProcessor',
673 'pseudoconstant' => [
674 'table' => 'civicrm_payment_processor',
676 'labelColumn' => 'name',
679 'financial_type_id' => [
680 'name' => 'financial_type_id',
681 'type' => CRM_Utils_Type
::T_INT
,
682 'title' => ts('Financial Type'),
683 'description' => ts('FK to Financial Type'),
684 'where' => 'civicrm_contribution_recur.financial_type_id',
686 'table_name' => 'civicrm_contribution_recur',
687 'entity' => 'ContributionRecur',
688 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
690 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
694 'pseudoconstant' => [
695 'table' => 'civicrm_financial_type',
697 'labelColumn' => 'name',
700 'payment_instrument_id' => [
701 'name' => 'payment_instrument_id',
702 'type' => CRM_Utils_Type
::T_INT
,
703 'title' => ts('Payment Method'),
704 'description' => ts('FK to Payment Instrument'),
705 'where' => 'civicrm_contribution_recur.payment_instrument_id',
706 'table_name' => 'civicrm_contribution_recur',
707 'entity' => 'ContributionRecur',
708 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
713 'pseudoconstant' => [
714 'optionGroupName' => 'payment_instrument',
715 'optionEditPath' => 'civicrm/admin/options/payment_instrument',
718 'contribution_campaign_id' => [
719 'name' => 'campaign_id',
720 'type' => CRM_Utils_Type
::T_INT
,
721 'title' => ts('Campaign'),
722 'description' => ts('The campaign for which this contribution has been triggered.'),
724 'where' => 'civicrm_contribution_recur.campaign_id',
726 'table_name' => 'civicrm_contribution_recur',
727 'entity' => 'ContributionRecur',
728 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
730 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
734 'pseudoconstant' => [
735 'table' => 'civicrm_campaign',
737 'labelColumn' => 'title',
740 'is_email_receipt' => [
741 'name' => 'is_email_receipt',
742 'type' => CRM_Utils_Type
::T_BOOLEAN
,
743 'title' => ts('Send email Receipt?'),
744 'description' => ts('if true, receipt is automatically emailed to contact on each successful payment'),
745 'where' => 'civicrm_contribution_recur.is_email_receipt',
747 'table_name' => 'civicrm_contribution_recur',
748 'entity' => 'ContributionRecur',
749 'bao' => 'CRM_Contribute_BAO_ContributionRecur',
752 'type' => 'CheckBox',
756 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
758 return Civi
::$statics[__CLASS__
]['fields'];
762 * Return a mapping from field-name to the corresponding key (as used in fields()).
765 * Array(string $name => string $uniqueName).
767 public static function &fieldKeys() {
768 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
769 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
771 return Civi
::$statics[__CLASS__
]['fieldKeys'];
775 * Returns the names of this table
779 public static function getTableName() {
780 return self
::$_tableName;
784 * Returns if this table needs to be logged
788 public function getLog() {
793 * Returns the list of fields that can be imported
795 * @param bool $prefix
799 public static function &import($prefix = FALSE) {
800 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'contribution_recur', $prefix, []);
805 * Returns the list of fields that can be exported
807 * @param bool $prefix
811 public static function &export($prefix = FALSE) {
812 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'contribution_recur', $prefix, []);
817 * Returns the list of indices
819 * @param bool $localize
823 public static function indices($localize = TRUE) {
825 'UI_contrib_trxn_id' => [
826 'name' => 'UI_contrib_trxn_id',
830 'localizable' => FALSE,
832 'sig' => 'civicrm_contribution_recur::1::trxn_id',
834 'UI_contrib_invoice_id' => [
835 'name' => 'UI_contrib_invoice_id',
839 'localizable' => FALSE,
841 'sig' => 'civicrm_contribution_recur::1::invoice_id',
843 'index_contribution_status' => [
844 'name' => 'index_contribution_status',
846 0 => 'contribution_status_id',
848 'localizable' => FALSE,
849 'sig' => 'civicrm_contribution_recur::0::contribution_status_id',
851 'UI_contribution_recur_payment_instrument_id' => [
852 'name' => 'UI_contribution_recur_payment_instrument_id',
854 0 => 'payment_instrument_id',
856 'localizable' => FALSE,
857 'sig' => 'civicrm_contribution_recur::0::payment_instrument_id',
860 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;