diff --git a/app/Services/Invoice/ApplyNumber.php b/app/Services/Invoice/ApplyNumber.php index 4f975d9e02..9f431bd5f1 100644 --- a/app/Services/Invoice/ApplyNumber.php +++ b/app/Services/Invoice/ApplyNumber.php @@ -39,11 +39,11 @@ class ApplyNumber extends AbstractService switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': - $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice); + $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice, $this->invoice->recurring_id); break; case 'when_sent': if ($this->invoice->status_id == Invoice::STATUS_SENT) { - $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice); + $this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice, $this->invoice->recurring_id); } break; diff --git a/app/Services/Recurring/ApplyNumber.php b/app/Services/Recurring/ApplyNumber.php index cac2010abc..8f623d021b 100644 --- a/app/Services/Recurring/ApplyNumber.php +++ b/app/Services/Recurring/ApplyNumber.php @@ -33,26 +33,11 @@ class ApplyNumber extends AbstractService /* Recurring numbers are set when saved */ public function run() { - if ($this->recurring_entity->number != '') { + if ($this->recurring_entity->number != '') return $this->recurring_entity; - } - $this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client); - - // switch ($this->client->getSetting('counter_number_applied')) { - // case 'when_saved': - // $this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client); - // break; - // case 'when_sent': - // break; - - // default: - // $this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client); - // break; - // } - return $this->recurring_entity; } } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 0364ee0fbd..1225c09521 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -35,7 +35,7 @@ trait GeneratesCounter - private function getNextEntityNumber($entity, Client $client) + private function getNextEntityNumber($entity, Client $client, $is_recurring = false) { $prefix = ''; @@ -75,7 +75,7 @@ trait GeneratesCounter $padding = $client->getSetting('counter_padding'); - if($entity instanceof Invoice && $entity && $entity->recurring_id) + if($is_recurring) $prefix = $client->getSetting('recurring_number_prefix'); $entity_number = $this->checkEntityNumber($entity, $client, $counter, $padding, $pattern, $prefix); @@ -154,9 +154,9 @@ trait GeneratesCounter * @param Invoice|null $invoice * @return string The next invoice number. */ - public function getNextInvoiceNumber(Client $client, ?Invoice $invoice) :string + public function getNextInvoiceNumber(Client $client, ?Invoice $invoice, $is_recurring = false) :string { - return $this->getNextEntityNumber(Invoice::class, $client); + return $this->getNextEntityNumber(Invoice::class, $client, $is_recurring); } /**