Recalculation of tax amounts / totals when an editted invoice or expense is saved.

Comments

Magnity’s picture

Magnity’s picture

Category: feature » bug

Marked as duplicate of this issue:
#508146: Tax and Total fields in Invoice item are not calculated efter editing
#371734: Recalculate Timetracking Duration on Each Save

Thus extending this issue to cover:
- Tax / totals on invoices (+ invoiceitems) and expenses
- Timetracking durations

All of which need some consideration on edit/save.

homoludens’s picture

Status: Active » Needs review

We don't even need a patch for this just change the code:

function _storminvoiceitem_beforesave(&$node) {
  if (!$node->tax) {
    $node->tax = $node->amount * $node->taxpercent * .01;
  }
  if (!$node->total) {
    $node->total = $node->amount + $node->tax;
  }
}

to

function _storminvoiceitem_beforesave(&$node) {
    $node->tax = $node->amount * $node->taxpercent * .01;
    $node->total = $node->amount + $node->tax;
}

I'm not sure why are those if's here, and i don't see the point. Invoice items and Invoice totals works nice without them.

homoludens’s picture

As expected same thing is for expense:

function _stormexpense_beforesave(&$node) {
  $node->expensedate = _storm_date_to_gmtimestamp($node->expensedate);

  if (!$node->total) {
    $node->total = $node->amount + $node->tax;
  }
...

chage to

function _stormexpense_beforesave(&$node) {
  $node->expensedate = _storm_date_to_gmtimestamp($node->expensedate);

  $node->total = $node->amount + $node->tax;

...

Same thing with time tracking duration:

function _stormtimetracking_beforesave(&$node) {
  $timebegin = _storm_strtotime($node->timebegin);
  $timeend = _storm_strtotime($node->timeend);

  if (is_array($node->trackingdate)) {
    $node->trackingdate = _storm_datetime_to_gmtimestamp($node->trackingdate + $timebegin);
  }

  $node->timebegin = _timetostr($timebegin);
  $node->timeend = _timetostr($timeend);

  if (!$node->duration) {
    $node->duration = ($timeend['hour'] - $timebegin['hour'] + ($timeend['minute'] - $timebegin['minute']) / 60);
  }

...

Maybe I'm missing something?

Magnity’s picture

I think the ifs were there in order to give a user the opportunity to manually override them if so desired. However, I think it is better to remove this flexibility but to gain the guaranteed consistency.

I have made these changes for invoices and expenses and also marked those fields on the node form as readonly so that there is no confusion about inputted data being overriden. The changes will all be committed later today when I am on a different web connection.

The timetracking ones I believe needs some option in order that those who have specified the duration in a custom way do not have to have it overriden.

Magnity’s picture

Status: Needs review » Fixed

Implemented setting for timetracking which defaults to automatically updating on any save, but can be switched back to the previous behaviour of only updating if duration is blank by a checkbox.

Possibility of further changes to the method of calculating durations if we change the start / end / duration format anyway though.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

cliffdiver1’s picture

I'm still experiencing this issue on 6.x-1.33

juliangb’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Please could you post some more details about the problem you´re experiencing, so we can see whether it is the same one and how the change above has helped / hindered.

juliangb’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Closed due to inactivity.