1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #6182 from turbo124/v5-develop

Fixes for setup flow
This commit is contained in:
David Bomba 2021-07-02 10:45:10 +10:00 committed by GitHub
commit e75d817bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 158 additions and 24 deletions

View File

@ -5,20 +5,14 @@ APP_DEBUG=false
APP_URL=http://localhost
DB_CONNECTION=db-ninja-01
DB_CONNECTION=mysql
MULTI_DB_ENABLED=false
DB_HOST1=localhost
DB_DATABASE1=ninja
DB_USERNAME1=ninja
DB_PASSWORD1=ninja
DB_PORT1=3306
DB_HOST2=localhost
DB_DATABASE2=ninja2
DB_USERNAME2=ninja
DB_PASSWORD2=ninja
DB_PORT2=3306
DB_HOST=localhost
DB_DATABASE=ninja
DB_USERNAME=ninja
DB_PASSWORD=ninja
DB_PORT=3306
DEMO_MODE=false

View File

@ -109,11 +109,11 @@ class SetupController extends Controller
'REQUIRE_HTTPS' => $request->input('https') ? 'true' : 'false',
'APP_DEBUG' => 'false',
'DB_HOST1' => $request->input('db_host'),
'DB_PORT1' => $request->input('db_port'),
'DB_DATABASE1' => $request->input('db_database'),
'DB_USERNAME1' => $request->input('db_username'),
'DB_PASSWORD1' => $request->input('db_password'),
'DB_HOST' => $request->input('db_host'),
'DB_PORT' => $request->input('db_port'),
'DB_DATABASE' => $request->input('db_database'),
'DB_USERNAME' => $request->input('db_username'),
'DB_PASSWORD' => $request->input('db_password'),
'MAIL_MAILER' => $mail_driver,
'MAIL_PORT' => $request->input('mail_port'),
@ -125,6 +125,7 @@ class SetupController extends Controller
'MAIL_PASSWORD' => $request->input('mail_password'),
'NINJA_ENVIRONMENT' => 'selfhost',
'DB_CONNECTION' => 'mysql',
];
if (config('ninja.db.multi_db_enabled')) {
@ -133,11 +134,11 @@ class SetupController extends Controller
if (config('ninja.preconfigured_install')) {
// Database connection was already configured. Don't let the user override it.
unset($env_values['DB_HOST1']);
unset($env_values['DB_PORT1']);
unset($env_values['DB_DATABASE1']);
unset($env_values['DB_USERNAME1']);
unset($env_values['DB_PASSWORD1']);
unset($env_values['DB_HOST']);
unset($env_values['DB_PORT']);
unset($env_values['DB_DATABASE']);
unset($env_values['DB_USERNAME']);
unset($env_values['DB_PASSWORD']);
}
try {

View File

@ -51,6 +51,7 @@ class ClientService
$credits = $this->client->credits
->where('is_deleted', false)
->where('balance', '>', 0)
->where('due_date', '<=', now())
->sortBy('created_at');
return Number::roundValue($credits->sum('balance'), $this->client->currency()->precision);

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.2.7',
'app_tag' => '5.2.7',
'app_version' => '5.2.8',
'app_tag' => '5.2.8',
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''),

71
tests/MockUnitData.php Normal file
View File

@ -0,0 +1,71 @@
<?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;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\User;
/**
* Class MockUnitData.
*/
trait MockUnitData
{
public $account;
public $company;
public $user;
public $client;
public $faker;
public $primary_contact;
public function makeTestData()
{
$this->faker = \Faker\Factory::create();
$this->account = Account::factory()->create();
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'email' => $this->faker->safeEmail
]);
$this->company = Company::factory()->create([
'account_id' => $this->account->id
]);
$this->client = Client::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id
]);
$this->primary_contact = ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $this->client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(2)->create([
'user_id' => $this->user->id,
'client_id' => $this->client->id,
'company_id' => $this->company->id,
]);
}
}

View File

@ -0,0 +1,67 @@
<?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\Unit;
use App\Models\Account;
use App\Models\Client;
use App\Models\Company;
use App\Models\Credit;
use App\Models\User;
use Tests\MockUnitData;
use Tests\TestCase;
/**
* @test
*/
class CreditBalanceTest extends TestCase
{
use MockUnitData;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
}
public function testCreditBalance()
{
$credit = Credit::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'client_id' => $this->client->id,
'balance' => 10,
'number' => 'testing-number-01',
'status_id' => Credit::STATUS_SENT,
]);
$this->assertEquals($this->client->service()->getCreditBalance(), 10);
}
public function testExpiredCreditBalance()
{
$credit = Credit::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'client_id' => $this->client->id,
'balance' => 10,
'due_date' => now()->addDays(5),
'number' => 'testing-number-02',
'status_id' => Credit::STATUS_SENT,
]);
$this->assertEquals($this->client->service()->getCreditBalance(), 0);
}
}