-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Add FrontEndPaymentFormTrait to start to share functionality between Event and Contribution forms #13843
Merged
eileenmcnaughton
merged 1 commit into
civicrm:master
from
eileenmcnaughton:trait_online
Mar 19, 2019
Merged
Add FrontEndPaymentFormTrait to start to share functionality between Event and Contribution forms #13843
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2019 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2019 | ||
*/ | ||
|
||
/** | ||
* This class holds functionality shared between various front end forms. | ||
*/ | ||
trait CRM_Financial_Form_FrontEndPaymentFormTrait { | ||
|
||
/** | ||
* Alter line items for template. | ||
* | ||
* This is an early cut of what will ideally eventually be a hooklike call to the | ||
* CRM_Invoicing_Utils class with a potential end goal of moving this handling to an extension. | ||
* | ||
* @param $tplLineItems | ||
* | ||
* @return array | ||
*/ | ||
protected function alterLineItemsForTemplate($tplLineItems) { | ||
$getTaxDetails = FALSE; | ||
foreach ($tplLineItems as $key => $value) { | ||
foreach ($value as $k => $v) { | ||
if (isset($v['tax_rate'])) { | ||
if ($v['tax_rate'] != '') { | ||
$getTaxDetails = TRUE; | ||
// Cast to float to display without trailing zero decimals | ||
$tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate']; | ||
} | ||
} | ||
} | ||
} | ||
// @todo fix this to only return $tplLineItems. Calling function can check for tax rate and | ||
// do all invoicing related assigns | ||
// another discrete function (it's just one more iteration through a an array with only a handful of | ||
// lines so the separation of concerns is more important than 'efficiency' | ||
return [$getTaxDetails, $tplLineItems]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should fix this before we start sharing with other forms.... But I wanted to keep it really easy to replicate & verify |
||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we collapse this if down to
if(!empty($v['tax_rate'])
as that's exactly what the 2 if statements here are doingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire what if the tax rate is 0% hypothetically like what if some line items have tax applied but not others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire Yes we can - I'm happy to add it in here but there is other cleanup to do in this function so I deliberately left the cleanup out of the first round to keep it simple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 that's fine - if ANY rows have tax then the getTaxDetails = TRUE is assigned to the template
A good follow up question is 'what does getTaxDetails mean'
I see it used in a few places - where I would probably say it's the wrong way to assign
And which probably rely on the variable being assigned somewhere completely different - so it's likely absolutely nothing is achieved.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire Actually in the cleanup round changing from 2 lines to the same 2 conditions on one line makes more sense as adding assumptions that the template doesn't want to know about zero is probably a bigger leap - but I'd rather cleanup as PR 2