<?php 
include "conexion_a.php";
?>
<?php 
ob_start();
session_start();
include '../_init.php';

// Redirect, If user is not logged in
if (!is_loggedin()) {
  redirect(root_url() . '/index.php?redirect_to=' . url());
}

// Redirect, If User has not Read Permission
if (user_group_id() != 1 && !has_permission('access', 'read_product')) {
	redirect(root_url() . '/'.ADMINDIRNAME.'/dashboard.php');
}

// Set Document Title
$document->setTitle(trans('title_product'));

// Add Script
$document->addScript('../assets/tinymce/tinymce.min.js');
$document->addScript('../assets/itsolution24/angular/controllers/ProductController.js');

// Include Header and Footer

?>
<style type="text/css">
.image-thumbnail {
  position: relative;
  width: 80px;
  height: 75px;
  overflow: hidden;
  display: inline-block;
}
.image-thumbnail img {
    position: relative;
    width: 100%;
    height: auto;
    max-height: 100%;
}
.Estilo1 {
	font-size: 18px;
	font-weight: bold;
}
</style>

<?php 
if (!empty($_POST)) {
    $alert = "";
    if (empty($_POST['porcentaje']) || empty($_POST['proveedor'])) {
        $alert = '<div class="alert alert-danger" role="alert">Todo los campos son requeridos</div>';
    } else {
        $porcentaje = $_POST['porcentaje'];
        $proveedor = $_POST['proveedor'];
            $sql_update = mysqli_query($conexion, "UPDATE product_to_store SET sell_price = sell_price + (sell_price * $porcentaje / 100) WHERE sup_id = $proveedor ");

            if ($sql_update) {
                $alert = '<div class="alert alert-success" role="alert">rango de precios Actualizado correctamente</div>';
            } else {
                $alert = '<div class="alert alert-danger" role="alert">Error al Actualizar los precios</div>';
            }
    }
}

?>

<link href="../assets/itsolution24/css/responsive.css" rel="stylesheet" type="text/css" />
<div class="container-fluid">

    <div class="row">
        <div class="col-lg-6 m-auto">
            <div class="card">
                <div class="text-white bg-primary card-header">
                  <div align="center" class="Estilo1">
                    Modificar PRECIOS POR PROVEEDOR               </div>
                </div>
                <div class="card-body">
                  <form class="" action="" method="post">
                        <?php echo isset($alert) ? $alert : ''; ?>
                        
                    <div class="form-group">
                            <label for="telefono"></label>
                            <table width="100%" border="0" align="center" cellspacing="0">
                              <tr>
                                <th width="33%" scope="col"><div align="right">Porcentaje de aumento</div></th>
                                <th width="12%" scope="col">
                                  <div align="left">
                                    <input type="text" placeholder="Ingrese el porcentaje" name="porcentaje" class="form-control" id="porcentaje" value="" />
                                  </div></th>
                                <th width="100%" scope="col"><div align="left"></div></th>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td><div align="left"> <div class="form-group">
                            <label for="direccion"></label>
                            </div>
                        <button type="submit" class="btn btn-primary"><i class="fas fa-user-edit"></i> Actualizar</button>
                        <div align="center"></div></div></td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>Codigo proveedor </strong></div></td>
                                <td><input type="text" placeholder="Ingrese el codigo de proveedor" name="proveedor" class="form-control" id="proveedor" value="" /></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                              </tr>
                            </table>
                    </div>
                       
                  </form>
                </div>
            </div>
        </div>
    </div>


<div class="table-responsive">
   	<table width="25%" height="1" border="1" cellspacing="1" bordercolor="#999999" id="product-product-list" data-hide-colums="<?php echo $hide_colums; ?>" data-print-columns="<?php echo $print_columns;?>" name="product-product-list">
								    <thead>
            <tr width="50%" class="bg-gray">
                <th> <div align="right">codigo proveedor</div></th>
                <th>Nombre de proveedor</th>       
            </tr>
        </thead>
        <tbody>
            <?php
            include "conexion_a.php";
			
			//$detalle = mysqli_query($conexion, "SELECT d.*, p.codproducto, p.descripcion FROM detalle_temp d INNER JOIN producto p ON d.id_producto = p.codproducto WHERE d.id_usuario = $id");

            $query = mysqli_query($conexion, "SELECT * FROM suppliers");
            $result = mysqli_num_rows($query);
            if ($result > 0) {
                while ($data = mysqli_fetch_assoc($query)) {
                   
            ?>
                    <tr>
                        <td><div align="right" class="Estilo1"><strong><?php echo $data['sup_id']; ?></strong></div></td>
                        <td><?php echo $data['sup_name']; ?></td>
                    </tr>
            <?php }
            } ?>
        </tbody>
  </table>
</div>
	
	<a href="dashboard.php">volver al menu    </a>