<?php
session_start();
include "../conexion.php";
require_once('../include/sesiones.php'); 
$art_id=$_GET['id'];  
?> 
<h4><center><strong>
    <?php
        $datoos=mysqli_query($con,"SELECT * FROM articulos where art_id='$art_id' and empresa='$empresa'") ;
        $da=mysqli_fetch_array( $datoos );
        $art_atributo_estado=$da['art_atributo_estado'];
        $art_atributo1=$da['art_atributo1'];
        $art_atributo2=$da['art_atributo2'];
    ?>
    <div class="alert alert-info alert-dismissable">
        <strong><?php  echo $da['art_nombre']; ?></strong>
    </div>
</strong></center></h4>
<div class="row">
<div class="col-md-12">
    <div class="col-md-6"> 
        <ul class="gallery-container">
            <?php
            $files = glob("../img/articulos/$art_id.jpg");
            if(count($files) > 0) 
            { 
                foreach($files as $file) 
                { 
            ?>
            <li>
                <?php $nu=rand(1,1000); $nu; ?>
                <a href="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" class="ui-lightbox">
                    <img src="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" alt="" />
                </a>
            </li>
            <?php } } else { ?>
            <li>
                <a href="img/articulos/sin_imagen.jpg" class="ui-lightbox">
                    <img src="img/articulos/sin_imagen.jpg" alt="" />
                </a>
            </li>

            <?php } ?>
        </ul>
    </div>
    <div class="col-md-1"></div>
        <div class="col-md-5">
        <?php
            $datos=mysqli_query($con,"SELECT * FROM precio p, tarifas t, articulos a where a.art_id=p.articulos_art_id and p.tarifas_tar_id=t.tar_id 
            and a.art_id='$art_id' and a.empresa='$empresa' and p.empresa='$empresa' and t.empresa='$empresa' and (t.tar_nombre<>'ASESOR' AND t.tar_nombre<>'MAYORISTA') order by t.tar_orden asc") ;
            while( $fila = mysqli_fetch_array( $datos ) )
            {
        ?>
            <div class="" >
                <label>Precio <?php echo ucwords(strtolower($fila['tar_nombre'])); ?></label>
                <input type="text" name="pre" id="pre" class="form-control input-sm" autocomplete="off" readonly="" value="<?php echo number_format($fila['pre_precio'],0); ?>">
            </div>
        <?php } ?>

        <?php
            $datos = mysqli_query($con,"SELECT * FROM precio p, tarifas t, articulos a where a.art_id=p.articulos_art_id and p.tarifas_tar_id=t.tar_id 
            and a.art_id='$art_id' and a.empresa='$empresa' and p.empresa='$empresa' and t.empresa='$empresa' and t.tar_nombre='ASESOR'") ;
            while( $fila = mysqli_fetch_array( $datos ) )
            {
        ?>
        <label>Precio <?php echo ucwords(strtolower($fila['tar_nombre'])); ?></label>
        <div class="input-group">
            <input type="password" id="asesor" placeholder="" class="form-control input-sm" readonly="" value="<?php echo number_format($fila['pre_precio'],0); ?>">
            <span class="input-group-addon">
                <a onclick="myFunction()" type='button'><i class="btn-icon-only icon-eye-open"></i></a>
            </span> 
        </div>
        <?php } ?>
        <?php
            $datos = mysqli_query($con,"SELECT * FROM precio p, tarifas t, articulos a where a.art_id=p.articulos_art_id and p.tarifas_tar_id=t.tar_id 
            and a.art_id='$art_id' and a.empresa='$empresa' and p.empresa='$empresa' and t.empresa='$empresa' and t.tar_nombre='MAYORISTA'") ;
            while( $fila = mysqli_fetch_array( $datos ) )
            {
        ?>
        <label>Precio <?php echo ucwords(strtolower($fila['tar_nombre'])); ?></label>
        <div class="input-group">
            <input type="password" id="mayorista" placeholder="" class="form-control input-sm" readonly="" value="<?php echo number_format($fila['pre_precio'],0); ?>">
                <span class="input-group-addon">
                     <a onclick="myFunction1()" type='button'><i class="btn-icon-only icon-eye-open"></i></a>
                </span> 
        </div>
        <?php } ?>
        <br>
        <?php
            $sucu=mysqli_query($con,"SELECT * FROM sucursal where empresa='$empresa'");
            while( $sucu1 = mysqli_fetch_array($sucu))
            {
                $suc_id=$sucu1['suc_id'];
                $suc_nombre=$sucu1['suc_nombre'];
        ?>
     
        <strong>STOCK <?php echo $suc_nombre; ?>: 
        <?php if($art_atributo_estado=='si') { ?>
        </BR>
            <?php
                $datoss=mysqli_query($con,"SELECT * FROM articulos_has_bodegas where articulos_art_id ='$art_id' AND sucursal='$suc_id'  ") ;
                while( $filas = mysqli_fetch_array( $datoss ) )
                {
                    if ($art_atributo1<>null) {
                        $atributo1=$filas['atributo1'];
                        if ($atributo1=='0')
                        {
                            echo '-&nbsp;&nbsp;SIN '; echo $art_atributo1; echo' ';
                            echo '<i style="color:red;">';
                           // echo $atri1['atri_nombre'];
                            echo '</i>';
                            echo '/';
                        } 
                        else
                        {
                            $atri1=mysqli_query($con,"SELECT * FROM atributos1 where atri_art_id='$art_id' and atri_id='$atributo1'");
                            $atri1 = mysqli_fetch_array($atri1);
                            if (isset($atri1['atri_nombre'])) 
                            {
                                echo '-&nbsp;&nbsp;';echo $art_atributo1; echo ' ';
                                echo '<i style="color:red;">';
                                echo $atri1['atri_nombre'];
                                echo '</i>';
                                echo ' ';
                            }
                        }
                    }


                    if ($art_atributo2<>null) {
                        $atributo2=$filas['atributo2'];
                        if ($atributo2=='0')
                        {
                            echo 'SIN '; echo $art_atributo2; echo' ';
                            echo '<i style="color:red;">';
                           // echo $atri1['atri_nombre'];
                            echo '</i>';
                            echo ' ';
                        } 
                        else
                        {
                            $atri2=mysqli_query($con,"SELECT * FROM atributos2 where atri_art_id2='$art_id' and atri_id2='$atributo2'");
                            $atri2 = mysqli_fetch_array($atri2);
                            if (isset($atri2['atri_nombre2'])) 
                            {
                                echo $art_atributo2;echo ' ';
                                echo '<i style="color:red;">';
                                echo $atri2['atri_nombre2'];
                                echo '</i>';
                                echo ' ';
                            }
                        }
                    }

                    echo ': ';
                    echo $cantidad=$filas['art_cantidad']; 
                    echo '</br>';
                } } else {

                $can=mysqli_query($con,"SELECT *, sum(art_cantidad) as art_cantidad FROM articulos_has_bodegas WHERE articulos_art_id='$art_id' and sucursal='$suc_id' ") or die(mysqli_error($con));
                $c=mysqli_fetch_array($can);
                $cantidad=$c['art_cantidad'];

                if (fmod($cantidad, 1) == 0) 
                {
                    echo number_format($cantidad, 0, '.', '');
                } 
                else 
                {
                    echo number_format($cantidad, 2, '.', '');
                }


                echo '</br>'; 
                }
            ?>

        
        </strong>
        
        <?php } ?>
        <br>
        <span> <strong>CODIGO: </strong><?php echo $da['art_referencia']; ?></span> <br>
        <span> <strong>REFERENCIA: </strong><?php echo $da['art_referencia2']; ?></span><br>
        <span> <strong>GARANTIA: </strong><?php echo $da['art_garantia']; ?> MESES </span>

        <?php if ($negocio_neg_id==3) 
        {
            $ubicacion=$da['ubicacion_ubi_id'];
            $ubi = mysqli_query($con,"SELECT * FROM ubicacion where ubi_id='$ubicacion' and empresa='$empresa' ") ;
            $ub = mysqli_fetch_array( $ubi );
            $ubi_nombre=$ub['ubi_nombre']; 
           ?>
                <p style=""> <strong>UBICACIÓN: </strong><?php echo $ubi_nombre; ?></p>
        <?php } ?>
    </div>
</div>
</div>
<script type="text/javascript">
function myFunction() {
    var x = document.getElementById("asesor");
    if (x.type === "password") {
        x.type = "text";
    } else {
        x.type = "password";
    }
}

function myFunction1() {
    var x = document.getElementById("mayorista");
    if (x.type === "password") {
        x.type = "text";
    } else {
        x.type = "password";
    }
}
</script>