- Add RoleEnum::MANAGER case - Add OrderStatusEnum with all statuses and getLabel() method - Fix HomeController::index() to pass all required view variables Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$summaryPrice = DB::table('auto_orders')
|
|
->whereNotNull('cost')
|
|
->sum('cost')
|
|
+ DB::table('estate_orders')
|
|
->whereNotNull('cost')
|
|
->sum('cost');
|
|
|
|
$autoOrders = DB::table('auto_orders')->count();
|
|
$estateOrders = DB::table('estate_orders')->count();
|
|
|
|
$recentOrders = collect(
|
|
DB::table('auto_orders')->latest()->limit(5)->get()->map(fn($o) => (object)array_merge((array)$o, ['type' => 'auto_']))
|
|
)->merge(
|
|
DB::table('estate_orders')->latest()->limit(5)->get()->map(fn($o) => (object)array_merge((array)$o, ['type' => 'estate_']))
|
|
)->sortByDesc('created_at')->take(10)->values();
|
|
|
|
$forModerate = collect(
|
|
DB::table('auto_orders')->where('status', 'moderated')->latest()->limit(10)->get()->map(fn($o) => (object)array_merge((array)$o, ['type' => 'auto_']))
|
|
)->merge(
|
|
DB::table('estate_orders')->where('status', 'moderated')->latest()->limit(10)->get()->map(fn($o) => (object)array_merge((array)$o, ['type' => 'estate_']))
|
|
)->sortByDesc('updated_at')->take(10)->values();
|
|
|
|
$actions = DB::table('tracking_actions')->latest()->limit(20)->get();
|
|
|
|
$appraiserChart = [[], []];
|
|
$appraisers = DB::table('users')->where('role', 'appraiser')->get();
|
|
foreach ($appraisers as $appraiser) {
|
|
$appraiserChart[0][] = $appraiser->name;
|
|
$count = DB::table('auto_orders')->where('appraiser_id', $appraiser->id)->count()
|
|
+ DB::table('estate_orders')->where('appraiser_id', $appraiser->id)->count();
|
|
$appraiserChart[1][] = $count;
|
|
}
|
|
|
|
return view('index', compact(
|
|
'summaryPrice',
|
|
'autoOrders',
|
|
'estateOrders',
|
|
'recentOrders',
|
|
'forModerate',
|
|
'actions',
|
|
'appraiserChart'
|
|
));
|
|
}
|
|
|
|
public function lang($locale)
|
|
{
|
|
session()->put('locale', $locale);
|
|
return redirect()->back();
|
|
}
|
|
|
|
public function pages($any = null)
|
|
{
|
|
return view('pages.index');
|
|
}
|
|
}
|