const pool = require('../db/connection');


const getSharedExpenses = async (req, res) => {
  try {
    
    const result = await pool.query(`SELECT * FROM shared_expenses_dashboard`);

    const data = result.rows.map(row => ({
      id_expense: row.id_expense,
      id_properties: row.id_properties,
      id_expense_type: row.id_expense_type,
      request_date: row.request_date,
      payment_deadline: row.payment_deadline,
      id_area: row.id_area,
      id_expense_cat: row.id_expense_cat,
      id_approval_stat: row.id_approval_stat,
      id_currency: row.id_currency,
      is_purchase: row.is_purchase,
      total: row.total,
      subtotal: row.subtotal,
      iva: row.iva,
      ieps: row.ieps,
      id_suppliers: row.id_suppliers,
      id_payment_status: row.id_payment_status,
      id_cat_percent: row.id_cat_percent,
      participation: row.participation,
      id_fix_variable: row.id_fix_variable
    }));

    res.json({ count: data.length, data });

  } catch (error) {
    console.error(error);
    res.status(500).json({ error: 'Error al obtener los datos del dashboard' });
  }
};

module.exports = { getSharedExpenses };