<?php 
session_start();

require('../cfg/res.php');
require('../cfg/cfg.php');


$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "ATS%" and info="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xacceso=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a Anexos Transaccionales ' );}	
?>

<?php

$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 year' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y-m-01' , $nuevafecha );
$xfecha2= date('Y-m-d');

if(isset($_POST['fecha_ini']) && !empty($_POST['fecha_ini']) && isset($_POST['fecha_fin']) && !empty($_POST['fecha_fin']))
{
	$xfecha1=$_POST['fecha_ini'];
	$xfecha2=$_POST['fecha_fin'];
}
$mes1=substr(str_replace('-','',$xfecha1),0,6);
$mes2=substr(str_replace('-','',$xfecha2),0,6);

// echo $mes1;
// echo $mes2;

// 	+'case ';
// 	+'when enti_tipoid="R" then "04" ';
// 	+'when enti_tipoid="C" then "05" ';
// 	+'when enti_tipoid="P" then "06" ';
// 	+'when enti_tipoid="F" then "07" ';
// 	+'else "00" end as tpIdCliente,'; 



$sql_anexo='select 
	sum(rcomp) as trcomp,
	sum(comp) as tcomp,
	sum(stiva0c) as stiva0c,
	sum(stivac) as stivac,
	sum(ivac) as tivac,
	sum(baseirc) as tbaseirc,
	sum(reteirc) as treteirc,
	sum(rretirc) as trretirc,
	sum(baseivac) as tbaseivac,
	sum(reteivac) as treteivac,
	sum(rretivac) as trretivac,
	sum(rvtas) as trvtas,
	sum(vtas) as tvtas,
	sum(stiva0v) as stiva0v,
	sum(stivav) as stivav,
	sum(ivav) as tivav,
	sum(baseirv) as tbaseirv,
	sum(reteirv) as treteirv,
	sum(rretirv) as trretirv,
	sum(baseivav) as tbaseivav,
	sum(reteivav) as treteivav,
	sum(rretivav) as trretivav,
	sum(anul) as tanul,
	fanio,fmes
	from ats_11
	where concat(fanio,fmes)>="'.$mes1.'" and concat(fanio,fmes)<="'.$mes2.'" ';
	

$sql_anexot=$sql_anexo;
$res_anexot=mysql_query($sql_anexot,$link_vcrx);

$sql_anexo.=' group by fanio,fmes ';
$sql_anexo.=' order by fanio desc, fmes desc';
$res_anexo=mysql_query($sql_anexo,$link_vcrx);
// echo $sql_anexo;s
echo str_repeat('-',date('s')*2).'';

?>
<table align="center" id="tabla_cxccli" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">

<tr style="border-top:solid 2px;border-bottom:solid 1px; ">
	<th colspan=5></th>
	<th colspan=4 style="border-left:solid 1px;">COMPRAS</th>
	<th colspan=6 style="border-left:solid 1px;">RET.COMP</th>
	<th colspan=4 style="border-left:solid 1px;">VENTAS</th>
	<th colspan=6 style="border-left:solid 1px;">RET.VTAS</th>
	<th style="border-left:solid 1px;"></th>
</tr>	

<tr style="border-bottom:#000000 solid 2px; ">
	<th >103</th>
	<th >104</th>
	<th >ATS</th>
	<th >ANIO</th>
	<th >MES</th>
	<th style="border-left:solid 1px;">ST-IVA 0</th>
	<th >ST-IVA</th>
	<th >IVA</th>
	<th >Regs.</th>
	<th style="border-left:solid 1px;">Base.IR</th>
	<th >Ret.IR</th>
	<th >Reg.IR</th>
	<th >B.IVA</th>
	<th >Ret.IVA</th>
	<th >Reg.IVA</th>
<!-- 
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
	 -->
	<th style="border-left:solid 1px;">ST-IVA 0</th>
	<th >ST-IVA</th>
	<th >IVA</th>
	<th >Regs.</th>
	<th style="border-left:solid 1px;">Base.IR</th>
	<th >Ret.IR</th>
	<th >Reg.IR</th>
	<th >B.IVA</th>
	<th >Ret.IVA</th>
	<th >Reg.IVA</th>
	<th style="border-left:solid 1px;border-right:solid 1px;">ANUL.</th>
<!-- 	<th width ="5%"style="border-left:solid 1px;"></th> -->
</tr>

<?php 
$filax=0;
$umdlo='';

