Merge pull request #6702 from turbo124/v5-develop

Selectively show recurring invoice dates
This commit is contained in:
David Bomba 2021-09-22 21:06:50 +10:00 committed by GitHub
commit 3fe45ac7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 573 additions and 78 deletions

View File

@ -29,6 +29,7 @@ use App\Models\Expense;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Models\Task;
use App\Models\User;
use App\Models\Vendor;
@ -532,7 +533,9 @@ class CreateTestData extends Command
$invoice->save();
$invoice->service()->createInvitations()->markSent();
if (rand(0, 1)) {
$this->invoice_repo->markSent($invoice);
}
if (rand(0, 1)) {
$invoice = $invoice->service()->markPaid()->save();
@ -545,6 +548,9 @@ class CreateTestData extends Command
'documentable_id' => $invoice->id
]);
RecurringInvoice::factory()->create(['user_id' => $invoice->user->id, 'company_id' => $invoice->company->id, 'client_id' => $invoice->client_id]);
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}

View File

@ -223,7 +223,7 @@ class PaymentController extends Controller
$invoice_totals = $payable_invoices->sum('amount');
$first_invoice = $invoices->first();
$credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'always' ? $first_invoice->client->service()->getCreditBalance() : 0;
$starting_invoice_amount = $first_invoice->amount;
$starting_invoice_amount = $first_invoice->balance;
if ($gateway) {
$first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
@ -234,7 +234,7 @@ class PaymentController extends Controller
* by adding it as a line item, and then subtract
* the starting and finishing amounts of the invoice.
*/
$fee_totals = $first_invoice->amount - $starting_invoice_amount;
$fee_totals = $first_invoice->balance - $starting_invoice_amount;
if ($gateway) {
$tokens = auth()->user()->client->gateway_tokens()

View File

@ -28,6 +28,8 @@ class LedgerService
{
$balance = 0;
\DB::connection(config('database.default'))->beginTransaction();
$company_ledger = $this->ledger();
if ($company_ledger) {
@ -44,6 +46,8 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
\DB::connection(config('database.default'))->commit();
return $this;
}
@ -51,6 +55,8 @@ class LedgerService
{
$balance = 0;
\DB::connection(config('database.default'))->beginTransaction();
/* Get the last record for the client and set the current balance*/
$company_ledger = $this->ledger();
@ -68,6 +74,8 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
\DB::connection(config('database.default'))->commit();
return $this;
}
@ -75,6 +83,8 @@ class LedgerService
{
$balance = 0;
\DB::connection(config('database.default'))->beginTransaction();
$company_ledger = $this->ledger();
if ($company_ledger) {
@ -91,6 +101,8 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
\DB::connection(config('database.default'))->commit();
return $this;
}
@ -99,6 +111,7 @@ class LedgerService
return CompanyLedger::whereClientId($this->entity->client_id)
->whereCompanyId($this->entity->company_id)
->orderBy('id', 'DESC')
->lockForUpdate()
->first();
}
@ -109,3 +122,11 @@ class LedgerService
return $this->entity;
}
}
/*
DB::connection(config('database.default'))->beginTransaction();
\DB::connection(config('database.default'))->commit();
*/

View File

@ -64,7 +64,8 @@ class RecurringInvoiceTransformer extends EntityTransformer
public function transform(RecurringInvoice $invoice)
{
return [
$data = [
'id' => $this->encodePrimaryKey($invoice->id),
'user_id' => $this->encodePrimaryKey($invoice->user_id),
'project_id' => $this->encodePrimaryKey($invoice->project_id),
@ -120,13 +121,19 @@ class RecurringInvoiceTransformer extends EntityTransformer
'entity_type' => 'recurringInvoice',
'frequency_id' => (string) $invoice->frequency_id,
'remaining_cycles' => (int) $invoice->remaining_cycles,
//'recurring_dates' => (array) $invoice->recurringDates(),
'recurring_dates' => [],
'auto_bill' => (string) $invoice->auto_bill,
'auto_bill_enabled' => (bool) $invoice->auto_bill_enabled,
'due_date_days' => (string) $invoice->due_date_days ?: '',
'paid_to_date' => (float) $invoice->paid_to_date,
'subscription_id' => (string)$this->encodePrimaryKey($invoice->subscription_id),
];
if(request()->has('show_dates') && request()->query('show_dates') == 'true')
$data['recurring_dates'] = (array) $invoice->recurringDates();
return $data;
}
}

View File

@ -107,8 +107,11 @@ class Helpers
* @param Client $client
* @return null|string
*/
public static function processReservedKeywords(string $value, Client $client): ?string
public static function processReservedKeywords(?string $value, Client $client): ?string
{
if(!$value)
return '';
Carbon::setLocale($client->locale());
$replacements = [

115
composer.lock generated
View File

@ -323,16 +323,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.194.1",
"version": "3.194.2",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "67bdee05acef9e8ad60098090996690b49babd09"
"reference": "1f0a0cec5721b6346c968533fba9b44e462fc728"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/67bdee05acef9e8ad60098090996690b49babd09",
"reference": "67bdee05acef9e8ad60098090996690b49babd09",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/1f0a0cec5721b6346c968533fba9b44e462fc728",
"reference": "1f0a0cec5721b6346c968533fba9b44e462fc728",
"shasum": ""
},
"require": {
@ -408,9 +408,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.194.1"
"source": "https://github.com/aws/aws-sdk-php/tree/3.194.2"
},
"time": "2021-09-17T18:15:42+00:00"
"time": "2021-09-21T18:14:06+00:00"
},
{
"name": "bacon/bacon-qr-code",
@ -2652,16 +2652,16 @@
},
{
"name": "google/apiclient",
"version": "v2.10.1",
"version": "v2.11.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client.git",
"reference": "11871e94006ce7a419bb6124d51b6f9ace3f679b"
"reference": "7db9eb40c8ba887e81c0fe84f2888a967396cdfb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/11871e94006ce7a419bb6124d51b6f9ace3f679b",
"reference": "11871e94006ce7a419bb6124d51b6f9ace3f679b",
"url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/7db9eb40c8ba887e81c0fe84f2888a967396cdfb",
"reference": "7db9eb40c8ba887e81c0fe84f2888a967396cdfb",
"shasum": ""
},
"require": {
@ -2669,8 +2669,8 @@
"google/apiclient-services": "~0.200",
"google/auth": "^1.10",
"guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0",
"guzzlehttp/psr7": "^1.2",
"monolog/monolog": "^1.17|^2.0",
"guzzlehttp/psr7": "^1.7||^2.0.0",
"monolog/monolog": "^1.17||^2.0",
"php": "^5.6|^7.0|^8.0",
"phpseclib/phpseclib": "~2.0||^3.0.2"
},
@ -2679,10 +2679,12 @@
"composer/composer": "^1.10.22",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.2",
"phpunit/phpunit": "^5.7||^8.5.13",
"phpspec/prophecy-phpunit": "^1.1||^2.0",
"phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"squizlabs/php_codesniffer": "~2.3",
"symfony/css-selector": "~2.1",
"symfony/dom-crawler": "~2.1"
"symfony/dom-crawler": "~2.1",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"
@ -2715,22 +2717,22 @@
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client/issues",
"source": "https://github.com/googleapis/google-api-php-client/tree/v2.10.1"
"source": "https://github.com/googleapis/google-api-php-client/tree/v2.11.0"
},
"time": "2021-06-25T14:25:44+00:00"
"time": "2021-09-20T21:15:55+00:00"
},
{
"name": "google/apiclient-services",
"version": "v0.212.0",
"version": "v0.213.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git",
"reference": "2c4bd512502ad9cdfec8ea711ea1592c79d345e5"
"reference": "260311821505438eb9208b068da0d849b8ea9baa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/2c4bd512502ad9cdfec8ea711ea1592c79d345e5",
"reference": "2c4bd512502ad9cdfec8ea711ea1592c79d345e5",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/260311821505438eb9208b068da0d849b8ea9baa",
"reference": "260311821505438eb9208b068da0d849b8ea9baa",
"shasum": ""
},
"require": {
@ -2759,9 +2761,9 @@
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client-services/issues",
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.212.0"
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.213.0"
},
"time": "2021-09-12T11:18:27+00:00"
"time": "2021-09-19T11:18:26+00:00"
},
{
"name": "google/auth",
@ -5586,20 +5588,20 @@
},
{
"name": "nette/utils",
"version": "v3.2.3",
"version": "v3.2.5",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822"
"reference": "9cd80396ca58d7969ab44fc7afcf03624dfa526e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822",
"reference": "5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822",
"url": "https://api.github.com/repos/nette/utils/zipball/9cd80396ca58d7969ab44fc7afcf03624dfa526e",
"reference": "9cd80396ca58d7969ab44fc7afcf03624dfa526e",
"shasum": ""
},
"require": {
"php": ">=7.2 <8.1"
"php": ">=7.2 <8.2"
},
"conflict": {
"nette/di": "<3.0.6"
@ -5665,22 +5667,22 @@
],
"support": {
"issues": "https://github.com/nette/utils/issues",
"source": "https://github.com/nette/utils/tree/v3.2.3"
"source": "https://github.com/nette/utils/tree/v3.2.5"
},
"time": "2021-08-16T21:05:00+00:00"
"time": "2021-09-20T10:50:11+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.12.0",
"version": "v4.13.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "6608f01670c3cc5079e18c1dab1104e002579143"
"reference": "50953a2691a922aa1769461637869a0a2faa3f53"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143",
"reference": "6608f01670c3cc5079e18c1dab1104e002579143",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53",
"shasum": ""
},
"require": {
@ -5721,9 +5723,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0"
},
"time": "2021-07-21T10:44:31+00:00"
"time": "2021-09-20T12:20:58+00:00"
},
{
"name": "nwidart/laravel-modules",
@ -12740,16 +12742,16 @@
},
{
"name": "filp/whoops",
"version": "2.14.1",
"version": "2.14.3",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "15ead64e9828f0fc90932114429c4f7923570cb1"
"reference": "89584ce67dd32307f1063cc43846674f4679feda"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/15ead64e9828f0fc90932114429c4f7923570cb1",
"reference": "15ead64e9828f0fc90932114429c4f7923570cb1",
"url": "https://api.github.com/repos/filp/whoops/zipball/89584ce67dd32307f1063cc43846674f4679feda",
"reference": "89584ce67dd32307f1063cc43846674f4679feda",
"shasum": ""
},
"require": {
@ -12799,7 +12801,7 @@
],
"support": {
"issues": "https://github.com/filp/whoops/issues",
"source": "https://github.com/filp/whoops/tree/2.14.1"
"source": "https://github.com/filp/whoops/tree/2.14.3"
},
"funding": [
{
@ -12807,7 +12809,7 @@
"type": "github"
}
],
"time": "2021-08-29T12:00:00+00:00"
"time": "2021-09-19T12:00:00+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
@ -13290,33 +13292,32 @@
},
{
"name": "nunomaduro/collision",
"version": "v5.9.0",
"version": "v5.10.0",
"source": {
"type": "git",
"url": "https://github.com/nunomaduro/collision.git",
"reference": "63456f5c3e8c4bc52bd573e5c85674d64d84fd43"
"reference": "3004cfa49c022183395eabc6d0e5207dfe498d00"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nunomaduro/collision/zipball/63456f5c3e8c4bc52bd573e5c85674d64d84fd43",
"reference": "63456f5c3e8c4bc52bd573e5c85674d64d84fd43",
"url": "https://api.github.com/repos/nunomaduro/collision/zipball/3004cfa49c022183395eabc6d0e5207dfe498d00",
"reference": "3004cfa49c022183395eabc6d0e5207dfe498d00",
"shasum": ""
},
"require": {
"facade/ignition-contracts": "^1.0",
"filp/whoops": "^2.7.2",
"filp/whoops": "^2.14.3",
"php": "^7.3 || ^8.0",
"symfony/console": "^5.0"
},
"require-dev": {
"brianium/paratest": "^6.1",
"fideloper/proxy": "^4.4.1",
"friendsofphp/php-cs-fixer": "^3.0",
"fruitcake/laravel-cors": "^2.0.3",
"laravel/framework": "^8.0 || ^9.0",
"laravel/framework": "8.x-dev",
"nunomaduro/larastan": "^0.6.2",
"nunomaduro/mock-final-classes": "^1.0",
"orchestra/testbench": "^6.0 || ^7.0",
"orchestra/testbench": "^6.0",
"phpstan/phpstan": "^0.12.64",
"phpunit/phpunit": "^9.5.0"
},
@ -13374,7 +13375,7 @@
"type": "patreon"
}
],
"time": "2021-08-26T15:32:09+00:00"
"time": "2021-09-20T15:06:32+00:00"
},
{
"name": "openlss/lib-array2xml",
@ -15274,16 +15275,16 @@
},
{
"name": "swagger-api/swagger-ui",
"version": "v3.52.2",
"version": "v3.52.3",
"source": {
"type": "git",
"url": "https://github.com/swagger-api/swagger-ui.git",
"reference": "e5611d72ff6b4affb373fa8859cc5feb6981f367"
"reference": "aa9f2e6733327b5f042f2529db76558d9c09bed2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swagger-api/swagger-ui/zipball/e5611d72ff6b4affb373fa8859cc5feb6981f367",
"reference": "e5611d72ff6b4affb373fa8859cc5feb6981f367",
"url": "https://api.github.com/repos/swagger-api/swagger-ui/zipball/aa9f2e6733327b5f042f2529db76558d9c09bed2",
"reference": "aa9f2e6733327b5f042f2529db76558d9c09bed2",
"shasum": ""
},
"type": "library",
@ -15329,9 +15330,9 @@
],
"support": {
"issues": "https://github.com/swagger-api/swagger-ui/issues",
"source": "https://github.com/swagger-api/swagger-ui/tree/v3.52.2"
"source": "https://github.com/swagger-api/swagger-ui/tree/v3.52.3"
},
"time": "2021-09-13T12:46:28+00:00"
"time": "2021-09-20T12:12:56+00:00"
},
{
"name": "symfony/debug",
@ -15901,5 +15902,5 @@
"platform-dev": {
"php": "^7.3|^7.4|^8.0"
},
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.0.0"
}

