const pool = require("./database");

async function checkOrderDetails() {
  try {
    const res = await pool.query(`
      SELECT 
        s.sub_order_id,
        s.order_id,
        s.design_id,
        s.design_style,
        s.print_type,
        s.colour_fabric,
        s.diameter,
        s.roll_length,
        s.inward_weight,
        s.dc_challan_no,
        s.dc_date,
        s.ground,
        om.cus_id,
        c.customer_name
      FROM sub_order s
      JOIN order_master om ON s.order_id = om.order_id
      LEFT JOIN customer_master c ON om.cus_id = c.cus_id
      WHERE LOWER(COALESCE(s.suborder_dept_flow_status, '')) NOT IN ('delivered', 'done', 'completed')
      LIMIT 15
    `);
    console.log("SUBORDER DETAILS SAMPLE:");
    res.rows.forEach(r => console.log(r));
  } catch (err) {
    console.error(err);
  } finally {
    await pool.end();
  }
}

checkOrderDetails();
