
<?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.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!');
    
    

  
 
$sql="SELECT top(100000) a.u_op_id as op_id,cast(a.DocDate as date) as dia,(doctotal-vatsum) as totalneto,'7' as suc_id from oinv a where

cast(A.docdate as date) BETWEEN '2017/10/01' AND '2017/10/16'  and left(a.u_op_id,1)='7'  
";

//echo $sql;

$result = mssql_query($sql);

$return_arr = array();

$total=0; 

while ($row = mssql_fetch_array($result)) {
    
   


 $SQLupdate="insert into 171_calzashoes.tmpcomparesap (op_id,dia,totalneto,suc_id) values ('".$row['op_id']."','".$row['dia']."','".$row['totalneto']."','".$row['suc_id']."') ";


// 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);
 
?>
