mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 12:24:36 -04:00
commit
9bdfacd49b
53
app/Console/Commands/RecurringCommand.php
Normal file
53
app/Console/Commands/RecurringCommand.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?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\Console\Commands;
|
||||||
|
|
||||||
|
use App\Jobs\Cron\RecurringInvoicesCron;
|
||||||
|
use App\Models\Design;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class RecurringCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'ninja:send-recurring';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Sends the recurring invoices';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
RecurringInvoicesCron::dispatchNow();
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Http\Requests\RecurringInvoice;
|
namespace App\Http\Requests\RecurringInvoice;
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
use App\Utils\Traits\CleanLineItems;
|
use App\Utils\Traits\CleanLineItems;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -98,7 +99,11 @@ class StoreRecurringInvoiceRequest extends Request
|
|||||||
|
|
||||||
if(isset($input['auto_bill']))
|
if(isset($input['auto_bill']))
|
||||||
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
|
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
|
||||||
|
else{
|
||||||
|
$client = Client::find($this->decodePrimaryKey($input['client_id']));
|
||||||
|
$input['auto_bill'] = $client->getSetting('auto_bill');
|
||||||
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,12 +14,15 @@ namespace App\Jobs\Cron;
|
|||||||
use App\Jobs\RecurringInvoice\SendRecurring;
|
use App\Jobs\RecurringInvoice\SendRecurring;
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class RecurringInvoicesCron
|
class RecurringInvoicesCron
|
||||||
{
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
@ -41,25 +44,34 @@ class RecurringInvoicesCron
|
|||||||
|
|
||||||
if (! config('ninja.db.multi_db_enabled')) {
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
|
|
||||||
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->cursor();
|
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())->cursor();
|
||||||
|
|
||||||
Log::info(Carbon::now()->addMinutes(30).' Sending Recurring Invoices. Count = '.$recurring_invoices->count());
|
Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db);
|
||||||
|
|
||||||
|
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||||
|
|
||||||
|
info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||||
|
|
||||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
|
||||||
SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db);
|
SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//multiDB environment, need to
|
//multiDB environment, need to
|
||||||
foreach (MultiDB::$dbs as $db) {
|
foreach (MultiDB::$dbs as $db) {
|
||||||
|
|
||||||
MultiDB::setDB($db);
|
MultiDB::setDB($db);
|
||||||
|
|
||||||
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->cursor();
|
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())->cursor();
|
||||||
|
|
||||||
Log::info(Carbon::now()->addMinutes(30).' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db);
|
Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db);
|
||||||
|
|
||||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||||
|
|
||||||
|
info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||||
|
|
||||||
SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db);
|
SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,19 @@ class SendRecurring implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle() : void
|
public function handle() : void
|
||||||
{
|
{
|
||||||
|
info(" in the handle ");
|
||||||
|
|
||||||
// Generate Standard Invoice
|
// Generate Standard Invoice
|
||||||
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
||||||
|
|
||||||
$invoice = $invoice->service()
|
$invoice = $invoice->service()
|
||||||
->markSent()
|
->markSent()
|
||||||
->applyRecurringNumber()
|
->applyNumber()
|
||||||
->createInvitations()
|
->createInvitations()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
info("Invoice {$invoice->number} created");
|
||||||
|
|
||||||
$invoice->invitations->each(function ($invitation) use ($invoice) {
|
$invoice->invitations->each(function ($invitation) use ($invoice) {
|
||||||
|
|
||||||
$email_builder = (new InvoiceEmail())->build($invitation);
|
$email_builder = (new InvoiceEmail())->build($invitation);
|
||||||
@ -76,6 +80,7 @@ class SendRecurring implements ShouldQueue
|
|||||||
if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled)
|
if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled)
|
||||||
$invoice->service()->autoBill()->save();
|
$invoice->service()->autoBill()->save();
|
||||||
|
|
||||||
|
info("updating recurring invoice dates");
|
||||||
/* Set next date here to prevent a recurring loop forming */
|
/* Set next date here to prevent a recurring loop forming */
|
||||||
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d');
|
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d');
|
||||||
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
|
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
|
||||||
@ -85,6 +90,10 @@ class SendRecurring implements ShouldQueue
|
|||||||
if ($this->recurring_invoice->remaining_cycles == 0)
|
if ($this->recurring_invoice->remaining_cycles == 0)
|
||||||
$this->recurring_invoice->setCompleted();
|
$this->recurring_invoice->setCompleted();
|
||||||
|
|
||||||
|
info($this->recurring_invoice->next_send_date);
|
||||||
|
info($this->recurring_invoice->remaining_cycles);
|
||||||
|
info($this->recurring_invoice->last_sent_date);
|
||||||
|
|
||||||
$this->recurring_invoice->save();
|
$this->recurring_invoice->save();
|
||||||
|
|
||||||
if ($invoice->invitations->count() > 0)
|
if ($invoice->invitations->count() > 0)
|
||||||
|
@ -47,7 +47,7 @@ class SendVerificationNotification implements ShouldQueue
|
|||||||
MultiDB::setDB($event->company->db);
|
MultiDB::setDB($event->company->db);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$event->user->notify(new VerifyUser($event->user));
|
$event->user->notify(new VerifyUser($event->user, $event->company));
|
||||||
|
|
||||||
Ninja::registerNinjaUser($event->user);
|
Ninja::registerNinjaUser($event->user);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class Gateway extends StaticModel
|
|||||||
'is_secure' => 'boolean',
|
'is_secure' => 'boolean',
|
||||||
'recommended' => 'boolean',
|
'recommended' => 'boolean',
|
||||||
//'visible' => 'boolean',
|
//'visible' => 'boolean',
|
||||||
|
//'sort_order' => 'int',
|
||||||
'updated_at' => 'timestamp',
|
'updated_at' => 'timestamp',
|
||||||
'created_at' => 'timestamp',
|
'created_at' => 'timestamp',
|
||||||
'default_gateway_type_id' => 'string',
|
'default_gateway_type_id' => 'string',
|
||||||
|
@ -200,6 +200,11 @@ class RecurringInvoice extends BaseModel
|
|||||||
|
|
||||||
public function nextSendDate() :?Carbon
|
public function nextSendDate() :?Carbon
|
||||||
{
|
{
|
||||||
|
if(!$this->next_send_date){
|
||||||
|
return null;
|
||||||
|
// $this->next_send_date = now()->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->frequency_id) {
|
switch ($this->frequency_id) {
|
||||||
case self::FREQUENCY_WEEKLY:
|
case self::FREQUENCY_WEEKLY:
|
||||||
return Carbon::parse($this->next_send_date)->addWeek();
|
return Carbon::parse($this->next_send_date)->addWeek();
|
||||||
|
@ -101,6 +101,7 @@ class EntitySentNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans("texts.view_{$this->entity_name}"),
|
'button' => ctrans("texts.view_{$this->entity_name}"),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -146,6 +146,8 @@ class EntityViewedNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans("texts.view_{$this->entity_name}"),
|
'button' => ctrans("texts.view_{$this->entity_name}"),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -96,6 +96,8 @@ class InvoiceSentNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.view_invoice'),
|
'button' => ctrans('texts.view_invoice'),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -96,6 +96,8 @@ class InvoiceViewedNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.view_invoice'),
|
'button' => ctrans('texts.view_invoice'),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -94,6 +94,7 @@ class NewPartialPaymentNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.view_payment'),
|
'button' => ctrans('texts.view_payment'),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -97,6 +97,7 @@ class NewPaymentNotification extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.view_payment'),
|
'button' => ctrans('texts.view_payment'),
|
||||||
'signature' => $this->settings->email_signature,
|
'signature' => $this->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -73,6 +73,7 @@ class NewAccountCreated extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.account_login'),
|
'button' => ctrans('texts.account_login'),
|
||||||
'signature' => $this->company->settings->email_signature,
|
'signature' => $this->company->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->company->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -73,6 +73,7 @@ class NewAccountCreated extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.account_login'),
|
'button' => ctrans('texts.account_login'),
|
||||||
'signature' => $this->company->settings->email_signature,
|
'signature' => $this->company->settings->email_signature,
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $this->company->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -32,9 +32,12 @@ class VerifyUser extends Notification implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
public function __construct($user)
|
private $company;
|
||||||
|
|
||||||
|
public function __construct($user, $company)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
$this->company = $company;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +66,7 @@ class VerifyUser extends Notification implements ShouldQueue
|
|||||||
'button' => ctrans('texts.button_confirmation_message'),
|
'button' => ctrans('texts.button_confirmation_message'),
|
||||||
'signature' => '',
|
'signature' => '',
|
||||||
'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png',
|
'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png',
|
||||||
|
'settings' => $this->company->settings,
|
||||||
];
|
];
|
||||||
|
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
"maennchen/zipstream-php": "^1.2",
|
"maennchen/zipstream-php": "^1.2",
|
||||||
"nwidart/laravel-modules": "^6.0",
|
"nwidart/laravel-modules": "^6.0",
|
||||||
"omnipay/paypal": "^3.0",
|
"omnipay/paypal": "^3.0",
|
||||||
"omnipay/stripe": "^3.0",
|
|
||||||
"predis/predis": "^1.1",
|
"predis/predis": "^1.1",
|
||||||
"sentry/sentry-laravel": "^1.8",
|
"sentry/sentry-laravel": "^1.8",
|
||||||
"spatie/browsershot": "^3.37",
|
"spatie/browsershot": "^3.37",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user