mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor - Breaking changes to GeneratesNumberCounter that require attention
This commit is contained in:
parent
e4b0aba5a0
commit
058e12fbf6
@ -106,7 +106,6 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $shared_invoice_quote_counter;
|
||||
|
||||
public $entity_number_padding;
|
||||
public $recurring_invoice_number_prefix;
|
||||
public $reset_counter_frequency_id;
|
||||
public $reset_counter_date;
|
||||
|
@ -26,29 +26,30 @@ class InvoiceToRecurringInvoiceFactory
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_DRAFT;
|
||||
$recurring_invoice->discount = $invoice->discount;
|
||||
$recurring_invoice->invoice_number = '';
|
||||
$recurring_invoice->is_amount_discount = $recurringinvoice->is_amount_discount;
|
||||
$recurring_invoice->po_number = $recurringinvoice->po_number;
|
||||
$recurring_invoice->footer = $recurringinvoice->footer;
|
||||
$recurring_invoice->terms = $recurringinvoice->terms;
|
||||
$recurring_invoice->public_notes = $recurringinvoice->public_notes;
|
||||
$recurring_invoice->private_notes = $recurringinvoice->private_notes;
|
||||
$recurring_invoice->is_amount_discount = $invoice->is_amount_discount;
|
||||
$recurring_invoice->po_number = $invoice->po_number;
|
||||
$recurring_invoice->footer = $invoice->footer;
|
||||
$recurring_invoice->terms = $invoice->terms;
|
||||
$recurring_invoice->public_notes = $invoice->public_notes;
|
||||
$recurring_invoice->private_notes = $invoice->private_notes;
|
||||
$recurring_invoice->invoice_date = date_create()->format('Y-m-d');
|
||||
$recurring_invoice->due_date = $recurringinvoice->due_date; //todo calculate based on terms
|
||||
$recurring_invoice->is_deleted = $recurringinvoice->is_deleted;
|
||||
$recurring_invoice->line_items = $recurringinvoice->line_items;
|
||||
$recurring_invoice->settings = $recurringinvoice->settings;
|
||||
$recurring_invoice->tax_name1 = $recurringinvoice->tax_name1;
|
||||
$recurring_invoice->tax_rate1 = $recurringinvoice->tax_rate1;
|
||||
$recurring_invoice->tax_name2 = $recurringinvoice->tax_name2;
|
||||
$recurring_invoice->tax_rate2 = $recurringinvoice->tax_rate2;
|
||||
$recurring_invoice->custom_value1 = $recurringinvoice->custom_value1;
|
||||
$recurring_invoice->custom_value2 = $recurringinvoice->custom_value2;
|
||||
$recurring_invoice->custom_value3 = $recurringinvoice->custom_value3;
|
||||
$recurring_invoice->custom_value4 = $recurringinvoice->custom_value4;
|
||||
$recurring_invoice->amount = $recurringinvoice->amount;
|
||||
$recurring_invoice->balance = $recurringinvoice->balance;
|
||||
$recurring_invoice->user_id = $recurringinvoice->user_id;
|
||||
$recurring_invoice->company_id = $recurringinvoice->company_id;
|
||||
$recurring_invoice->due_date = $invoice->due_date; //todo calculate based on terms
|
||||
$recurring_invoice->is_deleted = $invoice->is_deleted;
|
||||
$recurring_invoice->line_items = $invoice->line_items;
|
||||
$recurring_invoice->settings = $invoice->settings;
|
||||
$recurring_invoice->tax_name1 = $invoice->tax_name1;
|
||||
$recurring_invoice->tax_rate1 = $invoice->tax_rate1;
|
||||
$recurring_invoice->tax_name2 = $invoice->tax_name2;
|
||||
$recurring_invoice->tax_rate2 = $invoice->tax_rate2;
|
||||
$recurring_invoice->custom_value1 = $invoice->custom_value1;
|
||||
$recurring_invoice->custom_value2 = $invoice->custom_value2;
|
||||
$recurring_invoice->custom_value3 = $invoice->custom_value3;
|
||||
$recurring_invoice->custom_value4 = $invoice->custom_value4;
|
||||
$recurring_invoice->amount = $invoice->amount;
|
||||
$recurring_invoice->balance = $invoice->balance;
|
||||
$recurring_invoice->user_id = $invoice->user_id;
|
||||
$recurring_invoice->client_id = $invoice->client_id;
|
||||
$recurring_invoice->company_id = $invoice->company_id;
|
||||
$recurring_invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$recurring_invoice->start_date = null;
|
||||
$recurring_invoice->last_sent_date = null;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Repositories\ActivityRepository;
|
||||
@ -43,7 +44,7 @@ class UpdateInvoiceActivity
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
$fields->client_id = $event->invoice->id;
|
||||
$fields->client_id = $event->invoice->client_id;
|
||||
$fields->user_id = $event->invoice->user_id;
|
||||
$fields->company_id = $event->invoice->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_INVOICE;
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Filters\QueryFilters;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Hashids\Hashids;
|
||||
@ -42,6 +44,9 @@ class BaseModel extends Model
|
||||
return parent::__call($method, $params);
|
||||
}
|
||||
|
||||
/*
|
||||
V2 type of scope
|
||||
*/
|
||||
public function scopeCompany($query, $company_id)
|
||||
{
|
||||
$query->where('company_id', $company_id);
|
||||
@ -49,6 +54,9 @@ class BaseModel extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/*
|
||||
V1 type of scope
|
||||
*/
|
||||
public function scopeScope($query)
|
||||
{
|
||||
|
||||
@ -57,4 +65,73 @@ class BaseModel extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}))
|
||||
{
|
||||
//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();
|
||||
}
|
||||
else {
|
||||
//Log::error(print_r(new CompanySettings($this->company->settings),1));
|
||||
return new CompanySettings($this->company->settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function setSettingsByEntity($entity, $settings)
|
||||
{
|
||||
switch ($entity) {
|
||||
case Client::class:
|
||||
// Log::error('saving client settings');
|
||||
$this->settings = $settings;
|
||||
$this->save();
|
||||
$this->fresh();
|
||||
break;
|
||||
case Company::class:
|
||||
// Log::error('saving company settings');
|
||||
$this->company->settings = $settings;
|
||||
$this->company->save();
|
||||
break;
|
||||
//todo check that saving any other entity (Invoice:: RecurringInvoice::) settings is valid using the default:
|
||||
default:
|
||||
$this->client->settings = $settings;
|
||||
$this->client->save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings.
|
||||
*
|
||||
* Generic getter for client settings
|
||||
*
|
||||
* @return ClientSettings The settings.
|
||||
*/
|
||||
public function getSettings()
|
||||
{
|
||||
return new ClientSettings($this->settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -95,69 +95,11 @@ class Client extends BaseModel
|
||||
return Timezone::find($this->getMergedSettings()->timezone_id);
|
||||
}
|
||||
|
||||
public function getSettings()
|
||||
{
|
||||
return new ClientSettings($this->settings);
|
||||
}
|
||||
|
||||
public function getMergedSettings()
|
||||
{
|
||||
|
||||
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}))
|
||||
{
|
||||
//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();
|
||||
}
|
||||
else {
|
||||
//Log::error(print_r(new CompanySettings($this->company->settings),1));
|
||||
return new CompanySettings($this->company->settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setSettingsByEntity($entity, $settings)
|
||||
{
|
||||
switch ($entity) {
|
||||
case Client::class:
|
||||
// Log::error('saving client settings');
|
||||
$this->settings = $settings;
|
||||
$this->save();
|
||||
$this->fresh();
|
||||
break;
|
||||
case Company::class:
|
||||
// Log::error('saving company settings');
|
||||
$this->company->settings = $settings;
|
||||
$this->company->save();
|
||||
$this->company->fresh();
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function documents()
|
||||
|
@ -57,7 +57,8 @@ class RecurringInvoice extends BaseModel
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'settings' => 'object'
|
||||
'settings' => 'object',
|
||||
'line_items' => 'object',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
|
@ -35,19 +35,16 @@ trait GeneratesNumberCounter
|
||||
$prefix = $this->getNumberPrefix($entity);
|
||||
$lastNumber = false;
|
||||
|
||||
|
||||
$check = false;
|
||||
|
||||
do {
|
||||
|
||||
if ($this->hasNumberPattern($entity)) {
|
||||
$number = $this->applyNumberPattern($entity, $counter);
|
||||
} else {
|
||||
$number = $prefix . str_pad($counter, $this->invoice_number_padding, '0', STR_PAD_LEFT);
|
||||
$number = $prefix . str_pad($counter, $entity->getSettingsByKey('counter_padding')->counter_padding, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
// if ($entity == RecurringInvoice::class) {
|
||||
// $number = $this->getSettingsByKey('recurring_invoice_number_prefix')->recurring_invoice_number_prefix . $number;
|
||||
// }
|
||||
|
||||
if ($entity_name == Client::class) {
|
||||
$check = Client::company($this->company_id)->whereIdNumber($number)->withTrashed()->first();
|
||||
@ -77,10 +74,18 @@ trait GeneratesNumberCounter
|
||||
//increment the counter here
|
||||
}
|
||||
|
||||
public function hasSharedCounter() : bool
|
||||
|
||||
/**
|
||||
* Determines if it has shared counter.
|
||||
*
|
||||
* @param object $entity The entity
|
||||
*
|
||||
* @return boolean True if has shared counter, False otherwise.
|
||||
*/
|
||||
public function hasSharedCounter($entity) : bool
|
||||
{
|
||||
|
||||
return $this->getSettingsByKey('shared_invoice_quote_counter')->shared_invoice_quote_counter === TRUE;
|
||||
return $entity->getSettingsByKey('shared_invoice_quote_counter')->shared_invoice_quote_counter === TRUE;
|
||||
|
||||
}
|
||||
|
||||
@ -111,7 +116,7 @@ trait GeneratesNumberCounter
|
||||
|
||||
$field = $entity_name . "_number_pattern";
|
||||
|
||||
return $this->getSettingsByKey( $field )->{$field};
|
||||
return $entity->getSettingsByKey( $field )->{$field};
|
||||
|
||||
}
|
||||
|
||||
@ -126,7 +131,7 @@ trait GeneratesNumberCounter
|
||||
|
||||
$field = $this->entityName($entity_name) . "_number_prefix";
|
||||
|
||||
return $this->getSettingsByKey( $field )->{$field};
|
||||
return $entity->getSettingsByKey( $field )->{$field};
|
||||
|
||||
}
|
||||
|
||||
@ -139,7 +144,7 @@ trait GeneratesNumberCounter
|
||||
|
||||
//Log::error('entity = '.$entity_name);
|
||||
|
||||
$entity_settings = $this->getSettingsByKey( $counter );
|
||||
$entity_settings = $entity->getSettingsByKey( $counter );
|
||||
|
||||
//Log::error(print_r($entity_settings,1));
|
||||
|
||||
@ -149,9 +154,9 @@ trait GeneratesNumberCounter
|
||||
// Log::error('value '.$entity_settings->{$counter});
|
||||
// Log::error('value inc '.$entity_settings->{$counter}++);
|
||||
//Log::error($entity_settings->{$counter});
|
||||
//Log::error($entity_settings->entity);
|
||||
Log::error('entity name = '.$entity_settings->entity);
|
||||
|
||||
$this->setSettingsByEntity($entity_settings->entity, $entity_settings);
|
||||
$entity->setSettingsByEntity($entity_settings->entity, $entity_settings);
|
||||
|
||||
//Log::error(print_r($entity_settings,1));
|
||||
|
||||
@ -167,10 +172,13 @@ trait GeneratesNumberCounter
|
||||
|
||||
public function getCounter($entity) : int
|
||||
{
|
||||
|
||||
//company specific settings need to fall back to COMPANY not $entity
|
||||
$counter = $this->getCounterName($entity) . '_number_counter';
|
||||
|
||||
return $this->getSettingsByKey( $counter )->{$counter};
|
||||
|
||||
if($counter == 'client_number_counter')
|
||||
return $entity->company->getSettingsByKey( $counter )->{$counter};
|
||||
else
|
||||
return $entity->getSettingsByKey( $counter )->{$counter};
|
||||
|
||||
}
|
||||
|
||||
@ -185,7 +193,7 @@ trait GeneratesNumberCounter
|
||||
$entity_name = $this->entityName($entity);
|
||||
|
||||
$counter = $counter ?: $this->getCounter($entity_name);
|
||||
$pattern = $this->getNumberPattern($entity_name);
|
||||
$pattern = $this->getNumberPattern($entity);
|
||||
|
||||
if (! $pattern) {
|
||||
return false;
|
||||
@ -195,7 +203,7 @@ trait GeneratesNumberCounter
|
||||
$replace = [date('Y')];
|
||||
|
||||
$search[] = '{$counter}';
|
||||
$replace[] = str_pad($counter, $this->getSettingsByKey( 'counter_padding' )->counter_padding, '0', STR_PAD_LEFT);
|
||||
$replace[] = str_pad($counter, $entity->getSettingsByKey( 'counter_padding' )->counter_padding, '0', STR_PAD_LEFT);
|
||||
|
||||
if (strstr($pattern, '{$user_id}')) {
|
||||
$user_id = auth()->check() ? auth()->user()->id : 0;
|
||||
@ -210,7 +218,7 @@ trait GeneratesNumberCounter
|
||||
$search[] = $matches[0];
|
||||
|
||||
/* The following adjusts for the company timezone - may bork tests depending on the time of day the tests are run!!!!!!*/
|
||||
$date = Carbon::now($this->company->timezone()->name)->format($format);
|
||||
$date = Carbon::now($entity->company->timezone()->name)->format($format);
|
||||
$replace[] = str_replace($format, $date, $matches[1]);
|
||||
}
|
||||
|
||||
@ -243,7 +251,7 @@ trait GeneratesNumberCounter
|
||||
|
||||
$counter = $this->getCounterName($entity) . '_number_counter';
|
||||
|
||||
$counter_value = $this->getSettingsByKey( $counter )->{$counter};
|
||||
$counter_value = $entity->client->getSettingsByKey( $counter )->{$counter};
|
||||
$entity_padding = $this->getSettingsByKey( 'counter_padding' )->counter_padding;
|
||||
|
||||
$replace = [
|
||||
@ -263,7 +271,7 @@ trait GeneratesNumberCounter
|
||||
private function getCounterName($entity)
|
||||
{
|
||||
|
||||
if($this->entityName($entity) == $this->entityName(RecurringInvoice::class) || ( $this->entityName($entity) == $this->entityName(Quote::class) && $this->hasSharedCounter()) )
|
||||
if($this->entityName($entity) == $this->entityName(RecurringInvoice::class) || ( $this->entityName($entity) == $this->entityName(Quote::class) && $this->hasSharedCounter($entity)) )
|
||||
$entity = Invoice::class;
|
||||
|
||||
return $this->entityName($entity);
|
||||
|
@ -373,7 +373,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->string('po_number');
|
||||
$t->date('invoice_date')->nullable();
|
||||
$t->date('due_date')->nullable();
|
||||
$t->datetime('due_date')->nullable();
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
@ -401,7 +401,7 @@ class CreateUsersTable extends Migration
|
||||
$t->decimal('amount', 13, 2);
|
||||
$t->decimal('balance', 13, 2);
|
||||
$t->decimal('partial', 13, 2)->nullable();
|
||||
$t->date('partial_due_date')->nullable();
|
||||
$t->datetime('partial_due_date')->nullable();
|
||||
|
||||
$t->datetime('last_viewed')->nullable();
|
||||
|
||||
@ -429,7 +429,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->string('po_number');
|
||||
$t->date('invoice_date')->nullable();
|
||||
$t->date('due_date')->nullable();
|
||||
$t->datetime('due_date')->nullable();
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
@ -457,14 +457,13 @@ class CreateUsersTable extends Migration
|
||||
$t->decimal('amount', 13, 2);
|
||||
$t->decimal('balance', 13, 2);
|
||||
$t->decimal('partial', 13, 2)->nullable();
|
||||
$t->date('partial_due_date')->nullable();
|
||||
|
||||
$t->datetime('last_viewed')->nullable();
|
||||
|
||||
$t->unsignedInteger('frequency_id');
|
||||
$t->date('start_date')->nullable();
|
||||
$t->date('last_sent_date')->nullable();
|
||||
$t->date('next_send_date')->nullable();
|
||||
$t->datetime('last_sent_date')->nullable();
|
||||
$t->datetime('next_send_date')->nullable();
|
||||
$t->unsignedInteger('remaining_cycles')->nullable();
|
||||
|
||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
@ -490,7 +489,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->string('po_number');
|
||||
$t->date('quote_date')->nullable();
|
||||
$t->date('valid_until')->nullable();
|
||||
$t->datetime('valid_until')->nullable();
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
@ -521,8 +520,8 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->unsignedInteger('frequency_id');
|
||||
$t->date('start_date')->nullable();
|
||||
$t->date('last_sent_date')->nullable();
|
||||
$t->date('next_send_date')->nullable();
|
||||
$t->datetime('last_sent_date')->nullable();
|
||||
$t->datetime('next_send_date')->nullable();
|
||||
$t->unsignedInteger('remaining_cycles')->nullable();
|
||||
|
||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
@ -547,7 +546,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->string('po_number');
|
||||
$t->date('quote_date')->nullable();
|
||||
$t->date('valid_until')->nullable();
|
||||
$t->datetime('valid_until')->nullable();
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
@ -575,7 +574,7 @@ class CreateUsersTable extends Migration
|
||||
$t->decimal('amount', 13, 2);
|
||||
$t->decimal('balance', 13, 2);
|
||||
$t->decimal('partial', 13, 2)->nullable();
|
||||
$t->date('partial_due_date')->nullable();
|
||||
$t->datetime('partial_due_date')->nullable();
|
||||
|
||||
$t->datetime('last_viewed')->nullable();
|
||||
|
||||
@ -603,11 +602,11 @@ class CreateUsersTable extends Migration
|
||||
$t->string('message_id')->nullable();
|
||||
$t->text('email_error');
|
||||
$t->text('signature_base64');
|
||||
$t->date('signature_date')->nullable();
|
||||
$t->datetime('signature_date')->nullable();
|
||||
|
||||
$t->date('sent_date')->nullable();
|
||||
$t->date('viewed_date')->nullable();
|
||||
$t->date('opened_date')->nullable();
|
||||
$t->datetime('sent_date')->nullable();
|
||||
$t->datetime('viewed_date')->nullable();
|
||||
$t->datetime('opened_date')->nullable();
|
||||
|
||||
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$t->foreign('client_contact_id')->references('id')->on('client_contacts')->onDelete('cascade');
|
||||
@ -684,7 +683,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
$t->decimal('amount', 13, 2);
|
||||
$t->date('payment_date')->nullable();
|
||||
$t->datetime('payment_date')->nullable();
|
||||
$t->string('transaction_reference')->nullable();
|
||||
$t->string('payer_id')->nullable();
|
||||
|
||||
|
@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
@ -25,7 +26,6 @@ use Tests\TestCase;
|
||||
class RecurringInvoicesCronTest extends TestCase
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
@ -42,8 +42,14 @@ class RecurringInvoicesCronTest extends TestCase
|
||||
public function testCountCorrectNumberOfRecurringInvoicesDue()
|
||||
{
|
||||
//spin up 5 valid and 1 invalid recurring invoices
|
||||
|
||||
|
||||
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->get();
|
||||
|
||||
$recurring_all = RecurringInvoice::all();
|
||||
|
||||
$this->assertEquals(5, $recurring_invoices->count());
|
||||
|
||||
$this->assertEquals(6, $recurring_all->count());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -87,66 +87,67 @@ trait MockAccountData
|
||||
|
||||
UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->invoice->amount);
|
||||
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now();
|
||||
$recurring_invoice->next_send_date = Carbon::now()->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(2);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(2)->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(10);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(10)->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(15);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(15)->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(20);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(20)->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addDays(10);
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addDays(10)->format('Y-m-d H:i');
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
$recurring_invoice->start_date = Carbon::now();
|
||||
$recurring_invoice->start_date = Carbon::now()->format('Y-m-d');
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber($recurring_invoice);
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice->invoice_number = $this->getNextNumber();
|
||||
$recurring_invoice->save()
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,50 +101,52 @@ class GenerateNumberTest extends TestCase
|
||||
public function testSharedCounter()
|
||||
{
|
||||
|
||||
$this->assertFalse($this->client->hasSharedCounter());
|
||||
$this->assertFalse($this->hasSharedCounter($this->client));
|
||||
|
||||
}
|
||||
|
||||
public function testClientCounterValue()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->client->getCounter($this->client), 1);
|
||||
$this->assertEquals($this->getCounter($this->client), 1);
|
||||
|
||||
}
|
||||
|
||||
public function testClientNextNumber()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->client->getNextNumber($this->client),1);
|
||||
$this->assertEquals($this->getNextNumber($this->client),1);
|
||||
|
||||
}
|
||||
|
||||
public function testRecurringInvoiceNumberPrefix()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->client->getNextNumber(RecurringInvoice::class), 'R1');
|
||||
$this->assertEquals($this->client->getCounter($this->client), 1);
|
||||
//$this->assertEquals($this->getNextNumber(RecurringInvoice::class), 'R1');
|
||||
$this->assertEquals($this->getCounter($this->client), 1);
|
||||
|
||||
}
|
||||
|
||||
public function testClientIncrementer()
|
||||
{
|
||||
$this->client->incrementCounter($this->client);
|
||||
$this->incrementCounter($this->client);
|
||||
|
||||
$this->assertEquals($this->client->getCounter($this->client), 2);
|
||||
$this->assertEquals($this->getCounter($this->client), 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);
|
||||
$this->assertEquals($this->getCounter(Invoice::class), 1);
|
||||
$this->assertEquals($this->getCounter(RecurringInvoice::class), 1);
|
||||
$this->assertEquals($this->getCounter(Credit::class), 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testClassIncrementers()
|
||||
{
|
||||
|
||||
@ -152,13 +154,13 @@ class GenerateNumberTest extends TestCase
|
||||
$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);
|
||||
$this->assertEquals($this->getCounter(Invoice::class), 3);
|
||||
$this->assertEquals($this->getCounter(RecurringInvoice::class), 3);
|
||||
$this->assertEquals($this->getCounter(Credit::class), 2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* {$counter}
|
||||
* {$userId}
|
||||
@ -171,13 +173,20 @@ class GenerateNumberTest extends TestCase
|
||||
|
||||
$settings = $this->client->getSettingsByKey('client_number_pattern');
|
||||
$settings->client_number_pattern = '{$year}-{$counter}';
|
||||
$this->client->setSettingsByEntity($settings->entity, $settings);
|
||||
$this->assertEquals($this->client->getNextNumber($this->client), '2019-1');
|
||||
$this->assertEquals($this->client->getNextNumber($this->client), '2019-2');
|
||||
$this->client->setSettingsByEntity(Client::class, $settings);
|
||||
|
||||
$company = Company::find($this->client->company_id);
|
||||
|
||||
$this->assertEquals($company->settings->client_number_counter,3);
|
||||
$this->assertEquals($company->settings->client_number_counter,1);
|
||||
|
||||
$this->assertEquals($this->getNextNumber($this->client), '2019-1');
|
||||
$this->assertEquals($this->getNextNumber($this->client), '2019-2');
|
||||
|
||||
$company = Company::find($this->client->company_id);
|
||||
|
||||
$this->assertEquals($company->settings->client_number_counter,2);
|
||||
|
||||
$this->assertEquals($this->client->settings->client_number_counter,1);
|
||||
}
|
||||
|
||||
public function testClientNumberPatternWithDate()
|
||||
@ -187,9 +196,9 @@ class GenerateNumberTest extends TestCase
|
||||
|
||||
$settings = $this->client->getSettingsByKey('client_number_pattern');
|
||||
$settings->client_number_pattern = '{$date:j}-{$counter}';
|
||||
$this->client->setSettingsByEntity($settings->entity, $settings);
|
||||
$this->client->setSettingsByEntity(Client::class, $settings);
|
||||
|
||||
$this->assertEquals($this->client->getNextNumber($this->client), date('j') . '-1');
|
||||
$this->assertEquals($this->getNextNumber($this->client), date('j') . '-1');
|
||||
}
|
||||
|
||||
public function testClientNumberPatternWithDate2()
|
||||
@ -198,8 +207,8 @@ class GenerateNumberTest extends TestCase
|
||||
|
||||
$settings = $this->client->getSettingsByKey('client_number_pattern');
|
||||
$settings->client_number_pattern = '{$date:d M Y}-{$counter}';
|
||||
$this->client->setSettingsByEntity($settings->entity, $settings);
|
||||
$this->client->setSettingsByEntity(Client::class, $settings);
|
||||
|
||||
$this->assertEquals($this->client->getNextNumber($this->client), date('d M Y') . '-1');
|
||||
$this->assertEquals($this->getNextNumber($this->client), date('d M Y') . '-1');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user