View File

@ -69,19 +69,6 @@
</div>
</div>
@if(auth('contact')->user())
<a href="{{ route('client.invoices.index') }}" class="block mt-16 inline-flex items-center space-x-2">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-arrow-left">
<line x1="19" y1="12" x2="5" y2="12"></line>
<polyline points="12 19 5 12 12 5"></polyline>
</svg>
<span>{{ ctrans('texts.client_portal') }}</span>
</a>
@endif
@if($subscription->service()->getPlans()->count() > 1)
<div class="flex flex-col mt-10">
<p class="mb-4 uppercase leading-4 tracking-wide inline-flex items-center rounded-full text-xs font-medium">

472
tests/Feature/LoadTest.php Normal file
View File

@ -0,0 +1,472 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature;
use App\DataMapper\CompanySettings;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\Country;
use App\Models\Credit;
use App\Models\Document;
use App\Models\Expense;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\Task;
use App\Models\User;
use App\Models\Vendor;
use App\Models\VendorContact;
use App\Repositories\InvoiceRepository;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Str;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class LoadTest extends TestCase
{
use MakesHash;
use GeneratesCounter;
public int $count = 1;
public function setUp() :void
{
parent::setUp();
$this->markTestSkipped('Skip test not needed in this environment');
}
public function testLoad()
{
$account = Account::factory()->create();
$company = Company::factory()->create([
'account_id' => $account->id,
'slack_webhook_url' => config('ninja.notification.slack'),
]);
$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')),
]);
}
$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;
$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,
]);
dispatch(function () use($user, $company){
Product::factory()->count(500)->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
});
for ($x = 0; $x < $this->count * 100; $x++) {
$z = $x + 1;
$this->createClient($company, $user);
}
do{
sleep(3);
}
while($company->clients()->count() != 500);
for ($x = 0; $x < $this->count * 100 ; $x++) {
$client = $company->clients->random();
$this->createInvoice($client);
$client = $company->clients->random();
$this->createCredit($client);
$client = $company->clients->random();
$this->createQuote($client);
$client = $company->clients->random();
$this->createExpense($client);
$client = $company->clients->random();
$this->createVendor($client);
$client = $company->clients->random();
$this->createTask($client);
$client = $company->clients->random();
$this->createProject($client);
}
}
private function createClient($company, $user)
{
dispatch(function () use ($company, $user){
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'country_id' => 840,
]);
Document::factory()->count(2)->create([
'user_id' => $user->id,
'company_id' => $company->id,
'documentable_type' => Client::class,
'documentable_id' => $client->id
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(2)->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
]);
$client->number = Str::random(28);
$settings = $client->settings;
$settings->currency_id = (string) rand(1, 79);
$client->settings = $settings;
$client->save();
});
}
private function createExpense($client)
{
dispatch(function () use($client){
Expense::factory()->count(rand(1, 5))->create([
'user_id' => $client->user->id,
'client_id' => $client->id,
'company_id' => $client->company->id,
]);
});
}
private function createVendor($client)
{
dispatch(function () use($client){
$vendor = Vendor::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(2)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Vendor::class,
'documentable_id' => $vendor->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, 500))->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
'company_id' => $client->company->id,
'is_primary' => 0,
]);
});
}
private function createTask($client)
{
dispatch(function () use($client){
$vendor = Task::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Task::class,
'documentable_id' => $vendor->id
]);
});
}
private function createProject($client)
{
dispatch(function () use($client){
$vendor = Project::factory()->create([
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Project::class,
'documentable_id' => $vendor->id
]);
});
}
private function createInvoice($client)
{
$faker = \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\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();
$invoice->save();
$invoice->service()->createInvitations()->markSent();
if (rand(0, 1)) {
$invoice_repo = new InvoiceRepository();
$invoice_repo->markSent($invoice);
}
if (rand(0, 1)) {
$invoice = $invoice->service()->markPaid()->save();
}
Document::factory()->count(5)->create([
'user_id' => $invoice->user->id,
'company_id' => $invoice->company_id,
'documentable_type' => Invoice::class,
'documentable_id' => $invoice->id
]);
}
private function createCredit($client)
{
$faker = \Faker\Factory::create();
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
$dateable = \Carbon\Carbon::now()->subDays(rand(0, 90));
$credit->date = $dateable;
$credit->line_items = $this->buildLineItems(rand(1, 10));
$credit->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$credit->tax_name1 = 'GST';
$credit->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$credit->tax_name2 = 'VAT';
$credit->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$credit->tax_name3 = 'CA Sales Tax';
$credit->tax_rate3 = 5;
}
$credit->save();
$invoice_calc = new InvoiceSum($credit);
$invoice_calc->build();
$credit = $invoice_calc->getCredit();
$credit->save();
$credit->service()->markSent()->save();
$credit->service()->createInvitations();
}
private function createQuote($client)
{
$faker = \Faker\Factory::create();
//$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
$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();
$quote->service()->markSent()->save();
$quote->service()->createInvitations();
}
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;
}
}

View File

@ -141,8 +141,6 @@ class RecurringInvoiceTest extends TestCase
])->put('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id), $RecurringInvoice_update)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,