mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 14:24:45 -04:00
Fixes for client_id queries on client list
This commit is contained in:
parent
988a7defee
commit
c60045da58
@ -70,6 +70,16 @@ class ClientFilters extends QueryFilters
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function client_id(string $client_id = '') :Builder
|
||||||
|
{
|
||||||
|
if (strlen($client_id) == 0) {
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->builder->where('id', $this->decodePrimaryKey($client_id));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function id_number(string $id_number):Builder
|
public function id_number(string $id_number):Builder
|
||||||
{
|
{
|
||||||
return $this->builder->where('id_number', $id_number);
|
return $this->builder->where('id_number', $id_number);
|
||||||
|
@ -19,6 +19,12 @@ use Illuminate\Support\Facades\DB;
|
|||||||
trait ChartQueries
|
trait ChartQueries
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// $currencies = Payment::withTrashed()
|
||||||
|
// ->where('company_id', $this->company->id)
|
||||||
|
// ->where('is_deleted', 0)
|
||||||
|
// ->distinct()
|
||||||
|
// ->get(['currency_id']);
|
||||||
|
|
||||||
public function getRevenueQuery($start_date, $end_date)
|
public function getRevenueQuery($start_date, $end_date)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -35,13 +35,6 @@ class ChartService
|
|||||||
*/
|
*/
|
||||||
public function getCurrencyCodes() :array
|
public function getCurrencyCodes() :array
|
||||||
{
|
{
|
||||||
|
|
||||||
// $currencies = Payment::withTrashed()
|
|
||||||
// ->where('company_id', $this->company->id)
|
|
||||||
// ->where('is_deleted', 0)
|
|
||||||
// ->distinct()
|
|
||||||
// ->get(['currency_id']);
|
|
||||||
|
|
||||||
/* Get all the distinct client currencies */
|
/* Get all the distinct client currencies */
|
||||||
$currencies = Client::withTrashed()
|
$currencies = Client::withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
*/
|
*/
|
||||||
namespace Tests\Unit\Chart;
|
namespace Tests\Unit\Chart;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Services\Chart\ChartService;
|
use App\Services\Chart\ChartService;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
@ -17,6 +19,7 @@ use Tests\TestCase;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @covers App\Services\Chart\ChartService
|
||||||
*/
|
*/
|
||||||
class ChartCurrencyTest extends TestCase
|
class ChartCurrencyTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -29,80 +32,109 @@ class ChartCurrencyTest extends TestCase
|
|||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function testClientServiceDataSetBuild()
|
public function testgetCurrencyCodes()
|
||||||
// {
|
{
|
||||||
|
$settings = ClientSettings::defaults();
|
||||||
|
$settings->currency_id = "1"; //USD
|
||||||
|
|
||||||
// $haystack = [
|
Client::factory()->create([
|
||||||
// [
|
'user_id' => $this->user->id,
|
||||||
// 'currency_id' => null,
|
'company_id' => $this->company->id,
|
||||||
// 'amount' => 10
|
'settings' => $settings,
|
||||||
// ],
|
]);
|
||||||
// [
|
|
||||||
// 'currency_id' => 1,
|
|
||||||
// 'amount' => 11
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'currency_id' => 2,
|
|
||||||
// 'amount' => 12
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'currency_id' => 3,
|
|
||||||
// 'amount' => 13
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $cs = new ChartService($this->company);
|
$settings = ClientSettings::defaults();
|
||||||
|
$settings->currency_id = "2"; //GBP
|
||||||
|
|
||||||
// nlog($cs->totals(now()->subYears(10), now()));
|
Client::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'settings' => $settings,
|
||||||
|
]);
|
||||||
|
|
||||||
// $this->assertTrue(is_array($cs->totals(now()->subYears(10), now())));
|
$cs = new ChartService($this->company);
|
||||||
|
|
||||||
// }
|
$this->assertTrue(is_array($cs->getCurrencyCodes()));
|
||||||
|
|
||||||
// /* coalesces the company currency with the null currencies */
|
$this->assertTrue(in_array("GBP", $cs->getCurrencyCodes()));
|
||||||
// public function testFindNullValueinArray()
|
$this->assertTrue(in_array("USD", $cs->getCurrencyCodes()));
|
||||||
// {
|
$this->assertFalse(in_array("AUD", $cs->getCurrencyCodes()));
|
||||||
|
}
|
||||||
|
|
||||||
// $haystack = [
|
public function testClientServiceDataSetBuild()
|
||||||
// [
|
{
|
||||||
// 'currency_id' => null,
|
|
||||||
// 'amount' => 10
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'currency_id' => 1,
|
|
||||||
// 'amount' => 11
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'currency_id' => 2,
|
|
||||||
// 'amount' => 12
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'currency_id' => 3,
|
|
||||||
// 'amount' => 13
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $company_currency_id = 1;
|
$haystack = [
|
||||||
|
[
|
||||||
|
'currency_id' => null,
|
||||||
|
'amount' => 10
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'amount' => 11
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 2,
|
||||||
|
'amount' => 12
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 3,
|
||||||
|
'amount' => 13
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// $c_key = array_search($company_currency_id , array_column($haystack, 'currency_id'));
|
$cs = new ChartService($this->company);
|
||||||
|
|
||||||
// $this->assertNotEquals($c_key, 2);
|
nlog($cs->totals(now()->subYears(10), now()));
|
||||||
// $this->assertEquals($c_key, 1);
|
|
||||||
|
|
||||||
// $key = array_search(null , array_column($haystack, 'currency_id'));
|
$this->assertTrue(is_array($cs->totals(now()->subYears(10), now())));
|
||||||
|
|
||||||
// $this->assertNotEquals($key, 39);
|
}
|
||||||
// $this->assertEquals($key, 0);
|
|
||||||
|
|
||||||
// $null_currency_amount = $haystack[$key]['amount'];
|
/* coalesces the company currency with the null currencies */
|
||||||
|
public function testFindNullValueinArray()
|
||||||
|
{
|
||||||
|
|
||||||
// unset($haystack[$key]);
|
$haystack = [
|
||||||
|
[
|
||||||
|
'currency_id' => null,
|
||||||
|
'amount' => 10
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'amount' => 11
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 2,
|
||||||
|
'amount' => 12
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 3,
|
||||||
|
'amount' => 13
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// $haystack[$c_key]['amount'] += $null_currency_amount;
|
$company_currency_id = 1;
|
||||||
|
|
||||||
// $this->assertEquals($haystack[$c_key]['amount'], 21);
|
$c_key = array_search($company_currency_id , array_column($haystack, 'currency_id'));
|
||||||
|
|
||||||
// }
|
$this->assertNotEquals($c_key, 2);
|
||||||
|
$this->assertEquals($c_key, 1);
|
||||||
|
|
||||||
|
$key = array_search(null , array_column($haystack, 'currency_id'));
|
||||||
|
|
||||||
|
$this->assertNotEquals($key, 39);
|
||||||
|
$this->assertEquals($key, 0);
|
||||||
|
|
||||||
|
$null_currency_amount = $haystack[$key]['amount'];
|
||||||
|
|
||||||
|
unset($haystack[$key]);
|
||||||
|
|
||||||
|
$haystack[$c_key]['amount'] += $null_currency_amount;
|
||||||
|
|
||||||
|
$this->assertEquals($haystack[$c_key]['amount'], 21);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testCollectionMerging()
|
public function testCollectionMerging()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user