<?php
 
session_start();
$com = "M"; 
include("DMMYSQLG.php");
include("DF30000.inc");
include("DMMYSQLG.php");
include("DF80000.php");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>

<body>
<form name="frm1" id="frm1" method="post" >
<?php

$idRedocl=$_REQUEST['bot'];
$idBascps="";
$tipDocs="";
$tipMov='P';
$pag_reg2 = 'DW21000_PR-PRO.php';//A DONDE VA SI ES TODO OK
$pag_reg1 = 'DW21000_PR-PRO.php';//A DONDE VA SI ES ERROR
if(isset($_REQUEST['solDocs'])){
	if($_REQUEST['botPR']==""){
		echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
		echo '<meta content="1; url=DW21000_PR.php"  HTTP-EQUIV="REFRESH">';
		exit();	
	}
	else{
		echo '<input type="hidden" name="solDocs" id="solDocs" value="">';
		echo '<input type="hidden" name="botPR" id="botPR" value="'.$_REQUEST['botPR'].'">';
		$ArgsPag_reg="&solDocs=solDocs&botPR=$_REQUEST['botPR']&idpas=".date("H:i:s").date('d').date('m').date("Y");
		$tipDocs="solDocs";
		$idBascps=$_REQUEST['botPR'];	
	}
}
elseif(isset($_REQUEST['todDocs'])){
	$tipDocs="todDocs";
	$ArgsPag_reg="&todDocs=todDocs&idpas=".date("H:i:s").date('d').date('m').date("Y");
	echo '<input type="hidden" name="todDocs" id="todDocs" value="">';
}

if($_REQUEST['bot']==''){
	echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
	echo '<meta content="1; url='.$pag_reg1.'?ids=none'.$ArgsPag_reg.'"  HTTP-EQUIV="REFRESH">';
	exit();
}
$dt_redocl=mysqli_fetch_array(mysqli_query($con ,"SELECT * from dvredocl where n_reg='$idRedocl'"));
?>
<input name="bot" type="hidden" value="<? echo $_REQUEST['bot'];?>">
<input name="cargos" type="hidden" value="<? echo $dt_redocl['tot_car'];?>">
<input name="abonos" type="hidden" value="<? echo $dt_redocl['tot_abo'];?>">
<input name="notas" type="hidden" value="<? echo $dt_redocl['tot_not'];?>">
<input name="pagos" type="hidden" value="<? echo $dt_redocl['tot_pag'];?>">
  <table width="753"  align="center">
    <tr>
      <th colspan="6">Modificar Documento Cuentas X Pagar </th>
    </tr>
    <tr>
      <td width="84" nowrap>Cliente:</td>
      <td colspan="5" nowrap class="inputcodigo">
		<? if($idBascps==""){?>
        <input name="tncli" type="text" id="tncli" size="3" value="<? echo  $dt_redocl['codigo'];?>" readonly>
        <input name="tnom_alt" type="text" id="tnom_alt" size="50"  readonly
		<?php
 
		$dt_bascps = mysqli_fetch_array(mysqli_query($con ,"select CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) as nom from dxbascps where codigo = ' $dt_redocl['codigo']'"));
		//buscar el cliente por default
		echo 'value="'.$dt_bascps['nom'].'"';
		?>>
        <?php

		}else{
			echo '<input name="tncli" type="hidden" id="tncli" size="3" value = '.$idBascps.' readonly>';
			$dt_bascps = mysqli_fetch_array(mysqli_query($con ,"select codigo,CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) as nom from dxbascps where codigo = '$idBascps'"));
			echo $dt_bascps['codigo'].'-'.$dt_bascps['nom'];
		}
	  ?>
