Merge pull request #20627 from demeritcowboy/currency-fixation
[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:70be7900a331cb86c9cd6ee76544adc5)
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 * May contain civicrm_line_item, civicrm_financial_trxn etc
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 'html' => [
163 'type' => 'Number',
164 ],
165 'readonly' => TRUE,
166 'add' => '4.3',
167 ],
168 'created_date' => [
169 'name' => 'created_date',
170 'type' => CRM_Utils_Type::T_TIMESTAMP,
171 'title' => ts('Financial Item Created Date'),
172 'description' => ts('Date and time the item was created'),
173 'required' => TRUE,
174 'where' => 'civicrm_financial_item.created_date',
175 'default' => 'CURRENT_TIMESTAMP',
176 'table_name' => 'civicrm_financial_item',
177 'entity' => 'FinancialItem',
178 'bao' => 'CRM_Financial_BAO_FinancialItem',
179 'localizable' => 0,
180 'add' => '4.3',
181 ],
182 'transaction_date' => [
183 'name' => 'transaction_date',
184 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
185 'title' => ts('Financial Item Transaction Date'),
186 'description' => ts('Date and time of the source transaction'),
187 'required' => TRUE,
188 'where' => 'civicrm_financial_item.transaction_date',
189 'table_name' => 'civicrm_financial_item',
190 'entity' => 'FinancialItem',
191 'bao' => 'CRM_Financial_BAO_FinancialItem',
192 'localizable' => 0,
193 'add' => '4.3',
194 ],
195 'contact_id' => [
196 'name' => 'contact_id',
197 'type' => CRM_Utils_Type::T_INT,
198 'title' => ts('Contact ID'),
199 'description' => ts('FK to Contact ID of contact the item is from'),
200 'required' => TRUE,
201 'where' => 'civicrm_financial_item.contact_id',
202 'export' => TRUE,
203 'table_name' => 'civicrm_financial_item',
204 'entity' => 'FinancialItem',
205 'bao' => 'CRM_Financial_BAO_FinancialItem',
206 'localizable' => 0,
207 'FKClassName' => 'CRM_Contact_DAO_Contact',
208 'html' => [
209 'label' => ts("Contact"),
210 ],
211 'add' => '4.3',
212 ],
213 'description' => [
214 'name' => 'description',
215 'type' => CRM_Utils_Type::T_STRING,
216 'title' => ts('Financial Item Description'),
217 'description' => ts('Human readable description of this item, to ease display without lookup of source item.'),
218 'maxlength' => 255,
219 'size' => CRM_Utils_Type::HUGE,
220 'where' => 'civicrm_financial_item.description',
221 'table_name' => 'civicrm_financial_item',
222 'entity' => 'FinancialItem',
223 'bao' => 'CRM_Financial_BAO_FinancialItem',
224 'localizable' => 0,
225 'add' => '4.3',
226 ],
227 'amount' => [
228 'name' => 'amount',
229 'type' => CRM_Utils_Type::T_MONEY,
230 'title' => ts('Amount'),
231 'description' => ts('Total amount of this item'),
232 'required' => TRUE,
233 'precision' => [
234 20,
235 2,
236 ],
237 'where' => 'civicrm_financial_item.amount',
238 'headerPattern' => '/unit?.?amoun/i',
239 'dataPattern' => '/^\d+(\.\d{2})?$/',
240 'default' => '0',
241 'table_name' => 'civicrm_financial_item',
242 'entity' => 'FinancialItem',
243 'bao' => 'CRM_Financial_BAO_FinancialItem',
244 'localizable' => 0,
245 'add' => '4.3',
246 ],
247 'currency' => [
248 'name' => 'currency',
249 'type' => CRM_Utils_Type::T_STRING,
250 'title' => ts('Financial Item Currency'),
251 'description' => ts('Currency for the amount'),
252 'maxlength' => 3,
253 'size' => CRM_Utils_Type::FOUR,
254 'where' => 'civicrm_financial_item.currency',
255 'export' => TRUE,
256 'table_name' => 'civicrm_financial_item',
257 'entity' => 'FinancialItem',
258 'bao' => 'CRM_Financial_BAO_FinancialItem',
259 'localizable' => 0,
260 'html' => [
261 'type' => 'Select',
262 ],
263 'pseudoconstant' => [
264 'table' => 'civicrm_currency',
265 'keyColumn' => 'name',
266 'labelColumn' => 'full_name',
267 'nameColumn' => 'name',
268 'abbrColumn' => 'symbol',
269 ],
270 'add' => '4.3',
271 ],
272 'financial_account_id' => [
273 'name' => 'financial_account_id',
274 'type' => CRM_Utils_Type::T_INT,
275 'title' => ts('Financial Account ID'),
276 'description' => ts('FK to civicrm_financial_account'),
277 'where' => 'civicrm_financial_item.financial_account_id',
278 'table_name' => 'civicrm_financial_item',
279 'entity' => 'FinancialItem',
280 'bao' => 'CRM_Financial_BAO_FinancialItem',
281 'localizable' => 0,
282 'FKClassName' => 'CRM_Financial_DAO_FinancialAccount',
283 'html' => [
284 'type' => 'Select',
285 'label' => ts("Financial Account"),
286 ],
287 'pseudoconstant' => [
288 'table' => 'civicrm_financial_account',
289 'keyColumn' => 'id',
290 'labelColumn' => 'name',
291 ],
292 'add' => '4.3',
293 ],
294 'status_id' => [
295 'name' => 'status_id',
296 'type' => CRM_Utils_Type::T_INT,
297 'title' => ts('Financial Item Status ID'),
298 'description' => ts('Payment status: test, paid, part_paid, unpaid (if empty assume unpaid)'),
299 'where' => 'civicrm_financial_item.status_id',
300 'export' => TRUE,
301 'table_name' => 'civicrm_financial_item',
302 'entity' => 'FinancialItem',
303 'bao' => 'CRM_Financial_BAO_FinancialItem',
304 'localizable' => 0,
305 'html' => [
306 'type' => 'Select',
307 ],
308 'pseudoconstant' => [
309 'optionGroupName' => 'financial_item_status',
310 'optionEditPath' => 'civicrm/admin/options/financial_item_status',
311 ],
312 'add' => '4.3',
313 ],
314 'entity_table' => [
315 'name' => 'entity_table',
316 'type' => CRM_Utils_Type::T_STRING,
317 'title' => ts('Entity Table'),
318 'description' => ts('May contain civicrm_line_item, civicrm_financial_trxn etc'),
319 'maxlength' => 64,
320 'size' => CRM_Utils_Type::BIG,
321 'where' => 'civicrm_financial_item.entity_table',
322 'table_name' => 'civicrm_financial_item',
323 'entity' => 'FinancialItem',
324 'bao' => 'CRM_Financial_BAO_FinancialItem',
325 'localizable' => 0,
326 'pseudoconstant' => [
327 'callback' => 'CRM_Financial_BAO_FinancialItem::entityTables',
328 ],
329 'add' => '4.3',
330 ],
331 'entity_id' => [
332 'name' => 'entity_id',
333 'type' => CRM_Utils_Type::T_INT,
334 'title' => ts('Entity ID'),
335 'description' => ts('The specific source item that is responsible for the creation of this financial_item'),
336 'where' => 'civicrm_financial_item.entity_id',
337 'table_name' => 'civicrm_financial_item',
338 'entity' => 'FinancialItem',
339 'bao' => 'CRM_Financial_BAO_FinancialItem',
340 'localizable' => 0,
341 'add' => '4.3',
342 ],
343 ];
344 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
345 }
346 return Civi::$statics[__CLASS__]['fields'];
347 }
348
349 /**
350 * Return a mapping from field-name to the corresponding key (as used in fields()).
351 *
352 * @return array
353 * Array(string $name => string $uniqueName).
354 */
355 public static function &fieldKeys() {
356 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
357 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
358 }
359 return Civi::$statics[__CLASS__]['fieldKeys'];
360 }
361
362 /**
363 * Returns the names of this table
364 *
365 * @return string
366 */
367 public static function getTableName() {
368 return self::$_tableName;
369 }
370
371 /**
372 * Returns if this table needs to be logged
373 *
374 * @return bool
375 */
376 public function getLog() {
377 return self::$_log;
378 }
379
380 /**
381 * Returns the list of fields that can be imported
382 *
383 * @param bool $prefix
384 *
385 * @return array
386 */
387 public static function &import($prefix = FALSE) {
388 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'financial_item', $prefix, []);
389 return $r;
390 }
391
392 /**
393 * Returns the list of fields that can be exported
394 *
395 * @param bool $prefix
396 *
397 * @return array
398 */
399 public static function &export($prefix = FALSE) {
400 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_item', $prefix, []);
401 return $r;
402 }
403
404 /**
405 * Returns the list of indices
406 *
407 * @param bool $localize
408 *
409 * @return array
410 */
411 public static function indices($localize = TRUE) {
412 $indices = [
413 'IX_created_date' => [
414 'name' => 'IX_created_date',
415 'field' => [
416 0 => 'created_date',
417 ],
418 'localizable' => FALSE,
419 'sig' => 'civicrm_financial_item::0::created_date',
420 ],
421 'IX_transaction_date' => [
422 'name' => 'IX_transaction_date',
423 'field' => [
424 0 => 'transaction_date',
425 ],
426 'localizable' => FALSE,
427 'sig' => 'civicrm_financial_item::0::transaction_date',
428 ],
429 'index_entity_id_entity_table' => [
430 'name' => 'index_entity_id_entity_table',
431 'field' => [
432 0 => 'entity_id',
433 1 => 'entity_table',
434 ],
435 'localizable' => FALSE,
436 'sig' => 'civicrm_financial_item::0::entity_id::entity_table',
437 ],
438 ];
439 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
440 }
441
442 }