<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(){



	$("#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://amplecommodity.com:4002");

$(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>

<div class="body d-flex py-3"> 

                <div class="container-xxl">

                    <div class="row g-3 mb-3">

                        <div class="col-lg-12">

                            <div class="card">

                                <div class="card-body">

                                    <div class="row g-3 align-items-center">

                                        <div class="col-md-6 col-lg-6 col-xl-3">

                                            <div class="d-flex">

                                    <img class="avatar rounded-circle" src="<?php echo base_url();?>uassets/images/profile_av.svg" alt="profile">

                                    <div class="flex-fill ms-3">

                                       <p class="mb-0"><span class="font-weight-bold">Hi, <?php echo $this->session->userdata("name");?></span></p>

                                                    <small class=""><?php echo $this->session->userdata("email");?></small>

                                    </div>

                                            </div>

                                        </div>

                                        <div class="col-md-6 col-lg-6 col-xl-3">

                                            <div class="d-flex flex-column">

                                                <span class="text-muted mb-1">User ID:<?php echo ' AMPU-'.$this->session->userdata("user");?></span>

                                                

                                            </div>

                                        </div>

                                        <div class="col-md-6 col-lg-6 col-xl-2">

                                            <div class="d-flex-inline">

                                                <span class="badge bg-careys-pink mb-1">Personal</span>

                                                <span class="small text-muted d-flex align-items-center"><i class="icofont-diamond px-1 fs-5 color-lightyellow "></i> VIP</span>

                                            </div>

                                        </div>

                                        <div class="col-md-6 col-lg-6 col-xl-4">

                    <a href="<?php echo base_url().'home/deposite';?>" title="invite" class="btn btn-primary text-dark mb-1">Add Money</a>

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div>

                    </div><!-- Row End -->



                    <div class="row g-3 mb-3 row-cols-1 row-cols-md-2 row-cols-lg-4">

                    <?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();

                    $wallet=$l->left_amt;}else{$wallet=0;}?>

                        <div class="col">

                            <div class="card">

                                <div class="card-body d-flex align-items-center">

                                    <div class="flex-fill text-truncate">

                                        <span class="text-muted text-uppercase text-danger">WALLET BALANCE</span>

                                        <div class="d-flex flex-column">

                                            <div class="price-block">

                                                <span class="fs-6 fw-bold color-price-up"><i class="fa fa-inr"></i><?php echo $wallet;?></span>

                                            </div>

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div>

                        <?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();?>

                        <div class="col">

                            <div class="card">

                                <div class="card-body d-flex align-items-center">

                                    <div class="flex-fill text-truncate">

                                        <span class="text-muted text-uppercase text-danger"> PENDING DEPOSITE</span>

                                        <div class="d-flex flex-column">

                                            <div class="price-block">

                                                <span class="fs-6 fw-bold color-price-up" style="color:orange;"><?php if($this->db->get_where("deposites",array("userid"=>$this->session->userdata("user")))->num_rows()>0){echo $pending->dep_amt;}else{echo 0;}?></span>

                                            </div>

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div>

                    </div><!-- Row End -->



                    <div class="row g-3 mb-3 row-deck">

                        <div class="col-xl-12 col-xxl-7">

                            <div class="card">

                                <div class="card-header py-3 d-flex justify-content-between bg-transparent border-bottom align-items-center flex-wrap">

                                    <h6 class="mb-0 fw-bold">Quick View</h6> 

                                    <ul class="nav nav-tabs tab-body-header rounded d-inline-flex mt-2 mt-md-0" role="tablist">

                                <li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#Spot" role="tab">LIVE WATCH</a></li>
                                <li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#P2P" role="tab">ACTIVE TRADES</a></li>
                                <li class="nav-item"><a class="nav-link exits" data-bs-toggle="tab" href="#Margin" role="tab">CLOSED TRADES</a></li>


                                        

                                    </ul>

                                </div>

                                <div class="card-body">

                                    <div class="tab-content">

                                        <div class="tab-pane fade show active" id="Spot">

                                            <div class="row">

			<div class="col-md-8">

          	<table id="fullMcxPriceTable" class="table table-responsive">



                        <tr ><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>



                    <?php $metals=$this->db->get("metals")->result();



                        foreach($metals as $d){?>



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



                        <td><?php echo $d->metal;?></td>

                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>



                        <td></td>

                    </tr>



                <?php }?>



                    </table>

			</div>

            <div class="col-md-4">
            <?php if($this->session->flashdata("msg")!==""){ echo $this->session->flashdata("msg"); }?>
            <form  action="<?php echo base_url();?>home/buynow" method="post" style="background:#ffdd9b; border:5px solid #feb019; padding:10px;">



                        <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">



                        	<label>Asset</label>



                            <select name="metal" class="form-control" required id="metal_select">

					

                            	<option value="">Select Asset</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">



                        	<label>Limit</label>





                            <input type="text" name="setlimit" id="limit"  required class="form-control" />

       <label><input id="marketprice" type="checkbox" name="marketprice" value="marketprice" /> Market Rate</label>



                        </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>



						<br/>

                         <?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-danger btn-block buybtn btn-block">START TRADE</button>



                        <?php }else{?> 



                        <button type="submit" class="btn btn-danger btn-block buybtn btn-block">START TRADE</button>



                        <?php if($wallet<=1000){?> 



                        <label>Please 6.90oney 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 class="tab-pane fade" id="P2P">
                                        <div class="col-12">

            <div class="row header_row">

                <div class="col-md-2 col-12 text-center">ASSET</div>

                <div class="col-md-2 col-12 text-center">LIVERATES</div>

                <div class="col-md-2 col-12 text-center">LIMIT</div>

                <div class="col-md-2 col-12 text-center">TGT/SL</div>

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

                <div class="col-md-2 col-12 text-center">PROFIT/LOSS</div>
                
                <div class="col-md-2 col-12 text-center">ACTION</div>

            </div>

        </div>

                                            <?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 class="tab-pane fade" id="Margin">

                                            <table class="table table-bordered table-condensed table-striped">

                   <thead><tr><th>S.No.</th><th>Metal</th><th>TradeType</th><th>Lot</th><th>SqOff</th><th>Limit</th><th>Target</th><th>Stoploss</th><th>Profit/Loss</th></tr></thead>

                <tbody id="table_exits">

                </tbody>

            </table>

                                        </div>

                                        

                                        

                                        

                                    </div>

                                </div>

                            </div>

                        </div>

                        

                    </div><!-- Row End -->



                    <!-- Row End -->



                    <!-- Row End -->



                </div>

            </div>

            

              

        

            <!-- Modal Custom Settings-->

                    

            

        </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>


    <!-- Jquery Core Js -->

    <script src="<?php echo base_url();?>uassets/bundles/libscripts.bundle.js"></script>



    <!-- Plugin Js -->

    <script src="<?php echo base_url();?>uassets/bundles/dataTables.bundle.js"></script>

    <script src="<?php echo base_url();?>uassets/bundles/apexcharts.bundle.js"></script>



    <script src="<?php echo base_url();?>uassets/js/page/index.js"></script>

</body>

</html> 