<?php 
//error_reporting(0);
$this->load->view('header');?>
<?php if($_SESSION['ADMIN_TYPE']=='sales'){
    		    $sqlGatewayCond="";
    		    $getblockedGateways=$this->db->query("SELECT * FROM `t_midCenter` where ipn='".$_SESSION['ADMIN_USERNAME']."' and deny='Y'");
    			if($getblockedGateways->num_rows()>0){
        			foreach($getblockedGateways->result() as $row){
        				$sqlGatewayCond.="g_type != '".$row->gatewayID."' AND ";
        			}
        			$sqlGatewayCond=substr($sqlGatewayCond, 0, -4);
    			}else{
    			    $sqlGatewayCond=1;
    			}
    			//echo $sqlGatewayCond;
    			$sqlGateway=$this->db->query("select distinct(g_type) from ".$this->table." where ".$sqlGatewayCond);
    		}
			else{
				$sqlGateway=$this->db->query("select distinct(g_type) from ".$this->table." where g_type!=''");
			}
			//echo $this->db->last_query();
?>
<style>
	.redClass{ background-color: #FFD2D2;}
	.dangerCustom{ background-color: #F81717; font-weight:bold; color: #A1A19C;}
	.processCustom{ background-color: #ecec13; font-weight:bold; color: #A1A19C;}
	.successCustom{ background-color: #3F7A05; font-weight:bold; color: #A1A19C;}
	.tot{ margin:1px;}
</style>
<br/>
<br/>
<form class="form-inline" role="form" name="frmSearch" id="frmSearch" action="<?php echo base_url().$this->controllerFile;?>index" method="POST" >
	<input type="hidden" name="hdnOrderBy" id="hdnOrderBy" value="<?php echo $order_by; ?>"/>
	<input type="hidden" name="hdnOrderByFld" id="hdnOrderByFld" value="<?php echo $order_by_fld; ?>"/>						
	<input type="hidden" name="search" value="search"/>

	<!--div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">companyID</label>
		<select name="companyID" class="form-control">
		<option value="">Select Center</option>
		<?php foreach ($companyIDName->result() as $row){?>
		<option <?php if($companyID==$row->companyID){?> selected <?php } ?> value="<?php echo $row->companyID; ?>"><?php echo $row->companyID; ?></option>
		<?php } ?>
		</select>
	</div-->
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Start date</label>
		<input type="text" id="datepiker" name="start_date" placeholder="Start date" value="<?php echo $start_date;?>" class="dp form-control" autocomplete="off">
	</div>
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Start end</label>
		<input type="text" id="datepiker1" name="end_date" placeholder="End end" value="<?php echo $end_date;?>" class="dp form-control" autocomplete="off">
	</div>
	<?php if($_SESSION['ADMIN_LEVEL']=="System"){?>	
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">IPN</label>

			<?php 
			if($this->session->userdata('ADMIN_TYPE')=='group'){
				$newWhereClauseQuery ='(';
				$groupID=$this->session->userdata('groupID');
				$getCompanyID=$this->db->query("select * from t_groupCenter where groupID=".$groupID);
				foreach($getCompanyID->result() as $row){
					$newWhereClauseQuery .="username = '".$row->ipn_no."' OR ";
				}
				$newWhereClauseQuery  = substr($newWhereClauseQuery, 0, -3)." ) ";
				$uniqueMidQuery = "Select distinct(username), fname from t_admin where level='Company' and fname!='Test' And ".$newWhereClauseQuery;
				//echo $uniqueMidQuery;
			}else{
				$uniqueMidQuery = "Select distinct(username), fname from t_admin where level='Company' and fname!='Test' order by fname asc";
			}
			?>
			<select name="mid_no1" class="form-control" onchange="myFunctionIPN(this.value)">
			<option value="">Select IPN</option>
			<?php
			$uniqueMid = $this->db->query($uniqueMidQuery);
			foreach($uniqueMid->result() as $midRow){ ?>
				<option value="<?php echo $midRow->username;?>" <?php if($mid_no==$midRow->username){?> selected <?php } ?> ><?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?><?php echo $midRow->fname;?><?php }else{ echo $midRow->username; } ?></option>
		<?php } ?>
			</select>
		<!--input type="text" id="mid_no" name="mid_no" placeholder="IPN No." value="<?php echo $mid_no;?>" class="form-control" autocomplete="off"-->
	</div>
 
	<div class="form-group">
		<input type="text" id="order_id" name="order_id" placeholder="Order Id" value="<?php echo $order_id;?>" class="form-control">
	</div>	<br/></br>
	<div class="form-group">
		<input type="text" id="gatewayTransactionId" name="gatewayTransactionId" placeholder="Transaction Id" value="<?php echo $gatewayTransactionId;?>" class="form-control">
	</div>
	<!-- field -->
	<div class="form-group">
		<input type="text" id="client_transaction_id" name="client_transaction_id" placeholder="CL. Transaction Id" value="<?php echo $client_transaction_id;?>" class="form-control">
	</div>
	<!-- Here added -->
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">status</label>
		<select name="g_type" class="form-control"  >
			<option value="">Select Gateway</option>
    		<?php
			foreach($sqlGateway->result() as $sqlGatewayRow){ ?>
				<option value="<?php echo $sqlGatewayRow->g_type;?>" <?php if($g_type==$sqlGatewayRow->g_type){?> selected <?php } ?> ><?php echo $sqlGatewayRow->g_type;?></option>
		<?php	}
		?>
		</select>
	</div>	
	<div class="form-group">
        	<select name="currency_type" id="currency_type" class="form-control">
			                <option value="">Select Currency</option>
				            <option value="EUR" <?php if($currency_type=="EUR"){?> selected <?php } ?>>EUR</option>
				            <option value="USD" <?php if($currency_type=="USD"){?> selected <?php } ?>>USD</option>
				            <option value="GBP" <?php if($currency_type=="GBP"){?> selected <?php } ?>>GBP</option>
				            <option value="AUD" <?php if($currency_type=="AUD"){?> selected <?php } ?>>AUD</option>
				            <option value="INR" <?php if($currency_type=="INR"){?> selected <?php } ?>>INR</option>
		    </select>
		</div>
	 <?php //} ?>

	<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?>
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">status</label>
		<select  name="status" class="form-control">
			<option value="">Select Status</option>
			<option value="Declined" <?php if($status=="Declined"){?> selected <?php } ?> >Declined</option>
			<option value="Success" <?php if($status=="Success"){?> selected <?php } ?>>Success</option>
			<option value="Process" <?php if($status=="Process"){?> selected <?php } ?>>Process</option>
		</select>
	</div>
	<?php } ?>

	
	

	<!-- Here ended -->
	
	
	
	<?php } ?>
	<?php //if($_SESSION['ADMIN_LEVEL']=="Company"){?>
 	<br/>
	<br/> 	
	<!--div class="form-group">
		<input type="text" id="client_transaction_id" name="client_transaction_id" placeholder="CL. Transaction Id" value="<?php echo $client_transaction_id;?>" class="form-control">
	</div-->
   	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Customer Name</label>
		<input type="text" id="customer_name" name="customer_name" placeholder="Customer Name" value="<?php echo $customer_name;?>" class="form-control">
	</div>
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Customer Phone</label>
		<input type="text" id="customer_phone" name="customer_phone" placeholder="Customer Phone" value="<?php echo $customer_phone;?>" class="form-control">
	</div>
 		
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Customer Email</label>
		<input type="text" id="customer_email" name="customer_email" placeholder="Customer Email" value="<?php echo $customer_email;?>" class="form-control">
	</div>
	
	<?php if($_SESSION['ADMIN_LEVEL']=="System"){?>	
	<input type="text" id="mid_no" name="mid_no" placeholder="IPN No." value="<?php echo $mid_no;?>" class="form-control" autocomplete="off">
	<?php } ?>	<br/><br/>
	<div class="form-group">
		<label class="sr-only" for="exampleInputEmail2">Customer Email</label>
		<input type="number" id="record_limit" name="record_limit" placeholder="Records per page." value="<?php echo $record_limit;?>"  min="0" class="form-control">
	
	<small id="emailHelp" class="form-text text-muted">Enter No. of Records to be viewed per page. Higher number can cause problem in page load.</small>
	</div>	
	
	
	<?php /*if($this->session->userdata('ADMIN_TYPE')!='group'){ ?>
		<div class="form-group" >
		<strong>Load All (Center/ Gateway):</strong> 
		<input onclick="this.form.submit();" type="checkbox" name="activeRecords" id="activeRecords" value="1" <?php if($activeRecords==1){ echo 'checked'; }?> >
		</div>
	<?php }*/ ?>
 	<br/>
	<br/>	
	<div class="form-group">
		<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Search</button>
	</div>
	<div class="form-group">
		<a href="<?php echo base_url().$this->controllerFile; ?>" class="btn btn-primary"><i class="fa fa-align-justify"></i> Clear</a> 
	</div>
<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?>
	<div class="form-group">
		<a href="<?php echo base_url().'customers/download'; ?>" class="btn btn-primary"><i class="fa fa-align-justify"></i> Download</a> 
	</div>	
	<div class="form-group">
		<a href="<?php echo base_url().$this->controllerFile.'push_notification'; ?>" class="btn btn-primary"><i class="fa fa-align-justify"></i> Push Notification</a> 
	</div>
<?php } ?>
</form>
<br/>
<div class="row">
<div class="col-lg-12">
<?php if($query->num_rows() > 0){
	$i=0;
	$numCnt=0;
	if($where_clause==""){ 
		$where_clause = 1;
	}
	$saleValues=$this->db->query('SELECT sum(`grossPrice`) as Sum,status,currency_type,count(id) as cnt FROM '.$this->table.' where status="Success" and '.$where_clause.' group by status, currency_type');
	echo "<strong><span class='label label-info tot'>Total:</span></strong>";
	foreach($saleValues->result() as $saleRow){
		$numCnt+=1;
		/*if($numCnt%4==0){ echo "<br/><br/>"; }*/
		/*if($saleRow->status=='Declined'){
			echo "<span class='alert alert-danger dangerCustom' style='align:center;'>";
		}
		if($saleRow->status=='Process'){
			echo "<span class='alert alert-success processCustom'>";
		}		
		if($saleRow->status=='Success'){
			echo "<span class='alert alert-success successCustom'>";
		}*/
		if($saleRow->status=='Declined'){
			echo "<span class='label label-danger tot' style='align:center;'>";
		}
		if($saleRow->status=='Process'){
			echo "<span class='label label-warning tot'>";
		}
		
		if($saleRow->status=='Success'){
			echo "<span class='label label-success tot'>";
		}		
		echo '<strong>'.$saleRow->status.": ".number_format($saleRow->Sum,2).$saleRow->currency_type."(".$saleRow->cnt.")</strong></span>";
	}
	echo "<br/>";
	$RefundValues=$this->db->query('SELECT sum(`refund_amount`) as Sum,currency_type,count(id) as cnt FROM '.$this->table.' where refund="Y" and '.$where_clause.' group by currency_type' );
	foreach($RefundValues->result() as $RefundValues){
		//print_r($RefundValues);
		if($RefundValues->Sum > 0){ 	
			echo "<span class='label label-danger tot' style='align:center;font-weight: bold;'>Refund:".number_format($RefundValues->Sum,2).$RefundValues->currency_type."(".$RefundValues->cnt.")</span>"; 
		}		
	}

	
	$chargebackValues=$this->db->query('SELECT sum(`grossPrice`) as Sum,currency_type, count(id) as cnt FROM '.$this->table.' where chargeback="Y" and '.$where_clause.' group by currency_type');
	foreach($chargebackValues->result() as $chargebackValues){
		if($chargebackValues->Sum > 0){ 	
			echo "<span  class='label label-danger tot' style='align:center;font-weight: bold;'>Chargeback:".number_format($chargebackValues->Sum,2).$chargebackValues->currency_type."(".$chargebackValues->cnt.")</span>"; 
		}
	}
?>
<br/>

<?php 
	if($_SESSION['ADMIN_TYPE']=='sales'){
		//$where_clause.=" and g_type!='CommonWealth' ";
		if($sqlGatewayCond!='' || $sqlGatewayCond!='') $where_clause.=" AND ".$sqlGatewayCond." ";
		
	}
	$gatewayValues=$this->db->query("Select g_type, 
	sum(CASE WHEN status='Declined' THEN ROUND(grossPrice,2) else 0 END) as Declined,
	sum(CASE WHEN status='Process' THEN ROUND(grossPrice,2) else 0 END) as Process,
	sum(CASE WHEN status='Success' THEN ROUND(grossPrice,2) else 0 END) as Success,
	sum(CASE WHEN refund='Y' THEN ROUND(refund_amount,2) else 0 END) as Refund,
    sum(CASE WHEN chargeback='Y' THEN ROUND(grossPrice,2) else 0 END) as Chargeback,
	count(distinct case when status = 'Declined' then id END) as declinedCount,
	count(distinct case when status = 'Process' then id END) as processCount,
	count(distinct case when status = 'Success' then id END) as successCount,
	count(distinct case when refund='Y' then id END) as refundCount,
	count(distinct case when chargeback='Y'then id END) as chargebackCount,
    currency_type FROM ".$this->table_view." where ".$where_clause." group by g_type, currency_type order by g_type");
	foreach($gatewayValues->result() as $gatewayValues){
		echo "<strong><span class='label label-info'>".$gatewayValues->g_type.":</span>&nbsp;&nbsp;"; 
		if($gatewayValues->Success>0){
			echo "<span class='label label-success'>Success:".number_format($gatewayValues->Success,2).$gatewayValues->currency_type."(".$gatewayValues->successCount.")</span>&nbsp;&nbsp;";			
		}
		if($gatewayValues->processCount>0){
			echo "<span class='label label-warning'>Process:".number_format($gatewayValues->Process,2).$gatewayValues->currency_type."(".$gatewayValues->processCount.")</span>&nbsp;&nbsp;";
		}
		if($gatewayValues->Declined>0){		
			echo "<span class='label label-danger'>Declined:".number_format($gatewayValues->Declined,2).$gatewayValues->currency_type."(".$gatewayValues->declinedCount.")</span>&nbsp;&nbsp;";
		}
		if($gatewayValues->Refund>0){		
			echo "<span class='label label-danger'>Refund:".number_format($gatewayValues->Refund,2).$gatewayValues->currency_type."(".$gatewayValues->refundCount.")</span>&nbsp;&nbsp;";
		}
		if($gatewayValues->Chargeback>0){		
			echo "<span class='label label-danger'>Chargeback:".number_format($gatewayValues->Chargeback,2).$gatewayValues->currency_type."(".$gatewayValues->chargebackCount.")</span>&nbsp;&nbsp;";
		}
		echo "</strong><br/>";		
	}
?>
<br/>
	<div class="panel panel-default">
		<div class="panel-body">         
			<table id="dataTables-example" width="100%" class="table  table-hover table-condensed">
				<thead>
                <tr>
					<th style="width:2%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='g_type')?'bold':'normal'?>;" href="javascript: hdnSort('g_type','<?php echo $order_by; ?>');">Mid</a></th>
					<?php if($_SESSION['ADMIN_LEVEL']=="System"){?>
					<!--th style="width:3%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='gatewayTransactionId')?'bold':'normal'?>;" href="javascript: hdnSort('gatewayTransactionId','<?php echo $order_by; ?>');">TR ID</a></th-->
					<th style="width:5%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='order_id')?'bold':'normal'?>;" href="javascript: hdnSort('order_id','<?php echo $order_by; ?>');">Order ID</a></th>
					<?php } ?>								
                    <th style="width:7%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='rec_crt_date')?'bold':'normal'?>;" href="javascript: hdnSort('rec_crt_date','<?php echo $order_by; ?>');">Date</a></th>					
                    <?php if($_SESSION['ADMIN_LEVEL']=="System"){?>
					<!--th><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='ipn_no')?'bold':'normal'?>;" href="javascript: hdnSort('ipn_no','<?php echo $order_by; ?>');">IPN</a></th-->
					<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?>
					<th style="width:5%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='')?'bold':'normal'?>;" href="javascript: hdnSort('','<?php echo $order_by; ?>');">Client</a></th>
					<?php } ?>
					<?php } ?>
					<?php if($_SESSION['ADMIN_LEVEL']=="Company"){?>
					<th style="width:3%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='client_transaction_id')?'bold':'normal'?>;" href="javascript: hdnSort('client_transaction_id','<?php echo $order_by; ?>');">T.ID</a></th>
					<?php } ?>
					<th style="width:4%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='customer_name')?'bold':'normal'?>;" href="javascript: hdnSort('customer_name','<?php echo $order_by; ?>');">Name</a></th>
					
					<th style="width:4%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='customer_email')?'bold':'normal'?>;" href="javascript: hdnSort('customer_email','<?php echo $order_by; ?>');">Email</a></th>
	
					<th style="width:3%;"><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='grossPrice')?'bold':'normal'?>;" href="javascript: hdnSort('grossPrice','<?php echo $order_by; ?>');">Amt.</a></th>
					
					<th ><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='status')?'bold':'normal'?>;" href="javascript: hdnSort('status','<?php echo $order_by; ?>');">St.</a></th>
					
					<th ><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='response_code')?'bold':'normal'?>;" href="javascript: hdnSort('response_code','<?php echo $order_by; ?>');">Res.</a></th>
					
					<th ><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='refund')?'bold':'normal'?>;" href="javascript: hdnSort('refund','<?php echo $order_by; ?>');">Rf.</a></th>
					<th ><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='chargeback')?'bold':'normal'?>;" href="javascript: hdnSort('chargeback','<?php echo $order_by; ?>');">CB.</a></th>
					<?php //if($this->session->userdata('ADMIN_TYPE')=='superadmin' && $_SESSION['ADMIN_LEVEL']=="System"){ ?>
					<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?>
					<th  colspan="2"  ><a style="text-decoration:none;font-size:12px;font-weight:<?=($order_by_fld=='')?'bold':'normal'?>;" href="javascript: hdnSort('','<?php echo $order_by; ?>');"></a></th>
			        <?php //} ?>
					<?php } ?>
                </tr>
              </thead>
              <tbody>
