Update Dashboard.php
This commit is contained in:
		| @@ -11,6 +11,7 @@ use App\Models\Income\Invoice; | |||||||
| use App\Models\Income\InvoicePayment; | use App\Models\Income\InvoicePayment; | ||||||
| use App\Models\Income\Revenue; | use App\Models\Income\Revenue; | ||||||
| use App\Models\Setting\Category; | use App\Models\Setting\Category; | ||||||
|  | use App\Models\Setting\Setting; | ||||||
| use App\Traits\Currencies; | use App\Traits\Currencies; | ||||||
| use Charts; | use Charts; | ||||||
| use Date; | use Date; | ||||||
| @@ -20,6 +21,9 @@ class Dashboard extends Controller | |||||||
|     use Currencies; |     use Currencies; | ||||||
|  |  | ||||||
|     public $today; |     public $today; | ||||||
|  |      | ||||||
|  |     // get any custom financial year beginning | ||||||
|  |     public $financial_start; | ||||||
|  |  | ||||||
|     public $income_donut = ['colors' => [], 'labels' => [], 'values' => []]; |     public $income_donut = ['colors' => [], 'labels' => [], 'values' => []]; | ||||||
|  |  | ||||||
| @@ -33,6 +37,7 @@ class Dashboard extends Controller | |||||||
|     public function index() |     public function index() | ||||||
|     { |     { | ||||||
|         $this->today = Date::today(); |         $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(); |         list($total_incomes, $total_expenses, $total_profit) = $this->getTotals(); | ||||||
|  |  | ||||||
| @@ -55,7 +60,8 @@ class Dashboard extends Controller | |||||||
|             'donut_expenses', |             'donut_expenses', | ||||||
|             'accounts', |             'accounts', | ||||||
|             'latest_incomes', |             'latest_incomes', | ||||||
|             'latest_expenses' |             'latest_expenses', | ||||||
|  |             'financial_start' | ||||||
|         )); |         )); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -123,8 +129,13 @@ class Dashboard extends Controller | |||||||
|  |  | ||||||
|     private function getCashFlow() |     private function getCashFlow() | ||||||
|     { |     { | ||||||
|         $start = Date::parse(request('start', $this->today->startOfYear()->format('Y-m-d'))); |         // check and assign year start | ||||||
|         $end = Date::parse(request('end', $this->today->endOfYear()->format('Y-m-d'))); |         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'); |         $period = request('period', 'month'); | ||||||
|         $range = request('range', 'custom'); |         $range = request('range', 'custom'); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user