&nbsp;</td>
    </tr>
    <tr>
      <td nowrap>Fecha de revision </td>
      <td width="123" nowrap><input name="fec2" type="text" class="emplea" id="fec2" size="10" maxlength="20" readonly
			<?php

				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}else{
					echo 'value="' .chfecha($dt_redocl['fec_rev'],'Y-m-d','d/m/Y').'"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
        <input name="bot2" id="bot2" type="image" value="Cal" src="logos/cal4.jpg" />
      <script type="text/javascript">
Calendar.setup(
	{
		inputField  : "fec2",       // ID del cuadro de texto
		ifFormat    : "%d/%m/%Y",   // formato de la fecha
		button      : "bot2"      	// ID del boton
	}
);
        </script></td>
      <td width="118" nowrap>Fecha del documento:     </td>
      <td width="138" nowrap ><input name="fec" type="text" class="emplea" id="fec" size="10" maxlength="20" readonly
			<?php

				if(isset($_POST['fec'])){ //este es el truco
					echo 'value="' . $_POST['fec'] .  '"';
				}else{
					echo 'value="' .chfecha($dt_redocl['fec_doc'],'Y-m-d','d/m/Y').  '"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
        <input name="bot3" id="bot3" type="image" value="Cal" src="logos/cal4.jpg" />
<script type="text/javascript">
Calendar.setup(
	{
		inputField  : "fec",       // ID del cuadro de texto
		ifFormat    : "%d/%m/%Y",   // formato de la fecha
		button      : "bot3"      	// ID del boton
	}
);
</script>	  </td>
      <td width="104" nowrap># de Documento:</td>
      <td width="146" nowrap><input type="text" name="t1" tabindex="1" readonly
	  <?php
 
	  if(isset($_POST['t1'])){
	  	echo 'value = "' .$_REQUEST['t1']. '"';
	  }
	  else{
	  	echo 'value = "' .$dt_redocl['num_doc']. '"';
	  }
	  ?>
	  ></td>
    </tr>
    <tr>
      <td nowrap>Cuenta Contable:</td>
      <td nowrap><select name="t2" id="select" tabindex="4" >
        <?php

			$idBascps=$dt_redocl['codigo'];
			if(isset($_POST['t2'])){
				$selec=$_POST['t2'];
			}
			else{
				$selec=$dt_redocl['cve_mto'];
			}
			@$resultado=mysqli_query($con ,"select * from dvcatmov where tip_usu = 'p' and cod_usu = '$idBascps'");
			while($registro=mysqli_fetch_array($resultado))
			{
				@$sq_catcta=mysqli_query($con ,"select * from dycatcta where cta_con = '".$registro['id_cta']."'");
				@$dt_catcta=mysqli_fetch_array($sq_catcta);
	  			if($selec== $registro['id_cta']){
					echo '<option value="' . $registro['id_cta']. '" selected>' . $dt_catcta['descripcion'] . '</option>';
				}else{
					echo '<option value="' . $registro['id_cta']. '">' . $dt_catcta['descripcion'] . '</option>';
				}
			}	
		?>
      </select></td>
      <td nowrap> Sub-Total: </td>
      <td nowrap><input name="t3" type="text" id="t3" tabindex="3" onKeyUp="cal_cula(this.value)"
	  <?php
 
	  if(isset($_POST['t3'])){
	  		echo 'value = "' .$_REQUEST['t3']. '"';
	  }else{
	  		echo 'value = "'.number_format($dt_redocl['sub_tot'],2,'.','').'"';
	  }
	  ?>
	  ></td>
      <td nowrap>IVA</td>
      <td nowrap><select name="t4" id="t4" tabindex="4" onChange="cal_cula(t3.value)">
        <?php

			$selec='';
			$auxSelec=NULL;
			if(isset($_POST['t4'])){
				$auxSelec=explode("|",$_POST['t4']);
				$selec=$auxSelec[0];
			}
			else{
				$selec=$dt_redocl['cve_iva'];
			}
			@$resultado=mysqli_query($con ,"select * from dxtasiva");
			while($registro=mysqli_fetch_array($resultado))
			{
	  			if($selec.'|'.$registro['porc_iva'] == $registro['cve_iva'].'|'.$registro['porc_iva']){
					echo '<option value="' . $registro['cve_iva'].'|'.$registro['porc_iva'] . '" selected>' . $registro['conc_iva'] . '</option>';
				}else{
					echo '<option value="' . $registro['cve_iva'].'|'.$registro['porc_iva'] . '">' . $registro['conc_iva'] . '</option>';
				}
			}	
		?>
      </select></td>
    </tr>
    <tr>
      <td nowrap>Importe iva:</td>
      <td nowrap>
      <input name="t5" type="text" id="t5" tabindex="5" onKeyUp="cal_cula_deIVA(this.value)"
		<?php
 
	  if(isset($_POST['t5'])){
	  	echo 'value = "' .$_REQUEST['t5']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['iva_tot'],2,'.','').'"';
	  }
	  ?>
		>      </td>
      <td colspan="2" nowrap>Afectar Caja Chica:
        <label>
        <input name="afe_caj" type="checkbox" id="afe_caj" value="1"
			  <? 
	  	if(isset($_POST['t5'])){ 
			if(isset($_POST['afe_caj']))	echo 'checked';
		}
		else{
			if($dt_redocl['afe_caj']=='1') echo 'checked';
		}
	  
	  ?>>
        </label>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      Afectar IETU: 
      <input name="afe_ietu" type="checkbox" id="afe_ietu" value="S" 
	  <? 
	  	if(isset($_POST['t5'])){ 
			if(isset($_POST['afe_ietu']))	echo 'checked';
		}
		else{
			if($dt_redocl['afe_ietu']=='S') echo 'checked';
		}
	  
	  ?>></td>
      <td nowrap>Generar poliza </td>
      <td nowrap><input name="afe_pol" type="checkbox" id="afe_pol" value="S"
  	<? 
	  	if(isset($_POST['t5'])){ 
			if(isset($_POST['afe_pol']))	echo 'checked';
		}
		else{
			if($dt_redocl['afe_pol']=='S') echo 'checked';
		}
	  
	  ?>	  
	  ></td>
    </tr>
    <tr>
      <td nowrap>Retencion 1 </td>
      <td nowrap><select name="t8" id="t8" tabindex="8" onChange="ret(this)">
	  <option value="0|0"></option>
        <?php
 
	  $selec='';
	  $auxSelec=NULL;
	  if(isset($_POST['t8'])){
	  	$auxSelec=explode("|",$_POST['t8']);
		$selec=$auxSelec[0];
	 
	  }
	  else{
	  	$selec=$dt_redocl['ret1'];
	  }
	  @$sql=mysqli_query($con ,"select * from dvcatret");
	  $seleccion=$_POST['t8'];
	  while($reg = mysqli_fetch_array($sql)){
	  	if($selec."|$reg['tas_ret']"=="$reg['cve_ret']|$reg['tas_ret']")
	  		echo '<option value = "'.$reg['cve_ret'].'|'.$reg['tas_ret'].'" selected>'.$reg['cve_ret']. ' ' . $reg['des_ret'].'</option>';
		else
			echo '<option value = "'.$reg['cve_ret'].'|'.$reg['tas_ret'].'">'.$reg['cve_ret']. ' ' . $reg['des_ret'].'</option>';
	  }
	  ?>
      </select></td>
      <td nowrap>% Retencion : </td>
      <td nowrap><input name="t9" type="text" id="t9"  tabindex="9" readonly
	  <?php
 
	  if(isset($_POST['t9'])){
	  	echo 'value = "' .$_REQUEST['t9']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['ret1_po'],2,'.','').'"';
	  }
	  ?>
	  ></td>
      <td nowrap>Importe:</td>
      <td nowrap><input name="t10" type="text" id="t10" tabindex="10"
	  <?php
 
	  if(isset($_POST['t10'])){
	  	echo 'value = "' .$_REQUEST['t10']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['ret1_im'],2,'.','').'"';
	  }
	  ?>
	  ></td>
    </tr>
    <tr>
      <td nowrap>Retencion 2 </td>
      <td nowrap><select name="t11" id="t11" tabindex="11" onChange="ret(this)">
	  <option value="0|0"></option>
        <?php
 
		$selec='';
		$auxSelec=NULL;
		if(isset($_POST['t11'])){
			$auxSelec=explode("|",$_POST['t11']);
			$selec=$auxSelec[0];
		}
		else{
			$selec=$dt_redocl['ret2'];
		}
	  @$sql=mysqli_query($con ,"select * from dvcatret");
	  while($reg = mysqli_fetch_array($sql)){
	  	if($selec."|$reg['tas_ret']"=="$reg['cve_ret']|$reg['tas_ret']")
			echo '<option value = "'.$reg['cve_ret'].'|'.$reg['tas_ret'].'" selected>'.$reg['cve_ret']. ' ' . $reg['des_ret'].'</option>';

		else
			echo '<option value = "'.$reg['cve_ret'].'|'.$reg['tas_ret'].'">'.$reg['cve_ret']. ' ' . $reg['des_ret'].'</option>';
	  }
	  ?>
      </select></td>
      <td nowrap>% Retencion : </td>
      <td nowrap><input name="t12" type="text" id="t12" tabindex="12" readonly
	  <?php
 
	  if(isset($_POST['t12'])){
	  	echo 'value = "' .$_REQUEST['t12']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['ret2_po'],2,'.','').'"';
	  }
	  ?>
	  ></td>
      <td nowrap>Importe:</td>
      <td nowrap><input name="t13" type="text" id="t13" tabindex="13" 
	  <?php
 
	  if(isset($_POST['t13'])){
	  	echo 'value = "' .$_REQUEST['t13']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['ret2_im'],2,'.','').'"';
	  }
	  ?>
	  ></td>
    </tr>
    <tr>
      <td nowrap>Total/Documento </td>
      <td nowrap><input name="t14" type="text" id="t14" tabindex="14" readonly
	  <?php
 
	  if(isset($_POST['t14'])){
	  	echo 'value = "' .$_REQUEST['t14']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['tot_doc'],2,'.','').'"';
	  }
	  ?>
	  ></td>
      <td nowrap>Saldo:</td>
      <td nowrap><input name="t19" type="text" id="t19" tabindex="19" readonly
	  <?php
 
	  if(isset($_POST['t19'])){
	  	echo 'value = "' .$_REQUEST['t19']. '"';
	  }else{
	  	echo 'value = "'.number_format($dt_redocl['tot_sal'],2,'.','').'"';
	  }
	  ?>
	  ></td>
      <td nowrap>Tipo/Movimiento</td>
      <td nowrap><select name="t28" id="t28">
        <?php

		$selec='';
		$auxSelec=NULL;
		if(isset($_POST['t28'])){
			$selec=$_POST['t28'];	
		}
		else{
			$selec=$dt_redocl['tip_mot']; 
		}
		$tipMov= array("N"=>"NORMAL","R"=>"REFACTURACION");
		foreach($tipMov as $index=>$value){
			if($selec==$index)
				echo '<option value="'.$index.'" selected>'.$value.'</option>';
			else
				echo '<option value="'.$index.'">'.$value.'</option>';
		}
		?>
      </select></td>
    </tr>
    <tr style="#FFCC00">
      <td colspan="6" nowrap><div align="center" class="Estilo2 Estilo3">&nbsp;&nbsp;Tot. Pagos: <? echo number_format($dt_redocl['tot_pag'],2,'.',',');?> &nbsp;&nbsp;Tot. Notas: <? echo number_format($dt_redocl['tot_not'],2,'.',',');?> Tot.Cargos:<? echo number_format($dt_redocl['tot_car'],2,'.',',');?> &nbsp;&nbsp;Tot. Abonos: <? echo number_format($dt_redocl['tot_abo'],2,'.',',');?></div></td>
    </tr>
    <tr>
      <td nowrap>Tipo de Moneda: </td>
      <td nowrap><select name="ttmon" onChange="javascript: document.getElementById('frm1').submit()" tabindex="20">
          <?php

	 	$tipMon=array("1"=>"NACIONAL","2"=>"EXTRANJERA");
		$selecMon='';
		$auxSelec=NULL;
		if(isset($_POST['ttmon'])){
			$selMon=$_POST['ttmon'];	
		}
		else{
			$selMon=$dt_redocl['moneda']; 
		}
		foreach($tipMon as $index=>$value){
			if($selMon==$index)
				echo '<option value="'.$index.'" selected>'.$value.'</option>';
			else
				echo '<option value="'.$index.'">'.$value.'</option>';
		}
			?>
      </select></td>
      <td colspan="2" nowrap>Pais:
        <select name="tpai" onChange="javascript: document.getElementById('frm1').submit()" tabindex="21" <? if($selMon=='1') echo 'disabled';?>>
         <?php

		  	$selPai='-1';
		  	if($selMon!='1'){
				$sq_paises=mysqli_query($con ,"select * from geoyos_jc.dxpaises order by des_pais");
				@$dt_paises=mysqli_fetch_array($sq_paises);
				if(isset($_POST['tpai'])){
					$selPai=$_POST['tpai'];	
				}
				else{
					if(!isset($_POST['ttmon'])) $selPai=$dt_redocl['cve_pai'];
					else $selPai=$dt_paises["cve_pais"];
				}

				do{
					if($selPai==$dt_paises["cve_pais"])
						echo '<option value="'. $dt_paises["cve_pais"] .'" selected>'.$dt_paises["des_pais"].' </option>';
					else
						echo '<option value="'. $dt_paises["cve_pais"] .'">'.$dt_paises["des_pais"].' </option>';
				}while(@$dt_paises=mysqli_fetch_array($sq_paises));
			}

			?>
        </select> 
      Moneda: 
      <select name="cve_mon"  tabindex="22" <? if($selMon=='1') echo 'disabled';?>>
        <?php
 
		if($selMon!='1'){
			if(isset($_POST['cve_mon'])){
				$selMonPai=$_POST['cve_mon'];	
			}
			else{
				if(!isset($_POST['ttmon'])) $selMonPai=$dt_redocl['cve_mon'];
			}
			@$sq_paimon=mysqli_query($con ,"select * from geoyos_jc.dxpaimon where cve_pais='$selPai'");
			while($dt_paimon=mysqli_fetch_array($sq_paimon)){
				if($selMonPai==$dt_paimon['cve_mon'])
					echo '<option value="'. $dt_paimon['cve_mon'] .'" selected>'.$dt_paimon['des_moneda'].' </option>';
				else
					echo '<option value="'. $dt_paimon['cve_mon'] .'" >'.$dt_paimon['des_moneda'].' </option>';

			}
		}

