<?php require_once('Connections/conexionabm.php');
date_default_timezone_set('America/St_Lucia'); ?>

<?php
session_start();

if ($_SESSION['enviado'] == 0)
{
	echo '<script language = javascript>
	self.location = "index1.php"
	</script>';
}
 
$sigla = '';
$sigla = $_SESSION['sigla'];
$_SESSION['tipo'] = 'RC'; //Registr Documento Contabilidad

$idcliente = 0;
$idproducto = 0;
$totdebito = 0;
$totcredito = 0;
$debito = 0;
$credito = 0;

$tipo = $_SESSION['tipo'];

$valorfact = 0;
$impuesto = 0;
$totalfact = 0;

$maquina = $_SESSION['maquina'];
$ip = $_SESSION['ip'];

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	$date=$_SESSION['fecha'];
	$fechafact=implode('-',array_reverse(explode('-',$date)));
	$numfact = $_SESSION['numfact'];
	
	$_SESSION['ncfnumero']  ='';
	//------------------------------------------------------------------------------------------------------------------
	$consultaCta= "SELECT * FROM cont_contamov WHERE numdocument = $numfact"; 
	$resultadoCta= mysql_query($consultaCta,$conex) or die (mysql_error());
	$fila1=mysql_fetch_array($resultadoCta);
	
	if (!$fila1[0]) //opcion1: Si el usuario NO existe o los datos son INCORRRECTOS
	{
		echo '<script language = javascript>
		alert("Este documento no tiene movimientos registrado, Razon por la cual no puede ser impreso...")
		</script>';
	}
	else //opcion2: Usuario logueado correctamente
	{

	//-------------------------------------------------------------------------------------------------------------------

	 $insertSQL = sprintf("INSERT INTO encabezado (idcliente, tipo, numfact, valorfact, impuesto, totalfact, fecha, nombre, direccion, rnc, telefono, celular, 
	 email, termino, entregara, inicialncf, ncf, nombreuser, sigla, ip, maquina) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 
	 %s, %s, %s, %s)",
							   GetSQLValueString($_SESSION['idcliente'], "int"),
							   GetSQLValueString($tipo, "text"),
							   GetSQLValueString($_SESSION['numfact'], "int"),
							   GetSQLValueString($_SESSION['totalfact'], "decimal"),
							   GetSQLValueString($_SESSION['itbis'], "decimal"),
							   GetSQLValueString($_SESSION['totaltotal'], "decimal"),
							   GetSQLValueString($fechafact, "date"),
							   GetSQLValueString($_SESSION['nombre'], "text"),
							   GetSQLValueString($_SESSION['direccion'], "text"),
							   GetSQLValueString($_SESSION['rnc'], "text"),
							   GetSQLValueString($_SESSION['telefono'], "text"),
							   GetSQLValueString($_SESSION['celular'], "text"),
							   GetSQLValueString($_SESSION['email'], "text"),
							   GetSQLValueString($_SESSION['termino'], "text"),
							   GetSQLValueString($_SESSION['entregara'], "text"),
							   GetSQLValueString($_SESSION['inicialncf'], "text"),
							   GetSQLValueString($_POST['ncf2'], "text"),
							   GetSQLValueString($_SESSION['nombreuser'], "text"),					   
							   GetSQLValueString($_SESSION['sigla'], "text"),					   
							   GetSQLValueString($ip, "text"),					   
							   GetSQLValueString($maquina, "text"));
		
		  mysql_select_db($database_conexionabm, $conexionabm);
		  $Result1 = mysql_query($insertSQL, $conexionabm) or die(mysql_error());
	
		$_SESSION['numfactimpr'] = $_SESSION['numfact'];
		//----------------------------------------------------------------------------------------------
		  $updateSQL = sprintf("UPDATE document SET secuencia=%s WHERE sigla = '$sigla' AND tipo = '$tipo'",
							   GetSQLValueString($_SESSION['numfact'], "int"));
		
		  mysql_select_db($database_conexionabm, $conexionabm);
		  $Result1 = mysql_query($updateSQL, $conexionabm) or die(mysql_error());
		//----------------------------------------------------------------------------------------------
		//----------------------------------------------------------------------------------------------
	//	if ($_POST['ncf2']!=''){
	//	}
		//----------------------------------------------------------------------------------------------
	
		$_SESSION['fecha'] 		= $_POST['fecha2'];
		$_SESSION['idcliente'] 	= $_POST['idcliente2'];
		$_SESSION['numfact'] 	= $_POST['numfact2'];
		$_SESSION['nombre'] 	= $_POST['nombre2'];
		$_SESSION['direccion'] 	= $_POST['direccion2'];
		$_SESSION['cedula'] 	= $_POST['cedula2'];
		$_SESSION['telefono'] 	= $_POST['telefono2'];
		$_SESSION['celular'] 	= $_POST['celular2'];
		$_SESSION['totalfact'] 	= $_POST['totalfact2'];
		$_SESSION['itbis'] 		= $_POST['itbis2'];
		$_SESSION['totaltotal'] = $_POST['totaltotal2'];
		$_SESSION['rnc'] 		= $_POST['rnc2'];
		$_SESSION['email'] 		= $_POST['email2'];
		$_SESSION['termino'] 	= $_POST['termino2'];
		$_SESSION['entregara'] 	= $_POST['entregara2'];
	
	  $insertGoTo = "print_doc_contab.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
		$insertGoTo .= $_SERVER['QUERY_STRING'];
	  }
	  header(sprintf("Location: %s", $insertGoTo));
	}
}

