<?php
class Precios extends Conectar {


public function get_precios() {
        $conectar = parent::conexion();
        parent::set_names();

        $sql = "SELECT * FROM tm_precios ORDER BY pre_descrip ASC";
        $stmt = $conectar->prepare($sql);
        $stmt->execute();

        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
public function get_precios_select() {
        $conectar = parent::conexion();
        parent::set_names();

        $sql = "SELECT * FROM tm_precios ORDER BY pre_costo ASC";
        $stmt = $conectar->prepare($sql);
        $stmt->execute();

        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
public function delete_precios($pre_id) {
        $conectar = parent::conexion();
        parent::set_names();

        $sql = "DELETE FROM tm_precios WHERE pre_id = ?";
        $stmt = $conectar->prepare($sql);
        $stmt->execute([$pre_id]);
    }

public function get_precios_por_id($pre_id) {
        $conectar = parent::conexion();
        parent::set_names();

        $sql = "SELECT * FROM tm_precios WHERE pre_id = ?";
        $stmt = $conectar->prepare($sql);
        $stmt->execute([$pre_id]);

        return $stmt->fetch(PDO::FETCH_ASSOC);
    }



public function insert_or_update_precios($pre_id, $pre_descrip, $pre_costo) {
    $conectar = parent::conexion();
    parent::set_names();

   if (empty($pre_id)) {
            $sql = "INSERT INTO tm_precios (pre_descrip,pre_costo)
                    VALUES (?, ?)";
            $stmt = $conectar->prepare($sql);
            $stmt->execute([$pre_descrip, $pre_costo]);
        } else {
            $sql = "UPDATE tm_precios
                    SET pre_descrip = ?, pre_costo = ?
                    WHERE pre_id = ?";
            $stmt = $conectar->prepare($sql);
            $stmt->execute([$pre_descrip, $pre_costo, $pre_id]);
        }
    }
    




}
