<?php
session_start();
//include("../conexion.php");
include("../cls_conexion.php");$CNN=new ClsMySQL();include("../conexion23.php");
include("fe_funciones.php");
//++++
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("../login.php");	return;}
//++++
$HW="NC_".vbval($_SESSION['SYS_USER_ID']);
$StrGT="";$LStrMsg="S";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//++++++++++++++++++++++++++++++++++++
function NOT_GEN_SER_NUM($EMP,$DOC,&$SER,&$NUM){
	$ID=gn("MAX(id_ven)","fe_ventaz","fv_id_emp=$EMP AND fv_id_com=$DOC");
	$EMP_RUC=gs("emp_fe_ruc","empresas","id_emp=$EMP");
	if($ID==0){
		$SER="001";
		if(strcmp($EMP_RUC,"10097696794")==0 || strcmp($EMP_RUC,"10717533092")==0){
			$NUM="000003";return;
		}
		//++
		$NUM="000001";
	}else{
		$SER_MAX=gn("MAX(fv_ser_)","fe_ventaz","fv_id_emp=$EMP AND fv_id_com=$DOC");
		$NUM_MAX=gn("MAX(fv_num_)","fe_ventaz","fv_id_emp=$EMP AND fv_id_com=$DOC AND fv_ser_=".$SER_MAX)+1;
		//ZULMI MANULMENTE SE EMITIO EL 2
		if(strcmp($EMP_RUC,"10769761930") && $NUM_MAX==2){
			$NUM_MAX=$NUM_MAX+1;
		}
		//
		$SER_MAX=vbr("00".$SER_MAX,3);
		$NUM_MAX=vbr("000000".$NUM_MAX,6);
		$SER=$SER_MAX;
		$NUM=$NUM_MAX;
	}
}
//++++++++++++++++++++++++++++++++++++
$IdU=vbval($_SESSION['SYS_USER_ID']);
$PRO_ID_ALM=gn("pro_id_alm","usuarios","id_usuario=$IdU");
$REF_ID=V($_POST['TXT_REF_ID']);;
$FE_ANU="N";
$FE_GEN="N";
include("fe_emision_fun.php");
//+++++
$VP_RegXPag=10;
$LStrTR=0;//gn("count(*)","vis_facturacion_control","ID>0");
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
//++++++
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nota de credito</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="yy/fun_sunat4.js"></script>
<script type="text/javascript" src="yy/fe_emision_sunat24.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basixx.css"  />
<style type="text/css">
.cF {height:700px;width:1100px;position:relative;top:0px}
</style>
<script>
$(document).ready(function(){  
   Inicializar(); 
   var anu=gv("TXT_ANU");
   var gen=gv("TXT_GEN");
   if(anu=="S"){
	   document.getElementById("CmdG").disabled=true;
	   document.getElementById("CmdGenFE").disabled=true;
	   document.getElementById("CmdE").disabled=true;
	   document.getElementById("CmdA").disabled=true;
	   return;
   }
   if(gen=="S"){
	   document.getElementById("CmdG").disabled=true;
	   document.getElementById("CmdGenFE").disabled=true;
	   document.getElementById("CmdE").disabled=true;	   
   }
   NumAuto();
});
//+++++++++++++++++++
</script>
</head>

<body  <?php echo $LStrMsg;?>  >
<div align="center">
<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" 
action="fe_emision.php" autocomplete="off" enctype="multipart/form-data">
<!--INI_TITULO-->
<div id="DivT" class="dT" style="width:1100px" >
<img src="../img/unidades.png" class="iT" />
<div class="tT">NOTA DE CREDITO</div>
</div>
<!--FIN_TITULO-->
<div id="LINK_PDF" class="s1" style="left:477px; top: 100px; width: 200px; height: 18px;" >
</div>

<div class="s1" style="left:35px; top: 138px; width: 85px; height: 18px;">
EMPRESA</div>
<select name="Emp" id="Emp" 
class="lt" style="left:35px; top:155px; width: 100px;"
tabindex="<?php echo ++$TI;?>" onChange="EM_OC();"  >
<?php
echo LE($Emp,"N","N");	
?>
</select>

<div class="s1" style="left:141px; top: 138px; width: 130px; height: 18px;"> PUNTO DE EMISION
</div>
<select name="Alm" id="Alm" 
class="lt" style="left:139px; top:155px; width: 124px;"
tabindex="<?php echo ++$TI;?>" >
<?php
echo LA($Emp,$Alm,"N","N"); 	
?>
</select>

