1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5402 from turbo124/v5-develop

Fixes for endless recursion
This commit is contained in:
David Bomba 2021-04-10 12:06:01 +10:00 committed by GitHub
commit f0e14073e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 7 deletions

View File

@ -310,8 +310,6 @@ class InvoiceSum
private function getSurchargeTaxTotalForKey($key, $rate)
{
nlog("in the surg");
$tax_component = 0;
if($this->invoice->custom_surcharge_tax1)
@ -333,9 +331,7 @@ class InvoiceSum
{
$tax_component += round($this->invoice->custom_surcharge4 * ($rate / 100), 2);
}
nlog("key = {$key}");
nlog("tax component = {$tax_component}");
return $tax_component;
}

View File

@ -46,7 +46,7 @@ trait GeneratesCounter
$counter_string = $this->getEntityCounter($entity, $client);
$pattern = $this->getNumberPattern($entity, $client);
if (strpos($pattern, 'clientCounter') || strpos($pattern, 'client_counter')) {
if ((strpos($pattern, 'clientCounter') !== false) || (strpos($pattern, 'client_counter') !==false) ) {
if (property_exists($client->settings, $counter_string)) {
$counter = $client->settings->{$counter_string};
@ -55,7 +55,7 @@ trait GeneratesCounter
}
$counter_entity = $client;
} elseif (strpos($pattern, 'groupCounter') || strpos($pattern, 'group_counter')) {
} elseif ((strpos($pattern, 'groupCounter') !== false) || (strpos($pattern, 'group_counter') !== false)) {
if (property_exists($client->group_settings, $counter_string)) {
$counter = $client->group_settings->{$counter_string};
@ -73,6 +73,10 @@ trait GeneratesCounter
//If it is a quote - we need to
$pattern = $this->getNumberPattern($entity, $client);
if(strlen($pattern) > 1 && (stripos($pattern, 'counter') === false)){
$pattern = $pattern.'{$counter}';
}
$padding = $client->getSetting('counter_padding');
if($is_recurring)
@ -333,6 +337,7 @@ trait GeneratesCounter
*/
private function checkEntityNumber($class, $entity, $counter, $padding, $pattern, $prefix = '')
{
$check = false;
do {
@ -347,6 +352,11 @@ trait GeneratesCounter
$counter++;
} while ($check);
nlog($counter);
nlog($pattern);
nlog($number);
return $number;
}
@ -482,6 +492,9 @@ trait GeneratesCounter
}
switch ($company->reset_counter_frequency_id) {
case RecurringInvoice::FREQUENCY_DAILY:
$reset_date->addDay();
break;
case RecurringInvoice::FREQUENCY_WEEKLY:
$reset_date->addWeek();
break;

View File

@ -73,6 +73,45 @@ class GeneratesCounterTest extends TestCase
$this->assertTrue($this->hasSharedCounter($this->client));
}
public function testNoCounterBeingSpecifiedInCounterStringStub()
{
$settings = $this->client->company->settings;
$settings->invoice_number_counter = 1;
$settings->invoice_number_pattern = 'test-{$counter}';
$settings->shared_invoice_quote_counter = 1;
$this->client->company->settings = $settings;
$this->client->company->save();
$this->client->settings = $settings;
$this->client->save();
$this->client->fresh();
$invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->assertEquals('test-0001', $invoice_number);
}
public function testNoCounterBeingSpecifiedInCounterStringWithFix()
{
$settings = $this->client->company->settings;
$settings->invoice_number_counter = 100;
$settings->invoice_number_pattern = 'test-';
$settings->shared_invoice_quote_counter = 100;
$this->client->company->settings = $settings;
$this->client->company->save();
$this->client->settings = $settings;
$this->client->save();
$this->client->fresh();
$invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);
$this->assertEquals('test-0100', $invoice_number);
}
public function testInvoiceNumberValue()
{
$invoice_number = $this->getNextInvoiceNumber($this->client, $this->invoice);