<?php
	$Alm_=gn("id_almacen","almacenes","alm_obs='$StrAlm'");
	$Dex_=ToDate($StrDex);
	$Hax_=ToDate($StrHax);
	//INGRESOS
	$_CAJ_CHI=NF(gn("SUM(total)","caja_chica",
				 "id_almacen=$Alm_ AND fecha>='$Dex_' AND fecha<='$Hax_'"),2);
	$_VEN_CON=NF(gn("SUM(tot)","ventas",
				 "id_tip_pag='CO' AND anu='N' AND id_alm=$Alm_ AND 
				 fec>='$Dex_' AND fec<='$Hax_'"),2);
	$_VEN_TAR=NF(gn("SUM(tot)","ventas",
			 	 "id_tip_pag='TA' AND anu='N' AND id_alm=$Alm_ AND 
			      fec>='$Dex_' AND fec<='$Hax_'"),2);
	$_VEN_CRE=NF(gn("SUM(tot)","ventas",
			 	 "id_tip_pag='CR' AND anu='N' AND id_alm=$Alm_ AND 
			      fec>='$Dex_' AND fec<='$Hax_'"),2);
	$_VEN_DEP=NF(gn("SUM(tot)","ventas",
			 	 "id_tip_pag='DE' AND anu='N' AND id_alm=$Alm_ AND 
			      fec>='$Dex_' AND fec<='$Hax_'"),2);
	$_VEN_TOT=NF($_VEN_CON+$_VEN_TAR+$_VEN_CRE+$_VEN_DEP,2);
	//
	$_OTR_ING=NF(gn("SUM(tot)","ingresos","id_alm=$Alm_ AND fec>='$Dex_' AND fec<='$Hax_'"),2);
	//
	$_COB_CRE=NF(gn("SUM(total)","cobros","id_alm=$Alm_ AND 
				 fecpag>='$Dex_' AND fecpag<='$Hax_' AND 
				 pag='S' AND anu='N' AND mon='S' "),2);
 	$_COB_CRE=NF($_COB_CRE + gn("SUM(total * tcam)","cobros","id_alm=$Alm_ AND 
				 fecpag>='$Dex_' AND fecpag<='$Hax_' AND 
				 pag='S' AND anu='N' AND mon='D' "),2);
	$_TOT_ING=NF($_CAJ_CHI+$_VEN_TOT+$_OTR_ING+ $_COB_CRE,2);
	$_TOT_ING_NET=NF($_TOT_ING-($_VEN_CRE+$_VEN_TAR+$_VEN_DEP),2);
	//EGRESOS
	$_COM_CON=NF(gn("SUM(total)","compras",
				 "id_tip_pag='CO' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='S'"),2);				 
	$_COM_CON=NF($_COM_CON+ gn("SUM(total * t_cambio)","compras",
				 "id_tip_pag='CO' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='D'"),2);
				 
	$_COM_TAR=NF(gn("SUM(total)","compras",
				 "id_tip_pag='TA' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='S'"),2);				 
	$_COM_TAR=NF($_COM_TAR+ gn("SUM(total * t_cambio)","compras",
				 "id_tip_pag='TA' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='D'"),2);
				 
	$_COM_CRE=NF(gn("SUM(total)","compras",
				 "id_tip_pag='CR' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='S'"),2);				 
	$_COM_CRE=NF($_COM_CRE+ gn("SUM(total * t_cambio)","compras",
				 "id_tip_pag='CR' AND anulado='N' AND id_almacen=$Alm_ AND 
				 fecha>='$Dex_' AND fecha<='$Hax_' AND  moneda='D'"),2);
	$_COM_TOT=NF($_COM_CON+$_COM_TAR+$_COM_CRE,2);
	//
	$_OTR_EGR=NF(gn("SUM(tot)","egresos","id_alm=$Alm_ AND fec>='$Dex_' AND fec<='$Hax_'"),2);
	//
	$_PAG_CRE=NF(gn("SUM(total)","pagos","id_alm=$Alm_ AND 
				 fecpag>='$Dex_' AND fecpag<='$Hax_' AND 
				 pag='S' AND anu='N' AND mon='S' "),2);
 	$_PAG_CRE=NF($_PAG_CRE + gn("SUM(total * tcam)","pagos","id_alm=$Alm_ AND 
				 fecpag>='$Dex_' AND fecpag<='$Hax_' AND 
				 pag='S' AND anu='N' AND mon='D' "),2);
	$_TOT_EGR=NF($_COM_TOT+$_OTR_EGR+$_PAG_CRE,2);
	$_TOT_EGR_NET=NF($_TOT_EGR-($_COM_CRE+$_COM_TAR),2);
	$_NETO=NF($_TOT_ING_NET - $_TOT_EGR_NET,2);
	$LStrFoc="document.getElementById('CboAlm').focus();";
	$LStrMsg="onload=\"$LStrFoc;\"";

?>