<div class="s1" style="left:272px; top: 138px; width: 103px; height: 18px;">
DOCUMENTO</div>
<select name="Doc" id="Doc" class="lt" style="left:270px; top:155px; width: 113px;"
tabindex="<?php echo ++$TI;?>" >
<?php
echo FCBO("com_nombre","comprobantes",
		 "id_comprobante>0 AND com_nombre IN ('NC. ELEC.')",$Doc,"N","S");
?>
</select>

<div class="s1" style="left:391px; top:120px; height: 12px;">
<input name="ChN_AUTO" type="checkbox" tabindex="<?php echo ++$TI;?>" class="lt"
id="ChN_AUTO"  value="1"  onClick="NumAuto()" 
<?php
	if(vbval($Aut)==1){
		echo " checked ";
	}
?>>
</div>
<div class="s1" style="left:411px; top:120px; width: 117px;">
NUM. AUTOMATICA</div>

<div class="s1" style="left:391px; top:138px; width: 51px; height: 12px;">
SERIE</div>
<input name="Ser"  type="text" tabindex="<?php echo ++$TI;?>"
class="lt"  id="Ser"  onBlur="_S(this);"
style="left:391px; top: 155px; width: 52px;"
value="<?php echo $Ser;?>"/>

<div class="s1" style="left:453px; top:138px; width: 78px; height: 12px;">
NUMERO</div>
<input name="Num"  type="text" tabindex="<?php echo ++$TI;?>"
class="lt"  id="Num"  onBlur="_N(this);"
style="left:454px; top: 155px; width: 71px;"
value="<?php echo $Num;?>"/>
<?php
if(strlen($Fec)==0)$Fec=date("d-m-y");
?>
<div class="s1" style="left:531px; top:138px; width: 56px; height: 12px;">
FECHA</div>
<input name="Fec"  type="text" 
class="fe"  id="Fec" 
style="left:531px; top: 155px; width: 68px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Fec;?>"/>

<div class="s1b" style="left:609px; top: 119px; width: 213px; height: 18px;">
DOCUMENTO QUE MODIFICA</div>

<div class="s1" style="left:609px; top: 138px; width: 125px; height: 18px;">
DOCUMENTO</div>
<select name="DocM" id="DocM" 
class="lt" style="left:608px; top:155px; width: 126px;"
tabindex="<?php echo ++$TI;?>" >
<?php
echo FCBO("com_nombre","comprobantes",
		  "id_comprobante>0 AND com_nombre IN ('FACT. ELEC.','BOL. ELEC.','FACTURA','BOLETA')",$DocM,"N","S");
?>
</select>

<div class="s1" style="left:740px; top:138px; width: 61px; height: 12px;">
SERIE</div>
<input name="SerM"  type="text" tabindex="<?php echo ++$TI;?>"
class="lt"  id="SerM"  onBlur="_S(this)"
style="left:740px; top: 155px; width: 48px;"
value="<?php echo $SerM;?>"/>

<div class="s1" style="left:796px; top:138px; width: 73px; height: 12px;">
NUMERO</div>
<input name="NumM"  type="text" tabindex="<?php echo ++$TI;?>"
class="lt"  id="NumM"  onBlur="_N(this)"
style="left:795px; top: 155px; width: 79px;"
value="<?php echo $NumM;?>"/>

<input name="CmdDoc" type="button" id="CmdDoc" 
onClick="fDoc();"  tabindex="<?php echo ++$TI;?>"
style="position:absolute; left:879px; top:155px; width: 32px;" 
value=">>">

<div class="s1" style="left:918px; top:138px; width: 68px; height: 20px;">
FEC. EMI.</div>
<input name="FecM"  type="text" 
class="rod"  id="FecM" 
style="left:918px; top: 155px; width: 70px;"
value="<?php echo $FecM;?>"/>

<div class="s1" style="left:994px; top:138px; width: 72px; height: 20px;">
TOTAL</div>
<input name="TotM"  type="text" 
class="rod"  id="TotM" 
style="left:992px; top: 155px; width: 73px;"
value="<?php echo $TotM;?>"/>



<div class="s1" style="left:35px; top:182px; width: 130px; height: 16px;"> RUC / DNI
</div>
<input name="Ndi"  type="text" 
class="roi"  id="Ndi" tabindex="<?php echo ++$TI;?>" 
style="left:35px; top: 199px; width: 99px;"
value="<?php echo $Ndi;?>"/>

<div class="s1" style="left:142px; top:182px; width: 255px; height: 16px;">
  RAZON SOCIAL / NOMBRES Y APELLIDOS</div>
