<?php 
session_start();
require('../cfg/res.php');
require('../../_lib/vrdocu0.php');
require('../../_lib/vr_invedocu.php');
require('vrcospro.php');

$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');


// $gene1_sql='select * from inve12 where status!="O" and fecha>="'.$fini1.'" ';
$gene1_sql='select distinct item, item_lsub, item_descri from inve12 where status!="O" ';

if(!empty($_POST['fini']) && !empty($_POST['ffin']))
{$gene1_sql.=' and ( fecha >= "'.$_POST['fini'].'" and fecha <= "'.$_POST['ffin'].'" ) ';}

if(!empty($_POST['lsub']) && !empty($_POST['lsub']))
{$gene1_sql.=' and item_lsub like "'.$_POST['lsub'].'%"';}

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

// $gene1_sql.=' order by item_lsub,item,fecha,signo desc,docu,idnum1 ';
$gene1_sql.=' order by item_lsub,item ';

$gene1_res=mysql_query($gene1_sql,$link_vcrx);

if(mysql_num_rows($gene1_res)==0)
{die('No se encontraron resultados');}

echo "\n";
echo $gene1_sql;

while($gene1_r=mysql_fetch_assoc($gene1_res))
{
echo "\n";
echo $gene1_r['idnum1'];
//   if(mb_stristr('EB10',$gene1_r['docu']))
  if(1==1)
  {
    echo "\n";
    echo '***'.$gene1_r['idnum1'];
    $xcospro = new cospro('../cfg/res.php'); 
//     $xcospro ->get_cospro($gene1_r['item'],$gene1_r['fecha']); 
    $xcospro ->get_cospro($gene1_r['item'],$_POST['ffin'],1); 
    $xcospro =$xcospro->cospro; 
    
//     $sql_updc='update inve2 set puni='.$xcospro.' where idnum2="'.$gene1_r['idnum2'].'" and iddet="'.$gene1_r['iddet'].'"';
//     $res_updc=mysql_query($sql_updc,$link_vcrx);

//     echo "\n";
//     echo $sql_updc;
    
  }
//   $inve=new vrinventar($gene1_r['docu'],$gene1_r['idnum1']);
}



?>