akaunting 3.0 (the last dance)
This commit is contained in:
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Portal;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Charts;
|
||||
use App\Traits\DateTime;
|
||||
use App\Utilities\Chartjs;
|
||||
use Date;
|
||||
|
||||
class Dashboard
|
||||
@ -38,82 +37,10 @@ class Dashboard
|
||||
|
||||
//$invoices = Document::invoice()->accrued()->where('contact_id', $contact->id)->get();
|
||||
$invoices = Document::invoice()->accrued()->whereBetween('due_at', [$start, $end])->where('contact_id', $contact->id)->get();
|
||||
|
||||
$start_month = $start->month;
|
||||
$end_month = $end->month;
|
||||
|
||||
// look cashFlow widget
|
||||
$end_month = $end->diffInMonths($start);
|
||||
$start_month = 0;
|
||||
// Monthly
|
||||
$labels = [];
|
||||
|
||||
$s = clone $start;
|
||||
|
||||
for ($j = $end_month; $j >= $start_month; $j--) {
|
||||
$labels[$end_month - $j] = $s->format('M Y');
|
||||
|
||||
$s->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$amounts = $this->calculateAmounts($invoices, $start, $end);
|
||||
|
||||
$grand = array_sum($amounts['unpaid']) + array_sum($amounts['paid']) + array_sum($amounts['overdue']);
|
||||
|
||||
$totals = [
|
||||
'paid' => money(array_sum($amounts['paid']), setting('default.currency'), true),
|
||||
'unpaid' => money(array_sum($amounts['unpaid']), setting('default.currency'), true),
|
||||
'overdue' => money(array_sum($amounts['overdue']), setting('default.currency'), true),
|
||||
];
|
||||
|
||||
$progress = [
|
||||
'paid' => !empty($grand) ? (100 / $grand) * array_sum($amounts['paid']) : '0',
|
||||
'unpaid' => !empty($grand) ? (100 / $grand) * array_sum($amounts['unpaid']) : '0',
|
||||
'overdue' => !empty($grand) ? (100 / $grand) * array_sum($amounts['overdue']) : '0',
|
||||
];
|
||||
|
||||
$chart = new Chartjs();
|
||||
$chart->type('line')
|
||||
->width(0)
|
||||
->height(300)
|
||||
->options($this->getLineChartOptions())
|
||||
->labels(array_values($labels));
|
||||
|
||||
$chart->dataset(trans('general.paid'), 'line', array_values($amounts['paid']))
|
||||
->backgroundColor('#6da252')
|
||||
->color('#6da252')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$chart->dataset(trans('general.unpaid'), 'line', array_values($amounts['unpaid']))
|
||||
->backgroundColor('#efad32')
|
||||
->color('#efad32')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$chart->dataset(trans('general.overdue'), 'line', array_values($amounts['overdue']))
|
||||
->backgroundColor('#ef3232')
|
||||
->color('#ef3232')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$date_picker_shortcuts = $this->getDatePickerShortcuts();
|
||||
|
||||
if (!request()->has('start_date')) {
|
||||
request()->merge(['start_date' => $date_picker_shortcuts[trans('reports.this_year')]['start']]);
|
||||
request()->merge(['end_date' => $date_picker_shortcuts[trans('reports.this_year')]['end']]);
|
||||
}
|
||||
|
||||
return view('portal.dashboard.index', compact('contact', 'invoices', 'totals', 'progress', 'chart', 'date_picker_shortcuts'));
|
||||
return view('portal.dashboard.index', compact('contact', 'invoices'));
|
||||
}
|
||||
|
||||
private function calculateAmounts($invoices, $start, $end)
|
||||
|
Reference in New Issue
Block a user