Fixes for chart queries

This commit is contained in:
David Bomba 2023-05-16 17:50:05 +10:00
parent 9668f6ceb7
commit a66c9cc046
2 changed files with 7 additions and 17 deletions

View File

@ -35,12 +35,8 @@ class ChartService
$currencies = Client::withTrashed()
->where('company_id', $this->company->id)
->where('is_deleted', 0)
->distinct();
if(!$this->is_admin)
$currencies->where('user_id', $this->user->id);
$currencies->pluck('settings->currency_id as id');
->distinct()
->pluck('settings->currency_id as id');
/* Push the company currency on also */
$currencies->push((int) $this->company->settings->currency_id);
@ -49,14 +45,8 @@ class ChartService
$expense_currencies = Expense::withTrashed()
->where('company_id', $this->company->id)
->where('is_deleted', 0)
->distinct();
if (!$this->is_admin) {
$expense_currencies->where('user_id', $this->user->id);
}
$expense_currencies->pluck('currency_id as id');
->distinct()
->pluck('currency_id as id');
/* Merge and filter by unique */
$currencies = $currencies->merge($expense_currencies)->unique();

View File

@ -50,7 +50,7 @@ class ChartCurrencyTest extends TestCase
$this->assertDatabaseHas('invoices', ['number' => 'db_record']);
$cs = new ChartService($this->company);
$cs = new ChartService($this->company, $this->user, true);
// nlog($cs->getRevenueQuery(now()->subDays(20)->format('Y-m-d'), now()->addDays(100)->format('Y-m-d')));
$data = [
@ -86,7 +86,7 @@ class ChartCurrencyTest extends TestCase
'settings' => $settings,
]);
$cs = new ChartService($this->company);
$cs = new ChartService($this->company, $this->user, true);
$this->assertTrue(is_array($cs->getCurrencyCodes()));
@ -131,7 +131,7 @@ class ChartCurrencyTest extends TestCase
],
];
$cs = new ChartService($this->company);
$cs = new ChartService($this->company, $this->user, true);
// nlog($cs->totals(now()->subYears(10), now()));