Skip to content

Commit

Permalink
Update Dashboard.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sausin committed Dec 14, 2018
1 parent 0279dc1 commit 1eeee80
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/Http/Controllers/Common/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand All @@ -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' => []];

Expand All @@ -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();

Expand All @@ -55,7 +60,8 @@ public function index()
'donut_expenses',
'accounts',
'latest_incomes',
'latest_expenses'
'latest_expenses',
'financial_start'
));
}

Expand Down Expand Up @@ -123,8 +129,13 @@ private function getTotals()

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');

Expand Down

0 comments on commit 1eeee80

Please sign in to comment.