1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Subscription Crons

This commit is contained in:
David Bomba 2021-04-07 13:35:16 +10:00
parent 38a648866c
commit 498d8e4efc
2 changed files with 20 additions and 6 deletions

View File

@ -12,6 +12,7 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Invoice;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@ -51,13 +52,21 @@ class SubscriptionCron
private function loopSubscriptions() private function loopSubscriptions()
{ {
//looop recurring invoices with subscription id
// $client_subs = ClientSubscription::whereNull('deleted_at') $invoices = Invoice::where('is_deleted', 0)
// ->cursor() ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
// ->each(function ($cs){ ->where('balance', '>', 0)
// $this->processSubscription($cs); ->whereDate('due_date', '<=', now()->startOfDay())
// }); ->whereNotNull('subscription_id')
->cursor();
$invoices->each(function ($invoice){
$subscription = $invoice->subscription;
});
} }
/* Our daily cron should check /* Our daily cron should check

View File

@ -181,6 +181,11 @@ class Invoice extends BaseModel
return $this->belongsTo(Client::class)->withTrashed(); return $this->belongsTo(Client::class)->withTrashed();
} }
public function subscription()
{
return $this->belongsTo(Subscription::class)->withTrashed();
}
public function documents() public function documents()
{ {
return $this->morphMany(Document::class, 'documentable'); return $this->morphMany(Document::class, 'documentable');