<!DOCTYPE html>
<html lang="en">
   <head>
      <!-- Main navbar -->
      <?php 
         use App\Libraries\MyEncrypt;
        use App\Helpers\site_helper;
        use App\Helpers\form_helper;
        $this->db = db_connect();      
        $this->form_validation =  \Config\Services::validation();
         $this->finance_model = model('finance_model');
         $this->finance_model = model('CommonModel');
         //use App\Libraries\MyEncrypt;
         $this->session = session();
         $this->uri = service('uri');
         echo view('admin/common_header'); ?>
      <!-- /main navbar -->
      <style>
         label.error {
         color: #bb0505 !important;
         display: block !important;
         margin-top: 5px;
         clear:both;
         }
      </style>
      <!-- date picker JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/interactions.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/widgets.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/effects.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/extensions/mousewheel.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/globalize/globalize.js');?>"></script>
      <!-- select box theme JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_select.min.js');?>"></script>
      <!-- Theme JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/tables/datatables/datatables.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/tables/datatables/extensions/responsive.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/select2.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/pages/datatables_responsive.js');?>"></script>
      <!-- /theme JS files -->
      <!-- notify JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>
      <!-- Theme JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/bootbox.min.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/sweet_alert.min.js');?>"></script>

	  <script type="text/javascript" src="<?php echo base_url('assets/js/formValidation.js');?>"></script>
	  <script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.js');?>"></script>
      <style type="text/css">
         .icons-list a[data-action="reload1"]:after {
         content: '\e9fb';
         }
         .btns {
         padding: 5px;
         }
      </style>
   </head>
   <body class="navbar-top-md-md pace-done">
      <!-- Fixed navbars wrapper -->
      <div class="navbar-fixed-top">
         <!-- Main navbar -->
         <?php echo view('admin/mainnav'); ?>
         <!-- /main navbar -->
         <!-- Second navbar -->
         <?php echo view('admin/secondnav'); ?>
         <!-- /second navbar -->
      </div>
      <!-- /fixed navbars wrapper -->
      <!-- Page header -->
      <?php echo view('admin/'.$module_name.'_header'); ?>
      <!-- /page header -->
      <!-- Page container -->
      <div class="page-container">
         <!-- Page content -->
         <div class="page-content">
            <!-- Main content -->
            <div class="content-wrapper">
               <!-- Basic responsive configuration -->
               <div class="panel panel-flat">
                  <div class="panel-heading">
                     <h5 class="panel-title"><?php echo $page_title; ?></h5>
                     <div class="heading-elements">
                        <ul class="icons-list">
                           <!-- <li><a href="<?php echo base_url();?>admin/users/add" class="glyphicon-plus"></a></li> -->
                           <li><a data-action="collapse"></a></li>
                           <li><a data-action="reload"></a></li>
                           <li><a data-action="close"></a></li>
                        </ul>
                     </div>
                  </div>
                  <?php $currency_info = defaultcurrency();?>
                  <div class="panel-body">
                     <form class="form-horizontal export validateDontSubmit" name="frmexport" id="frmexport" action="<?php echo base_url('admin/history/earnings');?>" method="post">
                        <div class="form-group ">

                        <div class="col-lg-3">
                              <label class="control-label text-semibold">User Groups</label>
                              <select name="user_group" class="form-control bootstrap-select" id="user-group">
                                 <option value="" <?php if($usergroup=="") { echo "selected==selected";}?>>All</option>
                                 <?php 
                                  if($admin_group=='0')
                                  { 
                                 ?>
                                 <option value="0" <?php if($usergroup=="0") { echo "selected==selected";}?>>Group users - A</option>
                                 <option value="1" <?php if($usergroup=="1") { echo "selected==selected";}?>>Group users - B</option>
                                 <?php 
                                  }
                                 ?>

                                 <?php 
                                  if($admin_group=='1')
                                  { 
                                 ?>
                                 <option value="0" <?php if($usergroup=="0") { echo "selected==selected";}?>>Group users - A</option>
                                 <?php 
                                  }
                                 ?>

                                 <?php 
                                  if($admin_group=='2')
                                  { 
                                 ?>
                                 <option value="1" <?php if($usergroup=="1") { echo "selected==selected";}?>>Group users - B</option>
                                 <?php 
                                  }
                                 ?>
                              </select>
                           </div>

                           <div class="col-lg-3">
                              <label class="control-label text-semibold">Select User </label>
                              <select name="user_type" class="form-control bootstrap-select" id="user-type">
                                 <option value="">Select user</option>
                                 <?php 
                                 if($admin_group=='0')
                                 { 
                                    if($usergroup=='0')
                                       $condi=" where new_entry='0'";
                                    else if($usergroup=='1')
                                       $condi=" where new_entry='1'";
                                    else
                                       $condi=" where new_entry in('0','1')";
                                   
                                 }
                                 else 
                                 {  
                                    if($admin_group=='1')
                                       $condi=" where new_entry='0'";
                                    else if($admin_group=='2')
                                       $condi=" where new_entry='1'";
                                 }
                                    $users = $this->db->query("select * from uusers $condi order by username Asc")->getResult();
                                    if($users)
                                    {
                                    
                                        foreach($users as $row)
                                        {
                                            if($row->username!='')
                                            {
                                             ?>
                                 <option value="<?php echo $row->uusersid;?>" <?php if($userid==$row->uusersid) { echo "selected==selected";}?>><?php echo ucfirst($row->username);?></option>
                                 <?php } } }?>
                              </select>
                           </div>
                           <div class="col-lg-3">
                              <label class="control-label text-semibold"><?php echo lang('language_lang.lbl_date_from'); ?> </label>
                              <div class="input-group">
                                 <span class="input-group-addon"><i class="icon-calendar22"></i></span>
                                 <input type="text" class="form-control start_date" id="start_date" placeholder="<?php echo lang('language_lang.place_start_date'); ?>" name="start_date" value="<?php echo $fromdate;?>">
                              </div>
                           </div>
                           <div class="col-lg-3">
                              <label class="control-label text-semibold"><?php echo lang('language_lang.lbl_date_to'); ?> </label>
                              <div class="input-group">
                                 <span class="input-group-addon"><i class="icon-calendar22"></i></span>
                                 <input type="text" class="form-control end_date" id="end_date" placeholder="<?php echo lang('language_lang.place_end_date'); ?>" name="end_date" value="<?php echo $enddate;?>">
                              </div>
                           </div>
                        </div>
                        
						<div class="text-center">
							<button type="submit" class="btn btn-primary">Submit <i class="icon-arrow-right14 position-right"></i></button>
						</div>
                  
                  <div align="right">
                     <p style="font-size:12px;font-weight:bold;">Total Earnings: <span id="amount">0.00</span> USDT</p>
                  </div>
						<table class="table datatable-responsive table-hover">
							<colgroup>
								<col width="13%"/>
		  						<col width="12%"/>
		  						<col width="15%"/>
		  						<col width="23%"/>
		  						<col width="10%"/>
		  						<col width="13%" style="display:none;"/>
		  						<!-- <col width="13%"/> -->
		  						<col width="13%" style="display:none;"/>
	  						</colgroup>
							<thead>
								<tr>
									<th class=""><?php echo lang('language_lang.lbl_trans_date');?></th>
									<th class=""><?php echo lang('language_lang.lbl_transaction_id');?></th>
									<th class=""><?php echo "Username";?></th>
									<th class=""><?php  echo "Description";?></th>
									<th class="" style="display:none;"><?php echo "Chain Name";?></th>
									<th class="" style="display:none;"></th>
									<th class=""><?php echo lang('language_lang.lbl_amount');?></th>
									
								</tr>
							</thead>
							<tbody>
                            
							<?php
                        $total_balance=0;
                               
								if($history) {

									
									$row_count = count($history);
									// $this->load->library('MyEncrypt');
									$myencrypt = new MyEncrypt;
									foreach ($history as $row) {

                                      	if($row->uusersid=='0') {
											$username = 'Admin';
										} else 
                                        {
											$usernme = $row->uusersid;
										$referral1=$this->db->query("SELECT * FROM uusers WHERE uusersid='".$usernme."'")->getRow();
    									$user=$referral1;
										$username=$user->username;
                              }

                              $address=$row->description;

                              $flag=0;

                              if($admin_group=='0')
                              {
                                 if($usergroup=='0')
                                 {

                                    if($referral1->new_entry=='0')
                                       $flag=1;
                                 }
                                 else if($usergroup=='1')
                                 {
                                    if($referral1->new_entry=='1')
                                       $flag=1;

                                 }
                                 else
                                 {
                                    $flag=1;
                                 }

                              }
                              else
                              {
                                 if($admin_group=='1')
                                 {

                                    if($referral1->new_entry=='0')
                                       $flag=1;
                                 }
                                 else if($admin_group=='2')
                                 {
                                    if($referral1->new_entry=='1')
                                       $flag=1;

                                 }
                                

                              }

										if($row->amount > 0 && $flag=='1')
                                        { 

                                          $total_balance+=$row->amount;
								?>
								<tr>
									<td class=""><?php echo date('Y-m-d H:i:s', strtotime($row->date));?></td>
									<td class=""><?php echo $row->transactionid ? $row->transactionid : '---';?></td>
									<td class=""><?php echo $username;?></td>
									<td class=""><?php  echo $address; ?></td>
									<td class="" style="display:none;"><?php echo "TRC 20";?></td>
									<td class="" style="display:none;"></td>
									<td class=""><?php echo number_format($row->amount,4).' '."USDT";?></td>
										<!-- <td class=""><?php //echo ucfirst($payment_name);?></td> -->
					
								</tr>
							<?php 
                                   }
									}
								}
							
  
							?>
								
							</tbody>
						</table>
                        
                     </form>
                  </div>
                  <!-- </div> -->
               </div>
               <!-- /basic responsive configuration -->
            </div>
            <!-- /main content -->
         </div>
         <!-- /page content -->
         <!-- Footer -->
         <div class="footer text-muted">
            <?php echo site_footer();?>
         </div>
         <!-- /footer -->
      </div>
      <!-- /page container -->
      <script type="text/javascript">
         jQuery.noConflict();
         (function( $ ) {
         $(function() {
         
         
         
           
         
         	$(document).ready(function() {


               $('#amount').html('<?php echo $total_balance;?>');
         
         		$('.bootstrap-select').selectpicker();
         
         		$.jGrowl.defaults.closer = false;
         
         		<?php if(isset($form_err_data)) { ?>
         			$.jGrowl('<?php echo trim($form_err_data);?>', {
         	            header: '<?php echo lang("language_lang.error");?>',
         	            theme: 'bg-danger'
         	        });
         		<?php } ?>
         
         
         		<?php if($this->session->getFlashData('error_message')) { ?>
         			$.jGrowl("<?php echo $this->session->getFlashData('error_message');?>", {
         	            header: '<?php echo lang("language_lang.error");?>',
         	            theme: 'bg-danger'
         	        });
                    <?php } ?>
                            
                    <?php if($this->session->getFlashData('success_message')) { ?>
                        $.jGrowl("<?php echo $this->session->getFlashData('success_message');?>", {
         	            header: '<?php echo lang("language_lang.success");?>',
         	            theme: 'bg-success'
         	        });
                    <?php } ?>
         
                    $(".end_date").datepicker({
                    	format: 'mm-dd-yyyy',
                    	maxDate: 0
                    }).on('change', function(e) {
                    	$('.export').formValidation('revalidateField','end_date');
                           
                    })
         
                    $(".start_date").datepicker({
                    	format: 'mm-dd-yyyy',
                    	maxDate: 0
                    }).on('change', function(e) {
                    	$('.export').formValidation('revalidateField','start_date');
                    })
         
                
         
                    
         
         	});
             // $('[name="page_content"]').ckeditor();
          	$('#icon-bck').on('click',function() {
         		window.history.back();
         	});


             $('#user-group').change(function(){
	      		var id = '1';
				var group =$('#user-group').val();

	        	$.ajax({
	                type: 'post',
	                url : '<?php echo base_url('admin/finance/list_user_new/');?>',
	                data : {'group':group},
	                success : function(msg) {
	                    if(msg) {
                        
                        $('#user-type').html(msg);
                        
			              }
	                }
	            });
	    	});

			 /*$('.export').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
					fields: {
                        user_type: {
			        		message: '<?php echo lang("language_lang.reports_usertype_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_usertype_required"); ?>'
			                    }
			                }
			        	},
			        	start_date: {
			        		message: '<?php echo lang("language_lang.reports_from_date_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_from_date_required"); ?>'
			                    },
			                    date: {
		                            format: 'MM/DD/YYYY',
		                            max: 'end_date',
		                            message: 'The start date is not a valid'
		                        }
			                }
			        	},
			        	end_date: {
			        		message: '<?php echo lang("language_lang.reports_to_date_required"); ?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.reports_to_date_required"); ?>'
			                    },
			                    date: {
		                            format: 'MM/DD/YYYY',
		                            min: 'start_date',
		                            message: 'The end date is not a valid'
		                        }
			                }
			        	},
			           
			            
			        }
			    })*/
      
         
         
         
         
         	
         	
         
         
         
             	
         
         
          });
         })(jQuery);
         
     
         
      </script>
   </body>
</html>