<?php foreach ($query->result() as $row){
	//print_r($row);
		$tableClass="";
		$i+=1; 
		if($row->status=="Declined"){
			$tableClass="bg-danger";
		}						
		if($row->status=="Process"){
			$tableClass="bg-warning";
		}						
		if($row->status=="Success"){
			$tableClass="bg-success";
		}
?> 
                <tr class="<?php echo $tableClass;?>" id="recordRow<?php echo $row->id; ?>" <?php if($row->status=="Declined"){ if(is_numeric($row->response)){ $getError=getErrorDetails($row->response_code); } else{ $getError=$row->response; } if($getError!=""){ ?> title="<?php echo $getError; ?>" <?php } } ?> >
					<td><?php  echo $row->g_type;?></td>
					<?php if($_SESSION['ADMIN_LEVEL']=="System"){?>
					<!--td>
						<?php 
							echo $row->gatewayTransactionId; 
							/*if($row->status=="Process"){?>
								<a href="<?php echo base_url().$this->controllerFile.'change/'.$row->id.'/'.$offset; ?>" class="btn btn-primary btn-xs" onclick="return confirm('Are you sure?')" >Mark Success</a> 
							<?php }*/ ?>					
					</td-->
					<td><?php echo $row->order_id; ?></td>
					<?php } ?>
					<td><?php if($row->rec_up_date > 0){ echo date('m-d-Y H:i:s',strtotime($row->rec_up_date)); } else { echo date('m-d-Y H:i:s',strtotime($row->rec_crt_date)); }?></td>					
					
                    <?php if($_SESSION['ADMIN_LEVEL']=="System"){?>
					<!--td><?php echo $row->ipn_no; ?></td-->
					<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?>
					<td><?php /*$admin=$this->db->query("Select fname from t_admin where username='".$row->ipn_no."'")->row(); 
					//print_r($admin);
					if($admin) echo $admin->fname;*/ 
					echo $row->fname;
					?></td>
					<?php } } ?>
					
                    <?php if($_SESSION['ADMIN_LEVEL']=="Company"){?>
					<td><?php echo $row->client_transaction_id; ?></td>
					<?php } ?>

					<td><?php echo $row->customer_name; ?></td>
					<td><?php echo $row->customer_email; ?></td>

					<td><?php if($row->grossPrice < 0) echo number_format(abs($row->grossPrice), 2); else echo number_format($row->grossPrice, 2).$row->currency_type; ?>
					<?php if($row->refund=='Y'){echo '('.$row->refund_amount.')';} ?>
					</td>					
					<td><?php if($_SESSION['ADMIN_LEVEL']=="System" && $_SESSION['ADMIN_TYPE']!='sales'){ ?>
						<select name="record_status" id="record_status" onchange="record_status('<?php echo $row->id;?>',this.value);" >
							<option value="Declined" <?php if($row->status=="Declined"){?> selected="selected" <?php } ?> >Declined</option>
							<option value="Success" <?php if($row->status=="Success"){?> selected="selected" <?php } ?>>Success</option>
							<option value="Process" <?php if($row->status=="Process"){?> selected="selected" <?php } ?>>Process</option>
						</select>						
					<?php } else echo $row->status; ?></td>					
					<td><?php echo $row->response_code;
