
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<script>



//var socket=io.connect("http://localhost:4000");



function edit_trade1(id){



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



	//alert(id);



	$.ajax({



	 type: "POST",dataType:'json',



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



	 data: {id:id},



	 success: function(res){//alert(res.target);



		$("#target").val(res.target);



		$("#stoploss").val(res.stoploss);



		$("#edit_lot").val(res.lotsize);



		$("#bssid").val(res.bsid);



		$("#bstype").val(res.type);



		



		 }



	 });



}



function sq_offtrade(id){



		// alert(id);



		$("#"+id).remove();



		//$(this).remove();



		 $.ajax({



				 type: "POST",



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



				 data: {id:id},



				 success: function(res){



					// alert(res);



					 //$("div#"+id).remove();



					 //alert("Trade Exit");



					 window.location.href="<?php echo base_url();?>home/dashboard";



					 



					}



				 });



	 }



$(document).ready(function(){

	$("#pills-contact-tab").click(function(e){e.preventDefault();

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

				 $.ajax({

				 type: "POST",

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

				 data: {},

				 success: function(res){
					//alert(res);
					 $("#table_exits").html(res);

					}

				 });

			 });

	$("#edit_trade_submit").submit(function(e){e.preventDefault();



								var formdata=$(this).serialize();



								//alert(formdata);



								var id=$("#bssid").val();



								var t=$("#target").val();



								var s=$("#stoploss").val();



								$.ajax({



								 type: "POST",



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



								 data: {formdata:formdata},



								 success: function(res){//alert(res);return false;



									 //if(res==0){



										//window.location.href = '<?php //echo base_url();?>home/dashboard'; 



									 //}else{

										if(res!=0){

										 alert(res);

										}else{

										 alert("Trade Updated");

										 $('#myModal2').modal('hide');

									 	}



									 //}



									 //$("#msg").text(res);



//									 if(res=="Trade Updated"){



//										$("#target"+id).text(t);



//										$("#stoploss"+id).text(s); 



//									 }



									 }



								 });



							});



	socket.on("tr_emit",function(data){



		//console.log(data.trdata);



		$("tr#"+data.trid).html(data.trdata);



		$("tr#"+data.trid+" td:nth-child(2)").css("background-color",data.color);



		setTimeout(function(){ $("tr#"+data.trid+" td:nth-child(2)").css("background","none"); }, 2000);



	});



	socket.on("tr_emit_user",function(data){



		//console.log(data.trid);



		$("div#"+data.trid).html(data.tr);



		$("tr#"+data.trid+" div:nth-child(2)").css("background-color",data.color);



//		setTimeout(function(){ $("tr#"+data.trid+" td:nth-child(2)").css("background","none"); }, 2000);



	});



	setInterval(function(){



				var cur_rate_class=$("#cur_rate").attr("class");



				//console.log(cur_rate_class);



				//$(".GOLD_ticker").text($("tr#GOLD td:nth-child(2)").text());



				if(cur_rate_class!=""){



				var v=$("tr#"+cur_rate_class+" td:nth-child(2)").text();



				}



				$("#cur_rate").val(v);



				}, 1000);



	$("#metal_select").change(function(){



				var vall=$(this).val();



				var t=vall.split("-");



				$("#cur_rate").attr("class",t[0]);



			//	$("#limit").attr("class",t[0]+"_ticker form-control");



			});



			$("#marketprice").click(function(){



				if ($('input[type="checkbox"]').is(':checked')){



					$("#limit").attr('disabled',true);



				}else{



					$("#limit").removeAttr('disabled');



				}



				//



			});



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



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



				 $.ajax({



				 type: "POST",



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



				 data: {},



				 success: function(res){



					 $("#table_exits").html(res);



					}



				 });



			 });



			 $("#refresh").click(function(e){e.preventDefault();



				 $.ajax({



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



					   type: 'GET',



					   success: function(res) {



						   $("#walletamt").text(res);



					   }



					});



			 });



});



</script>

<script>

var socket=io.connect("https://swarajtraders.in:4003");

