2019-11-19 11:23:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
use App\Console\Commands\TestData\CreateTestCreditJob;
|
|
|
|
use App\Console\Commands\TestData\CreateTestInvoiceJob;
|
|
|
|
use App\Console\Commands\TestData\CreateTestQuoteJob;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\DataMapper\DefaultSettings;
|
2020-02-06 10:35:51 +01:00
|
|
|
use App\Events\Invoice\InvoiceWasCreated;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Events\Invoice\InvoiceWasMarkedSent;
|
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
|
|
use App\Factory\ClientFactory;
|
|
|
|
use App\Factory\InvoiceFactory;
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
|
|
|
use App\Factory\PaymentFactory;
|
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;
|
2019-12-26 07:09:14 +01:00
|
|
|
use App\Jobs\Quote\CreateQuoteInvitations;
|
2020-02-03 11:33:07 +01:00
|
|
|
use App\Listeners\Credit\CreateCreditInvitation;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Listeners\Invoice\CreateInvoiceInvitation;
|
|
|
|
use App\Models\CompanyToken;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\PaymentType;
|
2020-01-20 11:40:22 +01:00
|
|
|
use App\Models\Product;
|
2019-11-19 11:23:56 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Repositories\InvoiceRepository;
|
|
|
|
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;
|
|
|
|
|
|
|
|
class CreateTestData extends Command
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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');
|
|
|
|
|
|
|
|
$account = factory(\App\Models\Account::class)->create();
|
|
|
|
$company = factory(\App\Models\Company::class)->create([
|
|
|
|
'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
|
|
|
]);
|
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$user = User::whereEmail('small@example.com')->first();
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if (!$user) {
|
2019-11-26 09:14:01 +01:00
|
|
|
$user = factory(\App\Models\User::class)->create([
|
|
|
|
// 'account_id' => $account->id,
|
|
|
|
'email' => 'small@example.com',
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
|
|
|
]);
|
|
|
|
}
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$token = \Illuminate\Support\Str::random(64);
|
|
|
|
|
|
|
|
$company_token = CompanyToken::create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'name' => 'test token',
|
|
|
|
'token' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
|
|
|
'permissions' => '',
|
2020-02-26 04:26:07 +01:00
|
|
|
'settings' => null,
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
factory(\App\Models\Product::class,50)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->info('Creating '.$this->count. ' clients');
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
for ($x=0; $x<$this->count; $x++) {
|
2019-11-26 09:14:01 +01:00
|
|
|
$z = $x+1;
|
|
|
|
$this->info("Creating client # ".$z);
|
|
|
|
|
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
|
|
|
|
|
|
|
foreach($company->clients as $client) {
|
|
|
|
|
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
|
|
|
$this->createInvoice($client);
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
|
|
|
$this->createCredit($client);
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
|
|
|
$this->createQuote($client);
|
|
|
|
|
|
|
|
$this->info('creating expense for client #'.$client->id);
|
|
|
|
$this->createExpense($client);
|
|
|
|
|
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
|
|
|
$this->createVendor($client);
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating task for client #'.$client->id);
|
|
|
|
$this->createTask($client);
|
|
|
|
|
|
|
|
$this->info('creating project for client #'.$client->id);
|
|
|
|
$this->createProject($client);
|
|
|
|
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
}
|
2020-01-20 11:40:22 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createMediumAccount()
|
|
|
|
{
|
|
|
|
$this->info('Creating Medium Account and Company');
|
|
|
|
|
|
|
|
$account = factory(\App\Models\Account::class)->create();
|
|
|
|
$company = factory(\App\Models\Company::class)->create([
|
|
|
|
'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();
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if (!$user) {
|
2019-11-26 09:14:01 +01:00
|
|
|
$user = factory(\App\Models\User::class)->create([
|
|
|
|
// 'account_id' => $account->id,
|
|
|
|
'email' => 'medium@example.com',
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
|
|
|
]);
|
|
|
|
}
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$token = \Illuminate\Support\Str::random(64);
|
|
|
|
|
|
|
|
$company_token = CompanyToken::create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'name' => 'test token',
|
|
|
|
'token' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
|
|
|
'permissions' => '',
|
2020-03-03 23:46:19 +01:00
|
|
|
'settings' => null,
|
2019-11-26 09:14:01 +01:00
|
|
|
]);
|
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
|
|
|
|
factory(\App\Models\Product::class,50)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->count = $this->count*10;
|
|
|
|
|
|
|
|
$this->info('Creating '.$this->count. ' clients');
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
for ($x=0; $x<$this->count; $x++) {
|
2019-11-26 09:14:01 +01:00
|
|
|
$z = $x+1;
|
|
|
|
$this->info("Creating client # ".$z);
|
|
|
|
|
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
|
|
|
|
|
|
|
foreach($company->clients as $client) {
|
|
|
|
|
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createInvoice($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createCredit($client);
|
|
|
|
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createQuote($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating expense for client #'.$client->id);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createExpense($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createVendor($client);
|
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-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$this->createTask($client);
|
2020-01-21 10:22:10 +01:00
|
|
|
|
|
|
|
$this->info('creating project for client #'.$client->id);
|
2020-01-27 11:53:08 +01:00
|
|
|
|
|
|
|
for($i=0; $i<$this->count; $i++)
|
|
|
|
$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
|
|
|
|
|
|
|
$account = factory(\App\Models\Account::class)->create();
|
|
|
|
$company = factory(\App\Models\Company::class)->create([
|
|
|
|
'account_id' => $account->id,
|
2020-03-03 10:44:26 +01:00
|
|
|
'slack_webhook_url' => config('ninja.notification.slack'),
|
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
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if (!$user) {
|
2019-11-19 11:23:56 +01:00
|
|
|
$user = factory(\App\Models\User::class)->create([
|
|
|
|
// 'account_id' => $account->id,
|
2019-11-26 09:14:01 +01:00
|
|
|
'email' => 'large@example.com',
|
2019-11-19 11:23:56 +01:00
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
|
|
|
]);
|
|
|
|
}
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2019-11-19 11:23:56 +01:00
|
|
|
$token = \Illuminate\Support\Str::random(64);
|
|
|
|
|
|
|
|
$company_token = CompanyToken::create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'name' => 'test token',
|
|
|
|
'token' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2019-11-26 09:14:01 +01:00
|
|
|
'permissions' => '',
|
2020-03-03 23:46:19 +01:00
|
|
|
'settings' => null,
|
2019-11-19 11:23:56 +01:00
|
|
|
]);
|
|
|
|
|
2020-01-20 11:40:22 +01:00
|
|
|
|
|
|
|
factory(\App\Models\Product::class,50)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->count = $this->count*100;
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
$this->info('Creating '.$this->count. ' clients');
|
|
|
|
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
for ($x=0; $x<$this->count; $x++) {
|
2019-11-19 11:23:56 +01:00
|
|
|
$z = $x+1;
|
|
|
|
$this->info("Creating client # ".$z);
|
|
|
|
|
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
|
|
|
|
|
|
|
foreach($company->clients as $client) {
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating invoice for client #'.$client->id);
|
2020-01-20 11:10:33 +01:00
|
|
|
$this->createInvoice($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
$this->info('creating credit for client #'.$client->id);
|
|
|
|
$this->createCredit($client);
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
$this->info('creating quote for client #'.$client->id);
|
2020-01-20 11:10:33 +01:00
|
|
|
$this->createQuote($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating expense for client #'.$client->id);
|
2020-01-20 11:10:33 +01:00
|
|
|
$this->createExpense($client);
|
2020-01-20 11:16:16 +01:00
|
|
|
|
|
|
|
$this->info('creating vendor for client #'.$client->id);
|
2020-01-20 11:10:33 +01:00
|
|
|
$this->createVendor($client);
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$this->info('creating task for client #'.$client->id);
|
|
|
|
$this->createTask($client);
|
|
|
|
|
|
|
|
$this->info('creating project for client #'.$client->id);
|
|
|
|
$this->createProject($client);
|
2020-01-20 11:10:33 +01:00
|
|
|
}
|
2020-01-20 11:16:16 +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) {
|
|
|
|
|
|
|
|
// });
|
|
|
|
$client = factory(\App\Models\Client::class)->create([
|
2019-11-19 22:06:48 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
factory(\App\Models\ClientContact::class, 1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class, rand(1, 5))->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
2019-11-19 11:23:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
private function createExpense($client)
|
|
|
|
{
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
factory(\App\Models\Expense::class, rand(1, 5))->create([
|
2020-01-20 02:31:58 +01:00
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'company_id' => $client->company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createVendor($client)
|
|
|
|
{
|
|
|
|
|
|
|
|
$vendor = factory(\App\Models\Vendor::class)->create([
|
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'company_id' => $client->company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
factory(\App\Models\VendorContact::class, 1)->create([
|
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'vendor_id' => $vendor->id,
|
|
|
|
'company_id' => $client->company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
2020-01-20 11:16:16 +01:00
|
|
|
factory(\App\Models\VendorContact::class, 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,
|
|
|
|
'is_primary' => 0
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:32:34 +01:00
|
|
|
private function createTask($client)
|
|
|
|
{
|
|
|
|
|
2020-01-21 10:22:10 +01:00
|
|
|
$vendor = factory(\App\Models\Task::class)->create([
|
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'company_id' => $client->company->id
|
|
|
|
]);
|
2020-01-21 01:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createProject($client)
|
|
|
|
{
|
2020-01-21 10:22:10 +01:00
|
|
|
|
|
|
|
$vendor = factory(\App\Models\Project::class)->create([
|
|
|
|
'user_id' => $client->user->id,
|
|
|
|
'company_id' => $client->company->id
|
|
|
|
]);
|
2020-01-21 01:32:34 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 11:23:56 +01:00
|
|
|
private function createInvoice($client)
|
|
|
|
{
|
2020-03-04 05:06:27 +01:00
|
|
|
// for($x=0; $x<$this->count; $x++){
|
|
|
|
// dispatch(new CreateTestInvoiceJob($client));
|
|
|
|
// }
|
2019-11-28 11:35:13 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$faker = \Faker\Factory::create();
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
|
|
|
$invoice->client_id = $client->id;
|
|
|
|
// $invoice->date = $faker->date();
|
|
|
|
$dateable = Carbon::now()->subDays(rand(0,90));
|
|
|
|
$invoice->date = $dateable;
|
2019-12-04 02:06:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->line_items = $this->buildLineItems(rand(1,10));
|
|
|
|
$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-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();
|
|
|
|
$invoice->service()->createInvitations();
|
2020-02-20 22:05:01 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$invoice->ledger()->updateInvoiceBalance($invoice->balance);
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
//UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance, $invoice->company);
|
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
|
|
|
$invoice->service()->createInvitations();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
if (rand(0, 1)) {
|
|
|
|
$payment = PaymentFactory::create($client->company->id, $client->user->id);
|
|
|
|
$payment->date = $dateable;
|
|
|
|
$payment->client_id = $client->id;
|
|
|
|
$payment->amount = $invoice->balance;
|
|
|
|
$payment->transaction_reference = rand(0, 500);
|
|
|
|
$payment->type_id = PaymentType::CREDIT_CARD_OTHER;
|
|
|
|
$payment->status_id = Payment::STATUS_COMPLETED;
|
|
|
|
$payment->number = $client->getNextPaymentNumber($client);
|
|
|
|
$payment->save();
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$payment->invoices()->save($invoice);
|
2019-11-19 11:23:56 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
event(new PaymentWasCreated($payment, $payment->company));
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$payment->service()->updateInvoicePayment();
|
|
|
|
//UpdateInvoicePayment::dispatchNow($payment, $payment->company);
|
|
|
|
}
|
|
|
|
//@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging.
|
|
|
|
event(new InvoiceWasCreated($invoice, $invoice->company));
|
2019-11-19 11:23:56 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
private function createCredit($client)
|
|
|
|
{
|
2020-03-04 05:06:27 +01:00
|
|
|
// for($x=0; $x<$this->count; $x++){
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
// dispatch(new CreateTestCreditJob($client));
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
// }
|
|
|
|
$faker = \Faker\Factory::create();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit = factory(\App\Models\Credit::class)->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-04 05:06:27 +01:00
|
|
|
$dateable = Carbon::now()->subDays(rand(0,90));
|
|
|
|
$credit->date = $dateable;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$credit->line_items = $this->buildLineItems(rand(1,10));
|
|
|
|
$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-03 10:44:26 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
event(new CreateCreditInvitation($credit));
|
2020-02-03 11:33:07 +01:00
|
|
|
|
|
|
|
}
|
2019-12-26 07:09:14 +01:00
|
|
|
|
|
|
|
private function createQuote($client)
|
|
|
|
{
|
2020-03-04 05:06:27 +01:00
|
|
|
// for($x=0; $x<$this->count; $x++){
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
// dispatch(new CreateTestQuoteJob($client));
|
|
|
|
// }
|
|
|
|
$faker = \Faker\Factory::create();
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
|
|
|
$quote->date = $faker->date();
|
2019-12-26 07:09:14 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
$quote->line_items = $this->buildLineItems(rand(1,10));
|
|
|
|
$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();
|
|
|
|
$quote->service()->markSent()->save();
|
2019-12-28 07:25:18 +01:00
|
|
|
|
2020-03-04 05:06:27 +01:00
|
|
|
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
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-01-20 11:40:22 +01:00
|
|
|
for($x=0; $x<$count; $x++)
|
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$product = Product::all()->random();
|
|
|
|
|
2020-01-20 11:53:47 +01:00
|
|
|
$item->cost = (float)$product->cost;
|
2020-01-20 11:40:22 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|