
                  <div class="body-content">
                        <div class="row">
                            <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
                                <div class="card card-stats statistic-box mb-4">
                                    <div class="card-header card-header-warning card-header-icon position-relative border-0 text-right px-3 py-0">
                                        <div class="card-icon d-flex align-items-center justify-content-center">
                                            <i class="fa fa-users"></i>
                                        </div>
                                        <p class="card-category text-uppercase fs-12 font-weight-bold ">Total Clients</p>
                                        <h3 class="card-title fs-24 font-weight-bold"><?php echo $this->db->get("users")->num_rows();?></h3>
                                    </div>
                                    
                                </div>
                            </div>
                            <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
                                <div class="card card-stats statistic-box mb-4">
                                    <div class="card-header card-header-success card-header-icon position-relative border-0 text-right px-3 py-0">
                                        <div class="card-icon d-flex align-items-center justify-content-center">
                                            <i class="fa fa-users"></i>
                                        </div>
                                        <p class="card-category text-uppercase fs-12 font-weight-bold ">New Client</p>
                                        <h3 class="card-title fs-24 font-weight-bold"><?php echo $this->db->get_where("users",array("admin_approve"=>""))->num_rows();?></h3>
                                    </div>
                                   
                                </div>
                            </div>
                            <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
                                <div class="card card-stats statistic-box mb-4">
                                    <div class="card-header card-header-danger card-header-icon position-relative border-0 text-right px-3 py-0">
                                        <div class="card-icon d-flex align-items-center justify-content-center">
                                            <i class="fa fa-list"></i>
                                        </div>
                                        <p class="card-category text-uppercase fs-12 font-weight-bold ">New Deposite</p>
                                        <h3 class="card-title fs-24 font-weight-bold"><?php echo $this->db->get_where("deposites",array("dep_status"=>"Pending"))->num_rows();?></h3>
                                    </div>
                                    
                                </div>
                            </div>
                            <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
                                <div class="card card-stats statistic-box mb-4">
                                    <div class="card-header card-header-info card-header-icon position-relative border-0 text-right px-3 py-0">
                                        <div class="card-icon d-flex align-items-center justify-content-center">
                                            <i class="fa fa-list"></i>
                                        </div>
                                        <p class="card-category text-uppercase fs-12 font-weight-bold ">New WithDrawal</p>
                                        <h3 class="card-title fs-24 font-weight-bold"><?php echo $this->db->get_where("withdrawls",array("req_status"=>"Pending"))->num_rows();?></h3>
                                    </div>
                                    
                                </div>
                            </div>
                        </div>
<div class="row">
                            <div class="col-md-2">
                  <input type="date" name="date" value="<?php echo date("Y-m-d");?>" id="datefilter"  class="form-control" /></div>
                  <div class="col-md-3">
                  <select name="customer" class="form-control" id="customer" style="width:200px;">
                            	<option value="">All Customer</option>
							<?php $this->db->select("id,first_name,mobile");$this->db->order_by("first_name","asc");
                                    $users=$this->db->get('users')->result();foreach($users as $u){?>
                                    <option value="<?php echo $u->id;?>"><?php echo $u->first_name.'-'.$u->mobile;?></option>
                                    <?php }?></select></div>
                                    
                                    <?php $admin=$this->db->get("admin")->row();?>

                     <div class="col-md-2">
                    
                    <select class="form-control" id="link_on" style="width:200px;">

                        <option value="">Link On</option>

                        <option value="Off" <?php if($admin->link_pause!=""){echo "selected";}?>>Link Off</option>

                    </select></div>
                    <div class="col-md-5">
                    <form class="form-inline" action="">
              <div class="form-group">
              <select id="selected_metal" required class="form-control">
              	<option value="">Select Metal</option>
                <?php $this->db->select("metal,lots");$metals=$this->db->get("metals")->result();
				foreach($metals as $m){?>
                <option value="<?php echo $m->metal.'-'.$m->lots;?>"><?php echo $m->metal;?></option>
                <?php }?>
              </select>
              </div>
              <div class="form-group">
                <input type="number" placeholder="Enter Value" required class="form-control" id="metal_val">
              </div>
              <button type="button" class="btn btn-danger manual_val">Update</button>
            </form> 
                    </div>
                                    </div>
                                    <hr/>
                        <div class="row">

                            

                            

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

                                <div class="card mb-4">

                                    <div class="card-body">
                                        <button type="button" data-toggle="modal" data-target="#newtradeModal" class="btn btn-warning float-right">Add New Trade</button>
                                        <select class="form-control float-right" id="check_trade" style="width:200px;">

                        <option value="">Open</option>

                        <option value="Close" <?php if($admin->trade_enable!=""){echo "selected";}?>>Close</option>

                    </select>


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

                                            <li class="nav-item">

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

                                            </li>

                                            <li class="nav-item">

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

                                            </li>

                                            <li class="nav-item">

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

                                            </li>

                                        </ul>
                                        <div class="tab-content" id="pills-tabContent">

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

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

            <thead><tr bgcolor="#FF9900"><th>S.No.</th><th>Client</th><th>Metal</th><th>TradeType</th><th>Live</th><th>Limit</th><th>Target</th><th>Stoploss</th><th>Profit/Loss</th><th>Time</th><th>Action</th><th>Square Off</th><th>Hold Request</th><th>Hold Allow</th></tr></thead>

            <tbody id="live_trades">

            <tr><td colspan="10"><h3>Loading Trades...</h3></td></tr>

            </tbody>

        </table>

                                            </div>

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

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

            <thead><tr><th>S.No.</th><th>Client</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><th>Action</th></tr></thead>

            <tbody id="table_BUY">

            </tbody>

        </table>

                                            </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>Client</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><th>Action</th></tr></thead>

            <tbody id="table_SELL">

            </tbody>

        </table>

                                            </div>

                                        </div>

                                    </div>

                                </div>

                            </div>
<div class="col-md-12 col-lg-12 col-xl-12">

                                <div class="card mb-4">

                                    <div class="card-header">

                                        <h2 class="fs-18 font-weight-bold mb-0">Daily PROFIT/LOSS

                                        <select class="float-right" style="width:200px;" id="change_month">

    	<?php $m=date("m");

		for($i=1;$i<=$m;$i++){?>

        <option selected="selected" value="<?php echo date("F", mktime(0, 0, 0, $i, 10)).'-2021';?>"><?php echo date("F", mktime(0, 0, 0, $i, 10)).'-2021';?></option>

        <?php }?>

    </select></h2>

                                    </div>

                                    

                                </div>

                            </div>
                        </div>

                    </div><!--/.body content-->

                </div><!--/.main content-->

                <footer class="footer-content">

                    <div class="footer-text d-flex align-items-center justify-content-between">

                        <div class="copy">© 2021 <?php echo $this->session->userdata("company");?></div>

                        <div class="credit">Designed by: <a href="#">CODENINJAS</a></div>

                    </div>

                </footer><!--/.footer content-->

                <div class="overlay"></div>

            </div><!--/.wrapper-->

        </div>
        
        <div id="newtradeModal" class="modal fade" role="dialog">
          <div class="modal-dialog modal-lg">
        
            <!-- Modal content-->
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">Add New Trade</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
              </div>
              <div class="modal-body">
                <form id="test_trade_form" action="<?php echo base_url();?>swadmin/buynow2" method="post">
                        <div class="row">
                        <div class="form-group  col-md-4">
                        	<label>Select Customer</label>
                            <select name="customer"class="selectpicker form-control" data-show-subtext="true" data-live-search="true"required>
                            	<option value="">Select Customer</option>
							<?php $this->db->select("id,first_name,mobile");$this->db->order_by("first_name","asc");
                                    $users=$this->db->get('users')->result();foreach($users as $u){?>
                                    <option data-subtext="<?php echo  $u->id.'-'.$u->first_name.'-'.$u->mobile;?>" value="<?php echo $u->id.'-'.$u->first_name;?>"><?php echo $u->first_name.'-'.$u->mobile;?></option>
                                    <?php }?></select>
                        </div>
                        <div class="form-group col-md-4">
                        	<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-4">
                        	<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-2500">COPPER</option>
                                <option value="ALUMINIUM-5000">ALUMINIUM</option>
                                <option value="CRUDEOIL-100">CRUDEOIL</option>
                                <option value="ZINC-5000">ZINC</option>
                                <option value="LEAD-5000">LEAD</option>
                                <option value="NICKEL-1500">NICKEL</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-3">
                        	<label>Lot Size</label>
                            <input type="text" name="lotsize" required class="form-control" />
                        </div>
                        <div class="form-group col-md-3">
                        	<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-3">
                        	<label>Set Target</label>
                            <input type="text" name="target" class="form-control" />
                        </div>
                        <div class="form-group col-md-3">
                        	<label>Set StopLoss</label>
                            <input type="text" name="stoploss" class="form-control" />
                        </div>
                        </div>
                        <button type="submit" class="btn btn-warning  buybtn">Submit</button>
                        
                    </form>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
            </div>
        
          </div>
        </div>
        
        <div id="myModaledit" 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-4 form-group">
                        <label>Lot Size</label>
                        <input type="text" class="form-control" name="lotsize" id="lotsize" />
                        </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>

        <!--Global script(used by all pages)-->

        <script>//
		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);
			$("#lotsize").val(res.lotsize);
			$("#bssid").val(res.bsid);
			 }
		 });
	}
