Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20852 Show Tax term on UI #10640

Merged
merged 8 commits into from
Sep 30, 2017
Merged

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Jul 11, 2017

Ref CRM-20772. Show the tax term on the UI when possible (eg. "VAT" instead of "tax").


@mattwire
Copy link
Contributor Author

mattwire commented Aug 4, 2017

@JoeMurray @monishdeb @eileenmcnaughton Any of you have time to review this PR? There's no functional change, it's a tweak to the UI in various places to display sales tax a little bit more nicely. Pinging you as I've seen lot's of nice contribution related UI changes coming through from you :-)

@eileenmcnaughton
Copy link
Contributor

There are 2 things in this - neither of which I'm the expert on - 1 is the translation & @mlutfy would know the best approach there. The second is the rounding of line items & where is safe to do so. I think this probably should be on the form layer rather than a utility function - but I'm not familiar enough with that function to know if that is an issue with this change @KarinG knows the rounding best I think

@eileenmcnaughton
Copy link
Contributor

(as an aside - you should rebase to get rid of the extraneous commits - git rebase -i origin/master (do a get fetch -f first)

@mattwire mattwire force-pushed the CRM-20772_showtaxterm branch 2 times, most recently from 52d2d0a to cc3f313 Compare August 7, 2017 09:41
@mattwire
Copy link
Contributor Author

mattwire commented Aug 7, 2017

@eileenmcnaughton Thanks for the rebase tip. Now done, and I've added a note to the dev docs issue so we can include this workflow: https://github.com/civicrm/civicrm-dev-docs/issues/192

@monishdeb
Copy link
Member

Cool.. will be providing my feedback shortly !!

@@ -653,7 +654,7 @@ CRM.$(function($) {
var totalTaxAmount = taxAmount + Number(totalAmount);
totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );

$("#totalTaxAmount" ).html('Amount with tax : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
$("#totalTaxAmount" ).html('Amount with ' + taxTerm + ' : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this text should be passed through ts(...) as $("#totalTaxAmount" ).html(ts('Amount ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @monishdeb I've fixed that now

@monishdeb
Copy link
Member

I have tested the patch and ensured that Tax term are correctly shown in desired pages, except one place where I left comment. However, casting with float won't cause any regression or unintended side-effect. But, I like to have @KarinG feedback re rounding, before merge :)

@KarinG
Copy link
Contributor

KarinG commented Aug 7, 2017

@mattwire - thanks for rebasing this - looking at this now.

@KarinG
Copy link
Contributor

KarinG commented Aug 7, 2017

Hi @mattwire ! I've pulled your Edits into a 4.6 project that has extensive Sales Tax set up. Below is my summary screenshot;

Only thing that did not display properly for me was online -> Contribution page for Membership -> Confirm and Thank you screens; they both show too many zeros [middle section of screenshot]. Both the invoice PDF and the Contribution view generated from it are fine.

But Math is fine and many displays are much nicer - so don't let this stop the edits from being merged in.

image

@@ -301,7 +301,8 @@ public static function getLineItems($entityId, $entity = 'participant', $isQuick
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
if (isset($lineItems[$dao->id]['financial_type_id']) && array_key_exists($lineItems[$dao->id]['financial_type_id'], $taxRates)) {
// We are close to output/display here - so apply some rounding at output/display level - to not show Tax Rate in all 8 decimals
$lineItems[$dao->id]['tax_rate'] = round($taxRates[$lineItems[$dao->id]['financial_type_id']], 3);
// Cast to float so trailing zero decimals are removed.
$lineItems[$dao->id]['tax_rate'] = (float) round($taxRates[$lineItems[$dao->id]['financial_type_id']], 3);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine - I'm cautiously optimistic with the cast we can remove the round(,3) - but let's keep that in mind for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just checked, and removed the round here. It's only used for display so we don't need it with the cast.

@KarinG
Copy link
Contributor

KarinG commented Aug 7, 2017

Of course it would not be too hard to get rid of the trailing zeros in Confirm and ThankYou as well :-)

…The actual change is a cast to float, but a small amount of rearranging the function was required so it was actually set. Added note that buildQuickform() in Confirm.php and Thankyou.php share quite a bit of code and would benefit from refactoring
@mattwire
Copy link
Contributor Author

mattwire commented Aug 7, 2017

@monishdeb @KarinG Thanks for spending the time to review! @KarinG Awesome screenshot! I just pushed a couple of commits which I think address all your comments.

@@ -523,10 +523,11 @@ public function buildQuickForm() {
$getTaxDetails = FALSE;
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
Copy link
Contributor

@KarinG KarinG Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel these edits are going to require a lot more testing; multiple line items; online contribution form; w/ sales taxes;
I would prefer we merge your TaxTerm work in now: either delete this commit - or by replace it with a less invasive commit -> a TPL edit. All we really want is to change how line.tax_rate is displayed in the LineItem.tpl

<td class="right">{$taxTerm} ({$line.tax_rate}%)</td>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there doesn't seem to be an easy way of stripping zero decimals in smarty - there's things like this but it seems a bit heavy for a tpl: https://stackoverflow.com/questions/26565650/smarty-trim-zeros-from-the-end-of-string-float-value. I have just pushed a simpler, less invasive version of the previous patch. It still uses the cast to float as before, but only makes a single line change to Confirm.php (Thankyou.php requires a block of code to be moved so the lineItem variables are set for display but this is lower risk as Thankyou.php does not save anything, only displays to the end user). I have run tests with multiple line items on the contribution pages and can find no issues with displaying the line items (both use LineItem.tpl for actual display). @KarinG @monishdeb what do you think of the updated patch?

… forms. The actual change is a cast to float, but a small amount of rearranging the function was required so it was actually set. Added note that buildQuickform() in Confirm.php and Thankyou.php share quite a bit of code and would benefit from refactoring"

This reverts commit 4b58e3b.
@KarinG
Copy link
Contributor

KarinG commented Aug 8, 2017

Thank you @mattwire - do you know if there is a test specific to online contributions - multiple line items w/ sales taxes? (not at a desk right now).

@mattwire
Copy link
Contributor Author

mattwire commented Aug 9, 2017

It seems we're a bit light on unit tests in that area :-(
phpunit_contribute_online

@KarinG
Copy link
Contributor

KarinG commented Aug 9, 2017

So my thoughts are we should not make edits to Confirm and ThankYou php code if we don't have an existing test that proves that the edits are ok; Let's remove that commit; get this PR merged - then you can work on the more critical issue (support for more decimals) - first?

@eileenmcnaughton
Copy link
Contributor

@mattwire this test appears to give some cover - I've not read it carefully enough to know how it fits with the change you are making - there are some others in that class that might also

https://github.com/aydun/civicrm-core/blob/50d7b4ea81fe3b87319604300d3e2eb8fa05857e/tests/phpunit/api/v3/ContributionPageTest.php#L1585-L1585

@KarinG
Copy link
Contributor

KarinG commented Aug 9, 2017

That's the test I added [to secure the don't round sales taxes prematurely fix]. For sure it secures back-end entry [I tested the test left and right for that scenario] - but I'm not sure a callAPISuccess('contribution_page', 'submit', $submitParams); properly tests front-end Confirm/ThankYou pathway? I came across such a callAPISuccess('contribution_page', 'submit', $submitParams); test yesterday that passes - yet the feature it tried to secure - has failed in Core.

@eileenmcnaughton
Copy link
Contributor

Contribution_page.submit tests the postProcess (from Confirm I guess) - I don't think it tests Thank you at all. We don't have any precedent for testing thank you pages - but they are display pages rather than data saving pages.

Not sure about the test that passed that you mention - presumably you hit a different variant of factors

@mattwire
Copy link
Contributor Author

@KarinG I've broken out the changes to Confirm/Thankyou.php to a new issue https://issues.civicrm.org/jira/browse/CRM-21062 with PR#10856

So this one should now be good to merge?

@KarinG
Copy link
Contributor

KarinG commented Aug 14, 2017

I'm comfortable with these edits. It's a good improvement (to start displaying actual TaxTerm) and there will be another day when we can be certain the tests are in place to ensure Confirm.php edits don't have unexpected consequences.

@mattwire
Copy link
Contributor Author

Hey @monishdeb is this something you are happy to merge? Based on approval and testing from @KarinG

@monishdeb
Copy link
Member

Sorry for the delay. Merging based on @KarinG approval and my code review.

@monishdeb monishdeb merged commit 9868668 into civicrm:master Sep 30, 2017
@monishdeb
Copy link
Member

@mattwire can you please close related JIRA issue(s)? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants