Merge pull request #15821 from seamuslee001/dev_core_183_custom_group
[civicrm-core.git] / CRM / Financial / Form / SalesTaxTrait.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 trait CRM_Financial_Form_SalesTaxTrait {
18
19 /**
20 * Assign the sales tax term to the template.
21 */
22 public function assignSalesTaxTermToTemplate() {
23 $this->assign('taxTerm', $this->getSalesTaxTerm());
24 }
25
26 /**
27 * Assign sales tax rates to the template.
28 */
29 public function assignSalesTaxRates() {
30 $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
31 }
32
33 /**
34 * Return the string to be assigned to the template for sales tax - e.g GST, VAT.
35 *
36 * @return string
37 */
38 public function getSalesTaxTerm() {
39 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
40 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
41 if (!$invoicing) {
42 return '';
43 }
44 return CRM_Utils_Array::value('tax_term', $invoiceSettings);
45 }
46
47 /**
48 * Assign information to the template required for sales tax purposes.
49 */
50 public function assignSalesTaxMetadataToTemplate() {
51 $this->assignSalesTaxRates();
52 $this->assignSalesTaxTermToTemplate();
53 }
54
55 /**
56 * Get sales tax rates.
57 *
58 * @return array
59 */
60 public function getTaxRatesForFinancialTypes() {
61 return CRM_Core_PseudoConstant::getTaxRates();
62 }
63
64 /**
65 * @param int $financialTypeID
66 *
67 * @return string
68 */
69 public function getTaxRateForFinancialType($financialTypeID) {
70 return CRM_Utils_Array::value($financialTypeID, $this->getTaxRatesForFinancialTypes());
71 }
72
73 }