client = $client; $this->invoice = $invoice; } public function run() { if ($this->invoice->number != '') { return $this->invoice; } switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': $this->invoice->number = $this->getNextInvoiceNumber($this->client); break; case 'when_sent': if ($this->invoice->status_id == Invoice::STATUS_SENT) { $this->invoice->number = $this->getNextInvoiceNumber($this->client); } break; default: // code... break; } return $this->invoice; } }