<div class="app-content content">
      <div class="content-wrapper">
        <div class="content-header row">
        </div>
        <div class="content-body">
<!--/ Demo fullscreen-overlay --><!-- ICO Token &  Distribution-->

<!--/ ICO Token &  Distribution-->
<!-- Purchase token -->

<!--/ Purchase token -->
<!-- ICO Token balance & sale progress -->
<div class="row">
<div class="col-md-3 col-6 col-12">
        <div class="card pull-up">
            <div class="card-content">
                <div class="card-body">
                    <div class="col-12">
                        <div class="row">
                            <div class="col-md-12 col-12">
                            <?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();
									//print_r($l);
									$wallet=$l->left_amt;}else{$wallet=0;}?>
                                <p><strong> <i class="fa fa-credit-card"></i>   Wallet Balance:</strong></p>
                                <h1> <i class="fa fa-inr"></i> <b id="walletamt"><?php echo $wallet;?></b>
           <a href="#" class="btn btn-warning btn-sm pull-right" id="refresh"><i class="fa fa-refresh"></i> Refresh</a>
                                </h1>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
                       
                        	<div class="col-md-3">
                            <?php $this->db->select_sum('dep_amt');  
								  $this->db->where("dep_status",""); 
								  $this->db->where("userid",$this->session->userdata("user")); 
       							  $pending=$this->db->get('deposites')->row();
								  ?>
                            <div class="card bg-danger text-white">
                                <div class="card-body">
                                <p><strong> <i class="fa fa-credit-card"></i>   Pending Balance:</strong></p>
                                <h1> <i class="fa fa-inr"></i> <b id="walletamt"><?php echo $pending->dep_amt;?>0</b></h1>
    
                                </div>
                        	</div>
                            </div>
                        	<div class="col-md-3">
                            <div class="card bg-success text-white">
                                <div class="card-body">
                                <p><strong> <i class="fa fa-credit-card"></i> Trade Limit</strong></p>
                                <h1> <i class="fa fa-inr"></i> <b id="walletamt"><?php echo $wallet*$user->trade_limit;?></b></h1>
                                </div>
                        	</div>
                            </div>
                        </div>
<!--<div class="row">

    <div class="col-md-3 col-6 col-12">
        <div class="card pull-up">
            <div class="card-content">
                <div class="card-body">
                    <div class="col-12">
                        <div class="row">
                            <div class="col-md-12 col-12">
                                <p><strong>Wallet Balance:</strong></p>
                                <h1>1000</h1>
                                <a href="#" class="btn btn-sm btn-danger">WithDraw</a>
                                <a href="#" class="btn btn-sm btn-warning">Deposite</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
</div>-->
<!--/ ICO Token balance & sale progress -->
<!-- Recent Transactions -->
<style>.table td, .table th{padding:5px;}.linkin{ border:2px solid; margin:2px;}</style>
<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);
		$("#bssid").val(res.bsid);
		 }
	 });
}
function sq_offtrade(id){
		// alert(id);
		 $.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/square_off',
				 data: {id:id},
				 success: function(res){
					 $("div#"+id).remove();
					}
				 });
	 }
$(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);
									 if(res=="Trade Updated"){
										window.location.href = '<?php echo base_url();?>home/dashboard'; 
									 }else{
										 alert(res);
									 }
									 //$("#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>
