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