added last week orders to home

pull/44/head
A1Gard 4 months ago
parent e8993dcd81
commit d879825606

@ -3,6 +3,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\TDate; use App\Helpers\TDate;
use App\Models\Invoice;
use App\Models\Order;
use App\Models\Visitor; use App\Models\Visitor;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -28,6 +30,8 @@ class HomeController extends Controller
public function index() public function index()
{ {
// make visit date
$visits = Visitor::where('created_at', '>=', Carbon::now()->subMonth()) $visits = Visitor::where('created_at', '>=', Carbon::now()->subMonth())
->groupBy('date') ->groupBy('date')
->orderBy('date', 'DESC') ->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(); $mobiles_count = Visitor::where('created_at', '>=', Carbon::now()->subMonth())->where('is_mobile',1)->count();
$all_visitor = Visitor::where('created_at', '>=', Carbon::now()->subMonth())->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'));
} }
} }

@ -26,6 +26,8 @@ class InvoiceSeeder extends Seeder
$order->price_total = rand(100,2000).'000'; $order->price_total = rand(100,2000).'000';
$total = $order->price_total ; $total = $order->price_total ;
$order->invoice_id = $it->id; $order->invoice_id = $it->id;
$order->created_at = $it->created_at;
$order->updated_at = $it->updated_at;
$order->save(); $order->save();
} }
$it->total_price = $total; $it->total_price = $total;

@ -236,7 +236,7 @@ a.btn,a.action-btn,a.circle-btn{
i{ i{
font-size: 100px; font-size: 100px;
} }
a{ a,a:visited{
color: white; color: white;
} }
} }

@ -200,6 +200,7 @@
} }
} }
}); });
let ctx2 = document.getElementById('visitor-device').getContext('2d'); let ctx2 = document.getElementById('visitor-device').getContext('2d');
// document.getElementById('visitor-chart').setAttribute('width', document.querySelector('#visitor-container').clientWidth - 45); // document.getElementById('visitor-chart').setAttribute('width', document.querySelector('#visitor-container').clientWidth - 45);
window.dchart = new window.chartjs(ctx2, { 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')); window.dispatchEvent(new Event('resize'));
}); });

Loading…
Cancel
Save