<?php 
session_start();

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

require('vrcospro.php');
include('php_gene1.php');

$xacceso=0;
$sql_acce='select * from usrdoc1 where (docu like "IB%" or docu like "EB%") 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;}

$xacceso=1;

if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a Informe de Inventario ' );}	
	


$fini1= date('2000-01-01');
$sql_fini1='select * from empr0';
$res_fini1=mysql_query($sql_fini1,$link_vcrx);
$fini1=mysql_result($res_fini1,0,'empr_finve');


$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-120 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y/m/j' , $nuevafecha );
$xfecha1= date('Y/m/'.'1');
$xfecha2= date('Y/m/d');

$xtotcost=0;
$xtotpvp1=0;

//	if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
//	{$fini1=date('2010-11-01');}



$xmodi='0';
if(isset($_POST['xmodi']) && !empty($_POST['xmodi']))
{$xmodi=$_POST['xmodi'];}


// echo '****'.$xmodi;


$enti=$_POST['enti'];
	if(isset($_POST['fecha_ini']) && !empty($_POST['fecha_ini']))
	{
		$fini=$_POST['fecha_ini'];
	}
	else
	{
		$fini=$fini1;
	}
	
	if(isset($_POST['fecha_fin']) && !empty($_POST['fecha_fin']))
	{
		$ffin=$_POST['fecha_fin'];
	}
	else
	{
		$ffin=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'];
}



$sql_itemres='drop view qitemres';
$res_itemres=mysql_query($sql_itemres,$link_vcrx);

//echo $sql_itemres;
$sql_bode= 'select * from bode0 where bode_status not like "X" and bode_status not like "I" order by bode_codigo';

$sql_inves='select inve12.*,
	sum(case when fecha<"'.$xfecha1.'" then tcant end) as ttcanti,
	sum(case when fecha>="'.$xfecha1.'" and fecha<="'.$xfecha2.'" then tingreso end) as ttingreso,
	sum(case when fecha>="'.$xfecha1.'" and fecha<="'.$xfecha2.'" then tegreso end) as ttegreso,
	sum(tcant) as ttcant,
	sum(tsubt) as ttsubt,
	sum(total) as ttotal,
	sum(valpvp) as tvalpvp
	from inve12 where ';
//$sql_inves.='fecha >= "'.$fini1.'" AND fecha <= "'.$ffin.'"';
$sql_inves.='fecha >= "'.$fini1.'" AND fecha <= "'.$xfecha2.'"';


if(isset($_POST['fposi']) && ($_POST['fposi']=='true'))
{$xfposi=$_POST['fposi'];}
else
{$xfposi='false';}

if(isset($_POST['fcero']) && ($_POST['fcero']=='true'))
{$xfcero=$_POST['fcero'];}
else
{$xfcero='false';}

if(isset($_POST['fnega']) && ($_POST['fnega']=='true'))
{$xfnega=$_POST['fnega'];}
else
{$xfnega='false';}

if($xfposi=='false' && $xfnega=='false' && $xfcero=='false')
{$xfposi='true';}

$xfrepo='';
if(isset($_POST['frepo']) && !empty($_POST['frepo']))
{$xfrepo=$_POST['frepo'];}



if($xfrepo=='D')
{
  $sql_inves='select * from inve12 where ';
  $sql_inves.='fecha >= "'.$xfecha1.'" AND fecha <= "'.$xfecha2.'"';
}  



$xfcodi='1';
if (mb_stristr('elco',substr($_SESSION['user_vcrx_empr'],0,4)))
{$xfcodi='2';}


if(isset($_POST['fcodi']) && !empty($_POST['fcodi']))
{$xfcodi=$_POST['fcodi'];}

switch ($xfcodi)
{
	case '1': $item_codi='item';break;
	case '2': $item_codi='item_codigov';break;
	case '3': $item_codi='item_ean';break;
	default : $item_codi='item';break;
}
//echo $item_codi;


$xfdocu='';
if(isset($_POST['fdocu']) && !empty($_POST['fdocu']))
{
	$sql_inves.=' and  (docu like "'.$_POST['fdocu'].'%" or docu_descri like "%'.$_POST['fdocu'].'%" ) ';
	$xfdocu=$_POST['fdocu'];
}

