<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
include('DF80000.php');
require_once("DFMOVCAP.inc");
require_once("DFJQUERY.inc");
?>
<?php
 
$tipmov='C';
$fecini=chfecha($_POST['fecini'],'d/m/Y','Y-m-d');
$fecfin=chfecha($_POST['fecfin'],'d/m/Y','Y-m-d');

if(isset($_POST['bo_bus'])){//Inicia Si buscar
	if(trim($_POST['seclipro'])!="" && trim($_POST['seclipro'])!="TODOS"){
		$andCli=" AND codigo='".$_POST['seclipro']."'";
	}
	if($_POST['setipnot']=='NC'){
		if($_POST['teser']=="")
			$st_bus="select * from dvnotcre where tip_mto='$tipmov' and tot_not<>0 and fec_not between '$fecini' and '$fecfin' $andCli order by fec_not,num_not";
		else
			$st_bus="select * from dvnotcre where tip_mto='$tipmov' and num_doc like '$_POST['teser']%'and tot_not<>0 and fec_not between '$fecini' and '$fecfin' $andCli order by fec_not,num_not";
		//echo $st_bus;
	}elseif($_POST['setipnot']=='NA'){
		if($_POST['teser']=="")
			$st_bus="
			SELECT 
				fec_fac as fec_not,
				codigo,
				tip_fac as tip_not,
				num_fac as num_not,
				sub_fac as sub_not,
				iva_fac as iva_not,
				tot_fac as tot_not
			FROM
				dvencfac
			WHERE
				tip_doc='N' AND tot_fac>0 AND fec_fac  between '$fecini' and '$fecfin' $andCli  order by fec_fac,num_fac
			";
		else
			$st_bus="
			SELECT 
				fec_fac as fec_not,
				codigo,
				tip_fac as tip_not,
				num_fac as num_not,
				sub_fac as sub_not,
				iva_fac as iva_not,
				tot_fac as tot_not
			FROM
				dvencfac
			WHERE
				tip_doc='N' AND tot_fac>0 AND fec_fac  between '$fecini' and '$fecfin' AND tip_fac='".$_POST['teser']."' $andCli order by fec_fac,num_fac";
	
	}
	$sq_redocl=mysqli_query($con ,$st_bus);
}//Termina Si buscar
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
$(document).ready(function(){
	$('#bus_prov').click(function(){
		loadOnLayer(
			{
				action:'DYCLIBASCPS.php',
				idLayer:'loadCli',
				width:'auto',
				height:'300px'
			},
			{	textBus:document.getElementById('tebusclipro').value,
				idRetObj:'seclipro',
				nomRetObj:'tebusclipro',
				tipBusCat:'nom'
			});
	});
	$('#tod_prov').bind('click',function(){
		seTodPro();
	});
	seTodPro();


	/********************************AUTO COMPLETAR************************************/	
	var idObjDes="tebusclipro";
	var idObjId="seclipro";
	$("#"+idObjDes).autocomplete('DYCLIBASCPS.php',{
		minChars: 1,                 //Caracteres Minimos antes de autocompletar
		//max:3                        //maximo de resultados mostrados, se manda como limit en autosugestion
		delay: 200,                  //Retardo de autocompletar 
		width: 500,                  //ancho del cuadro de despliegue
		highlight: false,            //Resalta letras coincidentes
		autoFill: false,             //autocompleta en texto la posible palabra
		scroll: true,				 //si cuadro tiene barra scroll
		scrollHeight: 300,           //alto del cuadro para el scroll
		formatItem:formatItem,	     //formato de presentacion de las posibles busquedas
		extraParams:{tipBusCat:'nom',typeRequest:'ac'}     //Parametros Extra a Mandar en autosugestion
	});
	$("#"+idObjDes).result(function(event, data, formatted){
		$('#'+idObjId).val(data[1]);
	});
	$("#"+idObjId).autocomplete('DYCLIBASCPS.php',{
		minChars: 1,                 //Caracteres Minimos antes de autocompletar
		//max:3                        //maximo de resultados mostrados, se manda como limit en autosugestion
		delay: 200,                  //Retardo de autocompletar 
		width: 500,                  //ancho del cuadro de despliegue
		highlight: false,            //Resalta letras coincidentes
		autoFill: false,             //autocompleta en texto la posible palabra
		scroll: true,				 //si cuadro tiene barra scroll
		scrollHeight: 300,           //alto del cuadro para el scroll
		formatItem:formatItem,	     //formato de presentacion de las posibles busquedas
		formatResult:function(row){  //formato de seleccion de busqueda
			return row[1];
		},
		extraParams:{tipBusCat:'id',typeRequest:'ac'}     //Parametros Extra a Mandar en autosugestion
	});
	$("#"+idObjId).result(function(event, data, formatted){
		$('#'+idObjDes).val(data[0]);
	});
	function formatItem(row) {
		return " (<strong>" + row[1] + "Ant:"+row[3]+"</strong>)"+row[0];
	}	
	/********************************TERMINA AUTO COMPLETAR************************************/
	
});


