2019-05-14 06:05:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-14 06:05:05 +02:00
|
|
|
*
|
|
|
|
* @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)
|
2019-05-14 06:05:05 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-14 06:05:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests;
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\DataMapper\ClientRegistrationFields;
|
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use App\Factory\CompanyUserFactory;
|
|
|
|
use App\Factory\CreditFactory;
|
|
|
|
use App\Factory\InvoiceFactory;
|
|
|
|
use App\Factory\InvoiceInvitationFactory;
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
|
|
|
use App\Factory\InvoiceToRecurringInvoiceFactory;
|
|
|
|
use App\Factory\PurchaseOrderFactory;
|
|
|
|
use App\Helpers\Invoice\InvoiceSum;
|
|
|
|
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
2023-09-27 06:12:03 +02:00
|
|
|
use App\Models\Account;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\BankIntegration;
|
|
|
|
use App\Models\BankTransaction;
|
|
|
|
use App\Models\BankTransactionRule;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
2023-09-27 06:12:03 +02:00
|
|
|
use App\Models\Company;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\CompanyGateway;
|
|
|
|
use App\Models\CompanyToken;
|
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\CreditInvitation;
|
2020-10-01 12:49:47 +02:00
|
|
|
use App\Models\Expense;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\ExpenseCategory;
|
|
|
|
use App\Models\GroupSetting;
|
|
|
|
use App\Models\InvoiceInvitation;
|
2022-11-30 08:39:22 +01:00
|
|
|
use App\Models\Payment;
|
2020-10-11 23:34:02 +02:00
|
|
|
use App\Models\Product;
|
2020-10-08 00:25:39 +02:00
|
|
|
use App\Models\Project;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\PurchaseOrderInvitation;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Models\QuoteInvitation;
|
|
|
|
use App\Models\RecurringExpense;
|
|
|
|
use App\Models\RecurringInvoice;
|
|
|
|
use App\Models\RecurringQuote;
|
2023-01-13 02:43:38 +01:00
|
|
|
use App\Models\Scheduler;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\Task;
|
2020-10-20 01:01:59 +02:00
|
|
|
use App\Models\TaskStatus;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\TaxRate;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Vendor;
|
2023-09-27 06:12:03 +02:00
|
|
|
use App\Models\VendorContact;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2023-09-27 06:12:03 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Utils\TruthSource;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2023-09-27 06:12:03 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2023-11-26 08:41:42 +01:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2019-11-16 04:12:29 +01:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2020-12-04 07:40:59 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class MockAccountData.
|
2019-05-14 06:05:05 +02:00
|
|
|
*/
|
|
|
|
trait MockAccountData
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
use MakesHash;
|
|
|
|
use GeneratesCounter;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2024-03-10 03:01:30 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $project;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public $account;
|
2019-05-27 12:48:52 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public $company;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public $user;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public $client;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2019-10-02 12:22:10 +02:00
|
|
|
public $token;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2021-08-24 03:23:53 +02:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $recurring_expense;
|
2021-08-24 07:05:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $recurring_quote;
|
|
|
|
|
2023-01-03 01:36:13 +01:00
|
|
|
/**
|
2023-08-20 10:44:10 +02:00
|
|
|
* @var \App\Models\Credit
|
2023-01-03 01:36:13 +01:00
|
|
|
*/
|
|
|
|
public $credit;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
2023-08-20 10:44:10 +02:00
|
|
|
* @var \App\Models\Invoice
|
2020-10-28 11:10:49 +01:00
|
|
|
*/
|
2020-02-19 21:44:12 +01:00
|
|
|
public $invoice;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-02-19 21:44:12 +01:00
|
|
|
public $quote;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-09-23 02:16:19 +02:00
|
|
|
public $vendor;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-09-23 02:46:35 +02:00
|
|
|
public $expense;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-10-12 22:42:02 +02:00
|
|
|
public $task;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-10-20 01:01:59 +02:00
|
|
|
public $task_status;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-10-13 06:08:56 +02:00
|
|
|
public $expense_category;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
2020-10-13 15:06:25 +02:00
|
|
|
public $cu;
|
|
|
|
|
2022-08-11 09:05:33 +02:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $bank_integration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $bank_transaction;
|
|
|
|
|
2022-11-13 05:21:37 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $bank_transaction_rule;
|
|
|
|
|
2022-11-30 08:39:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $payment;
|
|
|
|
|
2022-01-03 02:14:24 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $tax_rate;
|
|
|
|
|
2023-01-13 02:43:38 +01:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $scheduler;
|
|
|
|
|
2023-08-30 04:21:22 +02:00
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
public $purchase_order;
|
|
|
|
|
2023-05-28 10:44:08 +02:00
|
|
|
public $contact;
|
|
|
|
|
2023-08-20 10:18:55 +02:00
|
|
|
public $product;
|
|
|
|
|
|
|
|
public $recurring_invoice;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function makeTestData()
|
|
|
|
{
|
2021-05-13 15:01:23 +02:00
|
|
|
config(['database.default' => config('ninja.db.default')]);
|
2019-11-16 04:12:29 +01:00
|
|
|
|
2023-01-18 07:35:43 +01:00
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
$fake_email = $this->faker->email();
|
|
|
|
|
2022-02-01 07:57:36 +01:00
|
|
|
$this->account = Account::factory()->create([
|
2023-02-20 11:12:19 +01:00
|
|
|
'hosted_client_count' => 1000000,
|
|
|
|
'hosted_company_count' => 1000000,
|
2023-03-15 00:59:40 +01:00
|
|
|
'account_sms_verified' => true,
|
2022-02-01 07:57:36 +01:00
|
|
|
]);
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2021-11-07 12:44:39 +01:00
|
|
|
$this->account->num_users = 3;
|
|
|
|
$this->account->save();
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$this->company = Company::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $this->account->id,
|
|
|
|
]);
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2021-10-18 12:46:26 +02:00
|
|
|
$this->company->client_registration_fields = ClientRegistrationFields::generate();
|
|
|
|
|
2020-12-04 07:40:59 +01:00
|
|
|
Storage::makeDirectory($this->company->company_key.'/documents', 0755, true);
|
|
|
|
Storage::makeDirectory($this->company->company_key.'/images', 0755, true);
|
|
|
|
|
2020-02-17 21:07:32 +01:00
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
|
2022-01-11 05:08:39 +01:00
|
|
|
$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png';
|
2020-09-06 11:38:10 +02:00
|
|
|
$settings->website = 'www.invoiceninja.com';
|
|
|
|
$settings->address1 = 'Address 1';
|
|
|
|
$settings->address2 = 'Address 2';
|
|
|
|
$settings->city = 'City';
|
|
|
|
$settings->state = 'State';
|
|
|
|
$settings->postal_code = 'Postal Code';
|
|
|
|
$settings->phone = '555-343-2323';
|
2023-01-18 07:35:43 +01:00
|
|
|
$settings->email = $fake_email;
|
2020-09-06 11:38:10 +02:00
|
|
|
$settings->country_id = '840';
|
2020-02-17 21:07:32 +01:00
|
|
|
$settings->vat_number = 'vat number';
|
2020-09-06 11:38:10 +02:00
|
|
|
$settings->id_number = 'id number';
|
2020-10-26 20:10:04 +01:00
|
|
|
$settings->use_credits_payment = 'always';
|
2021-01-26 22:42:00 +01:00
|
|
|
$settings->timezone_id = '1';
|
2022-03-10 21:45:23 +01:00
|
|
|
$settings->entity_send_time = 0;
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2022-06-08 12:40:26 +02:00
|
|
|
$this->company->track_inventory = true;
|
2020-02-17 21:07:32 +01:00
|
|
|
$this->company->settings = $settings;
|
|
|
|
$this->company->save();
|
|
|
|
|
2019-05-14 06:05:05 +02:00
|
|
|
$this->account->default_company_id = $this->company->id;
|
2023-12-16 08:43:44 +01:00
|
|
|
$this->account->plan = 'pro';
|
|
|
|
$this->account->plan_expires = now()->addMonth();
|
|
|
|
$this->account->plan_term = "month";
|
2019-05-14 06:05:05 +02:00
|
|
|
$this->account->save();
|
|
|
|
|
2023-01-18 07:35:43 +01:00
|
|
|
$user = User::whereEmail($fake_email)->first();
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
if (! $user) {
|
|
|
|
$user = User::factory()->create([
|
2021-05-26 03:32:01 +02:00
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
2023-01-18 07:35:43 +01:00
|
|
|
'email' => $fake_email,
|
2021-05-26 03:32:01 +02:00
|
|
|
]);
|
2019-11-20 06:41:49 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
$user->password = Hash::make('ALongAndBriliantPassword');
|
2021-06-21 07:02:28 +02:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
$user_id = $user->id;
|
|
|
|
$this->user = $user;
|
2020-06-27 04:35:11 +02:00
|
|
|
|
2022-02-10 23:07:41 +01:00
|
|
|
// auth()->login($user);
|
2023-01-22 06:34:47 +01:00
|
|
|
// auth()->user()->setCompany($this->company);
|
2022-02-10 03:38:10 +01:00
|
|
|
|
2022-06-24 13:15:14 +02:00
|
|
|
CreateCompanyTaskStatuses::dispatchSync($this->company, $this->user);
|
2021-02-24 03:12:23 +01:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
$this->cu = CompanyUserFactory::create($user->id, $this->company->id, $this->account->id);
|
2020-10-13 15:06:25 +02:00
|
|
|
$this->cu->is_owner = true;
|
|
|
|
$this->cu->is_admin = true;
|
2021-09-08 01:29:20 +02:00
|
|
|
$this->cu->is_locked = false;
|
2020-10-13 15:06:25 +02:00
|
|
|
$this->cu->save();
|
2019-11-21 09:38:57 +01:00
|
|
|
|
2020-10-13 15:06:25 +02:00
|
|
|
$this->token = \Illuminate\Support\Str::random(64);
|
2019-10-02 12:22:10 +02:00
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token = new CompanyToken;
|
2021-01-26 22:42:00 +01:00
|
|
|
$company_token->user_id = $user->id;
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->company_id = $this->company->id;
|
|
|
|
$company_token->account_id = $this->account->id;
|
|
|
|
$company_token->name = 'test token';
|
|
|
|
$company_token->token = $this->token;
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->save();
|
2019-10-02 12:22:10 +02:00
|
|
|
|
2023-01-22 06:34:47 +01:00
|
|
|
$truth = app()->make(TruthSource::class);
|
|
|
|
$truth->setCompanyUser($company_token->first());
|
|
|
|
$truth->setUser($this->user);
|
|
|
|
$truth->setCompany($this->company);
|
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
//todo create one token with token name TOKEN - use firstOrCreate
|
2020-10-13 15:06:25 +02:00
|
|
|
|
2020-10-11 23:34:02 +02:00
|
|
|
Product::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2020-10-11 23:34:02 +02:00
|
|
|
]);
|
2020-10-28 11:10:49 +01:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$this->client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2020-09-23 02:46:35 +02:00
|
|
|
]);
|
2020-02-17 21:07:32 +01:00
|
|
|
|
2020-12-04 07:40:59 +01:00
|
|
|
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/invoices', 0755, true);
|
|
|
|
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/credits', 0755, true);
|
|
|
|
Storage::makeDirectory($this->company->company_key.'/'.$this->client->client_hash.'/quotes', 0755, true);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$contact = ClientContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
'send_email' => true,
|
2020-09-23 02:46:35 +02:00
|
|
|
]);
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2023-05-28 10:44:08 +02:00
|
|
|
$this->contact = $contact;
|
|
|
|
|
2022-11-30 08:39:22 +01:00
|
|
|
$this->payment = Payment::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 10,
|
|
|
|
]);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$contact2 = ClientContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'send_email' => true,
|
2020-09-23 02:46:35 +02:00
|
|
|
]);
|
2020-08-12 03:04:15 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$this->vendor = Vendor::factory()->create([
|
2021-01-26 22:42:00 +01:00
|
|
|
'user_id' => $user_id,
|
2020-09-23 02:16:19 +02:00
|
|
|
'company_id' => $this->company->id,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => 1,
|
2020-09-23 02:16:19 +02:00
|
|
|
]);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$vendor_contact = VendorContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'vendor_id' => $this->vendor->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
'send_email' => true,
|
2020-09-23 02:46:35 +02:00
|
|
|
]);
|
2020-09-23 02:16:19 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$vendor_contact2 = VendorContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'vendor_id' => $this->vendor->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'send_email' => true,
|
2020-09-23 02:46:35 +02:00
|
|
|
]);
|
|
|
|
|
2020-10-08 00:25:39 +02:00
|
|
|
$this->project = Project::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_id' => $this->client->id,
|
2020-10-08 00:25:39 +02:00
|
|
|
]);
|
2020-10-01 12:49:47 +02:00
|
|
|
|
2023-08-20 10:18:55 +02:00
|
|
|
$this->product = Product::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->recurring_invoice = RecurringInvoice::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
]);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$this->expense = Expense::factory()->create([
|
2021-01-26 22:42:00 +01:00
|
|
|
'user_id' => $user_id,
|
2020-09-23 02:46:35 +02:00
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
2020-09-23 02:16:19 +02:00
|
|
|
|
2021-08-24 03:23:53 +02:00
|
|
|
$this->recurring_expense = RecurringExpense::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2021-09-07 01:02:23 +02:00
|
|
|
'frequency_id' => 5,
|
|
|
|
'remaining_cycles' => 5,
|
2021-08-24 03:23:53 +02:00
|
|
|
]);
|
|
|
|
|
2021-08-24 07:05:35 +02:00
|
|
|
$this->recurring_quote = RecurringQuote::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
]);
|
2021-08-24 03:23:53 +02:00
|
|
|
|
2020-10-12 22:42:02 +02:00
|
|
|
$this->task = Task::factory()->create([
|
2021-01-26 22:42:00 +01:00
|
|
|
'user_id' => $user_id,
|
2020-10-12 22:42:02 +02:00
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
2021-02-24 03:12:23 +01:00
|
|
|
$this->task->status_id = TaskStatus::where('company_id', $this->company->id)->first()->id;
|
|
|
|
$this->task->save();
|
2021-06-21 07:02:28 +02:00
|
|
|
|
2020-10-13 06:08:56 +02:00
|
|
|
$this->expense_category = ExpenseCategory::factory()->create([
|
2021-01-26 22:42:00 +01:00
|
|
|
'user_id' => $user_id,
|
2020-10-13 06:08:56 +02:00
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
2020-10-20 01:01:59 +02:00
|
|
|
$this->task_status = TaskStatus::factory()->create([
|
2021-01-26 22:42:00 +01:00
|
|
|
'user_id' => $user_id,
|
2020-10-20 01:01:59 +02:00
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
2022-01-03 02:14:24 +01:00
|
|
|
$this->tax_rate = TaxRate::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
2019-09-11 07:32:47 +02:00
|
|
|
$gs = new GroupSetting;
|
|
|
|
$gs->name = 'Test';
|
|
|
|
$gs->company_id = $this->client->company_id;
|
2019-09-19 07:50:05 +02:00
|
|
|
$gs->settings = ClientSettings::buildClientSettings($this->company->settings, $this->client->settings);
|
2019-12-16 12:34:38 +01:00
|
|
|
|
|
|
|
$gs_settings = $gs->settings;
|
|
|
|
$gs_settings->website = 'http://staging.invoicing.co';
|
|
|
|
$gs->settings = $gs_settings;
|
2019-09-11 07:32:47 +02:00
|
|
|
$gs->save();
|
|
|
|
|
|
|
|
$this->client->group_settings_id = $gs->id;
|
|
|
|
$this->client->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
$this->invoice = InvoiceFactory::create($this->company->id, $user_id); //stub the company and user_id
|
2019-05-14 06:05:05 +02:00
|
|
|
$this->invoice->client_id = $this->client->id;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice->line_items = $this->buildLineItems();
|
|
|
|
$this->invoice->uses_inclusive_taxes = false;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2019-10-22 04:07:00 +02:00
|
|
|
$this->invoice->save();
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice_calc = new InvoiceSum($this->invoice);
|
|
|
|
$this->invoice_calc->build();
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice = $this->invoice_calc->getInvoice();
|
2019-05-14 12:27:47 +02:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->setRelation('client', $this->client);
|
|
|
|
$this->invoice->setRelation('company', $this->company);
|
|
|
|
|
2019-05-14 06:05:05 +02:00
|
|
|
$this->invoice->save();
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->invoice->load('client');
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
InvoiceInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->invoice->user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
|
|
|
'invoice_id' => $this->invoice->id,
|
|
|
|
]);
|
2020-08-19 03:06:19 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
InvoiceInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->invoice->user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact2->id,
|
|
|
|
'invoice_id' => $this->invoice->id,
|
|
|
|
]);
|
2020-08-19 03:06:19 +02:00
|
|
|
|
2021-07-03 06:37:06 +02:00
|
|
|
$this->invoice->fresh()->service()->markSent();
|
|
|
|
// $this->invoice->service()->markSent();
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$this->quote = Quote::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->quote->line_items = $this->buildLineItems();
|
|
|
|
$this->quote->uses_inclusive_taxes = false;
|
|
|
|
|
|
|
|
$this->quote->save();
|
|
|
|
|
|
|
|
$this->quote_calc = new InvoiceSum($this->quote);
|
|
|
|
$this->quote_calc->build();
|
|
|
|
|
|
|
|
$this->quote = $this->quote_calc->getQuote();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-19 03:06:19 +02:00
|
|
|
$this->quote->status_id = Quote::STATUS_SENT;
|
2021-10-17 04:59:43 +02:00
|
|
|
$this->quote->number = $this->getNextQuoteNumber($this->client, $this->quote);
|
2020-08-19 03:06:19 +02:00
|
|
|
|
|
|
|
//$this->quote->service()->createInvitations()->markSent();
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
QuoteInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
|
|
|
'quote_id' => $this->quote->id,
|
|
|
|
]);
|
2020-08-19 03:06:19 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
QuoteInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact2->id,
|
|
|
|
'quote_id' => $this->quote->id,
|
|
|
|
]);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->quote->setRelation('client', $this->client);
|
|
|
|
$this->quote->setRelation('company', $this->company);
|
|
|
|
|
|
|
|
$this->quote->save();
|
2020-01-30 04:02:25 +01:00
|
|
|
|
2023-01-03 01:36:13 +01:00
|
|
|
|
|
|
|
$this->credit = Credit::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->credit->line_items = $this->buildLineItems();
|
|
|
|
$this->credit->uses_inclusive_taxes = false;
|
|
|
|
|
|
|
|
$this->credit->save();
|
|
|
|
|
|
|
|
$this->credit_calc = new InvoiceSum($this->credit);
|
|
|
|
$this->credit_calc->build();
|
|
|
|
|
|
|
|
$this->credit = $this->credit_calc->getCredit();
|
|
|
|
|
|
|
|
$this->credit->status_id = Quote::STATUS_SENT;
|
|
|
|
$this->credit->number = $this->getNextCreditNumber($this->client, $this->credit);
|
|
|
|
|
|
|
|
|
|
|
|
CreditInvitation::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
|
|
|
'credit_id' => $this->credit->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
CreditInvitation::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact2->id,
|
|
|
|
'credit_id' => $this->credit->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->credit->setRelation('client', $this->client);
|
|
|
|
$this->credit->setRelation('company', $this->company);
|
|
|
|
|
|
|
|
$this->credit->save();
|
|
|
|
|
2023-01-03 06:04:36 +01:00
|
|
|
$this->credit->service()->createInvitations()->markSent();
|
2023-01-03 01:36:13 +01:00
|
|
|
|
|
|
|
|
2022-05-29 05:22:15 +02:00
|
|
|
$this->purchase_order = PurchaseOrderFactory::create($this->company->id, $user_id);
|
2022-06-05 11:41:19 +02:00
|
|
|
$this->purchase_order->vendor_id = $this->vendor->id;
|
2022-05-29 05:22:15 +02:00
|
|
|
|
|
|
|
$this->purchase_order->amount = 10;
|
|
|
|
$this->purchase_order->balance = 10;
|
|
|
|
|
|
|
|
$this->purchase_order->tax_name1 = '';
|
|
|
|
$this->purchase_order->tax_name2 = '';
|
|
|
|
$this->purchase_order->tax_name3 = '';
|
|
|
|
|
|
|
|
$this->purchase_order->tax_rate1 = 0;
|
|
|
|
$this->purchase_order->tax_rate2 = 0;
|
|
|
|
$this->purchase_order->tax_rate3 = 0;
|
|
|
|
|
2023-08-29 14:56:36 +02:00
|
|
|
$this->purchase_order->line_items = InvoiceItemFactory::generate(5);
|
|
|
|
|
2022-05-29 05:22:15 +02:00
|
|
|
$this->purchase_order->uses_inclusive_taxes = false;
|
|
|
|
$this->purchase_order->save();
|
|
|
|
|
2022-06-05 05:57:57 +02:00
|
|
|
PurchaseOrderInvitation::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'vendor_contact_id' => $vendor_contact->id,
|
|
|
|
'purchase_order_id' => $this->purchase_order->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->purchase_order->service()->markSent();
|
|
|
|
|
2024-06-18 02:51:01 +02:00
|
|
|
$this->purchase_order->setRelation('vendor', $this->vendor);
|
2022-06-05 05:57:57 +02:00
|
|
|
$this->purchase_order->setRelation('company', $this->company);
|
|
|
|
|
|
|
|
$this->purchase_order->save();
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2021-01-26 22:42:00 +01:00
|
|
|
$this->credit = CreditFactory::create($this->company->id, $user_id);
|
2020-01-30 04:02:25 +01:00
|
|
|
$this->credit->client_id = $this->client->id;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->credit->line_items = $this->buildLineItems();
|
2020-02-01 21:45:23 +01:00
|
|
|
$this->credit->amount = 10;
|
|
|
|
$this->credit->balance = 10;
|
2022-05-29 05:22:15 +02:00
|
|
|
|
2021-07-02 08:36:14 +02:00
|
|
|
// $this->credit->due_date = now()->addDays(200);
|
2020-02-01 21:45:23 +01:00
|
|
|
|
2020-10-15 11:41:59 +02:00
|
|
|
$this->credit->tax_name1 = '';
|
|
|
|
$this->credit->tax_name2 = '';
|
|
|
|
$this->credit->tax_name3 = '';
|
|
|
|
|
|
|
|
$this->credit->tax_rate1 = 0;
|
|
|
|
$this->credit->tax_rate2 = 0;
|
|
|
|
$this->credit->tax_rate3 = 0;
|
2020-10-28 11:10:49 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->credit->uses_inclusive_taxes = false;
|
2020-01-30 04:02:25 +01:00
|
|
|
$this->credit->save();
|
2020-10-26 10:13:00 +01:00
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
$this->credit_calc = new InvoiceSum($this->credit);
|
|
|
|
$this->credit_calc->build();
|
|
|
|
|
|
|
|
$this->credit = $this->credit_calc->getCredit();
|
|
|
|
|
2020-10-08 05:31:02 +02:00
|
|
|
$this->client->service()->adjustCreditBalance($this->credit->balance)->save();
|
|
|
|
$this->credit->ledger()->updateCreditBalance($this->credit->balance)->save();
|
2021-10-17 04:59:43 +02:00
|
|
|
$this->credit->number = $this->getNextCreditNumber($this->client, $this->credit);
|
2020-10-26 10:13:00 +01:00
|
|
|
|
|
|
|
CreditInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
|
|
|
'credit_id' => $this->credit->id,
|
|
|
|
]);
|
2020-10-26 10:13:00 +01:00
|
|
|
|
|
|
|
CreditInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'client_contact_id' => $contact2->id,
|
|
|
|
'credit_id' => $this->credit->id,
|
|
|
|
]);
|
2020-10-26 10:13:00 +01:00
|
|
|
|
2022-08-11 09:05:33 +02:00
|
|
|
$this->bank_integration = BankIntegration::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->bank_transaction = BankTransaction::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2022-08-12 07:25:18 +02:00
|
|
|
'bank_integration_id' => $this->bank_integration->id,
|
2022-08-11 09:05:33 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
BankTransaction::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2022-08-12 07:25:18 +02:00
|
|
|
'bank_integration_id' => $this->bank_integration->id,
|
2022-08-11 09:05:33 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
BankTransaction::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2022-08-12 07:25:18 +02:00
|
|
|
'bank_integration_id' => $this->bank_integration->id,
|
2022-08-11 09:05:33 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
BankTransaction::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2022-08-12 07:25:18 +02:00
|
|
|
'bank_integration_id' => $this->bank_integration->id,
|
2022-08-11 09:05:33 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
BankTransaction::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
2022-08-12 07:25:18 +02:00
|
|
|
'bank_integration_id' => $this->bank_integration->id,
|
2022-08-11 09:05:33 +02:00
|
|
|
]);
|
|
|
|
|
2022-11-13 05:21:37 +01:00
|
|
|
$this->bank_transaction_rule = BankTransactionRule::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
2020-10-26 10:13:00 +01:00
|
|
|
$invitations = CreditInvitation::whereCompanyId($this->credit->company_id)
|
|
|
|
->whereCreditId($this->credit->id);
|
|
|
|
|
|
|
|
$this->credit->setRelation('invitations', $invitations);
|
|
|
|
|
|
|
|
$this->credit->service()->markSent();
|
|
|
|
|
|
|
|
$this->credit->setRelation('client', $this->client);
|
|
|
|
$this->credit->setRelation('company', $this->company);
|
|
|
|
|
|
|
|
$this->credit->save();
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
$contacts = $this->invoice->client->contacts;
|
|
|
|
|
|
|
|
$contacts->each(function ($contact) {
|
|
|
|
$invitation = InvoiceInvitation::whereCompanyId($this->invoice->company_id)
|
|
|
|
->whereClientContactId($contact->id)
|
|
|
|
->whereInvoiceId($this->invoice->id)
|
|
|
|
->first();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $invitation && $contact->send_email) {
|
2019-12-16 12:34:38 +01:00
|
|
|
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
2021-10-14 07:25:09 +02:00
|
|
|
$ii->key = $this->createDbHash(config('database.default'));
|
2019-12-16 12:34:38 +01:00
|
|
|
$ii->invoice_id = $this->invoice->id;
|
|
|
|
$ii->client_contact_id = $contact->id;
|
|
|
|
$ii->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
} elseif ($invitation && ! $contact->send_email) {
|
2019-12-16 12:34:38 +01:00
|
|
|
$invitation->delete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
$invitations = InvoiceInvitation::whereCompanyId($this->invoice->company_id)
|
|
|
|
->whereInvoiceId($this->invoice->id);
|
|
|
|
|
|
|
|
$this->invoice->setRelation('invitations', $invitations);
|
|
|
|
|
|
|
|
$this->invoice->save();
|
|
|
|
|
2020-02-20 22:05:01 +01:00
|
|
|
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount);
|
2019-05-16 07:36:53 +02:00
|
|
|
|
2021-02-16 11:23:32 +01:00
|
|
|
$user_id = $this->invoice->user_id;
|
|
|
|
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-13 12:20:11 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(2);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-13 12:20:11 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(10);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-13 12:20:11 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(15);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-13 12:20:11 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(20);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-13 12:20:11 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now();
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
|
|
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
2021-02-16 11:23:32 +01:00
|
|
|
$recurring_invoice->user_id = $user_id;
|
2019-09-22 12:25:05 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addDays(10);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
|
|
|
$recurring_invoice->remaining_cycles = 2;
|
2020-09-14 04:57:18 +02:00
|
|
|
$recurring_invoice->next_send_date = Carbon::now()->addDays(10);
|
2019-05-24 11:23:38 +02:00
|
|
|
$recurring_invoice->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-07-14 01:44:43 +02:00
|
|
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
2019-05-24 07:13:17 +02:00
|
|
|
$recurring_invoice->save();
|
|
|
|
|
2019-09-18 14:43:37 +02:00
|
|
|
$gs = new GroupSetting;
|
|
|
|
$gs->company_id = $this->company->id;
|
2021-01-26 22:42:00 +01:00
|
|
|
$gs->user_id = $user_id;
|
2019-09-19 07:50:05 +02:00
|
|
|
$gs->settings = ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults());
|
2019-09-18 14:43:37 +02:00
|
|
|
$gs->name = 'Default Client Settings';
|
|
|
|
$gs->save();
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if (config('ninja.testvars.stripe')) {
|
2020-07-07 16:50:51 +02:00
|
|
|
$data = [];
|
2024-06-18 04:57:15 +02:00
|
|
|
$data[1]['min_limit'] = 22;
|
2020-07-07 16:50:51 +02:00
|
|
|
$data[1]['max_limit'] = 65317;
|
|
|
|
$data[1]['fee_amount'] = 0.00;
|
|
|
|
$data[1]['fee_percent'] = 0.000;
|
|
|
|
$data[1]['fee_tax_name1'] = '';
|
|
|
|
$data[1]['fee_tax_rate1'] = '';
|
|
|
|
$data[1]['fee_tax_name2'] = '';
|
|
|
|
$data[1]['fee_tax_rate2'] = '';
|
|
|
|
$data[1]['fee_tax_name3'] = '';
|
|
|
|
$data[1]['fee_tax_rate3'] = 0;
|
2021-01-08 11:19:26 +01:00
|
|
|
$data[1]['fee_cap'] = '';
|
2021-01-27 02:06:25 +01:00
|
|
|
$data[1]['is_enabled'] = true;
|
2021-06-21 07:02:28 +02:00
|
|
|
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg = new CompanyGateway;
|
|
|
|
$cg->company_id = $this->company->id;
|
2021-01-26 22:42:00 +01:00
|
|
|
$cg->user_id = $user_id;
|
2019-09-24 13:22:41 +02:00
|
|
|
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->require_cvv = true;
|
2020-11-03 22:26:28 +01:00
|
|
|
$cg->require_billing_address = true;
|
|
|
|
$cg->require_shipping_address = true;
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->update_details = true;
|
|
|
|
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
2020-07-07 16:50:51 +02:00
|
|
|
$cg->fees_and_limits = $data;
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->save();
|
|
|
|
|
2023-08-01 15:53:10 +02:00
|
|
|
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg = new CompanyGateway;
|
|
|
|
$cg->company_id = $this->company->id;
|
2021-01-26 22:42:00 +01:00
|
|
|
$cg->user_id = $user_id;
|
2019-09-24 13:22:41 +02:00
|
|
|
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->require_cvv = true;
|
2020-11-03 22:26:28 +01:00
|
|
|
$cg->require_billing_address = true;
|
|
|
|
$cg->require_shipping_address = true;
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->update_details = true;
|
2020-07-07 16:50:51 +02:00
|
|
|
$cg->fees_and_limits = $data;
|
2019-09-18 14:43:37 +02:00
|
|
|
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
|
|
|
$cg->save();
|
|
|
|
}
|
2021-07-03 05:47:15 +02:00
|
|
|
|
|
|
|
$this->client = $this->client->fresh();
|
|
|
|
$this->invoice = $this->invoice->fresh();
|
2023-01-13 02:43:38 +01:00
|
|
|
|
|
|
|
$this->scheduler = Scheduler::factory()->create([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->scheduler->save();
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2019-09-18 14:43:37 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
private function buildLineItems()
|
|
|
|
{
|
|
|
|
$line_items = [];
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
2020-09-06 11:38:10 +02:00
|
|
|
$item->cost = 10;
|
2020-11-01 08:53:43 +01:00
|
|
|
$item->task_id = $this->encodePrimaryKey($this->task->id);
|
|
|
|
$item->expense_id = $this->encodePrimaryKey($this->expense->id);
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$line_items[] = $item;
|
2019-05-14 06:05:05 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
return $line_items;
|
|
|
|
}
|
|
|
|
}
|