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:
@@ -12,12 +12,31 @@ class DebitController extends Controller
|
||||
$filters = $request->only(['search', 'status', 'appraiser']);
|
||||
$size = $request->get('size', 20);
|
||||
|
||||
$query = DB::table('debits')->orderByDesc('id');
|
||||
if (!empty($filters['appraiser'])) $query->where('appraiser_id', $filters['appraiser']);
|
||||
if (!empty($filters['status'])) $query->where('status', $filters['status']);
|
||||
$query = DB::table('debits as d')
|
||||
->leftJoin('users as u', 'u.id', '=', 'd.appraiser_id')
|
||||
->select('d.*')
|
||||
->selectRaw('u.name as appraiser_name, u.id as appraiser_user_id')
|
||||
->orderByDesc('d.id');
|
||||
|
||||
$debits = $query->paginate($size)->withQueryString();
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->get();
|
||||
if (!empty($filters['appraiser'])) $query->where('d.appraiser_id', $filters['appraiser']);
|
||||
if (!empty($filters['status'])) $query->where('d.status', $filters['status']);
|
||||
|
||||
$rawDebits = $query->paginate($size)->withQueryString();
|
||||
|
||||
$debits = $rawDebits->through(function ($d) {
|
||||
$d->appraiser = (object)['id' => $d->appraiser_user_id, 'name' => $d->appraiser_name];
|
||||
// get order number
|
||||
if ($d->order_id && $d->order_type) {
|
||||
$table = $d->order_type === 'auto_' ? 'auto_orders' : 'estate_orders';
|
||||
$ord = DB::table($table)->select('id', 'number')->find($d->order_id);
|
||||
$d->order = $ord;
|
||||
} else {
|
||||
$d->order = null;
|
||||
}
|
||||
return $d;
|
||||
});
|
||||
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->get();
|
||||
$debit = null;
|
||||
$appraiser = null;
|
||||
|
||||
@@ -26,7 +45,7 @@ class DebitController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->get();
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->get();
|
||||
return view('debit.create', compact('appraisers'));
|
||||
}
|
||||
|
||||
@@ -44,7 +63,7 @@ class DebitController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$debit = DB::table('debits')->find($id);
|
||||
$appraisers = DB::table('users')->where('role', 'appraiser')->get();
|
||||
$appraisers = DB::table('users')->whereRaw('LOWER(role) = ?', ['appraiser'])->get();
|
||||
return view('debit.edit', compact('debit', 'appraisers'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user