<?php session_start();
require('../cfg/cfg.php');
require('../cfg/res.php');


$xacceso=0;
$sql_acce='select * from usrdoc1 where docu = "PREC" and modi="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xacceso=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a modificar precios' );}	


$pagina_descri='PRECIO ITEM';
$pagina_nivel;
$pagina_tipo;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $empr_nombre.'-'.$_SESSION['user_vcrx_id'];?> - Precio Item</title>
<link rel="stylesheet" href="http://vcrxol.com/_css/comun.css" type="text/css" />
<link rel="stylesheet" href="../css/comun2.css" type="text/css" />
<style>
.codigo{ width:50px;}
.nctlg{ width:50px; text-align:center;}
.pctlg{ width:50px; text-align:center;}
.iva{ width:50px; text-align:right;}
.pvp1{ width:50px; text-align:right;}
</style>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript">



function docu_key(e)
{
		
}
function docu_()
{
	busca_maes2('docu',document.getElementById('docu').value,'docu','docu_descri','');
}

function gene_itempvp(indi)
{

	var error='ext_error';
	var codigo=document.getElementsByClassName('codigo').item(indi).innerHTML;
	var puni=document.getElementsByClassName('puni').item(indi).value;
	var iva=document.getElementsByClassName('iva').item(indi).value;
	var pvp1=document.getElementsByClassName('pvp1').item(indi).value;
	var nctlg=document.getElementsByClassName('nctlg').item(indi).value;
	var pctlg=document.getElementsByClassName('pctlg').item(indi).value;
	var sqlitm='';
		sqlitm+='item_nctlg="'+nctlg+'", ';
		sqlitm+='item_pctlg="'+pctlg+'", '; 
		sqlitm+='item_puni="'+puni+'", ';
		sqlitm+='item_iva="'+iva+'", ';
		sqlitm+='item_pvp1="'+pvp1+'" ';
		//console.log(sqlitm);
		//return false
		$.ajax({
		cache:false,
		url:'vritempvp2.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{codigo:codigo,sqlitm:sqlitm}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	                  
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if(document.getElementById(error))
		   {
				
				document.getElementById(error).innerHTML='';
				if (jqXHR.status === 0) {
				document.getElementById(error).innerHTML='Not connect: Verify Network.';
				} else if (jqXHR.status == 404) {
				document.getElementById(error).innerHTML='Requested page not found [404]';
				} else if (jqXHR.status == 500) {
				document.getElementById(error).innerHTML='Internal Server Error [500].';
				} else if (exception === 'parsererror') {
				document.getElementById(error).innerHTML='Requested JSON parse failed.';
				} else if (exception === 'timeout') {
				document.getElementById(error).innerHTML='Servidor no Responde';
				} else if (exception === 'abort') {
				document.getElementById(error).innerHTML='Ajax request aborted.';
				} else {
				document.getElementById(error).innerHTML='Uncaught Error: ' + jqXHR.responseText;
				}
		   }
		   else
		   {
			
				if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
		           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
		           } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
		           } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
		           } else if (exception === 'timeout') {
	               alert('Servidor no Responde');
		           } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
		           } else {
	               console.log('Uncaught Error: ' + jqXHR.responseText);
           			}
			
			}
		   

		}, 
		complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success')
	        {
				
    	    	
			}
		},
		timeout:300000
	});

}
</script>
</head>

<body>
<div align="center" >
	<div align="center">
<?php include('../../_lib/cabecera2.php');
$item_sql='select * from item0 where ';
$item_sql.=' length(item_codigo)=6 ';
$item_sql.=' or (length(item_codigo)=8 and substring(item_codigo,1,2)="20")';
// $item_sql.=' order by item_nctlg desc,item_pctlg,item_codigo';
$item_sql.=' order by item_codigo';
$item_res=mysql_query($item_sql,$link_vcrx);
$i=0;
?>
<table>
<tr>
	<th>CODIGO</th>
    <th>P.UNIT</th>
    <th>IVA</th>
    <th>PVP</th>
    <th>NCTLG</th>
    <th>PCTLG</th>
    <th></th>
</tr>
<?php while($item_r=mysql_fetch_assoc($item_res)){?>
<tr align="right">
	<td><span class="codigo"><?php echo $item_r['item_codigo'];?></span></td>
    <td><input type="text" style="text-align:right;" size="10" class="puni" value="<?php echo $item_r['item_puni'];?>" /></td>
    <td><input type="text" style="text-align:right;" size="5" class="iva" value="<?php echo $item_r['item_iva'];?>" /></td>
    <td><input type="text" style="text-align:right;" size="10" class="pvp1" value="<?php echo $item_r['item_pvp1'];?>" /></td>
    <td align="center"><input type="text" class="nctlg" value="<?php echo $item_r['item_nctlg'];?>" /></td>
    <td align="center"><input type="text" class="pctlg" value="<?php echo $item_r['item_pctlg'];?>" /></td>
    <td><input type="button" value="Actualizar" onclick="gene_itempvp('<?php echo $i;?>')"  /> </td>
	
</tr>
<?php $i++; } ?>

</table>


<div id="ext_error"></div>
<div id="ext_list"></div>
</div>
</div>
</body>
</html>