Merge pull request #13073 from omarabuhussein/dev/core#513
[civicrm-core.git] / CRM / Price / DAO / LineItem.php
CommitLineData
e501603b 1<?php
c3fc2621 2
e501603b
TO
3/**
4 * @package CRM
8c9251b3 5 * @copyright CiviCRM LLC (c) 2004-2018
e501603b
TO
6 *
7 * Generated from xml/schema/CRM/Price/LineItem.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
e7a6b91a 9 * (GenCodeChecksum:db7c7e55df64ed93a7152b5297d13d25)
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 */
22 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 */
c3fc2621
CW
29 static $_log = TRUE;
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
TO
144 if (!isset(Civi::$statics[__CLASS__]['links'])) {
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,
522a26c9 170 'table_name' => 'civicrm_line_item',
171 'entity' => 'LineItem',
172 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 173 'localizable' => 0,
c3fc2621
CW
174 ],
175 'entity_table' => [
e501603b
TO
176 'name' => 'entity_table',
177 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 178 'title' => ts('Line Item Entity Type'),
215b423e 179 'description' => ts('table which has the transaction'),
c3fc2621 180 'required' => TRUE,
e501603b
TO
181 'maxlength' => 64,
182 'size' => CRM_Utils_Type::BIG,
522a26c9 183 'table_name' => 'civicrm_line_item',
184 'entity' => 'LineItem',
185 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 186 'localizable' => 0,
c3fc2621
CW
187 ],
188 'entity_id' => [
e501603b
TO
189 'name' => 'entity_id',
190 'type' => CRM_Utils_Type::T_INT,
c3fc2621 191 'title' => ts('Line Item Entity'),
215b423e 192 'description' => ts('entry in table'),
c3fc2621 193 'required' => TRUE,
522a26c9 194 'table_name' => 'civicrm_line_item',
195 'entity' => 'LineItem',
196 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 197 'localizable' => 0,
c3fc2621
CW
198 ],
199 'contribution_id' => [
e501603b
TO
200 'name' => 'contribution_id',
201 'type' => CRM_Utils_Type::T_INT,
c3fc2621 202 'title' => ts('Line Item Contribution'),
215b423e 203 'description' => ts('FK to civicrm_contribution'),
522a26c9 204 'table_name' => 'civicrm_line_item',
205 'entity' => 'LineItem',
206 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 207 'localizable' => 0,
e501603b 208 'FKClassName' => 'CRM_Contribute_DAO_Contribution',
c3fc2621
CW
209 ],
210 'price_field_id' => [
e501603b
TO
211 'name' => 'price_field_id',
212 'type' => CRM_Utils_Type::T_INT,
c3fc2621 213 'title' => ts('Line Item Price Field'),
215b423e 214 'description' => ts('FK to civicrm_price_field'),
522a26c9 215 'table_name' => 'civicrm_line_item',
216 'entity' => 'LineItem',
217 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 218 'localizable' => 0,
e501603b 219 'FKClassName' => 'CRM_Price_DAO_PriceField',
c3fc2621
CW
220 ],
221 'label' => [
e501603b
TO
222 'name' => 'label',
223 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 224 'title' => ts('Line Item Label'),
215b423e 225 'description' => ts('descriptive label for item - from price_field_value.label'),
e501603b
TO
226 'maxlength' => 255,
227 'size' => CRM_Utils_Type::HUGE,
228 'default' => 'NULL',
522a26c9 229 'table_name' => 'civicrm_line_item',
230 'entity' => 'LineItem',
231 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 232 'localizable' => 0,
c3fc2621 233 'html' => [
e501603b 234 'type' => 'Text',
c3fc2621
CW
235 ],
236 ],
237 'qty' => [
e501603b
TO
238 'name' => 'qty',
239 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 240 'title' => ts('Line Item Quantity'),
215b423e 241 'description' => ts('How many items ordered'),
c3fc2621
CW
242 'required' => TRUE,
243 'precision' => [
e501603b
TO
244 20,
245 2
c3fc2621 246 ],
522a26c9 247 'table_name' => 'civicrm_line_item',
248 'entity' => 'LineItem',
249 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 250 'localizable' => 0,
c3fc2621 251 'html' => [
e501603b 252 'type' => 'Text',
c3fc2621
CW
253 ],
254 ],
255 'unit_price' => [
e501603b
TO
256 'name' => 'unit_price',
257 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 258 'title' => ts('Unit Price'),
215b423e 259 'description' => ts('price of each item'),
c3fc2621
CW
260 'required' => TRUE,
261 'precision' => [
e501603b
TO
262 20,
263 2
c3fc2621 264 ],
522a26c9 265 'table_name' => 'civicrm_line_item',
266 'entity' => 'LineItem',
267 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 268 'localizable' => 0,
c3fc2621 269 'html' => [
e501603b 270 'type' => 'Text',
c3fc2621
CW
271 ],
272 ],
273 'line_total' => [
e501603b
TO
274 'name' => 'line_total',
275 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 276 'title' => ts('Line Item Total'),
215b423e 277 'description' => ts('qty * unit_price'),
c3fc2621
CW
278 'required' => TRUE,
279 'precision' => [
e501603b
TO
280 20,
281 2
c3fc2621 282 ],
522a26c9 283 'table_name' => 'civicrm_line_item',
284 'entity' => 'LineItem',
285 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 286 'localizable' => 0,
c3fc2621
CW
287 ],
288 'participant_count' => [
e501603b
TO
289 'name' => 'participant_count',
290 'type' => CRM_Utils_Type::T_INT,
c3fc2621 291 'title' => ts('Line Item Participant Count'),
215b423e 292 'description' => ts('Participant count for field'),
e501603b 293 'default' => 'NULL',
522a26c9 294 'table_name' => 'civicrm_line_item',
295 'entity' => 'LineItem',
296 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 297 'localizable' => 0,
c3fc2621 298 'html' => [
e501603b 299 'type' => 'Text',
c3fc2621
CW
300 ],
301 ],
302 'price_field_value_id' => [
e501603b
TO
303 'name' => 'price_field_value_id',
304 'type' => CRM_Utils_Type::T_INT,
c3fc2621 305 'title' => ts('Line Item Option'),
215b423e 306 'description' => ts('FK to civicrm_price_field_value'),
e501603b 307 'default' => 'NULL',
522a26c9 308 'table_name' => 'civicrm_line_item',
309 'entity' => 'LineItem',
310 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 311 'localizable' => 0,
e501603b 312 'FKClassName' => 'CRM_Price_DAO_PriceFieldValue',
c3fc2621
CW
313 ],
314 'financial_type_id' => [
e501603b
TO
315 'name' => 'financial_type_id',
316 'type' => CRM_Utils_Type::T_INT,
c3fc2621 317 'title' => ts('Financial Type'),
215b423e 318 'description' => ts('FK to Financial Type.'),
e501603b 319 'default' => 'NULL',
522a26c9 320 'table_name' => 'civicrm_line_item',
321 'entity' => 'LineItem',
322 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 323 'localizable' => 0,
e501603b 324 'FKClassName' => 'CRM_Financial_DAO_FinancialType',
c3fc2621 325 'html' => [
e501603b 326 'type' => 'Select',
c3fc2621
CW
327 ],
328 'pseudoconstant' => [
e501603b
TO
329 'table' => 'civicrm_financial_type',
330 'keyColumn' => 'id',
331 'labelColumn' => 'name',
c3fc2621
CW
332 ]
333 ],
334 'non_deductible_amount' => [
5afce5ad 335 'name' => 'non_deductible_amount',
e501603b 336 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 337 'title' => ts('Non-deductible Amount'),
215b423e 338 'description' => ts('Portion of total amount which is NOT tax deductible.'),
c3fc2621
CW
339 'required' => TRUE,
340 'precision' => [
e501603b
TO
341 20,
342 2
c3fc2621 343 ],
e501603b 344 'default' => '0.0',
522a26c9 345 'table_name' => 'civicrm_line_item',
346 'entity' => 'LineItem',
347 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 348 'localizable' => 0,
c3fc2621 349 'html' => [
e501603b 350 'type' => 'Text',
c3fc2621
CW
351 ],
352 ],
353 'tax_amount' => [
e501603b
TO
354 'name' => 'tax_amount',
355 'type' => CRM_Utils_Type::T_MONEY,
c3fc2621 356 'title' => ts('Tax Amount'),
215b423e 357 'description' => ts('tax of each item'),
c3fc2621 358 'precision' => [
e501603b
TO
359 20,
360 2
c3fc2621
CW
361 ],
362 'import' => TRUE,
e501603b
TO
363 'where' => 'civicrm_line_item.tax_amount',
364 'headerPattern' => '/tax(.?am(ou)?nt)?/i',
365 'dataPattern' => '/^\d+(\.\d{2})?$/',
c3fc2621 366 'export' => TRUE,
522a26c9 367 'table_name' => 'civicrm_line_item',
368 'entity' => 'LineItem',
369 'bao' => 'CRM_Price_BAO_LineItem',
6a7e5e5d 370 'localizable' => 0,
c3fc2621 371 'html' => [
e501603b 372 'type' => 'Text',
c3fc2621
CW
373 ],
374 ],
375 ];
346aaaba 376 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 377 }
346aaaba 378 return Civi::$statics[__CLASS__]['fields'];
e501603b 379 }
c3fc2621 380
e501603b 381 /**
bd8e0b14 382 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
383 *
384 * @return array
bd8e0b14 385 * Array(string $name => string $uniqueName).
e501603b 386 */
c3fc2621 387 public static function &fieldKeys() {
bd8e0b14
TO
388 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
389 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 390 }
bd8e0b14 391 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 392 }
c3fc2621 393
e501603b
TO
394 /**
395 * Returns the names of this table
396 *
397 * @return string
398 */
c3fc2621 399 public static function getTableName() {
e501603b
TO
400 return self::$_tableName;
401 }
c3fc2621 402
e501603b
TO
403 /**
404 * Returns if this table needs to be logged
405 *
c3fc2621 406 * @return bool
e501603b 407 */
c3fc2621 408 public function getLog() {
e501603b
TO
409 return self::$_log;
410 }
c3fc2621 411
e501603b
TO
412 /**
413 * Returns the list of fields that can be imported
414 *
415 * @param bool $prefix
416 *
417 * @return array
418 */
c3fc2621
CW
419 public static function &import($prefix = FALSE) {
420 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'line_item', $prefix, []);
60808919 421 return $r;
e501603b 422 }
c3fc2621 423
e501603b
TO
424 /**
425 * Returns the list of fields that can be exported
426 *
427 * @param bool $prefix
428 *
429 * @return array
430 */
c3fc2621
CW
431 public static function &export($prefix = FALSE) {
432 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'line_item', $prefix, []);
60808919 433 return $r;
e501603b 434 }
c3fc2621 435
e7a6b91a
AS
436 /**
437 * Returns the list of indices
c3fc2621
CW
438 *
439 * @param bool $localize
440 *
441 * @return array
e7a6b91a
AS
442 */
443 public static function indices($localize = TRUE) {
c3fc2621
CW
444 $indices = [
445 'index_entity' => [
e7a6b91a 446 'name' => 'index_entity',
c3fc2621 447 'field' => [
e7a6b91a
AS
448 0 => 'entity_table',
449 1 => 'entity_id',
c3fc2621
CW
450 ],
451 'localizable' => FALSE,
e7a6b91a 452 'sig' => 'civicrm_line_item::0::entity_table::entity_id',
c3fc2621
CW
453 ],
454 'UI_line_item_value' => [
e7a6b91a 455 'name' => 'UI_line_item_value',
c3fc2621 456 'field' => [
e7a6b91a
AS
457 0 => 'entity_table',
458 1 => 'entity_id',
459 2 => 'contribution_id',
460 3 => 'price_field_value_id',
461 4 => 'price_field_id',
c3fc2621
CW
462 ],
463 'localizable' => FALSE,
464 'unique' => TRUE,
e7a6b91a 465 'sig' => 'civicrm_line_item::1::entity_table::entity_id::contribution_id::price_field_value_id::price_field_id',
c3fc2621
CW
466 ],
467 ];
e7a6b91a
AS
468 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
469 }
c3fc2621 470
e501603b 471}