From: eileen Date: Sat, 16 Mar 2019 07:19:30 +0000 (+1300) Subject: Add FrontEndPaymentFormTrait to start to share functionality between Event and Contri... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=97dc7b6463f4503b10d449d8d72df52a44861dc0;p=civicrm-core.git Add FrontEndPaymentFormTrait to start to share functionality between Event and Contribution forms. I've done one small function extraction in the process --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index cf36444767..0afaf65fb1 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -35,6 +35,7 @@ * form to process actions on the group aspect of Custom Data */ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_ContributionBase { + use CRM_Financial_Form_FrontEndPaymentFormTrait; /** * The id of the contact associated with this contribution. @@ -514,17 +515,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if ($invoicing) { $getTaxDetails = FALSE; $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); - foreach ($this->_lineItem as $key => $value) { - foreach ($value as $k => $v) { - if (isset($v['tax_rate'])) { - if ($v['tax_rate'] != '') { - $getTaxDetails = TRUE; - // Cast to float to display without trailing zero decimals - $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate']; - } - } - } - } + list($getTaxDetails, $tplLineItems) = $this->alterLineItemsForTemplate($tplLineItems); $this->assign('getTaxDetails', $getTaxDetails); $this->assign('taxTerm', $taxTerm); $this->assign('totalTaxAmount', $params['tax_amount']); diff --git a/CRM/Financial/Form/FrontEndPaymentFormTrait.php b/CRM/Financial/Form/FrontEndPaymentFormTrait.php new file mode 100644 index 0000000000..c74dea5ad4 --- /dev/null +++ b/CRM/Financial/Form/FrontEndPaymentFormTrait.php @@ -0,0 +1,69 @@ + $value) { + foreach ($value as $k => $v) { + if (isset($v['tax_rate'])) { + if ($v['tax_rate'] != '') { + $getTaxDetails = TRUE; + // Cast to float to display without trailing zero decimals + $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate']; + } + } + } + } + // @todo fix this to only return $tplLineItems. Calling function can check for tax rate and + // do all invoicing related assigns + // another discrete function (it's just one more iteration through a an array with only a handful of + // lines so the separation of concerns is more important than 'efficiency' + return [$getTaxDetails, $tplLineItems]; + } + +}