if($row->status=="Declined"){ if(is_numeric($row->response)){ $getError=getErrorDetails($row->response_code); } else{ $getError=$row->response; }
echo $getError; }
					?></td>					

<td>
	<?php if($_SESSION['ADMIN_LEVEL']=="Company"){
	    if($row->status=="Success"){
	        echo $row->refund;
	    }
		
	} else{
	    if($row->status=="Success"){
			/*if($row->refund=='Y' && $row->grossPrice<=$row->refund_amount){ echo "<input type='checkbox' checked disabled/>"; } 
			else if($row->refund=='Y' && $row->grossPrice>$row->refund_amount) {*/ 
			if($row->refund=='Y' ) {?> 
					<input <?php if($_SESSION['ADMIN_TYPE']=='sales'){ ?> disabled <?php } ?> id="chkR<?php echo $row->id;?>" value="Y"  type="checkbox" checked onchange="showRefund('<?php echo $row->id;?>')" /><br/> 
					<span id="<?php echo 'spanR'.$row->id;?>" style="display:none;">
						<input id="refund_amount<?php echo $row->id;?>" type="text" value="<?php echo $row->grossPrice;?>"/><br/>
						<input id="dateR<?php echo $row->id;?>" type="text" value="<?php echo date('Y-m-d H:i:s');?>"/><br/>
						<input type="button" name="button" value="submit" onclick="submitRefund('<?php echo $row->id;?>')"/>
					</span> 
			<?php }			
			else if($row->refund!='Y'){?> 
					<input <?php if($_SESSION['ADMIN_TYPE']=='sales'){ ?> disabled <?php } ?> id="chkR<?php echo $row->id;?>" value="Y"  type="checkbox" onchange="showRefund('<?php echo $row->id;?>')" /><br/> 
					<span id="<?php echo 'spanR'.$row->id;?>" style="display:none;">
						<input id="refund_amount<?php echo $row->id;?>" type="text" value="<?php echo $row->grossPrice;?>"/><br/>
						<input id="dateR<?php echo $row->id;?>" type="text" value="<?php echo date('Y-m-d H:i:s');?>"/><br/>
						<input type="button" name="button" value="submit" onclick="submitRefund('<?php echo $row->id;?>')"/>
					</span> 
			<?php } 
		} }?>
