
<?php

include 'conn.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
    }

//$link = mssql_connect('192.168.1.30', 'sa', 'sap123');
$link = mssql_connect('10.1.0.28', 'rctech', 'rc.tech.2016');
$_SESSION['itemcode'] = $_GET['itemcode'];

$_SESSION['itemcode1'] ="";
 
if (!$link)
    die('Unable to connect!');
 
if (!mssql_select_db('btocumen', $link))
    die('Unable to select database!');
    
    

  
 
$result = mssql_query("select  oitm.itemcode,a.price as venta,b.price as fob ,c.price as cif from oitm

left outer join itm1 a on oitm.itemcode=a.itemcode and a.pricelist=4

left outer join itm1 b on oitm.itemcode=b.itemcode and b.pricelist=1


left outer join itm1 c on oitm.itemcode=c.itemcode and c.pricelist=2");

$return_arr = array();

$total=0; 

while ($row = mssql_fetch_array($result)) {
    
   
  
  $row_array['itemcode'] = $row['itemcode'];
    $row_array['venta'] = $row['venta'];
    
      $row_array['fob'] = $row['fob'];
     $row_array['cif'] = $row['cif'];
  

   // array_push($return_arr,$row_array);
    
   

 $SQLupdate="insert into ocadb.prodoca1 (pr_id,precio1,fob,cif) values ('".$row['itemcode']."','".$row['venta']."','".$row['fob']."','".$row['cif']."') ";


// echo "sql: " . $SQLupdate;



if ($connection->query($SQLupdate) === TRUE) {
    $msg = array("success" => "true", "detalle" => "Detalle ejemplo");
    
   // echo 'paso '.$row['itemcode'];
   
  $total=$total+1;

} else {
	
	$msg = array("success" => "false", "detalle" => $conn);

   // echo "Error: " . $SQLupdate . "<br>" . $conn->error;
}



}

echo 'termino'.   $total ;

// header('content-type: application/json');
//echo json_encode($return_arr);
//echo $json;
@mysqli_close($connection);
mssql_free_result($result);
 
?>