<div class="row">
    <div id="recent-transactions" class="col-12 col-md-8" style="background:#FFF; padding:5px;">
    	<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">Live Rates</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">My 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>
        </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">
          	<div class="table-responsive">
                    <table id="fullMcxPriceTable" class="table">
                    <tr bgcolor="black" style="color:#FFF;"><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 bgcolor="black" style="color:#FFF;" 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>
          <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">
            <div class="row px-1">
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Metal-Trade</p>
                </div>
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Live</p>
                </div>
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Limit</p>
                </div>
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Target</p>
                </div>
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Stoploss</p>
                </div>
                <div class="col-md-2 col-12 py-1">
                    <p class="mb-0">Profit/Loss</p>
                </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">
          	<table class="table table-bordered table-condensed table-striped">
                <thead><tr><th>S.No.</th><th>Metal</th><th>TradeType</th><th>SqOff</th><th>Limit</th><th>Target</th><th>Stoploss</th><th>Profit/Loss</th><th>Time</th></tr></thead>
                <tbody id="table_exits">
                </tbody>
            </table>
          </div>
        </div>
    </div>
    <div id="myModal" 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"  />
          	<div class="row">
            	<div class="col-md-6 form-group">
                <label>Target</label>
                <input type="text" class="form-control" name="target" id="target" />
                </div>
                <div class="col-md-6 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 class="col-12 col-md-4">
    <?php if($this->session->flashdata("msg")!==""){ echo $this->session->flashdata("msg"); }?>
    	<div class="card">
        	<div class="card-content">
            	<form id="test_trade_form" action="<?php echo base_url();?>home/buynow" method="post" style="background:#FBFBFB; border:5px solid #5E66E5; padding:10px;">
                        <div class="row">
                        <div class="form-group col-md-6">
                        	<label>TYPE</label><br/>
                        	<label>
                              <input type="radio" name="type" value="BUY" checked> BUY
                            </label>
                            <label>
                              <input type="radio" name="type" value="SELL"> SELL
                            </label>
                        </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>
                                <option value="GOLD-100">GOLD</option>
                                <option value="GOLDM-10">GOLDM</option>
                                <option value="SILVER-30">SILVER</option>
                                <option value="SILVERM-5">SILVERM</option>
                                <option value="COPPER-1000">COPPER</option>
                                <option value="COPPERM-250">COPPERM</option>
                                <option value="ALUMINIUM-5000">ALUMINIUM</option>
                                <option value="ALUMINI-1000">ALUMINI</option>
                                <option value="CRUDEOIL-100">CRUDEOIL</option>
                                <option value="CRUDEOILM-10">CRUDEOILM</option>
                                <option value="ZINC-5000">ZINC</option>
                                <option value="ZINCMINI-1000">ZINCMINI</option>
                                <option value="LEAD-5000">LEAD</option>
                                <option value="LEADMINI-1000">LEADMINI</option>
                                <option value="NICKEL-250">NICKEL</option>
                                <option value="NICKELM-100">NICKELM</option>
                                <option value="NATURALGAS-1200">NATURALGAS</option>
                            </select>
                            <input type="hidden" name="cur_rate" id="cur_rate" value="" class="" />
                        </div>
                        <div class="form-group col-md-6">
                        	<label>Lot Size</label>
                            <input type="text" name="lotsize" required class="form-control" />
                        </div>
                        <div class="form-group col-md-6">
                        	<label>Limit</label>
       <label class="pull-right"><input id="marketprice" type="checkbox" name="marketprice" value="marketprice" /> Market Rate</label>
                            <input type="text" name="setlimit" id="limit"  required class="form-control" />
                        </div>
                        <div class="form-group col-md-6">
                        	<label>Set Target</label>
                            <input type="text" name="target" class="form-control" />
                        </div>
                        <div class="form-group col-md-6">
                        	<label>Set StopLoss</label>
                            <input type="text" name="stoploss" class="form-control" />
                        </div>
                        <div class="form-group col-md-6">
                        	<label>Wallet PIN</label>
                            <input type="text" name="pin" required="" class="form-control">
                        </div>
                        </div>
                        <?php if($wallet>500){?>
                        <button type="submit" class="btn btn-warning btn-block buybtn">Submit</button>
                        <?php }else{?> 
                        <button type="button" class="btn btn-warning btn-block buybtn" disabled="disabled">Submit</button>
                        <p class="text-danger">Please Add Money to your wallet to start trading.</p>
                        <?php }?>
                    </form>
            </div>
        </div>
    </div>
</div>

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