</td>
<td>
	<?php if($_SESSION['ADMIN_LEVEL']=="Company"){
	    if($row->status=="Success"){
	        echo $row->chargeback;
	    }
		
	} else{
	    if($row->status=="Success"){
			if($row->chargeback=='Y'){ echo "<input type='checkbox' checked disabled/>"; } 
			else{?> 
					<input <?php if($_SESSION['ADMIN_TYPE']=='sales'){ ?> disabled <?php } ?> id="chkC<?php echo $row->id;?>" value="Y"  type="checkbox" onchange="showCB('<?php echo $row->id;?>')" /><br/> 
					<span id="<?php echo 'spanC'.$row->id;?>" style="display:none;">
						<input id="dateC<?php echo $row->id;?>" type="text" value="<?php echo date('Y-m-d H:i:s');?>"/><br/>
						<input type="button" name="button" value="submit" onclick="submitCB('<?php echo $row->id;?>')"/>
					</span> 
			<?php } 
		} }?>
</td>
<?php if($_SESSION['ADMIN_TYPE']!='sales'){ ?> 
                        <td>
						<div class="btn-group">
							<!--a title="Details" href="<?php echo site_url($this->controllerFile.'pop/'.$row->id);?>" ><i class="fa fa-search" aria-hidden="true"></i></a-->
							<a title="Invoice" href="<?php echo site_url($this->controllerFile.'invoice/'.$row->id);?>" ><i class="fa fa-search" aria-hidden="true"></i></a>							
						</div>
						<?php /*if($_SESSION['ADMIN_LEVEL']=="System"){?>
							<a title="Invoice" href="<?php echo site_url($this->controllerFile.'invoice/'.$row->id);?>" ><i class="fa fa-download" aria-hidden="true"></i></a>
						<?php }*/ ?>
					<!-- here am adding -->
						<div class="btn-group">
							<a title="KYC" href="<?php echo site_url($this->controllerFile.'kyc/'.$row->id);?>" ><i class="fa fa-upload" aria-hidden="true"></i></a>
						<?php $getKycRes=$this->db->query("SELECT id FROM `t_kyc` where tr_id=".$row->id);
						if($getKycRes->num_rows() > 0){
							echo '<i class="fa fa-check" aria-hidden="true" title="KYC Uploaded for this Record"></i>';
						}?>							
						</div>
					<!-- ending here by me -->
					</td>
					<?php } ?>
                </tr>
			<?php  } ?>  

                

              </tbody>

            </table>        
            </div>

		

		<?php echo $paginator; ?>			

    <?php }else{ ?>
			<div class="alert alert-info" role="alert">
			<strong>No Records Found.</strong>
			</div>
	<?php } ?>

            

            

                                   

			</div>

			</div>

			</div>

        </div><!-- mainpanel -->

    </div><!-- mainwrapper -->




      
