Merge pull request #13843 from eileenmcnaughton/trait_online
[civicrm-core.git] / CRM / Financial / Form / FrontEndPaymentFormTrait.php
CommitLineData
97dc7b64 1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33
34/**
35 * This class holds functionality shared between various front end forms.
36 */
37trait CRM_Financial_Form_FrontEndPaymentFormTrait {
38
39 /**
40 * Alter line items for template.
41 *
42 * This is an early cut of what will ideally eventually be a hooklike call to the
43 * CRM_Invoicing_Utils class with a potential end goal of moving this handling to an extension.
44 *
45 * @param $tplLineItems
46 *
47 * @return array
48 */
49 protected function alterLineItemsForTemplate($tplLineItems) {
50 $getTaxDetails = FALSE;
51 foreach ($tplLineItems as $key => $value) {
52 foreach ($value as $k => $v) {
53 if (isset($v['tax_rate'])) {
54 if ($v['tax_rate'] != '') {
55 $getTaxDetails = TRUE;
56 // Cast to float to display without trailing zero decimals
57 $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
58 }
59 }
60 }
61 }
62 // @todo fix this to only return $tplLineItems. Calling function can check for tax rate and
63 // do all invoicing related assigns
64 // another discrete function (it's just one more iteration through a an array with only a handful of
65 // lines so the separation of concerns is more important than 'efficiency'
66 return [$getTaxDetails, $tplLineItems];
67 }
68
69}