1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Recurring services - trial phase'

This commit is contained in:
David Bomba 2021-03-29 14:49:29 +11:00
parent d7bf927549
commit db7df69db7
2 changed files with 15 additions and 8 deletions

View File

@ -342,7 +342,7 @@ class BaseController extends Controller
$query->where('activities.user_id', $user->id);
},
'company.subscriptions'=> function ($query) use($user) {
'company.subscriptions'=> function ($query) use($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at);
if(!$user->isAdmin())

View File

@ -75,20 +75,27 @@ class SubscriptionService
$recurring_invoice_repo = new RecurringInvoiceRepository();
$subscription_repo = new SubscriptionRepository();
$invoice = RecurringInvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$invoice->line_items = $subscription_repo->generateLineItems($this->subscription, true);
$invoice->subscription_id = $this->subscription->id;
$invoice->frequency_id = $this->subscription->frequency_id;
$invoice->date = now()->addSeconds($this->subscription->trial_duration)->addDays(1);
$recurring_invoice = RecurringInvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$recurring_invoice->line_items = $subscription_repo->generateLineItems($this->subscription, true);
$recurring_invoice->subscription_id = $this->subscription->id;
$recurring_invoice->frequency_id = $this->subscription->frequency_id;
$recurring_invoice->date = now();
$recurring_invoice->next_send_date = now()->addSeconds($this->subscription->trial_duration)->addDays(1);
$recurring_invoice->remaining_cycles = -1;
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
{
$invoice->discount = $this->subscription->promo_discount;
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
$recurring_invoice->discount = $this->subscription->promo_discount;
$recurring_invoice->is_amount_discount = $this->subscription->is_amount_discount;
}
$recurring_invoice = $recurring_invoice_repo->save($data, $invoice);
/* Start the recurring service */
$recurring_invoice->service()
->start()
->save();
//execute any webhooks
$this->triggerWebhook();