1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
* Improve test data quality

* Add Projects and Tasks to schema

* Improve invoice data quality
This commit is contained in:
David Bomba 2020-01-20 21:40:22 +11:00 committed by GitHub
parent 8a202d54a0
commit db558acf70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 113 additions and 78 deletions

View File

@ -19,6 +19,7 @@ use App\Listeners\Invoice\CreateInvoiceInvitation;
use App\Models\CompanyToken;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\Product;
use App\Models\User;
use App\Repositories\InvoiceRepository;
use App\Utils\Traits\MakesHash;
@ -115,6 +116,11 @@ class CreateTestData extends Command
'settings' => new \stdClass,
]);
factory(\App\Models\Product::class,50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->info('Creating '.$this->count. ' clients');
@ -140,7 +146,7 @@ class CreateTestData extends Command
$this->createVendor($client);
}
}
private function createMediumAccount()
@ -184,6 +190,12 @@ class CreateTestData extends Command
'settings' => new \stdClass,
]);
factory(\App\Models\Product::class,50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->count = $this->count*10;
$this->info('Creating '.$this->count. ' clients');
@ -253,6 +265,12 @@ class CreateTestData extends Command
'settings' => new \stdClass,
]);
factory(\App\Models\Product::class,50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->count = $this->count*100;
$this->info('Creating '.$this->count. ' clients');
@ -352,7 +370,7 @@ class CreateTestData extends Command
// $invoice->date = $faker->date();
$invoice->date = Carbon::now()->subDays(rand(0,90));
$invoice->line_items = $this->buildLineItems();
$invoice->line_items = $this->buildLineItems(rand(1,10));
$invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) {
@ -415,7 +433,7 @@ class CreateTestData extends Command
$quote->client_id = $client->id;
$quote->date = $faker->date();
$quote->line_items = $this->buildLineItems();
$quote->line_items = $this->buildLineItems(rand(1,10));
$quote->uses_inclusive_taxes = false;
if (rand(0, 1)) {
@ -445,31 +463,46 @@ class CreateTestData extends Command
CreateQuoteInvitations::dispatch($quote, $quote->company);
}
private function buildLineItems()
private function buildLineItems($count = 1)
{
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost =10;
for($x=0; $x<$count; $x++)
{
$item = InvoiceItemFactory::create();
$item->quantity = 1;
//$item->cost =10;
if (rand(0, 1)) {
$item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00;
if (rand(0, 1)) {
$item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$item->tax_name1 = 'VAT';
$item->tax_rate1 = 17.50;
}
if (rand(0, 1)) {
$item->tax_name1 = 'Sales Tax';
$item->tax_rate1 = 5;
}
$product = Product::all()->random();
$item->cost = $product->cost;
$item->product_key = $product->product_key;
$item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4;
$line_items[] = $item;
}
if (rand(0, 1)) {
$item->tax_name1 = 'VAT';
$item->tax_rate1 = 17.50;
}
if (rand(0, 1)) {
$item->tax_name1 = 'Sales Tax';
$item->tax_rate1 = 5;
}
$line_items[] = $item;
return $line_items;
}

View File

@ -28,17 +28,6 @@ class Task extends BaseModel
'time_log',
];
protected $appends = ['task_id'];
public function getRouteKeyName()
{
return 'task_id';
}
public function getTaskIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
public function documents()
{

View File

@ -388,23 +388,6 @@ class CreateUsersTable extends Migration
//$table->unique(['company_id', 'email']);
});
Schema::create('projects', function ($t) {
$t->increments('id');
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id');
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('client_id')->nullable();
$t->string('name');
$t->string('description');
$t->timestamps();
$t->softDeletes();
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->foreign('company_id')->references('id')->on('companies');
});
Schema::create('company_gateways', function($table)
{
$table->increments('id');
@ -1004,34 +987,6 @@ class CreateUsersTable extends Migration
});
Schema::create('tasks', function ($table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('assigned_user_id')->nullable();
$table->unsignedInteger('company_id')->index();
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('invoice_id')->nullable();
$table->unsignedInteger('project_id')->nullable();
$table->unsignedInteger('vendor_id')->nullable();
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);
$table->string('custom_value1')->nullable();
$table->string('custom_value2')->nullable();
$table->string('description')->nullable();
$table->boolean('is_deleted')->default(false);
$table->boolean('is_running')->default(false);
$table->mediumText('time_log')->nullable();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
});
Schema::create('banks', function ($table) {
$table->increments('id');
$table->string('name')->nullable();
@ -1338,6 +1293,64 @@ class CreateUsersTable extends Migration
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
Schema::create('projects', function ($t) {
$t->increments('id');
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id');
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('client_id')->nullable();
$t->string('name');
$t->string('description');
$t->decimal('task_rate', 12, 4)->default(0);
$t->date('due_date')->nullable();
$t->text('private_notes')->nullable();
$t->float('budgeted_hours');
$t->text('custom_value1')->nullable();
$t->text('custom_value2')->nullable();
$t->text('custom_value3')->nullable();
$t->text('custom_value4')->nullable();
$t->timestamps(6);
$t->softDeletes();
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->foreign('company_id')->references('id')->on('companies');
$t->unique(['company_id', 'name']);
});
Schema::create('tasks', function ($table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('assigned_user_id');
$table->unsignedInteger('company_id')->index();
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('invoice_id')->nullable();
$table->unsignedInteger('project_id')->nullable();
$table->unsignedInteger('task_status_id')->nullable();
$table->smallInteger('task_status_sort_order')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->text('custom_value1')->nullable();
$table->text('custom_value2')->nullable();
$table->text('custom_value3')->nullable();
$table->text('custom_value4')->nullable();
$table->timestamp('start_time')->nullable();
$table->integer('duration')->nullable();
$table->text('description')->nullable();
$table->boolean('is_deleted')->default(false);
$table->boolean('is_running')->default(false);
$table->text('time_log')->nullable();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
});
}
/**