Line Item api does not create the underlying financial items
When creating a contribution with line items through the api the underlying Financial Items are not created.
Steps to reproduce
- Call contribution api with the following code (where we set
skipLineItem
to TRUE as we want to create the line items manually.
$contributionParams = array();
$contributionParams['contact_id'] = $contact_id;
$contributionParams['skipLineItem'] = TRUE; // This line is important!
$contributionParams['financial_type_id'] = $financial_type_id;
$contributionParams['contribution_status_id'] = $contribution_status_id;
$contributionParams['payment_instrument_id'] = $payment_instrument_id;
$contributionParams['total_amount'] = 121.00
$contributionParams['tax_amount'] = 21.00
$contributionParams['net_amount'] = 100.00
$contribution = civicrm_api3('Contribution', 'create', $contributionParams);
- Create the related line item
$line_item = array();
$line_item['label'] = 'Coaching';
$line_item['qty'] = 2
$line_item['unit_price'] = 50.00;
$line_item['line_total'] = 100.00;
$line_item['tax_amount'] = 21.00
$line_item['financial_type_id'] = $financial_type_id;
$line_item['entity_id'] => $activity_id;
$line_item['entity_table'] => 'civicrm_activity';
$line_item['contribution_id'] = $contribution['id'];
civicrm_api3('LineItem', 'Create', $line_item);
Expected result
- A contribution is created
- A line item is created and linked to the contribution
- Two financial items are created (one for the amount without tax and one for the tax amount)
Actual result
- A contribution is created (OK)
- A line item is created (OK)
- No financial items are created (NOT OK)
See this Stack Exchange post for more info: https://civicrm.stackexchange.com/q/28197/90
@JoeMurray does this description helps you to investigate the issue and solve it? Thanks anyway.