changes
This commit is contained in:
@@ -5,6 +5,10 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Container;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\User;
|
||||
use App\Models\MarkList;
|
||||
|
||||
class AdminAuthController extends Controller
|
||||
{
|
||||
@@ -31,16 +35,15 @@ class AdminAuthController extends Controller
|
||||
}
|
||||
|
||||
$credentials = [
|
||||
$field => $loginInput,
|
||||
$field => $loginInput,
|
||||
'password' => $request->password,
|
||||
];
|
||||
|
||||
// attempt login
|
||||
if (Auth::guard('admin')->attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
$user = Auth::guard('admin')->user();
|
||||
|
||||
return redirect()->route('admin.dashboard')->with('success', 'Welcome back, ' . $user->name . '!');
|
||||
return redirect()->route('admin.dashboard')
|
||||
->with('success', 'Welcome back, ' . $user->name . '!');
|
||||
}
|
||||
|
||||
return back()->withErrors(['login' => 'Invalid login credentials.']);
|
||||
@@ -51,6 +54,25 @@ class AdminAuthController extends Controller
|
||||
Auth::guard('admin')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
return redirect()->route('admin.login')->with('success', 'Logged out successfully.');
|
||||
return redirect()->route('admin.login')
|
||||
->with('success', 'Logged out successfully.');
|
||||
}
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
$user = Auth::guard('admin')->user();
|
||||
|
||||
// ── Real Stats ──
|
||||
$stats = [
|
||||
'total_containers' => Container::count(),
|
||||
'total_invoices' => Invoice::count(),
|
||||
'paid_invoices' => Invoice::where('status', 'paid')->count(),
|
||||
'pending_invoices' => Invoice::where('status', 'pending')->count(),
|
||||
'total_customers' => User::count(),
|
||||
'total_marklist' => MarkList::count(),
|
||||
'active_marklist' => MarkList::where('status', 'active')->count(),
|
||||
];
|
||||
|
||||
return view('admin.profile', compact('user', 'stats'));
|
||||
}
|
||||
}
|
||||
@@ -269,9 +269,23 @@ class AdminInvoiceController extends Controller
|
||||
$newPaid = $paidTotal + $request->amount;
|
||||
$remaining = max(0, $grandTotal - $newPaid);
|
||||
|
||||
if ($newPaid >= $grandTotal && $grandTotal > 0) {
|
||||
$invoice->update(['status' => 'paid']);
|
||||
}
|
||||
|
||||
|
||||
// Full payment logic (जर पूर्ण भरले तर status paid करणे, नाहीतर pending राहील)
|
||||
// if ($newPaid >= $grandTotal && $grandTotal > 0) {
|
||||
// $invoice->update([
|
||||
// 'payment_method' => $request->payment_method,
|
||||
// 'reference_no' => $request->reference_no,
|
||||
// 'status' => ($newPaid >= $grandTotal && $grandTotal > 0) ? 'paid' : $invoice->status,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// Partial payment status logic:
|
||||
$invoice->update([
|
||||
'payment_method' => $request->payment_method,
|
||||
'reference_no' => $request->reference_no,
|
||||
'status' => ($newPaid >= $grandTotal && $grandTotal > 0) ? 'paid' : $invoice->status,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
|
||||
@@ -28,11 +28,23 @@ class AdminOrderController extends Controller
|
||||
* ---------------------------*/
|
||||
public function dashboard()
|
||||
{
|
||||
$totalOrders = Order::count();
|
||||
$pendingOrders = Order::where('status', 'pending')->count();
|
||||
$totalShipments = Shipment::count();
|
||||
$totalItems = OrderItem::count();
|
||||
// ── Order counts (from Invoice Management / Orders table) ──
|
||||
$totalOrders = Order::count();
|
||||
|
||||
// "Pending" म्हणजे delivered नसलेले सर्व orders
|
||||
// Order तयार होतो तेव्हा status = 'order_placed' असतो, 'pending' नाही
|
||||
$deliveredStatuses = ['delivered'];
|
||||
$pendingOrders = Order::whereNotIn('status', $deliveredStatuses)->count();
|
||||
|
||||
// ── Invoice counts ──
|
||||
$totalContainers = Container::count();
|
||||
$totalInvoices = Invoice::count();
|
||||
$paidInvoices = Invoice::where('status', 'paid')->count();
|
||||
$pendingInvoices = Invoice::where('status', 'pending')->count();
|
||||
$overdueInvoices = Invoice::where('status', 'overdue')->count();
|
||||
$totalRevenue = Invoice::sum('final_amount_with_gst');
|
||||
|
||||
// ── User / Staff counts ──
|
||||
$activeCustomers = User::where('status', 'active')->count();
|
||||
$inactiveCustomers = User::where('status', 'inactive')->count();
|
||||
$totalStaff = Admin::where('type', 'staff')->count();
|
||||
@@ -43,8 +55,11 @@ class AdminOrderController extends Controller
|
||||
return view('admin.dashboard', compact(
|
||||
'totalOrders',
|
||||
'pendingOrders',
|
||||
'totalShipments',
|
||||
'totalItems',
|
||||
'totalContainers',
|
||||
'totalInvoices',
|
||||
'paidInvoices',
|
||||
'pendingInvoices',
|
||||
'overdueInvoices',
|
||||
'totalRevenue',
|
||||
'activeCustomers',
|
||||
'inactiveCustomers',
|
||||
@@ -90,11 +105,23 @@ class AdminOrderController extends Controller
|
||||
->when($request->filled('status'), function ($q) use ($request) {
|
||||
$q->where('invoices.status', $request->status);
|
||||
})
|
||||
->orderByDesc('invoices.invoice_date') // इथे बदल
|
||||
->orderByDesc('invoices.id') // same-date साठी tie-breaker
|
||||
->orderByDesc('invoices.invoice_date')
|
||||
->orderByDesc('invoices.id')
|
||||
->get();
|
||||
|
||||
return view('admin.orders', compact('invoices'));
|
||||
|
||||
// ── Real DB counts (filter-independent) ──
|
||||
$totalInvoices = \App\Models\Invoice::count();
|
||||
$paidInvoices = \App\Models\Invoice::where('status', 'paid')->count();
|
||||
$pendingInvoices = \App\Models\Invoice::where('status', 'pending')->count();
|
||||
$overdueInvoices = \App\Models\Invoice::where('status', 'overdue')->count();
|
||||
|
||||
return view('admin.orders', compact(
|
||||
'invoices',
|
||||
'totalInvoices',
|
||||
'paidInvoices',
|
||||
'pendingInvoices',
|
||||
'overdueInvoices'
|
||||
));
|
||||
}
|
||||
|
||||
/* ---------------------------
|
||||
@@ -759,4 +786,4 @@ class AdminOrderController extends Controller
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user