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