mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:04:34 -04:00
working on client currency conversion
This commit is contained in:
parent
a293f53c08
commit
edd0a57b29
@ -812,6 +812,15 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
return $defaults;
|
return $defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setExchangeRate()
|
||||||
|
{
|
||||||
|
|
||||||
|
$converter = new CurrencyApi();
|
||||||
|
|
||||||
|
return 1/$converter->convert(1, $this->currency()->id, $this->company->settings->currency_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function timezone_offset() :int
|
public function timezone_offset() :int
|
||||||
{
|
{
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
@ -567,7 +567,7 @@ class InvoiceService
|
|||||||
|
|
||||||
/* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/
|
/* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/
|
||||||
if (! isset($this->invoice->exchange_rate) && $this->invoice->client->currency()->id != (int) $this->invoice->company->settings->currency_id) {
|
if (! isset($this->invoice->exchange_rate) && $this->invoice->client->currency()->id != (int) $this->invoice->company->settings->currency_id) {
|
||||||
$this->invoice->exchange_rate = $this->invoice->client->currency()->exchange_rate;
|
$this->invoice->exchange_rate = $this->invoice->client->setExchangeRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->invoice->client->getSetting('auto_bill_standard_invoices')) {
|
if ($this->invoice->client->getSetting('auto_bill_standard_invoices')) {
|
||||||
|
@ -11,25 +11,27 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Credit;
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Currency;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use App\Models\CompanyToken;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\DataMapper\DefaultSettings;
|
use App\DataMapper\DefaultSettings;
|
||||||
use App\Factory\InvoiceItemFactory;
|
use App\Factory\InvoiceItemFactory;
|
||||||
use App\Models\Account;
|
|
||||||
use App\Models\Client;
|
|
||||||
use App\Models\ClientContact;
|
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\CompanyToken;
|
|
||||||
use App\Models\Credit;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Tests\MockAccountData;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
use Tests\TestCase;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -65,6 +67,34 @@ class ClientTest extends TestCase
|
|||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClientExchangeRateCalculation()
|
||||||
|
{
|
||||||
|
$settings = ClientSettings::defaults();
|
||||||
|
$settings->currency_id = 12;
|
||||||
|
|
||||||
|
$c = Client::factory()
|
||||||
|
->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'settings' => $settings
|
||||||
|
]);
|
||||||
|
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->currency_id = '3';
|
||||||
|
|
||||||
|
$this->company->saveSettings($settings, $this->company);
|
||||||
|
|
||||||
|
$client_exchange_rate = round($c->setExchangeRate(),2);
|
||||||
|
|
||||||
|
$aud_currency = Currency::find(12);
|
||||||
|
$eur_currency = Currency::find(3);
|
||||||
|
|
||||||
|
$synthetic_exchange = $aud_currency->exchange_rate / $eur_currency->exchange_rate;
|
||||||
|
|
||||||
|
$this->assertEquals($client_exchange_rate, round($synthetic_exchange,2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testStoreClientFixes2()
|
public function testStoreClientFixes2()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -39,6 +39,7 @@ class CurrencyApiTest extends TestCase
|
|||||||
$converted_synthetic = 100 / ($aud_currency->exchange_rate / $eur_currency->exchange_rate);
|
$converted_synthetic = 100 / ($aud_currency->exchange_rate / $eur_currency->exchange_rate);
|
||||||
|
|
||||||
$this->assertEquals(round($converted_synthetic, 2), round($converted_amount, 2));
|
$this->assertEquals(round($converted_synthetic, 2), round($converted_amount, 2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCurrencyConversionWorking()
|
public function testCurrencyConversionWorking()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user