$xfbode='';
if(isset($_POST['fbode']) && !empty($_POST['fbode']))
{
	$sql_inves.=' and  (bode like "'.$_POST['fbode'].'%" or bode_descri like "%'.$_POST['fbode'].'%" ) ';
	$xfbode=$_POST['fbode'];
}

if(isset($_POST['flsub']) && !empty($_POST['flsub']))
{
	$sql_inves.=' and  (item_lsub like "'.$_POST['flsub'].'%" or lsub_descri like "%'.$_POST['flsub'].'%" ) ';
	$xflsub=$_POST['flsub'];
}


if(isset($_POST['fitem']) && !empty($_POST['fitem']))
{
	$sql_inves.=' and  (item like "'.$_POST['fitem'].'%" or item_descri like "%'.$_POST['fitem'].'%" ) ';
	$xfitem=$_POST['fitem'];
}

if(isset($_POST['fmrca']) && !empty($_POST['fmrca']))
{
	$sql_inves.=' and  (item_mrca like "'.$_POST['fmrca'].'%" ) ';
	$xfmrca=$_POST['fmrca'];
}

if(isset($_POST['fmdlo']) && !empty($_POST['fmdlo']))
{
	$sql_inves.=' and  (item like "%'.$_POST['fmdlo'].'%" ) ';
	$xfmdlo=$_POST['fmdlo'];
}

$xfcost='false';
if(isset($_POST['fcost']) && ($_POST['fcost']=='true'))
{$xfcost=$_POST['fcost'];}

$xfpuni='false';
if(isset($_POST['fpuni']) && ($_POST['fpuni']=='true'))
{$xfpuni=$_POST['fpuni'];}

$xfpvp1='false';
if(isset($_POST['fpvp1']) && ($_POST['fpvp1']=='true'))
{$xfpvp1=$_POST['fpvp1'];}

$xfrese='false';
if(isset($_POST['frese']) && ($_POST['frese']=='true'))
{$xfrese=$_POST['frese'];}

$xmpuni='false';
if(isset($_POST['mpuni']) && ($_POST['mpuni']=='true'))
{$xmpuni=$_POST['mpuni'];}

$xmpvp1='false';
if(isset($_POST['mpvp1']) && ($_POST['mpvp1']=='true'))
{$xmpvp1=$_POST['mpvp1'];}

if ($xmpuni=='true' && $xmpvp1=='true'){$xmpvp1='false';}

$xmhoja='false';
if(isset($_POST['mhoja']) && ($_POST['mhoja']=='true'))
{$xmhoja=$_POST['mhoja'];}

$xmimgi='false';
if(isset($_POST['mimgi']) && ($_POST['mimgi']=='true'))
{$xmimgi=$_POST['mimgi'];}


if(isset($_POST['fctlg']) && !empty($_POST['fctlg']))
{
	$sql_inves.=' and  (item_nctlg ='.$_POST['fctlg'].' )';
	$xfctlg=$_POST['fctlg'];
}


	$sql_inves.=' and(status!="X") ';
	$sql_inves.=' and(status!="O") ';

$xgroup = 'item ';
$xgroup = 'item_lsub,item ';


$xforde='D';
if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
{$xforde='C';}

if(isset($_POST['forde']) && !empty($_POST['forde']))
{$xforde=$_POST['forde'];}

$xorder='';
if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
{$xorder='item_nctlg desc,';}

switch ($xforde)
{
	case 'D':$xorder.='item_lsub,item_descri,item ';break;
	case 'C':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',item',','.$item_codi.',item_descri,item',$xorder);break;
	case 'T':$xorder.='ttcant desc,item_lsub,item  ';break;

	default :$xorder=$xgroup;break;
}




if($xmodi=='2')
{
  $xfrepo='D';
}

$xbodes=0;
$xwidth = 100;
if ($xfrepo=='D')
{
  $xorder='fecha, signo desc, docu, numero ';
}  

