mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 14:34:44 -04:00
Updates for chart permissions
This commit is contained in:
parent
a35934f7b1
commit
4767c1a14a
@ -13,8 +13,6 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Http\Requests\Chart\ShowChartRequest;
|
use App\Http\Requests\Chart\ShowChartRequest;
|
||||||
use App\Services\Chart\ChartService;
|
use App\Services\Chart\ChartService;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
class ChartController extends BaseController
|
class ChartController extends BaseController
|
||||||
{
|
{
|
||||||
@ -67,14 +65,19 @@ class ChartController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function totals(ShowChartRequest $request)
|
public function totals(ShowChartRequest $request)
|
||||||
{
|
{
|
||||||
$cs = new ChartService(auth()->user()->company());
|
/** @var \App\Models\User auth()->user() */
|
||||||
|
$user = auth()->user();
|
||||||
|
$cs = new ChartService($user->company(), $user, $user->isAdmin());
|
||||||
|
|
||||||
return response()->json($cs->totals($request->input('start_date'), $request->input('end_date')), 200);
|
return response()->json($cs->totals($request->input('start_date'), $request->input('end_date')), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function chart_summary(ShowChartRequest $request)
|
public function chart_summary(ShowChartRequest $request)
|
||||||
{
|
{
|
||||||
$cs = new ChartService(auth()->user()->company());
|
|
||||||
|
/** @var \App\Models\User auth()->user() */
|
||||||
|
$user = auth()->user();
|
||||||
|
$cs = new ChartService($user->company(), $user, $user->isAdmin());
|
||||||
|
|
||||||
return response()->json($cs->chart_summary($request->input('start_date'), $request->input('end_date')), 200);
|
return response()->json($cs->chart_summary($request->input('start_date'), $request->input('end_date')), 200);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Services\Chart;
|
namespace App\Services\Chart;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
@ -20,11 +21,8 @@ class ChartService
|
|||||||
{
|
{
|
||||||
use ChartQueries;
|
use ChartQueries;
|
||||||
|
|
||||||
public Company $company;
|
public function __construct(public Company $company, private User $user, private bool $is_admin)
|
||||||
|
|
||||||
public function __construct(Company $company)
|
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,8 +35,12 @@ class ChartService
|
|||||||
$currencies = Client::withTrashed()
|
$currencies = Client::withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->distinct()
|
->distinct();
|
||||||
->pluck('settings->currency_id as id');
|
|
||||||
|
if(!$this->is_admin)
|
||||||
|
$currencies->where('user_id', $this->user->id);
|
||||||
|
|
||||||
|
$currencies->pluck('settings->currency_id as id');
|
||||||
|
|
||||||
/* Push the company currency on also */
|
/* Push the company currency on also */
|
||||||
$currencies->push((int) $this->company->settings->currency_id);
|
$currencies->push((int) $this->company->settings->currency_id);
|
||||||
@ -47,8 +49,14 @@ class ChartService
|
|||||||
$expense_currencies = Expense::withTrashed()
|
$expense_currencies = Expense::withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->distinct()
|
->distinct();
|
||||||
->pluck('currency_id as id');
|
|
||||||
|
|
||||||
|
if (!$this->is_admin) {
|
||||||
|
$expense_currencies->where('user_id', $this->user->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expense_currencies->pluck('currency_id as id');
|
||||||
|
|
||||||
/* Merge and filter by unique */
|
/* Merge and filter by unique */
|
||||||
$currencies = $currencies->merge($expense_currencies)->unique();
|
$currencies = $currencies->merge($expense_currencies)->unique();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user