Skip to content

Commit

Permalink
Merge pull request civicrm#11000 from JMAConsulting/CRM-20569-1
Browse files Browse the repository at this point in the history
CRM-20569: Add priceset validation on a partial payment use-case and other improvements
  • Loading branch information
eileenmcnaughton authored and sluc23 committed Jan 10, 2018
2 parents 64820ce + e65b8b9 commit 6fab5fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,17 @@ public static function priceSetValidation($priceSetId, $fields, &$error, $allowN
list($componentName) = explode(':', $fields['_qf_default']);
// now we have all selected amount in hand.
$totalAmount = array_sum($selectedAmounts);
// The form offers a field to enter the amount paid. This may differ from the amount that is due to complete the purchase
$totalPaymentAmountEnteredOnForm = CRM_Utils_Array::value('partial_payment_total', $fields, CRM_Utils_Array::value('total_amount', $fields));
if ($totalAmount < 0) {
$error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
}
elseif ($totalAmount > 0 &&
$totalPaymentAmountEnteredOnForm >= $totalAmount && // if total amount is equal to all selected amount in hand
(CRM_Utils_Array::value('contribution_status_id', $fields) == CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Partially paid'))
) {
$error['total_amount'] = ts('You have specified the status Partially Paid but have entered an amount that equals or exceeds the amount due. Please adjust the status of the payment or the amount');
}
}
else {
if ($allowNoneSelection) {
Expand Down
10 changes: 5 additions & 5 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ public static function processAmount($fields, &$params, &$lineItem, $component =
}
if ($priceSetID) {
$priceFields = self::filterPriceFieldsFromParams($priceSetID, $params);
if (count($priceFields) == 1 && !empty($params['total_amount'])) {
$amount_override = $params['total_amount'];
if (count($priceFields) == 1) {
$amount_override = CRM_Utils_Array::value('partial_payment_total', $params, CRM_Utils_Array::value('total_amount', $params));
}
}
foreach ($fields as $id => $field) {
Expand All @@ -719,7 +719,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =
case 'Text':
$firstOption = reset($field['options']);
$params["price_{$id}"] = array($firstOption['id'] => $params["price_{$id}"]);
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, CRM_Utils_Array::value('partial_payment_total', $params));
$optionValueId = key($field['options']);

if (CRM_Utils_Array::value('name', $field['options'][$optionValueId]) == 'contribution_amount') {
Expand Down Expand Up @@ -767,7 +767,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =
$params["price_{$id}"] = array($params["price_{$id}"] => 1);
$optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);

CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, CRM_Utils_Array::value('partial_payment_total', $params));
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionValueId, $totalTax);
}
Expand All @@ -783,7 +783,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =

case 'CheckBox':

CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, CRM_Utils_Array::value('partial_payment_total', $params));
foreach ($params["price_{$id}"] as $optionId => $option) {
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionId, $totalTax);
Expand Down

0 comments on commit 6fab5fa

Please sign in to comment.