<?php
$responseArray = array();

$itemId = $_GET['itemId'];
$storeId = $_GET['storeId'];

if(!empty($itemId) && !empty($storeId)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://mybooster.true-pos.com/TruePOS/api/v1/items?q=itemId==$itemId");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
    'Content-Type: application/json',
    'X-Auth-Token: 59B2D9AB5F23F0B583158882F1B2E09B63B98B494B541C44504FE65F9190781F5A9E95755166E523',
    'Accept: application/json'    
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$server_output = curl_exec ($ch);
curl_close ($ch);

$isInStock = 0;
$storesArray = json_decode($server_output,true);
if(!empty($storesArray['items'])) {
	foreach($storesArray['items'] as $key=>$itemArray) {
	  if(!empty($itemArray['stock'])) {
		foreach($itemArray['stock'] as $tempKey=>$stockArray) {
			if($stockArray['outletId'] == $storeId && $stockArray['stock'] > 0) {
			 $isInStock = $stockArray['stock'];
			}			
		}
	  }	
	}
}
$responseArray['status'] = 'Success';
$responseArray['content'] = $isInStock;
} else {
	$responseArray['status'] = 'Error';
	$responseArray['content'] = 'Blank Item';
}

$response = json_encode($responseArray);
echo $response;
exit;
?>