1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Services/Recurring/RecurringService.php

79 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Recurring;
use App\Models\RecurringInvoice;
2020-10-05 23:46:47 +02:00
use App\Services\Recurring\ApplyNumber;
2020-10-04 23:55:52 +02:00
use App\Services\Recurring\CreateRecurringInvitations;
2020-09-24 13:03:59 +02:00
use Illuminate\Support\Carbon;
class RecurringService
{
protected $recurring_entity;
public function __construct($recurring_entity)
{
$this->recurring_entity = $recurring_entity;
}
//set schedules - update next_send_dates
2020-09-24 02:57:44 +02:00
/**
* Stops a recurring invoice
*
* @return $this RecurringService object
*/
public function stop()
{
$this->status_id = RecurringInvoice::STATUS_PAUSED;
return $this;
}
2020-10-04 23:55:52 +02:00
public function createInvitations()
{
$this->recurring_entity = (new CreateRecurringInvitations($this->recurring_entity))->run();
return $this;
}
2020-09-24 02:57:44 +02:00
public function start()
{
//make sure next_send_date is either now or in the future else return.
if(Carbon::parse($this->recurring_entity->next_send_date)->lt(now()))
return $this;
2020-09-24 13:03:59 +02:00
$this->recurring_entity->status_id = RecurringInvoice::STATUS_ACTIVE;
2020-09-24 02:57:44 +02:00
return $this;
}
2020-10-05 23:46:47 +02:00
/**
* Applies the invoice number.
* @return $this InvoiceService object
*/
public function applyNumber()
{
$this->recurring_entity = (new ApplyNumber($this->recurring_entity->client, $this->recurring_entity))->run();
return $this;
}
2020-09-24 02:57:44 +02:00
public function save()
{
$this->recurring_entity->save();
return $this->recurring_entity;
}
}