<?php

session_start();
include("DMMYSQLG.php");
$codigo=$_REQUEST['cc'];
$nd=mysqli_real_escape_string($con,trim($_GET['q']));
$sq_fac="
	SELECT 
		CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) as nomCli,
		DATE_FORMAT(dvredocl.fec_doc,'%d/%m/%Y') as fecDoc,
		dvredocl.num_doc as numDoc,
		dvredocl.sub_tot as subTot,
		dvredocl.total as totDoc,
		dvredocl.tot_sal as totSal
	FROM
		dvredocl
		INNER JOIN dxbascps ON(dxbascps.codigo=dvredocl.codigo)
	WHERE
			dvredocl.tip_mov='C'
		AND	dvredocl.codigo='$codigo'
		AND dvredocl.num_doc like '%$nd'
		AND dvredocl.fec_doc<'2010-01-01'

	GROUP BY
		dvredocl.num_doc
	ORDER BY
		dvredocl.fec_doc desc limit 30";
//echo $sq_fac;		
$sq_redocl=mysqli_query($con ,$sq_fac);
echo mysqli_error($con);
while($dt_redocl=mysqli_fetch_array($sq_redocl)){
	$dt_ger_cajerosjSum=mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(dgger_cajeroso.import) as impTot FROM dgger_cajerosj INNER JOIN dgger_cajeroso ON(dgger_cajeroso.rec_caj=dgger_cajerosj.n_rec) WHERE dgger_cajeroso.num_doc='".$dt_redocl['numDoc']."' AND dgger_cajeroso.tip_mov='C' AND dgger_cajerosj.fec_rec>='2010-01-01' group by dgger_cajeroso.num_doc"));
//	echo "entra\n";
	echo utf8_encode("$dt_redocl['fecDoc']|$dt_redocl['numDoc']|".number_format($dt_redocl['totSal']+$dt_ger_cajerosjSum['impPagNueAxo'],2,'.','')."|$dt_redocl['nomCli']|".number_format($dt_redocl['totDoc'],2,'.',''))."|".number_format($dt_redocl['subTot'],2,'.','')."\n";
}
?>