<?php $this->load->view('footer');?>
<script type="text/javascript">
function record_status(id,status){
	<?php //echo base_url().$this->controllerFile.'change/'.$row->id.'/'.$offset; ?>
	//alert(id);
	//alert(status);
	var r=confirm("Are you sure to Change the status of transaction?"); 
	if (r == true) {
				$.post('<?php echo base_url().$this->controllerFile; ?>change', 'id='+id+'&status='+status, function(data){
					if(data) 
					{
						$("#msgDiv").show("");
						$('#msgDiv').html(data);
						$('#msgDiv').delay(5000).fadeOut('slow', function() {});
						//alert(data);
						location.reload();
					}

				});			
	}
}
</script>
<script>
    function showRefund(id){
        //alert(id);
        var chk=jQuery("#chkR"+id).val();
        //alert(chk);
        jQuery("#spanR"+id).toggle("slow");
    }
    function submitRefund(id){
        var chkR=jQuery("#chkR"+id).val();
        var dateR=jQuery("#dateR"+id).val();
        var refund_amount=jQuery("#refund_amount"+id).val();
        //alert(dateR);
        /**************************************/
		var r=confirm("Are you sure to Mark the transaction as Refund?"); 
		if (r == true) {
				$.post('<?php echo base_url().$this->controllerFile; ?>changeRefundStatus', 'id='+id+'&chkR='+chkR+'&dateR='+dateR+'&refund_amount='+refund_amount, function(data){
					if(data) 
					{
						//alert(data);
						$("#msgDiv").show("");
						$('#msgDiv').html(data);
						$('#msgDiv').delay(5000).fadeOut('slow', function() {});
						location.reload();
					}

				});			
		}
        /*************************************/
    }
    function showCB(id){
        var chk=jQuery("#chkC"+id).val();
        jQuery("#spanC"+id).toggle("slow");
    }
    function submitCB(id){
        var chkC=jQuery("#chkC"+id).val();
        var dateC=jQuery("#dateC"+id).val();
        //alert(dateR);
        /**************************************/
		var r=confirm("Are you sure to Mark the transaction as Chargeback?"); 
		if (r == true) {
				$.post('<?php echo base_url().$this->controllerFile; ?>changeChargebackStatus', 'id='+id+'&chkC='+chkC+'&dateC='+dateC, function(data){
					if(data) 
					{
						$("#msgDiv").show("");
						$('#msgDiv').html(data);
						$('#msgDiv').delay(5000).fadeOut('slow', function() {});
						location.reload();
					}

				});			
		}
        /*************************************/
    }
