<?php
session_start();
include("../include/config.php");
include("../include/functions.php"); 
include("../include/simpleimage.php");
validate_admin();

if($_REQUEST['submitForm']=='yes'){
	$user_id=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['rfduid']);
	$wallet_balance=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['wallet_balance']);
    $order_id=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['order_id']);
	$storeid=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['storeid']);
	$refd_type=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['refd_type']);
	$transaction_id=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['transaction_id']);
	$card_number=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['card_number']);
	$pay_date=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['pay_date']);
	$pay_amount=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['pay_amount']);

	$obj->query("insert into tbl_wallet set user_id='$user_id',wallet_balance='$wallet_balance',order_id='$order_id',storeid='$storeid',type='$refd_type',status=1,added_date=now()");
	//$obj->query("UPDATE $tbl_order set order_status='$order_status',payment_status='$payment_status' where id='$order_id'");	added_date

	################################ Reward Point Management ##################################

	$oArr=$obj->query("select user_id,total_amount,payment_status, coupon_code from $tbl_order where id='$order_id' ");
	$resultOrder=$obj->fetchNextObject($oArr);
	$user_id=$resultOrder->user_id;
	$total_amount=$resultOrder->total_amount;
	//$setting_reward=getField('rewardamount',$tbl_setting,1);
	//$reward_point=floor($total_amount/$setting_reward);

	################################ Reward Point Management End##################################
	$_SESSION['sess_msg']="Refund added in wallet successfully!";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<title><?php echo SITE_TITLE; ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="css/admin.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">

function validate(obj){

if(obj.order_status.value=='')	{

alert("Please select status");	

obj.order_status.focus();

return false;	

}

if(obj.payment_status.value==1){

if(obj.pay_via.value!='' && obj.pay_via.value=='Credit/Debit Card'){

	if(obj.transaction_id.value=='')	{

	alert("Please enter transaction id");	

    obj.transaction_id.focus();

    return false;	

	}

	

} 

if(obj.pay_amount.value==''){

	alert("Please enter received amount");	

    obj.pay_amount.focus();

    return false;	

	}



}}

</script>
	<script type="text/javascript">

function showFields(val){

	if(val==1){

	document.getElementById('pay_details').style.display='';	

	}else{

	document.getElementById('pay_details').style.display='none';	

	}

	

	}



</script>
	<script type="text/javascript">

function showCardDetail(val){

	if(val==1){

	document.getElementById('card_details').style.display='';	

	}else{

	document.getElementById('card_details').style.display='none';	

	}

	

	}



