Deploy: 2026-05-23 03:35:52
This commit is contained in:
@@ -42,16 +42,26 @@ class SuperAdminController extends BaseController
|
|||||||
SELECT
|
SELECT
|
||||||
c.id,
|
c.id,
|
||||||
c.name,
|
c.name,
|
||||||
c.status,
|
c.status as company_status,
|
||||||
cs.plan_id,
|
c.created_at,
|
||||||
sp.name as plan_name,
|
cs.plan_id,
|
||||||
cs.status as subscription_status,
|
cs.status as sub_status,
|
||||||
SELECT c.id, c.name, c.status as company_status, c.created_at,
|
cs.starts_at,
|
||||||
cs.plan_id, cs.status as sub_status, cs.starts_at, cs.ends_at, cs.payment_method, cs.receipt_reference,
|
cs.ends_at,
|
||||||
p.name as plan_name
|
cs.payment_method,
|
||||||
|
cs.receipt_reference,
|
||||||
|
p.name as plan_name,
|
||||||
|
(SELECT COUNT(*) FROM whatsapp_sessions WHERE company_id = c.id) as sessions_count,
|
||||||
|
(SELECT COUNT(*) FROM whatsapp_sessions WHERE company_id = c.id AND status = 'connected') as active_sessions,
|
||||||
|
COALESCE(cu.request_count, 0) as request_usage,
|
||||||
|
COALESCE(cu.voice_count, 0) as voice_usage,
|
||||||
|
COALESCE(cu.ocr_count, 0) as ocr_usage
|
||||||
FROM companies c
|
FROM companies c
|
||||||
LEFT JOIN company_subscriptions cs ON c.id = cs.company_id AND cs.status IN ('active', 'trialing', 'pending_approval')
|
LEFT JOIN company_subscriptions cs ON c.id = cs.company_id AND cs.status IN ('active', 'trialing', 'pending_approval')
|
||||||
LEFT JOIN subscription_plans p ON cs.plan_id = p.id
|
LEFT JOIN subscription_plans p ON cs.plan_id = p.id
|
||||||
|
LEFT JOIN company_subscription_usage cu ON cu.company_id = c.id
|
||||||
|
AND cu.billing_start <= CURRENT_DATE()
|
||||||
|
AND cu.billing_end >= CURRENT_DATE()
|
||||||
ORDER BY c.created_at DESC
|
ORDER BY c.created_at DESC
|
||||||
");
|
");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user