<?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'];
		$categoria = $_POST['categoria'];
		
	
		
		$sql_update = mysqli_query($conexion, "UPDATE product_to_store AS pts
JOIN products AS p ON pts.product_id = p.p_id
SET pts.sell_price = pts.sell_price - (pts.sell_price * $porcentaje)
WHERE pts.sup_id = $proveedor
  AND p.category_id = $categoria");
		
            //$sql_update = mysqli_query($conexion, "UPDATE product_to_store SET purchase_price = purchase_price + (purchase_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" />
<style type="text/css">
<!--
.Estilo2 {color: #FF6666}
-->
</style>
<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 Estilo2">
                   RETROTRAER PRECIOS USANDO PORCENTAJES   </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 bgcolor="#FF9966" scope="col">&nbsp;</th>
                                <th bgcolor="#FF9966" scope="col">&nbsp;</th>
                                <th bgcolor="#FF9966" scope="col">&nbsp;</th>
                              </tr>
                              <tr>
                                <th width="33%" bgcolor="#FF9966" scope="col"><div align="right">Porcentaje de aumento</div></th>
                                <th width="12%" bgcolor="#FF9966" 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%" bgcolor="#FF9966" scope="col"><div align="left"> Ingresar el porcentaje que se retro traera </div></th>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                              </tr>
                              <tr>
                                <td colspan="3" bgcolor="#FF9966">EL PORCENTAJE A RETROTRAER DEBE INGRESARSE EN EL SIGUIENTE FORMATO <span class="Estilo1">0.20 </span>si el % a retrotraer es 20% </td>
                              </tr>
                              <tr>
                                <td colspan="3" bgcolor="#FF9966">EL PORCENTAJE A RETROTRAER DEBE INGRESARSE EN EL SIGUIENTE FORMATO <span class="Estilo1">0.05 </span>si el % a retrotraer es 5% </td>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966"><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>RETROTRAER</button>
                        <div align="center"></div></div></td>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966"><div align="right"><strong>Codigo proveedor </strong></div></td>
                                <td bgcolor="#FF9966"><input type="text" placeholder="Ingrese el codigo de proveedor" name="proveedor" class="form-control" id="proveedor" value="" /></td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966"><div align="right"><strong>Codigo categoria</strong></div></td>
                                <td bgcolor="#FF9966"><input type="text" placeholder="Ingrese el codigo de categria" name="categoria" class="form-control" id="categoria" value="" /></td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                              </tr>
                              <tr>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                                <td bgcolor="#FF9966">&nbsp;</td>
                              </tr>
                              <tr>
                                <td colspan="2" bgcolor="#FF9966"><div align="right">
                                  <table width="63%" height="1" border="1" align="right" 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 bgcolor="#FFCC00"> <div align="right">codigo proveedor</div></th>
                                        <th bgcolor="#FFCC00">Nombre de proveedor</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <?php
            include "conexion_a.php";
			
			

            $query = mysqli_query($conexion, "SELECT * FROM suppliers");
            $result = mysqli_num_rows($query);
            if ($result > 0) {
                while ($data = mysqli_fetch_assoc($query)) {
                   
            ?>
                                      <tr>
                                        <td bgcolor="#FFCC00"><div align="right" class="Estilo1"><strong><?php echo $data['sup_id']; ?></strong></div></td>
                                        <td bgcolor="#FFCC00"><?php echo $data['sup_name']; ?></td>
                                      </tr>
                                      <?php }
            } ?>
                                    </tbody>
                                  </table>
                                </div></td>
                                <td bgcolor="#FF9966"><div align="left">
                                  <table width="35%" height="1" border="1" align="left" 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 bgcolor="#00FFCC"> <div align="right">codigo categoria</div></th>
                                        <th bgcolor="#00FFCC">Nombre de Categoria</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <?php
            include "conexion_a.php";
			
			

            $query = mysqli_query($conexion, "SELECT * FROM categorys");
            $result = mysqli_num_rows($query);
            if ($result > 0) {
                while ($data = mysqli_fetch_assoc($query)) {
                   
            ?>
                                      <tr>
                                        <td bgcolor="#00FFCC"><div align="right" class="Estilo1"><strong><?php echo $data['category_id']; ?></strong></div></td>
                                        <td bgcolor="#00FFCC"><?php echo $data['category_name']; ?></td>
                                      </tr>
                                      <?php }
            } ?>
                                    </tbody>
                                  </table>
                                </div>
                                </td>
                              </tr>
                      </table>
                    </div>
                       
                  </form>
                </div>
            </div>
        </div>
    </div>


<div class="table-responsive">
  <p>&nbsp;</p>
    <p>&nbsp;</p>
</div>
<div class="table-responsive"></div>
	
	<a href="dashboard.php">volver al menu    </a>