Fix billing calculations when services have an end date
This commit is contained in:
parent
d7829b93b9
commit
39a230f94c
@ -530,7 +530,7 @@ class Service extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the invoice has an end date, our invoice period shouldnt be greater than that.
|
// If the invoice has an end date, our invoice period shouldnt be greater than that.
|
||||||
if ($this->date_end AND $date > $this->date_end)
|
if ($this->date_end AND $this->date_end < $date)
|
||||||
$date = $this->date_end;
|
$date = $this->date_end;
|
||||||
|
|
||||||
return $date;
|
return $date;
|
||||||
@ -547,45 +547,42 @@ class Service extends Model
|
|||||||
switch ($this->recur_schedule) {
|
switch ($this->recur_schedule) {
|
||||||
// Weekly
|
// Weekly
|
||||||
case 0:
|
case 0:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->startOfWeek())->days;
|
$d = $this->invoice_next->addWeek()->diff($this->invoice_next_end->startOfWeek())->days;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Monthly
|
// Monthly
|
||||||
case 1:
|
case 1:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->startOfMonth())->days;
|
$d = $this->invoice_next->addMonth()->diff($this->invoice_next_end->startOfMonth())->days;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Quarterly
|
// Quarterly
|
||||||
case 2:
|
case 2:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->startOfQuarter())->days;
|
$d = $this->invoice_next->addQuarter()->diff($this->invoice_next_end->startOfQuarter())->days;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Half Yearly
|
// Half Yearly
|
||||||
case 3:
|
case 3:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->startOfHalf())->days;
|
$d = $this->invoice_next->addHalf()->diff($this->invoice_next_end->startOfHalf())->days;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Yearly
|
// Yearly
|
||||||
case 4:
|
case 4:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->startOfYear())->days;
|
$d = $this->invoice_next->addYear()->diff($this->invoice_next_end->startOfYear())->days;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Two Yearly
|
// Two Yearly
|
||||||
case 5:
|
case 5:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->subyear(2))->days-1;
|
$d = $this->invoice_next->addYear(2)->diff($this->invoice_next_end->subyear(2))->days-1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Three Yearly
|
// Three Yearly
|
||||||
case 6:
|
case 6:
|
||||||
$d = $this->invoice_next_end->diff($this->invoice_next_end->subyear(3))->days-1;
|
$d = $this->invoice_next->addYear(3)->diff($this->invoice_next_end->subyear(3))->days-1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: throw new Exception('Unknown recur_schedule');
|
default: throw new Exception('Unknown recur_schedule');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the start date and end date.
|
|
||||||
$d += 1;
|
|
||||||
|
|
||||||
return round($n/$d,2);
|
return round($n/$d,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user