From db558acf7003d0aa1c82f387b3367c42cd897df3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 20 Jan 2020 21:40:22 +1100 Subject: [PATCH] V2 (#3230) * Improve test data quality * Add Projects and Tasks to schema * Improve invoice data quality --- app/Console/Commands/CreateTestData.php | 77 +++++++++---- app/Models/Task.php | 11 -- .../2014_10_13_000000_create_users_table.php | 103 ++++++++++-------- 3 files changed, 113 insertions(+), 78 deletions(-) diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 7e39ecb446..086c842bb1 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -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; } diff --git a/app/Models/Task.php b/app/Models/Task.php index df0fda856c..797af7f020 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -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() { diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 95da14ca58..e38ee502a7 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -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'); + }); + } /**