diff --git a/app/Console/Commands/ChargeRenewalInvoices.php b/app/Console/Commands/ChargeRenewalInvoices.php index 4773f53c43d0..6f1de0a95d7a 100644 --- a/app/Console/Commands/ChargeRenewalInvoices.php +++ b/app/Console/Commands/ChargeRenewalInvoices.php @@ -5,6 +5,7 @@ use App\Ninja\Mailers\ContactMailer as Mailer; use App\Ninja\Repositories\AccountRepository; use App\Services\PaymentService; use App\Models\Invoice; +use App\Models\Account; /** * Class ChargeRenewalInvoices @@ -55,8 +56,8 @@ class ChargeRenewalInvoices extends Command { $this->info(date('Y-m-d').' ChargeRenewalInvoices...'); - $account = $this->accountRepo->getNinjaAccount(); - $invoices = Invoice::whereAccountId($account->id) + $ninjaAccount = $this->accountRepo->getNinjaAccount(); + $invoices = Invoice::whereAccountId($ninjaAccount->id) ->whereDueDate(date('Y-m-d')) ->with('client') ->orderBy('id') @@ -65,6 +66,14 @@ class ChargeRenewalInvoices extends Command $this->info(count($invoices).' invoices found'); foreach ($invoices as $invoice) { + + // check if account has switched to free since the invoice was created + $account = Account::find($invoice->client->public_id); + $company = $account->company; + if ( ! $company->plan || $company->plan == PLAN_FREE) { + continue; + } + $this->info("Charging invoice {$invoice->invoice_number}"); $this->paymentService->autoBillInvoice($invoice); } diff --git a/app/Models/Account.php b/app/Models/Account.php index 4c7cc5177aaa..4472b98ad51f 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1240,7 +1240,7 @@ class Account extends Eloquent $price = $this->company->plan_price; $trial_plan = $this->company->trial_plan; - if(!$plan && (!$trial_plan || !$include_trial)) { + if((!$plan || $plan == PLAN_FREE) && (!$trial_plan || !$include_trial)) { return null; }