@php $humanDiff = function(array $array) { foreach($array as $value) $array[array_search($value, $array)] = \Carbon\Carbon::parse($value)->toFormattedDateString(); return $array; }; @endphp
Income
@php $fix = function($n) { return is_float($n) || is_int($n) ? floatval($n) : floatval($n->jsonSerialize()['$numberDecimal']); }; $fill_data_currency = function($days, $currency_id) use($fix) { $out = []; for($i = 0; $i < $days; $i++) array_push($out, $fix(\Illuminate\Support\Facades\DB::table('invoices') ->where('created_at', '>=', \Carbon\Carbon::today()->subDays($i)) ->where('created_at', '<', \Carbon\Carbon::today()->subDays($i - 1)) ->where('currency', $currency_id)->where('status', 1)->sum('sum'))); return array_reverse($out); }; $fill_labels = function($days) { $out = []; for($i = 0; $i < $days; $i++) array_push($out, $i > 0 ? $i .' days ago' : 'Today'); return array_reverse($out); }; $merge = []; foreach (\App\Currency\Currency::all() as $currency) { array_push($merge, [ 'name' => $currency->name(), 'data' => $fill_data_currency(7, $currency->id()) ]); } $chart = new \ArielMejiaDev\LarapexCharts\LarapexChart(); $chart->setTitle('One week')->setType('area')->setHeight(680)->setXAxis($fill_labels(7))->setDataset($merge); @endphp
{{ $chart->script() }}
View
Latest withdraws
@if(\App\Withdraw::where('status', 0)->count() == 0)
Nothing here
@else @foreach(\App\Withdraw::where('status', 0)->latest()->take(5)->get() as $withdraw) @php $user = \App\User::where('_id', $withdraw->user)->first(); if(!$user) continue; @endphp
shreyu
{{ $user->name }}
{{ number_format($withdraw->sum, 8, '.', ' ') }} {{ \App\Currency\Currency::find($withdraw->currency)->name() }}
@endforeach @endif
Countries
@php $data = (array) \Spatie\Analytics\AnalyticsFacade::performQuery(\Spatie\Analytics\Period::days(7), 'ga:sessions', [ 'metrics' => 'ga:sessions', 'dimensions' => 'ga:country' ])['rows']; $labels = []; $dataset = []; foreach ($data as $info) { array_push($labels, $info[0]); array_push($dataset, intval($info[1])); } $chart = new \ArielMejiaDev\LarapexCharts\LarapexChart(); $chart->setType('pie')->setHeight(300)->setLabels($labels)->setDataset($dataset); @endphp
{{ $chart->script() }}