Files
ladill-woo-manager/app/Http/Controllers/Woo/DashboardController.php
T
isaaccladandCursor cebf0d2e61
Deploy Ladill Woo Manager / deploy (push) Successful in 51s
Add Woo Manager Pro with multi-store switching and free-tier limits.
Free: 1 store and 20 products. Pro/Business mirrors Invoice pricing (GHS 49/149)
with wallet renewals, Paystack prepay, session-based store switcher, and scoped UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 01:14:08 +00:00

67 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\Woo;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Woo\Concerns\ResolvesWooContext;
use App\Models\WooCategory;
use App\Models\WooOrder;
use App\Models\WooProduct;
use App\Models\WooStore;
use App\Services\Woo\SubscriptionService;
use Illuminate\Http\Request;
use Illuminate\View\View;
class DashboardController extends Controller
{
use ResolvesWooContext;
public function __construct(private SubscriptionService $subscriptions) {}
public function index(Request $request): View
{
$user = $this->accountUser($request);
$store = $this->currentStore($request);
$storeId = $store?->id;
$stats = [
'stores' => WooStore::query()->where('user_id', $user->id)->where('status', WooStore::STATUS_ACTIVE)->count(),
'orders_new' => $storeId
? WooOrder::query()->where('woo_store_id', $storeId)->where('fulfillment_status', WooOrder::FULFILLMENT_NEW)->count()
: 0,
'orders_open' => $storeId
? WooOrder::query()->where('woo_store_id', $storeId)->whereNotIn('fulfillment_status', [
WooOrder::FULFILLMENT_DELIVERED,
WooOrder::FULFILLMENT_CANCELLED,
])->count()
: 0,
'products' => $storeId
? WooProduct::query()->where('woo_store_id', $storeId)->count()
: 0,
'categories' => $storeId
? WooCategory::query()->where('woo_store_id', $storeId)->count()
: 0,
];
$recent = $storeId
? WooOrder::query()
->where('woo_store_id', $storeId)
->with('store')
->latest('created_at')
->limit(8)
->get()
: collect();
return view('woo.dashboard', [
'stats' => $stats,
'recent' => $recent,
'currentStore' => $store,
'hasPaidPlan' => $this->subscriptions->hasPaidPlan($user),
'productCount' => $this->subscriptions->productCount($user),
'productLimit' => $this->subscriptions->isPro($user) ? null : (int) config('woo.free.max_products', 20),
'storeCount' => $this->subscriptions->connectedStoreCount($user),
'storeLimit' => $this->subscriptions->isPro($user) ? null : (int) config('woo.free.max_stores', 1),
]);
}
}