Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Update interaction with contribution_invoice_settings #50

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions CRM/Lineitemedit/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static function insertFinancialItemOnAdd($lineItem, $trxn) {
// create financial item for added line item
$newFinancialItemDAO = CRM_Financial_BAO_FinancialItem::create($newFinancialItem, NULL, $trxnId);
if (!empty($lineItem['tax_amount']) && $lineItem['tax_amount'] != 0) {
$taxTerm = CRM_Utils_Array::value('tax_term', Civi::settings()->get('contribution_invoice_settings'));
$taxTerm = Civi::settings()->get('tax_term');
$taxFinancialItemInfo = array_merge($newFinancialItem, array(
'amount' => $lineItem['tax_amount'],
'description' => $taxTerm,
Expand Down Expand Up @@ -379,9 +379,8 @@ public static function getPriceFieldInfo() {
$priceFieldValueInfo = civicrm_api3('PriceFieldValue', 'getsingle', array('id' => $priceFieldValueID));

// calculate tax amount
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
if (!empty($contributeSettings['invoicing']) &&
if (Civi::settings()->get('invoicing') &&
array_key_exists($priceFieldValueInfo['financial_type_id'], $taxRates)
) {
$taxRate = $taxRates[$priceFieldValueInfo['financial_type_id']];
Expand Down Expand Up @@ -424,8 +423,7 @@ public static function getLineitemFieldNames($isAddItem = FALSE) {
}

// if tax is enabled append tax_amount field name
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');
if (!empty($contributeSettings['invoicing'])) {
if (Civi::settings()->get('invoicing')) {
$fieldNames = array_merge($fieldNames, array('tax_amount'));
}

Expand Down Expand Up @@ -664,7 +662,7 @@ public static function recordChangeInAmount(
$financialItem['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($lineItem['financial_type_id'], $accountRelName);
$ftItem = CRM_Financial_BAO_FinancialItem::create($financialItem, NULL, $trxnId);
if ($taxAmountChanged && $balanceTaxAmount != 0) {
$taxTerm = CRM_Utils_Array::value('tax_term', Civi::settings()->get('contribution_invoice_settings'));
$taxTerm = Civi::settings()->get('tax_term');
$taxFinancialItemInfo = array_merge($financialItem, array(
'amount' => $balanceTaxAmount,
'description' => $taxTerm,
Expand Down Expand Up @@ -726,7 +724,7 @@ public static function recordChangeInFT(
$trxnId = array('id' => $trxnId);
$ftItem = CRM_Financial_BAO_FinancialItem::create($financialItem, NULL, $trxnId);
if ($values['tax_amount'] != 0) {
$taxTerm = CRM_Utils_Array::value('tax_term', Civi::settings()->get('contribution_invoice_settings'));
$taxTerm = Civi::settings()->get('tax_term');
$taxFinancialItemInfo = array_merge($financialItem, array(
'amount' => $values['tax_amount'],
'description' => $taxTerm,
Expand Down Expand Up @@ -922,8 +920,7 @@ public static function buildLineItemRows(&$form, $contributionID = NULL) {
}
}
}
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');
$form->assign('taxEnabled', (!empty($contributeSettings['invoicing'])));
$form->assign('taxEnabled', Civi::settings()->get('invoicing'));
$form->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
$form->assign('lineItemSubmitted', json_encode($submittedValues));
}
Expand Down
6 changes: 3 additions & 3 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<url desc="Support">https://github.com/JMAConsulting/biz.jmaconsulting.lineitemedit/issues</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-06-24</releaseDate>
<version>2.2</version>
<releaseDate>2020-02-01</releaseDate>
<version>2.3</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
<ver>5.23</ver>
</compatibility>
<comments>This extension allows a backend user to add, edit and cancel line item(s) associated with a Contribution.
</comments>
Expand Down
2 changes: 1 addition & 1 deletion lineitemedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function lineitemedit_civicrm_pre($op, $entity, $entityID, &$params) {
if ($entity == 'Contribution') {
if ($op == 'create' && empty($params['price_set_id'])) {
$lineItemParams = [];
$taxEnabled = (bool) CRM_Utils_Array::value('invoicing', Civi::settings()->get('contribution_invoice_settings'));
$taxEnabled = (bool) Civi::settings()->get('invoicing');
for ($i = 0; $i <= 10; $i++) {
$lineItemParams[$i] = [];
$notFound = TRUE;
Expand Down
18 changes: 7 additions & 11 deletions tests/phpunit/CRM/Lineitemedit/Form/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,28 +327,24 @@ protected function enableTaxAndInvoicing($params = array()) {
'invoicing' => 1,
'invoice_prefix' => 'INV_',
'credit_notes_prefix' => 'CN_',
'due_date' => 10,
'due_date_period' => 'days',
'notes' => '',
'invoice_due_date' => 10,
'invoice_due_date_period' => 'days',
'invoice_notes' => '',
'is_email_pdf' => 1,
'tax_term' => 'Sales Tax',
'tax_display_settings' => 'Inclusive',
)
);
return Civi::settings()->set('contribution_invoice_settings', $contributeSetting);
foreach ($contributeSetting as $key => $value) {
Civi::settings()->set($key, $value);
}
}

/**
* Enable Tax and Invoicing
*/
protected function disableTaxAndInvoicing($params = array()) {
// Enable component contribute setting
$contributeSetting = array_merge($params,
array(
'invoicing' => 0,
)
);
return Civi::settings()->set('contribution_invoice_settings', $contributeSetting);
return Civi::settings()->set('invoicing', 0);
}

/**
Expand Down