</script>
<script language="javascript">

	function fnrequestType(requestType){

		jQuery("#requestType").val(requestType);

	}

	function showHidePhn(phnVal){

		if(phnVal=='EnterNumber'){

			jQuery("#phoneBlock").show('slow');

		}else{

			jQuery("#phoneBlock").hide('slow');

		}

	} 

	function showHideBlock(){

		jQuery("#billingCompanyShow").toggle('slow');

		jQuery("#customerMailSendBlock").toggle('slow');

		

	}

	function change_frozen_status(id,val){

		if(val=='Y'){

			jQuery("#dateFrozen"+id).show('slow');

		}else{

		var r=confirm("Are you sure to change the Frozen staus of the transaction?"); 

			if (r == true) {

				$.post('<?php echo base_url().$this->controllerFile; ?>change_frozen_status', 'id='+id+'&val='+val, function(data){

					if(data) 

					{

							$("#msgDiv").show("");

							$('#msgDiv').html(data);

							$('#msgDiv').delay(5000).fadeOut('slow', function() {});

							location.reload();					

					}

				});			

			}

		}		

	}

	function change_frozen_status2(id){

		var recDate=jQuery("#datepikerFrozen"+id+"").val();

		var val=jQuery("#frozen"+id+"").val();

		var r=confirm("Are you sure to change the Frozen staus of the transaction?"); 

		if (r == true) {

			$.post('<?php echo base_url().$this->controllerFile; ?>change_frozen_status', 'id='+id+'&val='+val+'&recDate='+recDate, function(data){

				if(data) 

				{

						$("#msgDiv").show("");

						$('#msgDiv').html(data);

						$('#msgDiv').delay(5000).fadeOut('slow', function() {});

						location.reload();					

				}

			});			

		}

	}

   function SetInvoiceId(id){

		$('#TextInvoiceId').val(id);

		$('#RefundInvoiceId').val(id);

	}

	$('#resendInvoiceForm').submit(function() {

		var total=$(this).find('input[name="emailType[]"]:checked').length;

		//alert(total);

		if(total<1){

			alert("Select at least 1 Email Type");

			return false;

		}

	});	

	function changeProduct (invoice_id, companyID, productPeriod, productId){

		//alert(productId);

		var r=confirm("Are you sure to change the Product of Record?");

		if (r == true) {

			$.post('<?php echo base_url().$this->controllerFile; ?>changeProduct', 'invoice_id='+invoice_id+'&companyID='+companyID+'&productId='+productId+"&productPeriod="+productPeriod, function(data){

				if(data) 

				{

					$("#msgDiv").show("");

					$('#msgDiv').html('Product Information Changed Successfully');

					$('#msgDiv').delay(5000).fadeOut('slow', function() {});

					location.reload();					

				}

			});			

		}

	}

	function changeProductInfo (id, invoice_id, companyID){

		var r=confirm("Are you sure to change the Product Information?");

		if (r == true) {

			var productId = jQuery("#productId"+id).val();

			var product_name = jQuery("#product_name"+id).val();

			var productPeriod = jQuery("#productPeriod"+id).val();

			var productDuration = jQuery("#productDuration"+id).val();



			$.post('<?php echo base_url().$this->controllerFile; ?>changeProductInfo', 'invoice_id='+invoice_id+'&companyID='+companyID+'&productId='+productId+'&product_name='+product_name+'&productPeriod='+productPeriod+'&productDuration='+productDuration, function(data){

				if(data) 

				{

					$("#msgDiv").show("");

					$('#msgDiv').html('Product Information Changed Successfully');

					$('#msgDiv').delay(5000).fadeOut('slow', function() {});

					location.reload();					

				}

			});			

		}

	}

	function check_status(gatewayTransactionId,gatewayID,companyID){

	$('.bolt').show();

	$('#bolt'+gatewayTransactionId).html('<img src="<?php echo base_url(); ?>images/loading.gif" alt=""/>');

	$.post('<?php echo base_url().$this->controllerFile; ?>check_status', 'gatewayTransactionId='+gatewayTransactionId+'&gatewayID='+gatewayID+'&companyID='+companyID, function(data){		

		$('#bolt'+gatewayTransactionId).html('');

		$('#bolt'+gatewayTransactionId).hide("slow");

		$('.statInfo').hide("slow");

		$('#statInfo'+gatewayTransactionId).html(data);

		$('#statInfo'+gatewayTransactionId).show("slow");

	});

}

