<?php 
session_start();
require('../cfg/res.php');
if($_POST['opcion']=='N')
{

$sql_num='select max(item_codigo) as nume from item0 where CAST(item_codigo AS UNSIGNED) > 100000 and CAST(item_codigo AS UNSIGNED) < 200000';
$res_num=mysql_query($sql_num,$link_vcrx);

if(mysql_num_rows($res_num)== 0)
{$num=10000;}
else
{
	$num=mysql_result($res_num,0,'nume');
	if(empty($num))
	{$num=10000;}
}

//echo $num;

$num=substr($num, 0, 5);
$num++;


require('../../_lib/vrmod11.php');

$num=$num . vrmod11($num,false);



$sql_item='insert into item0(
item_codigo,
item_descri,
item_mrca,
item_mdlo,
item_numpart,
item_medida,
item_tlla,
item_tmno,
item_kldd,
item_clor,
item_umdd,
item_unixpack,
item_codxunid,
item_codigov,
item_ean,
item_at10,
item_lsub,
item_provee,
item_pcp1,
item_puni,
item_ice,
item_iva,
item_irbp,
item_pvp1,
item_pais,
item_idate,
item_iuser
)
values(
"'.$num.'",
"'.$_POST['descri'].'",
"'.$_POST['marca'].'",
"'.$_POST['modelo'].'",
"'.$_POST['parte'].'",
"'.$_POST['medida'].'",
"'.$_POST['talla'].'",
"'.$_POST['tamanio'].'",
"'.$_POST['klidad'].'",
"'.$_POST['color'].'",
"'.$_POST['umedida'].'",
"'.$_POST['upack'].'",
"'.$_POST['cxunidad'].'",
"'.$_POST['cgenerico'].'",
"'.$_POST['cean'].'",
"'.$_POST['cinterno'].'",
"'.$_POST['lsub'].'",
"'.$_POST['proveedor'].'",
"'.$_POST['pcp'].'",
"'.$_POST['puni'].'",
"'.$_POST['ice'].'",
"'.$_POST['iva'].'",
"'.$_POST['irbp'].'",
"'.$_POST['pvp'].'",
"'.$_POST['pais'].'",
NOW(),
"'.$_SESSION['user_vcrx_id'].'"
)';
if(mysql_query($sql_item,$link_vcrx))
{
	echo $num;
}
else
{
	
	echo 'error';
}

}
//+++++++++++++++

if($_POST['opcion']=='M' && isset($_POST['opcion']) && !empty($_POST['opcion']))
{

$sql_item='update item0
set
item_descri="'.$_POST['descri'].'",
item_mrca="'.$_POST['marca'].'",
item_mdlo="'.$_POST['modelo'].'",
item_numpart="'.$_POST['parte'].'",
item_medida="'.$_POST['medida'].'",
item_tlla="'.$_POST['talla'].'",
item_tmno="'.$_POST['tamanio'].'",
item_kldd="'.$_POST['klidad'].'",
item_clor="'.$_POST['color'].'",
item_umdd="'.$_POST['umedida'].'",
item_unixpack="'.$_POST['upack'].'",
item_codxunid="'.$_POST['cxunidad'].'",
item_codigov="'.$_POST['cgenerico'].'",
item_ean="'.$_POST['cean'].'",
item_at10="'.$_POST['cinterno'].'",
item_lsub="'.$_POST['lsub'].'",
item_provee="'.$_POST['proveedor'].'",
item_pcp1="'.$_POST['pcp'].'",
item_puni="'.$_POST['puni'].'",
item_ice="'.$_POST['ice'].'",
item_iva="'.$_POST['iva'].'",
item_irbp="'.$_POST['irbp'].'",
item_pvp1="'.$_POST['pvp'].'" ,
item_pais="'.$_POST['pais'].'" 
where item_codigo="'.$_POST['codigo'].'"
';

if(mysql_query($sql_item,$link_vcrx))
{
	echo '0';
}
else
{
	
	echo 'error';
}

	
	
	
}

















?>