
    <tr bgcolor="#eee"><th>S.No.</th><th>Client</th><th>Pair</th><th>Sell</th><th>Buy</th><th>LotSize</th><th>Profit/Loss</th><th>TGT/SL</th><th>Action</th></tr>
<?php $i=1;
//echo "<pre>";print_r($trades);exit;
foreach($trades as $allt){
	//$chka=$allt->last_active+20;?>
<tr><td><?php echo $i;?></td>
	<td><?php echo $allt->first_name.'<br/>';//.' '.$chka;'<br/>'.$allt->last_active.'<br/>'.time();
	//if($chka>time()){echo '<span class="badge badge-success">LIVE</span>';}?>
      <span class="badge badge-dark"><?php echo $allt->trade_id;?></span></td>
	<td><?php echo $allt->cpair;?></td>
	<td style="background:<?php echo $allt->trd_sell_color;?>;"><?php echo $allt->sell_price;?></td>
	<td style="background:<?php echo $allt->trd_buy_color;?>;"><?php echo $allt->buy_price;?></td>
	<td><?php echo $allt->trade_type.' '.$allt->lotsize.' Lot @'.$allt->trade_price;?></td>
	<td style="color:<?php if($allt->profit_loss>0){echo 'green';}else{echo 'red';}?>; font-size:20px;"><?php echo $allt->profit_loss;?></td>
	<td><?php echo 'TGT: '.$allt->target.'<br/>SL: '.$allt->stoploss;?></td>
    <td>
		<?php if($this->session->userdata("admin")){?>
  <!--  <button id="<?php //echo $allt->trade_id;?>" type="button" class="btn btn-xs btn-info edit_trade" data-toggle="modal" data-target="#myModal">EDIT</button><br/>-->
    <button id="<?php echo $allt->trade_id;?>" ttime="<?php echo $allt->trade_start_time;?>"  type="button" title="<?php echo $allt->lotsize.'-'.$allt->trade_price;?>" class="btn btn-xs btn-warning exit1" data-toggle="modal" data-target="#myModal1">EDIT</button><br/>
    <button id="<?php echo $allt->trade_id;?>" type="button" class="btn btn-xs btn-danger delete">DEL</button>
    <button id="<?php echo $allt->trade_id;?>" type="button" class="btn btn-xs btn-primary square_off">SQOFF</button>
    <?php if($allt->hold_status=="Off" || $allt->hold_status==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>
    <a href="#"  id="<?php echo $allt->trade_id;?>" class="btn btn-xs btn-<?php echo $btn;?> holdtrade"><?php echo $sst;?></a>
<?php }?></td>
    </tr>
<?php $i++;}?>
<script>
$(".holdtrade").click(function(e){e.preventDefault();
                                var id=$(this).attr("id");
								var sst=$(this).text();
								if(sst=="on"){
								$(this).removeClass("btn-success");
								$(this).addClass("btn-danger");	
								}else{
								$(this).removeClass("btn-danger");
								$(this).addClass("btn-success");	
								}
								//if(sst=="Off"){$(this).text('On');}else{$(this).text('Off');}
                                $.ajax({
                                     type: "POST",
                                     url: '<?php echo base_url();?>home/holdtrade_enable',
                                     data: {id:id,sst:sst},
                                     success: function(res){
										// alert(res);
                                        }
                                     });
                            });
$(".exit1").click(function(){
	var id=$(this).attr("id");
	var ttime=$(this).attr("ttime");
	var lot=$(this).attr("title").split("-");
	//alert(lot[1]);
	$("#trade_id").val(id);
	$("#trade_start_time").val(ttime);
	$("#trd_lot").val(lot[0]);
	$("#buy_pricee").val(lot[1]);
	//return false;
//	if (!confirm("Sure you want to Square-Off?")){
//	  return false;
//	}$(this).closest("tr").remove();
//	$.ajax({
//				 type: "POST",
//				 url: '<?php //echo base_url();?>home/ajax_close_trade',
//				 data: {id:id},
//				 success: function(res){
//					 //console.log(res);
//					 //$(".exit_trades").html(res);
//				 }
//			 });
			 
});
$(".edit_trade").click(function(){
	var id=$(this).attr("id");
	$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_edit_trade',
				 data: {id:id},
				 success: function(res){
					 $(".trade_data").html(res);
					 //$(".exit_trades").html(res);
				 }
			 });
			 
});
$(".delete").click(function(){
	var id=$(this).attr("id");
	if (!confirm("Sure you want to Remove this trade?")){
	  return false;
	}$(this).closest("tr").remove();
	$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_delete_trade',
				 data: {id:id},
				 success: function(res){
					 //console.log(res);
					 //$(".exit_trades").html(res);
				 }
			 });
			 
});
$(".square_off").click(function(){
	var id=$(this).attr("id");
	if (!confirm("Sure you want to Square Off this trade?")){
	  return false;
	}$(this).closest("tr").remove();
	$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_square_off',
				 data: {id:id},
				 success: function(res){
					 //console.log(res);
					 //$(".exit_trades").html(res);
				 }
			 });
			 
});
</script>