public function fire() { $this->info(date('Y-m-d') . ' ChargeRenewalInvoices...'); $ninjaAccount = $this->accountRepo->getNinjaAccount(); $invoices = Invoice::whereAccountId($ninjaAccount->id)->whereDueDate(date('Y-m-d'))->where('balance', '>', 0)->with('client')->orderBy('id')->get(); $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); if (!$account) { continue; } $company = $account->company; if (!$company->plan || $company->plan == PLAN_FREE) { continue; } try { $this->info("Charging invoice {$invoice->invoice_number}"); $this->paymentService->autoBillInvoice($invoice); } catch (Exception $exception) { $this->info('Error: ' . $exception->getMessage()); } } $this->info('Done'); }
public function fire() { $this->info(date('Y-m-d') . ' ChargeRenewalInvoices...'); $account = $this->accountRepo->getNinjaAccount(); $invoices = Invoice::whereAccountId($account->id)->whereDueDate(date('Y-m-d'))->with('client')->orderBy('id')->get(); $this->info(count($invoices) . ' invoices found'); foreach ($invoices as $invoice) { $this->info("Charging invoice {$invoice->invoice_number}"); $this->paymentService->autoBillInvoice($invoice); } $this->info('Done'); }
public function findNeedingReminding($account) { $dates = []; for ($i = 1; $i <= 3; $i++) { $field = "enable_reminder{$i}"; if (!$account->{$field}) { continue; } $field = "num_days_reminder{$i}"; $dates[] = "due_date = '" . date('Y-m-d', strtotime("- {$account->{$field}} days")) . "'"; } $sql = implode(' OR ', $dates); $invoices = Invoice::whereAccountId($account->id)->where('balance', '>', 0)->whereRaw('(' . $sql . ')')->get(); return $invoices; }
public function findNeedingReminding($account) { $dates = []; for ($i = 1; $i <= 3; $i++) { if ($date = $account->getReminderDate($i)) { $field = $account->{"field_reminder{$i}"} == REMINDER_FIELD_DUE_DATE ? 'due_date' : 'invoice_date'; $dates[] = "{$field} = '{$date}'"; } } $sql = implode(' OR ', $dates); $invoices = Invoice::whereAccountId($account->id)->where('balance', '>', 0)->whereRaw('(' . $sql . ')')->get(); return $invoices; }