if ((isset($_POST["MM_insert2"])) && ($_POST["MM_insert2"] == "form2")) {
//	$date=$_SESSION['fecha'];
//	$fechafact=implode('-',array_reverse(explode('-',$date)));
	$_SESSION['document'] = $_POST['document'];
	$_SESSION['numfact'] = $_POST['numfact'];
	$_SESSION['benefic'] = $_POST['benefic'];
	$_SESSION['concepto'] = $_POST['concepto'];
	$_SESSION['debito'] = $_POST['debito2'];
	$_SESSION['credito'] = $_POST['credito2'];
	
	$descripcion = $_POST['descripcion'];
	$debito = 0;
	$credito = 0;
	if ($_POST['debito2'] != ''){
		$debito = $_POST['debito2'];
	}
	//--------------------------------
	if ($_POST['credito2'] != ''){
		$credito = $_POST['credito2'];
	}
	//--------------------------------
	if ($debito > 0 && $credito > 0){
		echo '<script language = javascript>
		alert("No puede introducir un valor Debito y Otro Credito en el Mismo Movimiento, Debe registrar el Debito o el Credito, Uno a la Vez...")
		</script>';		
	}	
	else
	{
		$insertSQL = sprintf("INSERT INTO cont_contamov (cuenta, concepto, debito, credito, descripcio, benefic, fecha, numdocument, tipodoc, sigla) 
		VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

							   GetSQLValueString($_POST['cuenta'], "text"),
							   GetSQLValueString($_POST['concepto'], "text"),
							   GetSQLValueString($debito, "decimal"),
							   GetSQLValueString($credito, "decimal"),
							   GetSQLValueString($_POST['descripcion'], "text"),
							   GetSQLValueString($_POST['benefic'], "text"),
							   GetSQLValueString($_POST['fecha'], "date"),
							   GetSQLValueString($_POST['numfact'], "text"),
							   GetSQLValueString($_POST['document'], "text"),
							   GetSQLValueString($sigla, "text"));
		
		mysql_select_db($database_conexionabm, $conexionabm);
		$Result1 = mysql_query($insertSQL, $conexionabm) or die(mysql_error());
		
			$_SESSION['fecha'] 		= $_POST['fecha'];
			$_SESSION['cuenta'] 	= $_POST['cuenta'];
			$_SESSION['concepto'] 	= $_POST['concepto'];
			$_SESSION['debito'] 	= $_POST['debito'];
			$_SESSION['credito'] 	= $_POST['credito'];
			$_SESSION['descripcion'] = $_POST['descripcion'];
			$_SESSION['benefic'] 	= $_POST['benefic'];
			$_SESSION['numfact'] 	= $_POST['numfact'];
			$_SESSION['document'] 		= $_POST['document'];
							  
		  $insertGoTo = "cont_reg_document.php";
		  if (isset($_SERVER['QUERY_STRING'])) {
			$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
			$insertGoTo .= $_SERVER['QUERY_STRING'];
		  }
		  header(sprintf("Location: %s", $insertGoTo));
		}

}

