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