<?php //echo "asdfasf";exit;



$i=1;foreach($trades as $tr){
	if($tr->type=="SELL"){
	$col="text-danger";}else{$col="text-success";}

///$this->db->order_by("trid","desc");

//$chk=$this->db->get_where("transaction",array("userid"=>$tr->uid))->row();

//$ubal=$chk->left_amt;

if($tr->pro_loss>0){$bgcolor="#00FF99";}else{$bgcolor="#FF9900";}?>
<tr><td><script>
var tr='<div class="col-md-2 col-12"><?php echo $tr->metal.' <b class="'.$col.'">'.$tr->type.'<span class="badge badge-warning">'.$tr->lotsize.' Lot</span></b>';?></div><div class="col-md-2 col-6">LIVE <?php echo $tr->last_live;?></div><div class="col-md-2 col-6 pull-right">LIMIT <?php echo $tr->setlimit;?></div><div class="col-md-2 col-12"><b><?php echo 'TGT: '.$tr->target.'</b><br/><b class="pull-right">SL: '.$tr->stoploss;?></b></div><div class="col-md-2 col-4 text-center"><span  style="color:white;background:<?php echo $bgcolor;?>;padding:2px 10px;font-size:14px;"><?php echo $tr->pro_loss;?></span></div><div class="col-md-2 col-8"><?php if($tr->sq_off!="On"){?><button type="button" class="btn btn-sm btn-warning" onclick="sq_offtrade(<?php echo $tr->bsid;?>)">SqOff</button><?php }?><button style="min-width:36px;" type="button" class="btn btn-danger pull-right btn-sm" data-toggle="modal" data-target="#myModal2" onclick="edit_trade1(<?php echo $tr->bsid;?>)"><i class="fa fa-edit"></i></button></div>';

//<div class="col-md-2 col-12 "><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;?><br />

    	<!--<label class="badge badge-info"><?php //echo 'Bal '.$ubal;?></label><br/>-->

        <?php if($tr->low_fund=="Off" || $tr->low_fund==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>



    Low Fund - <a href="#" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> fundlow"><?php echo $sst;?></a></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>

<button id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-warning" onclick="edit_trade1(<?php echo $tr->bsid;?>)" data-toggle="modal" data-target="#myModaledit">Edit</button>

    <?php }?>



    <a href="#" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-danger delete_trade">Delete</a>

	 </td>

     <?php if($tr->status!='EXIT'){?>

     <td>

	

    <?php if($tr->sq_off=="Off" || $tr->sq_off==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>



    <a href="#" title="Allow Square Off" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> sqoff_enable"><?php echo $sst;?></a>



    </td>

    <td>

    <?php if($tr->del_req=="Requested"){ if($tr->holding=="Off" || $tr->holding==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>



    <a href="#" title="Trade Hold" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> holding_enable"><?php echo $sst;?></a>

   

    <?php }?></td><td>

<?php if($tr->hold_status=="Off" || $tr->hold_status==""){$sst="On";$btn="success";}else{$sst="Off";$btn="danger";}?>



    <a href="#" title="Allow Unhold" id="<?php echo $tr->bsid;?>" class="btn btn-xs btn-<?php echo $btn;?> unhold_enable"><?php echo $sst;?></a>



    </td><?php }?>

    </tr>



<?php $i++;}?>



<script>



$(document).ready(function(){
	
	$(".unhold_enable").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/unhold_enable',



                                     data: {id:id,sst:sst},



                                     success: function(res){



										// alert(res);



                                        }



                                     });



                            });

	$(".holding_enable").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/holding_enable',



                                     data: {id:id,sst:sst},



                                     success: function(res){



										// alert(res);



                                        }



                                     });



                            });

							

							$(".unhold").click(function(){



                                var id=$(this).attr("id");



								



                                $.ajax({



                                     type: "POST",



                                     url: '<?php echo base_url();?>home/unhold_trade',



                                     data: {id:id},



                                     success: function(res){



										// alert(res);



                                        }



                                     });



                            });



	$(".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);



				}



		});



	});



	$(".sqoff_enable").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/sqoff_enable',



                                     data: {id:id,sst:sst},



                                     success: function(res){



										// alert(res);



                                        }



                                     });



                            });

							

							$(".fundlow").click(function(e){e.preventDefault();



                                var id=$(this).attr("id");



								var sst=$(this).text();



								if(sst=="Low Fund Off"){



								$(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/lowfund_enable',



                                     data: {id:id,sst:sst},



                                     success: function(res){



										// alert(res);



                                        }



                                     });



                            });



	$(".square").click(function(e){e.preventDefault();



                                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>