1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
invoiceninja/app/Jobs/RecurringInvoice/SendRecurring.php

83 lines
2.0 KiB
PHP
Raw Normal View History

2019-05-23 07:08:31 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\RecurringInvoice;
use App\Factory\RecurringInvoiceToInvoiceFactory;
2019-05-23 08:15:06 +02:00
use App\Models\Invoice;
2019-05-23 07:08:31 +02:00
use App\Models\RecurringInvoice;
use App\Utils\Traits\GeneratesNumberCounter;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
class SendRecurring
{
use GeneratesNumberCounter;
public $recurring_invoice;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(RecurringInvoice $recurring_invoice)
{
$this->recurring_invoice = $recurring_invoice;
}
/**
* Execute the job.
*
* @return void
*/
public function handle() : void
{
// Generate Standard Invoice
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice);
$invoice->invoice_number = $this->getNextNumber($invoice);
2019-05-23 08:15:06 +02:00
$invoice->status_id = Invoice::STATUS_SENT;
2019-05-23 07:08:31 +02:00
$invoice->save();
2019-05-23 08:15:06 +02:00
// Queue: Emails for invoice
// $this->recurring_invoice->settings->invoice_email_list //todo comma separated list of emails to fire this email to
2019-05-23 07:08:31 +02:00
// Fire Payment if auto-bill is enabled
2019-05-23 08:15:06 +02:00
if($this->recurring_invoice->settings->auto_bill)
//PAYMENT ACTION HERE TODO
2019-05-23 07:08:31 +02:00
// Clean up recurring invoice object
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
$this->recurring_invoice->last_sent_date = date('Y-m-d');
if($this->recurring_invoice->remaining_cycles != 0)
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate();
else
$this->recurring_invoice->setCompleted();
$this->recurring_invoice->save();
}
}