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