Merge pull request #18237 from mattwire/mailingsearchcolumns
[civicrm-core.git] / api / v3 / LineItem.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
a30c801b 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
a30c801b
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12
13/**
244bbdd8
CW
14 * This api exposes CiviCRM LineItem records.
15 *
16 * Line items are sub-components of a complete financial transaction record.
6a488035
TO
17 *
18 * @package CiviCRM_APIv3
6a488035
TO
19 */
20
21/**
22242c87 22 * Create or update a line_item.
6a488035 23 *
cf470720 24 * @param array $params
dc64d047 25 * Array of property name/value pairs to insert in new 'line_item'
6a488035 26 *
a6c01b45 27 * @return array
72b3a70c 28 * api result array
6a488035
TO
29 */
30function civicrm_api3_line_item_create($params) {
1c281d1d 31 // @todo the following line is not really appropriate for the api. The BAO should
32 // do the work, and it should be in a tighter function. The below function is not really
33 // readable because it is handling contribution and line item together.
8cb8ae98 34 $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params, TRUE);
ddaf2161 35 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'LineItem');
6a488035 36}
11e09c59
TO
37
38/**
0aa0303c
EM
39 * Adjust Metadata for Create action.
40 *
41 * The metadata is used for setting defaults, documentation & validation.
6a488035 42 *
cf470720 43 * @param array $params
b081365f 44 * Array of parameters determined by getfields.
6a488035
TO
45 */
46function _civicrm_api3_line_item_create_spec(&$params) {
47 $params['entity_id']['api.required'] = 1;
48 $params['qty']['api.required'] = 1;
49 $params['unit_price']['api.required'] = 1;
50 $params['line_total']['api.required'] = 1;
51 $params['label']['api.default'] = 'line item';
52}
53
54/**
d1b0d05e 55 * Returns array of line_items matching a set of one or more group properties.
6a488035 56 *
cf470720
TO
57 * @param array $params
58 * Array of one or more valid property_name=>value pairs. If $params is set.
16b10e64 59 * as null, all line_items will be returned (default limit is 25)
6a488035 60 *
a6c01b45 61 * @return array
72b3a70c 62 * Array of matching line_items
6a488035
TO
63 */
64function civicrm_api3_line_item_get($params) {
de6c59ca 65 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !empty($params['check_permissions'])) {
ac5a0d1c 66 CRM_Price_BAO_LineItem::getAPILineItemParams($params);
2344a42b 67 }
6a488035
TO
68 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
69}
70
71/**
244bbdd8 72 * Delete an existing LineItem.
6a488035 73 *
244bbdd8 74 * This method is used to delete any existing LineItem given its id.
6a488035 75 *
cf470720 76 * @param array $params
b081365f 77 * Array containing id of the group to be deleted.
b82fb202 78 *
8089541a 79 * @return array API result array
8089541a 80 * @throws API_Exception
b82fb202 81 * @throws \CiviCRM_API3_Exception
6a488035
TO
82 */
83function civicrm_api3_line_item_delete($params) {
84 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
9716cd7c 85}