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