<link rel="stylesheet" href="<?php echo base_url();?>newadminassets/plugins/datatables/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>newadminassets/plugins/datatables/responsive.bootstrap.min.css">
<div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                   OrderBook
                </h1>
              <ol class="breadcrumb">
                    <li><a href="<?php echo base_url();?>admin"><i class="fa fa-home"></i>Home</a></li>
                    <li class="active">Manage OrderBook</li><li class="active"><?php echo $this->uri->segment(3);?> OrderBook</li>
                </ol>
            </section>
            <!-- Main content -->
            <div class="content">
           
                <div class="container-fluid">
                    <div class="row"> 
                       <div class="col-md-12 col-sm-12">
                           <form class="form-inline" action="" method="get">
                  <div class="form-group">
                    <input type="date" class="form-control" value="<?php if(isset($_GET['date'])){echo $_GET['date'];}?>" id="datepicker"  name="date" placeholder="Filter By Date">
                  </div>
                  <button type="submit" class="btn btn-success">Submit</button>
                </form>
                       <?php if($this->session->flashdata("msg")!==""){?>
                          <!--<div class="alert alert-info">
                                            <strong><?php echo $this->session->flashdata("msg");?>!</strong> 
                                        </div>--><?php }?>
                                        <div class="tab-container widget">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a href="#messages" data-toggle="tab">BUY EXIT</a></li>
                                    <li><a href="#messages1" data-toggle="tab">SELL EXIT</a></li>
                                </ul>
                                <div class="tab-content">
                                     <div class="tab-pane active fade in" id="messages">
                                       	<table class="table table-condensed table-striped">
            <thead bgcolor="#666666" style="color:#FFF;"><tr><th>S.No.</th><th>Customer</th><th>SetTime</th><th>Commodity</th><th>LivePrice</th><th>LOT</th><th>LIMIT</th><th>TARGET</th><th>STOPLOSS</th><th>Profit/Loss</th><th>Action</th></tr></thead>
            <tbody>
                <?php $i=1;foreach($bexit as $dep){?>
                <tr><td><?php echo $i;?></td><td><?php echo $dep->first_name.' '.$dep->last_name;?></td><td><?php echo date("d M'Y H:i a",strtotime($dep->bsdate));?></td>
                    <td><?php echo $dep->metal;?></td>
                    <td><?php echo $dep->last_live;?></td>
                    <td><?php echo $dep->lotsize;?></td>
                    <td><?php echo $dep->setlimit;?></td>
                   <td><?php if($dep->target==1000000 || $dep->target==0){echo '-';}else{echo $dep->target;}?></td>
                                    <td><?php if($dep->stoploss==1000000 || $dep->stoploss==0){echo '-';}else{echo $dep->stoploss;}?></td>
                    <td><?php $p=0;$l=0;
			  $this->db->select_sum('tr_amt');  
			  $this->db->where("userid",$dep->id);
			  $this->db->where("tr_type","Credit");
			  $this->db->where("buysell_id",$dep->bsid);
			  $profit=$this->db->get('transaction');
			  if($profit->num_rows()>0){$pro=$profit->row();$p=$pro->tr_amt;}	
			  //loss
			  $this->db->select_sum('tr_amt');  
			  $this->db->where("userid",$dep->id);
			  $this->db->where("tr_type","Debit");
			  $this->db->where("buysell_id",$dep->bsid);
			  $loss=$this->db->get('transaction');
			  if($loss->num_rows()>0){$loo=$loss->row();$l=$loo->tr_amt;}
			  echo $prr= $p-$l;?></td><td>  <a class="btn btn-xs btn-danger trade_delete" title="delete"  href="#" id="<?php echo $dep->bsid;?>"><i class="fa fa-trash"></i></a></td></tr>
                <?php $i++;}?>
            </tbody>
            </table>
                                    </div>
                                    <div class="tab-pane fade in" id="messages1">
                                       	<table class="table table-condensed table-striped">
            <thead bgcolor="#666666" style="color:#FFF;"><tr><th>S.No.</th><th>Customer</th><th>SetTime</th><th>Commodity</th><th>LivePrice</th><th>LOT</th><th>LIMIT</th><th>TARGET</th><th>STOPLOSS</th><th>Profit/Loss</th><th>Action</th></tr></thead>
            <tbody>
                <?php $i=1;foreach($sexit as $dep){?>
                <tr><td><?php echo $i;?></td><td><?php echo $dep->first_name.' '.$dep->last_name;?></td><td><?php echo date("d M'Y H:i a",strtotime($dep->bsdate));?></td>
                    <td><?php echo $dep->metal;?></td>
                    <td><?php echo $dep->last_live;?></td>
                    <td><?php echo $dep->lotsize;?></td>
                    <td><?php echo $dep->setlimit;?></td>
                   <td><?php if($dep->target==1000000 || $dep->target==0){echo '-';}else{echo $dep->target;}?></td>
                                    <td><?php if($dep->stoploss==1000000 || $dep->stoploss==0){echo '-';}else{echo $dep->stoploss;}?></td>
                    <td><?php $p=0;$l=0;
			  $this->db->select_sum('tr_amt');  
			  $this->db->where("userid",$dep->id);
			  $this->db->where("tr_type","Credit");
			  $this->db->where("buysell_id",$dep->bsid);
			  $profit=$this->db->get('transaction');
			  if($profit->num_rows()>0){$pro=$profit->row();$p=$pro->tr_amt;}	
			  //loss
			  $this->db->select_sum('tr_amt');  
			  $this->db->where("userid",$dep->id);
			  $this->db->where("tr_type","Debit");
			  $this->db->where("buysell_id",$dep->bsid);
			  $loss=$this->db->get('transaction');
			  if($loss->num_rows()>0){$loo=$loss->row();$l=$loo->tr_amt;}
			  echo $prr= $p-$l;?></td><td>  <a class="btn btn-xs btn-danger trade_delete" title="delete"  href="#" id="<?php echo $dep->bsid;?>"><i class="fa fa-trash"></i></a></td></tr>
                <?php $i++;}?>
            </tbody>
            </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.content -->
        </div>
         <script>
	$(document).ready(function(){
		$(".trade_delete").click(function(e){e.preventDefault();
		if (!confirm("Sure you want to delete?")){
				  return false;
				}
			var id=$(this).attr("id");
			$(this).closest("tr").remove();
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/trade_delete',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		});
</script>
  <footer class="main-footer">
            <strong>Copyright &copy; 2018 <a href="#">GuruCommodities</a>.</strong> All rights reserved.
        </footer>
    </div>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/bootstrap.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/material.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/ripples.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery.slimscroll.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/jszip.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/pdfmake.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/vfs_fonts.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/buttons.html5.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/buttons.print.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/datatables/buttons.colVis.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/datatables.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/app.js"></script>
</body>

