<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Editar Factura</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />

</head>
<?php
include "../../conn.php";
include "../../class.nroenletraver2.php";
include "../../general.php";

//index.php?pkyTicket=2&user=Luigi
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

$cod_nota_venta = $_GET["pkySalesNote"];
$cod_factura = $_GET["pkySalesLedger"];
$action = $_GET["action"];
$cont = $_GET["cont"];
$nombree = $_POST["nombre"];
$glosae = $_POST["glosa"];

//$mostrar_asiento_cc = $_GET["showCC"];
$usuario = $_GET["user"];

//$n_decimales = 6;
?>
<body>

<?php
//si action es edit

if ($action == "edit" && $cod_nota_venta != NULL && $cod_factura != NULL) {
	$resultfac = mysqli_query($link, "update txsSalesLedger set fldName='$nombree', txtDescription='$glosae' where pkySalesLedger='$cod_factura';");
	$resultnv = mysqli_query($link, "update slsSalesNote set txtDescription='$glosae' where pkySalesNote='$cod_nota_venta';");
	$mensaje='Registros guardados exitosamente';
	$cont=$cont-1;
}

// lectura datos factura

$result = mysqli_query($link, "select a.fldNumber as nro_fac, d.fldAuthorization as nro_auto,
a.fldDate as fecha, a.fldControlCode as cod_control, 
a.fldName as cliente, a.fldNIT as nit_cli, a.txtDescription as glosa, 
a.fldNetTotal as total, a.sysEnabled as enabled, 
a.sysAuthorized as authorized, b.pkySalesNote as cod_nota_venta, 
b.codCurrency as cod_moneda, b.codExchangeRate as cod_tc, b.fldGlobalDiscountPercent as desc_global, c.fldName as moneda, d.fldEmissionDate as fecha_limite, 
d.txtDescription as leyenda, e.fldID as nro_suc, 
e.fldName as sucursal, e.fldPhone as tel_suc,
e.fldAddress as dir_suc, f.fldName as ciu_suc, 
b.codType as cod_tipo, a.codClient as cod_cliente, b.codItemMovement as cod_mov_merc
from
txsSalesLedger a, slsSalesNote b, actCurrency c, 
txsAuthorizationControl d, agnCompanyBranch e, 
regCity f
where
a.pkySalesLedger = b.codInvoice and 
a.codAuthorizationControl = d.pkyAuthorizationControl and 
d.codCompanyBranch = e.pkyCompanyBranch and 
e.codCity = f.pkyCity and 
b.codInvoice = '$cod_factura' and 
b.codCurrency = c.pkyCurrency;");
	while ($row = mysqli_fetch_array($result)) {
		$nro_fac = $row['nro_fac'];
		$nro_auto = $row['nro_auto'];
		$fecha_fac = $row['fecha'];
		$cod_control = $row['cod_control'];
		$cliente = $row['cliente'];
		$nit_cli = $row['nit_cli'];
		$total = $row['total'];
		$cod_nota_venta = $row['cod_nota_venta'];
		//$cod_moneda = $row['cod_moneda'];
		$moneda = $row['moneda'];
		//$cod_tc = $row['cod_tc'];
		$fecha_limite = $row['fecha_limite'];
		$sucursal = $row['sucursal'];
		//$nro_sucursal = $row['nro_suc'];
		//$tel_sucursal = $row['tel_suc'];
		//$dir_sucursal = $row['dir_suc'];
		//$ciu_sucursal = $row['ciu_suc'];
		//$desc_global = $row['desc_global'];
		
		//$leyenda = $row['leyenda'];
		//$leyenda = nl2br($leyenda);//quita salto de linea 
		//$leyenda = str_replace('\n','<br />',$leyenda);//reemplaza para salto de linea
				
		$glosa = $row['glosa'];
		//$glosa = nl2br($glosa);//quita salto de linea 
		//$glosa = str_replace('\n','<br />',$glosa);//reemplaza para salto de linea
		//$glosa = substr($glosa, 0, 200); //era necesario para cortar la glosa
		$enabled = $row['enabled'];
		$authorized = $row['authorized'];
		//$cod_tipo = $row['cod_tipo'];//tipo  si es 1=efectivo, 5=CxC
		//$cod_cliente = $row['cod_cliente'];//codigo del cliente de la factura
		//$cod_mov_merc = $row['cod_mov_merc'];//codigo mov de merc para lotes
		if($enabled == 1) { 
			$anulado = 'No'; 
		} else { 
			$anulado = 'Si';
		}
	}
	mysqli_free_result($result);
	

	

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Editar Factura</b></font></center></p>
<form method="post" action="edit.php?action=edit&pkySalesNote=<?php echo $cod_nota_venta; ?>&pkySalesLedger=<?php echo $cod_factura; ?>&cont=<?php echo $cont; ?>&user=<?php echo $usuario; ?>">
<table border="1" align="center" cellpadding="2" width="30%">
    <TR> 
    <TD width="50%"><b>Nro. Factura: </b></TD><TD><?php echo $nro_fac; ?></TD>
    </TR>
    <TR>
    <TD><b>Nro. Auto.: </b></TD><TD><?php echo $nro_auto; ?></TD>
    </TR>
    <TR>
    <TD><b>Fecha: </b></TD><TD><?php echo $fecha_fac; ?></TD>
    </TR>
    <TR>
    <TD><b>Cod. Control: </b></TD><TD><?php echo $cod_control; ?></TD>
    </TR>
    <TR>
    <TD><b>Cod. Nota Venta: </b></TD><TD><?php echo $cod_nota_venta; ?></TD>
    </TR>
    <TR>
    <TD><b>Moneda: </b></TD><TD><?php echo $moneda; ?></TD>
    </TR>
    <TR>
    <TD><b>Total: </b></TD><TD><?php echo number_format($total,2); ?></TD>
    </TR>
    <TR>
    <TD><b>Fecha Lim.: </b></TD><TD><?php echo $fecha_limite; ?></TD>
    </TR>
    <TR>
    <TD><b>Sucursal: </b></TD><TD><?php echo $sucursal; ?></TD>
    </TR>
    <TR>
    <TD><b>Anulado: </b></TD><TD><?php echo $anulado; ?></TD>
    </TR>
    <TR>
    <TD><b>NIT: </b></TD><TD><?php echo $nit_cli; ?></TD>
    </TR>
    <TR>
    <TD><b>Nombre: </b></TD><TD><input type="text" size="52" maxlength="150" name="nombre" value="<?php echo $cliente; ?>" /></TD>
    </TR>
    <TR>
    <TD><b>Glosa: </b></TD><TD><textarea rows="10" cols="40" name="glosa" maxlength="1000"><?php echo $glosa; ?></textarea></TD>
    </TR>
    <TR>
    <TD colspan="2" align="center"><br/><INPUT TYPE="submit" VALUE="Guardar" class="formulario"><br/></TD>
    </form>
    </TR>
</table>

<br />
<p><center><font color="#FF0000" size="+1"><b><?php echo $mensaje; ?></b></font></center></p>
<p><center><a href="javascript:history.go('<?php echo $cont; ?>');"><b>VOLVER AL REPORTE</b></a></center></p>
</body>
</html>