//am4core.ready(function() {
//
//// Themes begin
//am4core.useTheme(am4themes_animated);
//// Themes end
//
//// Create chart instance
//var chart = am4core.create("chartdiv", am4charts.PieChart);
//
//// Add data
//chart.data = [ {
//  "country": "Profit",
//  <?php   //$this->db->select_sum('pro_loss'); 
//  		  $this->db->where("pro_loss>",0); 
//		  $this->db->where("monthyr",date("F-Y")); 
//		  $profit=$this->db->get('buysell')->row();
//		  
//		  $this->db->select_sum('pro_loss'); 
//  		  $this->db->where("pro_loss<",0); 
//		  $this->db->where("monthyr",date("F-Y")); 
//		  $loss=$this->db->get('buysell')->row();?>
//  "litres": <?php //echo $profit->pro_loss;?>
//}, {
//  "country": "Loss",
//  "litres": <?php //echo $loss->pro_loss;?>
//}];
//
//// Add and configure Series
//var pieSeries = chart.series.push(new am4charts.PieSeries());
//pieSeries.dataFields.value = "litres";
//pieSeries.dataFields.category = "country";
//pieSeries.slices.template.stroke = am4core.color("#fff");
//pieSeries.slices.template.strokeWidth = 2;
//pieSeries.slices.template.strokeOpacity = 1;
//
//// This creates initial animation
//pieSeries.hiddenState.properties.opacity = 1;
//pieSeries.hiddenState.properties.endAngle = -90;
//pieSeries.hiddenState.properties.startAngle = -90;
//
//}); // end am4core.ready()
	$(document).ready(function(){
		$("#marketprice").click(function(){
				if ($('input[type="checkbox"]').is(':checked')){
					$("#limit").attr('disabled',true);
				}else{
					$("#limit").removeAttr('disabled');
				}
				//
			});
		$(".manual_val").click(function(){
				var metal=$("#selected_metal").val().split('-');
				//var oldrate=$("#"+metal[0]).text();
				var metal_val=parseFloat($("#metal_val").val());
				if(metal[0]=="" || metal_val==""){alert("Please Select Metal an Put Rate.");return false;}
				
				//check_new(metal[0],oldrate,metal_val,metal[1]);
				 $.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>welcome/check_new2',
				 data: {metal:metal[0],rate:metal_val,lotsize:metal[1]},
				 success: function(res){
					 console.log(res);
					 //alert(response);
				//	 console.log(response)
				//	$("#rate_return").html(response);
					}
				 });
				
			 });
$("#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);
								 	alert(res);return false;
									 if(res=="Trade Updated"){
										//window.location.href = '<?php //echo base_url();?>admin'; 
									 }else{
										 alert(res);
									 }
									 //$("#msg").text(res);
//									 if(res=="Trade Updated"){
//										$("#target"+id).text(t);
//										$("#stoploss"+id).text(s); 
//									 }
									 }
								 });
							});
		var m=$("#change_month").val();

	$.ajax({

		 type: "POST",

		 url: '<?php echo base_url();?>swadmin/ajax_daily_proloss',

		 data: {m:m},

		 success: function(res){

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

		}

	});

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

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

		$.ajax({

			 type: "POST",

			 url: '<?php echo base_url();?>swadmin/ajax_daily_proloss',

			 data: {m:m},

			 success: function(res){

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

			}

		});

	});

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

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

			$.ajax({

				 type: "POST",

				 url: '<?php echo base_url();?>swadmin/check_trade',

				 data: {st:st},

				 success: function(res){
					 console.log(res);

					// $("#live_trades").html(res);

					}

				 });

		});
		
		$("#link_on").change(function(){

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

			$.ajax({

				 type: "POST",

				 url: '<?php echo base_url();?>swadmin/link_on',

				 data: {st:st},

				 success: function(res){
					 console.log(res);

					// $("#live_trades").html(res);

					}

				 });

		});

		setInterval(function(){

				$.ajax({

				 type: "POST",

				 url: '<?php echo base_url();?>welcome/live_trades',

				 data: {},

				 success: function(res){

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

					}

				 });

			 }, 1000);

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

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

				 var date=$("#datefilter").val();

				 $.ajax({

				 type: "POST",

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

				 data: {id:id,date:date},

				 success: function(res){

					 $("#table_"+id).html(res);

					}

				 });

			 });

		

	});

	</script>

        <script src="<?php echo base_url();?>adminassets/plugins/metisMenu/metisMenu.min.js"></script>

        <script src="<?php echo base_url();?>adminassets/plugins/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>

        <!-- Third Party Scripts(used by this page)-->

        <script src="<?php echo base_url();?>adminassets/plugins/sparkline/sparkline.min.js"></script>

        <!--Page Active Scripts(used by this page)-->

        <script src="<?php echo base_url();?>adminassets/dist/js/pages/dashboard.js"></script>

        <!--Page Scripts(used by all page)-->

        <script src="<?php echo base_url();?>adminassets/dist/js/sidebar.js"></script>

    </body>



</html>