set search_path = budget_app, public;

-- 1. 회사 목록
select id, code, name from companies;

-- 2. 프로젝트 목록
select project_code, project_name, status, contract_amount
from projects
order by project_code;

-- 3. 프로젝트별 월 예산 대비 실적
select
    p.project_code,
    p.project_name,
    v.month_no,
    a.code as account_code,
    a.name as account_name,
    v.budget_amount,
    v.actual_amount,
    v.variance_amount,
    v.execution_rate
from vw_budget_vs_actual_monthly v
join projects p on p.id = v.project_id
join accounts a on a.id = v.account_id
order by p.project_code, v.month_no, a.code;

-- 4. 프로젝트 손익 요약
select
    project_code,
    project_name,
    revenue_amount,
    cost_amount,
    profit_amount,
    profit_rate
from vw_project_profit_summary
order by project_code;

-- 5. 발주 요청과 발주 현황
select
    pr.request_no,
    po.order_no,
    p.project_code,
    v.name as vendor_name,
    pr.total_amount as request_amount,
    po.total_amount as order_amount
from purchase_requests pr
left join purchase_orders po on po.purchase_request_id = pr.id
left join projects p on p.id = pr.project_id
left join vendors v on v.id = pr.vendor_id
order by pr.request_no;
