2019-11-19 11:23:56 +01:00
|
|
|
<?php
|
2020-09-07 12:18:56 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-07 12:18:56 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2020-03-09 10:38:15 +01:00
|
|
|
use App\DataMapper\CompanySettings;
|
2020-02-06 10:35:51 +01:00
|
|
|
use App\Events\Invoice\InvoiceWasCreated;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Factory\InvoiceFactory;
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
2019-12-26 07:09:14 +01:00
|
|
|
use App\Factory\QuoteFactory;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Helpers\Invoice\InvoiceSum;
|
2020-10-05 10:08:30 +02:00
|
|
|
use App\Models\Account;
|
2020-10-01 13:34:05 +02:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
2020-10-05 10:08:30 +02:00
|
|
|
use App\Models\Company;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Models\CompanyToken;
|
2020-06-29 01:38:37 +02:00
|
|
|
use App\Models\Country;
|
2020-11-25 15:19:52 +01:00
|
|
|
use App\Models\Credit;
|
2020-10-01 13:34:05 +02:00
|
|
|
use App\Models\Expense;
|
2020-01-20 11:40:22 +01:00
|
|
|
use App\Models\Product;
|
2020-10-01 13:34:05 +02:00
|
|
|
use App\Models\Project;
|
2020-10-06 12:27:49 +02:00
|
|
|
use App\Models\Quote;
|
2020-10-01 13:34:05 +02:00
|
|
|
use App\Models\Task;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Models\User;
|
2020-10-01 13:34:05 +02:00
|
|
|
use App\Models\Vendor;
|
|
|
|
use App\Models\VendorContact;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Repositories\InvoiceRepository;
|
2020-07-08 14:02:16 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-06-02 12:15:12 +02:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-01-20 11:10:33 +01:00
|
|
|
use Carbon\Carbon;
|
2019-11-28 11:35:13 +01:00
|
|
|
use Faker\Factory;
|
2019-11-19 11:23:56 +01:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2020-04-09 14:36:20 +02:00
|
|
|
use Illuminate\Support\Str;
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
class CreateTestData extends Command
|
|
|
|
{
|
2020-06-02 12:15:12 +02:00
|
|
|
use MakesHash, GeneratesCounter;
|
2019-11-19 11:23:56 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Create Test Data';
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'ninja:create-test-data {count=1}';
|
|
|
|
|
|
|
|
protected $invoice_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param InvoiceRepository $invoice_repo
|
2019-11-19 11:23:56 +01:00
|
|
|
*/
|
|
|
|
public function __construct(InvoiceRepository $invoice_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->invoice_repo = $invoice_repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->info(date('r').' Running CreateTestData...');
|
|
|
|
$this->count = $this->argument('count');
|
|
|
|
|
|
|
|
$this->info('Warming up cache');
|
|
|
|
|
|
|
|
$this->warmCache();
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->createSmallAccount();
|
|
|
|
$this->createMediumAccount();
|
|
|
|
$this->createLargeAccount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createSmallAccount()
|
|
|
|
{
|
|
|
|
$this->info('Creating Small Account and Company');
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2019-11-26 09:14:01 +01:00
|
|
|
'account_id' => $account->id,
|
2020-03-03 10:44:26 +01:00
|
|
|
'slack_webhook_url' => config('ninja.notification.slack'),
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$user = User::whereEmail('small@example.com')->first();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $user) {
|
2020-10-01 13:34:05 +02:00
|
|
|
$user = User::factory()->create([
|
2020-03-24 10:15:30 +01:00
|
|
|
'account_id' => $account->id,
|
2019-11-26 09:14:01 +01:00
|
|
|
'email' => 'small@example.com',
|
2020-09-06 11:38:10 +02:00
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
|
|
|
$company_token->name = 'test token';
|
|
|
|
$company_token->token = Str::random(64);
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
|
|
|
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token->save();
|
2019-11-26 09:14:01 +01:00
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2020-03-09 10:38:15 +01:00
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
// 'permissions' => '',
|
2020-02-26 04:26:07 +01:00
|
|
|
'settings' => null,
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
Product::factory()->count(50)->create([
|
2020-01-20 11:40:22 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->info('Creating '.$this->count.' clients');
|
2019-11-26 09:14:01 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $this->count; $x++) {
|
|
|
|
$z = $x + 1;
|
|
|
|
$this->info('Creating client # '.$z);
|
2019-11-26 09:14:01 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$this->createClient($company, $user);
|
2019-11-26 09:14:01 +01:00
|
|
|
}
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $this->count; $x++) {
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createInvoice($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createCredit($client);
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createQuote($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating expense for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createExpense($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createVendor($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating task for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createTask($client);
|
2020-01-21 10:22:10 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating project for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createProject($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
}
|
2019-11-26 09:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createMediumAccount()
|
|
|
|
{
|
|
|
|
$this->info('Creating Medium Account and Company');
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2019-11-26 09:14:01 +01:00
|
|
|
'account_id' => $account->id,
|
2020-03-03 10:44:26 +01:00
|
|
|
'slack_webhook_url' => config('ninja.notification.slack'),
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$user = User::whereEmail('medium@example.com')->first();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $user) {
|
2020-10-01 13:34:05 +02:00
|
|
|
$user = User::factory()->create([
|
2020-03-24 10:15:30 +01:00
|
|
|
'account_id' => $account->id,
|
2019-11-26 09:14:01 +01:00
|
|
|
'email' => 'medium@example.com',
|
2020-09-06 11:38:10 +02:00
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
}
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
|
|
|
$company_token->name = 'test token';
|
|
|
|
$company_token->token = Str::random(64);
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token->save();
|
2019-11-26 09:14:01 +01:00
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2020-03-09 10:38:15 +01:00
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
// 'permissions' => '',
|
2020-03-03 23:46:19 +01:00
|
|
|
'settings' => null,
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
Product::factory()->count(50)->create([
|
2020-01-20 11:40:22 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->count = $this->count * 10;
|
2019-11-26 09:14:01 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->info('Creating '.$this->count.' clients');
|
2019-11-26 09:14:01 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $this->count; $x++) {
|
|
|
|
$z = $x + 1;
|
|
|
|
$this->info('Creating client # '.$z);
|
2019-11-26 09:14:01 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$this->createClient($company, $user);
|
2019-11-26 09:14:01 +01:00
|
|
|
}
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $this->count * 100; $x++) {
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createInvoice($client);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createCredit($client);
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createQuote($client);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating expense for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createExpense($client);
|
|
|
|
|
|
|
|
$client = $company->clients->random();
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createVendor($client);
|
|
|
|
|
|
|
|
$client = $company->clients->random();
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating task for client #'.$client->id);
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->createTask($client);
|
2020-01-21 10:22:10 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
2020-01-27 11:53:08 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$this->info('creating project for client #'.$client->id);
|
|
|
|
$this->createProject($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
}
|
2019-11-26 09:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createLargeAccount()
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$this->info('Creating Large Account and Company');
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2019-11-19 11:23:56 +01:00
|
|
|
'account_id' => $account->id,
|
2020-03-03 10:44:26 +01:00
|
|
|
'slack_webhook_url' => config('ninja.notification.slack'),
|
2020-07-28 10:37:13 +02:00
|
|
|
'is_large' => true,
|
2019-11-19 11:23:56 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$user = User::whereEmail('large@example.com')->first();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $user) {
|
2020-10-01 13:34:05 +02:00
|
|
|
$user = User::factory()->create([
|
2020-03-24 10:15:30 +01:00
|
|
|
'account_id' => $account->id,
|
2019-11-26 09:14:01 +01:00
|
|
|
'email' => 'large@example.com',
|
2020-09-06 11:38:10 +02:00
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
2019-11-19 11:23:56 +01:00
|
|
|
]);
|
|
|
|
}
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
|
|
|
$company_token->name = 'test token';
|
|
|
|
$company_token->token = Str::random(64);
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
2020-04-09 14:36:20 +02:00
|
|
|
$company_token->save();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2020-03-09 10:38:15 +01:00
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
// 'permissions' => '',
|
2020-03-03 23:46:19 +01:00
|
|
|
'settings' => null,
|
2019-11-19 11:23:56 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
Product::factory()->count(15000)->create([
|
2020-01-20 11:40:22 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2020-09-16 09:06:06 +02:00
|
|
|
$this->count = $this->count * 10;
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->info('Creating '.$this->count.' clients');
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2021-01-27 10:57:12 +01:00
|
|
|
for ($x = 0; $x < $this->count * 100; $x++) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$z = $x + 1;
|
|
|
|
$this->info('Creating client # '.$z);
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$this->createClient($company, $user);
|
2019-11-19 11:23:56 +01:00
|
|
|
}
|
2020-01-20 11:10:33 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $this->count; $x++) {
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createInvoice($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createCredit($client);
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createQuote($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating expense for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createExpense($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createVendor($client);
|
2020-01-20 11:10:33 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating task for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createTask($client);
|
2020-01-21 10:22:10 +01:00
|
|
|
|
2020-05-28 02:04:48 +02:00
|
|
|
$client = $company->clients->random();
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating project for client #'.$client->id);
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->createProject($client);
|
2020-01-20 11:10:33 +01:00
|
|
|
}
|
2019-11-19 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createClient($company, $user)
|
|
|
|
{
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
// dispatch(function () use ($company, $user) {
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
// });
|
2020-10-01 13:34:05 +02:00
|
|
|
$client = Client::factory()->create([
|
2019-11-19 22:06:48 +01:00
|
|
|
'user_id' => $user->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $company->id,
|
2019-11-19 22:06:48 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
ClientContact::factory()->create([
|
2020-03-03 10:44:26 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $company->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'is_primary' => 1,
|
2020-03-03 10:44:26 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
ClientContact::factory()->count(rand(1, 5))->create([
|
2020-03-03 10:44:26 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $company->id,
|
2020-03-03 10:44:26 +01:00
|
|
|
]);
|
2020-06-02 12:15:12 +02:00
|
|
|
|
2021-01-25 11:34:12 +01:00
|
|
|
$client->number = $this->getNextClientNumber($client);
|
2020-06-29 01:38:37 +02:00
|
|
|
|
|
|
|
$settings = $client->settings;
|
2020-09-06 11:38:10 +02:00
|
|
|
$settings->currency_id = (string) rand(1, 79);
|
2020-06-29 01:38:37 +02:00
|
|
|
$client->settings = $settings;
|
|
|
|
|
|
|
|
$country = Country::all()->random();
|
|
|
|
|
|
|
|
$client->country_id = $country->id;
|
2020-06-02 12:15:12 +02:00
|
|
|
$client->save();
|
2019-11-19 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
private function createExpense($client)
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
Expense::factory()->count(rand(1, 5))->create([
|
2020-01-20 02:31:58 +01:00
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'client_id' => $client->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $client->company->id,
|
2020-01-20 02:31:58 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createVendor($client)
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
$vendor = Vendor::factory()->create([
|
2020-01-20 02:31:58 +01:00
|
|
|
'user_id' => $client->user->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $client->company->id,
|
2020-01-20 02:31:58 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
VendorContact::factory()->create([
|
2020-01-20 02:31:58 +01:00
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'vendor_id' => $vendor->id,
|
|
|
|
'company_id' => $client->company->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'is_primary' => 1,
|
2020-01-20 02:31:58 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
VendorContact::factory()->count(rand(1, 5))->create([
|
2020-01-20 02:31:58 +01:00
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'vendor_id' => $vendor->id,
|
|
|
|
'company_id' => $client->company->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'is_primary' => 0,
|
2020-01-20 02:31:58 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:32:34 +01:00
|
|
|
private function createTask($client)
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
$vendor = Task::factory()->create([
|
2020-01-21 10:22:10 +01:00
|
|
|
'user_id' => $client->user->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $client->company->id,
|
2020-01-21 10:22:10 +01:00
|
|
|
]);
|
2020-01-21 01:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createProject($client)
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
$vendor = Project::factory()->create([
|
2020-01-21 10:22:10 +01:00
|
|
|
'user_id' => $client->user->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $client->company->id,
|
2020-01-21 10:22:10 +01:00
|
|
|
]);
|
2020-01-21 01:32:34 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 11:23:56 +01:00
|
|
|
private function createInvoice($client)
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$faker = Factory::create();
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->client_id = $client->id;
|
|
|
|
// $invoice->date = $faker->date();
|
2020-03-21 06:37:30 +01:00
|
|
|
$dateable = Carbon::now()->subDays(rand(0, 90));
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->date = $dateable;
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$invoice->line_items = $this->buildLineItems(rand(1, 10));
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->uses_inclusive_taxes = false;
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$invoice->tax_name1 = 'GST';
|
|
|
|
$invoice->tax_rate1 = 10.00;
|
|
|
|
}
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$invoice->tax_name2 = 'VAT';
|
|
|
|
$invoice->tax_rate2 = 17.50;
|
|
|
|
}
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$invoice->tax_name3 = 'CA Sales Tax';
|
|
|
|
$invoice->tax_rate3 = 5;
|
|
|
|
}
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-04-11 03:41:43 +02:00
|
|
|
$invoice->custom_value1 = $faker->date;
|
2020-04-15 02:30:52 +02:00
|
|
|
$invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
|
2020-04-11 03:41:43 +02:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->save();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice_calc = new InvoiceSum($invoice);
|
|
|
|
$invoice_calc->build();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice = $invoice_calc->getInvoice();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->save();
|
2020-05-04 13:13:46 +02:00
|
|
|
$invoice->service()->createInvitations()->markSent();
|
2019-12-24 22:55:29 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$this->invoice_repo->markSent($invoice);
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
2020-04-11 13:19:05 +02:00
|
|
|
$invoice = $invoice->service()->markPaid()->save();
|
2020-03-04 05:06:27 +01:00
|
|
|
}
|
2020-11-08 11:53:47 +01:00
|
|
|
|
2020-07-08 14:02:16 +02:00
|
|
|
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
|
2019-11-19 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
private function createCredit($client)
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$faker = Factory::create();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-10-01 13:34:05 +02:00
|
|
|
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$dateable = Carbon::now()->subDays(rand(0, 90));
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit->date = $dateable;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$credit->line_items = $this->buildLineItems(rand(1, 10));
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit->uses_inclusive_taxes = false;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$credit->tax_name1 = 'GST';
|
|
|
|
$credit->tax_rate1 = 10.00;
|
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$credit->tax_name2 = 'VAT';
|
|
|
|
$credit->tax_rate2 = 17.50;
|
|
|
|
}
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$credit->tax_name3 = 'CA Sales Tax';
|
|
|
|
$credit->tax_rate3 = 5;
|
|
|
|
}
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit->save();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice_calc = new InvoiceSum($credit);
|
|
|
|
$invoice_calc->build();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit = $invoice_calc->getCredit();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit->save();
|
2020-03-06 14:41:15 +01:00
|
|
|
$credit->service()->markSent()->save();
|
|
|
|
$credit->service()->createInvitations();
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
2019-12-26 07:09:14 +01:00
|
|
|
|
|
|
|
private function createQuote($client)
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$faker = Factory::create();
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
//$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
2020-10-01 13:34:05 +02:00
|
|
|
$quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote->date = $faker->date();
|
2020-03-10 13:54:20 +01:00
|
|
|
$quote->client_id = $client->id;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-06 14:41:15 +01:00
|
|
|
$quote->setRelation('client', $client);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$quote->line_items = $this->buildLineItems(rand(1, 10));
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote->uses_inclusive_taxes = false;
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$quote->tax_name1 = 'GST';
|
|
|
|
$quote->tax_rate1 = 10.00;
|
|
|
|
}
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$quote->tax_name2 = 'VAT';
|
|
|
|
$quote->tax_rate2 = 17.50;
|
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$quote->tax_name3 = 'CA Sales Tax';
|
|
|
|
$quote->tax_rate3 = 5;
|
|
|
|
}
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote->save();
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote_calc = new InvoiceSum($quote);
|
|
|
|
$quote_calc->build();
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote = $quote_calc->getQuote();
|
2020-03-06 14:41:15 +01:00
|
|
|
|
|
|
|
$quote->save();
|
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote->service()->markSent()->save();
|
2020-03-06 14:41:15 +01:00
|
|
|
$quote->service()->createInvitations();
|
2019-12-26 07:09:14 +01:00
|
|
|
}
|
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
private function buildLineItems($count = 1)
|
2019-11-19 11:23:56 +01:00
|
|
|
{
|
|
|
|
$line_items = [];
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
for ($x = 0; $x < $count; $x++) {
|
2020-01-20 11:40:22 +01:00
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-01-20 11:53:47 +01:00
|
|
|
//$item->cost = 10;
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$item->tax_name1 = 'GST';
|
|
|
|
$item->tax_rate1 = 10.00;
|
|
|
|
}
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$item->tax_name1 = 'VAT';
|
|
|
|
$item->tax_rate1 = 17.50;
|
|
|
|
}
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$item->tax_name1 = 'Sales Tax';
|
|
|
|
$item->tax_rate1 = 5;
|
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$product = Product::all()->random();
|
2020-01-20 11:40:22 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = (float) $product->cost;
|
2020-03-21 06:37:30 +01:00
|
|
|
$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;
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
$line_items[] = $item;
|
|
|
|
}
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
return $line_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function warmCache()
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
/* Warm up the cache !*/
|
2019-11-19 11:23:56 +01:00
|
|
|
$cached_tables = config('ninja.cached_tables');
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2019-11-19 11:23:56 +01:00
|
|
|
foreach ($cached_tables as $name => $class) {
|
|
|
|
if (! Cache::has($name)) {
|
|
|
|
// check that the table exists in case the migration is pending
|
|
|
|
if (! Schema::hasTable((new $class())->getTable())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($name == 'payment_terms') {
|
|
|
|
$orderBy = 'num_days';
|
|
|
|
} elseif ($name == 'fonts') {
|
|
|
|
$orderBy = 'sort_order';
|
|
|
|
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
|
|
|
$orderBy = 'name';
|
|
|
|
} else {
|
|
|
|
$orderBy = 'id';
|
|
|
|
}
|
|
|
|
$tableData = $class::orderBy($orderBy)->get();
|
|
|
|
if ($tableData->count()) {
|
|
|
|
Cache::forever($name, $tableData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|