<?php
error_reporting(0);
include 'connect.php';
$json = file_get_contents('php://input');
$objdata = json_decode( $json );
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");

$businessids = $objdata->{'businessids'};
$usertoken = $objdata->{'usertoken'};


$url1 = $site_api_url_fetch.'/orders?orderBy=-id&page=0&page_size=50&where=[{%22attribute%22:%22status%22,%22value%22:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},{%22conector%22:%22OR%22,%22conditions%22:[{%22attribute%22:%22products%22,%22conditions%22:[{%22attribute%22:%22type%22,%22value%22:{%22condition%22:%22=%22,%22value%22:%22item%22}}]},,{"conector":"AND","conditions":[{"attribute":"business_id","value":'.$businessids.'}]}],{%22attribute%22:%22products%22,%22conditions%22:[{%22attribute%22:%22type%22,%22value%22:{%22condition%22:%22=%22,%22value%22:%22service%22}}]}]}]';

/*$url1 = $site_api_url_fetch.'/orders?orderBy=-id&page=1&page_size=50&where={"conditions":[{"conector":"OR","conditions":[{"attribute":"products","conditions":[{"attribute":"type","value":{"condition":"=","value":"item"}}]},{"attribute":"cloned_order_id","value":{"condition":"!=","value":null}},{"attribute":"delivery_type","value":{"condition":"=","value":9}}]},{"attribute":"status","value":[0,13,1,11,15,7,8,4,9,3,14,18,19,20,21,22,23,24,25,26]},{"conector":"AND","conditions":[{"attribute":"business_id","value":'.$businessids.'}]}],"conector":"AND"}&mode=dashboard';*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json',
  'Accept: application/json',
  'Authorization: Bearer '.$usertoken
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$busordresult = curl_exec($ch);
$busorders = json_decode($busordresult);

$ordbusinessarr = array();
$ordbusinessarrids = array();
foreach($busorders->result as $bus){
  if (!in_array($bus->business_id, $ordbusinessarrids))
  {
    $bus->business->id = $bus->business_id;
    array_push($ordbusinessarr, $bus->business);
    array_push($ordbusinessarrids, $bus->business_id);
  }

}
//file_put_contents('stest.txt', json_encode($ordbusinessarr ));
echo json_encode($ordbusinessarr);
?>
