Merge pull request #21590 from totten/master-msgtplui
[civicrm-core.git] / CRM / Financial / Form / SalesTaxTrait.php
CommitLineData
a6e29c95 1<?php
2/*
bc77d7c0
TO
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 +--------------------------------------------------------------------+
a6e29c95 10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
a6e29c95 16 */
a6e29c95 17trait 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() {
530f1e12 39 if (!Civi::settings()->get('invoicing')) {
a6e29c95 40 return '';
41 }
530f1e12 42 return Civi::settings()->get('tax_term');
a6e29c95 43 }
44
45 /**
46 * Assign information to the template required for sales tax purposes.
47 */
48 public function assignSalesTaxMetadataToTemplate() {
49 $this->assignSalesTaxRates();
50 $this->assignSalesTaxTermToTemplate();
51 }
52
53 /**
54 * Get sales tax rates.
55 *
56 * @return array
57 */
58 public function getTaxRatesForFinancialTypes() {
59 return CRM_Core_PseudoConstant::getTaxRates();
60 }
61
62 /**
63 * @param int $financialTypeID
64 *
65 * @return string
66 */
67 public function getTaxRateForFinancialType($financialTypeID) {
68 return CRM_Utils_Array::value($financialTypeID, $this->getTaxRatesForFinancialTypes());
69 }
70
71}