Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20569: Add priceset validation on a partial payment use-case and other improvements #11000

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$totalAmount = $sumOfSelectedOptions really?

// 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