<?php

    class Statics
    {
        public static function SafeInput($con, $input)
        {
            $input = htmlspecialchars($input);
            $input = mysqli_real_escape_string($con, $input);
            return $input;
        }


        public static function fileExists($file)
        {
            if(file_exists($file))
            {
                unlink($file);
            }
        }

        public static function RedLight()
        {
            if(isset($_COOKIE))
            {
                foreach($_COOKIE as $key=>$value)
                {
                    setcookie($key,$value,time() - 3600,'/','','',true);
                }
            }
            session_destroy();

            header('Location:index.php');
        }

        public static function redirectInput($input, $redirect = false)
        {
            if(!isset($input))
            {
                if($redirect)
                {
                    header('Location:' . $redirect);
                }
                else
                {
                    header('Location:dashboard.php');
                }
            }
            if(empty($input))
            {
                if($redirect)
                {
                    header('Location:' . $redirect);
                }
                else
                {
                    header('Location:dashboard.php');
                }
            }
        }

        public static function getIvaValue ($Schema, $codigo) {
            $sql = "SELECT PORCENTAJE FROM EXPEDIENTES_IMPUESTOS WHERE GRUPO = ? AND CODIGO = ?";
            $res = $Schema->executeQuery($sql, 'si', ['IVA', $codigo]);
            $row_compra_impuesto = $res->fetch_array();
            return $row_compra_impuesto['PORCENTAJE'];
        }

        
    }

?>