
<?php

date_default_timezone_set("America/Panama");
//$connection = new mysqli("db1.solucionesatc.com", "remoto", "1234") or die(mysqli_error());

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.0.0.50', 'sa', 'sap123');
$_SESSION['itemcode'] = $_GET['itemcode'];

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

  
 
$result = mssql_query("select  itemcode,onhand, CASE 
 WHEN whscode='01' THEN 1
     
   END as dep
	
	 from oitw where onhand>0 and whscode in ('01')");



 $jsonData      = array();
    $jsonTempData  = array();

$total=0; 
while ($r= mssql_fetch_array($result)) {
    
 

  $jsonTempData = array();
          $jsonTempData['itemcode']         = utf8_encode($r['itemcode']);
          
          $jsonTempData['dep']         = $r['dep'];
              $jsonTempData['onhand']         = $r['onhand'];
    
    
          $jsonData[] = $jsonTempData;

$i=$i+1;
};

 	$json->registros     =$i;
 	
 		$json->item     =  $jsonData;
 		
 	//echo json_encode( $json);
 	
 	$url1="http://db.rctech-soft.com/rest/171_calzashoes/v65/phpsqlserver/existencia.php";
 	
 	//$url1="http://200.115.145.197:3390/rest/171_calzashoes/v65/phpsqlserver/existencia.php";


$json9 = '{"registros":1,"item":[{"itemcode":"101","dep":"1","onhand":"6"}]}';


$parametros_post = 'datos='.json_encode($json9);

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




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

 
?>
