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