<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">
                       <div class="alert alert-danger" id="newtrademsg" style="display:none;">One New Trade</div>
                           <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="#home" data-toggle="tab">BUY</a></li>
                                    <li><a href="#profile" data-toggle="tab">SELL</a></li>
                                </ul>
                                <div class="tab-content">
                                    <div class="tab-pane active fade in" id="home">
                                     <table class="table table-striped table-responsive table-bordered dataTable" id="example-2">
                            <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 $trade=0;$i=1;foreach($buy 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 class="metal_<?php echo $dep->metal;?>" bgcolor="#CCCCCC"></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 id="<?php echo $dep->metal.$dep->bsid;?>"><?php //echo $dep->dep_remarks;?></td>
                                    <td><a href="#" class="btn btn-danger btn-xs square" id="<?php echo $dep->bsid;?>">Square Off</a>
                                    <a class="btn btn-xs btn-danger trade_delete" title="delete"  href="#" id="<?php echo $dep->bsid;?>"><i class="fa fa-trash"></i></a>
                                    <a class="btn btn-xs btn-warning trade_refresh" href="<?php echo $dep->setlimit;?>" id="<?php echo $dep->bsid;?>"><i class="fa fa-refresh"></i></a></td></tr>
                                <?php $i++;$trade++;}?>
                            </tbody>
                        </table>
                        				
                                    </div>
                                    <div class="tab-pane fade in" id="profile">
                                     	<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($sell 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 class="metal_<?php echo $dep->metal;?>" bgcolor="#CCCCCC"></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 id="<?php echo $dep->metal.$dep->bsid;?>"></td>
                    <td><?php if($dep->status!="EXIT"){?><a href="#" class="btn btn-danger btn-xs square" id="<?php echo $dep->bsid;?>">Square Off</a><?php }?>
                    <a class="btn btn-xs btn-danger trade_delete" title="delete"  href="#" id="<?php echo $dep->bsid;?>"><i class="fa fa-trash"></i></a>
                    <a class="btn btn-xs btn-warning trade_refresh" href="<?php echo $dep->setlimit;?>" id="<?php echo $dep->bsid;?>"><i class="fa fa-refresh"></i></a></td></tr>
                <?php $i++;$trade++;}?>
            </tbody>
            </table>
                                    </div>
                                    
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.content -->
            <input type="hidden" id="total_trade" value="<?php echo $trade;?>" />
        </div>
        <script>
                        $(document).ready(function(){
							
                            $(".square").click(function(){
                                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){
                                        }
                                     });
                            });
                            setInterval(function(){
								var total_trade=$("#total_trade").val(); 
								$.ajax({
									 type: "POST",
									 url: '<?php echo base_url();?>admin/total_trades',
									 data: {total_trade:total_trade},
									 success: function(res){console.log(res);
										if(res!=total_trade){
										$("#total_trade").val();
										$("#newtrademsg").show();
										setTimeout(function(){ 
										window.location.href = "<?php echo base_url();?>admin/orderbook";
										 }, 2000);//return false;
										}else{
											
										}
									 }
									 });
                                $.ajax({
                                   url: '<?php echo base_url();?>home/livedata_rates',
                                   type: 'GET',dataType: 'json',
                                   success: function(res) {
									   //console.log(res);
                                     $.each (res, function (bb) {
                                         $(".metal_"+res[bb].metal).text(res[bb].rate);
                                    });
                                   }
                                 });
                                 $.ajax({
                                     type: "POST",
                                     url: '<?php echo base_url();?>admin/livedata_rates1',
                                     data: {id:"adfa"},
                                     success: function(res){
                                         //console.log(res);
                                         var rdata=res.split("=");
                                         for (i=0;i<rdata.length;i++){
                                                 var dd=rdata[i].split("-");
                                                $("#"+dd[2]).text(dd[0]);
                                                 $("#"+dd[2]).css('background-color',dd[3]);
                                            }
                                        }
                                     });
                             }, 1000);
                        });
                        </script>
         <script>
	$(document).ready(function(){
		
	    $(".trade_refresh").click(function(e){e.preventDefault();
			var id=$(this).attr("id");
			var href=$(this).attr("href");
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/trade_refresh',
							 data: {id:id,href:href},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".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>

