Commit fe3f0ee3 authored by Edselopez's avatar Edselopez Committed by Monish Deb
Browse files

Added chapter and fund for each lineitem

parent 027f1b2c
......@@ -127,7 +127,7 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
// Add fund codes.
$fundCodes = CRM_Core_OptionGroup::values('fund_codes');
$this->add('select', 'fund_code',
ts('Chapter Code'),
ts('Fund Code'),
$fundCodes
);
$this->assign('fieldNames', $fieldNames);
......
......@@ -868,6 +868,8 @@ ORDER BY ps.id, pf.weight ;
public static function buildLineItemRows(&$form, $contributionID = NULL) {
$fields = CRM_Lineitemedit_Util::getLineitemFieldNames(TRUE);
$submittedValues = $pvIDs = [];
$chapterCodes = CRM_Core_OptionGroup::values('chapter_codes');
$fundCodes = CRM_Core_OptionGroup::values('fund_codes');
if (!empty($contributionID)) {
$options = CRM_Lineitemedit_Util::getPriceFieldLists($contributionID) + ['new' => ts('Create new item')];
$pvIDs = array_keys($options);
......@@ -877,6 +879,14 @@ ORDER BY ps.id, pf.weight ;
if (!empty($_POST['item_unit_price']) && !empty($_POST['item_unit_price'][$rowNumber])) {
$submittedValues[] = $rowNumber;
}
$form->add('select', "item_chapter_code[$rowNumber]",
ts('Chapter Code'),
$chapterCodes
);
$form->add('select', "item_fund_code[$rowNumber]",
ts('Fund Code'),
$fundCodes
);
foreach ($fields as $fieldName) {
if ($fieldName != 'price_field_value_id') {
if (in_array($fieldName, ['line_total', 'tax_amount'])) {
......
......@@ -230,7 +230,7 @@ function lineitemedit_civicrm_pre($op, $entity, $entityID, &$params) {
for ($i = 0; $i <= 10; $i++) {
$lineItemParams[$i] = [];
$notFound = TRUE;
foreach (['item_label', 'item_financial_type_id', 'item_qty', 'item_unit_price', 'item_line_total', 'item_price_field_value_id', 'item_tax_amount'] as $attribute) {
foreach (['item_label', 'item_financial_type_id', 'item_chapter_code', 'item_fund_code', 'item_qty', 'item_unit_price', 'item_line_total', 'item_price_field_value_id', 'item_tax_amount'] as $attribute) {
if (!empty($params[$attribute]) && !empty($params[$attribute][$i])) {
if ($attribute == 'item_line_total') {
$notFound = FALSE;
......@@ -272,7 +272,16 @@ function lineitemedit_civicrm_pre($op, $entity, $entityID, &$params) {
'financial_type_id' => $lineItem['financial_type_id'],
'tax_amount' => CRM_Utils_Array::value('tax_amount', $lineItem),
);
$newLineItem[] = civicrm_api3('LineItem', 'create', $newLineItemParams)['id'];
$newLineItem[] = $newId = civicrm_api3('LineItem', 'create', $newLineItemParams)['id'];
$chapterFundParams = [
'entity_id' => $newId,
'entity_table' => 'civicrm_line_item',
'chapter' => $lineItem['chapter_code'],
'fund' => $lineItem['fund_code'],
];
CRM_Core_Session::singleton()->set('noUpdate', TRUE);
CRM_EFT_BAO_EFT::saveChapterFund($chapterFundParams);
CRM_Core_Session::singleton()->set('noUpdate', FALSE);
}
if (!empty($lineItemParams)) {
......
......@@ -45,3 +45,5 @@
{/literal}
{include file="CRM/Lineitemedit/Form/CalculateLineItemFields.tpl"}
{include file="CRM/EFT/AddChapterFundCode.tpl"}
......@@ -190,6 +190,7 @@ CRM.$(function($) {
if (pvid == 'new') {
$('input[id^="item_label"]', row).val(ts('Additional line item'));
$('select[id^="item_financial_type_id"]', row).select2('val', $('#financial_type_id').val());
$('select[id^="item_chapter_code"]', row).val(1000);
$('input[id^="item_qty"]', row).val(1);
total_amount = CRM.formatMoney(1, true);
$('input[id^="item_unit_price"], input[id^="item_line_total"]', row).val(total_amount);
......@@ -207,6 +208,7 @@ CRM.$(function($) {
}
$('input[id^="item_label"]', row).val(result.label);
$('select[id^="item_financial_type_id"]', row).select2('val', result.financial_type_id);
$('select[id^="item_chapter_code"]', row).val(1000);
$('input[id^="item_qty"]', row).val(1);
total_amount = CRM.formatMoney(result.amount, true);
$('input[id^="item_unit_price"], input[id^="item_line_total"]', row).val(total_amount);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment