mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 22:34:37 -04:00
Implement more testing on generates numbers
This commit is contained in:
parent
568fbdf6c8
commit
71d00c1aeb
@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
/**
|
/**
|
||||||
* Class Bank.
|
* Class Bank.
|
||||||
*/
|
*/
|
||||||
class Bank extends BaseModel
|
class Bank extends Model
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
|
@ -115,14 +115,17 @@ class Client extends BaseModel
|
|||||||
*/
|
*/
|
||||||
public function getSettingsByKey($key)
|
public function getSettingsByKey($key)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Does Setting Exist @ client level */
|
/* Does Setting Exist @ client level */
|
||||||
if(isset($this->getSettings()->{$key}))
|
if(isset($this->getSettings()->{$key}))
|
||||||
{
|
{
|
||||||
|
//Log::error('harvesting client settings for key = '. $key . ' and it has the value = '. $this->getSettings()->{$key});
|
||||||
|
//Log::error(print_r($this->getSettings(),1));
|
||||||
return $this->getSettings();
|
return $this->getSettings();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
return new CompanySettings($this->company->settings);
|
//Log::error('harvesting company settings for key = '. $key);
|
||||||
|
return new CompanySettings($this->company->settings);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,14 +133,14 @@ class Client extends BaseModel
|
|||||||
{
|
{
|
||||||
switch ($entity) {
|
switch ($entity) {
|
||||||
case Client::class:
|
case Client::class:
|
||||||
Log::error('saving client settings');
|
// Log::error('saving client settings');
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->save();
|
$this->save();
|
||||||
break;
|
break;
|
||||||
case Company::class:
|
case Company::class:
|
||||||
Log::error('saving company settings');
|
// Log::error('saving company settings');
|
||||||
$this->company->settings = $settings;
|
$this->company->settings = $settings;
|
||||||
$this->push();
|
$this->company->save();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class ClientLocation extends BaseModel
|
|
||||||
{
|
|
||||||
use MakesHash;
|
|
||||||
|
|
||||||
public $timestamps = false;
|
|
||||||
|
|
||||||
protected $appends = ['client_location_id'];
|
|
||||||
|
|
||||||
public function getRouteKeyName()
|
|
||||||
{
|
|
||||||
return 'client_location_id';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClientLocationIdAttribute()
|
|
||||||
{
|
|
||||||
return $this->encodePrimaryKey($this->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function client()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Client::class);
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Currency extends BaseModel
|
class Currency extends Model
|
||||||
{
|
{
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Gateway extends BaseModel
|
class Gateway extends Model
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Industry extends BaseModel
|
class Industry extends Model
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Language extends BaseModel
|
class Language extends Model
|
||||||
{
|
{
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ trait GeneratesNumberCounter
|
|||||||
|
|
||||||
public function hasSharedCounter() : bool
|
public function hasSharedCounter() : bool
|
||||||
{
|
{
|
||||||
|
Log::error('The Shared Counter = '. $this->getSettingsByKey('shared_invoice_quote_counter')->shared_invoice_quote_counter);
|
||||||
return $this->getSettingsByKey('shared_invoice_quote_counter')->shared_invoice_quote_counter;
|
return $this->getSettingsByKey('shared_invoice_quote_counter')->shared_invoice_quote_counter === TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,20 +125,20 @@ trait GeneratesNumberCounter
|
|||||||
|
|
||||||
$counter = $this->entityName($entity) . '_number_counter';
|
$counter = $this->entityName($entity) . '_number_counter';
|
||||||
|
|
||||||
Log::error($counter);
|
//Log::error($counter);
|
||||||
|
|
||||||
$entity_settings = $this->getSettingsByKey( $counter );
|
$entity_settings = $this->getSettingsByKey( $counter );
|
||||||
|
|
||||||
Log::error(print_r($entity_settings,1));
|
//Log::error(print_r($entity_settings,1));
|
||||||
|
|
||||||
$entity_settings->{$counter} = $entity_settings->{$counter} + 1;
|
$entity_settings->{$counter} = $entity_settings->{$counter} + 1;
|
||||||
|
|
||||||
Log::error($entity_settings->{$counter});
|
//Log::error($entity_settings->{$counter});
|
||||||
Log::error($entity_settings->entity);
|
//Log::error($entity_settings->entity);
|
||||||
|
|
||||||
$this->setSettingsByEntity($entity_settings->entity, $entity_settings);
|
$this->setSettingsByEntity($entity_settings->entity, $entity_settings);
|
||||||
|
|
||||||
Log::error(print_r($entity_settings,1));
|
//Log::error(print_r($entity_settings,1));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ $factory->define(App\Models\Client::class, function (Faker $faker) {
|
|||||||
'shipping_state' => $faker->state,
|
'shipping_state' => $faker->state,
|
||||||
'shipping_postal_code' => $faker->postcode,
|
'shipping_postal_code' => $faker->postcode,
|
||||||
'shipping_country_id' => 4,
|
'shipping_country_id' => 4,
|
||||||
'settings' => ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())),
|
'settings' => new ClientSettings(ClientSettings::defaults()),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,8 @@ namespace Tests\Unit;
|
|||||||
|
|
||||||
use App\DataMapper\DefaultSettings;
|
use App\DataMapper\DefaultSettings;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Credit;
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
use App\Utils\Traits\GeneratesNumberCounter;
|
use App\Utils\Traits\GeneratesNumberCounter;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -32,19 +34,8 @@ class GenerateNumberTest extends TestCase
|
|||||||
$this->faker = \Faker\Factory::create();
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
}
|
|
||||||
|
|
||||||
|
$account = factory(\App\Models\Account::class)->create();
|
||||||
public function testEntityName()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->assertEquals($this->entityName(Client::class), 'client');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCounterVariables()
|
|
||||||
{
|
|
||||||
$account = factory(\App\Models\Account::class)->create();
|
|
||||||
$company = factory(\App\Models\Company::class)->create([
|
$company = factory(\App\Models\Company::class)->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
]);
|
]);
|
||||||
@ -95,20 +86,81 @@ class GenerateNumberTest extends TestCase
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
$this->client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertEquals($client->getCounter(Client::class), 1);
|
|
||||||
|
|
||||||
$this->assertEquals($client->getNextNumber(Client::class),1);
|
public function testEntityName()
|
||||||
|
{
|
||||||
|
|
||||||
$settings = $client->getSettingsByKey('recurring_invoice_number_prefix');
|
$this->assertEquals($this->entityName(Client::class), 'client');
|
||||||
$settings->recurring_invoice_number_prefix = 'R';
|
|
||||||
$client->setSettingsByEntity($settings->entity, $settings);
|
|
||||||
|
|
||||||
$this->assertEquals($client->getNextNumber(RecurringInvoice::class), 'R1');
|
|
||||||
|
|
||||||
$client->incrementCounter(Client::class);
|
|
||||||
|
|
||||||
$this->assertEquals($client->getCounter(Client::class), 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSharedCounter()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->assertFalse($this->client->hasSharedCounter());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientCounterValue()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getCounter(Client::class), 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientNextNumber()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getNextNumber(Client::class),1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecurringInvoiceNumberPrefix()
|
||||||
|
{
|
||||||
|
|
||||||
|
$settings = $this->client->getSettingsByKey('recurring_invoice_number_prefix');
|
||||||
|
$settings->recurring_invoice_number_prefix = 'R';
|
||||||
|
$this->client->setSettingsByEntity($settings->entity, $settings);
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getNextNumber(RecurringInvoice::class), 'R1');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIncrementer()
|
||||||
|
{
|
||||||
|
$this->client->incrementCounter(Client::class);
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getCounter(Client::class), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCounterValues()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getCounter(Invoice::class), 1);
|
||||||
|
$this->assertEquals($this->client->getCounter(RecurringInvoice::class), 1);
|
||||||
|
$this->assertEquals($this->client->getCounter(Credit::class), 1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClassIncrementers()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->client->incrementCounter(Invoice::class);
|
||||||
|
$this->client->incrementCounter(RecurringInvoice::class);
|
||||||
|
$this->client->incrementCounter(Credit::class);
|
||||||
|
|
||||||
|
$this->assertEquals($this->client->getCounter(Invoice::class), 3);
|
||||||
|
$this->assertEquals($this->client->getCounter(RecurringInvoice::class), 3);
|
||||||
|
$this->assertEquals($this->client->getCounter(Credit::class), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientNumberPattern()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user