1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Console/Commands/DemoMode.php

665 lines
20 KiB
PHP
Raw Normal View History

2020-06-29 00:02:56 +02:00
<?php
2020-09-07 12:18:56 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-07 12:18:56 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-09-07 12:18:56 +02:00
*/
2020-06-29 00:02:56 +02:00
namespace App\Console\Commands;
2020-06-30 00:19:43 +02:00
use App\DataMapper\CompanySettings;
use App\Events\Invoice\InvoiceWasCreated;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
2020-12-12 09:46:28 +01:00
use App\Factory\RecurringInvoiceFactory;
2020-06-30 00:19:43 +02:00
use App\Helpers\Invoice\InvoiceSum;
2020-10-04 12:24:55 +02:00
use App\Jobs\Company\CreateCompanyPaymentTerms;
2020-10-20 01:01:59 +02:00
use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Jobs\Ninja\CompanySizeCheck;
2020-07-14 00:06:28 +02:00
use App\Jobs\Util\VersionCheck;
2020-10-01 13:41:23 +02:00
use App\Models\Account;
2020-10-01 12:49:47 +02:00
use App\Models\Client;
use App\Models\ClientContact;
2020-10-01 13:41:23 +02:00
use App\Models\Company;
2020-06-30 00:19:43 +02:00
use App\Models\CompanyToken;
2020-10-01 12:49:47 +02:00
use App\Models\Credit;
use App\Models\Expense;
2020-06-30 00:19:43 +02:00
use App\Models\Product;
2020-10-01 12:49:47 +02:00
use App\Models\Project;
use App\Models\Quote;
2020-12-12 09:46:28 +01:00
use App\Models\RecurringInvoice;
2020-10-01 12:49:47 +02:00
use App\Models\Task;
2021-04-19 23:47:50 +02:00
use App\Models\TaskStatus;
2020-06-30 00:19:43 +02:00
use App\Models\User;
2020-10-01 12:49:47 +02:00
use App\Models\Vendor;
use App\Models\VendorContact;
2020-06-30 00:19:43 +02:00
use App\Repositories\InvoiceRepository;
2020-07-08 14:02:16 +02:00
use App\Utils\Ninja;
2020-06-30 00:19:43 +02:00
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use Carbon\Carbon;
2020-06-29 00:02:56 +02:00
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
2020-06-30 00:19:43 +02:00
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
2020-06-29 00:02:56 +02:00
class DemoMode extends Command
{
2020-06-30 00:19:43 +02:00
use MakesHash, GeneratesCounter;
2020-06-29 00:02:56 +02:00
protected $name = 'ninja:demo-mode';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:demo-mode';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Setup demo mode';
2020-06-30 00:19:43 +02:00
protected $invoice_repo;
2020-06-30 00:19:43 +02:00
public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
2020-06-29 00:02:56 +02:00
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(0);
2020-08-21 07:47:34 +02:00
$cached_tables = config('ninja.cached_tables');
2020-08-21 07:47:34 +02: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);
}
}
}
$this->info('Migrating');
2020-06-29 01:38:37 +02:00
Artisan::call('migrate:fresh --force');
$this->info('Seeding');
2020-06-29 01:38:37 +02:00
Artisan::call('db:seed --force');
$this->info('Seeding Random Data');
2020-06-30 00:19:43 +02:00
$this->createSmallAccount();
2020-07-14 00:06:28 +02:00
VersionCheck::dispatchNow();
CompanySizeCheck::dispatchNow();
2020-06-30 00:19:43 +02:00
}
private function createSmallAccount()
{
2020-07-16 23:50:02 +02:00
$faker = \Faker\Factory::create();
2021-05-15 08:54:27 +02:00
$this->count = 25;
2020-06-30 00:19:43 +02:00
$this->info('Creating Small Account and Company');
2020-10-01 12:49:47 +02:00
$account = Account::factory()->create();
$company = Company::factory()->create([
2020-06-30 00:19:43 +02:00
'account_id' => $account->id,
'slack_webhook_url' => config('ninja.notification.slack'),
2020-07-21 13:26:58 +02:00
'enabled_modules' => 32767,
2020-08-03 12:01:27 +02:00
'company_key' => 'KEY',
'enable_shop_api' => true,
2020-06-30 00:19:43 +02:00
]);
$settings = $company->settings;
2020-07-16 23:50:02 +02:00
$settings->name = $faker->company;
$settings->address1 = $faker->buildingNumber;
$settings->address2 = $faker->streetAddress;
$settings->city = $faker->city;
$settings->state = $faker->state;
$settings->postal_code = $faker->postcode;
$settings->website = $faker->url;
$settings->vat_number = (string) $faker->numberBetween(123456789, 987654321);
$settings->phone = (string) $faker->phoneNumber;
2020-07-16 23:50:02 +02:00
$company->settings = $settings;
$company->save();
2020-06-30 00:19:43 +02:00
$account->default_company_id = $company->id;
$account->save();
$user = User::whereEmail('small@example.com')->first();
if (! $user) {
2020-10-01 12:49:47 +02:00
$user = User::factory()->create([
2020-06-30 00:19:43 +02:00
'account_id' => $account->id,
'email' => 'small@example.com',
'confirmation_code' => $this->createDbHash(config('database.default')),
2021-03-17 11:26:02 +01:00
'email_verified_at' => now(),
2020-06-30 00:19:43 +02:00
]);
}
2020-10-04 12:24:55 +02:00
CreateCompanyPaymentTerms::dispatchNow($company, $user);
2020-10-20 01:01:59 +02:00
CreateCompanyTaskStatuses::dispatchNow($company, $user);
2020-10-04 12:24:55 +02:00
2020-06-30 00:19:43 +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);
$company_token->is_system = true;
2020-06-30 00:19:43 +02:00
$company_token->save();
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
// 'permissions' => '',
'settings' => null,
]);
$u2 = User::where('email', 'demo@invoiceninja.com')->first();
if (! $u2) {
2020-10-01 12:49:47 +02:00
$u2 = User::factory()->create([
2020-06-30 00:19:43 +02:00
'email' => 'demo@invoiceninja.com',
'password' => Hash::make('Password0'),
2020-06-30 00:19:43 +02:00
'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
2021-03-17 11:26:02 +01:00
'email_verified_at' => now(),
2020-06-30 00:19:43 +02:00
]);
$company_token = new CompanyToken;
$company_token->user_id = $u2->id;
$company_token->company_id = $company->id;
$company_token->account_id = $account->id;
$company_token->name = 'test token';
$company_token->token = 'TOKEN';
$company_token->save();
$u2->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
'permissions' => '',
'settings' => null,
]);
}
2020-10-01 12:49:47 +02:00
Product::factory()->count(50)->create([
2020-06-30 00:19:43 +02:00
'user_id' => $user->id,
'company_id' => $company->id,
]);
$this->info('Creating '.$this->count.' clients');
2020-06-30 00:19:43 +02:00
for ($x = 0; $x < $this->count; $x++) {
$z = $x + 1;
$this->info('Creating client # '.$z);
2020-06-30 00:19:43 +02:00
$this->createClient($company, $user, $u2->id);
2020-06-30 00:19:43 +02:00
}
for ($x = 0; $x < $this->count; $x++) {
2020-06-30 00:19:43 +02:00
$client = $company->clients->random();
2020-07-20 00:04:52 +02:00
$this->info('creating entities for client #'.$client->id);
$this->createInvoice($client, $u2->id);
2020-06-30 00:19:43 +02:00
2020-12-12 09:46:28 +01:00
$this->createRecurringInvoice($client, $u2->id);
2020-06-30 00:19:43 +02:00
2020-07-20 00:04:52 +02:00
$client = $company->clients->random();
$this->createCredit($client, $u2->id);
2020-06-30 00:19:43 +02:00
2020-07-20 00:04:52 +02:00
$client = $company->clients->random();
$this->createQuote($client, $u2->id);
2020-07-20 00:04:52 +02:00
2020-06-30 00:19:43 +02:00
$client = $company->clients->random();
2020-10-28 11:10:49 +01:00
$this->createExpense($client);
2020-06-30 00:19:43 +02:00
$client = $company->clients->random();
$this->createVendor($client, $u2->id);
2020-06-30 00:19:43 +02:00
2020-07-20 00:04:52 +02:00
$client = $company->clients->random();
$this->createTask($client, $u2->id);
2020-06-30 00:19:43 +02:00
2020-07-20 00:04:52 +02:00
$client = $company->clients->random();
$this->createProject($client, $u2->id);
2020-06-30 00:19:43 +02:00
}
}
private function createClient($company, $user, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
// dispatch(function () use ($company, $user) {
2020-06-30 00:19:43 +02:00
// });
2020-10-01 12:49:47 +02:00
$client = Client::factory()->create([
2020-06-30 00:19:43 +02:00
'user_id' => $user->id,
'company_id' => $company->id,
2020-06-30 00:19:43 +02:00
]);
2020-10-01 12:49:47 +02:00
ClientContact::factory()->create([
2020-06-30 00:19:43 +02:00
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
2020-06-30 00:19:43 +02:00
]);
2020-11-25 15:19:52 +01:00
ClientContact::factory()->count(rand(1, 5))->create([
2020-06-30 00:19:43 +02:00
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
2020-06-30 00:19:43 +02:00
]);
2021-01-25 11:34:12 +01:00
$client->number = $this->getNextClientNumber($client);
2020-06-30 00:19:43 +02:00
$settings = $client->settings;
$settings->currency_id = (string) rand(1, 3);
2020-06-30 00:19:43 +02:00
$client->settings = $settings;
if (rand(0, 1)) {
$client->assigned_user_id = $assigned_user_id;
}
$client->country_id = array_rand([36, 392, 840, 124, 276, 826]);
2020-06-30 00:19:43 +02:00
$client->save();
}
private function createExpense($client)
{
2020-11-25 15:19:52 +01:00
Expense::factory()->count(rand(1, 5))->create([
2020-07-16 23:50:02 +02:00
'user_id' => $client->user_id,
2020-06-30 00:19:43 +02:00
'client_id' => $client->id,
'company_id' => $client->company_id,
2020-06-30 00:19:43 +02:00
]);
2021-01-24 21:46:53 +01:00
Expense::all()->each(function ($expense){
$expense->number = $this->getNextExpenseNumber($expense);
$expense->save();
});
2020-06-30 00:19:43 +02:00
}
private function createVendor($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
2020-10-01 13:44:17 +02:00
$vendor = Vendor::factory()->create([
2020-07-16 23:50:02 +02:00
'user_id' => $client->user_id,
'company_id' => $client->company_id,
2020-06-30 00:19:43 +02:00
]);
2020-10-01 12:49:47 +02:00
VendorContact::factory()->create([
2020-06-30 00:19:43 +02:00
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
2020-07-16 23:50:02 +02:00
'company_id' => $client->company_id,
'is_primary' => 1,
2020-06-30 00:19:43 +02:00
]);
2020-11-25 15:19:52 +01:00
VendorContact::factory()->count(rand(1, 5))->create([
2020-06-30 00:19:43 +02:00
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
2020-07-16 23:50:02 +02:00
'company_id' => $client->company_id,
'is_primary' => 0,
2020-06-30 00:19:43 +02:00
]);
2021-01-24 21:46:53 +01:00
2021-02-07 09:25:05 +01:00
$vendor->number = $this->getNextVendorNumber($vendor);
2021-01-24 21:46:53 +01:00
$vendor->save();
2020-06-30 00:19:43 +02:00
}
private function createTask($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
2021-01-24 21:46:53 +01:00
$task = Task::factory()->create([
2020-06-30 00:19:43 +02:00
'user_id' => $client->user->id,
'company_id' => $client->company_id,
2020-12-12 09:46:28 +01:00
'client_id' => $client->id
2020-06-30 00:19:43 +02:00
]);
2021-01-24 21:46:53 +01:00
2021-04-19 23:47:50 +02:00
$task->status_id = TaskStatus::all()->random()->id;
2021-01-24 21:46:53 +01:00
$task->number = $this->getNextTaskNumber($task);
$task->save();
2020-06-30 00:19:43 +02:00
}
private function createProject($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
2020-11-11 01:13:39 +01:00
$project = Project::factory()->create([
2020-06-30 00:19:43 +02:00
'user_id' => $client->user->id,
'company_id' => $client->company_id,
2020-11-11 01:13:39 +01:00
'client_id' => $client->id,
2020-06-30 00:19:43 +02:00
]);
2020-11-11 01:13:39 +01:00
$project->number = $this->getNextProjectNumber($project);
$project->save();
2020-06-30 00:19:43 +02:00
}
private function createInvoice($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
$faker = \Faker\Factory::create();
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
2020-06-30 00:19:43 +02:00
$invoice->client_id = $client->id;
2020-07-06 13:22:36 +02:00
if ((bool) rand(0, 1)) {
2020-07-06 13:22:36 +02:00
$dateable = Carbon::now()->subDays(rand(0, 90));
} else {
2020-07-06 13:22:36 +02:00
$dateable = Carbon::now()->addDays(rand(0, 90));
}
2020-07-06 13:22:36 +02:00
2020-06-30 00:19:43 +02:00
$invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false;
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name1 = 'GST';
// $invoice->tax_rate1 = 10.00;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name2 = 'VAT';
// $invoice->tax_rate2 = 17.50;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name3 = 'CA Sales Tax';
// $invoice->tax_rate3 = 5;
// }
2020-06-30 00:19:43 +02:00
// $invoice->custom_value1 = $faker->date;
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
2020-06-30 00:19:43 +02:00
$invoice->save();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$invoice = $invoice_calc->getInvoice();
if (rand(0, 1)) {
$invoice->assigned_user_id = $assigned_user_id;
}
2020-06-30 00:19:43 +02:00
$invoice->save();
$invoice->service()->createInvitations()->markSent();
$this->invoice_repo->markSent($invoice);
if ((bool) rand(0, 2)) {
2020-06-30 00:19:43 +02:00
$invoice = $invoice->service()->markPaid()->save();
$invoice->payments->each(function ($payment) {
$payment->date = now()->addDays(rand(-30, 30));
2020-07-13 05:35:28 +02:00
$payment->save();
});
2020-06-30 00:19:43 +02: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()));
2020-06-30 00:19:43 +02:00
}
2020-12-12 09:46:28 +01:00
private function createRecurringInvoice($client, $assigned_user_id = null)
{
$faker = \Faker\Factory::create();
$invoice = RecurringInvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$invoice->last_sent_date = now()->subMonth();
$invoice->next_send_date = now()->addMonthNoOverflow();
if ((bool) rand(0, 1)) {
$dateable = Carbon::now()->subDays(rand(0, 90));
} else {
$dateable = Carbon::now()->addDays(rand(0, 90));
}
$invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false;
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name1 = 'GST';
// $invoice->tax_rate1 = 10.00;
// }
2020-12-12 09:46:28 +01:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name2 = 'VAT';
// $invoice->tax_rate2 = 17.50;
// }
2020-12-12 09:46:28 +01:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $invoice->tax_name3 = 'CA Sales Tax';
// $invoice->tax_rate3 = 5;
// }
2020-12-12 09:46:28 +01:00
// $invoice->custom_value1 = $faker->date;
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
$invoice->save();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$invoice = $invoice_calc->getInvoice();
if (rand(0, 1)) {
$invoice->assigned_user_id = $assigned_user_id;
}
2021-05-15 08:54:27 +02:00
$invoice->number = $this->getNextRecurringInvoiceNumber($client);
2020-12-12 09:46:28 +01:00
$invoice->save();
}
private function createCredit($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
$faker = \Faker\Factory::create();
2020-10-01 12:49:47 +02:00
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
2020-06-30 00:19:43 +02:00
if ((bool) rand(0, 1)) {
2020-07-01 13:33:42 +02:00
$dateable = Carbon::now()->subDays(rand(0, 90));
} else {
2020-07-01 13:33:42 +02:00
$dateable = Carbon::now()->addDays(rand(0, 90));
}
2020-07-01 13:33:42 +02:00
2020-06-30 00:19:43 +02:00
$credit->date = $dateable;
$credit->line_items = $this->buildLineItems(rand(1, 10));
$credit->uses_inclusive_taxes = false;
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $credit->tax_name1 = 'GST';
// $credit->tax_rate1 = 10.00;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $credit->tax_name2 = 'VAT';
// $credit->tax_rate2 = 17.50;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $credit->tax_name3 = 'CA Sales Tax';
// $credit->tax_rate3 = 5;
// }
2020-06-30 00:19:43 +02:00
$credit->save();
$invoice_calc = new InvoiceSum($credit);
$invoice_calc->build();
$credit = $invoice_calc->getCredit();
if (rand(0, 1)) {
$credit->assigned_user_id = $assigned_user_id;
}
2020-06-30 00:19:43 +02:00
$credit->save();
$credit->service()->markSent()->save();
$credit->service()->createInvitations();
}
private function createQuote($client, $assigned_user_id = null)
2020-06-30 00:19:43 +02:00
{
$faker = \Faker\Factory::create();
2020-10-01 12:49:47 +02:00
$quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company_id, 'client_id' => $client->id]);
2020-07-06 13:22:36 +02:00
if ((bool) rand(0, 1)) {
2020-07-16 23:50:02 +02:00
$dateable = Carbon::now()->subDays(rand(1, 30));
2020-07-20 00:04:52 +02:00
$dateable_due = $dateable->addDays(rand(1, 30));
} else {
2020-07-16 23:50:02 +02:00
$dateable = Carbon::now()->addDays(rand(1, 30));
2020-07-20 00:04:52 +02:00
$dateable_due = $dateable->addDays(rand(-10, 30));
}
2020-07-06 13:22:36 +02:00
$quote->date = $dateable;
2020-07-20 00:04:52 +02:00
$quote->due_date = $dateable_due;
2020-06-30 00:19:43 +02:00
$quote->client_id = $client->id;
2020-06-30 00:19:43 +02:00
$quote->setRelation('client', $client);
$quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false;
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $quote->tax_name1 = 'GST';
// $quote->tax_rate1 = 10.00;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $quote->tax_name2 = 'VAT';
// $quote->tax_rate2 = 17.50;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $quote->tax_name3 = 'CA Sales Tax';
// $quote->tax_rate3 = 5;
// }
2020-06-30 00:19:43 +02:00
$quote->save();
$quote_calc = new InvoiceSum($quote);
$quote_calc->build();
$quote = $quote_calc->getQuote();
if (rand(0, 1)) {
$quote->assigned_user_id = $assigned_user_id;
}
2020-06-30 00:19:43 +02:00
$quote->save();
$quote->service()->markSent()->save();
$quote->service()->createInvitations();
}
private function buildLineItems($count = 1)
{
$line_items = [];
for ($x = 0; $x < $count; $x++) {
2020-06-30 00:19:43 +02:00
$item = InvoiceItemFactory::create();
$item->quantity = 1;
//$item->cost = 10;
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $item->tax_name1 = 'GST';
// $item->tax_rate1 = 10.00;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $item->tax_name1 = 'VAT';
// $item->tax_rate1 = 17.50;
// }
2020-06-30 00:19:43 +02:00
2021-04-18 01:04:40 +02:00
// if (rand(0, 1)) {
// $item->tax_name1 = 'Sales Tax';
// $item->tax_rate1 = 5;
// }
2020-06-30 00:19:43 +02:00
$product = Product::all()->random();
$item->cost = (float) $product->cost;
2020-06-30 00:19:43 +02: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;
$line_items[] = $item;
}
return $line_items;
}
private function warmCache()
{
/* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables');
2020-06-29 00:02:56 +02:00
2020-06-30 00:19:43 +02: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);
}
}
}
2020-06-29 00:02:56 +02:00
}
}