<?php
ob_start();
session_start();
 
date_default_timezone_set("Asia/Kolkata");
require_once("../config.php");

$fetch_service = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `sc_services` WHERE `service_id` = '".$_REQUEST['hid_service_id']."'"));

if($_REQUEST['chk'] == 'val1')
{
    $service_type = "Installation With Material";
    $price = $fetch_service['material_installation_cost'];
}
if($_REQUEST['chk'] == 'val2')
{
    $service_type = "Only Installation";
    $price = $fetch_service['installation_cost'];
}

$sql_check_order = "SELECT * FROM `sc_orders` ORDER BY `order_id` DESC LIMIT 0,1";
$exe_check_order = mysqli_query($connection,$sql_check_order);
$num_check_order = mysqli_num_rows($exe_check_order);
if($num_check_order>0)
{
	$arr_check_order = mysqli_fetch_array($exe_check_order);
	$new_order_no =  $arr_check_order['order_no']+1;
	$new_orderid =  'SKYCOM'.$new_order_no;
}
else
{
	$new_order_no =  '500';
	$new_orderid =  'SKYCOM500';
}

$sql_insert = "INSERT INTO `sc_orders` SET `user_id` = '".$_SESSION['USER_ID']."',`service_id` = '".$_REQUEST['hid_service_id']."',`service_type` = '".$service_type."',`price` = '".$price."',`order_no` = '".$new_order_no."',`orderid` = '".$new_orderid."',`post_date` = '".date('Y-m-d H:i:s',time())."'";
$exe_insert = mysqli_query($connection,$sql_insert);
$last_id = mysqli_insert_id($connection);

header("location: visit-payment.php?order_id=".$last_id);
?>