<input name="Nom"  type="text" 
class="roi"  id="Nom" tabindex="<?php echo ++$TI;?>" 
style="left:141px; top: 199px; width: 245px;"
value="<?php echo $Nom;?>"/>

<div class="s1" style="left:396px; top:182px; width: 152px; height: 16px;">
DIRECCION</div>
<input name="Dir"  type="text" 
class="roi"  id="Dir" tabindex="<?php echo ++$TI;?>" 
style="left:394px; top: 199px; width: 258px;"
value="<?php echo $Dir;?>"/>

<div class="s1" style="left:659px; top:182px; width: 127px; height: 16px;">
EMAIL</div>
<input name="Ema"  type="text" 
class="lt"  id="Ema" tabindex="<?php echo ++$TI;?>" 
style="left:659px; top: 199px; width: 182px;"
value="<?php echo $Ema;?>"/>

<div class="s1" style="left:847px; top: 182px; width: 181px; height: 18px;">
MOTIVO DE EMISION
</div>
<select name="Tip" id="Tip" class="lt" style="left:845px; top:199px; width: 220px;"
tabindex="<?php echo ++$TI;?>" >
<?php
echo FCBOO("TRIM(CONCAT(tab,'-',des))","fe_catalogos","tab='NC'",$Tip,"N","S","o");
?>
</select>

<div class="s1" style="left:35px; top:230px; width: 141px; height: 16px;">
OBSERVACION </div>
<input name="Obs"  type="text" 
class="lt"  id="Obs" tabindex="<?php echo ++$TI;?>" 
style="left:35px; top: 250px; width: 1028px;"
value="<?php echo $Obs;?>"/>


<div class="s1b" style="left:35px; top:288px; width: 260px; height: 16px;">
DETALLE DE NOTA DE CREDITO </div>
<div class="s1" style="left:35px; top:308px; width: 93px; height: 16px;">
CODIGO</div>
<input name="Kod"  type="text" 
class="lt"  id="Kod" tabindex="<?php echo ++$TI;?>" 
style="left:35px; top: 326px; width: 89px;"
value="<?php echo $Kod;?>"/>

<div class="s1" style="left:133px; top:308px; width: 581px; height: 16px;">
DESCRIPCION </div>
<input name="Des"  type="text" 
class="lt"  id="Des" tabindex="<?php echo ++$TI;?>" 
style="left:132px; top: 326px; width: 593px;"
value="<?php echo $Des;?>"/>

<div class="s1" style="left:731px; top:294px; width: 69px; height: 16px;">
PRE. UNI. <b>Inc. Igv</b>
</div>
<input name="Pre"  type="text" 
class="ndd"  id="Pre"  onKeyUp="CalImporte();"
style="left:731px; top: 326px; width: 64px;" tabindex="<?php echo ++$TI;?>" 
value="<?php echo $Pre;?>"/>

<div class="s1" style="left:803px; top:308px; width: 53px; height: 20px;">
CANT</div>
<input name="Can"  type="text" 
class="ned"  id="Can"  onKeyUp="CalImporte()"
style="left:803px; top: 326px; width: 52px;" tabindex="<?php echo ++$TI;?>" 
value="<?php echo $Can;?>"/>

<div class="s1" style="left:866px; top:308px; width: 53px; height: 20px;">
PIEZAS</div>
<input name="Pie"  type="text" 
class="ned"  id="Pie"  onKeyUp="CalImporte()"
style="left:866px; top: 326px; width: 52px;" 
tabindex="<?php echo ++$TI;?>" 
value="<?php echo $Pie;?>"/>

<div class="s1" style="left:928px; top:308px; width: 53px; height: 20px;">
IMPORTE</div>
<input name="Imp"  type="text" 
class="rod"  id="Imp" 
style="left:925px; top: 326px; width: 74px;"
value="<?php echo $Imp;?>"/>

<input name="CmdAdd" type="button" id="CmdAdd" 
onClick="fAdd();"  tabindex="<?php echo ++$TI;?>"
style="position:absolute; left:1005px; top:326px; width: 64px;" 
value="Agregar">

<input name="CMD_UP" type="button" id="CMD_UP" 
onClick="SM('XYZ')"  tabindex="<?php echo ++$TI;?>"
style="position:absolute; left:1005px; top:342px; width: 64px; height: 44px;visibility:hidden" 
value="Agregar">
<!--INI_BOTONES----->
<?php
	$BUSCAR="fe_emision_b.php";
	$F_A="flAnular()";
	$F_E="flEliminar()";
	//++