function discard(gatewayTransactionId){	

	$('#statInfo'+gatewayTransactionId).hide("slow");

	$('#bolt'+gatewayTransactionId).show("slow");

}

function change_trans_status(id, val, name)

{

		//alert(val);

		if(val=='Chargeback'){

			var r=confirm("Are you sure to change the state of transaction record for "+name+" and use Present Date?"); 

		}else if(val=='Settlement'){

			var r=confirm("Are you sure to change the state of transaction record for "+name+" and use Present Date?"); 

		}else{

			var r=confirm("Are you sure to change the state of transaction record for "+name+" ?"); 

		}

		if (r == true) {

			if(val=='Refund'){

				jQuery("#refundAmount"+id+"").show();

			}

			else{

				$.post('<?php echo base_url().$this->controllerFile; ?>change_trans_type', 'id='+id+'&val='+val, function(data){

					if(data) 

					{

						$("#msgDiv").show("");

						//$('#msgDiv').html('Status Changed Successfully');

						$('#msgDiv').html(data);

						$('#msgDiv').delay(5000).fadeOut('slow', function() {});

						//alert("Tansaction record for "+name+" changed successfully");

						location.reload();					

					}

				});

			}

		}else if(r == false && val=='Chargeback'){

			//alert('ok');

			jQuery("#dateChargeback"+id+"").show();

		}else if(r == false && val=='Settlement'){

			//alert('ok');

			jQuery("#dateSettlement"+id+"").show();

		}

}

