Fix DB schema mismatches from backup import
- purpose/concern/region/district tables use uz/ru/cr instead of name - auto_orders/estate_orders use purpose_id not purpose - Add ownerName/owner computed fields from owner_first/last_name - Fix appraiserChart to use order_members instead of appraiser_id - Fix DebitController to join appraiser and order relations - Fix role queries to be case-insensitive (DB has mixed case) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,33 +9,38 @@ class EstateController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$filters = $request->only(['search', 'period', 'status', 'appraiser', 'diller', 'purpose']);
|
||||
$filters = $request->only(['search', 'period', 'status', 'appraiser', 'purpose_id']);
|
||||
$size = $request->get('size', 20);
|
||||
|
||||
$query = DB::table('estate_orders')->selectRaw('*, ordered_customer as customer')->orderByDesc('id');
|
||||
$query = DB::table('estate_orders as o')
|
||||
->selectRaw('o.*, o.ordered_customer as customer, CONCAT_WS(\' \', o.owner_last_name, o.owner_first_name, o.owner_patronymic) as owner')
|
||||
->addSelect([
|
||||
'purpose_uz' => DB::table('purposes')->select('uz')->whereColumn('id', 'o.purpose_id'),
|
||||
'purpose_ru' => DB::table('purposes')->select('ru')->whereColumn('id', 'o.purpose_id'),
|
||||
'purpose_cr' => DB::table('purposes')->select('cr')->whereColumn('id', 'o.purpose_id'),
|
||||
'region_uz' => DB::table('regions')->select('uz')->whereColumn('id', 'o.region'),
|
||||
'district_uz' => DB::table('districts')->select('uz')->whereColumn('id', 'o.district'),
|
||||
])
|
||||
->orderByDesc('o.id');
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$s = '%' . $filters['search'] . '%';
|
||||
$query->where(function ($q) use ($s) {
|
||||
$q->where('number', 'like', $s)
|
||||
->orWhere('ordered_customer', 'like', $s);
|
||||
$q->where('o.number', 'like', $s)->orWhere('o.ordered_customer', 'like', $s);
|
||||
});
|
||||
}
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
if (!empty($filters['purpose'])) {
|
||||
$query->where('purpose', $filters['purpose']);
|
||||
}
|
||||
if (!empty($filters['status'])) $query->where('o.status', $filters['status']);
|
||||
if (!empty($filters['purpose_id'])) $query->where('o.purpose_id', $filters['purpose_id']);
|
||||
|
||||
$orders = $query->paginate($size)->withQueryString();
|
||||
$rawOrders = $query->paginate($size)->withQueryString();
|
||||
|
||||
$stats = DB::table('estate_orders')
|
||||
->selectRaw('status, count(*) as cnt')
|
||||
->groupBy('status')
|
||||
->pluck('cnt', 'status');
|
||||
$orders = $rawOrders->through(function ($o) {
|
||||
$o->purposeOne = (object)['uz' => $o->purpose_uz, 'ru' => $o->purpose_ru, 'cr' => $o->purpose_cr];
|
||||
return $o;
|
||||
});
|
||||
|
||||
$purposeCases = DB::table('estate_orders')->distinct()->pluck('purpose');
|
||||
$stats = DB::table('estate_orders')->selectRaw('status, count(*) as cnt')->groupBy('status')->pluck('cnt', 'status');
|
||||
$purposeCases = DB::table('purposes')->get();
|
||||
|
||||
return view('estate.index', compact('orders', 'stats', 'filters', 'size', 'purposeCases'));
|
||||
}
|
||||
@@ -45,7 +50,7 @@ class EstateController extends Controller
|
||||
$purposes = DB::table('purposes')->get();
|
||||
$regions = DB::table('regions')->get();
|
||||
$concerns = DB::table('concerns')->get();
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->where('status', 'active')->get();
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->where('status', 'active')->get();
|
||||
return view('estate.create', compact('purposes', 'regions', 'concerns', 'appraisers'));
|
||||
}
|
||||
|
||||
@@ -70,9 +75,23 @@ class EstateController extends Controller
|
||||
|
||||
public function show($order)
|
||||
{
|
||||
$order = DB::table('estate_orders')->selectRaw('*, ordered_customer as customer')->find($order);
|
||||
$order = DB::table('estate_orders as o')
|
||||
->selectRaw('o.*, o.ordered_customer as customer, CONCAT_WS(\' \', o.owner_last_name, o.owner_first_name, o.owner_patronymic) as owner')
|
||||
->addSelect([
|
||||
'purpose_uz' => DB::table('purposes')->select('uz')->whereColumn('id', 'o.purpose_id'),
|
||||
'purpose_ru' => DB::table('purposes')->select('ru')->whereColumn('id', 'o.purpose_id'),
|
||||
'purpose_cr' => DB::table('purposes')->select('cr')->whereColumn('id', 'o.purpose_id'),
|
||||
'region_uz' => DB::table('regions')->select('uz')->whereColumn('id', 'o.region'),
|
||||
'district_uz' => DB::table('districts')->select('uz')->whereColumn('id', 'o.district'),
|
||||
])
|
||||
->where('o.id', $order)->first();
|
||||
|
||||
if ($order) {
|
||||
$order->purposeOne = (object)['uz' => $order->purpose_uz, 'ru' => $order->purpose_ru, 'cr' => $order->purpose_cr];
|
||||
}
|
||||
|
||||
$members = DB::table('order_members')->where('order_id', $order->id ?? 0)->where('order_type', 'estate_')->get();
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->where('status', 'active')->get();
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->where('status', 'active')->get();
|
||||
$isAppraisers = $members->where('user_id', auth()->id())->count() > 0;
|
||||
$files = DB::table('files')->where('order_id', $order->id ?? 0)->where('order_type', 'estate_')->get();
|
||||
return view('estate.show', compact('order', 'members', 'appraisers', 'isAppraisers', 'files'));
|
||||
@@ -89,7 +108,7 @@ class EstateController extends Controller
|
||||
{
|
||||
$order = DB::table('estate_orders')->find($order);
|
||||
$members = DB::table('order_members')->where('order_id', $order->id ?? 0)->where('order_type', 'estate_')->get();
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->where('status', 'active')->get();
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->where('status', 'active')->get();
|
||||
return view('estate.show-team', compact('order', 'members', 'appraisers'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user