3369ccdec41fb25558028870e72529862df7e7fc
[civicrm-core.git] / CRM / Contribute / DAO / ContributionRecur.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27 /**
28 * @package CRM
29 * @copyright CiviCRM LLC (c) 2004-2016
30 *
31 * Generated from xml/schema/CRM/Contribute/ContributionRecur.xml
32 * DO NOT EDIT. Generated by CRM_Core_CodeGen
33 * (GenCodeChecksum:fe7fe63ae2bf5e2e2c1f9e2449d5bda6)
34 */
35 require_once 'CRM/Core/DAO.php';
36 require_once 'CRM/Utils/Type.php';
37 class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO {
38 /**
39 * static instance to hold the table name
40 *
41 * @var string
42 */
43 static $_tableName = 'civicrm_contribution_recur';
44 /**
45 * static instance to hold the field values
46 *
47 * @var array
48 */
49 static $_fields = null;
50 /**
51 * static instance to hold the keys used in $_fields for each field.
52 *
53 * @var array
54 */
55 static $_fieldKeys = null;
56 /**
57 * static instance to hold the FK relationships
58 *
59 * @var string
60 */
61 static $_links = null;
62 /**
63 * static instance to hold the values that can
64 * be imported
65 *
66 * @var array
67 */
68 static $_import = null;
69 /**
70 * static instance to hold the values that can
71 * be exported
72 *
73 * @var array
74 */
75 static $_export = null;
76 /**
77 * static value to see if we should log any modifications to
78 * this table in the civicrm_log table
79 *
80 * @var boolean
81 */
82 static $_log = true;
83 /**
84 * Contribution Recur ID
85 *
86 * @var int unsigned
87 */
88 public $id;
89 /**
90 * Foreign key to civicrm_contact.id .
91 *
92 * @var int unsigned
93 */
94 public $contact_id;
95 /**
96 * Amount to be contributed or charged each recurrence.
97 *
98 * @var float
99 */
100 public $amount;
101 /**
102 * 3 character string, value from config setting or input via user.
103 *
104 * @var string
105 */
106 public $currency;
107 /**
108 * Time units for recurrence of payment.
109 *
110 * @var string
111 */
112 public $frequency_unit;
113 /**
114 * Number of time units for recurrence of payment.
115 *
116 * @var int unsigned
117 */
118 public $frequency_interval;
119 /**
120 * Total number of payments to be made. Set this to 0 if this is an open-ended commitment i.e. no set end date.
121 *
122 * @var int unsigned
123 */
124 public $installments;
125 /**
126 * The date the first scheduled recurring contribution occurs.
127 *
128 * @var datetime
129 */
130 public $start_date;
131 /**
132 * When this recurring contribution record was created.
133 *
134 * @var datetime
135 */
136 public $create_date;
137 /**
138 * Last updated date for this record. mostly the last time a payment was received
139 *
140 * @var datetime
141 */
142 public $modified_date;
143 /**
144 * Date this recurring contribution was cancelled by contributor- if we can get access to it
145 *
146 * @var datetime
147 */
148 public $cancel_date;
149 /**
150 * Date this recurring contribution finished successfully
151 *
152 * @var datetime
153 */
154 public $end_date;
155 /**
156 * Possibly needed to store a unique identifier for this recurring payment order - if this is available from the processor??
157 *
158 * @var string
159 */
160 public $processor_id;
161 /**
162 * Optionally used to store a link to a payment token used for this recurring contribution.
163 *
164 * @var int unsigned
165 */
166 public $payment_token_id;
167 /**
168 * unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method
169 *
170 * @var string
171 */
172 public $trxn_id;
173 /**
174 * unique invoice id, system generated or passed in
175 *
176 * @var string
177 */
178 public $invoice_id;
179 /**
180 *
181 * @var int unsigned
182 */
183 public $contribution_status_id;
184 /**
185 *
186 * @var boolean
187 */
188 public $is_test;
189 /**
190 * Day in the period when the payment should be charged e.g. 1st of month, 15th etc.
191 *
192 * @var int unsigned
193 */
194 public $cycle_day;
195 /**
196 * Next scheduled date
197 *
198 * @var datetime
199 */
200 public $next_sched_contribution_date;
201 /**
202 * Number of failed charge attempts since last success. Business rule could be set to deactivate on more than x failures.
203 *
204 * @var int unsigned
205 */
206 public $failure_count;
207 /**
208 * Date to retry failed attempt
209 *
210 * @var datetime
211 */
212 public $failure_retry_date;
213 /**
214 * Some systems allow contributor to set a number of installments - but then auto-renew the subscription or commitment if they do not cancel.
215 *
216 * @var boolean
217 */
218 public $auto_renew;
219 /**
220 * Foreign key to civicrm_payment_processor.id
221 *
222 * @var int unsigned
223 */
224 public $payment_processor_id;
225 /**
226 * FK to Financial Type
227 *
228 * @var int unsigned
229 */
230 public $financial_type_id;
231 /**
232 * FK to Payment Instrument
233 *
234 * @var int unsigned
235 */
236 public $payment_instrument_id;
237 /**
238 * The campaign for which this contribution has been triggered.
239 *
240 * @var int unsigned
241 */
242 public $campaign_id;
243 /**
244 * if true, receipt is automatically emailed to contact on each successful payment
245 *
246 * @var boolean
247 */
248 public $is_email_receipt;
249 /**
250 * class constructor
251 *
252 * @return civicrm_contribution_recur
253 */
254 function __construct() {
255 $this->__table = 'civicrm_contribution_recur';
256 parent::__construct();
257 }
258 /**
259 * Returns foreign keys and entity references
260 *
261 * @return array
262 * [CRM_Core_Reference_Interface]
263 */
264 static function getReferenceColumns() {
265 if (!self::$_links) {
266 self::$_links = static ::createReferenceColumns(__CLASS__);
267 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
268 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'payment_token_id', 'civicrm_payment_token', 'id');
269 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'payment_processor_id', 'civicrm_payment_processor', 'id');
270 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
271 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'campaign_id', 'civicrm_campaign', 'id');
272 }
273 return self::$_links;
274 }
275 /**
276 * Returns all the column names of this table
277 *
278 * @return array
279 */
280 static function &fields() {
281 if (!(self::$_fields)) {
282 self::$_fields = array(
283 'id' => array(
284 'name' => 'id',
285 'type' => CRM_Utils_Type::T_INT,
286 'title' => ts('Recurring Contribution ID') ,
287 'description' => 'Contribution Recur ID',
288 'required' => true,
289 ) ,
290 'contact_id' => array(
291 'name' => 'contact_id',
292 'type' => CRM_Utils_Type::T_INT,
293 'title' => ts('Contact ID') ,
294 'description' => 'Foreign key to civicrm_contact.id .',
295 'required' => true,
296 'FKClassName' => 'CRM_Contact_DAO_Contact',
297 ) ,
298 'amount' => array(
299 'name' => 'amount',
300 'type' => CRM_Utils_Type::T_MONEY,
301 'title' => ts('Amount') ,
302 'description' => 'Amount to be contributed or charged each recurrence.',
303 'required' => true,
304 'precision' => array(
305 20,
306 2
307 ) ,
308 'html' => array(
309 'type' => 'Text',
310 ) ,
311 ) ,
312 'currency' => array(
313 'name' => 'currency',
314 'type' => CRM_Utils_Type::T_STRING,
315 'title' => ts('Currency') ,
316 'description' => '3 character string, value from config setting or input via user.',
317 'maxlength' => 3,
318 'size' => CRM_Utils_Type::FOUR,
319 'default' => 'NULL',
320 'html' => array(
321 'type' => 'Select',
322 ) ,
323 'pseudoconstant' => array(
324 'table' => 'civicrm_currency',
325 'keyColumn' => 'name',
326 'labelColumn' => 'full_name',
327 'nameColumn' => 'name',
328 )
329 ) ,
330 'frequency_unit' => array(
331 'name' => 'frequency_unit',
332 'type' => CRM_Utils_Type::T_STRING,
333 'title' => ts('Frequency Unit') ,
334 'description' => 'Time units for recurrence of payment.',
335 'maxlength' => 8,
336 'size' => CRM_Utils_Type::EIGHT,
337 'default' => 'month',
338 'html' => array(
339 'type' => 'Select',
340 ) ,
341 'pseudoconstant' => array(
342 'optionGroupName' => 'recur_frequency_units',
343 'keyColumn' => 'name',
344 'optionEditPath' => 'civicrm/admin/options/recur_frequency_units',
345 )
346 ) ,
347 'frequency_interval' => array(
348 'name' => 'frequency_interval',
349 'type' => CRM_Utils_Type::T_INT,
350 'title' => ts('Interval (number of units)') ,
351 'description' => 'Number of time units for recurrence of payment.',
352 'required' => true,
353 'html' => array(
354 'type' => 'Text',
355 ) ,
356 ) ,
357 'installments' => array(
358 'name' => 'installments',
359 'type' => CRM_Utils_Type::T_INT,
360 'title' => ts('Number of Installments') ,
361 'description' => 'Total number of payments to be made. Set this to 0 if this is an open-ended commitment i.e. no set end date.',
362 'html' => array(
363 'type' => 'Text',
364 ) ,
365 ) ,
366 'start_date' => array(
367 'name' => 'start_date',
368 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
369 'title' => ts('Recurring Contribution Started Date') ,
370 'description' => 'The date the first scheduled recurring contribution occurs.',
371 'required' => true,
372 'html' => array(
373 'type' => 'Select Date',
374 ) ,
375 ) ,
376 'create_date' => array(
377 'name' => 'create_date',
378 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
379 'title' => ts('Recurring Contribution Created Date') ,
380 'description' => 'When this recurring contribution record was created.',
381 'required' => true,
382 'html' => array(
383 'type' => 'Select Date',
384 ) ,
385 ) ,
386 'modified_date' => array(
387 'name' => 'modified_date',
388 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
389 'title' => ts('Recurring Contribution Modified Date') ,
390 'description' => 'Last updated date for this record. mostly the last time a payment was received',
391 'html' => array(
392 'type' => 'Select Date',
393 ) ,
394 ) ,
395 'cancel_date' => array(
396 'name' => 'cancel_date',
397 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
398 'title' => ts('Recurring Contribution Cancel Date') ,
399 'description' => 'Date this recurring contribution was cancelled by contributor- if we can get access to it',
400 'html' => array(
401 'type' => 'Select Date',
402 ) ,
403 ) ,
404 'end_date' => array(
405 'name' => 'end_date',
406 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
407 'title' => ts('Recurring Contribution End Date') ,
408 'description' => 'Date this recurring contribution finished successfully',
409 'html' => array(
410 'type' => 'Select Date',
411 ) ,
412 ) ,
413 'processor_id' => array(
414 'name' => 'processor_id',
415 'type' => CRM_Utils_Type::T_STRING,
416 'title' => ts('Processor ID') ,
417 'description' => 'Possibly needed to store a unique identifier for this recurring payment order - if this is available from the processor??',
418 'maxlength' => 255,
419 'size' => CRM_Utils_Type::HUGE,
420 ) ,
421 'payment_token_id' => array(
422 'name' => 'payment_token_id',
423 'type' => CRM_Utils_Type::T_INT,
424 'title' => ts('Payment Token ID') ,
425 'description' => 'Optionally used to store a link to a payment token used for this recurring contribution.',
426 'FKClassName' => 'CRM_Financial_DAO_PaymentToken',
427 ) ,
428 'trxn_id' => array(
429 'name' => 'trxn_id',
430 'type' => CRM_Utils_Type::T_STRING,
431 'title' => ts('Transaction ID') ,
432 'description' => 'unique transaction id. may be processor id, bank id + trans id, or account number + check number... depending on payment_method',
433 'maxlength' => 255,
434 'size' => CRM_Utils_Type::HUGE,
435 ) ,
436 'invoice_id' => array(
437 'name' => 'invoice_id',
438 'type' => CRM_Utils_Type::T_STRING,
439 'title' => ts('Invoice ID') ,
440 'description' => 'unique invoice id, system generated or passed in',
441 'maxlength' => 255,
442 'size' => CRM_Utils_Type::HUGE,
443 ) ,
444 'contribution_status_id' => array(
445 'name' => 'contribution_status_id',
446 'type' => CRM_Utils_Type::T_INT,
447 'title' => ts('Recurring Contribution Status') ,
448 'import' => true,
449 'where' => 'civicrm_contribution_recur.contribution_status_id',
450 'headerPattern' => '',
451 'dataPattern' => '',
452 'export' => true,
453 'default' => '1',
454 'pseudoconstant' => array(
455 'optionGroupName' => 'contribution_status',
456 'optionEditPath' => 'civicrm/admin/options/contribution_status',
457 )
458 ) ,
459 'is_test' => array(
460 'name' => 'is_test',
461 'type' => CRM_Utils_Type::T_BOOLEAN,
462 'title' => ts('Test') ,
463 'import' => true,
464 'where' => 'civicrm_contribution_recur.is_test',
465 'headerPattern' => '',
466 'dataPattern' => '',
467 'export' => true,
468 ) ,
469 'cycle_day' => array(
470 'name' => 'cycle_day',
471 'type' => CRM_Utils_Type::T_INT,
472 'title' => ts('Number of Cycle Day') ,
473 'description' => 'Day in the period when the payment should be charged e.g. 1st of month, 15th etc.',
474 'required' => true,
475 'default' => '1',
476 ) ,
477 'next_sched_contribution_date' => array(
478 'name' => 'next_sched_contribution_date',
479 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
480 'title' => ts('Next Scheduled Contribution Date') ,
481 'description' => 'Next scheduled date',
482 'html' => array(
483 'type' => 'Select Date',
484 ) ,
485 ) ,
486 'failure_count' => array(
487 'name' => 'failure_count',
488 'type' => CRM_Utils_Type::T_INT,
489 'title' => ts('Number of Failures') ,
490 'description' => 'Number of failed charge attempts since last success. Business rule could be set to deactivate on more than x failures.',
491 ) ,
492 'failure_retry_date' => array(
493 'name' => 'failure_retry_date',
494 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
495 'title' => ts('Retry Failed Attempt Date') ,
496 'description' => 'Date to retry failed attempt',
497 'html' => array(
498 'type' => 'Select Date',
499 ) ,
500 ) ,
501 'auto_renew' => array(
502 'name' => 'auto_renew',
503 'type' => CRM_Utils_Type::T_BOOLEAN,
504 'title' => ts('Auto Renew') ,
505 'description' => 'Some systems allow contributor to set a number of installments - but then auto-renew the subscription or commitment if they do not cancel.',
506 'required' => true,
507 ) ,
508 'payment_processor_id' => array(
509 'name' => 'payment_processor_id',
510 'type' => CRM_Utils_Type::T_INT,
511 'title' => ts('Payment Processor') ,
512 'description' => 'Foreign key to civicrm_payment_processor.id',
513 'FKClassName' => 'CRM_Financial_DAO_PaymentProcessor',
514 ) ,
515 'financial_type_id' => array(
516 'name' => 'financial_type_id',
517 'type' => CRM_Utils_Type::T_INT,
518 'title' => ts('Financial Type') ,
519 'description' => 'FK to Financial Type',
520 'export' => false,
521 'where' => 'civicrm_contribution_recur.financial_type_id',
522 'headerPattern' => '',
523 'dataPattern' => '',
524 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
525 'pseudoconstant' => array(
526 'table' => 'civicrm_financial_type',
527 'keyColumn' => 'id',
528 'labelColumn' => 'name',
529 )
530 ) ,
531 'payment_instrument_id' => array(
532 'name' => 'payment_instrument_id',
533 'type' => CRM_Utils_Type::T_INT,
534 'title' => ts('Payment Method') ,
535 'description' => 'FK to Payment Instrument',
536 'html' => array(
537 'type' => 'Select',
538 ) ,
539 'pseudoconstant' => array(
540 'optionGroupName' => 'payment_instrument',
541 'optionEditPath' => 'civicrm/admin/options/payment_instrument',
542 )
543 ) ,
544 'contribution_campaign_id' => array(
545 'name' => 'campaign_id',
546 'type' => CRM_Utils_Type::T_INT,
547 'title' => ts('Campaign') ,
548 'description' => 'The campaign for which this contribution has been triggered.',
549 'import' => true,
550 'where' => 'civicrm_contribution_recur.campaign_id',
551 'headerPattern' => '',
552 'dataPattern' => '',
553 'export' => true,
554 'FKClassName' => 'CRM_Campaign_DAO_Campaign',
555 'pseudoconstant' => array(
556 'table' => 'civicrm_campaign',
557 'keyColumn' => 'id',
558 'labelColumn' => 'title',
559 )
560 ) ,
561 'is_email_receipt' => array(
562 'name' => 'is_email_receipt',
563 'type' => CRM_Utils_Type::T_BOOLEAN,
564 'title' => ts('Send email Receipt?') ,
565 'description' => 'if true, receipt is automatically emailed to contact on each successful payment',
566 'default' => '1',
567 ) ,
568 );
569 }
570 return self::$_fields;
571 }
572 /**
573 * Returns an array containing, for each field, the arary key used for that
574 * field in self::$_fields.
575 *
576 * @return array
577 */
578 static function &fieldKeys() {
579 if (!(self::$_fieldKeys)) {
580 self::$_fieldKeys = array(
581 'id' => 'id',
582 'contact_id' => 'contact_id',
583 'amount' => 'amount',
584 'currency' => 'currency',
585 'frequency_unit' => 'frequency_unit',
586 'frequency_interval' => 'frequency_interval',
587 'installments' => 'installments',
588 'start_date' => 'start_date',
589 'create_date' => 'create_date',
590 'modified_date' => 'modified_date',
591 'cancel_date' => 'cancel_date',
592 'end_date' => 'end_date',
593 'processor_id' => 'processor_id',
594 'payment_token_id' => 'payment_token_id',
595 'trxn_id' => 'trxn_id',
596 'invoice_id' => 'invoice_id',
597 'contribution_status_id' => 'contribution_status_id',
598 'is_test' => 'is_test',
599 'cycle_day' => 'cycle_day',
600 'next_sched_contribution_date' => 'next_sched_contribution_date',
601 'failure_count' => 'failure_count',
602 'failure_retry_date' => 'failure_retry_date',
603 'auto_renew' => 'auto_renew',
604 'payment_processor_id' => 'payment_processor_id',
605 'financial_type_id' => 'financial_type_id',
606 'payment_instrument_id' => 'payment_instrument_id',
607 'campaign_id' => 'contribution_campaign_id',
608 'is_email_receipt' => 'is_email_receipt',
609 );
610 }
611 return self::$_fieldKeys;
612 }
613 /**
614 * Returns the names of this table
615 *
616 * @return string
617 */
618 static function getTableName() {
619 return self::$_tableName;
620 }
621 /**
622 * Returns if this table needs to be logged
623 *
624 * @return boolean
625 */
626 function getLog() {
627 return self::$_log;
628 }
629 /**
630 * Returns the list of fields that can be imported
631 *
632 * @param bool $prefix
633 *
634 * @return array
635 */
636 static function &import($prefix = false) {
637 if (!(self::$_import)) {
638 self::$_import = array();
639 $fields = self::fields();
640 foreach($fields as $name => $field) {
641 if (CRM_Utils_Array::value('import', $field)) {
642 if ($prefix) {
643 self::$_import['contribution_recur'] = & $fields[$name];
644 } else {
645 self::$_import[$name] = & $fields[$name];
646 }
647 }
648 }
649 }
650 return self::$_import;
651 }
652 /**
653 * Returns the list of fields that can be exported
654 *
655 * @param bool $prefix
656 *
657 * @return array
658 */
659 static function &export($prefix = false) {
660 if (!(self::$_export)) {
661 self::$_export = array();
662 $fields = self::fields();
663 foreach($fields as $name => $field) {
664 if (CRM_Utils_Array::value('export', $field)) {
665 if ($prefix) {
666 self::$_export['contribution_recur'] = & $fields[$name];
667 } else {
668 self::$_export[$name] = & $fields[$name];
669 }
670 }
671 }
672 }
673 return self::$_export;
674 }
675 }