function change_trans_status2(id, val, name){

	var recDate=jQuery("#datepiker"+id+"").val();

	//alert(date);

	$.post('<?php echo base_url().$this->controllerFile; ?>change_trans_type', 'id='+id+'&val='+val+'&recDate='+recDate, function(data){

		if(data) 

		{

				$("#msgDiv").show("");

				//$('#msgDiv').html('Status Changed Successfully');

				$('#msgDiv').html(data);

				$('#msgDiv').delay(5000).fadeOut('slow', function() {});

				//alert("Tansaction record for "+name+" changed successfully");

				location.reload();					

		}

	});

}

function change_trans_statusSettle(id, val, name){

	var recDate=jQuery("#datepikerSettlement"+id+"").val();

	//alert(recDate);

	$.post('<?php echo base_url().$this->controllerFile; ?>change_trans_type', 'id='+id+'&val='+val+'&recSettleDate='+recDate, function(data){

		if(data) 

		{

				$("#msgDiv").show("");

				$('#msgDiv').html(data);

				$('#msgDiv').delay(5000).fadeOut('slow', function() {});

				location.reload();					

		}

	});

}

function change_trans_status3(id, val, name){

	var amount=jQuery("#amount"+id+"").val();

	//alert(amount);

	//alert(date);

	$.post('<?php echo base_url().$this->controllerFile; ?>change_trans_type', 'id='+id+'&val='+val+'&amount='+amount, function(data){

		if(data) 

		{

				$("#msgDiv").show("");

				//$('#msgDiv').html('Status Changed Successfully');

				$('#msgDiv').html(data);

				$('#msgDiv').delay(5000).fadeOut('slow', function() {});

				//alert("Tansaction record for "+name+" changed successfully");

				location.reload();					

		}

	});

}

function hdnSort(name, type)

{

	//alert(name);

	document.frmSearch.hdnOrderByFld.value = name;

	if(type == 'ASC')

		document.frmSearch.hdnOrderBy.value = 'DESC';

	else

		document.frmSearch.hdnOrderBy.value = 'ASC';

	document.frmSearch.submit();

}

function change_center_status(id, val, companyID)

{	

	$('#statusDiv'+id).html('<img src="<?php echo base_url(); ?>images/admin/loading.gif" alt=""/>');

	$.post('<?php echo base_url().$this->controllerFile; ?>change_center_status', 'id='+id+'&val='+val+'&companyID='+companyID, function(data){

		if(data) 

		{

			/*if(val == 'Y')

			{

				var val2 = "'N'";

				var text = '<?php print active_icon(); ?>';

				$('#statusDiv'+id).html(text);

				$("#msgDiv").show("");

				$('#msgDiv').html('Center Record Status Changed Successfully');

				$('#msgDiv').delay(5000).fadeOut('slow', function() {});

				

			}

			else

			{

				var val2 = "'Y'";

				var text = '<a href="javascript: void(0);" onclick="javascript: change_status('+id+','+val2+');"><?php print inactive_icon(); ?></a>';

				$('#statusDiv'+id).html(text);

				$("#msgDiv").show("");

				$('#msgDiv').html('Center Record Status Changed Successfully');

				$('#msgDiv').delay(5000).fadeOut('slow', function() {});

				

			}*/

			$("#msgDiv").show("");

			//$('#msgDiv').html('Status Updated Successfully');

			

			$('#msgDiv').delay(5000).fadeOut('slow', function() {});

			alert("Status Updated Successfully");

			location.reload();

		}

	});

}

</script>

<script src="<?php echo base_url(); ?>admin_utils/js/bootstrap-datepicker.js"></script>

<script type="text/javascript">

	// When the document is ready

	$(document).ready(function () {

		$('.dtpkr').datepicker({

			format: "mm-dd-yyyy"

		});

		$('#datepiker1').datepicker({

			format: "mm-dd-yyyy"

		});

		

		$('#datepiker').datepicker({

			format: "mm-dd-yyyy",

			minDate: new Date(),

		});

		

		$('.dp').on('change', function () {

			$('.datepicker').hide();

			var startDate = new Date($('#datepiker').val());

			var endDate = new Date($('#datepiker1').val());

			if(startDate!="" && endDate!=''){

				if (startDate > endDate){

					//alert('End Date Connot be Less than Start Date');

					// Do something

					jQuery(".errSuccessRoutineMsg").show();

					jQuery(".errSuccessRoutineMsg").html('End Date Connot be Less than Start Date');

					jQuery("#datepiker1").val("");

					setTimeout(function() {

						$('.errSuccessRoutineMsg').fadeOut('fast');

					}, 5000);

				}

			}			

		});

	});
function myFunctionIPN(ipn){
	//alert(ipn);
	jQuery("#mid_no").val(""+ipn+"");
}
</script>