if ($xfrepo=='B')
{
		$xfecha1=date('Y-m-01',strtotime($xfecha1));
		$xfecha2=date('Y-m-t', strtotime($xfecha2));
		$xf2col='false';
// 		$sql_bodes='select distinct bode from inve11 where fecha>="'.$xfecha1.'" and fecha<="'.$xfecha2.'" order by bode';
		$sql_bodes='select distinct bode from inve1 where fecha>="'.$xfecha1.'" and fecha<="'.$xfecha2.'" order by bode';
		$res_bodes=mysql_query($sql_bodes,$link_vcrx);
		$xbodes = mysql_num_rows($res_bodes);
		$xcbod=0;
		$sql_pivot='';
		while ($r_bod0=mysql_fetch_assoc($res_bodes))	
		{
			$xcbod++;
			$xbod=$r_bod0['bode'];
			$sql_pivot.='sum(case when bode="'.$xbod.'" then tcant end) as s'.$xbod.',';	
			$sql_pivot.='sum(case when bode="'.$xbod.'" then tingreso end) as d'.$xbod.',';	
			$sql_pivot.='sum(case when bode="'.$xbod.'" then tegreso end) as c'.$xbod.',';	
		}

	$sql_inves=str_replace($xfecha1,$xfecha1c,$sql_inves);
	$sql_inves=str_replace('inve12.*,','inve12.*,'.$sql_pivot,$sql_inves);

	$sql_invest=str_replace($xfecha1,$xfecha1c,$sql_invest);
	$sql_invest=str_replace('inve12.*,','inve12.*,'.$sql_pivot,$sql_invest);
// 		echo $sql_inves;
	if($xbodes>6){$xwidth = 100 + ($xbodes-6)*10;}
	
}
// echo $sql_pivot;

// $res_invest=mysql_query($sql_inves,$link_vcrx);
$sql_inves.=' group by '.$xgroup;


// echo '****'.$xmodi;


if($xmodi=='1')
{
	$xfgrou=$xmodi;
}

if($xmodi=='2' or $xfrepo=='D')
{
	$sql_inves=str_replace('sum','',$sql_inves);
	$sql_inves=str_replace('group by ','group by idnum1,iddet,',$sql_inves);
	$sql_inves.=',iddet';
	$xfgrou=$xmodi;
}

$sql_inves.=' order by '.$xorder;
$res_inves=mysql_query($sql_inves,$link_vcrx);

// echo '*****'.$xmodi;

// echo $sql_inves;
// echo str_repeat('-',date('s')*2).'';

// echo explain_sql($sql_inves);
?>


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

<?php if($xfrepo=='D'){?>
<tr style="border-bottom:#000000 solid 2px; ">
	<th></th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>PROVEEDOR</th>
	<th>CODIGO</th>
	<th>ITEM</th>
	<th>DETALLE</th>
	<th>CANT.</th>
	<th>P.UNI</th>
	<th></th>
	<th></th>
  </tr> 
   
<?php } ?>


  
<?php if($xfrepo=='G' or $xfrepo=='B'){?>
<tr style="border-bottom:#000000 solid 2px; ">

  <th></th>
	<th >LINEA</th>
	<th >ITEM</th>

	<th width="1%" style="	<?php if ($xmhoja!='true'){echo 'display:none;'; }?>">HOJA</th>
	<th width="1%" style="	<?php if ($xmhoja!='true'){echo 'display:none;'; }?>">TVIR</th>
	
	<th width="1%" style="	<?php if ($xmimgi!='true'){echo 'display:none;'; }?>">IMG</th>
	
	<?php if ($xmcost=='true'){ ?>
<!-- 	<th width="1%"></th> -->
	<?php }  ?>

	<th width="1%" align="center" style="">
	<?php if ($xmpuni=='true'){ ?>
    P.Unit
	<?php }  ?>
  </th>
	<th width="1%" align="center" style="">
	<?php if ($xmpvp1=='true'){ ?>
    P.V.P.
	<?php }  ?>
  </th>

	<?php if ($xmpuni=='true' || $xmpvp1=='true'){ ?>
	<td></td>
	<?php }  ?>
	
	<?php if ($xmpuni=='true' || $xmpvp1=='true' || $xmhoja=='true'){ ?>
	<th width="1%" align="right">SALDO</th>
	<th width="1%"></th>
	<?php }  ?>
	
	<th >DESCRIPCION</th>

	<th align="right">INIC.</th>
	<th align="right">INGR.</th>
	<th align="right">EGRE.</th>
	<th align="right">SALDO</th>
	<td>.</td>

<?php	
if ($xfrepo=='B')
{
		$xf2col='false';
		$res_bodes=mysql_query($sql_bodes,$link_vcrx);
		$xbodes = mysql_num_rows($res_bodes);
		$xcbod=0;
		$sql_pivot='';
		while ($r_bod0=mysql_fetch_assoc($res_bodes))	
		{
			$xbod=$r_bod0['bode'];
			if ($xbod==""){$xbod="B---";}
			echo '<th align="right">'.$xbod.'</th>';
		}
}
?>
	
	<?php if ($xfcost=='true'){ ?>
	<th align="right">COSTO</th>
	<th align="right">T.COSTO</th>
	<?php } ?>

	<?php if ($xfpuni=='true'){ ?>
	<th align="right">P.Unit.</th>
	<th align="right">T.P.Uni</th>

	<?php } ?>
	<?php if ($xfpvp1=='true'){ ?>
	<th align="right">PVP</th>
	<th align="right">T.PVP</th>
	<?php } ?>
	
	
	
<!-- 	<th>DESCRIPCION</th> -->
	<th>MARCA/MODELO</th>
	<th>CTLG</th>
	
	<?php if ($xfrese=='true'){ ?>
	<th width="1%">RESER</th>
	<th width="1%">DISPO</th>
	<?php }  ?>


</tr>
<?php } ?>

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

