-
-
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
[wip] CRM-19585, added function to Calculate Tax for each item when Financi… #9685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5457,4 +5457,25 @@ public static function createProportionalFinancialEntries($entityParams, $lineIt | |
} | ||
} | ||
|
||
/** | ||
* Calculate Tax for each item when Financial Type is changed. | ||
* | ||
* @param array $lineItem | ||
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. It would be nice to know what are the values expected in this $lineItem array 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. explained in updated PR |
||
* | ||
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. no need to this empty line here 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. https://www.drupal.org/node/1354#functions suggests a blank line between args and no blank line after last one. |
||
* @param int $contributionId | ||
* | ||
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. no need for this empty line here 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. Actually, https://www.drupal.org/node/1354#functions suggests a blank line between args and no blank line after last one. |
||
*/ | ||
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. Missing @return 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. Agreed. Partially fixed in updated PR. |
||
public static function calculateTaxAfterChangeInFinancialTypeForLineItems($lineItem, $contributionId) { | ||
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. I think this method name and its description are confusing. Usually, the method name should describe what it does and not when it should be executed. It says it calculates the Tax after the Financial Type is changed, but looking at the code, it looks like it can do the calculation anytime, even if the Financial Type hasn't been changed. 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. Pradeep, there is merit in @davialexandre comment, but the code at some level needs to be either reversing out financial_items for both the line_item and its tax and posting new entries (I think that is the spec at https://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Data+Flow but Confluence is down at the moment) or maybe (I don't think so) creating a difference transaction for financial_line_item for both line item and tax. Could you respond to his comment? Thx. 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. What about adding tests to this new method? 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. Pradeep, you should respond to each comment indicating if you accept it or provide reason(s) for disagreeing. In this case, indicate that you have added a test in updated PR. |
||
$taxAmount = 0; | ||
$previousLineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionId); | ||
foreach ($lineItem as $items) { | ||
foreach ($items as $item) { | ||
$lineTotal = CRM_Utils_Array::value('line_total', CRM_Utils_Array::value($item['id'], $previousLineItem)); | ||
$lineTaxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($lineTotal, $item['tax_rate']); | ||
$taxAmount += $lineTaxAmount['tax_amount']; | ||
} | ||
} | ||
return $taxAmount; | ||
} | ||
|
||
} |
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.
It would be nice to add the logic of the calculation to the method description. Otherwise, we have to read the code in order to understand what is going on
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.
This function is just repeatedly calling a different function that does the calculation. I don't think it should be documenting details that is not responsible for.