mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Filter dashboard expenses by first month of year setting
This commit is contained in:
parent
ecc6cc0b7a
commit
44eb7d52f9
@ -38,7 +38,7 @@ class DashboardController extends BaseController
|
||||
$pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll);
|
||||
$upcoming = $dashboardRepo->upcoming($accountId, $userId, $viewAll);
|
||||
$payments = $dashboardRepo->payments($accountId, $userId, $viewAll);
|
||||
$expenses = $dashboardRepo->expenses($accountId, $userId, $viewAll);
|
||||
$expenses = $dashboardRepo->expenses($account, $userId, $viewAll);
|
||||
$tasks = $dashboardRepo->tasks($accountId, $userId, $viewAll);
|
||||
|
||||
$showBlueVinePromo = $user->is_admin
|
||||
|
@ -1663,6 +1663,10 @@ class Account extends Eloquent
|
||||
|
||||
public function financialYearStart()
|
||||
{
|
||||
if (! $this->financial_year_start) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$yearStart = Carbon::parse($this->financial_year_start);
|
||||
$yearStart->year = date('Y');
|
||||
|
||||
|
@ -211,8 +211,8 @@ class DashboardRepository
|
||||
|
||||
if ($startDate) {
|
||||
$paidToDate->where('payments.payment_date', '>=', $startDate);
|
||||
} elseif ($account->financial_year_start) {
|
||||
$paidToDate->where('payments.payment_date', '>=', $account->financialYearStart());
|
||||
} elseif ($startDate = $account->financialYearStart()) {
|
||||
$paidToDate->where('payments.payment_date', '>=', $startDate);
|
||||
}
|
||||
|
||||
return $paidToDate->groupBy('payments.account_id')
|
||||
@ -242,8 +242,8 @@ class DashboardRepository
|
||||
$averageInvoice->where('invoices.user_id', '=', $userId);
|
||||
}
|
||||
|
||||
if ($account->financial_year_start) {
|
||||
$averageInvoice->where('invoices.invoice_date', '>=', $account->financialYearStart());
|
||||
if ($startDate = $account->financialYearStart()) {
|
||||
$averageInvoice->where('invoices.invoice_date', '>=', $startDate);
|
||||
}
|
||||
|
||||
return $averageInvoice->groupBy('accounts.id')
|
||||
@ -365,7 +365,7 @@ class DashboardRepository
|
||||
->get();
|
||||
}
|
||||
|
||||
public function expenses($accountId, $userId, $viewAll)
|
||||
public function expenses($account, $userId, $viewAll)
|
||||
{
|
||||
$amountField = DB::getQueryGrammar()->wrap('expenses.amount', true);
|
||||
$taxRate1Field = DB::getQueryGrammar()->wrap('expenses.tax_rate1', true);
|
||||
@ -375,17 +375,21 @@ class DashboardRepository
|
||||
"SUM({$amountField} + ({$amountField} * {$taxRate1Field} / 100) + ({$amountField} * {$taxRate2Field} / 100)) as value,"
|
||||
.DB::getQueryGrammar()->wrap('expenses.expense_currency_id', true).' as currency_id'
|
||||
);
|
||||
$paidToDate = DB::table('accounts')
|
||||
$expenses = DB::table('accounts')
|
||||
->select($select)
|
||||
->leftJoin('expenses', 'accounts.id', '=', 'expenses.account_id')
|
||||
->where('accounts.id', '=', $accountId)
|
||||
->where('accounts.id', '=', $account->id)
|
||||
->where('expenses.is_deleted', '=', false);
|
||||
|
||||
if (! $viewAll) {
|
||||
$paidToDate = $paidToDate->where('expenses.user_id', '=', $userId);
|
||||
$expenses = $expenses->where('expenses.user_id', '=', $userId);
|
||||
}
|
||||
|
||||
return $paidToDate->groupBy('accounts.id')
|
||||
if ($startDate = $account->financialYearStart()) {
|
||||
$expenses->where('expenses.expense_date', '>=', $startDate);
|
||||
}
|
||||
|
||||
return $expenses->groupBy('accounts.id')
|
||||
->groupBy('expenses.expense_currency_id')
|
||||
->get();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user