$maxRows_DatosDetalle = 1000;
$pageNum_DatosDetalle = 0;
if (isset($_GET['pageNum_DatosDetalle'])) {
  $pageNum_DatosDetalle = $_GET['pageNum_DatosDetalle'];
}
$startRow_DatosDetalle = $pageNum_DatosDetalle * $maxRows_DatosDetalle;

///--------------------------------------------------------------------------------------------------------------------------

$tipodoc = $_SESSION['document'];
$numfact = $_SESSION['numfact'];

mysql_select_db($database_conexionabm, $conexionabm);
$query_DatosDetalle = "SELECT * FROM cont_contamov WHERE numdocument = '$numfact' AND tipodoc = '$tipodoc' ORDER BY id DESC";
$query_limit_DatosDetalle = sprintf("%s LIMIT %d, %d", $query_DatosDetalle, $startRow_DatosDetalle, $maxRows_DatosDetalle);
$DatosDetalle = mysql_query($query_limit_DatosDetalle, $conexionabm) or die(mysql_error());
$row_DatosDetalle = mysql_fetch_assoc($DatosDetalle);

if (isset($_GET['totalRows_DatosDetalle'])) {
  $totalRows_DatosDetalle = $_GET['totalRows_DatosDetalle'];
} else {
  $all_DatosDetalle = mysql_query($query_DatosDetalle);
  $totalRows_DatosDetalle = mysql_num_rows($all_DatosDetalle);
}
$totalPages_DatosDetalle = ceil($totalRows_DatosDetalle/$maxRows_DatosDetalle)-1;

mysql_select_db($database_conexionabm, $conexionabm);
$query_Documentos = "SELECT * FROM cont_document ORDER BY cont_document.descrip";
$Documentos = mysql_query($query_Documentos, $conexionabm) or die(mysql_error());
$row_Documentos = mysql_fetch_assoc($Documentos);
$totalRows_Documentos = mysql_num_rows($Documentos);

//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
?>
<!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" />

<script type='text/javascript' src='jquery-1.7.1.min.js'></script>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.maskedinput.js" type="text/javascript"></script>
<script type="text/javascript" src="engine1/jquery.js"></script>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script src="jquery.maskedinput-1.2.2.js" type="text/javascript"></script>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.maskedinput.js" type="text/javascript"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script>
<script src="jquery.maskMoney.js" type="text/javascript"></script>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script src="jquery.maskedinput-1.2.2.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>


<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/custom_cuenta.js"></script>
<script type="text/javascript" src="js/custom_cuentadescript.js"></script>
<script type="text/javascript" src="js/custom_cliente.js"></script>


<SCRIPT LANGUAGE="JavaScript">
	function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	// End -->
</script>


<script type="text/javascript">
    function showContent() {
        check = document.getElementById("check");
        if (check.checked) {
			document.getElementById("ncf").value = <?php echo $_SESSION['numeroncf'] ?>;
			document.getElementById("ncf2").value = <?php echo $_SESSION['numeroncf'] ?>;
//			document.getElementById("inicialncf").value = <?php echo $_SESSION['inicialncf'] ?>;
        }
        else {
			document.getElementById("ncf2").value = '';
			document.getElementById("ncf").value = '';
//			document.getElementById("inicialncf").value = '';
        }
    }
