Commit d3c71b2f authored by Monish Deb's avatar Monish Deb

Merge pull request #4764 from rohankatkar/CRM-15615

Fix for CRM-15615
parents b5d05fb5 5b22467a
......@@ -1839,27 +1839,29 @@ WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
$submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
}
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
$updateLines = array();
foreach ($previousLineItems as $id => $previousLineItem) {
// check through the submitted items if the previousItem exists,
// if found in submitted items, do not use it for new item creations
if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) {
$updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
$updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
if (!empty($submittedLineItems)) {
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
$updateLines = array();
foreach ($previousLineItems as $id => $previousLineItem) {
// check through the submitted items if the previousItem exists,
// if found in submitted items, do not use it for new item creations
if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if (($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) ||
($submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] == 0 && $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'] == 1)) {
$updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
$updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
}
}
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
}
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li
INNER JOIN civicrm_financial_item fi
......@@ -1925,7 +1927,16 @@ GROUP BY li.entity_table, li.entity_id, price_field_value_id
}
}
}
elseif (empty($submittedFields) && empty($submittedFieldValues)){
$updateLineItem = "UPDATE civicrm_line_item li
INNER JOIN civicrm_financial_item fi
ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')
SET li.qty = 0,
li.line_total = 0.00,
li.tax_amount = NULL
WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
CRM_Core_DAO::executeQuery($updateLineItem);
}
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
if (isset($vals['tax_amount'])) {
......@@ -1950,11 +1961,13 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI
// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
// insert new line items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineParams['contribution_id'] = $contributionId;
$lineObj = CRM_Price_BAO_LineItem::create($lineParams);
if (!empty($insertLines)) {
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineParams['contribution_id'] = $contributionId;
$lineObj = CRM_Price_BAO_LineItem::create($lineParams);
}
}
// the recordAdjustedAmt code would execute over here
......@@ -1980,15 +1993,17 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI
$fetchCon = array('id' => $contributionId);
$updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
// insert financial items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
// insert financial items
// ensure entity_financial_trxn table has a linking of it.
$prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution);
if (isset($lineObj->tax_amount)) {
CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, TRUE);
if (!empty($insertLines)) {
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
// insert financial items
// ensure entity_financial_trxn table has a linking of it.
$prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution);
if (isset($lineObj->tax_amount)) {
CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, TRUE);
}
}
}
......
......@@ -129,10 +129,17 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId);
$priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE);
$priceFieldId = (array_keys($this->_values['fee']));
if (!empty($priceSetValues)) {
$defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues);
}
else {
foreach($priceFieldId as $key => $value) {
if (!empty($value) && ($this->_values['fee'][$value]['html_type'] == 'Radio' || $this->_values['fee'][$value]['html_type'] == 'Select') && !$this->_values['fee'][$value]['is_required']) {
$defaults[$this->_participantId]['price_'.array_keys($this->_values['fee'])[$key]] = 0;
}
}
}
$this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
if ($this->_action == CRM_Core_Action::UPDATE) {
$fee_level = $defaults[$this->_participantId]['fee_level'];
......
......@@ -533,6 +533,9 @@ AND li.entity_id = {$entityId}
* @static
*/
public static function calculateTaxRate($lineItemId) {
if ($lineItemId['unit_price'] == 0) {
return;
}
if ($lineItemId['html_type'] == 'Text') {
$tax = $lineItemId['tax_amount']/($lineItemId['unit_price'] * $lineItemId['qty'])*100;
}
......
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