<?php
include_once('database_connection.php');

if(isset($_GET['action']))
{
  if($_GET['action']=="eVoucherWiseStatement")
  {


    $data=array();
    if((isset($_GET['startdate']) && $_GET['startdate']!="undefined" && $_GET['startdate']!="") && (isset($_GET['enddate']) && $_GET['enddate']!="undefined" && $_GET['enddate']!=""))
    {
      $date=" convert(date,Tdate) between '".$_GET['startdate']."' and '".$_GET['enddate']."' and ";
      
    }
    else
    {
      $date='';
    } 
    if(isset($_GET['LocationID']) && $_GET['LocationID']!="undefined" && $_GET['LocationID']!="" && $_GET['LocationID']>0)
    {
      $LocationID=" LocationID=".$_GET['LocationID']." and ";
    }
    else
    {
      $LocationID="";
    }
    if(isset($_GET['COAID']) && $_GET['COAID']!="undefined" && $_GET['COAID']!="")
    {
      //$COAID=" COAID=".$_GET['COAID']." and ";
      $COAID=" evoucherNumber=(select eVoucherNumber from eVoucherMaster where  ID=".$_GET['COAID'].") and ";
    }
    else
    {
      $COAID="";
    } 
    //?$_GET['SupplierID']:;
  $searchboxopen=$COAID."".$LocationID;
  $searchbox=$COAID."".$LocationID."".$date;
  //$_GET['startdate']="2020-02-01";
    if($_GET['startdate']!="" && $_GET['startdate']!="undefined")
    {

      $sqlopening ="select sum(Debit) as Debit,sum(Credit) as Credit,COAID,(sum(Debit)-sum(Credit)) as balance from  
eVoucherTransaction where $COAID  tdate<'".$_GET['startdate']."'
group by COAID

      ";
     $resultopening=odbc_exec($connection, $sqlopening) or die(odbc_error().$sqlopening);
    while($rowopening=odbc_fetch_array($resultopening))
    {
      $rowopening['Narration']='Opening Balance eVoucher';
      $data['opening']=$rowopening;
    }

   /*  $sqlopening ="select sum(Debit) as Debit,sum(Credit) as Credit,COAID,(sum(Debit)-sum(Credit)) as balance from  generalledger where $searchboxopen  VoucherDate<'".$_GET['startdate']."'  group by COAID";
     $resultopening=odbc_exec($connection, $sqlopening) or die(odbc_error().$sqlopening);
    while($rowopening=odbc_fetch_array($resultopening))
    {
      $rowopening['Narration']='Opening Balance';
      $data['opening']=$rowopening;
    }
*/
    }//end opening
    else
    {
$sqlopening ="select sum(Debit) as Debit,(sum(Credit)*-1) as Credit,LedgerID,(sum(Debit)-(sum(Credit)*-1)) as balance from  voucherdetails where LedgerID=".$_GET['COAID']." and VoucherID in (select VoucherID from vouchermaster where VoucherTypeID=0)  group by LedgerID
      ";
     $resultopening=odbc_exec($connection, $sqlopening) or die(odbc_error().$sqlopening);
    while($rowopening=odbc_fetch_array($resultopening))
    {
      $rowopening['Narration']='Opening Balance ';
      $data['opening']=$rowopening;
    }      
     
    }

      $sql="select ROW_NUMBER() OVER (ORDER BY [ID])  as row_num,date as VoucherDate1,(select COAName from accounts where COAID=generalledger.COAID) as creditaccount,(select COAName from accounts where COAID=generalledger.COAID) as debitaccount,(select Name from inventory where ID=(select top 1 ItemID from InvoiceDetail where InvoiceID=generalledger.InvoiceID)) as ItemName,* from eVoucherTransaction as generalledger  where $searchbox ID>0";
    $result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
   
    while($row=odbc_fetch_array($result))
    {

      foreach($row as $key=>$value)
      $row[$key]= utf8_encode($value);  
   /* if($row['CardNumber']!="")
    $row['CardNumber']=getCardCodeDecode($row['CardNumber']);*/
  
    $data['details'][]=$row;  
    }
  //  print_r($data);
    echo json_encode($data);
  
  
  }
  if($_GET['action']=="GetVoucherBalance")
  {

    $data=array();
    $eVoucherNumber=$_GET['eVoucherNumber'];
    if(isset($_GET['RequestNo']) && $_GET['RequestNo']!="")
    {
      $RequestNo=$_GET['RequestNo'];
      $REQ= " RequestNo='$RequestNo' ";
    }
    else
    {
     $REQ=" eVoucherNumber='$eVoucherNumber' "; 
    }

        $sql="select (sum(Debit)-sum(Credit)) as Balance,(select top 1 convert(date,ExpiryDate) from eVoucherMaster where eVoucherNumber='$eVoucherNumber' and ExpiryDate>='".Date('Y-m-d')."') as ExpiryDate,COAID,(select top 1 COAName from accounts where COAID=evoucherTransaction.COAID) as COAName,(select CustomerName from eVoucherMaster where evoucherNumber='$eVoucherNumber') as CustomerName from evoucherTransaction where $REQ group by COAID";
   
   
      
    $result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
    while($row=odbc_fetch_array($result))
    {

      $data[]=$row;
    }
  echo json_encode($data);  
  
  }
	//ReActivateVoucher
	if($_GET['action']=="ReActivateVoucher")
	{

		$ID=$_GET['ID'];
		$sql="update [eVoucherMaster] set active=1 where ID=$ID";
		odbc_exec($connection, $sql) or die(odbc_error().$sql);
		     if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'e-Voucher DeActivated  Sucessfully');
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');

}
    echo json_encode($res);
	
	
	}
		if($_GET['action']=="DeActivateVoucher")
	{
		$ID=$_GET['ID'];
		$sql="update [eVoucherMaster] set active=0 where ID=$ID";
		odbc_exec($connection, $sql) or die(odbc_error().$sql);
		     if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'e-Voucher DeActivated  Sucessfully');
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');

}
    echo json_encode($res);
	
	}
	if($_GET['action']=="ActivateVoucher")
	{
		odbc_autocommit($connection, FALSE);
			$data=array();
		$RequestID=$_GET['ID'];
		$sql="select * from eVoucherRequest where ID=$RequestID and isPosted=0";
		  $result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
     while($row=odbc_fetch_array($result))
     {
     	$CustomerName=$row['CustomerName'];
    //$evoucherNumber=$row['FathersName'];
     $evoucherNumber=dechex(rand()*12000);
    $Price=$row['Price'];
    $IssueDate=Date("Y-m-d");
    $date=date("Y-m-d");
    $ExpiryDate=(date('Y-m-d', strtotime($date. ' + 1 year')));
    $Reference=$row['Reference'];
    $ClientReference=$row['Reference'];
    $Name=$row['Name'];
    $MobileNumber=$row['MobileNumber'];
    $Email=$row['Email'];    
    $CustomerUserID=$row['CustomerUserID'];
    $COAID=$row['COAID'];
    $TotalTaxAmount=0;
    $CreateLog=$_SESSION['UserName'];
    $Price=$row['Balance'];
    $Qty=$row['Qty'];
    $Balance=$Price;
    $NetAmount=$Price;
    $Active=1;
    $Narration='activate Card';
    $ServiceDiscount=$row['ServiceDiscount'];
    $VoucherTypeID=$row['ItemID'];
    $ItemID=$VoucherTypeID;
    $VoucherTypeID=getnamesingle("inventory","ITemType","ID",$ItemID,$connection);
    if($VoucherTypeID==1)
    {
      $transType="Price";
    }
    else
    {
      $transType="Service";
    }

    $ID=getMaxId("eVoucherMaster","ID",$connection)+1;
    if($ID<1)$ID=1;
  $RequestNo=generateCode("eVoucherMaster","ID","1=1",$connection)+1;
    $RequestNo=str_pad($RequestNo,7,"0",STR_PAD_LEFT);
    $RequestNo="REQ-".$RequestNo;
    $VoucherCode=rand()*1200;
    //$eVoucherNumber="";
$RequestedIP=$_SERVER['REMOTE_ADDR'];
$isPosted=1;
$Used=0;
$Credit=0;
 $sql="INSERT INTO [dbo].[eVoucherMaster]
           ([ID]
           ,[Name]
           ,[Price]
           ,[VoucherTypeID]
           ,[Active]
           ,[ExpiryDate]
           ,[Reference]
           ,[ItemID]
           ,[RequestNo]
           ,[Qty]
           ,[ClientReference]
           ,[IssueDate]
           ,[COAID]
           ,[NetAmount]
           ,[Narration]
           ,[TotalTaxAmount]
           ,[CreateLog]
           ,[CustomerUserID]
           ,[RequestedIP]
           ,[Used]
           ,[Balance]
           ,[ServiceDiscount]
           ,[isPosted]
           ,[CustomerName]
           ,[MobileNumber]
           ,[Email]
           ,[evoucherNumber])
     VALUES
(
			$ID
           ,'$Name'
           ,$Price
           ,$VoucherTypeID
           ,$Active
           ,'$ExpiryDate'
           ,'$Reference'
           ,$ItemID
           ,'$RequestNo'
           ,$Qty
           ,'$ClientReference'
           ,'$IssueDate'
           ,$COAID
           ,$NetAmount
           ,'$Narration'
           ,$TotalTaxAmount
           ,'$CreateLog'
           ,$CustomerUserID
           ,'$RequestedIP'
           ,$Used
           ,$Balance
           ,$ServiceDiscount
           ,$isPosted
           ,'$CustomerName'
           ,'$MobileNumber'
           ,'$Email'
           ,'$evoucherNumber'
)";
     odbc_exec($connection,$sql) or die(odbc_error().$sql);
    //end Voucher Generation 
    //insert services 
	$sql="select * from [eVoucher_Policy] where ItemID=$ItemID";
	$result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
    while($row=odbc_fetch_array($result))
    {
    	$SubTotal=$row['Qty']*$row['RetailPrice'];

    	$sqlinsert="INSERT INTO [dbo].[eVoucherServices]
           ([ItemID]
           ,[Qty]
           ,[EVMID]
           ,[Balance]
           ,[COAID]
           ,[Price]
           ,[SubTotal]
           ,[VoucherCode]
           ,[Used],Under) values( ".$row['MaterialID'].",".$row['Qty'].",$ID,".$row['Qty'].",$COAID,".$row['RetailPrice'].",".$SubTotal.",'$evoucherNumber',0,".$row['Under'].")";
odbc_exec($connection, $sqlinsert) or die(odbc_error().$sqlinsert);
	   
      }//end while 
      $TransCode="Opening Balance";
      $evtID=getMaxId("evoucherTransaction","ID",$connection)+1;
$sql="insert into evoucherTransaction (ID,COAID,Debit,Credit,Under,ItemID,Qty,Narration,Price,RequestNo,eVoucherNumber,transType,VoucherTypeID,AgentID,TransCode,VoucherID) values($evtID,$COAID,$NetAmount,$Credit,0,0,1,'$Narration',$Price,'$RequestNo','$evoucherNumber','$transType',$VoucherTypeID,$CustomerUserID,'$TransCode',$ID)";
odbc_exec($connection, $sql) or die(odbc_error().$sql); 
// entry for VoucherMaster 
$LocationID=1;
$VoucherTypeID=9;
            $where="VoucherTypeID=$VoucherTypeID"; 
    $VoucherID=getMaxId("VoucherMaster","VoucherID",$connection)+1;
    $KeyField=generateCode("VoucherMaster","KeyField",$where,$connection)+1;

    $KeyField="SALES-".str_pad($KeyField,7,"0",STR_PAD_LEFT);
    $CreateLog=$_SESSION['UserName'];
    $date=Date("Y-m-d h:i:s");
    $Narration='';
    $TotalAmount=$NetAmount;
    $Active=1;//
    $Posted=1;
$sql="insert into VoucherMaster (VoucherID,TotalAmount,Narration,LedgerID,VoucherDate,VoucherNo,VoucherTypeID,LocationID,CreateLog,PaymentType,Active,Posted) values($VoucherID,'$TotalAmount','$Narration',$COAID,'$date','$KeyField',$VoucherTypeID,'$LocationID','$CreateLog','$evoucherNumber',$Active,$Posted)"; 
odbc_exec($connection, $sql) or die(odbc_error().$sql); 

$sqlupdate="update eVoucherMaster set VoucherID=$VoucherID where ID=$ID ";
odbc_exec($connection, $sqlupdate) or die(odbc_error().$sqlupdate); 

//entry for VoucherDetails 
$LedgerID=$COAID;
$CreditLedgerID=9000;
$CostCenterID=$LocationID;
$DebitCostCenterID=$CostCenterID;
$Debit=$NetAmount;
$Credit=$NetAmount;
$ModeofPayment=$evoucherNumber;
$TransactionType=$transType;
$sql="insert into VoucherDetails (DebitCostCenterID,CostCenterID,
TransactionType,
ModeofPayment,
Debit,
Credit,
VoucherID,LedgerID,CreditLedgerID) values ($DebitCostCenterID,$CostCenterID,
'$TransactionType',
'$ModeofPayment',
$Debit,
$Credit,
$VoucherID,$LedgerID,$CreditLedgerID)";
odbc_exec($connection, $sql) or die(odbc_error().$sql); 

	
     }//end while 