//$urcdd='';
// 	include('php_gene1.php');
// echo $sql_inves;
// 	explain_sql($sql_inves);
?>
<?php  
while($r_inves=mysql_fetch_assoc($res_inves))
{
$docu=$r_inves['docu'];
$duni=$r_inves['item_duni'];
$dval=$r_inves['item_dval'];
?>

<?php if($xfrepo=='D'){ ?>
	<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" valign="top" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;'; $filax=1;}else{$filax++;} ?>" >
<td>
		<a href="../print1.php?prnt=1&docu=<?php echo $r_inves['docu']; ?>&idnum=<?php echo $r_inves['idnum1']; ?>&formato=1" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_inves['docu'];?>-<?php echo $r_inves['numero'];?>"  /></a>
</td>
        <td align="center"><?php echo'<span title="'.$r_inves['docu'].'">'.$r_inves['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="inves1d('<?php echo $xfgrou; ?>','<?php echo $r_inves['idnum1']; ?>',this);" tabindex="-1"><?php echo '<span title="'.$r_inves['ptonumero'].'">'.$r_inves['numero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_inves['fechadmy'].'">'.$r_inves['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_inves['enti'].'">'.$r_inves['enti_descri'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_inves['item'].'">'.$r_inves['item'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_inves['item'].'">'.$r_inves['item_descri'].'</span>';?></td>

		<td align="left"><?php echo'<span >'.$r_inves['concepto'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_inves['cant'],2);?></td>
   	<td align="right"><?php echo number_format($r_inves['puni'],2);?></td>

<?php if($xmodi=='2'){?>    
<td style="<?php if(!mb_stristr('IB',substr($docu,0,2))){echo 'display:none;';} ?>">
		<?php $pcaption=$r_inves['puni'];  $pidtxt='puni_'.$r_inves['idnum1'].'_'.$r_inves['iddet']; $pdefa=$r_inves['puni']; $pobj=1; include('vrgetval.php'); ?>
</td>
		<td>
			<?php $pcaption='Modif';  $ponclick='_modi2('.$r_inves['idnum1'].','.$r_inves['iddet'].'); '; include('vrbutton.php'); ?>
		</td>
		<td style="font-size:10px;"><div id="error_<?php echo $r_inves['idnum1'];?>_<?php echo $r_inves['iddet'];?>"></div></td>
<?php } ?>

		
	<th></th>
  </tr>  
<?php } ?>  
  
<?php if($xfrepo=='G' or $xfrepo=='B'){ ?>
<?php	
if(($xfposi=='true' && $r_inves['ttcant']>0) || ($xfcero=='true' && $r_inves['ttcant']==0) || ($xfnega=='true' && $r_inves['ttcant']<0))
{

$xsalda=0;
$xreser=0;
$xdispo=0;
	
if ($xfrese=='true')	
{
	$sql_itemres='select reserva,item from invrese where item="'.$r_inves['item'].'"';
	$res_itemres=mysql_query($sql_itemres,$link_vcrx);
	if (mysql_num_rows($res_itemres)!=0)
	{
		$xreser=mysql_result($res_itemres,0,'reserva');
		$xdispo=$r_inves['ttcant']-$xreser;
	}
}
//echo $sql_itemres;
?>

<?php	
if ($r_inves['item_modelo']==$umdlo)
{if($umdlo==$pmdlo){$filax=1;}}
else
{if($umdlo!=$pmdlo){}else{$filax=4;}}

$pmdlo=$umdlo;
$umdlo=$r_inves['item_modelo'];

?>
	<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" valign="top" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;'; $filax=1;}else{$filax++;} ?>" >

	<td>
    <a href="../lib/impr_inves1d.php?grupo=I&idnum=<?php echo $r_inves['item']; ?>&bode=<?php echo $xfbode; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>&fcost=<?php echo $xfcost; ?>" target="_blank" tabIndex="-1" >
		<img src="http://vcrxol.com/_img/print2.png" tabIndex="-1" width="20"  title="Imprimir  <?php echo $r_inves['item'];?>"  />
		</a>
	</td>

	<td align="center"><?php echo'<span title="'.$r_inves['item_lsub'].'">'.$r_inves['lsub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="inves1d('I','<?php echo $r_inves['item']; ?>',this);"><?php echo '<span title="'.$r_inves['item_ean'].'">'.$r_inves[$item_codi].'</span>';?></a> </td>

	<td width="1%" style="	<?php if ($xmhoja!='true'){echo 'display:none;'; }?>">
		<?php $pidtxt='hoja_'.$r_inves['item']; $ponclick='_modii('.$r_inves['item'].');'; $pdefa=$r_inves['item_hoja']; include('vrchkbox.php'); ?>
	</td>
	<td width="1%" style="	<?php if ($xmhoja!='true'){echo 'display:none;'; }?>">
		<?php $pidtxt='carr_'.$r_inves['item']; $ponclick='_modii('.$r_inves['item'].');'; $pdefa=$r_inves['item_carr']; include('vrchkbox.php'); ?>
	</td>
		
	<td width="20%" style="	<?php if ($xmimgi!='true'){echo 'display:none;'; }?>">
		<?php $pcaption='Subir'; $pidtxt='imag_'.$r_inves['item']; $paccept="image/*"; $ponclick="_uplimgi('".$pidtxt."','".$r_inves['item']."');"; $pobj=2; include('vrgetfil.php'); ?>
		<a href="#" onClick="inves1d('G','<?php echo $r_inves['item']; ?>',this);"><?php echo '<span title="'.$r_inves['item_ean'].'">'.$r_inves[$item_codi].'</span>';?></a> 
	</td>
		
<!-- 	<td width="1%"> -->
		<?php //$pcaption='Costo'; $pidtxt='cost_'.$r_inves['item']; $pobj=1; $pdefa=number_format($r_inves['item_pcp1'],4) ;include('vrgetval.php'); ?>
<!-- 	</td> -->

	<td width="1%" style="">
    <?php if ($xmpuni=='true'){ ?> 
		<?php $pcaption='P.Unit'; $pidtxt='puni_'.$r_inves['item']; $pobj=1; $pdefa=number_format($r_inves['item_puni'],4) ;include('vrgetval.php'); ?>
    <?php } ?>
	</td>

	<td width="1%" style="">
    <?php if ($xmpvp1=='true'){ ?> 
		<?php $pcaption='P.V.P.'; $pidtxt='pvp1_'.$r_inves['item']; $pobj=1; $pdefa=number_format($r_inves['item_pvp'],4) ;include('vrgetval.php'); ?>
    <?php } ?>
	</td>

	<?php if ($xmpuni=='true' || $xmpvp1=='true'){ ?>
	<td width="1%">	<?php $pcaption='Modi'; $ponclick='_modii('.$r_inves['item'].');';  include('vrbutton.php'); ?>	</td>
	<?php }  ?>
    
	<?php if ($xmpuni=='true' || $xmpvp1=='true' || $xmhoja=='true'){ ?>
  <td align="right"><?php if($r_inves['ttcant']<0){echo '<font color="red">';} ?> <?php echo '<b>'.number_format($r_inves['ttcant'],$duni);?></td>
	<td style="font-size:10px;"><div id="error_<?php echo $r_inves['item'];?>"></div></td>
	<?php }  ?>
		
		<td align="left"><?php echo'<span title="'.$r_inves['item_modelo'].'">'.$r_inves['item_descri'].'</span>';?></td>

   	<td align="right"><?php if($r_inves['ttcanti']<0){echo '<font color="red">';} ?> <?php echo '<b>'.number_format($r_inves['ttcanti'],$duni);?></td>
   	<td align="right"><?php if($r_inves['ttingreso']!=0){echo number_format($r_inves['ttingreso'],$duni);}?></td>
   	<td align="right"><?php if($r_inves['ttegreso']!=0){echo '<i>'.number_format($r_inves['ttegreso'],$duni);}?></td>
   	<td align="right"><?php if($r_inves['ttcant']<0){echo '<font color="red">';} ?> <?php echo '<b>'.number_format($r_inves['ttcant'],$duni);?></td>

	<td></td>

	<?php	

if ($xfrepo=='B')
{
		$xf2col='false';
		$res_bodes=mysql_query($sql_bodes,$link_vcrx);
		$xbodes = mysql_num_rows($res_bodes);
		$xcbod=0;
		$sql_pivot='';
		while ($r_bod0=mysql_fetch_assoc($res_bodes))	
		{
			$xbod=$r_bod0['bode'];
			echo '<td  align="right">'.number_format($r_inves['s'.$xbod],$duni).'</td>';
		}
}
?>

	<?php if ($xfcost=='true'){ ?>
	<?php $xcospro = new cospro('../cfg/res.php'); ?>
	<?php $xcospro ->get_cospro($r_inves['item'],$xfecha2,1); ?>
	<?php $xcospro =$xcospro->cospro; ?>
	<?php $xstcos=0; if($r_inves['ttcant']>=0){$xstcos=$r_inves['ttcant']*$xcospro;} ?>
  <td align="right"><?php echo number_format($xcospro,2);?></td>
	<td align="right"><?php echo number_format($xstcos,2);?></td>
	<?php $xtotcost=$xtotcost+ $xstcos;?>	
	<?php } ?>

	<?php if ($xfpuni=='true'){ ?>
	<?php $xstpuni=0; if($r_inves['ttcant']>=0){$xstpuni=$r_inves['ttcant']*$r_inves['item_puni'];} ?>
  <td align="right"><?php echo number_format($r_inves['item_puni'],2);?></td>
	<td align="right"><?php echo number_format($xstpuni,2);?></td>
	<?php $xtotpuni=$xtotpuni+ $xstpuni;?>	
	<?php } ?>
		
	<?php if ($xfpvp1=='true'){ ?>
	<?php $xstpvp=0; if($r_inves['ttcant']>=0){$xstpvp=$r_inves['ttcant']*$r_inves['item_pvp'];} ?>
  <td align="right"><?php echo number_format($r_inves['item_pvp'],2);?></td>
	<td align="right"><?php echo number_format($xstpvp,2);?></td>
	<?php $xtotpvp1=$xtotpvp1+ $xstpvp;?>	
	<?php } ?>
		
<!-- 		
	<td align="left"><?php echo'<span title="'.$r_inves['item_modelo'].'">'.$r_inves['item_descri'].'</span>';?></td>
 -->
		<td align="center"><?php echo'<span title="'.$r_inves['item_modelo'].'">'.$r_inves['item_mrca'].'/'.$r_inves['item_modelo'].'</span>';?></td>
	<td align="center"><?php  if($r_inves['item_nctlg']>0){echo'<span title="Pag.'.$r_inves['item_pctlg'].'">'.$r_inves['item_nctlg'].'</span>';}?></td>

	<?php	if ($xfrese=='true')		{	 ?>
   	<td align="right"><?php if($xreser!=0){echo '<i>'.number_format($xreser,$duni);}?></td>
   	<td align="right"><?php if($xdispo<0){echo '<font color="red">';} ?> <?php echo number_format($xdispo,$duni);?></td>
	<?php }?>

	
	</tr>
<?php }
?>
  
<?php }?>

<?php if ($xfcost=='true' || $xfpuni=='true'|| $xfpvp1=='true'){ ?>
	
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
	<th></th>
	<th></th>
	<th></th>
	<th>TOTALES</th>
	<th></th>
	<th></th>
	<th></th>
	<th></th>
	<th></th>
<?php if ($xfcost=='true'){ ?>
	<th></th>
	<th align="right"><?php echo number_format($xtotcost,2);?></th>
<?php }?>
<?php if ($xfpuni=='true'){ ?>
	<th></th>
	<th align="right"><?php echo number_format($xtotpuni,2);?></th>
<?php }?>
<?php if ($xfpvp1=='true'){ ?>
	<th></th>
	<th align="right"><?php echo number_format($xtotpvp1,2);?></th>
<?php }?>
</tr>
<?php }?>

<?php }?>

</table>
</div>
	

<br>