?>
            </select></td>
      <td nowrap>Tipo de cambio: </td>
      <td nowrap><input name="ttc" type="text" tabindex="23" onFocus="checkTipCam();" <? if($selMon=='1') echo 'readonly';?>
	  <?php

	  	if($selMon!='1'){
 			if(isset($_POST['ttc'])){
				echo "value=\"$_POST['ttc']\"";
			}
			else{
				if(isset($_POST['ttmon'])) echo "value=\"0.00\"";
				else  echo "value=\"$dt_redocl['tip_cam']\"";
			}
		}
		else{
			echo "value=\"0.00\"";
		}
	?>/></td>
    </tr>
    <tr>
      <td nowrap>Contado/Credito:</td>
      <td nowrap><select name="t26" id="t26" onChange="document.frm1.submit();">
        <?php

		$selec='';
		if(isset($_POST['t26'])){
			$selec=$_POST['t26'];
		}
		else{
			$selec=$dt_redocl['con_cre'];
		}
		$forPag=array("C"=>"CONTADO","R"=>"CREDITO");
		foreach($forPag as $index=>$value){
			if($selec==$index)
				echo '<option value="'.$index.'" selected>'.$value.'</option>';
			else
				echo '<option value="'.$index.'">'.$value.'</option>';
		} 
		?>
      </select></td>
      <td nowrap>Dias de credito: </td>
      <td nowrap><input name="t24" type="text" id="t24" tabindex="24" onBlur="javascript: document.getElementById('frm1').submit()"
	  <?php

	  if($selec!='C'){ 
		  if(isset($_POST['t24'])){
			echo 'value = "' .$_REQUEST['t24']. '"';
		  }else{
			echo 'value = "'.$dt_redocl['dia_cre'].'"';
		  }
	  }elseif($selec=='C'){
	  	echo 'value="0" readonly';
	  }
	  ?>
	  ></td>
      <td nowrap>Fecha de Vencimiento </td>
      <td nowrap><input name="t27" type="text" id="t27" tabindex="24" size="10" readonly
	  <?php
 
	  if(isset($_POST['t27'])){
			if (preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$_REQUEST['fec2']))
              	list($dia,$mes,$aņo)=split("/", $_REQUEST['fec2']);
      		if (preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$_REQUEST['fec2']))
              	list($dia,$mes,$aņo)=split("-",$_REQUEST['fec2']);
        		$nueva = mktime(0,0,0, $mes,$dia,$aņo) + $_REQUEST['t24'] * 24 * 60 * 60;
        		$nuevafecha=date("d/m/Y",$nueva);

	  	echo 'value = "' .$nuevafecha. '"';
	  }else{
	  	echo 'value = "'.chfecha($dt_redocl['fec_ven'],'Y-m-d','d/m/Y').'"';
	  }
	  ?>
	  >
      <input name="bot27" id="bot27" type="image" value="Cal" src="logos/cal4.jpg" />
	  <script type="text/javascript">
		Calendar.setup(
			{
				inputField  : "t27",       // ID del cuadro de texto
				ifFormat    : "%d/%m/%Y",   // formato de la fecha
				button      : "bot27"      	// ID del boton
			}
		);
		</script></td>
    </tr>
    <tr>
      <td nowrap>Descripcion</td>
      <td colspan="5" nowrap><div align="center">
        <textarea name="t25" cols="70" rows="3" id="t25" tabindex="25" ><?php
 
	  	if(isset($_POST['t25'])){
	  		echo $_REQUEST['t25'];
	  	}
		else{
			echo $dt_redocl['des'];
		}
	  ?></textarea>
      </div></td>
    </tr>
    <tr>
      <th colspan="6">
  <div align="center">
  <input name="modificarPRO" type="button" id="modificarPRO" onClick="openpage('DW21000_MC.php','_self')" value="Modificar"/>
  &nbsp;&nbsp;
  <input type="button" name="Submit2" value="Regresar" onClick="openpage('DW21000_PR-PRO.php','_self')">
  </div></th>
    </tr>
  </table>
</form>
</body>
</html>
