<?php

include_once('lib_main.php');

echo '<br>*/*/*/* '.$empr0['empr_codigo'];

die();
if($empr0['empr_codigo']!='imcp'){return;}

$sql_caja='select * from caja1 left join caja2 on idnum1=idnum2 where docu="IE13" and ifnull(status,"")not in ("X") order by caja,fecha,idnum1 ';
$res_caja=msql_query($sql_caja,$link_data);


$xcaja='';
$xnum=0;

while($aso_caja=msql_fetch_assoc($res_caja))
{
     if($xcaja!=$aso_caja['caja']){$xnum=0; $xcaja=$aso_caja['caja'];}
     $xnum++;
     $xnume=str_pad($xnum, 9, "0", STR_PAD_LEFT);
     echo '<br>== '.$aso_caja['numero'];
     echo '<br>==>> '.$xnume;
     $sql_updt='update caja1 set numero="'.$xnume.'" where idnum1="'.$aso_caja['idnum1'].'"';
     $res_updt=msql_query($sql_updt,$link_data);
     echo '<br>==>> '.$sql_updt;

     $sql_updt='update cont1 set numero="'.$xnume.'" where idfrom="'.$aso_caja['idnum1'].'" and mdfrom="caja"';
     $res_updt=msql_query($sql_updt,$link_data);
     
     
     
     $sql_bcos='select * from bcos1 left join bcos2 on idnum1=idnum2 where ifnull(status,"") not in("O","X") and docum="IE13" and fecha="'.$aso_caja['fecha'].'" and cant="'.$aso_caja['cant'].'"';
     $res_bcos=msql_query($sql_bcos,$link_data);
     
     if(msql_num_rows($res_bcos)==1)
     {
          $sql_updt='update bcos2 set ptoem="'.$aso_caja['ptoe'].'", numer="'.$xnume.'" where idnum2="'.msql_result($res_bcos,0,'idnum1').'"';
          $res_updt=msql_query($sql_updt,$link_data);
          echo '<br>==>>+++++ '.$sql_updt;
     }
     
     
     
     
}



?>