function seTodPro(){
	var objTodProv=document.getElementById('tod_prov');
	var objSeCliPro=document.getElementById('seclipro');
	var objBusProv=document.getElementById('bus_prov');
	if(objTodProv.checked){
		objBusProv.disabled=true;
		objSeCliPro.value=objTodProv.value;
	}
	else{
		objBusProv.disabled=false;
	}
}

</script>


<body  onLoad="movCap({idObj:'loadCli'});">
<div id="loadCli"></div>
<form name="form1" method="post" action="DV46000_PR.php">
  
  <div align="center">
  <table border="0">
    <tr>
      <th >LISTADO NOTAS CREDITO/CARGO </th>
      </tr>
    <tr>
      <td style="#F4F4F4">&nbsp;
          <input name="seclipro" type="text" id="seclipro" size="10" value="<?php
echo $_POST['seclipro'];?>" >
          <label></label>
        &nbsp;
        <input name="tebusclipro" type="text" id="tebusclipro" size="50" value="<?php
echo $_POST['tebusclipro'];?>">
        <input name="bus_prov" type="button" id="bus_prov" value="Buscar">
        <label>
          <input name="tod_prov" type="checkbox" id="tod_prov" value="TODOS"<?php
if($_POST['tod_prov']=='TODOS') echo 'checked';?>>
          <span class="Estilo2"> Todos</span>&nbsp;</label>
        &nbsp; </td>
    </tr>
    <tr>
      <td class="style8">Del  
        <input name="fecini" type="text" class="emplea" id="fecini" size="15" 
					value="<?php
 if(!isset($_POST['fecini'])){
									echo date("d/m/Y");
								}
								else{
									echo $_POST['fecini'];
								}
					?>"> 
				<input name="bot1" id="bot1" value=" ... " type="image" src="logos/cal4.jpg"/>
Al                <script type="text/javascript">
				  	Calendar.setup(
    					{
      						inputField  : "fecini",        // ID of the input field
      						ifFormat    : "%d/%m/%Y",    // the date format
      						button      : "bot1"      // ID of the button
    					}
  					);
				</script>                &nbsp;
				<input name="fecfin" type="text" class="emplea" id="fecfin" size="15" 
					value="<?php
 if(!isset($_POST['fecfin'])){
									echo date("d/m/Y");
								}
								else{
									echo $_POST['fecfin'];
								}
					?>">
                <input name="bot2" id="bot2" value=" ... " type="image" src="logos/cal4.jpg"/>
                <script type="text/javascript">
				  	Calendar.setup(
    					{
      						inputField  : "fecfin",        // ID of the input field
      						ifFormat    : "%d/%m/%Y",    // the date format
      						button      : "bot2"      // ID of the button
    					}
  					);
				</script>
        &nbsp;
        Serie Facturas:        <input name="teser" type="text" id="teser" value="<?php
 echo $_POST['teser'];?>">      </td>
      </tr>
    <tr>
      <td>
        <div align="center">
          <select name="setipnot" id="setipnot">
            <option value="NC" <?php
 if (!(strcmp("NC", "$_REQUEST['setipnot']"))) {echo "selected=\"selected\"";} ?>>NOTAS DE CREDITO</option>
            <option value="NA" <?php
 if (!(strcmp("NA", "$_REQUEST['setipnot']"))) {echo "selected=\"selected\"";} ?>>NOTAS DE CARGO</option>
          </select>
        </div>
        </td>
    </tr>
    <tr>
      <td>
        <div align="center">
          <input name="bo_bus" type="submit" id="bo_bus" value="Buscar">
          </div>     </td>
      </tr>
  </table>
  </div>
