Merge pull request #21959 from civicrm/5.43
[civicrm-core.git] / CRM / Price / DAO / LineItem.php
CommitLineData
e501603b 1<?php
c3fc2621 2
e501603b
TO
3/**
4 * @package CRM
ca5cec67 5 * @copyright CiviCRM LLC https://civicrm.org/licensing
e501603b
TO
6 *
7 * Generated from xml/schema/CRM/Price/LineItem.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
cf7384c1 9 * (GenCodeChecksum:27940b7d9e1152223c1fde0e32a8e909)
e501603b 10 */
c3fc2621 11
f41f0342 12/**
c3fc2621 13 * Database access object for the LineItem entity.
f41f0342 14 */
e501603b 15class CRM_Price_DAO_LineItem extends CRM_Core_DAO {
929a1c14
CW
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.7';
d31fb4e3 18 const COMPONENT = 'CiviContribute';
c3fc2621 19
e501603b 20 /**
f41f0342 21 * Static instance to hold the table name.
e501603b
TO
22 *
23 * @var string
24 */
fa45b5b9 25 public static $_tableName = 'civicrm_line_item';
c3fc2621 26
e501603b 27 /**
f41f0342 28 * Should CiviCRM log any modifications to this table in the civicrm_log table.
e501603b 29 *
c3fc2621 30 * @var bool
e501603b 31 */
fa45b5b9 32 public static $_log = TRUE;
c3fc2621 33
e501603b
TO
34 /**
35 * Line Item
36 *
e6ca0a57 37 * @var int
e501603b
TO
38 */
39 public $id;
c3fc2621 40
e501603b 41 /**
6844be64 42 * May contain civicrm_contribution, civicrm_participant or civicrm_membership
e501603b
TO
43 *
44 * @var string
45 */
46 public $entity_table;
c3fc2621 47
e501603b
TO
48 /**
49 * entry in table
50 *
e6ca0a57 51 * @var int
e501603b
TO
52 */
53 public $entity_id;
c3fc2621 54
e501603b
TO
55 /**
56 * FK to civicrm_contribution
57 *
e6ca0a57 58 * @var int
e501603b
TO
59 */
60 public $contribution_id;
c3fc2621 61
e501603b
TO
62 /**
63 * FK to civicrm_price_field
64 *
e6ca0a57 65 * @var int
e501603b
TO
66 */
67 public $price_field_id;
c3fc2621 68
e501603b
TO
69 /**
70 * descriptive label for item - from price_field_value.label
71 *
72 * @var string
73 */
74 public $label;
c3fc2621 75
e501603b
TO
76 /**
77 * How many items ordered
78 *
79 * @var float
80 */
81 public $qty;
c3fc2621 82
e501603b
TO
83 /**
84 * price of each item
85 *
86 * @var float
87 */
88 public $unit_price;
c3fc2621 89
e501603b
TO
90 /**
91 * qty * unit_price
92 *
93 * @var float
94 */
95 public $line_total;
c3fc2621 96
e501603b
TO
97 /**
98 * Participant count for field
99 *
e6ca0a57 100 * @var int
e501603b
TO
101 */
102 public $participant_count;
c3fc2621 103
e501603b
TO
104 /**
105 * FK to civicrm_price_field_value
106 *
e6ca0a57 107 * @var int
e501603b
TO
108 */
109 public $price_field_value_id;
c3fc2621 110
e501603b
TO
111 /**
112 * FK to Financial Type.
113 *
e6ca0a57 114 * @var int
e501603b
TO
115 */
116 public $financial_type_id;
c3fc2621 117
e501603b 118 /**
5afce5ad 119 * Portion of total amount which is NOT tax deductible.
e501603b
TO
120 *
121 * @var float
122 */
5afce5ad 123 public $non_deductible_amount;
c3fc2621 124
e501603b
TO
125 /**
126 * tax of each item
127 *
128 * @var float
129 */
130 public $tax_amount;
c3fc2621 131
cf7384c1
EM
132 /**
133 * Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership
134 *
135 * @var int
136 */
137 public $membership_num_terms;
138
e501603b 139 /**
f41f0342 140 * Class constructor.
e501603b 141 */
c3fc2621 142 public function __construct() {
e501603b
TO
143 $this->__table = 'civicrm_line_item';
144 parent::__construct();
145 }
c3fc2621 146
449c4e6b
CW
147 /**
148 * Returns localized title of this entity.
7b66c3b5
AH
149 *
150 * @param bool $plural
151 * Whether to return the plural version of the title.
449c4e6b 152 */
7b66c3b5
AH
153 public static function getEntityTitle($plural = FALSE) {
154 return $plural ? ts('Line Items') : ts('Line Item');
449c4e6b
CW
155 }
156
e501603b 157 /**
f41f0342 158 * Returns foreign keys and entity references.
e501603b
TO
159 *
160 * @return array
161 * [CRM_Core_Reference_Interface]
162 */
c3fc2621 163 public static function getReferenceColumns() {
346aaaba 164 if (!isset(Civi::$statics[__CLASS__]['links'])) {
fa45b5b9 165 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
c3fc2621
CW
166 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contribution_id', 'civicrm_contribution', 'id');
167 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'price_field_id', 'civicrm_price_field', 'id');
168 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'price_field_value_id', 'civicrm_price_field_value', 'id');
169 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_type_id', 'civicrm_financial_type', 'id');
170 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), 'entity_id', NULL, 'id', 'entity_table');
346aaaba 171 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
e501603b 172 }
346aaaba 173 return Civi::$statics[__CLASS__]['links'];
e501603b 174 }
c3fc2621 175
e501603b
TO
176 /**
177 * Returns all the column names of this table
178 *
179 * @return array
180 */
c3fc2621 181 public static function &fields() {
346aaaba 182 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
c3fc2621
CW
183 Civi::$statics[__CLASS__]['fields'] = [
184 'id' => [
e501603b
TO
185 'name' => 'id',
186 'type' => CRM_Utils_Type::T_INT,
c3fc2621 187 'title' => ts('Line Item ID'),
215b423e 188 'description' => ts('Line Item'),
c3fc2621 189 'required' => TRUE,
a36434b9 190 'where' => 'civicrm_line_item.id',
522a26c9 191 'table_name' => 'civicrm_line_item',
192 'entity' => 'LineItem',
193 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 194 'localizable' => 0,
2cbbebe8
A
195 'html' => [
196 'type' => 'Number',
197 ],
1fe423d6 198 'readonly' => TRUE,
a9d0587b 199 'add' => '1.7',
c3fc2621
CW
200 ],
201 'entity_table' => [
e501603b
TO
202 'name' => 'entity_table',
203 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 204 'title' => ts('Line Item Entity Type'),
6844be64 205 'description' => ts('May contain civicrm_contribution, civicrm_participant or civicrm_membership'),
c3fc2621 206 'required' => TRUE,
e501603b
TO
207 'maxlength' => 64,
208 'size' => CRM_Utils_Type::BIG,
a36434b9 209 'where' => 'civicrm_line_item.entity_table',
522a26c9 210 'table_name' => 'civicrm_line_item',
211 'entity' => 'LineItem',
212 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 213 'localizable' => 0,
6844be64
MD
214 'pseudoconstant' => [
215 'callback' => 'CRM_Price_BAO_LineItem::entityTables',
216 ],
a9d0587b 217 'add' => '1.7',
c3fc2621
CW
218 ],
219 'entity_id' => [
e501603b
TO
220 'name' => 'entity_id',
221 'type' => CRM_Utils_Type::T_INT,
c3fc2621 222 'title' => ts('Line Item Entity'),
215b423e 223 'description' => ts('entry in table'),
c3fc2621 224 'required' => TRUE,
a36434b9 225 'where' => 'civicrm_line_item.entity_id',
522a26c9 226 'table_name' => 'civicrm_line_item',
227 'entity' => 'LineItem',
228 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 229 'localizable' => 0,
a9d0587b 230 'add' => '1.7',
c3fc2621
CW
231 ],
232 'contribution_id' => [
e501603b
TO
233 'name' => 'contribution_id',
234 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 235 'title' => ts('Contribution ID'),
215b423e 236 'description' => ts('FK to civicrm_contribution'),
a36434b9 237 'where' => 'civicrm_line_item.contribution_id',
522a26c9 238 'table_name' => 'civicrm_line_item',
239 'entity' => 'LineItem',
240 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 241 'localizable' => 0,
e501603b 242 'FKClassName' => 'CRM_Contribute_DAO_Contribution',
2cbbebe8
A
243 'html' => [
244 'label' => ts("Contribution"),
245 ],
a9d0587b 246 'add' => '4.5',
c3fc2621
CW
247 ],
248 'price_field_id' => [
e501603b
TO
249 'name' => 'price_field_id',
250 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 251 'title' => ts('Price Field ID'),
215b423e 252 'description' => ts('FK to civicrm_price_field'),
a36434b9 253 'where' => 'civicrm_line_item.price_field_id',
522a26c9 254 'table_name' => 'civicrm_line_item',
255 'entity' => 'LineItem',
256 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 257 'localizable' => 0,
e501603b 258 'FKClassName' => 'CRM_Price_DAO_PriceField',
2cbbebe8
A
259 'html' => [
260 'label' => ts("Price Field"),
261 ],
8e17d9d3 262 'pseudoconstant' => [
263 'table' => 'civicrm_price_field',
264 'keyColumn' => 'id',
265 'labelColumn' => 'label',
266 'nameColumn' => 'name',
267 ],
a9d0587b 268 'add' => '1.7',
c3fc2621
CW
269 ],
270 'label' => [
e501603b
TO
271 'name' => 'label',
272 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 273 'title' => ts('Line Item Label'),
215b423e 274 'description' => ts('descriptive label for item - from price_field_value.label'),
e501603b
TO
275 'maxlength' => 255,
276 'size' => CRM_Utils_Type::HUGE,
a36434b9 277 'where' => 'civicrm_line_item.label',
5fb0de1f 278 'default' => NULL,
522a26c9 279 'table_name' => 'civicrm_line_item',
280 'entity' => 'LineItem',
281 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 282 'localizable' => 0,
c3fc2621 283 'html' => [
e501603b 284 'type' => 'Text',
c3fc2621 285 ],
a9d0587b 286 'add' => '1.7',
c3fc2621
CW
287 ],
288 'qty' => [
e501603b
TO
289 'name' => 'qty',
290 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 291 'title' => ts('Line Item Quantity'),
215b423e 292 'description' => ts('How many items ordered'),
c3fc2621
CW
293 'required' => TRUE,
294 'precision' => [
e501603b 295 20,
fb607354 296 2,
c3fc2621 297 ],
a36434b9 298 'where' => 'civicrm_line_item.qty',
522a26c9 299 'table_name' => 'civicrm_line_item',
300 'entity' => 'LineItem',
301 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 302 'localizable' => 0,
c3fc2621 303 'html' => [
e501603b 304 'type' => 'Text',
c3fc2621 305 ],
a9d0587b 306 'add' => '1.7',
c3fc2621
CW
307 ],
308 'unit_price' => [
e501603b
TO
309 'name' => 'unit_price',
310 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 311 'title' => ts('Unit Price'),
215b423e 312 'description' => ts('price of each item'),
c3fc2621
CW
313 'required' => TRUE,
314 'precision' => [
e501603b 315 20,
fb607354 316 2,
c3fc2621 317 ],
a36434b9 318 'where' => 'civicrm_line_item.unit_price',
522a26c9 319 'table_name' => 'civicrm_line_item',
320 'entity' => 'LineItem',
321 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 322 'localizable' => 0,
c3fc2621 323 'html' => [
e501603b 324 'type' => 'Text',
c23563e3 325 'label' => ts("Unit Price"),
c3fc2621 326 ],
a9d0587b 327 'add' => '1.7',
c3fc2621
CW
328 ],
329 'line_total' => [
e501603b
TO
330 'name' => 'line_total',
331 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 332 'title' => ts('Line Item Total'),
215b423e 333 'description' => ts('qty * unit_price'),
c3fc2621
CW
334 'required' => TRUE,
335 'precision' => [
e501603b 336 20,
fb607354 337 2,
c3fc2621 338 ],
a36434b9 339 'where' => 'civicrm_line_item.line_total',
522a26c9 340 'table_name' => 'civicrm_line_item',
341 'entity' => 'LineItem',
342 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 343 'localizable' => 0,
a9d0587b 344 'add' => '1.7',
c3fc2621
CW
345 ],
346 'participant_count' => [
e501603b
TO
347 'name' => 'participant_count',
348 'type' => CRM_Utils_Type::T_INT,
c3fc2621 349 'title' => ts('Line Item Participant Count'),
215b423e 350 'description' => ts('Participant count for field'),
a36434b9 351 'where' => 'civicrm_line_item.participant_count',
5fb0de1f 352 'default' => NULL,
522a26c9 353 'table_name' => 'civicrm_line_item',
354 'entity' => 'LineItem',
355 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 356 'localizable' => 0,
c3fc2621 357 'html' => [
e501603b 358 'type' => 'Text',
c3fc2621 359 ],
a9d0587b 360 'add' => '3.2',
c3fc2621
CW
361 ],
362 'price_field_value_id' => [
e501603b
TO
363 'name' => 'price_field_value_id',
364 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 365 'title' => ts('Option ID'),
215b423e 366 'description' => ts('FK to civicrm_price_field_value'),
a36434b9 367 'where' => 'civicrm_line_item.price_field_value_id',
5fb0de1f 368 'default' => NULL,
522a26c9 369 'table_name' => 'civicrm_line_item',
370 'entity' => 'LineItem',
371 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 372 'localizable' => 0,
e501603b 373 'FKClassName' => 'CRM_Price_DAO_PriceFieldValue',
2cbbebe8
A
374 'html' => [
375 'label' => ts("Option"),
376 ],
8e17d9d3 377 'pseudoconstant' => [
378 'table' => 'civicrm_price_field_value',
379 'keyColumn' => 'id',
380 'labelColumn' => 'label',
381 'nameColumn' => 'name',
382 ],
a9d0587b 383 'add' => '3.3',
c3fc2621
CW
384 ],
385 'financial_type_id' => [
e501603b
TO
386 'name' => 'financial_type_id',
387 'type' => CRM_Utils_Type::T_INT,
8e17d9d3 388 'title' => ts('Financial Type ID'),
215b423e 389 'description' => ts('FK to Financial Type.'),
a36434b9 390 'where' => 'civicrm_line_item.financial_type_id',
5fb0de1f 391 'default' => NULL,
522a26c9 392 'table_name' => 'civicrm_line_item',
393 'entity' => 'LineItem',
394 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 395 'localizable' => 0,
e501603b 396 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
c3fc2621 397 'html' => [
e501603b 398 'type' => 'Select',
8e17d9d3 399 'label' => ts("Financial Type"),
c3fc2621
CW
400 ],
401 'pseudoconstant' => [
e501603b
TO
402 'table' => 'civicrm_financial_type',
403 'keyColumn' => 'id',
404 'labelColumn' => 'name',
e6ca0a57 405 ],
a9d0587b 406 'add' => '4.3',
c3fc2621
CW
407 ],
408 'non_deductible_amount' => [
5afce5ad 409 'name' => 'non_deductible_amount',
e501603b 410 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 411 'title' => ts('Non-deductible Amount'),
215b423e 412 'description' => ts('Portion of total amount which is NOT tax deductible.'),
c3fc2621
CW
413 'required' => TRUE,
414 'precision' => [
e501603b 415 20,
fb607354 416 2,
c3fc2621 417 ],
a36434b9 418 'where' => 'civicrm_line_item.non_deductible_amount',
419 'headerPattern' => '/non?.?deduct/i',
420 'dataPattern' => '/^\d+(\.\d{2})?$/',
e501603b 421 'default' => '0.0',
522a26c9 422 'table_name' => 'civicrm_line_item',
423 'entity' => 'LineItem',
424 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 425 'localizable' => 0,
c3fc2621 426 'html' => [
e501603b 427 'type' => 'Text',
c3fc2621 428 ],
a9d0587b 429 'add' => '4.7',
c3fc2621
CW
430 ],
431 'tax_amount' => [
e501603b
TO
432 'name' => 'tax_amount',
433 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 434 'title' => ts('Tax Amount'),
215b423e 435 'description' => ts('tax of each item'),
c3fc2621 436 'precision' => [
e501603b 437 20,
fb607354 438 2,
c3fc2621
CW
439 ],
440 'import' => TRUE,
e501603b
TO
441 'where' => 'civicrm_line_item.tax_amount',
442 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
443 'dataPattern' => '/^\d+(\.\d{2})?$/',
c3fc2621 444 'export' => TRUE,
522a26c9 445 'table_name' => 'civicrm_line_item',
446 'entity' => 'LineItem',
447 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 448 'localizable' => 0,
c3fc2621 449 'html' => [
e501603b 450 'type' => 'Text',
c3fc2621 451 ],
a9d0587b 452 'add' => '4.6',
c3fc2621 453 ],
cf7384c1
EM
454 'membership_num_terms' => [
455 'name' => 'membership_num_terms',
456 'type' => CRM_Utils_Type::T_INT,
457 'title' => ts('Number of membership terms purchased'),
458 'description' => ts('Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership'),
459 'where' => 'civicrm_line_item.membership_num_terms',
5fb0de1f 460 'default' => NULL,
cf7384c1
EM
461 'table_name' => 'civicrm_line_item',
462 'entity' => 'LineItem',
463 'bao' => 'CRM_Price_BAO_LineItem',
464 'localizable' => 0,
465 'add' => '5.40',
466 ],
c3fc2621 467 ];
346aaaba 468 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 469 }
346aaaba 470 return Civi::$statics[__CLASS__]['fields'];
e501603b 471 }
c3fc2621 472
e501603b 473 /**
bd8e0b14 474 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
475 *
476 * @return array
bd8e0b14 477 * Array(string $name => string $uniqueName).
e501603b 478 */
c3fc2621 479 public static function &fieldKeys() {
bd8e0b14
TO
480 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
481 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 482 }
bd8e0b14 483 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 484 }
c3fc2621 485
e501603b
TO
486 /**
487 * Returns the names of this table
488 *
489 * @return string
490 */
c3fc2621 491 public static function getTableName() {
e501603b
TO
492 return self::$_tableName;
493 }
c3fc2621 494
e501603b
TO
495 /**
496 * Returns if this table needs to be logged
497 *
c3fc2621 498 * @return bool
e501603b 499 */
c3fc2621 500 public function getLog() {
e501603b
TO
501 return self::$_log;
502 }
c3fc2621 503
e501603b
TO
504 /**
505 * Returns the list of fields that can be imported
506 *
507 * @param bool $prefix
508 *
509 * @return array
510 */
c3fc2621
CW
511 public static function &import($prefix = FALSE) {
512 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'line_item', $prefix, []);
60808919 513 return $r;
e501603b 514 }
c3fc2621 515
e501603b
TO
516 /**
517 * Returns the list of fields that can be exported
518 *
519 * @param bool $prefix
520 *
521 * @return array
522 */
c3fc2621
CW
523 public static function &export($prefix = FALSE) {
524 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'line_item', $prefix, []);
60808919 525 return $r;
e501603b 526 }
c3fc2621 527
e7a6b91a
AS
528 /**
529 * Returns the list of indices
c3fc2621
CW
530 *
531 * @param bool $localize
532 *
533 * @return array
e7a6b91a
AS
534 */
535 public static function indices($localize = TRUE) {
c3fc2621 536 $indices = [
c3fc2621 537 'UI_line_item_value' => [
e7a6b91a 538 'name' => 'UI_line_item_value',
c3fc2621 539 'field' => [
90dcf8f8 540 0 => 'entity_id',
541 1 => 'entity_table',
e7a6b91a
AS
542 2 => 'contribution_id',
543 3 => 'price_field_value_id',
544 4 => 'price_field_id',
c3fc2621
CW
545 ],
546 'localizable' => FALSE,
547 'unique' => TRUE,
90dcf8f8 548 'sig' => 'civicrm_line_item::1::entity_id::entity_table::contribution_id::price_field_value_id::price_field_id',
c3fc2621
CW
549 ],
550 ];
e7a6b91a
AS
551 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
552 }
c3fc2621 553
e501603b 554}