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 | */ |
37 | trait 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 |
97dc7b64 |
46 | */ |
f1b56c48 |
47 | protected function alterLineItemsForTemplate(&$tplLineItems) { |
48 | if (!CRM_Invoicing_Utils::isInvoicingEnabled()) { |
49 | return; |
50 | } |
51 | // @todo this should really be the first time we are determining |
52 | // the tax rates - we can calculate them from the financial_type_id |
53 | // & amount here so we didn't need a deeper function to semi-get |
54 | // them but not be able to 'format them right' because they are |
55 | // potentially being used for 'something else'. |
56 | // @todo invoicing code - please feel the hate. Also move this 'hook-like-bit' |
57 | // to the CRM_Invoicing_Utils class. |
97dc7b64 |
58 | foreach ($tplLineItems as $key => $value) { |
59 | foreach ($value as $k => $v) { |
97288cdc |
60 | if (isset($v['tax_rate']) && $v['tax_rate'] != '') { |
f1b56c48 |
61 | // These only need assigning once, but code is more readable with them here |
62 | $this->assign('getTaxDetails', TRUE); |
63 | $this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm()); |
97288cdc |
64 | // Cast to float to display without trailing zero decimals |
65 | $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate']; |
97dc7b64 |
66 | } |
67 | } |
68 | } |
f1b56c48 |
69 | } |
70 | |
71 | /** |
72 | * Assign line items to the template. |
73 | * |
74 | * @param $tplLineItems |
75 | */ |
76 | protected function assignLineItemsToTemplate($tplLineItems) { |
77 | // @todo this should be a hook that invoicing code hooks into rather than a call to it. |
78 | $this->alterLineItemsForTemplate($tplLineItems); |
79 | $this->assign('lineItem', $tplLineItems); |
97dc7b64 |
80 | } |
81 | |
82 | } |