1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Working on client, quote, invoice number generator

This commit is contained in:
David Bomba 2019-04-29 15:50:08 +10:00
parent 50a43720d1
commit 76d625d723
5 changed files with 101 additions and 9 deletions

View File

@ -4,6 +4,7 @@ namespace App\DataMapper;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Models\Client;
use App\Utils\TranslationHelper;
/**
@ -53,15 +54,18 @@ class ClientSettings extends BaseSettings
*/
public $invoice_number_prefix;
public $invoice_number_pattern;
public $invoice_number_counter;
public $quote_number_prefix;
public $quote_number_pattern;
public $quote_number_counter;
public $client_number_prefix;
public $client_number_pattern;
public $credit_number_prefix;
public $credit_number_pattern;
public $credit_number_counter;
public $shared_invoice_quote_counter;
@ -95,6 +99,7 @@ class ClientSettings extends BaseSettings
{
return (object)[
'entity' => Client::class,
'industry_id' => NULL,
'size_id' => NULL,
'invoice_email_list' => NULL,

View File

@ -2,6 +2,8 @@
namespace App\DataMapper;
use App\Models\Company;
/**
* CompanySettings
*/
@ -77,15 +79,18 @@ class CompanySettings extends BaseSettings
*/
public $invoice_number_prefix;
public $invoice_number_pattern;
public $invoice_number_counter;
public $quote_number_prefix;
public $quote_number_pattern;
public $quote_number_counter;
public $client_number_prefix;
public $client_number_pattern;
public $credit_number_prefix;
public $credit_number_pattern;
public $credit_number_counter;
public $shared_invoice_quote_counter;
@ -115,6 +120,7 @@ class CompanySettings extends BaseSettings
$config = json_decode(config('ninja.settings'));
return (object) [
'entity' => Company::class,
'timezone_id' => config('ninja.i18n.timezone_id'),
'language_id' => config('ninja.i18n.language_id'),
'currency_id' => config('ninja.i18n.currency_id'),
@ -134,7 +140,10 @@ class CompanySettings extends BaseSettings
'custom_taxes2' => 'FALSE',
'lock_sent_invoices' => 'TRUE',
'shared_invoice_quote_counter' => 'FALSE',
'invoice_number_counter' => 1,
'quote_number_counter' => 1,
'credit_number_counter' => 1,
'translations' => (object) [],
];
}

View File

@ -4,6 +4,7 @@ namespace App\Models;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Models\Client;
use App\Models\Company;
use App\Models\Country;
use App\Models\Filterable;
@ -90,6 +91,54 @@ class Client extends BaseModel
return ClientSettings::buildClientSettings(new CompanySettings($this->company->settings), new ClientSettings($this->settings));
}
/**
* Gets the settings by key.
*
* When we need to update a setting value, we need to harvest
* the object of the setting. This is not possible when using the merged settings
* as we do not know which object the setting has come from.
*
* The following method will return the entire object of the property searched for
* where a value exists for $key.
*
* This object can then be mutated by the handling class,
* to persist the new settings we will also need to pass back a
* reference to the parent class.
*
* @param mixes $key The key of property
*/
public function getSettingsByKey($key)
{
/* Does Setting Exist @ client level */
if(isset($this->getSettings()->{$key}))
{
return $this->getSettings();
}
else
return new CompanySettings($this->company->settings);
}
public function setSettingsByEntity($entity, $settings)
{
switch ($entity) {
case Client::class:
$this->settings = $settings;
$this->save();
break;
case Company::class:
$this->company->settings = $settings;
$this->company->save();
break;
default:
# code...
break;
}
}
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
@ -97,4 +146,5 @@ class Client extends BaseModel
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Utils\Traits;
/**
* Class GeneratesNumberCounter
* @package App\Utils\Traits
*/
trait GeneratesNumberCounter
{
public function getNextNumber($entity)
{
}
public function hasSharedCounter() : bool
{
return $this->getSettingsByKey($shared_invoice_quote_counter)->shared_invoice_quote_counter;
}
public function incrementCounter($entity)
{
}
public function entity_name($entity)
{
return strtolower(class_basename($entity));
}
}

View File

@ -147,10 +147,6 @@ class CreateUsersTable extends Migration
$table->string('vat_number')->nullable();
$table->string('id_number')->nullable();
$table->unsignedInteger('size_id')->nullable();
$table->unsignedInteger('invoice_number_counter')->default(1);
$table->unsignedInteger('quote_number_counter')->default(1);
$table->unsignedInteger('credit_number_counter')->default(1);
$table->text('settings');
@ -288,10 +284,6 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('shipping_country_id')->nullable();
$table->text('settings');
$table->unsignedInteger('invoice_number_counter')->default(1);
$table->unsignedInteger('quote_number_counter')->default(1);
$table->unsignedInteger('credit_number_counter')->default(1);
$table->boolean('is_deleted')->default(false);
$table->string('payment_terms')->nullable(); //todo type? depends how we are storing this
$table->string('vat_number')->nullable();