SELECT 
    company.company_id,
    company.company_name,
    COUNT(DISTINCT patient.patient_id) AS total_patient,
    SUM(COALESCE(bill_payment.amount, 0)) AS total_amount
FROM 
    patient
LEFT JOIN 
    appointment ON patient.patient_id = appointment.patient_id
LEFT JOIN 
    visit ON appointment.visit_id = visit.visit_id
LEFT JOIN 
    bill ON visit.bill_id = bill.bill_id
LEFT JOIN 
    bill_payment ON bill.bill_id = bill_payment.bill_id
LEFT JOIN 
    person ON patient.person_id = person.person_id
LEFT JOIN 
    patient_company_relation ON patient.patient_id = patient_company_relation.patient_id
LEFT JOIN 
    company ON patient_company_relation.company_id = company.company_id
WHERE 
    DATE(bill.bill_date) = '2025-02-03'
    AND patient_company_relation.to_date IS NULL
GROUP BY 
    company.company_id, 
    company.company_name;