</script>
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<link rel="stylesheet" href="calender/css/jquery-ui.css">
	<script src="calender/js/jquery-ui.js"></script>
	<script>

	$(function() {

	       $( "#pay_date" ).datepicker({

			changeMonth: true,

			changeYear: true,

			numberOfMonths: 1,

			dateFormat:'yy-mm-dd' ,

			yearRange:'2014:<?php echo date('Y');  ?>',

			

          })



		});

	

	</script>
	</head>

	<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
    <td align="left" valign="middle" class="headingbg bodr text14"><em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Add Wallet Refund
          
        
		  For User ID : <?php echo $_REQUEST['rfduid']; ?>
		  
		  </td>
  </tr>
      <tr>
    <td height="100" align="left" valign="top" bgcolor="#f7faf9" class="bodr"><form name="frm" method="POST" enctype="multipart/form-data" action="" onSubmit="return validate(this)">
        <input type="hidden" name="submitForm" value="yes" />
        <input type="hidden" name="order_id" value="<?php echo $_REQUEST['order_id'];?>" />
		<input type="hidden" name="rfduid" value="<?php echo $_REQUEST['rfduid'];?>" />
        <table width="100%" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center" colspan="2" style="color:#C00;"><?php echo $_SESSION['sess_msg'];$_SESSION['sess_msg']=''; ?></td>
          </tr>
          <tr>
            <td width="33%" align="right" class="paddBot11 paddRt14"><strong>Current Status</strong></td>
            <td width="67%" align="left" class="paddBot11"><select name="refd_type" style="width:240px;" >
               
                <option value="Cr" selected>Refund (Credit)</option>
           <option value="Dr" >Debit</option>
              </select></td>
          </tr>
          <tr>
            <td width="33%" align="right" class="paddBot11 paddRt14"><strong>Amount</strong></td>
            <td width="67%" align="left" class="paddBot11">
			<input type="text" name="wallet_balance" style="width:240px;"  >
			  </td>
          </tr>
  
          <tr>
            <td align="right" class="paddRt14 paddBot11">&nbsp;</td>
            <td align="left" class="paddBot11">&nbsp;</td>
          </tr>
          <tr>
            <td width="33%" align="right" class="paddRt14 paddBot11">&nbsp;</td>
            <td width="67%" align="left" class="paddBot11"><input type="submit" name="submit" value="Submit"  class="submit" border="0" />
              &nbsp;&nbsp;&nbsp;&nbsp;</td>
          </tr>
        </table>
      </form></td>
  </tr>
      <tr>
    <td align="center"></td>
  </tr>
      <?php $commentArr=$obj->query("select * from $tbl_order_comments where order_id='".$_REQUEST['order_id']."'  order by id desc ");

	if($obj->numRows($commentArr)>0){?>
      <tr>
    <td><table width="100%" border="0" cellspacing="4" cellpadding="4" bgcolor="#f7faf9" class="bodr">
        <tr>
          <td width="21%"><strong>Date</strong></td>
          <td width="21%"><strong>Pay Via</strong></td>
          <td width="21%"><strong>Received Amount</strong></td>
          <td width="21%"><strong>Received Date</strong></td>
          <td width="58%"><strong>Comment</strong></td>
        </tr>
        <?php while($resultComment=$obj->fetchNextObject($commentArr)){?>
        <tr>
          <td><?php echo date('d M Y H:i',strtotime($resultComment->posted_date)); ?></td>
          <td><?php  if($resultComment->pay_via=='Credit/Debit Card'){

		if($resultComment->transaction_id!=''){

		echo 'Transaction ID:#'.$resultComment->transaction_id."<br/>";

		}

		if($resultComment->card_number!=''){

		echo 'Crad Last digits:'.$resultComment->card_number."<br/>";

		}	

		

		?>
            <?php } else{?>
            Cash
            <?php }?></td>
          <td><?php  if($resultComment->pay_amount!=0){echo 'Rs. '.stripslashes($resultComment->pay_amount);} ?></td>
          <td><?php if($resultComment->posted_date!='0000-00-00'){ echo stripslashes($resultComment->posted_date); }?></td>
          <td><?php echo stripslashes($resultComment->comments); ?></td>
        </tr>
        <?php } ?>
      </table></td>
  </tr>
      <?php } ?>
    </table>
</td>
</tr>
<tr>
		<td align="right" class="paddRtLt70" valign="top">
			<table width="99%" border="0" cellspacing="0" cellpadding="0">
					<tr>
					
						<td align="right" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
                            
								<tr>
									<td align="left" valign="middle" class="headingbg bodr text14">
									<em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>View Wallet History of <?php echo $_REQUEST['rfduid']; ?><span style="float:right; padding-right:300px;"><h2>Current Wallet Balance: <?php echo $website_currency_symbol.getwallet($_REQUEST['rfduid']); ?></h2></span></td>
								</tr>
								<form name="frm" method="post" action="enquiry-del.php" enctype="multipart/form-data">
									<tr>
										<td height="100" align="left" valign="top" bgcolor="#FFFFFF" class="bodr">
											<table width="100%" cellpadding="0" cellspacing="0">
											<?php if($_SESSION['sess_msg']){ ?>
											<tr><td  align="center"><font color="#FF0000"><strong><?php echo $_SESSION['sess_msg'];$_SESSION['sess_msg']='';?></strong></font></td></tr>
											
											<?php }?>
												<tr>
														<td align="left">
															<?php 
