From 0b2b58eab76b1cb8ad94372c702af529487da780 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Thu, 13 Mar 2014 19:00:46 +0530 Subject: [PATCH] CRM-13973-qa : fixed for points mentioned in #comment-58264 --- CRM/Event/BAO/Participant.php | 28 +++++++++++++++++-- CRM/Event/Form/Participant.php | 3 ++ CRM/Event/Form/ParticipantView.php | 6 ++++ templates/CRM/Contribute/Page/PaymentInfo.tpl | 20 +++++++------ templates/CRM/Event/Form/Participant.tpl | 4 +-- templates/CRM/Event/Form/ParticipantView.tpl | 6 ++-- 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index f0432ce009..a0be4bbda6 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1788,12 +1788,17 @@ WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2"; } $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)) { - unset($insertLines[$previousLineItem['price_field_value_id']]); + // for updating the line items i.e. use-case - once deselect-option selecting again + if ($previousLineItem['qty'] == 0) { + $updateLines[$previousLineItem['price_field_value_id']]['qty'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['qty']; + $updateLines[$previousLineItem['price_field_value_id']]['line_total'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']; + unset($insertLines[$previousLineItem['price_field_value_id']]); + } } } @@ -1817,6 +1822,25 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI CRM_Core_DAO::executeQuery($updateLineItem); } + if (!empty($updateLines)) { + foreach ($updateLines as $valueId => $vals) { + $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') +INNER JOIN civicrm_entity_financial_trxn eft + ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item') +SET li.qty = {$vals['qty']}, + li.line_total = {$vals['line_total']}, + fi.amount = {$vals['line_total']}, + eft.amount = {$vals['line_total']} +WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND + (price_field_value_id = {$valueId}) +"; + CRM_Core_DAO::executeQuery($updateLineItem); + } + } + // insert new 'adjusted amount' transaction entry and update contribution entry. // ensure entity_financial_trxn table has a linking of it. $updatedAmount = $params['amount']; diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 587cfc472e..f8928cb9de 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -236,6 +236,9 @@ class CRM_Event_Form_Participant extends CRM_Contact_Form_Task { $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id' ); + + $this->assign('hasPayment', $this->_paymentId); + // CRM-12615 - Get payment information from the primary registration if ((!$this->_paymentId) && ($this->_action == CRM_Core_Action::UPDATE)) { $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', diff --git a/CRM/Event/Form/ParticipantView.php b/CRM/Event/Form/ParticipantView.php index fd69ba2945..dc38494c24 100644 --- a/CRM/Event/Form/ParticipantView.php +++ b/CRM/Event/Form/ParticipantView.php @@ -68,6 +68,12 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form { $this->assign('contactId', $contactID); $this->assign('participantId', $participantID); + + $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', + $participantID, 'id', 'participant_id' + ); + $this->assign('hasPayment', $paymentId); + $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id'); $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); diff --git a/templates/CRM/Contribute/Page/PaymentInfo.tpl b/templates/CRM/Contribute/Page/PaymentInfo.tpl index 02e479cf83..c09daaf24e 100644 --- a/templates/CRM/Contribute/Page/PaymentInfo.tpl +++ b/templates/CRM/Contribute/Page/PaymentInfo.tpl @@ -27,16 +27,18 @@ {literal} {/literal} diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index 92d228ef77..f460a10664 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -296,7 +296,7 @@ {ts}Source for this registration (if applicable).{/ts} - {if $participantId} + {if $participantId and $hasPayment} @@ -332,7 +332,7 @@ {* JS block for ADD or UPDATE actions only *} {if $action eq 1 or $action eq 2} - {if $participantId} + {if $participantId and $hasPayment} {include file="CRM/Contribute/Page/PaymentInfo.tpl" show='event-payment'} {/if} diff --git a/templates/CRM/Event/Form/ParticipantView.tpl b/templates/CRM/Event/Form/ParticipantView.tpl index 192ba55804..b715ce6f2c 100644 --- a/templates/CRM/Event/Form/ParticipantView.tpl +++ b/templates/CRM/Event/Form/ParticipantView.tpl @@ -99,7 +99,7 @@ {/if} - {if $participantId} + {if $participantId and $hasPayment} @@ -110,7 +110,9 @@ {if $lineItem} {else} @@ -124,7 +126,7 @@ {/if} {/foreach}
{ts}Fees{/ts}{ts}Event Source{/ts}{$source} 
{ts}Fees{/ts} {ts}Selections{/ts} {include file="CRM/Price/Page/LineItem.tpl" context="Event"} + {if $hasPayment}
{ts}Change Selections{/ts}
+ {/if}
{ts}Event Level{/ts}
- {if $participantId} + {if $participantId and $hasPayment} {include file="CRM/Contribute/Page/PaymentInfo.tpl" show='event-payment'} {/if} {include file="CRM/Custom/Page/CustomDataView.tpl"} -- 2.25.1