?>
<?php 
	include("botones_fe_ex.php");
?>
<!--FIN_BOTONES-->
<!--INI_TABLA----->
<div class="datagrid" 
style="position:absolute; left: 36px; top: 363px; width: 1034px; height: 287px; overflow:auto">
<table width="75%" id="T_D">
<thead>
<tr>
<th width="2%">#</th>
<th width="10%">CODIGO</th>
<th width="63%">DESCRIPCION</th>
<th width="4%" >PRECIO</th>
<th width="5%" >CANT</th>
<th width="5%" >PIEZAS</th>
<th width="6%" >IMPORTE</th>
<th width="3%" >&nbsp;</th>
<th width="2%" >&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$Tot=gn("SUM(imp_)","fe_ventas_det_te","hw='$HW'");
$Sto=$Tot / 1.18;
$Igv=$Tot - $Sto;
$Sto=round($Sto,2);
$Igv=round($Igv,2);
//
$X_IMPORTE=0;
//
$CX=0;
$s="SELECT * FROM fe_ventas_det_te WHERE cx>0 AND hw='$HW' ORDER BY cx ";
$rs = grs($s);
while ($r = $rs->fetch_assoc()){
	$CX++;
	$X_IMPORTE=$X_IMPORTE+$r['imp_'];
?>
	<tr >
	<!----------------------------------------------->
    <td valign="top"><?php echo $CX;?></td>
	<td valign="top"><?php echo $r['cod']."x".$r['pie'];?></td>
    <td valign="top"><?php echo $r['des'];?></td>
    <td valign="top" align="right"><?php echo $r['pre_'];?></td>
    <td valign="top" align="right"><?php echo $r['can_'];?></td>
    <td valign="top" align="right"><?php echo $r['pie_'];?></td>    
    <td valign="top" align="right"><?php echo NF2($r['imp_'],1);?></td>
    <!----------------------------------------------->	
    <td bgcolor="#FFFFFF" align="center">
	<a href="javascript:void(0)" 
    onClick="fE(<?php echo $r['cx'];?>);">
	<img src="img/b_edit.png"  border="0"/></a></td>
    <td bgcolor="#FFFFFF" align="center">
	<a href="javascript:void(0)" 
    onClick="fK(<?php echo $r['cx'];?>);">
	<img src="img/eliminar.png"  border="0"/></a></td>
	</tr>    
<?php
}
?>
</tbody>
</table>
</div>
<?php
$X_UNO=$X_IMPORTE / 118;
$X_IG=round($X_UNO * 18,2);
$X_ST=$X_IMPORTE - $X_IG;
$X_TO=$X_ST + $X_IG;	
//
$Sto=$X_ST;
$Igv=$X_IG;
$Tot=$X_TO;
?>
<!--FIN_TABLA----->
<input name="TXT_TI" id="TXT_TI" type="hidden" value="<?php echo $CX?>">
<input name="TXT_HW" id="TXT_HW" type="hidden" value="<?php echo $HW;?>">
<input name="TXT_KI" id="TXT_KI" type="hidden" value="">
<div class="s1" style="left:628px; top:662px; width: 72px; height: 20px;"> SUB TOTAL
</div>
<input name="Sto"  type="text" 
class="rod"  id="Sto" 
style="left:703px; top: 659px; width: 91px;"
value="<?php echo number_format($Sto,2,'.','');?>"/>

<div class="s1" style="left:804px; top:662px; width: 27px; height: 20px;">IGV</div>
<input name="Igv"  type="text" 
class="rod"  id="Igv" 
style="left:835px; top: 659px; width: 78px;"
value="<?php echo number_format($Igv,2,'.','');?>"/>

<div class="s1" style="left:925px; top:662px; width: 44px; height: 20px;">
TOTAL</div>
<input name="Tot"  type="text" 
class="rod"  id="Tot" 
style="left:975px; top: 659px; width: 95px;"
value="<?php echo number_format($Tot,2,'.','');?>"/>
<!--INI_OCULTOS-------------------------------->
<?php include("ocultos.php");?>
<input name="TxtKI" type="hidden" value="" id="TxtKI">
<input name="TXT_ANU" type="hidden"  id="TXT_ANU" value="<?php echo $FE_ANU;?>">
<input name="TXT_GEN" type="hidden"  id="TXT_GEN" value="<?php echo $FE_GEN;?>">
<input name="TxtCX" type="hidden" value="<?php echo $CX;?>" id="TxtCX">
<!--FIN_OCULTOS-------------------------------->
</form>
</div>
</div>
</body>
</html>