$where='';
if($_REQUEST['rfduid']!=''){
$name=$_REQUEST['rfduid']	;
$where.=" and user_id='".$name."' ";	
}
$start=0;
if(isset($_GET['start'])) $start=$_GET['start'];
$pagesize=15;
if(isset($_GET['pagesize'])) $pagesize=$_GET['pagesize'];
$order_by='id';
if(isset($_GET['order_by'])) $order_by=$_GET['order_by'];
$order_by2='desc';
if(isset($_GET['order_by2'])) $order_by2=$_GET['order_by2'];
$sql=$obj->Query("select * from tbl_wallet where 1=1 $where order by $order_by $order_by2 limit $start, $pagesize");
$sql2=$obj->query("select * from tbl_wallet where 1=1 $where order by $order_by $order_by2",$debug=-1);
$reccnt=$obj->numRows($sql2);

															if($reccnt==0)
															{
															?>
																<table width="100%" border="0" cellspacing="0" cellpadding="0">
																	<tr>
																		<td align="center" valign="middle"><font face="Arial, Helvetica, sans-serif"   color="#FF0000" size="+1">No Record</font></td>
																	</tr>
																</table>
															<?php 
															}
															else
															{
															?>
															<table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                                 <tr>
	                                                  <td valign="top" colspan="11"  align="center" class="dark_red" ><strong><?php echo $reccnt;?> Record found.</strong></td>
	                                                  </tr>
																<tr>
																	<td width="9%" align="left" class="padd5" bgcolor="#f3f4f6"><strong>S No.</strong></td>
                                                                    <td width="14%" align="left" bgcolor="#f3f4f6" class="padd5"><strong> Date</strong></td>
                                                                    
                                                                <td width="11%" align="left" bgcolor="#f3f4f6" class="padd5"><strong>Order ID</strong></td>
																	<td width="14%" align="left" bgcolor="#f3f4f6" class="padd5"><strong>Total Amount</strong></td>
                                                                    <td width="19%" align="left" bgcolor="#f3f4f6" class="padd5"><strong>Wallet Balance</strong></td>
                                                                   
                                                                <td width="33%" align="left" bgcolor="#f3f4f6" class="padd5"><strong>Type</strong></td>
                                                                  <!--   
																 <td width="4%" align="center" bgcolor="#f3f4f6" class="padd5" >  <input name="check_all" type="checkbox"   id="check_all" onclick="checkall(this.form)" value="check_all" /></td> -->
																</tr>
																<?php
																$i=0;
																while($line=$obj->fetchNextObject($sql))
																{
																$i++;
															
																
																if($i%2==0)
																{
																$bgcolor = "#f3f4f6";
																}
																else
																{
																$bgcolor = "";
																}
																?>
																	<tr bgcolor="<?php echo $bgcolor;?>">
																		<td class="padd5"><strong><?php echo $i+$start; ?>.</strong></td>
                                                                        <td class="padd5">
																		<?php
																			echo date('d M Y',strtotime($line->added_date));
																		?>
																		</td>
                                                                     
																		<td class="padd5">
																		<?php
																		echo stripslashes($line->order_id);
																		?>
																		</td>
                                                                        <td class="padd5">
																		Rs.<?php
																		echo getField('total_amount',$tbl_order,$line->order_id);
																		?>
																		</td>
                                                                        <td class="padd5">
																		<?php
																		echo stripslashes($line->wallet_balance);
																		?>
																		</td>
                                                                        <td class="padd5">
																		 <?php
																		 echo stripslashes($line->type);
																		 ?>
																		</td>
																			
        
                                                                       <!--  
																		
																		<td align="center" valign="middle" class="padd5">
																	<input type="checkbox" name="ids[]" value="<?php echo $line->id;?>" />
																		</td> -->
																	</tr>
																<?php
																
																}
																
																?>
													<tr>
                          <td valign="top" colspan="11"  align="right">&nbsp;
						  
</td>   </tr>    			
	                                                <tr>
	                                                  <td valign="top" colspan="11"  align="right" class="dark_red" style="padding-right:150px;">&nbsp;</td>
	                                                  </tr>
	                                                <tr>
                          <td valign="top" colspan="11"  align="right" class="dark_red" style="padding-right:150px;"><?php include("../include/paging.inc.php"); ?>
						  
</td>   </tr>  
 <tr>
	                                                  <td valign="top" colspan="13"  align="right" class="dark_red" style="padding-right:150px;">&nbsp;</td>
	                                                  </tr>
  			<!--<tr><td align="right"  style="padding-right:80px;" colspan="10"> <input type="hidden" name="what" value="what" />
												
                        <input type="submit" name="Submit" value="Delete" class="button" onclick="return del_prompt(this.form,this.value)" /></td></tr> -->
															</table><?php }?>
														</td>
												</tr>
												
											</table>
										</td>
									</tr>
								</form>
							</table>
						</td>
					</tr>
			</table>
		</td>
</tr>
<tr><td height="100"></td></tr>

</table>
<?php

	


?>
</body>
</html>
