close #1053 Added: Dashboard date filter
This commit is contained in:
parent
237b161fe0
commit
bd0598b4d4
@ -29,6 +29,18 @@ abstract class Widget extends AbstractWidget
|
|||||||
return $this->show();
|
return $this->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function applyFilters($model, $args = ['date_field' => 'paid_at'])
|
||||||
|
{
|
||||||
|
if (empty(request()->get('start_date', null))) {
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
$start_date = request()->get('start_date') . ' 00:00:00';
|
||||||
|
$end_date = request()->get('end_date') . ' 23:59:59';
|
||||||
|
|
||||||
|
return $model->whereBetween($args['date_field'], [$start_date, $end_date]);
|
||||||
|
}
|
||||||
|
|
||||||
public function calculateDocumentTotals($model)
|
public function calculateDocumentTotals($model)
|
||||||
{
|
{
|
||||||
$open = $overdue = 0;
|
$open = $overdue = 0;
|
||||||
|
@ -7,9 +7,12 @@ use App\Abstracts\Http\Controller;
|
|||||||
use App\Models\Common\Dashboard as Model;
|
use App\Models\Common\Dashboard as Model;
|
||||||
use App\Models\Common\DashboardWidget;
|
use App\Models\Common\DashboardWidget;
|
||||||
use App\Http\Requests\Common\Dashboard as Request;
|
use App\Http\Requests\Common\Dashboard as Request;
|
||||||
|
use App\Traits\DateTime;
|
||||||
|
|
||||||
class Dashboard extends Controller
|
class Dashboard extends Controller
|
||||||
{
|
{
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
@ -42,7 +45,9 @@ class Dashboard extends Controller
|
|||||||
->where('user_id', $user_id)
|
->where('user_id', $user_id)
|
||||||
->orderBy('sort', 'asc')->get();
|
->orderBy('sort', 'asc')->get();
|
||||||
|
|
||||||
return view('common.dashboard.index', compact('dashboards','dashboard', 'widgets'));
|
$financial_start = $this->getFinancialStart()->format('Y-m-d');
|
||||||
|
|
||||||
|
return view('common.dashboard.index', compact('dashboards','dashboard', 'widgets', 'financial_start'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +137,7 @@ class CashFlow extends Widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = Transaction::type($type)->whereBetween('paid_at', [$start, $end])->isNotTransfer()->get();
|
$items = $this->applyFilters(Transaction::type($type)->whereBetween('paid_at', [$start, $end])->isNotTransfer())->get();
|
||||||
|
|
||||||
$this->setTotals($totals, $items, $date_format, $period);
|
$this->setTotals($totals, $items, $date_format, $period);
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@ class ExpensesByCategory extends Widget
|
|||||||
Category::with('expense_transactions')->type('expense')->enabled()->each(function ($category) {
|
Category::with('expense_transactions')->type('expense')->enabled()->each(function ($category) {
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
|
||||||
foreach ($category->expense_transactions as $transacion) {
|
$transactions = $this->applyFilters($category->expense_transactions())->get();
|
||||||
|
|
||||||
|
foreach ($transactions as $transacion) {
|
||||||
$amount += $transacion->getAmountConvertedToDefault();
|
$amount += $transacion->getAmountConvertedToDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@ class IncomeByCategory extends Widget
|
|||||||
Category::with('income_transacions')->type('income')->enabled()->each(function ($category) {
|
Category::with('income_transacions')->type('income')->enabled()->each(function ($category) {
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
|
||||||
foreach ($category->income_transacions as $transacion) {
|
$transactions = $this->applyFilters($category->income_transacions())->get();
|
||||||
|
|
||||||
|
foreach ($transactions as $transacion) {
|
||||||
$amount += $transacion->getAmountConvertedToDefault();
|
$amount += $transacion->getAmountConvertedToDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ class LatestExpenses extends Widget
|
|||||||
{
|
{
|
||||||
public function show()
|
public function show()
|
||||||
{
|
{
|
||||||
$transactions = Transaction::with('category')->type('expense')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5)->get();
|
$transactions = $this->applyFilters(Transaction::with('category')->type('expense')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||||
|
|
||||||
return view('widgets.latest_expenses', [
|
return view('widgets.latest_expenses', [
|
||||||
'config' => (object) $this->config,
|
'config' => (object) $this->config,
|
||||||
'transactions' => $transactions,
|
'transactions' => $transactions,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@ class LatestIncome extends Widget
|
|||||||
{
|
{
|
||||||
public function show()
|
public function show()
|
||||||
{
|
{
|
||||||
$transactions = Transaction::with('category')->type('income')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5)->get();
|
$transactions = $this->applyFilters(Transaction::with('category')->type('income')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||||
|
|
||||||
return view('widgets.latest_income', [
|
return view('widgets.latest_income', [
|
||||||
'config' => (object) $this->config,
|
'config' => (object) $this->config,
|
||||||
'transactions' => $transactions,
|
'transactions' => $transactions,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ class TotalExpenses extends Widget
|
|||||||
{
|
{
|
||||||
$current = $open = $overdue = 0;
|
$current = $open = $overdue = 0;
|
||||||
|
|
||||||
Transaction::type('expense')->isNotTransfer()->each(function ($transaction) use (&$current) {
|
$this->applyFilters(Transaction::type('expense')->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||||
$current += $transaction->getAmountConvertedToDefault();
|
$current += $transaction->getAmountConvertedToDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
Bill::accrued()->notPaid()->each(function ($bill) use (&$open, &$overdue) {
|
$this->applyFilters(Bill::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open, &$overdue) {
|
||||||
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
|
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
|
||||||
|
|
||||||
$open += $open_tmp;
|
$open += $open_tmp;
|
||||||
|
@ -12,11 +12,11 @@ class TotalIncome extends Widget
|
|||||||
{
|
{
|
||||||
$current = $open = $overdue = 0;
|
$current = $open = $overdue = 0;
|
||||||
|
|
||||||
Transaction::type('income')->isNotTransfer()->each(function ($transaction) use (&$current) {
|
$this->applyFilters(Transaction::type('income')->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||||
$current += $transaction->getAmountConvertedToDefault();
|
$current += $transaction->getAmountConvertedToDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
Invoice::accrued()->notPaid()->each(function ($invoice) use (&$open, &$overdue) {
|
$this->applyFilters(Invoice::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open, &$overdue) {
|
||||||
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
|
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
|
||||||
|
|
||||||
$open += $open_tmp;
|
$open += $open_tmp;
|
||||||
|
@ -14,7 +14,7 @@ class TotalProfit extends Widget
|
|||||||
$current_income = $open_invoice = $overdue_invoice = 0;
|
$current_income = $open_invoice = $overdue_invoice = 0;
|
||||||
$current_expenses = $open_bill = $overdue_bill = 0;
|
$current_expenses = $open_bill = $overdue_bill = 0;
|
||||||
|
|
||||||
Transaction::isNotTransfer()->each(function ($transaction) use (&$current_income, &$current_expenses) {
|
$this->applyFilters(Transaction::isNotTransfer())->each(function ($transaction) use (&$current_income, &$current_expenses) {
|
||||||
$amount = $transaction->getAmountConvertedToDefault();
|
$amount = $transaction->getAmountConvertedToDefault();
|
||||||
|
|
||||||
if ($transaction->type == 'income') {
|
if ($transaction->type == 'income') {
|
||||||
@ -24,14 +24,14 @@ class TotalProfit extends Widget
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Invoice::accrued()->notPaid()->each(function ($invoice) use (&$open_invoice, &$overdue_invoice) {
|
$this->applyFilters(Invoice::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open_invoice, &$overdue_invoice) {
|
||||||
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
|
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
|
||||||
|
|
||||||
$open_invoice += $open_tmp;
|
$open_invoice += $open_tmp;
|
||||||
$overdue_invoice += $overdue_tmp;
|
$overdue_invoice += $overdue_tmp;
|
||||||
});
|
});
|
||||||
|
|
||||||
Bill::accrued()->notPaid()->each(function ($bill) use (&$open_bill, &$overdue_bill) {
|
$this->applyFilters(Bill::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open_bill, &$overdue_bill) {
|
||||||
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
|
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
|
||||||
|
|
||||||
$open_bill += $open_tmp;
|
$open_bill += $open_tmp;
|
||||||
|
18
resources/assets/js/plugins/functions.js
vendored
Normal file
18
resources/assets/js/plugins/functions.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Get Url Paramater
|
||||||
|
function getQueryVariable(variable) {
|
||||||
|
var query = window.location.search.substring(1);
|
||||||
|
|
||||||
|
var vars = query.split("&");
|
||||||
|
|
||||||
|
for (var i = 0; i < vars.length; i++) {
|
||||||
|
var pair = vars[i].split("=");
|
||||||
|
|
||||||
|
if (pair[0] == variable) {
|
||||||
|
return pair[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {getQueryVariable}
|
47
resources/assets/js/views/common/dashboard.js
vendored
47
resources/assets/js/views/common/dashboard.js
vendored
@ -9,6 +9,7 @@ require('./../../bootstrap');
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
import Global from './../../mixins/global';
|
import Global from './../../mixins/global';
|
||||||
|
import {getQueryVariable} from './../../plugins/functions';
|
||||||
|
|
||||||
import AkauntingDashboard from './../../components/AkauntingDashboard';
|
import AkauntingDashboard from './../../components/AkauntingDashboard';
|
||||||
import AkauntingWidget from './../../components/AkauntingWidget';
|
import AkauntingWidget from './../../components/AkauntingWidget';
|
||||||
@ -49,38 +50,20 @@ const dashboard = new Vue({
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
widget_id: 0
|
widget_id: 0
|
||||||
},
|
},
|
||||||
pickerOptions: {
|
filter_date: [],
|
||||||
shortcuts: [{
|
|
||||||
text: 'Last week',
|
|
||||||
onClick(picker) {
|
|
||||||
const end = new Date();
|
|
||||||
const start = new Date();
|
|
||||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
|
|
||||||
picker.$emit('pick', [start, end]);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: 'Last month',
|
|
||||||
onClick(picker) {
|
|
||||||
const end = new Date();
|
|
||||||
const start = new Date();
|
|
||||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
|
|
||||||
picker.$emit('pick', [start, end]);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: 'Last 3 months',
|
|
||||||
onClick(picker) {
|
|
||||||
const end = new Date();
|
|
||||||
const start = new Date();
|
|
||||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
|
|
||||||
picker.$emit('pick', [start, end]);
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
value2: ''
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
let start_date = getQueryVariable('start_date');
|
||||||
|
|
||||||
|
if (start_date) {
|
||||||
|
let end_date = getQueryVariable('end_date');
|
||||||
|
|
||||||
|
this.filter_date.push(start_date);
|
||||||
|
this.filter_date.push(end_date);
|
||||||
|
}
|
||||||
|
|
||||||
this.getWidgets();
|
this.getWidgets();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -166,5 +149,13 @@ const dashboard = new Vue({
|
|||||||
this.widget.sort = 0;
|
this.widget.sort = 0;
|
||||||
this.widget.widget_id = 0;
|
this.widget.widget_id = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onChangeFilterDate() {
|
||||||
|
if (this.filter_date) {
|
||||||
|
window.location.href = url + '?start_date=' + this.filter_date[0] + '&end_date=' + this.filter_date[1];
|
||||||
|
} else {
|
||||||
|
window.location.href = url;
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -134,6 +134,7 @@ return [
|
|||||||
'difference' => 'Difference',
|
'difference' => 'Difference',
|
||||||
'footer' => 'Footer',
|
'footer' => 'Footer',
|
||||||
'start_date' => 'Start Date',
|
'start_date' => 'Start Date',
|
||||||
|
'end_date' => 'End Date',
|
||||||
'basis' => 'Basis',
|
'basis' => 'Basis',
|
||||||
'accrual' => 'Accrual',
|
'accrual' => 'Accrual',
|
||||||
'cash' => 'Cash',
|
'cash' => 'Cash',
|
||||||
|
@ -92,19 +92,84 @@
|
|||||||
|
|
||||||
@section('new_button')
|
@section('new_button')
|
||||||
<!--Dashboard General Filter-->
|
<!--Dashboard General Filter-->
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="value2"
|
v-model="filter_date"
|
||||||
type="daterange"
|
type="daterange"
|
||||||
align="right"
|
align="right"
|
||||||
unlink-panels
|
unlink-panels
|
||||||
:class="datepicker"
|
:format="'yyyy-MM-dd'"
|
||||||
:format="'yyyy-MM-dd'"
|
value-format="yyyy-MM-dd"
|
||||||
:default-time="['00:00:00', '23:59:59']"
|
@change="onChangeFilterDate"
|
||||||
range-separator="To"
|
range-separator="{{ trans('general.to')}}"
|
||||||
start-placeholder="Start date"
|
start-placeholder="{{ trans('general.start_date')}}"
|
||||||
end-placeholder="End date"
|
end-placeholder="{{ trans('general.end_date')}}"
|
||||||
:picker-options="pickerOptions">
|
:picker-options="{
|
||||||
</el-date-picker>
|
shortcuts: [
|
||||||
|
{
|
||||||
|
text: '{{ trans("reports.this_year") }}',
|
||||||
|
onClick(picker) {
|
||||||
|
const end = new Date('{{ $financial_start }}');
|
||||||
|
const start = new Date('{{ $financial_start }}');
|
||||||
|
|
||||||
|
end.setFullYear(start.getFullYear() + 1);
|
||||||
|
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
|
||||||
|
|
||||||
|
picker.$emit('pick', [start, end]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '{{ trans("reports.previous_year") }}',
|
||||||
|
onClick(picker) {
|
||||||
|
const end = new Date('{{ $financial_start }}');
|
||||||
|
const start = new Date('{{ $financial_start }}');
|
||||||
|
|
||||||
|
start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
|
||||||
|
|
||||||
|
end.setFullYear(start.getFullYear() + 1);
|
||||||
|
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
|
||||||
|
|
||||||
|
picker.$emit('pick', [start, end]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '{{ trans("reports.this_quarter") }}',
|
||||||
|
onClick(picker) {
|
||||||
|
const now = new Date();
|
||||||
|
const quarter = Math.floor((now.getMonth() / 3));
|
||||||
|
const start = new Date(now.getFullYear(), quarter * 3, 1);
|
||||||
|
const end = new Date(start.getFullYear(), start.getMonth() + 3, 0);
|
||||||
|
|
||||||
|
picker.$emit('pick', [start, end]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '{{ trans("reports.previous_quarter") }}',
|
||||||
|
onClick(picker) {
|
||||||
|
const now = new Date();
|
||||||
|
const quarter = Math.floor((now.getMonth() / 3));
|
||||||
|
const start = new Date(now.getFullYear(), quarter * 3, 1);
|
||||||
|
const end = new Date(start.getFullYear(), start.getMonth() + 3, 0);
|
||||||
|
|
||||||
|
start.setMonth(start.getMonth() - 3);
|
||||||
|
end.setMonth(end.getMonth() - 3);
|
||||||
|
|
||||||
|
picker.$emit('pick', [start, end]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '{{ trans("reports.last_12_months") }}',
|
||||||
|
onClick(picker) {
|
||||||
|
const end = new Date();
|
||||||
|
const start = new Date();
|
||||||
|
|
||||||
|
start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
|
||||||
|
|
||||||
|
picker.$emit('pick', [start, end]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}">
|
||||||
|
</el-date-picker>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user