<?php
if(!isset($_SESSION)){ 
session_start(); 
}
	$out  = array('data'=>array());
	$CID = $_POST['cid'];

	if(ctype_digit(strval($CID)) AND $CID >0){
		$url = "http://www.keentech.co/projects/goran_api/public/products/".$CID."/sell_item";
	}else{
		$url = "http://www.keentech.co/projects/goran_api/public/sell_items";
		
	}

	$ch1 = curl_init();
	$headers = array(
				    'Accept: application/json',
				    'Content-Type: application/json',
				    'Authorization: Bearer '. $_SESSION['access_token'],
				    );
	curl_setopt($ch1, CURLOPT_URL,$url);
	curl_setopt($ch1, CURLOPT_HTTPGET, 1);
	curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch1, CURLOPT_HEADER, 0);

	// receive server response ...
	curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);

	$server_output1 = curl_exec ($ch1);

	curl_close ($ch1);

	$op = json_decode( $server_output1,True);
	//print_r(($server_output1));
	// conver stdclass object to array
	if(isset($op['message'])){
			
			
	}else{

	

				$OPT =array();
				for($i=0;$i<count($op['data']);$i++){
					$OPT[0] = $op['data'][$i]['id'];
					$OPT[1] = $op['data'][$i]['product_name'];
					$OPT[2] = $op['data'][$i]['quantity'];
					$OPT[3] = $op['data'][$i]['unit_price'];
					$OPT[4] = $op['data'][$i]['discount'];
					$OPT[5] = date('Y-m-d',strtotime($op['data'][$i]['created_at']));
					$OPT[6] = $op['data'][$i]['part_number'];
					$OPT[7] = $op['data'][$i]['invoice_id'];
					$OPT[8] = $op['data'][$i]['customer_name'];
					$OPT[9] = $op['data'][$i]['mobile'];
					$OPT[10] = $op['data'][$i]['address'];
					$OPT[11] = $op['data'][$i]['job'];
					$OPT[12] = $op['data'][$i]['product_id'];
					
					
					array_push($out['data'] , $OPT);
				} 
	}
	 // json_decode(json_encode($op->data->data), True);
	//print_r($array);
	//$out['data']=$server_output1->data;
	//$out['status']  = $op->status;
							
	echo json_encode($out);
		

?>