1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Console/Commands/CreateSingleAccount.php

1135 lines
37 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Console\Commands;
2024-03-18 02:58:42 +01:00
use stdClass;
use Carbon\Carbon;
use Faker\Factory;
use App\Models\Task;
use App\Models\User;
use App\Utils\Ninja;
use App\Models\Quote;
2023-11-26 08:41:42 +01:00
use App\Models\Client;
2024-03-18 02:58:42 +01:00
use App\Models\Credit;
use App\Models\Vendor;
use App\Models\Account;
use App\Models\Company;
use App\Models\Country;
use App\Models\Expense;
2023-09-27 10:10:22 +02:00
use App\Models\Invoice;
use App\Models\Product;
use App\Models\Project;
2023-11-26 08:41:42 +01:00
use App\Models\TaxRate;
2024-03-18 02:58:42 +01:00
use App\Libraries\MultiDB;
use App\Models\TaskStatus;
use App\Models\CompanyToken;
use App\Models\ClientContact;
use App\Models\VendorContact;
2024-03-18 02:58:42 +01:00
use App\Models\CompanyGateway;
use App\Factory\InvoiceFactory;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Utils\Traits\MakesHash;
use Illuminate\Console\Command;
2024-03-18 02:58:42 +01:00
use App\Models\RecurringInvoice;
use App\DataMapper\FeesAndLimits;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Models\BankTransactionRule;
use App\Factory\GroupSettingFactory;
use App\Factory\SubscriptionFactory;
2023-11-26 08:41:42 +01:00
use Illuminate\Support\Facades\Hash;
2024-03-18 02:58:42 +01:00
use Illuminate\Support\Facades\Cache;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Support\Facades\Schema;
2024-03-18 02:58:42 +01:00
use App\Repositories\InvoiceRepository;
use App\Factory\RecurringInvoiceFactory;
use App\Events\Invoice\InvoiceWasCreated;
use App\DataMapper\ClientRegistrationFields;
use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
class CreateSingleAccount extends Command
{
2024-01-14 05:05:00 +01:00
use MakesHash;
use GeneratesCounter;
protected $description = 'Create Single Sample Account';
2024-01-14 05:05:00 +01:00
2021-09-03 13:20:52 +02:00
protected $signature = 'ninja:create-single-account {gateway=all} {--database=db-ninja-01}';
protected $invoice_repo;
protected $count;
protected $gateway;
2020-10-28 11:10:49 +01:00
2023-11-16 10:02:05 +01:00
public $faker;
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2023-11-16 10:02:05 +01:00
$this->faker = Factory::create();
2023-02-16 02:36:09 +01:00
if (Ninja::isHosted() || config('ninja.is_docker') || !$this->confirm('Are you sure you want to inject dummy data?')) {
return;
2023-02-16 02:36:09 +01:00
}
$this->invoice_repo = new InvoiceRepository();
2021-09-03 13:20:52 +02:00
MultiDB::setDb($this->option('database'));
$this->info(date('r').' Create Single Sample Account...');
2022-12-01 02:00:53 +01:00
$this->count = 5;
$this->gateway = $this->argument('gateway');
$this->createSmallAccount();
2024-01-10 07:15:53 +01:00
2024-01-14 05:05:00 +01:00
2024-01-10 07:15:53 +01:00
try {
$pdo = \DB::connection('ronin')->getPdo();
2024-01-14 05:05:00 +01:00
if(class_exists(\Modules\Ronin\app\Models\Admin::class)) {
2024-01-10 07:15:53 +01:00
$this->info('Creating Ronin Account');
$this->createRoninAccount();
}
} catch (\Exception $e) {
2024-01-14 05:05:00 +01:00
2024-01-10 07:15:53 +01:00
}
}
private function createRoninAccount()
{
$admin = \Modules\Ronin\app\Models\Admin::create([
'first_name' => 'small',
'last_name' => 'example',
'email' => 'small@example.com',
'password' => Hash::make('password'),
]);
}
private function createSmallAccount()
{
$this->info('Creating Small Account and Company');
2023-02-16 02:36:09 +01:00
if ($user = User::where('email', 'small@example.com')->first()) {
2023-01-19 02:16:51 +01:00
$user->account->delete();
}
$account = Account::factory()->create();
$company = Company::factory()->create([
'account_id' => $account->id,
'slack_webhook_url' => config('ninja.notification.slack'),
2024-01-14 05:05:00 +01:00
'default_password_timeout' => 30 * 60000,
'portal_mode' => 'domain',
'portal_domain' => 'http://ninja.test:8000',
'track_inventory' => true
]);
2023-02-26 00:51:19 +01:00
$faker = \Faker\Factory::create();
2021-05-26 01:14:41 +02:00
$settings = $company->settings;
$settings->invoice_terms = 'Default company invoice terms';
$settings->quote_terms = 'Default company quote terms';
$settings->invoice_footer = 'Default invoice footer';
2023-02-26 00:51:19 +01:00
$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png';
$settings->name = $faker->name();
$settings->email = $faker->safeEmail();
$settings->phone = $faker->phoneNumber();
$settings->website = $faker->url();
$settings->address1 = $faker->streetName();
$settings->address2 = $faker->streetAddress();
$settings->city = $faker->city();
$settings->state = $faker->state();
$settings->postal_code = $faker->postcode();
$settings->country_id = '840';
$settings->vat_number = 'vat number';
$settings->id_number = 'id number';
$settings->use_credits_payment = 'always';
$settings->timezone_id = '1';
$settings->entity_send_time = 0;
$settings->name = $faker->name();
2021-05-26 01:14:41 +02:00
$company->settings = $settings;
$company->client_registration_fields = ClientRegistrationFields::generate();
2021-05-26 01:14:41 +02:00
$company->save();
$account->default_company_id = $company->id;
$account->save();
$user = User::whereEmail('small@example.com')->first();
if (! $user) {
$user = User::factory()->create([
'account_id' => $account->id,
'email' => 'small@example.com',
'confirmation_code' => $this->createDbHash(config('database.default')),
]);
}
2024-01-14 05:05:00 +01: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';
2021-02-08 16:39:04 +01:00
$company_token->token = 'company-token-test';
$company_token->is_system = true;
$company_token->save();
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'notifications' => CompanySettings::notificationDefaults(),
'settings' => null,
]);
Product::factory()->count(1)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
2021-05-26 08:04:38 +02:00
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'GST',
'rate' => 10
]);
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
2021-05-26 08:04:38 +02:00
'name' => 'VAT',
'rate' => 17.5
]);
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'CA Sales Tax',
'rate' => 5
]);
2022-12-01 02:00:53 +01:00
$bi = BankIntegration::factory()->create([
'account_id' => $account->id,
'company_id' => $company->id,
'user_id' => $user->id,
]);
BankTransaction::factory()->count(50)->create([
'bank_integration_id' => $bi->id,
'user_id' => $user->id,
'company_id' => $company->id,
]);
$btr = BankTransactionRule::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
2023-02-16 02:36:09 +01:00
'applies_to' => (bool)rand(0, 1) ? 'CREDIT' : 'DEBIT',
2022-12-01 02:00:53 +01:00
]);
2021-05-26 08:04:38 +02:00
2023-01-24 21:15:54 +01:00
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'cypress'
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
'email' => 'cypress@example.com',
'password' => Hash::make('password'),
]);
$this->info('Creating '.$this->count.' clients');
for ($x = 0; $x < $this->count; $x++) {
$z = $x + 1;
$this->info('Creating client # '.$z);
$this->createClient($company, $user);
}
2022-09-07 06:15:27 +02:00
(new CreateCompanyTaskStatuses($company, $user))->handle();
2021-02-24 03:12:23 +01:00
for ($x = 0; $x < $this->count; $x++) {
$client = $company->clients->random();
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
$client = $company->clients->random();
2020-10-15 10:50:53 +02:00
// $this->info('creating credit for client #'.$client->id);
// $this->createCredit($client); /** Prevents Stripe from running payments. */
$client = $company->clients->random();
$this->info('creating quote for client #'.$client->id);
$this->createQuote($client);
$client = $company->clients->random();
$this->info('creating expense for client #'.$client->id);
$this->createExpense($client);
$client = $company->clients->random();
$this->info('creating vendor for client #'.$client->id);
$this->createVendor($client);
$client = $company->clients->random();
$this->info('creating task for client #' . $client->id);
$this->createTask($client);
$client = $company->clients->random();
$this->info('creating project for client #' . $client->id);
$this->createProject($client);
2020-10-21 05:10:32 +02:00
$this->info('creating credit for client #' . $client->id);
2020-10-21 05:10:32 +02:00
$this->createCredit($client);
$this->info('creating recurring invoice for client # ' . $client->id);
$this->createRecurringInvoice($client);
}
$this->createGateways($company, $user);
2021-04-10 04:47:47 +02:00
$this->createSubsData($company, $user);
2023-09-27 10:10:22 +02:00
$repo = new \App\Repositories\TaskRepository();
Task::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\ExpenseRepository();
Expense::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\VendorRepository(new \App\Repositories\VendorContactRepository());
Vendor::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\ClientRepository(new \App\Repositories\ClientContactRepository());
Client::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\RecurringInvoiceRepository();
RecurringInvoice::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\InvoiceRepository();
Invoice::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\QuoteRepository();
Quote::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\CreditRepository();
Credit::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
2024-01-14 05:05:00 +01:00
2023-10-25 10:04:27 +02:00
Project::query()->with('client')->whereNotNull('client_id')->cursor()->each(function ($p) {
2024-01-14 05:05:00 +01:00
2023-10-25 10:04:27 +02:00
if($p && $p->client && !isset($p->number)) {
2023-09-27 10:10:22 +02:00
$p->number = $this->getNextProjectNumber($p);
$p->save();
}
});
2024-07-22 11:31:19 +02:00
$this->countryClients($company, $user);
2023-10-25 10:04:27 +02:00
$this->info("finished");
2024-01-14 05:05:00 +01:00
2021-04-10 04:47:47 +02:00
}
private function createSubsData($company, $user)
{
$gs = GroupSettingFactory::create($company->id, $user->id);
$gs->name = "plans";
$gs->save();
$p1 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'pro_plan',
'notes' => 'The Pro Plan',
'cost' => 10,
'price' => 10,
'quantity' => 1,
]);
2021-04-10 04:47:47 +02:00
$p2 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan',
'notes' => 'The Enterprise Plan',
'cost' => 14,
'price' => 14,
'quantity' => 1,
]);
2021-04-10 04:47:47 +02:00
2021-04-14 04:40:16 +02:00
$p3 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'free_plan',
'notes' => 'The Free Plan',
'cost' => 0,
'price' => 0,
'quantity' => 1,
]);
2021-04-14 04:40:16 +02:00
2021-04-10 04:47:47 +02:00
$webhook_config = [
'post_purchase_url' => 'http://ninja.test:8000/api/admin/plan',
2023-01-12 02:22:32 +01:00
'post_purchase_rest_method' => 'post',
'post_purchase_headers' => [config('ninja.ninja_hosted_header') => config('ninja.ninja_hosted_secret')],
2021-04-10 04:47:47 +02:00
];
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Pro Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p1->hashed_id}";
$sub->webhook_configuration = $webhook_config;
2021-04-13 11:34:59 +02:00
$sub->allow_plan_changes = true;
2021-04-14 06:41:04 +02:00
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
2021-04-10 04:47:47 +02:00
$sub->save();
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Enterprise Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p2->hashed_id}";
$sub->webhook_configuration = $webhook_config;
2021-04-13 11:34:59 +02:00
$sub->allow_plan_changes = true;
2021-04-14 06:41:04 +02:00
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
2021-04-10 04:47:47 +02:00
$sub->save();
2021-04-14 04:40:16 +02:00
$sub = SubscriptionFactory::create($company->id, $user->id);
$sub->name = "Free Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p3->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
2021-04-14 06:41:04 +02:00
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
2021-04-14 04:40:16 +02:00
$sub->save();
}
private function createClient($company, $user)
{
// dispatch(function () use ($company, $user) {
// });
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
2023-01-24 21:15:54 +01:00
'email' => 'user@example.com',
]);
ClientContact::factory()->count(rand(1, 2))->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
2021-01-25 11:34:12 +01:00
$client->number = $this->getNextClientNumber($client);
$settings = $client->settings;
2020-10-10 12:57:28 +02:00
$settings->currency_id = "1";
2023-10-26 04:57:44 +02:00
// $settings->use_credits_payment = "always";
2020-10-28 11:10:49 +01:00
$client->settings = $settings;
$country = Country::all()->random();
$client->country_id = $country->id;
$client->save();
}
private function createExpense($client)
{
2022-12-01 02:00:53 +01:00
Expense::factory()->count(rand(1, 20))->create([
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
}
private function createVendor($client)
{
$vendor = Vendor::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 1,
]);
VendorContact::factory()->count(rand(1, 2))->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
}
private function createTask($client)
{
2023-11-26 08:41:42 +01:00
$time_log = $this->createTimeLog(rand(1, 20));
2023-11-16 10:02:05 +01:00
$status = TaskStatus::where('company_id', $client->company_id)->get()->random();
2024-01-14 05:05:00 +01:00
2023-11-16 10:02:05 +01:00
return Task::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
2023-11-16 10:02:05 +01:00
'time_log' => $time_log,
'description' => $this->faker->paragraph,
'status_id' => $status->id ?? null,
2023-11-26 08:41:42 +01:00
'number' => rand(10000, 100000000),
'rate' => rand(1, 150),
2023-11-16 10:02:05 +01:00
'client_id' => $client->id
]);
}
2023-11-16 10:02:05 +01:00
private function createTimeLog(int $count)
{
$time_log = [];
$min = 0;
for ($x = 0; $x < $count; $x++) {
$rando = rand(300, 87000);
$time_log[] = [
Carbon::now()->addSeconds($min)->timestamp,
Carbon::now()->addSeconds($min += $rando)->timestamp,
$this->faker->sentence,
2023-11-26 08:41:42 +01:00
rand(0, 1) === 0 ? false : true
2023-11-16 10:02:05 +01:00
];
$min += 300;
}
return json_encode($time_log);
}
private function createProject($client)
{
2023-11-16 10:02:05 +01:00
$project = Project::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
'client_id' => $client->id,
2023-11-26 08:41:42 +01:00
'due_date' => now()->addSeconds(rand(100000, 1000000))->format('Y-m-d'),
'budgeted_hours' => rand(100, 1000),
'task_rate' => rand(1, 200),
]);
2023-11-16 10:02:05 +01:00
2024-01-14 05:05:00 +01:00
for($x = 0; $x < rand(2, 5); $x++) {
2023-11-16 10:02:05 +01:00
$task = $this->createTask($client);
$task->project_id = $project->id;
$task->save();
}
}
private function createInvoice($client)
{
2020-10-28 11:10:49 +01:00
$faker = Factory::create();
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$dateable = Carbon::now()->subDays(rand(0, 90));
$invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5;
}
$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 ($this->gateway === 'braintree') {
$invoice->amount = 100; // Braintree sandbox only allows payments under 2,000 to complete successfully.
}
2023-11-16 10:02:05 +01:00
/** @var \App\Models\Invoice $invoice */
$invoice->save();
$invoice->service()->createInvitations()->markSent();
$this->invoice_repo->markSent($invoice);
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}
private function createCredit($client)
{
2020-10-28 11:10:49 +01:00
$faker = Factory::create();
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
$dateable = Carbon::now()->subDays(rand(0, 90));
$credit->date = $dateable;
2020-10-21 05:10:32 +02:00
$credit->line_items = $this->buildCreditItem();
$credit->uses_inclusive_taxes = false;
$credit->save();
$invoice_calc = new InvoiceSum($credit);
$invoice_calc->build();
$credit = $invoice_calc->getCredit();
2023-11-16 10:02:05 +01:00
/** @var \App\Models\Credit $credit */
$credit->save();
$credit->service()->markSent()->save();
$credit->service()->createInvitations();
}
private function createQuote($client)
{
2020-10-28 11:10:49 +01:00
$faker = Factory::create();
$quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
$quote->date = $faker->date();
$quote->client_id = $client->id;
$quote->setRelation('client', $client);
$quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$quote->tax_name1 = 'GST';
$quote->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$quote->tax_name2 = 'VAT';
$quote->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$quote->tax_name3 = 'CA Sales Tax';
$quote->tax_rate3 = 5;
}
$quote->save();
$quote_calc = new InvoiceSum($quote);
$quote_calc->build();
$quote = $quote_calc->getQuote();
$quote->save();
2023-11-16 10:02:05 +01:00
/** @var \App\Models\Quote $quote */
$quote->service()->markSent()->save();
$quote->service()->createInvitations();
}
2020-10-21 05:10:32 +02:00
private function buildCreditItem()
{
$line_items = [];
2020-11-25 15:19:52 +01:00
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 1000;
2020-10-21 05:10:32 +02:00
2020-11-25 15:19:52 +01:00
$product = Product::all()->random();
2020-10-21 05:10:32 +02:00
2020-11-25 15:19:52 +01:00
$item->cost = (float) $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;
2020-10-21 05:10:32 +02:00
2020-11-25 15:19:52 +01:00
$line_items[] = $item;
2020-10-28 11:10:49 +01:00
2020-10-21 05:10:32 +02:00
return $line_items;
}
private function buildLineItems($count = 1)
{
$line_items = [];
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 = '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 = (float) $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;
}
return $line_items;
}
private function createGateways($company, $user)
2020-10-15 10:50:53 +02:00
{
if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.stripe'));
$cg->save();
2021-10-10 00:37:42 +02:00
$gateway_types = $cg->driver()->gatewayTypes();
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-10-03 07:09:12 +02:00
// if (config('ninja.testvars.paypal') && ($this->gateway == 'all' || $this->gateway == 'paypal')) {
// $cg = new CompanyGateway();
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e';
// $cg->require_cvv = true;
// $cg->require_billing_address = true;
// $cg->require_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.paypal'));
// $cg->save();
// $gateway_types = $cg->driver()->gatewayTypes();
// $fees_and_limits = new stdClass();
// $fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
// $cg->fees_and_limits = $fees_and_limits;
// $cg->save();
// }
2023-06-23 12:05:36 +02:00
if (config('ninja.testvars.paypal_rest') && ($this->gateway == 'all' || $this->gateway == 'paypal_rest')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
2023-06-23 12:05:36 +02:00
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '80af24a6a691230bbec33e930ab40665';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.paypal_rest'));
$cg->save();
2023-08-01 15:53:10 +02:00
// $gateway_types = $cg->driver()->gatewayTypes();
2023-06-23 12:05:36 +02:00
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{3} = new FeesAndLimits();
2023-06-23 12:05:36 +02:00
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.checkout') && ($this->gateway == 'all' || $this->gateway == 'checkout')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '3758e7f7c6f4cecf0f4f348b9a00f456';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.checkout'));
$cg->save();
2024-01-14 05:05:00 +01:00
$gateway_types = $cg->driver(new Client())->gatewayTypes();
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.authorize') && ($this->gateway == 'all' || $this->gateway == 'authorizenet')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.authorize'));
$cg->save();
2024-01-14 05:05:00 +01:00
$gateway_types = $cg->driver(new Client())->gatewayTypes();
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-10-03 07:09:12 +02:00
if (config('ninja.testvars.braintree') && ($this->gateway == 'all' || $this->gateway == 'braintree')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'f7ec488676d310683fb51802d076d713';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.braintree'));
$cg->save();
2021-10-10 00:37:42 +02:00
$gateway_types = $cg->driver()->gatewayTypes();
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2021-08-11 08:43:20 +02:00
2024-03-18 02:58:42 +01:00
if (config('ninja.testvars.paytrace') && ($this->gateway == 'all' || $this->gateway == 'paytrace')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'bbd736b3254b0aabed6ad7fda1298c88';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
2024-03-18 02:58:42 +01:00
$cg->config = encrypt(config('ninja.testvars.paytrace'));
2021-08-11 08:43:20 +02:00
$cg->save();
2021-10-10 00:37:42 +02:00
$gateway_types = $cg->driver()->gatewayTypes();
2021-08-11 08:43:20 +02:00
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
2021-08-11 08:43:20 +02:00
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.mollie') && ($this->gateway == 'all' || $this->gateway == 'mollie')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '1bd651fb213ca0c9d66ae3c336dc77e8';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.mollie'));
$cg->save();
2021-10-10 00:37:42 +02:00
$gateway_types = $cg->driver()->gatewayTypes();
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2021-08-14 11:32:16 +02:00
if (config('ninja.testvars.square') && ($this->gateway == 'all' || $this->gateway == 'square')) {
2024-01-14 05:05:00 +01:00
$cg = new CompanyGateway();
2021-08-14 11:32:16 +02:00
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '65faab2ab6e3223dbe848b1686490baz';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.square'));
$cg->save();
2021-10-10 00:37:42 +02:00
$gateway_types = $cg->driver()->gatewayTypes();
2021-08-14 11:32:16 +02:00
2024-01-14 05:05:00 +01:00
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
2021-08-14 11:32:16 +02:00
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-06-14 09:09:44 +02:00
2024-03-18 02:58:42 +01:00
if (config('ninja.testvars.eway') && ($this->gateway == 'all' || $this->gateway == 'eway')) {
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '944c20175bbe6b9972c05bcfe294c2c7';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.eway'));
$cg->save();
$gateway_types = $cg->driver()->gatewayTypes();
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-06-14 09:09:44 +02:00
2024-03-18 02:58:42 +01:00
if (config('ninja.testvars.gocardless') && ($this->gateway == 'all' || $this->gateway == 'gocardless')) {
$c_settings = ClientSettings::defaults();
$c_settings->currency_id = '2';
2024-06-14 09:09:44 +02:00
2024-03-18 02:58:42 +01:00
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'name' => 'cypress',
'country_id' => 826,
'settings' => $c_settings
]);
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'b9886f9257f0c6ee7c302f1c74475f6c';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.gocardless'));
$cg->save();
$gateway_types = $cg->driver($client)->gatewayTypes();
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-03-18 04:06:16 +01:00
if (config('ninja.testvars.forte') && ($this->gateway == 'all' || $this->gateway == 'forte')) {
$cg = new CompanyGateway();
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.forte'));
$cg->save();
$gateway_types = $cg->driver()->gatewayTypes();
$fees_and_limits = new stdClass();
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits();
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
2024-03-18 02:58:42 +01:00
}
2023-10-25 10:04:27 +02:00
private function createRecurringInvoice(Client $client)
{
$faker = Factory::create();
2023-10-25 10:04:27 +02:00
$invoice = RecurringInvoiceFactory::create($client->company_id, $client->user_id); //stub the company and user_id
$invoice->client_id = $client->id;
$dateable = Carbon::now()->subDays(rand(0, 90));
$invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5;
}
$invoice->custom_value1 = $faker->date;
$invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
$invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
$invoice->save();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
event(new RecurringInvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}
2024-07-22 11:31:19 +02:00
private function countryClients($company, $user)
{
2024-08-22 08:45:06 +02:00
2024-07-22 11:31:19 +02:00
Client::unguard();
Client::create([
'company_id' => $company->id,
'user_id' => $user->id,
'name' => 'Swiss Company AG',
'website' => 'https://www.testcompany.ch',
'private_notes' => 'These are some private notes about the test client.',
'balance' => 0,
'paid_to_date' => 0,
'vat_number' => '654321987',
'id_number' => 'CH9300762011623852957', // Sample Swiss IBAN
'custom_value1' => '2024-07-22 10:00:00',
'custom_value2' => 'blue',
'custom_value3' => 'sampleword',
'custom_value4' => 'test@example.com',
'address1' => '123',
'address2' => 'Test Street 45',
'city' => 'Zurich',
'state' => 'Zurich',
'postal_code' => '8001',
'country_id' => '756', // Switzerland
'shipping_address1' => '123',
'shipping_address2' => 'Test Street 45',
'shipping_city' => 'Zurich',
'shipping_state' => 'Zurich',
'shipping_postal_code' => '8001',
'shipping_country_id' => '756', // Switzerland
'settings' => ClientSettings::Defaults(),
'client_hash' => \Illuminate\Support\Str::random(32),
'routing_id' => '',
]);
}
}