while($r_anexo=mysql_fetch_assoc($res_anexo))
{
$duni=2;
?>
	<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >
	<td>
  <a href="../lib/vr103js1.php?fanio=<?php echo $r_anexo['fanio']; ?>&fmes=<?php echo $r_anexo['fmes']; ?>" >
		<img src="http://vcrxol.com/_img/ico_xml1.png" width="20"  title="Descargar  <?php echo 'F103_'.$r_anexo['fanio'].$r_anexo['fmes'];?>" target="_blank" />
		</a>
	</td>
	<td>
  <a href="../lib/vr104xml1.php?fanio=<?php echo $r_anexo['fanio']; ?>&fmes=<?php echo $r_anexo['fmes']; ?>" >
		<img src="http://vcrxol.com/_img/ico_xml1.png" width="20"  title="Descargar  <?php echo 'F104_'.$r_anexo['fanio'].$r_anexo['fmes'];?>" target="_blank" />
		</a>
	</td>
	<td>
  <a href="../lib/vratsxml1.php?fanio=<?php echo $r_anexo['fanio']; ?>&fmes=<?php echo $r_anexo['fmes']; ?>" >
		<img src="http://vcrxol.com/_img/ico_xml1.png" width="20"  title="Descargar  <?php echo 'ATS_'.$r_anexo['fanio'].$r_anexo['fmes'];?>" target="_blank" />
		</a>
		</td>

	<td align="center"><?php echo'<span title="'.$r_anexo['fanio'].'">'.$r_anexo['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="anexo1d('I','<?php echo $r_anexo['fmes']; ?>',this);"><?php echo '<span title="'.$r_anexo['fmes'].'">'.$r_anexo['fmes'].'</span>';?></a> </td>

   	<td align="right" style="border-left:solid 1px;"><?php if($r_anexo['tcomp']!=0){echo number_format($r_anexo['stiva0c'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['stivac']!=0){echo number_format($r_anexo['stivac'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tivac']!=0){echo number_format($r_anexo['tivac'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trcomp']!=0){echo number_format($r_anexo['trcomp'],0);}?></td>
   	<td align="right" style="border-left:solid 1px;"><?php if($r_anexo['tbaseirc']!=0){echo number_format($r_anexo['tbaseirc'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseirc']!=0){echo number_format($r_anexo['treteirc'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trretirc']!=0){echo number_format($r_anexo['trretirc'],0);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseivac']!=0){echo number_format($r_anexo['tbaseivac'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseivac']!=0){echo number_format($r_anexo['treteivac'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trretivac']!=0){echo number_format($r_anexo['trretivac'],0);}?></td>
<!-- 
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		 -->
   	<td align="right" style="border-left:solid 1px;"><?php if($r_anexo['tvtas']!=0){echo number_format($r_anexo['stiva0v'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['stivav']!=0){echo number_format($r_anexo['stivav'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tivav']!=0){echo number_format($r_anexo['tivav'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trvtas']!=0){echo number_format($r_anexo['trvtas'],0);}?></td>
   	<td align="right" style="border-left:solid 1px;"><?php if($r_anexo['tbaseirv']!=0){echo number_format($r_anexo['tbaseirv'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseirv']!=0){echo number_format($r_anexo['treteirv'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trretirv']!=0){echo number_format($r_anexo['trretirv'],0);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseivav']!=0){echo number_format($r_anexo['tbaseivav'],$duni);}?></td>
   	<td align="right"><?php if($r_anexo['tbaseivav']!=0){echo number_format($r_anexo['treteivav'],$duni);}?></td>
   	<td align="center"><?php if($r_anexo['trretivav']!=0){echo number_format($r_anexo['trretivav'],0);}?></td>
   	<td align="center" style="border-left:solid 1px;border-right:solid 1px;"><?php if($r_anexo['tanul']!=0){echo number_format($r_anexo['tanul'],0);}?></td>
	</tr>
<?php }?>
<tr style="border-top:solid 1px;border-bottom:solid 1px;">
	<th colspan="5">TOTALES</th>
   	<th align="right" style="border-left:solid 1px;"><?php echo number_format(mysql_result($res_anexot,0,'stiva0c'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'stivac'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'tivac'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trcomp'),0);?></th>
   	<th align="right" style="border-left:solid 1px;"><?php echo number_format(mysql_result($res_anexot,0,'tbaseirc'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'treteirc'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trretirc'),0);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'tbaseivac'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'treteivac'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trretivac'),0);?></th>
<!-- 
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
	 -->
		<th align="right" style="border-left:solid 1px;"><?php echo number_format(mysql_result($res_anexot,0,'stiva0v'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'stivav'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'tivav'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trvtas'),0);?></th>
   	<th align="right" style="border-left:solid 1px;"><?php echo number_format(mysql_result($res_anexot,0,'tbaseirv'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'treteirv'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trretirv'),0);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'tbaseivav'),$duni);?></th>
   	<th align="right"><?php echo number_format(mysql_result($res_anexot,0,'treteivav'),$duni);?></th>
   	<th align="center"><?php echo number_format(mysql_result($res_anexot,0,'trretivav'),0);?></th>
   	<th align="center" style="border-left:solid 1px;border-right:solid 1px;"><?php echo number_format(mysql_result($res_anexot,0,'tanul'),0);?></th>
</tr>	
</table>
</div>