Add "labelField" metadata to entities
[civicrm-core.git] / CRM / Financial / DAO / FinancialItem.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Financial/FinancialItem.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:d8fb58f8b09009330bcb325ebfea20e0)
10 */
11
12 /**
13 * Database access object for the FinancialItem entity.
14 */
15 class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '4.3';
18 const COMPONENT = 'CiviContribute';
19
20 /**
21 * Static instance to hold the table name.
22 *
23 * @var string
24 */
25 public static $_tableName = 'civicrm_financial_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 * @var int
36 */
37 public $id;
38
39 /**
40 * Date and time the item was created
41 *
42 * @var timestamp
43 */
44 public $created_date;
45
46 /**
47 * Date and time of the source transaction
48 *
49 * @var datetime
50 */
51 public $transaction_date;
52
53 /**
54 * FK to Contact ID of contact the item is from
55 *
56 * @var int
57 */
58 public $contact_id;
59
60 /**
61 * Human readable description of this item, to ease display without lookup of source item.
62 *
63 * @var string
64 */
65 public $description;
66
67 /**
68 * Total amount of this item
69 *
70 * @var float
71 */
72 public $amount;
73
74 /**
75 * Currency for the amount
76 *
77 * @var string
78 */
79 public $currency;
80
81 /**
82 * FK to civicrm_financial_account
83 *
84 * @var int
85 */
86 public $financial_account_id;
87
88 /**
89 * Payment status: test, paid, part_paid, unpaid (if empty assume unpaid)
90 *
91 * @var int
92 */
93 public $status_id;
94
95 /**
96 * The table providing the source of this item such as civicrm_line_item
97 *
98 * @var string
99 */
100 public $entity_table;
101
102 /**
103 * The specific source item that is responsible for the creation of this financial_item
104 *
105 * @var int
106 */
107 public $entity_id;
108
109 /**
110 * Class constructor.
111 */
112 public function __construct() {
113 $this->__table = 'civicrm_financial_item';
114 parent::__construct();
115 }
116
117 /**
118 * Returns localized title of this entity.
119 *
120 * @param bool $plural
121 * Whether to return the plural version of the title.
122 */
123 public static function getEntityTitle($plural = FALSE) {
124 return $plural ? ts('Financial Items') : ts('Financial Item');
125 }
126
127 /**
128 * Returns foreign keys and entity references.
129 *
130 * @return array
131 * [CRM_Core_Reference_Interface]
132 */
133 public static function getReferenceColumns() {
134 if (!isset(Civi::$statics[__CLASS__]['links'])) {
135 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
136 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
137 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'financial_account_id', 'civicrm_financial_account', 'id');
138 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), 'entity_id', NULL, 'id', 'entity_table');
139 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
140 }
141 return Civi::$statics[__CLASS__]['links'];
142 }
143
144 /**
145 * Returns all the column names of this table
146 *
147 * @return array
148 */
149 public static function &fields() {
150 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
151 Civi::$statics[__CLASS__]['fields'] = [
152 'id' => [
153 'name' => 'id',
154 'type' => CRM_Utils_Type::T_INT,
155 'title' => ts('Financial Item ID'),
156 'required' => TRUE,
157 'where' => 'civicrm_financial_item.id',
158 'table_name' => 'civicrm_financial_item',
159 'entity' => 'FinancialItem',
160 'bao' => 'CRM_Financial_BAO_FinancialItem',
161 'localizable' => 0,
162 'add' => '4.3',
163 ],
164 'created_date' => [
165 'name' => 'created_date',
166 'type' => CRM_Utils_Type::T_TIMESTAMP,
167 'title' => ts('Financial Item Created Date'),
168 'description' => ts('Date and time the item was created'),
169 'required' => TRUE,
170 'where' => 'civicrm_financial_item.created_date',
171 'default' => 'CURRENT_TIMESTAMP',
172 'table_name' => 'civicrm_financial_item',
173 'entity' => 'FinancialItem',
174 'bao' => 'CRM_Financial_BAO_FinancialItem',
175 'localizable' => 0,
176 'add' => '4.3',
177 ],
178 'transaction_date' => [
179 'name' => 'transaction_date',
180 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
181 'title' => ts('Financial Item Transaction Date'),
182 'description' => ts('Date and time of the source transaction'),
183 'required' => TRUE,
184 'where' => 'civicrm_financial_item.transaction_date',
185 'table_name' => 'civicrm_financial_item',
186 'entity' => 'FinancialItem',
187 'bao' => 'CRM_Financial_BAO_FinancialItem',
188 'localizable' => 0,
189 'add' => '4.3',
190 ],
191 'contact_id' => [
192 'name' => 'contact_id',
193 'type' => CRM_Utils_Type::T_INT,
194 'title' => ts('Financial Item Contact ID'),
195 'description' => ts('FK to Contact ID of contact the item is from'),
196 'required' => TRUE,
197 'where' => 'civicrm_financial_item.contact_id',
198 'export' => TRUE,
199 'table_name' => 'civicrm_financial_item',
200 'entity' => 'FinancialItem',
201 'bao' => 'CRM_Financial_BAO_FinancialItem',
202 'localizable' => 0,
203 'FKClassName' => 'CRM_Contact_DAO_Contact',
204 'add' => '4.3',
205 ],
206 'description' => [
207 'name' => 'description',
208 'type' => CRM_Utils_Type::T_STRING,
209 'title' => ts('Financial Item Description'),
210 'description' => ts('Human readable description of this item, to ease display without lookup of source item.'),
211 'maxlength' => 255,
212 'size' => CRM_Utils_Type::HUGE,
213 'where' => 'civicrm_financial_item.description',
214 'table_name' => 'civicrm_financial_item',
215 'entity' => 'FinancialItem',
216 'bao' => 'CRM_Financial_BAO_FinancialItem',
217 'localizable' => 0,
218 'add' => '4.3',
219 ],
220 'amount' => [
221 'name' => 'amount',
222 'type' => CRM_Utils_Type::T_MONEY,
223 'title' => ts('Amount'),
224 'description' => ts('Total amount of this item'),
225 'required' => TRUE,
226 'precision' => [
227 20,
228 2,
229 ],
230 'where' => 'civicrm_financial_item.amount',
231 'headerPattern' => '/unit?.?amoun/i',
232 'dataPattern' => '/^\d+(\.\d{2})?$/',
233 'default' => '0',
234 'table_name' => 'civicrm_financial_item',
235 'entity' => 'FinancialItem',
236 'bao' => 'CRM_Financial_BAO_FinancialItem',
237 'localizable' => 0,
238 'add' => '4.3',
239 ],
240 'currency' => [
241 'name' => 'currency',
242 'type' => CRM_Utils_Type::T_STRING,
243 'title' => ts('Financial Item Currency'),
244 'description' => ts('Currency for the amount'),
245 'maxlength' => 3,
246 'size' => CRM_Utils_Type::FOUR,
247 'where' => 'civicrm_financial_item.currency',
248 'export' => TRUE,
249 'table_name' => 'civicrm_financial_item',
250 'entity' => 'FinancialItem',
251 'bao' => 'CRM_Financial_BAO_FinancialItem',
252 'localizable' => 0,
253 'html' => [
254 'type' => 'Select',
255 ],
256 'pseudoconstant' => [
257 'table' => 'civicrm_currency',
258 'keyColumn' => 'name',
259 'labelColumn' => 'full_name',
260 'nameColumn' => 'name',
261 'abbrColumn' => 'symbol',
262 ],
263 'add' => '4.3',
264 ],
265 'financial_account_id' => [
266 'name' => 'financial_account_id',
267 'type' => CRM_Utils_Type::T_INT,
268 'title' => ts('Financial Account ID'),
269 'description' => ts('FK to civicrm_financial_account'),
270 'where' => 'civicrm_financial_item.financial_account_id',
271 'table_name' => 'civicrm_financial_item',
272 'entity' => 'FinancialItem',
273 'bao' => 'CRM_Financial_BAO_FinancialItem',
274 'localizable' => 0,
275 'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
276 'html' => [
277 'type' => 'Select',
278 ],
279 'pseudoconstant' => [
280 'table' => 'civicrm_financial_account',
281 'keyColumn' => 'id',
282 'labelColumn' => 'name',
283 ],
284 'add' => '4.3',
285 ],
286 'status_id' => [
287 'name' => 'status_id',
288 'type' => CRM_Utils_Type::T_INT,
289 'title' => ts('Financial Item Status ID'),
290 'description' => ts('Payment status: test, paid, part_paid, unpaid (if empty assume unpaid)'),
291 'where' => 'civicrm_financial_item.status_id',
292 'export' => TRUE,
293 'table_name' => 'civicrm_financial_item',
294 'entity' => 'FinancialItem',
295 'bao' => 'CRM_Financial_BAO_FinancialItem',
296 'localizable' => 0,
297 'html' => [
298 'type' => 'Select',
299 ],
300 'pseudoconstant' => [
301 'optionGroupName' => 'financial_item_status',
302 'optionEditPath' => 'civicrm/admin/options/financial_item_status',
303 ],
304 'add' => '4.3',
305 ],
306 'entity_table' => [
307 'name' => 'entity_table',
308 'type' => CRM_Utils_Type::T_STRING,
309 'title' => ts('Entity Table'),
310 'description' => ts('The table providing the source of this item such as civicrm_line_item'),
311 'maxlength' => 64,
312 'size' => CRM_Utils_Type::BIG,
313 'where' => 'civicrm_financial_item.entity_table',
314 'table_name' => 'civicrm_financial_item',
315 'entity' => 'FinancialItem',
316 'bao' => 'CRM_Financial_BAO_FinancialItem',
317 'localizable' => 0,
318 'add' => '4.3',
319 ],
320 'entity_id' => [
321 'name' => 'entity_id',
322 'type' => CRM_Utils_Type::T_INT,
323 'title' => ts('Entity ID'),
324 'description' => ts('The specific source item that is responsible for the creation of this financial_item'),
325 'where' => 'civicrm_financial_item.entity_id',
326 'table_name' => 'civicrm_financial_item',
327 'entity' => 'FinancialItem',
328 'bao' => 'CRM_Financial_BAO_FinancialItem',
329 'localizable' => 0,
330 'add' => '4.3',
331 ],
332 ];
333 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
334 }
335 return Civi::$statics[__CLASS__]['fields'];
336 }
337
338 /**
339 * Return a mapping from field-name to the corresponding key (as used in fields()).
340 *
341 * @return array
342 * Array(string $name => string $uniqueName).
343 */
344 public static function &fieldKeys() {
345 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
346 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
347 }
348 return Civi::$statics[__CLASS__]['fieldKeys'];
349 }
350
351 /**
352 * Returns the names of this table
353 *
354 * @return string
355 */
356 public static function getTableName() {
357 return self::$_tableName;
358 }
359
360 /**
361 * Returns if this table needs to be logged
362 *
363 * @return bool
364 */
365 public function getLog() {
366 return self::$_log;
367 }
368
369 /**
370 * Returns the list of fields that can be imported
371 *
372 * @param bool $prefix
373 *
374 * @return array
375 */
376 public static function &import($prefix = FALSE) {
377 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_item', $prefix, []);
378 return $r;
379 }
380
381 /**
382 * Returns the list of fields that can be exported
383 *
384 * @param bool $prefix
385 *
386 * @return array
387 */
388 public static function &export($prefix = FALSE) {
389 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_item', $prefix, []);
390 return $r;
391 }
392
393 /**
394 * Returns the list of indices
395 *
396 * @param bool $localize
397 *
398 * @return array
399 */
400 public static function indices($localize = TRUE) {
401 $indices = [
402 'IX_created_date' => [
403 'name' => 'IX_created_date',
404 'field' => [
405 0 => 'created_date',
406 ],
407 'localizable' => FALSE,
408 'sig' => 'civicrm_financial_item::0::created_date',
409 ],
410 'IX_transaction_date' => [
411 'name' => 'IX_transaction_date',
412 'field' => [
413 0 => 'transaction_date',
414 ],
415 'localizable' => FALSE,
416 'sig' => 'civicrm_financial_item::0::transaction_date',
417 ],
418 'index_entity_id_entity_table' => [
419 'name' => 'index_entity_id_entity_table',
420 'field' => [
421 0 => 'entity_id',
422 1 => 'entity_table',
423 ],
424 'localizable' => FALSE,
425 'sig' => 'civicrm_financial_item::0::entity_id::entity_table',
426 ],
427 ];
428 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
429 }
430
431 }