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