<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include('DF30000.inc');
require_once("DF80000.php");
// Graba Detalle Poliza  
function fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo){
		$sql="insert into dcdpoliz (tip_pol, fec_pol, num_pol, num_reg, cta_con, desc_con, cargo, abono) values ('$tpol', '$fpol', '$npol','$nr', '$cta', '$ddpol','$car', '$abo')";
	   	$result = mysqli_query($con ,$sql);
}
// verifica cta contable  
function fver_cta($cta,$doc,$er){

	global $er;
	$er ='';
	if($dt_catcta['cta_con']<>$cta)$er ="s";
	if($dt_catcta['tipo']<>'D')$er ="s";
}

function getCtaCon($cta){
	$sq_catcta=mysqli_query($con ,"select * from dycatcta where cta_con = '$cta'");
	if(mysqli_num_rows($sq_catcta)==0)
		return 0;
	else{
		$dt_catcta=mysqli_fetch_array($sq_catcta); // obtiene cta contable	
		return $dt_catcta;
	}
}

// -----Empieza Formulario -----------------
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>

<body>
<div align="center">
<form name="form1" id="form1" method="post" action="">
  <table width="730"  align="center">
    <tr>
      <th width="720" colspan="4">GENERA POLIZAS VENTAS/DEV.VENTAS/COSTO VENTAS </th>
    </tr>
    <tr>
      <td>A&ntilde;o Proceso </td>
      <td><select name="axo" id="axo">
          <?php
 
			$sq_a = mysqli_query($con ,"select axo from dccalend group by axo DESC");
			while($re_a = mysqli_fetch_array($sq_a)){
				echo '<option value = "'.$re_a['axo'].'">'.$re_a['axo'].'</option>';
				}
			?>
        </select>      </td>
      <td>Mes Proceso </td>
      <td><select name="mes" id="mes">
          <option value="01" selected>Enero</option>
          <option value="02">Febrero</option>
          <option value="03">Marzo</option>
          <option value="04">Abril</option>
          <option value="05">Mayo</option>
          <option value="06">Junio</option>
          <option value="07">Julio</option>
          <option value="08">Agosto</option>
          <option value="09">Septiembre</option>
          <option value="10">Octubre</option>
          <option value="11">Noviembre</option>
          <option value="12">Diciembre</option>
      </select></td>
    </tr>
          <tr>
          <td colspan="4" align="center" class="inputcodigo"> <input name="calcula" type="submit" id="calcula" value="Genera Polizas" /></td>
        </tr>
      <tr>
        <td colspan="4" class="typeagre">
		<div align="left">
<?php
 
