<?php
error_reporting(0);
@session_start();
include("../config.php");
$empbranch = $_SESSION['branch'];
//$content=$_POST[content];

date_default_timezone_set('Asia/Kolkata');
$ptime = date( 'h:i:s A', time () );
//echo $currentTime;
$pdate =date("Y/m/d");

 $pname =$_POST['pname'];
 $price =$_POST['price'];   
$mobile =$_POST['mobile']; 
 $cid =$_POST['cid'];	 
 $ftyp =$_POST['ftyp'];
$mode = $_REQUEST[mode];
$prepoint =$_POST['prepoint']; 

$output =$_POST['output']; 
$rdte =date("m-Y");
$branch =$_POST['branch']; 
 $paytyp =$_POST['paytyp'];
 $vnumber =$_POST['vnumber'];
  $mnumber =$_POST['mnumber'];
//echo $expiry_date; exit;
/***********************************/
//$reward = $prepoint + $output;
$end_month_date =  date('Y-m-d', strtotime('+30 days'));
 $empmob =$_POST['empmob'];$empid =$_POST['empid']; $empname =$_POST['empname'];
  $employeeid = $_SESSION['empid'];
$reward = $prepoint + $output;

$id= $_POST[id];
$cid= $_POST[cid];
if($id=="")
{ 
    	
		
		 $query_insert=sprintf("Insert INTO record  SET   
		 cid='%s', fueltyp='$ftyp', mobile='%s',price='$price',narration='point',purchased ='$pdate', ptime ='$ptime',pay_typ='$paytyp', branch='$branch',pbranch='$empbranch',
		 employee='$empmob',eid='$empid',ctype='new' ",$cid,$mobile); 
		if(!($resi=mysql_query($query_insert))){echo $query_insert.mysql_error(); exit;}
		 $rid = mysql_insert_id();
			//echo $rid; exit;
			
		 $query_insert=sprintf("Insert INTO customer_product_point  SET   
		 cid='%s', upid='$rid', fueltyp='$ftyp', mobile='%s',vnumber='$vnumber',price='$price',oldpoint='$reward',point='%s',
		 purchased ='$pdate', ptime ='$ptime', endmonth ='$end_month_date', rdte='$rdte',status='first',pay_typ='$paytyp', branch='$branch'",$cid,$mobile,$reward);
		if(!($resi=mysql_query($query_insert))){echo $query_insert.mysql_error(); exit;}
		
		
		

		
		$message = urlencode("Thanks for Fueling Diesel-Petrol ".$price." Points added to your loyalty account. Balance Point is ".$reward." .- Road Ka Raja");
$mobile = $mobile;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://bulksmsindia.mobi/sendurlcomma.aspx?user=20064497&pwd=Prasad@0509&senderid=RKRAJA&mobileno='.$mobile.'&msgtext='.$message.'&smstype=0',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: ASP.NET_SessionId=qojdkmyjuhbrhodcflxie1mj'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
		
	
	
		
		

		header("Location:welcome.php?vnumber=$vnumber&flag=dn");
		exit;
}
if($id!="")
{ 
            $reward = $prepoint + $output;
			   
		   
		   $query_insert=sprintf("Insert INTO record  SET   
		 cid='%s', fueltyp='$ftyp', mobile='%s',price='$price',narration='point',purchased ='$pdate', ptime ='$ptime',pay_typ='$paytyp', branch='$branch',pbranch='$empbranch',
		 employee='$empmob',eid='$empid',ctype='old'  ",$cid,$mobile);
		if(!($resi=mysql_query($query_insert))){echo $query_insert.mysql_error(); exit;}
	$rid = mysql_insert_id();
	 $query_up=sprintf("UPDATE customer_product_point SET 
		 cid='%s',  upid='$rid', fueltyp='$ftyp', mobile='%s',vnumber='$vnumber',price='$price',oldpoint='$reward',point='%s',
		 purchased ='$pdate',  ptime ='$ptime',endmonth ='$end_month_date',rdte='$rdte',status='second',pay_typ='$paytyp', branch='$branch' 
		 WHERE id='$id' ", 
		 
		$cid,$mobile,$reward,$price);
		   if(!($resu=mysql_query($query_up))){echo $query_up.mysql_error(); exit;}
		
		
	   
		$message = urlencode("Thanks for Fueling Diesel-Petrol ".$price." Points added to your loyalty account. Balance Point is ".$reward." .- Road Ka Raja");
$mobile = $mobile;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://bulksmsindia.mobi/sendurlcomma.aspx?user=20064497&pwd=Prasad@0509&senderid=RKRAJA&mobileno='.$mobile.'&msgtext='.$message.'&smstype=0',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: ASP.NET_SessionId=qojdkmyjuhbrhodcflxie1mj'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
	
		
		   header("Location:welcome.php?vnumber=$vnumber");
		exit;
			
}	
?>
