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