sendInvoice() public method

public sendInvoice ( Invoice $invoice, boolean $reminder = false, boolean $pdfString = false ) : boolean | null | string
$invoice app\models\Invoice
$reminder boolean
$pdfString boolean
return boolean | null | string
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendRecurringInvoices...');
     $today = new DateTime();
     $invoices = Invoice::with('account.timezone', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today])->orderBy('id', 'asc')->get();
     $this->info(count($invoices) . ' recurring invoice(s) found');
     foreach ($invoices as $recurInvoice) {
         $shouldSendToday = $recurInvoice->shouldSendToday();
         $this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($shouldSendToday ? 'YES' : 'NO'));
         if (!$shouldSendToday) {
             continue;
         }
         $recurInvoice->account->loadLocalizationSettings($recurInvoice->client);
         $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice);
         if ($invoice && !$invoice->isPaid()) {
             $this->info('Sending Invoice');
             $this->mailer->sendInvoice($invoice);
         }
     }
     $delayedAutoBillInvoices = Invoice::with('account.timezone', 'recurring_invoice', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS FALSE
         AND balance > 0 AND due_date = ? AND recurring_invoice_id IS NOT NULL', [$today->format('Y-m-d')])->orderBy('invoices.id', 'asc')->get();
     $this->info(count($delayedAutoBillInvoices) . ' due recurring invoice instance(s) found');
     /** @var Invoice $invoice */
     foreach ($delayedAutoBillInvoices as $invoice) {
         if ($invoice->isPaid()) {
             continue;
         }
         if ($invoice->getAutoBillEnabled() && $invoice->client->autoBillLater()) {
             $this->info('Processing Autobill-delayed Invoice ' . $invoice->id);
             $this->paymentService->autoBillInvoice($invoice);
         }
     }
     $this->info('Done');
 }
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendRenewalInvoices...');
     // get all accounts with plans expiring in 10 days
     $companies = Company::whereRaw('datediff(plan_expires, curdate()) = 10')->orderBy('id')->get();
     $this->info(count($companies) . ' companies found renewing in 10 days');
     foreach ($companies as $company) {
         if (!count($company->accounts)) {
             continue;
         }
         $account = $company->accounts->sortBy('id')->first();
         $plan = [];
         $plan['plan'] = $company->plan;
         $plan['term'] = $company->plan_term;
         $plan['num_users'] = $company->num_users;
         $plan['price'] = min($company->plan_price, Utils::getPlanPrice($plan));
         if ($company->pending_plan) {
             $plan['plan'] = $company->pending_plan;
             $plan['term'] = $company->pending_term;
             $plan['num_users'] = $company->pending_num_users;
             $plan['price'] = min($company->pending_plan_price, Utils::getPlanPrice($plan));
         }
         if ($plan['plan'] == PLAN_FREE || !$plan['plan'] || !$plan['term'] || !$plan['price']) {
             continue;
         }
         $client = $this->accountRepo->getNinjaClient($account);
         $invitation = $this->accountRepo->createNinjaInvoice($client, $account, $plan, 0, false);
         // set the due date to 10 days from now
         $invoice = $invitation->invoice;
         $invoice->due_date = date('Y-m-d', strtotime('+ 10 days'));
         $invoice->save();
         $term = $plan['term'];
         $plan = $plan['plan'];
         if ($term == PLAN_TERM_YEARLY) {
             $this->mailer->sendInvoice($invoice);
             $this->info("Sent {$term}ly {$plan} invoice to {$client->getDisplayName()}");
         } else {
             $this->info("Created {$term}ly {$plan} invoice for {$client->getDisplayName()}");
         }
     }
     $this->info('Done');
 }
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendReminders...');
     $accounts = $this->accountRepo->findWithReminders();
     $this->info(count($accounts) . ' accounts found');
     /** @var \App\Models\Account $account */
     foreach ($accounts as $account) {
         if (!$account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
             continue;
         }
         $invoices = $this->invoiceRepo->findNeedingReminding($account);
         $this->info($account->name . ': ' . count($invoices) . ' invoices found');
         /** @var Invoice $invoice */
         foreach ($invoices as $invoice) {
             if ($reminder = $account->getInvoiceReminder($invoice)) {
                 $this->info('Send to ' . $invoice->id);
                 $this->mailer->sendInvoice($invoice, $reminder);
             }
         }
     }
     $this->info('Done');
 }