mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 12:14:37 -04:00
Fixes for tests
This commit is contained in:
parent
42e54d0bd5
commit
e329c24879
@ -41,7 +41,6 @@ class ClientSettings extends BaseSettings
|
|||||||
public $payment_terms;
|
public $payment_terms;
|
||||||
|
|
||||||
public $language_id;
|
public $language_id;
|
||||||
public $currency_id;
|
|
||||||
public $precision;
|
public $precision;
|
||||||
public $default_task_rate;
|
public $default_task_rate;
|
||||||
public $send_reminders;
|
public $send_reminders;
|
||||||
|
@ -27,7 +27,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $financial_year_start;
|
public $financial_year_start;
|
||||||
|
|
||||||
public $language_id;
|
public $language_id;
|
||||||
public $currency_id;
|
|
||||||
public $precision;
|
public $precision;
|
||||||
public $show_currency_symbol;
|
public $show_currency_symbol;
|
||||||
public $show_currency_code;
|
public $show_currency_code;
|
||||||
@ -138,7 +138,6 @@ class CompanySettings extends BaseSettings
|
|||||||
'entity' => Company::class,
|
'entity' => Company::class,
|
||||||
'timezone_id' => config('ninja.i18n.timezone_id'),
|
'timezone_id' => config('ninja.i18n.timezone_id'),
|
||||||
'language_id' => config('ninja.i18n.language_id'),
|
'language_id' => config('ninja.i18n.language_id'),
|
||||||
'currency_id' => config('ninja.i18n.currency_id'),
|
|
||||||
'precision' => 2,
|
'precision' => 2,
|
||||||
'payment_terms' => config('ninja.i18n.payment_terms'),
|
'payment_terms' => config('ninja.i18n.payment_terms'),
|
||||||
'datetime_format' => config('ninja.i18n.datetime_format'),
|
'datetime_format' => config('ninja.i18n.datetime_format'),
|
||||||
|
@ -29,7 +29,7 @@ class ClientFactory
|
|||||||
$client->country_id = 4;
|
$client->country_id = 4;
|
||||||
$client->is_deleted = 0;
|
$client->is_deleted = 0;
|
||||||
$client->client_hash = str_random(40);
|
$client->client_hash = str_random(40);
|
||||||
|
$client->currency_id = config('ninja.i18n.currency_id');
|
||||||
$client->settings = new ClientSettings(ClientSettings::defaults());
|
$client->settings = new ClientSettings(ClientSettings::defaults());
|
||||||
|
|
||||||
$client_contact = ClientContactFactory::create($company_id, $user_id);
|
$client_contact = ClientContactFactory::create($company_id, $user_id);
|
||||||
|
@ -62,9 +62,9 @@ class InvoiceController extends Controller
|
|||||||
})->editColumn('due_date', function ($invoice){
|
})->editColumn('due_date', function ($invoice){
|
||||||
return $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
return $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||||
})->editColumn('balance', function ($invoice) {
|
})->editColumn('balance', function ($invoice) {
|
||||||
return Number::formatMoney($invoice->balance, $invoice->client->currency(), $invoice->client->country, $invoice->client->getMergedSettings());
|
return Number::formatMoney($invoice->balance, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings());
|
||||||
})->editColumn('amount', function ($invoice) {
|
})->editColumn('amount', function ($invoice) {
|
||||||
return Number::formatMoney($invoice->amount, $invoice->client->currency(), $invoice->client->country, $invoice->client->getMergedSettings());
|
return Number::formatMoney($invoice->amount, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings());
|
||||||
})
|
})
|
||||||
->rawColumns(['checkbox', 'action', 'status_id'])
|
->rawColumns(['checkbox', 'action', 'status_id'])
|
||||||
->make(true);
|
->make(true);
|
||||||
@ -125,14 +125,14 @@ class InvoiceController extends Controller
|
|||||||
$invoices->filter(function ($invoice){
|
$invoices->filter(function ($invoice){
|
||||||
return $invoice->isPayable();
|
return $invoice->isPayable();
|
||||||
})->map(function ($invoice){
|
})->map(function ($invoice){
|
||||||
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client->currency(), $invoice->client->country, $invoice->client->getMergedSettings());
|
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client->currency, $invoice->client->country, $invoice->client->getMergedSettings());
|
||||||
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||||
|
|
||||||
return $invoice;
|
return $invoice;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$formatted_total = Number::formatMoney($total, auth()->user()->client->currency(), auth()->user()->client->country, auth()->user()->client->getMergedSettings());
|
$formatted_total = Number::formatMoney($total, auth()->user()->client->currency, auth()->user()->client->country, auth()->user()->client->getMergedSettings());
|
||||||
|
|
||||||
$payment_methods = auth()->user()->client->getPaymentMethods($total);
|
$payment_methods = auth()->user()->client->getPaymentMethods($total);
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ class Client extends BaseModel
|
|||||||
|
|
||||||
public function currency()
|
public function currency()
|
||||||
{
|
{
|
||||||
return Currency::find($this->getMergedSettings()->currency_id);
|
return $this->belongsTo(Currency::class);
|
||||||
|
//return Currency::find($this->getMergedSettings()->currency_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMergedSettings()
|
public function getMergedSettings()
|
||||||
|
@ -151,7 +151,7 @@ class CompanyGateway extends BaseModel
|
|||||||
$fee = $this->calcGatewayFee($amount);
|
$fee = $this->calcGatewayFee($amount);
|
||||||
|
|
||||||
if($fee > 0 ){
|
if($fee > 0 ){
|
||||||
$fee = Number::formatMoney(round($fee, 2), $client->currency(), $client->country(), $client->getMergedSettings());
|
$fee = Number::formatMoney(round($fee, 2), $client->currency, $client->country(), $client->getMergedSettings());
|
||||||
$label = ' - ' . $fee . ' ' . ctrans('texts.fee');
|
$label = ' - ' . $fee . ' ' . ctrans('texts.fee');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,17 +172,6 @@ class Invoice extends BaseModel
|
|||||||
return $this->client->getMergedSettings()->lock_sent_invoices;
|
return $this->client->getMergedSettings()->lock_sent_invoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the currency from the settings object.
|
|
||||||
*
|
|
||||||
* @return Eloquent Model The currency.
|
|
||||||
*/
|
|
||||||
public function getCurrency()
|
|
||||||
{
|
|
||||||
return Currency::find($this->settings->currency_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if invoice overdue.
|
* Determines if invoice overdue.
|
||||||
*
|
*
|
||||||
|
@ -71,13 +71,11 @@ class Statics
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
$cached_tables = config('ninja.cached_tables');
|
foreach (config('ninja.cached_tables') as $name => $class) {
|
||||||
|
|
||||||
foreach ($cached_tables as $name => $class) {
|
|
||||||
$data[$name] = Cache::get($name);
|
$data[$name] = Cache::get($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::error($data);
|
// Log::error($data);
|
||||||
|
|
||||||
if ($locale) {
|
if ($locale) {
|
||||||
|
|
||||||
|
@ -167,13 +167,13 @@ trait MakesInvoiceValues
|
|||||||
// $data['$quantity'] = ;
|
// $data['$quantity'] = ;
|
||||||
// $data['$line_total'] = ;
|
// $data['$line_total'] = ;
|
||||||
// $data['$paid_to_date'] = ;
|
// $data['$paid_to_date'] = ;
|
||||||
$data['$discount'] = Number::formatMoney($this->calc()->getTotalDiscount(), $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$discount'] = Number::formatMoney($this->calc()->getTotalDiscount(), $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$subtotal'] = Number::formatMoney($this->calc()->getSubTotal(), $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$subtotal'] = Number::formatMoney($this->calc()->getSubTotal(), $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$balance_due'] = Number::formatMoney($this->balance, $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$balance_due'] = Number::formatMoney($this->balance, $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$partial_due'] = Number::formatMoney($this->partial, $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$partial_due'] = Number::formatMoney($this->partial, $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$total'] = Number::formatMoney($this->calc()->getTotal(), $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$total'] = Number::formatMoney($this->calc()->getTotal(), $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$balance'] = Number::formatMoney($this->calc()->getBalance(), $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$balance'] = Number::formatMoney($this->calc()->getBalance(), $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$taxes'] = Number::formatMoney($this->calc()->getTotalTaxes(), $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$data['$taxes'] = Number::formatMoney($this->calc()->getTotalTaxes(), $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$data['$terms'] = $this->terms;
|
$data['$terms'] = $this->terms;
|
||||||
// $data['$your_invoice'] = ;
|
// $data['$your_invoice'] = ;
|
||||||
// $data['$quote'] = ;
|
// $data['$quote'] = ;
|
||||||
@ -365,14 +365,14 @@ trait MakesInvoiceValues
|
|||||||
foreach($items as $item)
|
foreach($items as $item)
|
||||||
{
|
{
|
||||||
|
|
||||||
$item->cost = Number::formatMoney($item->cost, $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$item->cost = Number::formatMoney($item->cost, $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
$item->line_total = Number::formatMoney($item->line_total, $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$item->line_total = Number::formatMoney($item->line_total, $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
|
|
||||||
if(isset($item->discount) && $item->discount > 0)
|
if(isset($item->discount) && $item->discount > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($item->is_amount_discount)
|
if($item->is_amount_discount)
|
||||||
$item->discount = Number::formatMoney($item->discount, $this->client->currency(), $this->client->country, $this->client->getMergedSettings());
|
$item->discount = Number::formatMoney($item->discount, $this->client->currency, $this->client->country, $this->client->getMergedSettings());
|
||||||
else
|
else
|
||||||
$item->discount = $item->discount . '%';
|
$item->discount = $item->discount . '%';
|
||||||
}
|
}
|
||||||
@ -403,7 +403,7 @@ trait MakesInvoiceValues
|
|||||||
{
|
{
|
||||||
$data .= '<tr class="line_taxes">';
|
$data .= '<tr class="line_taxes">';
|
||||||
$data .= '<td>'. $tax['name'] .'</td>';
|
$data .= '<td>'. $tax['name'] .'</td>';
|
||||||
$data .= '<td>'. Number::formatMoney($tax['total'], $this->client->currency(), $this->client->country, $this->client->getMergedSettings()) .'</td></tr>';
|
$data .= '<td>'. Number::formatMoney($tax['total'], $this->client->currency, $this->client->country, $this->client->getMergedSettings()) .'</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -40,7 +40,7 @@ return [
|
|||||||
'i18n' => [
|
'i18n' => [
|
||||||
'timezone_id' => env('DEFAULT_TIMEZONE', 15),
|
'timezone_id' => env('DEFAULT_TIMEZONE', 15),
|
||||||
'country_id' => env('DEFAULT_COUNTRY', 840), // United Stated
|
'country_id' => env('DEFAULT_COUNTRY', 840), // United Stated
|
||||||
'currency_id' => env('DEFAULT_CURRENCY', 1), //USD
|
'currency_id' => env('DEFAULT_CURRENCY', 1),
|
||||||
'language_id' => env('DEFAULT_LANGUAGE', 1), //en
|
'language_id' => env('DEFAULT_LANGUAGE', 1), //en
|
||||||
'date_format' => env('DEFAULT_DATE_FORMAT', 'M j, Y'),
|
'date_format' => env('DEFAULT_DATE_FORMAT', 'M j, Y'),
|
||||||
'date_picker_format' => env('DEFAULT_DATE_PICKER_FORMAT', 'M d, yyyy'),
|
'date_picker_format' => env('DEFAULT_DATE_PICKER_FORMAT', 'M d, yyyy'),
|
||||||
|
@ -21,6 +21,7 @@ $factory->define(App\Models\Client::class, function (Faker $faker) {
|
|||||||
'city' => $faker->city,
|
'city' => $faker->city,
|
||||||
'state' => $faker->state,
|
'state' => $faker->state,
|
||||||
'postal_code' => $faker->postcode,
|
'postal_code' => $faker->postcode,
|
||||||
|
'currency_id' => 1,
|
||||||
'country_id' => 4,
|
'country_id' => 4,
|
||||||
'shipping_address1' => $faker->buildingNumber,
|
'shipping_address1' => $faker->buildingNumber,
|
||||||
'shipping_address2' => $faker->streetAddress,
|
'shipping_address2' => $faker->streetAddress,
|
||||||
|
@ -4,6 +4,7 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\CompanyToken;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
@ -12,6 +13,7 @@ use Illuminate\Foundation\Testing\WithFaker;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -142,18 +144,37 @@ class LoginTest extends TestCase
|
|||||||
'password' => \Hash::make('123456')
|
'password' => \Hash::make('123456')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$company = factory(\App\Models\Company::class)->make([
|
$company = factory(\App\Models\Company::class)->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'domain' => 'ninja.test',
|
'domain' => 'ninja.test',
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$account->default_company_id = $account->id;
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
|
||||||
|
$ct = CompanyToken::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'token' => str_random(64),
|
||||||
|
'name' => $user->first_name. ' '. $user->last_name,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
$user->companies()->attach($company->id, [
|
$user->companies()->attach($company->id, [
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'is_owner' => 1,
|
'is_owner' => 1,
|
||||||
'is_admin' => 1,
|
'is_admin' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$user->fresh();
|
||||||
|
|
||||||
|
$this->assertTrue($user->companies !== null);
|
||||||
|
$this->assertTrue($user->user_companies !== null);
|
||||||
|
$this->assertTrue($user->user_companies->first() !== null);
|
||||||
|
$this->assertTrue($user->user_companies->first()->account !== null);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
'password' => '123456'
|
'password' => '123456'
|
||||||
|
@ -34,7 +34,7 @@ class CollectionMergingTest extends TestCase
|
|||||||
|
|
||||||
public function testMergingCollection()
|
public function testMergingCollection()
|
||||||
{
|
{
|
||||||
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
|
$payment_terms = collect(config('ninja.payment_terms'));
|
||||||
|
|
||||||
$new_terms = $this->terms->map(function($term) {
|
$new_terms = $this->terms->map(function($term) {
|
||||||
return $term['num_days'];
|
return $term['num_days'];
|
||||||
@ -47,7 +47,7 @@ class CollectionMergingTest extends TestCase
|
|||||||
|
|
||||||
public function testSortingCollection()
|
public function testSortingCollection()
|
||||||
{
|
{
|
||||||
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
|
$payment_terms = collect(config('ninja.payment_terms'));
|
||||||
|
|
||||||
$new_terms = $this->terms->map(function($term) {
|
$new_terms = $this->terms->map(function($term) {
|
||||||
return $term['num_days'];
|
return $term['num_days'];
|
||||||
@ -65,7 +65,7 @@ class CollectionMergingTest extends TestCase
|
|||||||
|
|
||||||
public function testSortingCollectionLast()
|
public function testSortingCollectionLast()
|
||||||
{
|
{
|
||||||
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
|
$payment_terms = collect(config('ninja.payment_terms'));
|
||||||
|
|
||||||
$new_terms = $this->terms->map(function($term) {
|
$new_terms = $this->terms->map(function($term) {
|
||||||
return $term['num_days'];
|
return $term['num_days'];
|
||||||
|
@ -28,13 +28,6 @@ class CompanySettingsTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCurrencyId()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->assertEquals($this->company_settings->currency_id, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLanguageId()
|
public function testLanguageId()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -52,7 +45,7 @@ class CompanySettingsTest extends TestCase
|
|||||||
public function testPropertyIsSet()
|
public function testPropertyIsSet()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->assertTrue(isset($this->company_settings->currency_id));
|
$this->assertTrue(isset($this->company_settings->timezone_id));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ class CompareObjectTest extends TestCase
|
|||||||
$build_client_settings = $this->buildClientSettings();
|
$build_client_settings = $this->buildClientSettings();
|
||||||
|
|
||||||
$this->assertEquals($build_client_settings->timezone_id, 15);
|
$this->assertEquals($build_client_settings->timezone_id, 15);
|
||||||
$this->assertEquals($build_client_settings->currency_id, 1);
|
|
||||||
$this->assertEquals($build_client_settings->language_id, 1);
|
$this->assertEquals($build_client_settings->language_id, 1);
|
||||||
$this->assertEquals($build_client_settings->payment_terms, 1);
|
$this->assertEquals($build_client_settings->payment_terms, 1);
|
||||||
}
|
}
|
||||||
@ -56,7 +55,6 @@ class CompareObjectTest extends TestCase
|
|||||||
$settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults()));
|
$settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults()));
|
||||||
|
|
||||||
$this->assertEquals($settings->timezone_id, 15);
|
$this->assertEquals($settings->timezone_id, 15);
|
||||||
$this->assertEquals($settings->currency_id, 1);
|
|
||||||
$this->assertEquals($settings->language_id, 1);
|
$this->assertEquals($settings->language_id, 1);
|
||||||
$this->assertEquals($settings->payment_terms, 1);
|
$this->assertEquals($settings->payment_terms, 1);
|
||||||
$this->assertEquals($settings->custom_taxes1, 'FALSE');
|
$this->assertEquals($settings->custom_taxes1, 'FALSE');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user