 <?php

  if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }



//$eje2=verificacorre($connection,$_SESSION['e_id'],$_SESSION['suc_id']);

//echo $eje2+1;
  

  	function verificacorre($connection2,$est,$suc_id,$database,$suc_id,$est_id)
   {
  	
   $montoesql3="select    sum(". $_SESSION['database'].".operacion.op_subtotalneto) as monto,e_corre_eop	 as e_corre_eop  from  ". $_SESSION['database'].".operacion 
   
   left outer join ".$_SESSION['database'].".estaciones on  ". $_SESSION['database'].".operacion.op_estacion=".$_SESSION['database'].".estaciones.e_id
   
   and ".$_SESSION['database'].".estaciones.e_id=".$est." and ".$_SESSION['database'].".estaciones.suc_id=".$suc_id." 
   
    where  ".$_SESSION['database'].".operacion.suc_id=".$suc_id."  and (op_tipo=2 or op_tipo=16) limit 1";


$qur = $connection2->query($montoesql3);

//echo $montoesql3;

$_SESSION['op_id'] ="NO";
$_SESSION['monto'] ='0';

while($r = mysqli_fetch_assoc($qur)){

$_SESSION['monto'] = $r['monto'];

$_SESSION['e_corre_eop'] = $r['e_corre_eop'];


}
$url1="http://54.244.208.51/rest/v2/ver2.php";


//$database='8_final1';

$monto=$_SESSION['monto'];
$pack=$_SESSION['e_corre_eop'] ;
$ip='2';

$parametros_post = 'dbname='.urlencode($database)
                               .'&suc_id='.urlencode($suc_id)
                               .'&est_id='.urlencode($est_id)
                               .'&monto='.urlencode($monto)
                               .'&pack='.urlencode($pack)
                               .'&ip='.urlencode($ip);

    $ch = curl_init($url1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
   curl_setopt ($ch, CURLOPT_POSTFIELDS, $parametros_post); 
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $result = curl_exec($ch);
    curl_close($ch);


//echo   $result;

$data = json_decode($result,TRUE);

$corre=$data['corre'];

return $corre;

}

?>