$(document).ready(function(){

	var metal="<?php echo $this->uri->segment(3);?>";

	socket.on("tr_emit",function(data){

		console.log(data);

		if(metal==data.trid){

			var icon='';

			//if(data.color=='green'){

//				//icon='<i class="fa fa-arrow-circle-up"></i>';	

//			}if(data.color=='red'){

//				//icon='<i class="fa fa-arrow-circle-down"></i>';	

//			}

			var dd=data.trdata.split('</td><td>');

		//console.log(dd);

			$("#rate").html(icon+' '+data.single_val);

			//$("#rate").addClass(data.color);

			$("#rate").css("background-color",data.color);

			if(data.color=='none'){

			$("#rate").css("color",'#000');	

			}else{

			$("#rate").css("color",'#fff');

			}

			setTimeout(function(){ $("#rate").css("background","#fff");

			$("#rate").css("color",'#000'); }, 2000);

			//setTimeout(function(){$("#rate").removeClass('green','red','none'); },1000);

			$("#time").html(dd[7].substring(0,8));

			//$("#div"+data.trid).css("border-left","2px solid "+data.color);

			//$("#bgcolor").css("background-color",data.color);

			//setTimeout(function(){ $("#bgcolor").css("background","#212F3C"); }, 2000);

		}

	});

});

</script>

<section id="breadcrumb-section" class="breadcrumb-section clearfix" style="background-image: url(assets/images/breadcrumb-bg.jpg);">
<div class="overlay-black">
<div class="container">
<h2 class="page-title">Dashboard</h2>
</div>
</div>
</section>
<div class="breadcrumb-list">
<div class="container">
<ul>
<li class="breadcrumb-item"><a href="<?php echo base_url();?>">Home</a></li>
<li class="breadcrumb-item active">Dashboard</li>
</ul>
</div>
</div>


<section id="service-section" class="service-section sec-ptb-100 clearfix">
<div class="container">
<div class="row">

<div class="col-lg-3 col-md-12 col-sm-12">
<div class="sidebar-section">

<div class="service-menu mb-30">
<h2 class="sidebar-title">Quick Links</h2>
<ul>
<li class="active">
    <a href="#">Dashboard</a>
</li>
<li>
    <a href="<?php echo base_url();?>deposite">Deposite</a>
</li>
<li>
    <a href="<?php echo base_url();?>withdrawls">Withdrawl</a>
</li>
<li>
    <a href="<?php echo base_url();?>transactions">Transactions</a>
</li>
<li>
    <a href="<?php echo base_url();?>account">My Profile</a>
</li>
<li>
    <a href="<?php echo base_url();?>logout">Logout</a>
</li>
</ul>
</div>
</div>
</div>


<div class="col-lg-9 col-md-12 col-sm-12">
<div class="service-details">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="servicev2 mb-30">
<div class="contant">
<h4 class="service-title title-small mb-15">
<span>
<i class="fa fa-inr"></i>
</span>
<a href="#"><?php 	$this->db->order_by("trid","desc");

					$chk=$this->db->get_where("transaction",array("userid"=>$this->session->userdata("user")));

					if($chk->num_rows()>0){

                    $l=$chk->row();

                    echo $wallet=$l->left_amt;}else{echo $wallet=0;}?></a>
</h4>
<p>Wallet Balance
</p>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="servicev2 mb-30">
<div class="contant">
<h4 class="service-title title-small mb-15">
<span>
<i class="ion-stats-bars"></i>
</span>
<a href="#">0/-</a>
</h4>
<p>Pending Withdrawls</p>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="servicev2 mb-30">
<div class="contant">
<h4 class="service-title title-small mb-15">
<span>
<i class="ion-usb"></i>
</span>
<a href="#"><?php $this->db->select_sum('dep_amt');  

					  $this->db->where("dep_status","Pending"); 

					  $this->db->where("userid",$this->session->userdata("user"));

					  $chk= $this->db->get('deposites');

					 // echo $chk->num_rows();

					  $pending=$chk->row();?>
                      ₹<?php if($this->db->get_where("deposites",array("userid"=>$this->session->userdata("user")))->num_rows()>0){echo $pending->dep_amt;}else{echo 0;}?>/-</a>
</h4>
<p>Pending Deposites</p>
</div>
</div>
</div>
</div>

<ul class="nav nav-pills" id="pills-tab" role="tablist">

<li class="nav-item">

<a class="nav-link active linkin" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">MCX LIVE WATCH</a>

</li>

<li class="nav-item">

<a class="nav-link linkin" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">LIVE TRADES</a>

</li>

<li class="nav-item">

<a class="nav-link linkin exits" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">EXIT TRADES</a>

</li>
<li class="nav-item pull-right float-right">

<a class="nav-link linkin new_trade" id="pills-new_trade-tab" data-toggle="pill" href="#pills-new_trade" role="tab" aria-controls="pills-new_trade" aria-selected="false">START NEW TRADE</a>

