<?php
 header("Access-Control-Allow-Origin: *");
 header("Content-Type: application/json; charset=UTF-8");
include 'dbconfig.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
}
// Access-Control headers are received during OPTIONS requests
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(0);
}

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$json = json_decode(file_get_contents('php://input'), true);
$serviceid=$json['serviceid'];
$subid=$json['subid'];
$vendor_id=$json['vendor_id'];
//$serviceid= '6';
//$subid= '6';	
//$vendor_id="1001";
$sql = "SELECT sp.*,ss.service_id from serviceprice sp INNER JOIN subservices ss ON ss.id=sp.service_id  INNER JOIN services  ON services.id=sp.service_id WHERE sp.service_id='".$serviceid."' AND sp.subservice_id='".$subid."' and vendor_id='$vendor_id'";
$result = $conn->query($sql);
$arr=array();
while($row = mysqli_fetch_assoc($result)) {
$discountprice=0;
if(($row['discount']==0)|| ($row['discount']=='')){
$total=($row['default_price']); 	
}else{
$discountprice=ROUND(($row['default_price'])*($row['discount']/100));
$total=(($row['default_price'])- $discountprice); 
}
$image=$base_url."image/service.jpg";
if(@is_array(getimagesize($base_url."/image/services/".$row['banner_image']))){
 $image=$base_url."image/services/".$row['banner_image']; 
}
     $arr[]=array("id" => $row['id'],"service_id" => $row['service_id'],"service_name" => $row['service_name'],"image" => "".$base_url."image/services/".$row['service_image'],"banner_image"=>$image,"price" => $row['default_price'],"discount_price" => $total,"discount" => $row['discount'],"description_title" => $row['description_title'],"short_desc_title" => $row['short_description_title'],"description" => strip_tags($row['description']),"short_desc" => strip_tags($row['short_description']),"status" => $row['status'],"qty" => 0);
}
$data = array("data" => $arr);
echo json_encode($data);     
$conn->close();
?>