</form>
<form name="frm1" method="post" action="">
<input name="teser" type="hidden" id="teser" value="<?php
 echo $_POST['teser'];?>">
<input name="fecini" type="hidden" id="fecini" value="<?php
 echo $_POST['fecini'];?>">
<input name="fecfin" type="hidden" id="fecfin" value="<?php
 echo $_POST['fecfin'];?>">
<input name="busqueda" type="hidden" id="busqueda" value="<?php
 echo $st_bus;?>">
<input name="setipnot" type="hidden" id="setipnot" value="<?php
 echo $_POST['setipnot'];?>">
<div align="center">
  <table border="0">
    <tr>
      <th colspan="7" >
        <div align="left">
          <input name="bo_imp" type="button" id="bo_imp" value="Imprimir"  onClick="openpage('DV46000_IM.php','_self')">
          <input name="toExcel" type="button" id="toExcel" value="Exportar Excel" onClick="openpage('DV46000_IME.php','_self')">
        </div>     </th>
    </tr>
    <tr>
      <td nowrap class="tdagre1">Fecha </td>
      <td nowrap class="tdagre1">Codigo </td>
      <td nowrap class="tdagre1">Nombre</td>
      <td nowrap class="tdagre1">Num. Nota </td>
      <td nowrap class="tdagre1">Subtotal</td>
      <td nowrap class="tdagre1">IVA</td>
      <td nowrap class="tdagre1">Total  </td>
      </tr>
	<?php
 
	if(isset($_POST['bo_bus'])){
		$z=-1;
		$totales=NULL;
		$totgeneral=NULL;
		while(@$dt_redocl=mysqli_fetch_array($sq_redocl)){
		if ($dt_redocl['tip_cam'] > 0 && $dt_redocl['tip_mon']!='N') $tipcambio=$dt_redocl['tip_cam'];
		else $tipcambio=1;
			$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select * from dxbascps where codigo='".$dt_redocl['codigo']."'"));
			llenaTotales($totgeneral,$dt_redocl);
			echo '<tr>';
			echo '<td class="regFacL" nowrap colspan="1">'.chfecha($dt_redocl['fec_not'],'Y-m-d','d/m/Y').'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_redocl['codigo'].'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_bascps['ap_paterno'].' '.$dt_bascps['ap_materno'].' '.$dt_bascps['nombre'].'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_redocl['tip_not'].$dt_redocl['num_not'].'&nbsp;</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['sub_not']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['iva_not']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['tot_not']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '</tr>';
		}
		
		imptotales("Total General: ",$totgeneral);
		//imptotales("Saldo General Documentos: ",$totgeneral);
	}
	
	function llenaTotales(&$totales, $dat){
		if ($dat['tip_cam'] > 0 && $dat['tip_mon']!='N') $tipcambio=$dat['tip_cam'];
		else $tipcambio=1;
		$totales[0]+=$dat["sub_not"]*$tipcambio;
		$totales[1]+=$dat["iva_not"]*$tipcambio;
		$totales[2]+=$dat["tot_not"]*$tipcambio;
	}
	
	function imptotales($leyenda,$totales){
		echo '<tr>';
		echo '<td class="granTotal" colspan="4"><div align="right">'.$leyenda.'&nbsp;</div></td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[0],2,'.',',').'&nbsp;</td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[1],2,'.',',').'&nbsp;</td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[2],2,'.',',').'&nbsp;</td>';
		echo '</tr>';
	}
	?>
  </table>
  </div>
</form>
</body>
</html>