Commit 8a50c9ba authored by Edselopez's avatar Edselopez Committed by Edsel Lopez
Browse files

Added chapter/fund functionality

parent 7bbf7dbb
......@@ -71,11 +71,18 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
* @return array
*/
public function setDefaultValues() {
// Fetch chapter and fund codes.
$codes = CRM_Core_DAO::executeQuery("SELECT chapter_code, fund_code FROM civicrm_chapter_entity WHERE entity_table = 'civicrm_line_item' AND entity_id = {$this->_lineitemInfo['id']}")->fetchAll()[0];
if (!empty($codes)) {
$this->_values['chapter_code'] = $codes['chapter_code'];
$this->_values['fund_code'] = $codes['fund_code'];
}
return $this->_values;
}
public function buildQuickForm() {
$fieldNames = array_keys($this->_values);
$fields = $this->_values;
$fieldNames = array_keys($fields);
foreach ($fieldNames as $fieldName) {
$required = TRUE;
if ($fieldName == 'line_total') {
......@@ -111,6 +118,18 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
$ele->freeze();
}
}
// Add chapter codes.
$chapterCodes = CRM_Core_OptionGroup::values('chapter_codes');
$this->add('select', 'chapter_code',
ts('Chapter Code'),
$chapterCodes
);
// Add fund codes.
$fundCodes = CRM_Core_OptionGroup::values('fund_codes');
$this->add('select', 'fund_code',
ts('Chapter Code'),
$fundCodes
);
$this->assign('fieldNames', $fieldNames);
$this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
......@@ -177,6 +196,15 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
$lineItem = CRM_Price_BAO_LineItem::create($params);
$lineItem = $lineItem->toArray();
// Save the chapter and fund information.
$chapterFundParams = [
'entity_id' => $this->_id,
'entity_table' => 'civicrm_line_item',
'chapter' => $values['chapter_code'],
'fund' => $values['fund_code'],
];
CRM_EFT_BAO_EFT::saveChapterFund($chapterFundParams);
// calculate balance, tax and paidamount later used to adjust transaction
$updatedAmount = CRM_Price_BAO_LineItem::getLineTotal($this->_lineitemInfo['contribution_id']);
$taxAmount = CRM_Lineitemedit_Util::getTaxAmountTotalFromContributionID($this->_lineitemInfo['contribution_id']);
......
......@@ -19,6 +19,16 @@ class CRM_Lineitemedit_Util {
$lineItems = civicrm_api3('LineItem', 'Get', array('contribution_id' => $order['contribution_id']));
$lineItems = $lineItems['values'];
}
$chapterCodes = CRM_Core_OptionGroup::values('chapter_codes');
$fundCodes = CRM_Core_OptionGroup::values('fund_codes');
foreach ($lineItems as $key => &$item) {
$codes = CRM_Core_DAO::executeQuery("SELECT chapter_code, fund_code FROM civicrm_chapter_entity WHERE entity_table = 'civicrm_line_item' AND entity_id = {$item['id']}")->fetchAll()[0];
if (empty($codes)) {
continue;
}
$item['chapter_code'] = $chapterCodes[$codes['chapter_code']] . '-' . $codes['chapter_code'];
$item['fund_code'] = $fundCodes[$codes['fund_code']] . '-' . $codes['fund_code'];
}
$lineItemTable = array(
'rows' => array(),
......@@ -61,6 +71,8 @@ class CRM_Lineitemedit_Util {
'id' => $lineItem['id'],
'item' => CRM_Utils_Array::value('label', $lineItem),
'financial_type' => CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'financial_type_id', $lineItem['financial_type_id']),
'chapter_code' => $lineItem['chapter_code'],
'fund_code' => $lineItem['fund_code'],
'qty' => $lineItem['qty'],
'unit_price' => $lineItem['unit_price'],
'total_price' => $lineItem['line_total'],
......
......@@ -15,6 +15,8 @@
<tr class="line-item-columnheader">
<th>{ts}Item{/ts}</th>
<th>{ts}Financial Type{/ts}</th>
<th>{ts}Chapter Code{/ts}</th>
<th>{ts}Fund Code{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Unit Price{/ts}</th>
<th>{ts}Total Price{/ts}</th>
......@@ -26,6 +28,8 @@
<tr class="lineitem-info-row">
<td>{$row.item}</td>
<td>{$row.financial_type}</td>
<td>{$row.chapter_code}</td>
<td>{$row.fund_code}</td>
<td>{$row.qty}</td>
<td>{$row.unit_price|crmMoney:$row.currency}</td>
<td>{$row.total_price|crmMoney:$row.currency}</td>
......@@ -39,6 +43,8 @@
<tr id="add-item-row-{$rowNumber}" class="line-item-row hiddenElement">
<td>{$form.item_label.$rowNumber.html}</td>
<td>{$form.item_financial_type_id.$rowNumber.html}</td>
<td>{$form.item_chapter_code.$rowNumber.html}</td>
<td>{$form.item_fund_code.$rowNumber.html}</td>
<td>{$form.item_qty.$rowNumber.html}</td>
<td>{$form.item_unit_price.$rowNumber.html}</td>
<td>{$form.item_line_total.$rowNumber.html}</td>
......
......@@ -19,3 +19,5 @@
</div>
{include file="CRM/Lineitemedit/Form/CalculateLineItemFields.tpl"}
{include file="CRM/EFT/AddChapterFundCode.tpl"}
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