Update Dashboard.php

This commit is contained in:
sausin 2018-12-14 11:20:28 +05:30 committed by GitHub
parent 0279dc1796
commit 1eeee80fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ use App\Models\Income\Invoice;
use App\Models\Income\InvoicePayment;
use App\Models\Income\Revenue;
use App\Models\Setting\Category;
use App\Models\Setting\Setting;
use App\Traits\Currencies;
use Charts;
use Date;
@ -20,6 +21,9 @@ class Dashboard extends Controller
use Currencies;
public $today;
// get any custom financial year beginning
public $financial_start;
public $income_donut = ['colors' => [], 'labels' => [], 'values' => []];
@ -33,6 +37,7 @@ class Dashboard extends Controller
public function index()
{
$this->today = Date::today();
$this->financial_start = $financial_start = Date::parse(Setting::where('key', 'general.financial_start')->first()->value)->format('Y-m-d');
list($total_incomes, $total_expenses, $total_profit) = $this->getTotals();
@ -55,7 +60,8 @@ class Dashboard extends Controller
'donut_expenses',
'accounts',
'latest_incomes',
'latest_expenses'
'latest_expenses',
'financial_start'
));
}
@ -123,8 +129,13 @@ class Dashboard extends Controller
private function getCashFlow()
{
$start = Date::parse(request('start', $this->today->startOfYear()->format('Y-m-d')));
$end = Date::parse(request('end', $this->today->endOfYear()->format('Y-m-d')));
// check and assign year start
if (($year_start = $this->today->startOfYear()->format('Y-m-d')) !== $this->financial_start) {
$year_start = $this->financial_start;
}
$start = Date::parse(request('start', $year_start));
$end = Date::parse(request('end', Date::parse($year_start)->addYear(1)->subDays(1)->format('Y-m-d')));
$period = request('period', 'month');
$range = request('range', 'custom');