mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Include expense currencies in dashboard selector
This commit is contained in:
parent
b6453c932a
commit
d58540f432
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Expense;
|
||||||
use App\Ninja\Repositories\DashboardRepository;
|
use App\Ninja\Repositories\DashboardRepository;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Utils;
|
use Utils;
|
||||||
@ -58,26 +59,6 @@ class DashboardController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the account has multiple curencies
|
|
||||||
$currencyIds = $account->currency_id ? [$account->currency_id] : [DEFAULT_CURRENCY];
|
|
||||||
$data = Client::scope()
|
|
||||||
->withArchived()
|
|
||||||
->distinct()
|
|
||||||
->get(['currency_id'])
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
array_map(function ($item) use (&$currencyIds) {
|
|
||||||
$currencyId = intval($item['currency_id']);
|
|
||||||
if ($currencyId && ! in_array($currencyId, $currencyIds)) {
|
|
||||||
$currencyIds[] = $currencyId;
|
|
||||||
}
|
|
||||||
}, $data);
|
|
||||||
|
|
||||||
$currencies = [];
|
|
||||||
foreach ($currencyIds as $currencyId) {
|
|
||||||
$currencies[$currencyId] = Utils::getFromCache($currencyId, 'currencies')->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'account' => $user->account,
|
'account' => $user->account,
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
@ -93,7 +74,7 @@ class DashboardController extends BaseController
|
|||||||
'title' => trans('texts.dashboard'),
|
'title' => trans('texts.dashboard'),
|
||||||
'hasQuotes' => $hasQuotes,
|
'hasQuotes' => $hasQuotes,
|
||||||
'showBreadcrumbs' => false,
|
'showBreadcrumbs' => false,
|
||||||
'currencies' => $currencies,
|
'currencies' => $this->getCurrencyCodes(),
|
||||||
'expenses' => $expenses,
|
'expenses' => $expenses,
|
||||||
'tasks' => $tasks,
|
'tasks' => $tasks,
|
||||||
'showBlueVinePromo' => $showBlueVinePromo,
|
'showBlueVinePromo' => $showBlueVinePromo,
|
||||||
@ -123,6 +104,47 @@ class DashboardController extends BaseController
|
|||||||
return View::make('dashboard', $data);
|
return View::make('dashboard', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCurrencyCodes()
|
||||||
|
{
|
||||||
|
$account = Auth::user()->account;
|
||||||
|
$currencyIds = $account->currency_id ? [$account->currency_id] : [DEFAULT_CURRENCY];
|
||||||
|
|
||||||
|
// get client/invoice currencies
|
||||||
|
$data = Client::scope()
|
||||||
|
->withArchived()
|
||||||
|
->distinct()
|
||||||
|
->get(['currency_id'])
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
array_map(function ($item) use (&$currencyIds) {
|
||||||
|
$currencyId = intval($item['currency_id']);
|
||||||
|
if ($currencyId && ! in_array($currencyId, $currencyIds)) {
|
||||||
|
$currencyIds[] = $currencyId;
|
||||||
|
}
|
||||||
|
}, $data);
|
||||||
|
|
||||||
|
// get expense currencies
|
||||||
|
$data = Expense::scope()
|
||||||
|
->withArchived()
|
||||||
|
->distinct()
|
||||||
|
->get(['expense_currency_id'])
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
array_map(function ($item) use (&$currencyIds) {
|
||||||
|
$currencyId = intval($item['expense_currency_id']);
|
||||||
|
if ($currencyId && ! in_array($currencyId, $currencyIds)) {
|
||||||
|
$currencyIds[] = $currencyId;
|
||||||
|
}
|
||||||
|
}, $data);
|
||||||
|
|
||||||
|
$currencies = [];
|
||||||
|
foreach ($currencyIds as $currencyId) {
|
||||||
|
$currencies[$currencyId] = Utils::getFromCache($currencyId, 'currencies')->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $currencies;
|
||||||
|
}
|
||||||
|
|
||||||
public function chartData($groupBy, $startDate, $endDate, $currencyCode, $includeExpenses)
|
public function chartData($groupBy, $startDate, $endDate, $currencyCode, $includeExpenses)
|
||||||
{
|
{
|
||||||
$includeExpenses = filter_var($includeExpenses, FILTER_VALIDATE_BOOLEAN);
|
$includeExpenses = filter_var($includeExpenses, FILTER_VALIDATE_BOOLEAN);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user