if(isset($_POST['calcula'])){
/*	
   	$f1 = $_POST['axo'].'-'.$_POST['mes'].'-01';
	$fr_fec = 'AMD';
    $fr_fecr = 'Ymd';
    $sep_fecr = '-';
	include('DF70000.php');

	$dt_parame=mysqli_fetch_array(mysqli_query($con ,"select * from dgparame")); // parametros generales

	$fec_ini = $fec_imes;
	$fec_fin = $fec_fmes;
	$tpol = $dt_parame['tip_pol_ven']; // tipo de poliza
	$ori = "DG"; // VENTAS
	$hayerr = "N";

	//Graba Movtos si no hay Errores 
	if($hayerr=="N"){
	echo 'Procesando Polizas del '.$fec_ini.' al '.$fec_fin.'<br>';
	$sq_factur=mysqli_query($con ,"select * from dgfactur where between '$fec_ini' and '$fec_fin' group by fec_fac order by fec_fac");
	while($dt_factur=mysqli_fetch_array($sq_factur)){ //lee agrupado x rango de fecha
		echo 'Procesando Fecha del '.$dt_factur['fec_fac'].'<br>';
		$auxFecAct=explode('-',$dt_factur['fec_fac']);
		$npol=$auxFecAct[2];
	   	$f1 = '".$dt_factur['fec_fac']."';$fr_fec = 'AMD';$fr_fecr = 'Ymd';$sep_fecr = '/';
		include('DF70000.php');
		$dpol='Ventas Dia '.$dt_factur['fec_fac'];
		$fpol=$dt_factur['fec_fac'];
		$ipol=0;

		@$sql=mysqli_query($con ,"insert into dcepoliz (tip_pol, num_pol, fec_pol, desc_pol, acc_fec, acc_hor, usuario, origen, actualiza) values ('$tpol', '$npol','$fpol', '$dpol', '".date('Y-m-d')."', '".date('H:i:s')."', '".$_SESSION['num_usu']."','$ori','0')");
		$nr =mysqli_insert_id($con); //id alta poliza encabezado
		$sq_factur0=mysqli_query($con ,"select * from dvfactur where tip_mov='$tmov' and fec_doc = '".$dt_factur['fec_doc']."' order by codigo,num_doc");
		while($dt_factur0=mysqli_fetch_array($sq_factur0)){ //lee doctos x fecha
			$tcar=0;$tabo=0;
//			echo '<br>';
//			echo '	Procesando Docto : ('.$dt_factur0['codigo'].')'.$dt_factur0['num_doc'].' $'.$dt_factur0['sub_tot'].'<br>';
			$dt_tasiva=mysqli_fetch_array(mysqli_query($con ,"select * from dxtasiva where cve_iva='".$dt_factur0['cve_iva']."'")); // obtiene registro de iva para ctas contables
			$ddpol='Factura '.$dt_factur0['num_doc'];
			$cta=$dt_factur0['cve_mto'];
			$car=$dt_factur0['tot_doc'];$tcar +=$car;
			$abo='0.00'; 
			fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo);//graba total Factura

			if($dt_factur0['_im']<>0){
				$dt_catret=mysqli_fetch_array(mysqli_query($con ,"select * from dvcatret where cve_ret ='".$dt_factur0['ret1']."'")); // obtiene retenciones
				$ddpol=$dt_catret['des_ret'].' Documento '.$dt_factur0['num_doc'];
				$cta=$dt_catret['cta_con'];
				$car=$dt_factur0['_im'];$tcar +=$car;
				$abo='0.00'; 
				fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo);//graba retencion 1
			}
			if($dt_factur0['_im']<>0){
				$dt_catret=mysqli_fetch_array(mysqli_query($con ,"select * from dvcatret where cve_ret ='".$dt_factur0['ret2']."'")); // obtiene retenciones
				$ddpol=$dt_catret['des_ret'].' Documento '.$dt_factur0['num_doc'];
				$cta=$dt_catret['cta_con'];
				$car=$dt_factur0['_im'];$tcar +=$car;
				$abo='0.00'; 
				fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo);//graba retencion 2
			}

			$sq_redocd=mysqli_query($con ,"select * from dvredocd where tip_mov='$tmov' and fec_doc = '".$dt_factur0['fec_doc']."' and num_doc = '".$dt_factur0['num_doc']."' and codigo = '".$dt_factur0['codigo']."'");
			while($dt_redocd=mysqli_fetch_array($sq_redocd)){ //lee detalle doctos
//				echo '		Procesando Detalle ('.$dt_redocd['n_reg'].')'.$dt_redocd['num_doc'].' $'.$dt_redocd['sub_tot'].'<br>';
				$ddpol='Factura '.$dt_factur0['num_doc'];
				$cta=$dt_redocd['cve_mto'];
				$abo=$dt_redocd['sub_tot'];
				$car='0.00'; 
				$ipol +=$abo;$tabo +=$abo;
				fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo);//graba detalle docto
			}//termina while detalle doctos
			if($dt_factur0['iva_tot']<>0){
				$ddpol='Iva Factura '.$dt_factur0['num_doc'];
				$cta=$dt_tasiva['cta_iva_acr_np'];
				$abo=$dt_factur0['iva_tot'];
				$car='0.00'; 
				$ipol +=$abo;$tabo +=$abo;
				fgrab_dpol($tpol,$fpol,$npol,$nr,$cta,$ddpol,$car,$abo);//graba iva docto
			}

			if(number_format($tcar,2,'.',',')==number_format($tabo,2,'.',',')){
				$cua = "S";
			}else{
				$cua ="N";	
				$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select * from dxbascps where codigo ='".$dt_factur0['codigo']."'")); 
				echo 'Error Docto :'.$dt_factur0['num_doc'].'/'.$dt_factur0['fec_doc'].'/'.$dt_bascps['nombre'].' '.$dt_bascps['ap_paterno'].' Car:'.number_format($tcar,2,'.',',').' Abo:'.number_format($tabo,2,'.',',').'<br>';
			}
			$rs=mysqli_query($con ,"update dcepoliz set imp_total='$ipol',cuadrada='$cua' where id_dcepol ='$nr'");
		}//termina while documentos fecha especifica
	}// termina while fechas agrupadas
	}// termina if si procedia grabacion o no 
	if($hayerr=="S"){
		echo '<br>';
		echo 'No se grabaron polizas verifique errores '.'<br>';
	}else{
		echo '<br>';
		echo 'Fin Proceso Polizas Generadas Correctamente '.'<br>';
	}*/
	
   	$f1 = $_POST['axo'].'-'.$_POST['mes'].'-01';
	$fr_fec = 'AMD';
    $fr_fecr = 'Ymd';
    $sep_fecr = '-';
	include('DF70000.php');

	$dt_parame=getDatParVen(); // parametros generales

	$fec_ini = $fec_imes;
	$fec_fin = $fec_fmes;
	$tpol = $dt_parame['tip_pol_kja']; // tipo de poliza
	$ori = "DG"; // VENTAS
	if(strcmp($tpol,"")==0){
		echo "<h2>Es Necesario Tipo de Poliza, Verifique Parametros!!!</h2>";
		exit();
	}
	$npol=getLastNumPol($tpol,$_POST['axo'],$_POST['mes'])+1;
	$fpol='';

	//Graba Movtos si no hay Errores 
	$sq_ger_cajerosj=mysqli_query($con ,"SELECT 
							   dgger_cajerosj.fec_rec,
							   dgger_cajerosj.tip_caj,
							   SUM(dgger_cajerosj.importe) as totImp, 
							   SUM(((dgger_cajerosj.importe/dgpemema.tot_ven)*dgpemema.iva_ven)) as totIva,
							   dgtipven.cta_con_caj,
							   dgtipven.cve_iva,
							   dxtasiva.cta_iva_acr as ctaIvaCob,
							   dxtasiva.cta_iva_acr_np as ctaIvaPpc,
							   dgtipven.cta_con_vta as ctaCliCon 
						    FROM 
								dgger_cajerosj 
								INNER JOIN dgtipven ON (dgtipven.tip_ven=dgger_cajerosj.tip_caj) 
								INNER JOIN dgpemema ON(dgpemema.fol_ven=dgger_cajerosj.pedido) 
								LEFT JOIN dxtasiva ON(dxtasiva.cve_iva=dgtipven.cve_iva) 
						    WHERE 
								dgger_cajerosj.fec_rec BETWEEN '$fec_ini' AND '$fec_fin' 
							GROUP BY 
								dgger_cajerosj.fec_rec,dgtipven.tip_ven 
							ORDER BY 
								dgger_cajerosj.fec_rec,dgtipven.tip_ven");
	$totIva=0;
	$totImp=0;
	echo "<h2>POLIZAS CAJA</h2>";
	while($dt_ger_cajerosj=mysqli_fetch_array($sq_ger_cajerosj)){ //lee agrupado x rango de fecha
		echo 'Procesando Fecha del '.$dt_ger_cajerosj['fec_rec'].'<br>';
		
		//Si Cambio de Fechas Inserta Encabezado Poliza
		if(strcmp($fpol,$dt_ger_cajerosj['fec_rec'])!=0){
			//Si fecha no es vacia Insertamos Detalles de Iva de poliza
			if(strcmp($fpol,"")!=0){
				fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$ctaIvaPpc,"IVA PENDIENTE POR COBRAR",$totIva,"0.00");
				fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$ctaIvaCob,"IVA COBRADO","0.00",$totIva);
				fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$dt_parame['cta_clie_cont'],"CLIENTES CONTADO","0.00",$totImp);
				$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totIva + $totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");
				$totIva=0;
				$totImp=0;
			}
		
			$fpol=$dt_ger_cajerosj['fec_rec'];
			$ctaIvaPpc=$dt_ger_cajerosj['ctaIvaPpc'];
			$ctaIvaCob=$dt_ger_cajerosj['ctaIvaCob'];
			$dpol='Ingresos Serie Dia: '.chfecha($fpol,'Y-m-d','d/m/Y');
			@$rs=mysqli_query($con ,"insert into dcepoliz (tip_pol, num_pol, fec_pol, desc_pol, acc_fec, acc_hor, usuario, origen, actualiza) values ('$tpol', '$npol','$fpol', '$dpol', CURDATE(),CURTIME(), '".$_SESSION['num_usu']."','$ori','0')");
			$idEncPol=mysqli_insert_id($con);
			$npol++;
		}
		$datCtaCon=getCtaCon($dt_ger_cajerosj['cta_con_caj']);
		if(is_array($datCtaCon)){
			fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$datCtaCon['cta_con'],$datCtaCon['descripcion'],$dt_ger_cajerosj['totImp'],"0.00");
			$totIva +=$dt_ger_cajerosj['totIva'];
			$totImp +=$dt_ger_cajerosj['totImp'];			
		}else{
			echo "<h2>ERROR:Cuenta Contable No Valida, Tip.Pol.:$tpol Poliza:$npol, $dpol</h2>";
		}
		unset($datCtaCon);
	}// termina while fechas agrupadas
	fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$ctaIvaPpc,"IVA PENDIENTE POR COBRAR",$totIva,"0.00");
	fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$ctaIvaCob,"IVA COBRADO","0.00",$totIva);
	fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$dt_parame['cta_clie_cont'],"CLIENTES CONTADO","0.00",$totImp);
	$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totIva + $totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");


	
	
	/*********************************POLIZAS VENTAS*********************************/
	$tpol = $dt_parame['tip_pol_ven']; // tipo de poliza
	$ori = "DG"; // VENTAS
	$npol=getLastNumPol($tpol,$_POST['axo'],$_POST['mes'])+1;	
	$fpol='';
	$sq="SELECT dgfactur.fec_fac as fecVen,
				dglineas.linea as idLin,
				dglineas.des_linea as desLin,
				dgtipven.des_tipven as desTipVen,
				dgtipven.cta_con_vta as ctaVtaPadre,
				dgtipven.cta_con_dev as ctaDevVtaPadre,
				dglineas.cta_con_vta as ctaVtaHijo,
				dglineas.cta_dev_vta as ctaDevVtaHijo,
				dglineas.cta_con_costo as ctaCosHijo,
				dglineas.cta_con_inven as ctaInvHijo,
				dglineas.cta_des_bon as ctaDesBonHijo,
				SUM(dgfactud.subtotal) as subTotLin,
				SUM(dgfactud.iva_pre) as totIvaLin
		 FROM
			dgfactud
			INNER JOIN dgfactur ON (dgfactud.cons_fac=dgfactur.fol_fac)
			INNER JOIN dginvent ON (dgfactud.nparte1 =dginvent.nparte1)
			INNER JOIN dgtipven ON (dgtipven.tip_ven =dgfactur.tip_ven)
			LEFT  JOIN dglineas ON (dginvent.linea   =dglineas.linea)
			
		WHERE
			dgfactur.fec_fac BETWEEN '$fec_ini' AND '$fec_fin' 
		GROUP BY 
			dgfactur.fec_fac,dglineas.des_linea,dgtipven.tip_ven
		ORDER BY 
			dgfactur.fec_fac,dglineas.des_linea,dgtipven.tip_ven
		";
	$sq_pememd=mysqli_query($con ,$sq);
	echo mysqli_error($con);
	$totImp=0;
	$totIva=0;
	echo "<h2>POLIZAS VENTAS</h2>";
	$dt_tasiva=mysqli_fetch_array(mysqli_query($con ,"SELECT  cta_iva_acr_np as ctaIvaPpc, cta_iva_acr as ctaIvaCob FROM dxtasiva WHERE cve_iva='1'"));
	while($dt_pememd=mysqli_fetch_array($sq_pememd)){
		//Si Cambio de Fechas Inserta Encabezado Poliza
		if(strcmp($fpol,$dt_pememd['fecVen'])!=0){
			//Si fecha no es vacia Insertamos Detalles de Iva de poliza
			if(strcmp($fpol,"")!=0){
				fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$dt_tasiva['ctaIvaPpc'],"IVA PENDIENTE POR COBRAR","0.00",$totIva);
				$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totIva + $totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");
				$totIva=0;
				$totImp=0;
			}
			$fpol=$dt_pememd['fecVen'];
			$dpol='Ventas Del Dia: '.chfecha($fpol,'Y-m-d','d/m/Y');
			echo $dpol."<br>";
			@$rs=mysqli_query($con ,"insert into dcepoliz (tip_pol, num_pol, fec_pol, desc_pol, acc_fec, acc_hor, usuario, origen, actualiza) values ('$tpol', '$npol','$fpol', '$dpol', CURDATE(),CURTIME(), '".$_SESSION['num_usu']."','$ori','0')");
			$idEncPol=mysqli_insert_id($con);
			$sq_pememaTotConCre=getTotConCreVen($fpol);
			
			while($row=mysqli_fetch_array($sq_pememaTotConCre)){
				if($row['conCre']=='1'){
					$ctaCon=$dt_parame['cta_clie_cont'];
					$desDet="CLIENTES CONTADO";
				}else{
					$ctaCon=$dt_parame['cta_clie_cred'];
					$desDet="CLIENTES CREDITO";
				}
				fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$ctaCon,$desDet,$row['totVen'],"0.00");
			}		
			$npol++;
		}
		$datCtaCon=getCtaCon($dt_pememd['ctaVtaPadre'].$dt_pememd['ctaVtaHijo']);
		if(is_array($datCtaCon)){
			fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$datCtaCon['cta_con'],$datCtaCon['descripcion'],"0.00",$dt_pememd['subTotLin']);
			$totIva +=$dt_pememd['totIvaLin'];
			$totImp +=$dt_pememd['subTotLin'];			
		}else{
			echo "<h2>ERROR:Cuenta Contable No Valida, Tip.Pol.:$tpol Poliza:$npol, $dpol</h2>";
		}
		unset($datCtaCon);	
	}
	fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$dt_tasiva['ctaIvaPpc'],"IVA PENDIENTE POR COBRAR","0.00",$totIva);
	$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totIva + $totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");
	/********************************************************TERMINA POLIZAS VENTAS***********************************************/
	
	
	/*********************************POLIZAS VENTAS*********************************/
	$tpol = $dt_parame['tip_pol_cven']; // tipo de poliza
	$ori = "DG"; // VENTAS
	$npol=getLastNumPol($tpol,$_POST['axo'],$_POST['mes'])+1;	
	$fpol='';
	$sq="SELECT dgfactur.fec_fac as fecVen,
				dglineas.linea as idLin,
				dglineas.des_linea as desLin,
				dgtipven.des_tipven as desTipVen,
				dgtipven.cta_con_vta as ctaVtaPadre,
				dgtipven.cta_con_dev as ctaDevVtaPadre,
				dgtipven.cta_cos_inv as ctaCosPadre,
				dgtipven.cta_con_inv as ctaInvPadre,
				dglineas.cta_con_vta as ctaVtaHijo,
				dglineas.cta_dev_vta as ctaDevVtaHijo,
				dglineas.cta_con_costo as ctaCosHijo,
				dglineas.cta_con_inven as ctaInvHijo,
				dglineas.cta_des_bon as ctaDesBonHijo,
				SUM(dgfactud.cos_ref*dgfactud.can_ref) as subTotLin,
				SUM(dgfactud.iva_pre) as totIvaLin
		 FROM
			dgfactud
			INNER JOIN dgfactur ON (dgfactud.cons_fac=dgfactur.fol_fac)
			INNER JOIN dginvent ON (dgfactud.nparte1 =dginvent.nparte1)
			INNER JOIN dgtipven ON (dgtipven.tip_ven =dgfactur.tip_ven)
			LEFT  JOIN dglineas ON (dginvent.linea   =dglineas.linea)
			
		WHERE
			dgfactur.fec_fac BETWEEN '$fec_ini' AND '$fec_fin' 
		GROUP BY 
			dgfactur.fec_fac,dglineas.des_linea,dgtipven.tip_ven
		ORDER BY 
			dgfactur.fec_fac,dglineas.des_linea,dgtipven.tip_ven
		";
	$sq_pememd=mysqli_query($con ,$sq);
	echo mysqli_error($con);
	echo "<h2>POLIZAS COSTOS</h2>";
	$totImp=0;
	$totIva=0;
	while($dt_pememd=mysqli_fetch_array($sq_pememd)){
		//Si Cambio de Fechas Inserta Encabezado Poliza
		if(strcmp($fpol,$dt_pememd['fecVen'])!=0){
			//Si fecha no es vacia Insertamos Detalles de Iva de poliza
			if(strcmp($fpol,"")!=0){
				$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");
				$totIva=0;
				$totImp=0;
			}
			$fpol=$dt_pememd['fecVen'];
			$dpol='Costo Ventas Del Dia: '.chfecha($fpol,'Y-m-d','d/m/Y');
			echo $dpol."<br>";
			@$rs=mysqli_query($con ,"insert into dcepoliz (tip_pol, num_pol, fec_pol, desc_pol, acc_fec, acc_hor, usuario, origen, actualiza) values ('$tpol', '$npol','$fpol', '$dpol', CURDATE(),CURTIME(), '".$_SESSION['num_usu']."','$ori','0')");
			$idEncPol=mysqli_insert_id($con);
			$npol++;
		}
		$datCtaConCos=getCtaCon($dt_pememd['ctaCosPadre'].$dt_pememd['ctaCosHijo']);
		$datCtaConInv=getCtaCon($dt_pememd['ctaInvPadre'].$dt_pememd['ctaInvHijo']);
		if(is_array($datCtaConCos) && is_array($datCtaConInv)){
			fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$datCtaConCos['cta_con'],$datCtaConCos['descripcion'],$dt_pememd['subTotLin'],"0.00");
			fgrab_dpol($tpol,$fpol,$npol,$idEncPol,$datCtaConInv['cta_con'],$datCtaConInv['descripcion'],"0.00",$dt_pememd['subTotLin']);
			$totImp +=$dt_pememd['subTotLin'];			
		}else{
			if(!is_array($datCtaConCos))
				$ctaInvalida="COSTO: $dt_pememd['ctaCosPadre']$dt_pememd['ctaCosHijo'] ";
			if(!is_array($datCtaConInv))
				$ctaInvalida .="  INVENTARIO: $dt_pememd['ctaInvPadre']$dt_pememd['ctaInvHijo'] ";				
			echo "<h2>ERROR:Cuenta Contable ( $ctaInvalida ) No Valida, Tip.Pol.:$tpol Poliza:$npol, $dpol</h2>";
		}
		unset($datCtaConCos);
		unset($datCtaConInv);	
	}
	$rs=mysqli_query($con ,"update dcepoliz set imp_total='".($totImp)."',cuadrada='S' where id_dcepol ='$idEncPol'");
	/********************************************************TERMINA POLIZAS VENTAS***********************************************/
		
}// Termina Isset Calculo

//Obtiene Datos de Ultima Poliza por tipo aņo y mes
function getLastNumPol($tipPol,$axo,$mes){
	$sq_epoliz=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dcepoliz WHERE tip_pol='$tipPol' AND YEAR(fec_pol)='$axo' AND MONTH(fec_pol)='$mes' order by num_pol desc limit 1"));
	return $dt_epoliz['num_pol'];
}

//Obtiene Datos Totales de Contado y Credito de Cierta fecha
function getTotConCreVen($fecha){
	$sq="SELECT 
			dgfactur.fec_fac as fecVen,
			dgfactur.con_cre as conCre,
			SUM(dgfactur.tot_ven) as totVen
		 FROM
			dgfactur
		WHERE
			dgfactur.fec_fac = '$fecha' 
		GROUP BY 
			dgfactur.con_cre
		ORDER BY 
			dgfactur.con_cre
		";
		$sq_pemema=mysqli_query($con ,$sq);
		return $sq_pemema;
}
//Obtiene Datos de Parametros Generales de Ventas
function getDatParVen(){
	$sq_parame=mysqli_query($con ,"SELECT * from dgparame");
	return mysqli_fetch_array($sq_parame);
}
?>

</div></td></tr>
</table>
</form>
</body>
</html>