</script>
		
<script type="text/javascript">
    function CargaForm1() {
//		alert('Estamos en CargaForm1')
		fecha 		= document.getElementById("fecha").value;		
		document 	= document.getElementById("document").value;
        numfact		= document.getElementById("numfact").value;		
        benefic 	= document.getElementById("benefic").value;		
        concepto	= document.getElementById("concepto").value;		
		
//		alert(nombre)
        document.getElementById("numfact").value = numfact;
        document.getElementById("benefic").value = benefic;
        document.getElementById("concepto").value = concepto;
    }	
</script>
    
<script type="text/javascript">
function justNumbers(e)
        {
        var keynum = window.event ? window.event.keyCode : e.which;
        if ((keynum == 8) || (keynum == 46))
        return true;
         
        return /\d/.test(String.fromCharCode(keynum));
        }
</script>


<script type="text/javascript">
function separarDebito(Elemento){
    //0123456789
    //deve de quedar $123,456,789.00
    //del elemento que obtenemos su valor
	//	alert('Estamos en Dinero');

	document.form2.debito2.value	= document.form2.debito.value;

    var valor=Elemento.value;
    var valorDecimal;
    var agregar00=true;
    if(valor.indexOf("$")!=-1){
    }else{
        //se compara para ver si tiene decimales
        if(valor.indexOf(".")!=-1){
            //si tiene decimales no se la gregara el .00
            agregar00=false;
            //se separa el valor decimal del valor entero
            valorDecimal=valor.substring(valor.indexOf("."), largo);
            valor=valor.substring(0, valor.indexOf("."));
        }
        //se toma el valor del entero
        var largo=valor.length;
        if(largo>9){
            valor=valor.substring(largo-12,largo-9)+","+valor.substring(largo-9,largo-6)+","+valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }else
        if(largo>6){
            valor=valor.substring(largo-9,largo-6)+","+valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }else
        if(largo>3){
            valor=valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }
        valor="$"+valor;
        if(agregar00==true){
            valor=valor+".00"
        }else{
            valor=valor+valorDecimal;
        }
        Elemento.value=valor;
    }
}
</script>

<script type="text/javascript">
function separarCredito(Elemento){
    //0123456789
    //deve de quedar $123,456,789.00
    //del elemento que obtenemos su valor
	//	alert('Estamos en Dinero');

	document.form2.credito2.value	= document.form2.credito.value;

    var valor=Elemento.value;
    var valorDecimal;
    var agregar00=true;
    if(valor.indexOf("$")!=-1){
    }else{
        //se compara para ver si tiene decimales
        if(valor.indexOf(".")!=-1){
            //si tiene decimales no se la gregara el .00
            agregar00=false;
            //se separa el valor decimal del valor entero
            valorDecimal=valor.substring(valor.indexOf("."), largo);
            valor=valor.substring(0, valor.indexOf("."));
        }
        //se toma el valor del entero
        var largo=valor.length;
        if(largo>9){
            valor=valor.substring(largo-12,largo-9)+","+valor.substring(largo-9,largo-6)+","+valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }else
        if(largo>6){
            valor=valor.substring(largo-9,largo-6)+","+valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }else
        if(largo>3){
            valor=valor.substring(largo-6,largo-3)+","+valor.substring(largo-3, largo);
        }
        valor="$"+valor;
        if(agregar00==true){
            valor=valor+".00"
        }else{
            valor=valor+valorDecimal;
        }
        Elemento.value=valor;
    }
}
</script>

<style type="text/css">
#form1 table tr td {
	font-family: Arial, Helvetica, sans-serif;
}
#form1 table {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: normal;

}

