<?php $i=1;foreach($trades as $tr){if($tr->type=="SELL"){$col="text-danger";}else{$col="text-success";}
if($tr->pro_loss>0){$bgcolor="#00FF99";}else{$bgcolor="#FF9900";}?>
<tr><td><script>
var tr='<div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">Metal: </span> <?php echo $tr->metal.' <b class="'.$col.'">'.$tr->type.'</b>';?></p></div><div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">Live Rate: </span> <?php echo $tr->last_live;?></p></div><div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">SetLimit: </span> <?php echo $tr->setlimit;?></p></div><div class="col-md-2 col-12 py-1"><p class="mb-0"> <span class="d-inline-block d-md-none text-bold-700">Target: </span> <?php echo $tr->target;?></p></div><div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">Stoploss: </span> <?php echo $tr->stoploss;?></p></div><div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">Profit/Loss: </span> <b style="color:white;background:<?php echo $bgcolor;?>;padding:5px;"><?php echo $tr->pro_loss;?></b></p><?php if($tr->sq_off!="On"){?><button type="button" class="btn btn-xs btn-warning" onclick="sq_offtrade(<?php echo $tr->bsid;?>)">SqOff</button><?php }?><button type="button" class="btn btn-danger btn-xs" onclick="edit_trade1(<?php echo $tr->bsid;?>)" data-toggle="modal" data-target="#myModal2">Edit</button></div>';
//<div class="col-md-2 col-12 py-1"><p class="mb-0"><span class="d-inline-block d-md-none text-bold-700">Stoploss: </span> <?php //echo $tr->bsdate;?></p></div>
 //socket.emit("tr_emit_user",{trid:<?php //echo $tr->bsid;?>,tr:tr});
 
</script><?php echo $i;?></td>
    <td><?php echo $tr->uname;?></td>
    <td><?php echo $tr->metal.'<br/>'.$tr->lotsize;?> Lot(s)</td>
    <td><?php echo $tr->type;?></td>
    <td class="text-danger"><?php echo $tr->last_live;?></td>
    <td><?php echo $tr->setlimit;?></td>
    <td><?php echo $tr->target;?></td>
    <td><?php echo $tr->stoploss;?></td>
    <td <?php if($tr->pro_loss>0){echo 'bgcolor="#75DB40"';}else if($tr->pro_loss<0){echo 'bgcolor="#FF5050"';}?>><?php echo $tr->pro_loss;?></td>
    <td><?php echo date("H:i a",strtotime($tr->bsdate));?></td>
    <td><?php if($tr->status=="start"){?>
    <a href="#" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-warning square">Sq.Off</a>
    <?php }?>
    <?php if($tr->hold_status=="Off" || $tr->hold_status==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>
    <a href="#"  id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> holdtrade"><?php echo $sst;?></a>
    <a href="#" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-danger delete_trade">Delete</a>
    <?php if($tr->sq_off=="Off" || $tr->sq_off==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>
    <a href="#" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> sqoff_enable"><?php echo $sst;?></a>
    </td></tr>
<?php $i++;}?>
<script>
$(document).ready(function(){
	$(".delete_trade").click(function(e){e.preventDefault();
		var id=$(this).attr("id");
		//if (!confirm("Sure you want to delete?")){
//				  return false;
//				}
		$(this).closest("tr").remove();
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>welcome/delete_trade',
			 data: {id:id},
			 success: function(res){
				 //$("#live_trades").html(res);
				}
		});
	});
	$(".holdtrade").click(function(){
                                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);
                                        }
                                     });
                            });
							
							$(".sqoff_enable").click(function(){
                                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/sqoff_enable',
                                     data: {id:id,sst:sst},
                                     success: function(res){
										// alert(res);
                                        }
                                     });
                            });
	$(".square").click(function(){
                                var id=$(this).attr("id");
                                if (!confirm("Sure you want to Square-Off?")){
                                      return false;
                                    }
                                $(this).closest("tr").remove();
                                $.ajax({
                                     type: "POST",
                                     url: '<?php echo base_url();?>home/square_off',
                                     data: {id:id},
                                     success: function(res){
                                        }
                                     });
                            });
});
</script>