mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-08 06:54:35 -04:00
Updated logic for subscription crons
This commit is contained in:
parent
43eccc7cb0
commit
2bf9aa3447
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Cron;
|
namespace App\Jobs\Cron;
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
use App\Models\Company;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use App\Utils\Traits\SubscriptionHooker;
|
use App\Utils\Traits\SubscriptionHooker;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class SubscriptionCron
|
class SubscriptionCron
|
||||||
{
|
{
|
||||||
@ -97,4 +98,61 @@ class SubscriptionCron
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Requires the crons to be updated and set to hourly @ 00:01
|
||||||
|
private function timezoneAware()
|
||||||
|
{
|
||||||
|
$grouped_company_ids =
|
||||||
|
|
||||||
|
Invoice::select('company_id')
|
||||||
|
->where('is_deleted', 0)
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->where('is_proforma', 0)
|
||||||
|
->whereDate('due_date', '<=', now()->addDay()->startOfDay())
|
||||||
|
->whereNull('deleted_at')
|
||||||
|
->whereNotNull('subscription_id')
|
||||||
|
->groupBy('company_id')
|
||||||
|
->cursor()
|
||||||
|
->each(function ($company_id){
|
||||||
|
|
||||||
|
$company = Company::find($company_id);
|
||||||
|
|
||||||
|
$timezone_now = now()->setTimezone($company->timezone()->name);
|
||||||
|
|
||||||
|
//Capture companies within the window of 00:00 and 00:30
|
||||||
|
if($timezone_now->gt($timezone_now->copy()->startOfDay()) && $timezone_now->lt($timezone_now->copy()->startOfDay()->addMinutes(30))) {
|
||||||
|
|
||||||
|
Invoice::query()
|
||||||
|
->where('company_id', $company->id)
|
||||||
|
->whereNull('deleted_at')
|
||||||
|
->where('is_deleted', 0)
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('is_proforma', 0)
|
||||||
|
->whereNotNull('subscription_id')
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->whereDate('due_date', '<=', now()->setTimezone($company->timezone()->name)->addDay()->startOfDay())
|
||||||
|
->cursor()
|
||||||
|
->each(function (Invoice $invoice) {
|
||||||
|
|
||||||
|
$subscription = $invoice->subscription;
|
||||||
|
|
||||||
|
$body = [
|
||||||
|
'context' => 'plan_expired',
|
||||||
|
'client' => $invoice->client->hashed_id,
|
||||||
|
'invoice' => $invoice->hashed_id,
|
||||||
|
'subscription' => $subscription->hashed_id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sendLoad($subscription, $body);
|
||||||
|
//This will send the notification daily.
|
||||||
|
//We'll need to handle this by performing some action on the invoice to either archive it or delete it?
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user