.normal {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: normal;
	color: #000;
}
.normal2 {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.brillo:hover {
	background-color: #EFD776;
	color: #CCC;
}

#form2 table {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}

.artic {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;	
	background:#FF0
}

.style7 {color: #000066; font-weight: normal;}

.total {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	background:#FF0;
	font-weight: bold;
}

.titulos {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}

.titulos2 {
	font-size: 14px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}
.encabez {
	font-size: 16px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #009;
}

.coloruser {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	font-weight: bold;
	color: #FF0000;
}

.desc {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #FF0000;
}

inic {
	font-size: 14px;
}
chkderecha {
	text-align: right;
}

//------------------

.button {
   line-height:1em;
   border: 1px solid #999;
	box-shadow: 5px 5px 10px #888888; /* sombra */
	width:120px;
	height:30px;  
	background: #80BFFF;
	border-radius: 6px;
}

.button:hover, r {
   background: -moz-linear-gradient(
      center top,
      rgba(255, 255, 255, .2) 0%,
      rgba(255, 255, 255, .1) 100%
   );
   background: -webkit-gradient(
      linear,
      center bottom,
      center top,
      from(rgba(255, 255, 255, .1)),
      to(rgba(255, 255, 255, .2))
   );
}

.textbox2 {
  border: 1px solid #A8D3FF;
  font-size: 12px;
  font-family: Arial, Verdana;
  border-radius: 4px;
  color: #2E3133;
  background-color: #FF9;
  padding: 4px;
  height:20;
}

.textbox {
  border: 1px solid #A8D3FF;
  font-size: 12px;
  font-family: Arial, Verdana;
  border-radius: 4px;
  color: #2E3133;
  padding: 4px;
  height:20;
}

.textbox:hover {
  background: #E8FFFF;
  border-color: #F5C27E;
}

.textbox:focus
  {
  border-color: #FC6;
}
	
input[type="checkbox"]{
 border: 0px;
 width: 12px;
 height: 12px;
 border-radius: 4px;
}	   

.checkbox:hover, .checkbox.hover {
  background:#FFFFAE ;
  border-color: #F5C27E;
}

</style>

<title><?php echo $_SESSION['cia'] ?></title>

<script type="text/javascript"> 
function Cantidad() 
{ 
//	alert("Estamos dentro de cantidad");
	document.form2.total.value = document.form2.cant.value * document.form2.precio.value 
}
</script>



<script type="text/javascript">
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
</head>

<body onload="MM_preloadImages('imagenes/Delete2.jpg','imagenes/OPEN.jpg','botoncancelarfact2.jpg')">
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th scope="col">
    <table width="800" bgcolor="#BAD7B0" border="1" style="border-collapse: collapse; font-family: Arial, Helvetica, sans-serif;" bordercolor="#CCCCCC" align="center">
      <tr>
        <td width="810" align="center" bgcolor="#D9F2CE"><a href="index1.php"><img src="imagenes/logo1.jpg" alt="" width="800" height="100" /></a></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF">&nbsp;</td>
      </tr>
      <tr>
        <td bgcolor="#B9E9FF"><form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
          <table width="810" align="center">
            <tr valign="baseline">
              <td width="802" align="left" nowrap="nowrap" ><table width="806" align="center">
                <tr valign="baseline" bgcolor="#000099">
                  <td width="125" height="18" align="right" valign="middle" nowrap="nowrap"><a href="index1.php" class="titulos"><span class="titulos2">INICIO</span></a><span class="titulos2"> - </span></td>
                  <td colspan="3" valign="middle" class="encabez"><span class="titulos"><span class="titulos2">&nbsp;- REGISTRO DOCUMENTOS DE CONTABILIDAD</span></span></td>
                  <td width="270" valign="middle" class="titulos"><?php echo $_SESSION['nombreuser'] ?> <?php echo $_SESSION['apellidouser'] ?></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" nowrap="nowrap"><span class="normal">Fecha :</span></td>
                  <td width="257" align="left" valign="middle"><span class="normal">
                    <input type="text" name="fecha" id="fecha" value="<?php echo date("d-m-Y"); ?>" class="textbox" size="10" />
                    </span></td>
                  <td width="79" height="27" align="right" valign="middle"  class="justicatabla">&nbsp;</td>
                  <td width="51" align="left" valign="middle">&nbsp;</td>
                  <td align="left" valign="middle">&nbsp;</td>
                </tr>
                <tr valign="baseline">
                  <td height="17" align="right" valign="middle"  class="justicatabla">&nbsp;</td>
                  <td align="left" valign="middle">&nbsp;</td>
                  <td valign="middle">&nbsp;</td>
                  <td valign="middle">&nbsp;</td>
                  <td align="left" valign="middle">&nbsp;</td>                  
                </tr>
                <tr valign="baseline">
                  <td height="17" align="right" valign="middle" nowrap="nowrap" class="normal">Tipo de Documento :</td>
                  <td align="left" valign="middle"><select name="document" id="document" class="textbox" onchange="javascript:showTarjeta()" >
                    <?php
do {  
?>
                    <option value="<?php echo $row_Documentos['tipodoc']?>"><?php echo $row_Documentos['descrip']?></option>
                    <?php
} while ($row_Documentos = mysql_fetch_assoc($Documentos));
  $rows = mysql_num_rows($Documentos);
  if($rows > 0) {
      mysql_data_seek($Documentos, 0);
	  $row_Documentos = mysql_fetch_assoc($Documentos);
  }
?>
                  </select></td>
                  <td height="27" align="right" valign="middle"  class="justicatabla"><span class="coloruser"> Numero :</span></td>
                  <td colspan="2" align="left" valign="middle"><span class="normal">
                    <input name="numfact" id="numfact" type="text" class="textbox" value="<?php echo $_SESSION['numfact'] ?>" style="color:#F20000" size="5" onblur="CargaForm1()"/>
                  </span></td>
                  </tr>
                <tr valign="baseline">
                  <td height="17" align="right" valign="middle" nowrap="nowrap" class="normal">Beneficiario  :</td>
                  <td colspan="4" align="left" valign="middle"><label for="benefic"></label>
                    <input name="benefic" type="text" id="benefic" class="textbox" value="<?php echo $_SESSION['benefic'] ?>" size="62" onblur="CargaForm1()"/></td>
                  </tr>
                <tr valign="baseline">
                  <td height="17" align="right" valign="middle" nowrap="nowrap" class="normal">Concepto :</td>
                  <td colspan="4" align="left" valign="middle"><label for="concepto"></label>
                    <textarea name="concepto" id="concepto" cols="64" class="textbox" rows="3" onblur="CargaForm1()"><?php echo $_SESSION['concepto'] ?></textarea></td>
                  </tr>
              </table></td>
              </tr>
            <tr valign="baseline">
              <td height="221" align="left" nowrap="nowrap"><table width="800" border="1" cellspacing="0" style="border-collapse: collapse; padding-top: 0px; font-family: Arial, Helvetica, sans-serif;" bordercolor="#CCCCCC" align="left" bgcolor="#FFFFFF">
                  <tr bgcolor="#000099" class="titulos2">
                    <th height="17" colspan="2" align="left" class="titulos2" scope="col">CUENTA</th>
                    <th align="left" class="titulos2" scope="col">DESCRIPCION</th>
                    <th align="right" class="titulos2" scope="col">DEBITO</th>
                    <th align="right" class="titulos2" scope="col">CREDITO</th>
                    <th colspan="2" align="right" class="titulos2" scope="col">&nbsp;</th>
                    </tr>
                  <tr bgcolor="#EFD776" class="brillo">
                    <th width="22" height="35" align="left" class="normal" scope="col"><a href="list_busca_cuenta2.php"><img src="botonbuscar.jpg" alt="Buscar Cuenta por su Descripcion" width="21" height="20" /></a></th>
                    <th width="94" align="left" class="normal" scope="col"><span class="form-group col-md-6 col-md-offset-3">
                      <input name="cuenta" id="buscacuenta" type="text" autofocus="autofocus" class="textbox2"     style="text-align: right" step="any" value="<?php echo $_SESSION['cuenta'] ?>" size="7"/>
                    </span></a></th>
                    <th align="left" class="normal" scope="col"><span class="form-group col-md-6 col-md-offset-3">
                    <input name="descripcion" type="text" class="textbox2" id="buscadescript" placeholder="Articulo a Buscar" value="<?php echo $_SESSION['descripcion'] ?>" size="50" />
                      </span></th>
                    <th align="right" class="normal" scope="col">
                    <input name="debito" id="debito" type="text" class="textbox2" size="10" style="text-align: right"  onblur="separarDebito(this)"/></th>
                    <th align="right" class="normal" scope="col">
                    <input name="credito" id="credito" type="text" class="textbox2" size="10" style="text-align: right" onblur="separarCredito(this)"/></th>
                    <th colspan="2" align="right" class="normal" scope="col"><input type="submit" value="Aceptar" /></th>
                    </tr>
                  <tr bgcolor="#FFFFFF" class="brillo">
                    <th colspan="2" align="left" class="normal" scope="col">&nbsp;</th>
                    <th align="left" class="normal" scope="col">&nbsp;</th>
                    <th align="right" class="normal" scope="col">&nbsp;</th>
                    <th align="right" class="normal" scope="col">&nbsp;</th>
                    <th colspan="2" align="right" class="normal" scope="col">&nbsp;</th>
                    </tr>
                <?php do { ?>
                    
				<?php               
					$totdebito = $totdebito + $row_DatosDetalle['debito'];
                    $totcredito = $totcredito + $row_DatosDetalle['credito'];
				?>
                  <tr bgcolor="#FFFFFF" class="brillo">                  
                    <th colspan="2" align="left" class="normal" scope="col"><?php echo $row_DatosDetalle['cuenta']; ?></th>
                    <th width="325" align="left" class="normal" scope="col"><?php echo $row_DatosDetalle['descripcio']; ?></th>
                    <th width="117" align="right" class="normal" scope="col"><?php echo number_format($row_DatosDetalle['debito'],2); ?></th>
                    <th width="154" align="right" class="normal" scope="col"><?php echo number_format($row_DatosDetalle['credito'],2); ?></th>
                    <th width="31" align="center" class="normal" scope="col"><a href="elimina_cuenta_doc.php?recordID=<?php echo $row_DatosDetalle['id']; ?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','imagenes/Delete2.jpg',1)"><img src="imagenes/DELETE.jpg" alt="1" name="Image3" width="16" height="15" id="Image3" /></a></th>
                    <th width="27" align="center" class="normal" scope="col"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','imagenes/OPEN.jpg',1)"><img src="imagenes/edit3.jpg" alt="2" name="Image" width="16" height="17" id="Image" /></a></th>
                    </tr>
                  <?php } while ($row_DatosDetalle = mysql_fetch_assoc($DatosDetalle)); ?>
                
                <tr class="brillo">
                  <th colspan="2" align="left" scope="col">&nbsp;</th>
                  <th align="left" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th colspan="2" align="right" scope="col">&nbsp;</th>
                  </tr>
                <tr class="brillo">
                  <th colspan="2" align="left" scope="col">&nbsp;</th>
                  <th align="left" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th colspan="2" align="right" scope="col">&nbsp;</th>
                  </tr>
                <tr class="brillo">
                  <th colspan="2" align="left" scope="col">&nbsp;</th>
                  <th align="left" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th align="right" scope="col">&nbsp;</th>
                  <th colspan="2" align="right" scope="col">&nbsp;</th>
                  </tr>
                <tr class="brillo">
                  <th colspan="7" align="left" scope="col">&nbsp;</th>
                  </tr>
                <tr class="brillo">
                  <th colspan="2" align="left" scope="col">&nbsp;</th>
                  <th align="left" scope="col"><span class="normal">
                    <input name="debito2" id="debito2" type="text" class="textbox2" size="10" style="text-align: right"  />
                    <input name="credito2" id="credito2" type="text" class="textbox2" size="10" style="text-align: right" />
                  </span></th>
                  <th align="right" class="coloruser" scope="col"><?php echo number_format($totdebito,2)?></th>
                  <th align="right" class="coloruser" scope="col"><?php echo number_format($totcredito,2)?></th>
                  <th colspan="2" align="right" scope="col">&nbsp;</th>
                  </tr>
                </table></td>
            </tr>
            </table>
          <input type="hidden" name="MM_insert2" value="form2" />
        </form>
          <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
            <table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th height="31" scope="col"><a href="cancelar_fact.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','botoncancelarfact2.jpg',1)"><img src="botoncancelarfact.jpg" alt="Cancelar Factura Actual..." name="Image6" width="146" height="22" id="Image6" class="button"/></a>                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</th>
                <th align="left" scope="col"><input type="submit" value="Guardar e Imprimir Factura" class="button"/></th>
              </tr>
            </table>
            <p>
              <input type="hidden" name="MM_insert" value="form1" />
              <input type="hidden" name="ncf2" class="coloruser" id="ncf2" value="" size="8" />

              <input name="porcdesc" type="hidden" id="porcdesc" size="5" />
              <input name="vlordesc" type="hidden" id="vlordesc" size="5" />

              <input type="hidden" name="fecha2" id="fecha2" value="<?php echo $_SESSION['fecha'] ?>" size="5" />
              <input type="hidden" name="idcliente2" id="idcliente2" value="<?php echo $_SESSION['idcliente'] ?>" size="5" />
              <input type="hidden" name="numfact2" id="numfact2" value="<?php echo $_SESSION['numfact'] ?>" size="5" />
              <input type="hidden" name="rnc2" id="rnc2" value="<?php echo $_SESSION['rnc'] ?>" size="10" />
              <input type="hidden" name="nombre2" id="nombre2" value="<?php echo $_SESSION['nombre'] ?>" size="16" />
              <input type="hidden" name="direccion2" id="direccion2" value="<?php echo $_SESSION['direccion'] ?>" size="64" />
              <input type="hidden" name="telefono2" id="telefono2" value="<?php echo $_SESSION['telefono'] ?>" size="10" />
              <input type="hidden" name="celular2" id="celular2" value="<?php echo $_SESSION['celular'] ?>" size="10" />
              <input type="hidden" name="email2" id="email2" value="<?php echo $_SESSION['email'] ?>" size="32" />
              <input type="hidden" name="termino2" id="termino2" value="<?php echo $_SESSION['termino'] ?>" size="22" />
              <input type="hidden" name="entregara2" id="entregara2" value="<?php echo $_SESSION['entregara'] ?>" size="32" />
              <input type="hidden" name="tipopago2" id="tipopago2" value="<?php echo $_SESSION['tipopago'] ?>" size="22" />
              <input type="hidden" name="tarjetacr2" id="tarjetacr2" value="<?php echo $_SESSION['tarjetacr'] ?>" size="22" />
              <input type="hidden" name="tarjetacr2" id="tarjetacr2" value="<?php echo $_SESSION['tarjetacr'] ?>" size="22" />
              <input type="hidden" name="tarjetacr2" id="tarjetacr2" value="<?php echo $_SESSION['tarjetacr'] ?>" size="22" />
              </span></p>
          </form></td>
      </tr>
      <tr bgcolor="#D2D2D2">
        <td bgcolor="#CCCCCC">&nbsp;</td>
      </tr>
    </table>
      <p>&nbsp;</p>
      <p>&nbsp; </p>
    <p>&nbsp;</p></th>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($DatosDetalle);
?>
