mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-15 23:52:33 +01:00
107 lines
2.5 KiB
PHP
107 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace App\Services\Recurring;
|
|
|
|
use App\Jobs\Util\UnlinkFile;
|
|
use App\Models\RecurringInvoice;
|
|
use App\Services\Recurring\GetInvoicePdf;
|
|
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
|
|
|
|
/**
|
|
* Stops a recurring invoice
|
|
*
|
|
* @return $this RecurringService object
|
|
*/
|
|
public function stop()
|
|
{
|
|
if($this->recurring_entity->status_id < RecurringInvoice::STATUS_PAUSED)
|
|
$this->recurring_entity->status_id = RecurringInvoice::STATUS_PAUSED;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function createInvitations()
|
|
{
|
|
$this->recurring_entity = (new CreateRecurringInvitations($this->recurring_entity))->run();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
|
|
if ($this->recurring_entity->remaining_cycles == 0) {
|
|
return $this;
|
|
}
|
|
|
|
// $this->createInvitations()->setStatus(RecurringInvoice::STATUS_ACTIVE);
|
|
|
|
$this->setStatus(RecurringInvoice::STATUS_ACTIVE);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setStatus($status)
|
|
{
|
|
$this->recurring_entity->status_id = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
public function getInvoicePdf($contact = null)
|
|
{
|
|
return (new GetInvoicePdf($this->recurring_entity, $contact))->run();
|
|
}
|
|
|
|
public function deletePdf()
|
|
{
|
|
|
|
$this->recurring_entity->invitations->each(function ($invitation){
|
|
|
|
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath($invitation) . $this->recurring_entity->numberFormatter().'.pdf');
|
|
|
|
});
|
|
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->recurring_entity->save();
|
|
|
|
return $this->recurring_entity;
|
|
}
|
|
}
|