$sql="update eVoucherRequest set isPosted=1 where ID=$RequestID";
odbc_exec($connection, $sql) or die(odbc_error().$sql);

	     if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'e-Voucher Activated Sucessfully');
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');

}
    echo json_encode($res);

	}
	 if($_GET['action']=="eVoucherPendingList")
  {

$data=array();
    $sql="select ID as row_num,*,'' as col_Action from [eVoucherRequest] where isPosted=0";
  $result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
     while($row=odbc_fetch_array($result))
     {
      $row["col_Action"]='<i title="Print Voucher" class="fa fa-print fa-lg" style="text-align: left;color: blue;cursor:pointer;" onclick="javascript:eVoucherPrintOut('.$row['ID'].');"></i> &nbsp;&nbsp;&nbsp; <i title="Activate Voucher" class="fa fa-play fa-lg" style="text-align: right;color: green;cursor:pointer;" onclick="javascript:ActivateVoucher(this);"></i>';
        $data[]=$row;

     }
      echo json_encode($data);

   
  }

	if($_GET['action']=="eVoucherList")
	{
$data=array();
		$sql="select ID as row_num,*,convert(date,ExpiryDate) as ExpiryDate1,'' as col_Action from [eVoucherMaster]";
	$result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
 	   while($row=odbc_fetch_array($result))
 	   {
 	   	$row["col_Action"]='<i class="fa fa-pencil fa-lg" style="text-align: left;color: blue;cursor:pointer;" onclick="javascript:editRow(this);"></i> &nbsp;&nbsp;&nbsp;<i class="fa fa-print fa-lg" style="text-align: left;color: green;cursor:pointer;" onclick=javascript:eVoucherPrintOut("'.$row['RequestNo'].'","'.urlencode($row['CustomerName']).'","'.$row['ExpiryDate1'].'","'.$row['evoucherNumber'].'");></i>';

 	   	if($row['Active']==1)
 	   	$row["col_Action"]=$row["col_Action"].'&nbsp;&nbsp;&nbsp; <i class="fa fa-play  fa-lg" title="DeActivate Voucher" style="text-align: right;color: red;cursor:pointer;" onclick="javascript:DeActivateVoucher(this);"></i>';
 	   	else
 	   	$row["col_Action"]=$row["col_Action"].'&nbsp;&nbsp;&nbsp; <i class="fa fa-play fa-lg" title="Activate Voucher" style="text-align: right;color: green;cursor:pointer;" onclick="javascript:ReActivateVoucher(this);"></i>';	
 	   		$data[]=$row;

	   }
	    echo json_encode($data);

	}
		if($_GET['action']=="InserteVoucher")
		{
			odbc_autocommit($connection, FALSE);
			$data=array();
			$data=json_decode($_POST['data']);
	/*		print_r($data);
			return;*/
	$CustomerName=(isset($data->CustomerName) && $data->CustomerName)?$data->CustomerName:'';
    $evoucherNumber=(isset($data->FathersName) && $data->FathersName)?$data->FathersName:'';
    $Address3=(isset($data->Address3) && $data->Address3!="")?$data->Address3:'';
    $IssueDate=(isset($data->IssueDate) && $data->IssueDate!="")?$data->IssueDate:'';
    $ExpiryDate=(isset($data->DateOfExpiry) && $data->DateOfExpiry!="")?$data->DateOfExpiry:'';
    $Reference=(isset($data->Reference) && $data->Reference!="")?$data->Reference:'';
    $ClientReference=(isset($data->Reference) && $data->Reference!="")?$data->Reference:'';
    $MobileNumber=(isset($data->ContactNo) && $data->ContactNo!="")?$data->ContactNo:'';
    $TotalTaxAmount=(isset($data->TotalTaxAmount) && $data->TotalTaxAmount!="")?$data->TotalTaxAmount:0;
    $Name=$CustomerName."-".$ClientReference;
    $CustomerUserID=0;
    $Price=(isset($data->Balance) && $data->Balance!="")?$data->Balance:0;
    $Balance=$Price;
    $NetAmount=$Price;
    $Narration='';
    $ServiceDiscount=(isset($data->ServiceDiscount) && $data->ServiceDiscount!="")?$data->ServiceDiscount:0;
    $VoucherTypeID=(isset($data->CardTypeID) && $data->CardTypeID!="")?$data->CardTypeID:0;
    $ItemID=$VoucherTypeID;
    $VoucherTypeID=getnamesingle("inventory","ITemType","ID",$ItemID,$connection);
    if($VoucherTypeID==1)
    {
      $transType="Price";
    }
    else
    {
      $transType="Service";
    }

    $Qty=1;
    $CreateLog=$_SESSION['UserName'];
    $Active=$data->IsCurrentlyActive; 
    $COAID=$data->COAID;
    $Email=$data->EmailID;
    $ID=(isset($data->ID) && $data->ID!="")?$data->ID:0;

    if($ID==0)
    {	
    $ID=getMaxId("eVoucherMaster","ID",$connection)+1;
    if($ID<1)$ID=1;
    $RequestNo=generateCode("eVoucherMaster","ID","COAID=$COAID",$connection)+1;
    $RequestNo=str_pad($RequestNo,7,"0",STR_PAD_LEFT);
    $RequestNo="REQ-".$RequestNo;
    $VoucherCode=rand()*1200;
    //$eVoucherNumber="";
$RequestedIP=$_SERVER['REMOTE_ADDR'];
$isPosted=0;
$Used=0;

 $sql="INSERT INTO [dbo].[eVoucherMaster]
           ([ID]
           ,[Name]
           ,[Price]
           ,[VoucherTypeID]
           ,[Active]
           ,[ExpiryDate]
           ,[Reference]
           ,[ItemID]
           ,[RequestNo]
           ,[Qty]
           ,[ClientReference]
           ,[IssueDate]
           ,[COAID]
           ,[NetAmount]
           ,[Narration]
           ,[TotalTaxAmount]
           ,[CreateLog]
           ,[CustomerUserID]
           ,[RequestedIP]
           ,[Used]
           ,[Balance]
           ,[ServiceDiscount]
           ,[isPosted]
           ,[CustomerName]
           ,[MobileNumber]
           ,[Email]
           ,[evoucherNumber])
     VALUES
(
			$ID
           ,'$Name'
           ,$Price
           ,$VoucherTypeID
           ,$Active
           ,'$ExpiryDate'
           ,'$Reference'
           ,$ItemID
           ,'$RequestNo'
           ,$Qty
           ,'$ClientReference'
           ,'$IssueDate'
           ,$COAID
           ,$NetAmount
           ,'$Narration'
           ,$TotalTaxAmount
           ,'$CreateLog'
           ,$CustomerUserID
           ,'$RequestedIP'
           ,$Used
           ,$Balance
           ,$ServiceDiscount
           ,$isPosted
           ,'$CustomerName'
           ,'$MobileNumber'
           ,'$Email'
           ,'$evoucherNumber'
)";
     odbc_exec($connection,$sql) or die(odbc_error().$sql);
    //end Voucher Generation 
     $Credit=0;
     //insert in Evoucher Ledger of Customer 
    //insert services 
     
	$sql="select * from [eVoucher_Policy] where ItemID=$ItemID";
	$result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
    while($row=odbc_fetch_array($result))
    {
    	$SubTotal=$row['Qty']*$row['RetailPrice'];

    	$sqlinsert="INSERT INTO [dbo].[eVoucherServices]
           ([ItemID]
           ,[Qty]
           ,[EVMID]
           ,[Balance]
           ,[COAID]
           ,[Price]
           ,[SubTotal]
           ,[VoucherCode]
           ,[Used],Under) values( ".$row['MaterialID'].",".$row['Qty'].",$ID,".$row['Qty'].",$COAID,".$row['RetailPrice'].",".$SubTotal.",'$evoucherNumber',0,".$row['Under'].")";
odbc_exec($connection, $sqlinsert) or die(odbc_error().$sqlinsert);



	    }//end while 
      $TransCode="Opening Balance";
      $evtID=getMaxId("evoucherTransaction","ID",$connection)+1;
$sql="insert into evoucherTransaction (ID,date,COAID,Debit,Credit,Under,ItemID,Qty,Narration,Price,RequestNo,eVoucherNumber,transType,VoucherTypeID,AgentID,TransCode,VoucherID) values($evtID,'".Date("Y-m-d H:i:s")."',$COAID,$NetAmount,$Credit,0,0,1,'$Narration',$Price,'$RequestNo','$evoucherNumber','$transType',$VoucherTypeID,$CustomerUserID,'$TransCode',$ID)";
odbc_exec($connection, $sql) or die(odbc_error().$sql);	
// entry for VoucherMaster 
$LocationID=1;
$VoucherTypeID=9;
            $where="VoucherTypeID=$VoucherTypeID"; 
    $VoucherID=getMaxId("VoucherMaster","VoucherID",$connection)+1;
    $KeyField=generateCode("VoucherMaster","KeyField",$where,$connection)+1;

    $KeyField="SALES-".str_pad($KeyField,7,"0",STR_PAD_LEFT);
    $CreateLog=$_SESSION['UserName'];
    $date=Date("Y-m-d h:i:s");
    $Narration='';
    $TotalAmount=$NetAmount;
    $Active=1;//
    $Posted=1;
$sql="insert into VoucherMaster (VoucherID,TotalAmount,Narration,LedgerID,VoucherDate,VoucherNo,VoucherTypeID,LocationID,CreateLog,PaymentType,Active,Posted) values($VoucherID,'$TotalAmount','$Narration',$COAID,'$date','$KeyField',$VoucherTypeID,'$LocationID','$CreateLog','$evoucherNumber',$Active,$Posted)"; 
odbc_exec($connection, $sql) or die(odbc_error().$sql); 

$sqlupdate="update eVoucherMaster set VoucherID=$VoucherID where ID=$ID ";
odbc_exec($connection, $sqlupdate) or die(odbc_error().$sqlupdate); 

//entry for VoucherDetails 
$LedgerID=$COAID;
$CreditLedgerID=9000;
$CostCenterID=$LocationID;
$DebitCostCenterID=$CostCenterID;
$Debit=$NetAmount;
$Credit=$NetAmount;
$ModeofPayment=$evoucherNumber;
$TransactionType=$transType;
$sql="insert into VoucherDetails (DebitCostCenterID,CostCenterID,
TransactionType,
ModeofPayment,
Debit,
Credit,
VoucherID,LedgerID,CreditLedgerID) values ($DebitCostCenterID,$CostCenterID,
'$TransactionType',
'$ModeofPayment',
$Debit,
$Credit,
$VoucherID,$LedgerID,$CreditLedgerID)";
odbc_exec($connection, $sql) or die(odbc_error().$sql); 

  }
	else
	{
		$updatesql="update eVoucherMaster set CustomerName='$CustomerName',ServiceDiscount='$ServiceDiscount',MobileNumber='$MobileNumber',Email='$Email',ExpiryDate='$ExpiryDate' where ID=$ID";
		odbc_exec($connection, $updatesql) or die(odbc_error().$updatesql);
	}
     if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'Data Saved Sucessfully');
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');

}
    echo json_encode($res);

		}

		if($_GET['action']=="geteVoucherType")
		{
			$ItemID=$_GET['ItemID'];
			if($ItemID=="") return;
			$data=array();
	$sql="select ID,Name,StandardPrice2 as price,under,Attr1,Attr2 from inventory where ID=".$ItemID;
	$result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
    while($row=odbc_fetch_array($result))
    {
    	$data['master'][]=$row;
    }
	$sql="select * from [eVoucher_Policy] where ItemID=$ItemID";
	$result=odbc_exec($connection, $sql) or die(odbc_error().$sql);
    while($row=odbc_fetch_array($result))
    {
	$data['details'][]=$row;

    }
    echo json_encode($data);
		}
}

?>