diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 6efea09..4eb084c 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers; use App\Helpers\TDate; +use App\Models\Invoice; +use App\Models\Order; use App\Models\Visitor; use Carbon\Carbon; use Illuminate\Http\Request; @@ -28,6 +30,8 @@ class HomeController extends Controller public function index() { + + // make visit date $visits = Visitor::where('created_at', '>=', Carbon::now()->subMonth()) ->groupBy('date') ->orderBy('date', 'DESC') @@ -47,8 +51,43 @@ class HomeController extends Controller } }); + + + // make device data $mobiles_count = Visitor::where('created_at', '>=', Carbon::now()->subMonth())->where('is_mobile',1)->count(); $all_visitor = Visitor::where('created_at', '>=', Carbon::now()->subMonth())->count(); - return view('home',compact('dates','visits','all_visitor','mobiles_count')); + + + // make order data + + $invoices = Invoice::where('created_at', '>=', Carbon::now()->subWeek()) + ->groupBy('date') + ->orderBy('date', 'DESC') + ->get(array( + DB::raw('Date(created_at) as date'), + DB::raw('COUNT(*) as "count"'), + ))->pluck('count')->toArray(); + $orders = Order::where('created_at', '>=', Carbon::now()->subWeek()) + ->groupBy('date') + ->orderBy('date', 'DESC') + ->get(array( + DB::raw('Date(created_at) as date'), + DB::raw('SUM(count) as "count"'), + ))->pluck('count')->toArray(); + + $week = range((count($invoices) - 1) * -1, 0); + + array_walk($week, function (&$item, $key) use ($dt) { + $x = strtotime($item . ' days'); + if (config('app.locale') == 'fa') { + $item = $dt->PDate('Y/m/d', $x); + } else { + $item = date('Y-m-d', $x); + } + }); + + + return view('home',compact('dates', 'visits', + 'all_visitor','mobiles_count','week','invoices','orders')); } } diff --git a/database/seeders/InvoiceSeeder.php b/database/seeders/InvoiceSeeder.php index cd50c67..b0749f5 100644 --- a/database/seeders/InvoiceSeeder.php +++ b/database/seeders/InvoiceSeeder.php @@ -26,6 +26,8 @@ class InvoiceSeeder extends Seeder $order->price_total = rand(100,2000).'000'; $total = $order->price_total ; $order->invoice_id = $it->id; + $order->created_at = $it->created_at; + $order->updated_at = $it->updated_at; $order->save(); } $it->total_price = $total; diff --git a/resources/sass/panel/_common.scss b/resources/sass/panel/_common.scss index be6cd57..806b0c2 100644 --- a/resources/sass/panel/_common.scss +++ b/resources/sass/panel/_common.scss @@ -236,7 +236,7 @@ a.btn,a.action-btn,a.circle-btn{ i{ font-size: 100px; } - a{ + a,a:visited{ color: white; } } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index c948511..84e45ef 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -200,6 +200,7 @@ } } }); + let ctx2 = document.getElementById('visitor-device').getContext('2d'); // document.getElementById('visitor-chart').setAttribute('width', document.querySelector('#visitor-container').clientWidth - 45); window.dchart = new window.chartjs(ctx2, { @@ -240,6 +241,51 @@ } }); + let ctx3 = document.getElementById('orders-chart').getContext('2d'); + // document.getElementById('visitor-chart').setAttribute('width', document.querySelector('#visitor-container').clientWidth - 45); + window.dchart = new window.chartjs(ctx3, { + // The type of chart we want to create + type: 'bar', // also try bar or other graph types + + // The data for our dataset + data: { + labels: @json($week), + datasets: [ + { + label: "{{__('Orders')}}", + backgroundColor: 'rgba(128,0,255,0.4)', + borderColor: 'rgba(140,0,255,0.6)', + data: @json($orders), + fill: true, + }, + { + label: "{{__('Invoices')}}", + backgroundColor: 'rgba(255,0,0,0.4)', + borderColor: '#ff000099', + data: @json($invoices), + fill: true, + }, + ] + }, + + // Configuration options + options: { + maintainAspectRatio: false, + resizeDelay: 1000, + // aspectRatio: 6, + layout: { + padding: 10 + }, + legend: { + position: 'bottom', + }, + title: { + display: true, + text: 'Visitor device' + } + } + }); + window.dispatchEvent(new Event('resize')); });