invoice = $invoice; $this->settings = $settings; $this->company = $company; } /** * Execute the job. * * * @return void */ public function handle() { MultiDB::setDB($this->company->db); //return early if($this->invoice->number != '') return $this->invoice; switch ($this->settings->counter_number_applied) { case 'when_saved': $this->invoice->number = $this->getNextInvoiceNumber($this->invoice->client); break; case 'when_sent': if($this->invoice->status_id == Invoice::STATUS_SENT) $this->invoice->number = $this->getNextInvoiceNumber($this->invoice->client); break; default: # code... break; } $this->invoice->save(); return $this->invoice; } }