Fixes for generating counters

This commit is contained in:
David Bomba 2022-10-02 12:24:49 +11:00
parent 2b07dd1066
commit e951a44737
3 changed files with 16 additions and 4 deletions

View File

@ -33,6 +33,9 @@ use Illuminate\Support\Str;
*/ */
trait GeneratesConvertedQuoteCounter trait GeneratesConvertedQuoteCounter
{ {
private int $update_counter;
private function harvestQuoteCounter($quote, $invoice, Client $client) private function harvestQuoteCounter($quote, $invoice, Client $client)
{ {
$settings = $client->getMergedSettings(); $settings = $client->getMergedSettings();

View File

@ -34,6 +34,9 @@ use Illuminate\Support\Str;
*/ */
trait GeneratesCounter trait GeneratesCounter
{ {
private int $update_counter;
//todo in the form validation, we need to ensure that if a prefix and pattern is set we throw a validation error, //todo in the form validation, we need to ensure that if a prefix and pattern is set we throw a validation error,
//only one type is allow else this will cause confusion to the end user //only one type is allow else this will cause confusion to the end user
@ -418,7 +421,8 @@ trait GeneratesCounter
$check_counter = 1; $check_counter = 1;
do { do {
nlog($counter);
$number = $this->padCounter($counter, $padding); $number = $this->padCounter($counter, $padding);
$number = $this->applyNumberPattern($entity, $number, $pattern); $number = $this->applyNumberPattern($entity, $number, $pattern);
@ -432,12 +436,16 @@ trait GeneratesCounter
if ($check_counter > 100) { if ($check_counter > 100) {
$this->update_counter = $counter--;
return $number.'_'.Str::random(5); return $number.'_'.Str::random(5);
} }
} while ($check); } while ($check);
$this->update_counter = $counter--;
return $number; return $number;
} }
@ -469,7 +477,8 @@ trait GeneratesCounter
$settings->{$counter_name} = 1; $settings->{$counter_name} = 1;
} }
$settings->{$counter_name} = $settings->{$counter_name} + 1; // $settings->{$counter_name} = $settings->{$counter_name} + 1;
$settings->{$counter_name} = $this->update_counter;
$entity->settings = $settings; $entity->settings = $settings;

View File

@ -179,7 +179,7 @@ class GeneratesCounterTest extends TestCase
$invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh()); $invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh());
$this->assertEquals($invoice_number, '0002'); $this->assertEquals($invoice_number, '0003');
} }
public function testQuoteNumberValue() public function testQuoteNumberValue()
@ -351,7 +351,7 @@ class GeneratesCounterTest extends TestCase
$invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice); $invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice);
$this->assertEquals($invoice_number, '0002'); $this->assertEquals($invoice_number, '0003');
} }
public function testClientNumber() public function testClientNumber()