</li>

</ul>
                                <div class="tab-content" id="pills-tabContent" style="margin-top:10px;">
			
          <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
          <table id="fullMcxPriceTable" class="display misco-data-table table table-condensed table-bordered" style="width:100%">
                                        <thead>
                                            <tr  bgcolor="#FFCC33"><th>Commodity</th><th>Price</th><th>Chg</th><th>%Chg</th><th>Open</th><th>High</th><th>Low</th><th>Time</th></tr>
                                        </thead>
                                        <tbody>
                                         <?php $metals=$this->db->get("metals")->result();



                        foreach($metals as $d){?>



                    <tr  id="<?php echo $d->metal;?>" class="metals_tr">



                        <th><b><?php echo $d->metal;?></b></th>

                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>

                    </tr>



                <?php }?>
                                        </tbody>
                                    </table>
          </div>

          <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">

          <div class="history-table-th d-none d-md-block">

        <div class="col-12">
			<style>
			.livediv{color:#fff; padding:10px;}
			</style>
            <div class="row header_row" style="background:#000;">

                <div class="col-md-2 col-12 livediv">Metal</div>

                <div class="col-md-2 col-12 livediv">Live</div>

                <div class="col-md-2 col-12 livediv">Limit</div>

                <div class="col-md-2 col-12 livediv">Target/SL</div>

                <!--<div class="col-md-2 col-12">Stoploss</div>-->

                <div class="col-md-2 col-12 livediv">Profit/Loss</div>
                
                <div class="col-md-2 col-12 livediv">Actions</div>

            </div>

        </div>

    </div>

<div class="history-table-tbody">

 <?php $trades=$this->db->get_where("buysell",array("status!="=>"EXIT","uid"=>$this->session->userdata("user")))->result();	

			 		  $i=1;foreach($trades as $tr){?>

                        <section class="card pull-up">
                    
                            <div class="card-content">
                    
                                <div class="card-body">
                    
                                    <div class="col-12">
                    
                                        <div class="row" id="<?php echo $tr->bsid;?>">
                    
                                            
                    
                                        </div>
                    
                                    </div>
                    
                                </div>
                    
                            </div>
                    
                        </section>

      <?php }?>

</div>

          </div>

          <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
 <div class="row header_row" style="background:#000;">

                <div class="col-md-2 col-12 livediv">Metal</div>

                <div class="col-md-2 col-12 livediv">Live</div>

                <div class="col-md-2 col-12 livediv">Limit</div>

                <div class="col-md-2 col-12 livediv">Target/SL</div>

                <!--<div class="col-md-2 col-12">Stoploss</div>-->

                <div class="col-md-2 col-12 livediv">Profit/Loss</div>
                

            </div>
          	<section class="card pull-up">
                    
                            <div class="card-content">
                    
                                <div class="card-body"  id="table_exits">
                    
                    
                                </div>
                    
                            </div>
                    
                        </section>

          </div>
          
           <div class="tab-pane fade" id="pills-new_trade" role="tabpanel" aria-labelledby="pills-new_trade-tab">
           <div class="row"><div class="col-md-6"><div  style="padding:20px; background:#faecc4;">
                                <style> label{color:#49596d;}</style>
								<?php if($this->session->flashdata("msg")!==""){ echo $this->session->flashdata("msg"); }?>
                                <form action="<?php echo base_url();?>home/buynow" method="post">
                    
                    
                    
                                            <div class="row">
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                            <div class="frb frb-warning">
                    
                    
                    
                                            <input type="radio" name="type" id="radio-button-0" checked="checked" value="BUY">
                    
                    
                    
                                            <label for="radio-button-0">
                    
                    
                    
                                                <span class="frb-title">BUY</span>
                    
                    
                    
                                            </label>
                    
                    
                    
                                            </div>
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <div class="frb frb-primary">
                    
                    
                    
                                                    <input type="radio" id="radio-button-1" name="type" value="SELL">
                    
                    
                    
                                                    <label for="radio-button-1">
                    
                    
                    
                                                        <span class="frb-title">SELL</span>
                    
                    
                    
                                                    </label>
                    
                    
                    
                                                </div>
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <label>Asset</label>
                    
                    
                    
                                                <select name="metal" class="form-control" required id="metal_select">
                    
                                        
                    
                                                    <option value="">Select</option>
                    
                                                    
                    
                                                    <?php $this->db->select("*");
                    
                                        $this->db->from("metals");
                    
                                        $this->db->join("user_assets","user_assets.asset_type=metals.metal");
                    
                                        $this->db->where("user_assets.uid",$this->session->userdata("user"));
                    
                                        $metals=$this->db->get()->result();
                    
                                        foreach($metals as $d){?>

                    
                                        <option value="<?php echo $d->metal.'-'.$d->lots;?>"><?php echo $d->metal;?></option>
                    
                                        <?php }?>
                    
                    
                    
                                                    
                    
                    
                    
                                                </select>
                    
                    
                    
                                                <input type="hidden" name="cur_rate" id="cur_rate" value="" class="" />
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6  col-6">
                    
                    
                    
                                                <label>Limit</label>
                           <label class="pull-right float-right"><input id="marketprice" type="checkbox" name="marketprice" value="marketprice" /> Live Rate</label>
                    
                    
                    
                    
                    
                                                <input type="text" name="setlimit" id="limit"  required class="form-control" />
                    
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <?php $lim=$this->db->get_where("users",array("id"=>$this->session->userdata("user")))->row();
                    
                    
                    
                                            //print_r($lim);?>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <label>Lot Size</label>
                    
                    
                    
                                                <input type="text" name="lotsize" required class="form-control" />
                    
                    
                    
                                                <!--<select class="form-control" name="lotsize" required>
                    
                    
                    
                                                <?php 
                    
                    
                    
                                                 //for($i=0;$i<$lim->trade_limit+1;$i++){?>
                    
                    
                    
                                                <option value="<?php //echo $i+1;?>"><?php //echo $i+1;?> Lot</option>
                    
                    
                    
                                                <?php //}?></select>-->
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <label>Set Target</label>
                    
                    
                    
                                                <input type="text" name="target" class="form-control" />
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <label>Set StopLoss</label>
                    
                    
                    
                                                <input type="text" name="stoploss" class="form-control" />
                    
                    
                    
                                            </div>
                    
                    
                    
                                            <div class="form-group col-md-6 col-6">
                    
                    
                    
                                                <label>Wallet PIN</label>
                    
                    
                    
                                                <input type="text" name="pin" required="" class="form-control">
                    
                    
                    
                                            </div>
                    
                    
                    
                                            </div>
                    
                    
                    
                                             <?php 
                    
                                             if($this->db->get_where("users",array("id"=>$this->session->userdata("user"),"usertrade!="=>""))->num_rows()>0){
                    
                    
                    
                                ?><div class="alert alert-danger">Your Trade is Disabled from company. Please Contact Company.</div><?php 
                    
                    
                    
                            }else{
                    
                                             $admin=$this->db->get("admin")->row(); if($wallet>1000 && $admin->trade_enable==""){?>
                    
                                            <button type="submit" class="btn btn-warning">START TRADE</button>
                    
                    
                    
                                            <?php }else{?> 
                    
                    
                    
                                            <button type="submit" class="btn btn-warning">START TRADE</button>
                    
                    
                    
                                            <?php if($wallet<=1000){?> 
                    
                    
                    
                                            <label>Please add funds to your wallet to start trading.</label>
                    
                    
                    
                                            <?php }else if($admin->trade_enable!=""){?>
                    
                    
                    
                                            <label>Trade is Closed due to Server Technical issue.</label>
                    
                    
                    
                                            <?php }}}?>
                    
                    
                    
                                        </form>
                                        </div>
                                        </div></div>
           </div>

        </div>
        <div id="myModal2" class="modal fade" role="dialog">
  <div class="modal-dialog modal-md">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
       
        <h4 class="modal-title">Edit Trade</h4>
         <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
      <div class="modal-body">
          <form action="" method="post" id="edit_trade_submit">
          		<input type="hidden" name="bsid" id="bssid"  />
                <input type="hidden" name="type" id="bstype"  />
          	<div class="row">
            	<div class="col-md-4 form-group">
                <label>LotSize</label>
                <input type="text" class="form-control" readonly="readonly" name="lotsize" id="edit_lot" />
                </div>
                <div class="col-md-4 form-group">
                <label>Target</label>
                <input type="text" class="form-control" name="target" id="target" />
                </div>
                <div class="col-md-4 form-group">
                <label>Stoploss</label>
                <input type="text"class="form-control" name="stoploss" id="stoploss" />
                </div>
            </div>
            <p class="text-warning" id="msg"></p>
            <button type="submit" class="btn btn-xs btn-warning">Update</button>
          </form>	
      </div>
    </div>

  </div>
</div>                        

</div>
</div>

</div>
</div>
</section>