<?php
class Material extends Conectar
{
    public function get_material()
    {
        $conectar = parent::conexion();
        parent::set_names();
        $sql = "SELECT * FROM material";
        $stmt = $conectar->prepare($sql);
        $stmt->execute();
        return $stmt->fetchAll();
    }
    public function get_material_estado()
    {
        $conectar = parent::conexion();
        parent::set_names();
        $sql = "SELECT * FROM material WHERE Cest_mat = 1";
        $stmt = $conectar->prepare($sql);
        $stmt->execute();
        return $stmt->fetchAll();
    }

    public function get_material_id($Ccod_matID)
    {
        $conectar = parent::conexion();
        parent::set_names();
        $sql = "SELECT * FROM material WHERE Ccod_matID = ?";
        $stmt = $conectar->prepare($sql);
        $stmt->execute([$Ccod_matID]);
        return $stmt->fetch(); // Utiliza fetch() en lugar de fetchAll()
    }

    public function insert_material($Ccod_mat, $Cdescrip)
    {
        $conectar = parent::conexion();
        parent::set_names();
        $sql = "INSERT INTO material (Ccod_mat, Cdescrip, Cest_mat) VALUES (?, ?, 1)";
        $stmt = $conectar->prepare($sql);
        $stmt->execute([$Ccod_mat, $Cdescrip]);
        return true; // Opcional: Puedes devolver un indicador de éxito/fallo
    }

    public function update_material($Ccod_matID, $Ccod_mat, $Cdescrip, $Cest_mat)
    {
        $conectar = parent::conexion();
        parent::set_names();
        $sql = "UPDATE material 
                SET Ccod_mat = ?, Cdescrip = ?, Cest_mat = ?
                WHERE Ccod_matID = ?";
        $stmt = $conectar->prepare($sql);
        $stmt->execute([$Ccod_mat, $Cdescrip, $Cest_mat, $Ccod_matID]);
        return true;
    }
}
?>

