mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Fixes for calculating pro rata refunds for subscriptions
This commit is contained in:
parent
4364f0d168
commit
a382dbe1b6
@ -29,6 +29,8 @@ class UpdateOrCreateProduct implements ShouldQueue
|
|||||||
|
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
|
public $deleteWhenMissingModels = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
|
@ -331,6 +331,7 @@ class SubscriptionService
|
|||||||
* We refund unused days left.
|
* We refund unused days left.
|
||||||
*
|
*
|
||||||
* @param Invoice $invoice
|
* @param Invoice $invoice
|
||||||
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
private function calculateProRataRefundForSubscription($invoice) :float
|
private function calculateProRataRefundForSubscription($invoice) :float
|
||||||
@ -338,6 +339,20 @@ class SubscriptionService
|
|||||||
if(!$invoice || !$invoice->date || $invoice->status_id != Invoice::STATUS_PAID)
|
if(!$invoice || !$invoice->date || $invoice->status_id != Invoice::STATUS_PAID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/*Remove previous refunds from the calculation of the amount*/
|
||||||
|
$invoice->line_items = collect($invoice->line_items)->filter(function($item){
|
||||||
|
|
||||||
|
if($item->product_key == ctrans("texts.refund"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$amount = $invoice->calc()->getTotal();
|
||||||
|
|
||||||
$start_date = Carbon::parse($invoice->date);
|
$start_date = Carbon::parse($invoice->date);
|
||||||
|
|
||||||
$current_date = now();
|
$current_date = now();
|
||||||
@ -346,7 +361,7 @@ class SubscriptionService
|
|||||||
|
|
||||||
$days_in_frequency = $this->getDaysInFrequency();
|
$days_in_frequency = $this->getDaysInFrequency();
|
||||||
|
|
||||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $amount ,2);
|
||||||
|
|
||||||
return max(0, $pro_rata_refund);
|
return max(0, $pro_rata_refund);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user