<?php
$user_id=$this->session->userdata('user_id');
if(!$user_id){
  redirect('user/login_view', 'refresh');
}

 $value='';

?>
<?php 
$b_type='';
 $bus_type=$this->db->query("select * from buisness_type  where user_id='$user_id'
    ");
  $data='';
  foreach ($bus_type->result() as $key => $bus_type){
    $b_type=$bus_type->buisness_id;

  }
if($tabsearch){
  
      $tabactv='';
   
 }
else{
   
     $tabactv='active';
    $tabsearch='';  
}
?>
<!DOCTYPE html>
<html lang="en">

    <?php
    $this->load->view('head.php');
     ?>

<body>

    <div id="wrapper">

      <div class="admin-title">
      <div class="row">
       <?php $this->load->view('header.php'); ?>
      </div>
    </div>
        
     <div class="content-area">
      <div class="row">
       
          <div class="admin-menu">
            <?php $this->load->view('sidebar.php'); ?>
          </div>
         <div class="content-menu">
              <ul class="nav nav-tabs">
             <li class="page-header <?php echo $tabactv; ?>"><a  href="<?php echo base_url().'expense/trash/' ?>">All Trash</a></li>
                <?php
                $type=$this->db->query("select * from expense_type where buisness_type='$b_type' 
                 and status=1 ");
                $data='';
                foreach ($type->result() as $key => $type){
                  $data=$type->id;
                  $type=$type->type;
                     if($data==$tabsearch ){
                     $active='active';   
                    }
                    else{
                        $active='';
                    }
                  echo '<li class="page-header '.$active.'"><a   href="'.base_url().'expense/trash/'.$data.'">'. ucfirst($type).'</a> </li>';
                }
                ?>
              </ul>
            
            </div>
         <div class="panel-heading headingnone">
              <h2 class="transac">Expense Trash</h2>
              
            </div>
          <div class="main-content">
            
            
            
             <form method="post" action="<?php echo site_url('expense/trash/'.$tabsearch.'');?>">
              <div  class="input dashboard-input" style="padding-top: 83px;">
                <label>From<input class="form-control" id="from" type="date" name="from" value="<?php echo $from ; ?>">
                </label>
                <label>To<input class="form-control" id="to" type="date" name="to" value="<?php echo $to ; ?>">
                </label>
                <button type="submit" id="submit" class="btn btn-default" >
                  <span class="glyphicon glyphicon-search"></span> Search
                </button>
               
              </div>
              <div id="status-area" class="f-message" style="display:none; background: #2fffea;" ></div>
            </form>
            <!-- /.panel-heading -->
           
            <div class="panel-body " id="printableArea" >

              <div class="tab-content">

                <div id="home" class="tab-pane fade in active">


                  <table width="100%" class="table table-striped table-bordered table-hover mytable" id="dataTables-example">
                               
                                <thead>
                                    <tr>
                       <th><p><label><input type="checkbox" id="checkAll" name="check_list[]"/> </label></p></th>
                        <th>DATE</th>
                        <th>TYPE</th>
                        <th>CASH PAY</th>
                      
                        <th>cHEQUE PAY</th>
                        <th>TOTAL</th>
                        <th>ACTION</th>
                        </tr>
                               <input class="savebtn btn btn-danger" id="reset" type="submit" onclick="exmycheck()" value="Delete all"/>
                                </thead>
                                <tbody>
                                    <?php
                  
                    
                                   $cash=0.0;
                                    $card=0.0;
                                    $tr=0.0;
                                    $total=0.0;
                                    $k=1;
                                    for ($i = 0; $i < count($deptlist); ++$i) {
                                        $value=(unserialize($deptlist[$i]->bank_info));
                                        
                                    ?>
                                       <tr class="delete_mem<?php echo $deptlist[$i]->id; ?>">
                              <td><input type="checkbox"  id="chk" name="selected_item" value="<?php echo  $deptlist[$i]->id; ?>" /></td>
                              <td><?php echo  date('d F Y',strtotime($deptlist[$i]->date)); ?></td>
                              <td><?php echo ucfirst($deptlist[$i]->expensetype); ?></td>
                              <td><?php echo number_format($value[$cashbank],2) ; ?>€</td>
                              
                              <td class="center"><?php echo number_format($deptlist[$i]->total-$value[$cashbank],2); ?>€</td>
                              <td class="center"><?php echo  number_format($deptlist[$i]->total,2); ?>€</td>
                                       
                                       
                                        <td class="action type-center"><a class="btn edit" onclick="mytrash(<?php echo $deptlist[$i]->id;?>)" >recover</a> <a id="printpagebutton" class="btn btn-danger btn-xs" onclick="myFunction(<?php echo $deptlist[$i]->id;?>)" >Delete</a></td>
                                        
                                    </tr>
                                       <?php
            
                                     
                                       
                                    }
                       
                          ?>
                             
                           
                        
                       
                               
                                </tbody>
                            </table>
                    </div>
                       
                      </div>
                    </div>

         

     
      <div class="pagi" style ="float:right;">
           <?php echo $this->pagination->create_links(); ?>   
          </div>
                  </div>
           
              </div>
            </div>
    

    </div>
     <?php $this->load->view('footer.php'); ?>

  
    
  <script type="text/javascript" src="<?= base_url() ?>assets/admin/js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?= base_url() ?>assets/admin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?= base_url() ?>assets/admin/js/my.js"></script>
<script type="text/javascript" src="<?= base_url() ?>assets/admin/js/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>
     <script>
function myFunction(ref) {
    
swal({
          
  title: "Are you sure?",
  text: "Your will not be able to recover this data again!",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
              var datastr=ref;
     
        //var datastr='ref='+ encodeURIComponent(ref)
       
            $.ajax({
            url: "<?php echo base_url()?>expense/trash_delete", 
            type: "POST",
            data    : {'uristring':datastr},
           success: function(data){
    
    
      
  }
        });
  swal("Deleted!", "Your data has been deleted.", "success");
          $(".delete_mem" + ref).fadeOut('slow');
    
});
  
    }

    </script>
    
    <script>
        function mytrash(ref) {
           swal({
          
  title: "Are you sure?",
  text: "Your want to recover this data!",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, recover it!",
  closeOnConfirm: false
},
function(){
              var datastr=ref;
     
        //var datastr='ref='+ encodeURIComponent(ref)
       
            $.ajax({
            url: "<?php echo base_url()?>expense/trash_recover", 
            type: "POST",
            data    : {'uristring':datastr},
           success: function(data){
    
    
      
  }
        });
  swal("Deleted!", "Your data has been recovered.", "success");
          $(".delete_mem" + ref).fadeOut('slow');
    
});
        }
    </script>
 

  <script>
   function myexpenseFunction(ref) {
                var datastr=ref;
     
            $.ajax({
            url: "<?php echo base_url()?>expense/trash_delete", 
            type: "POST",
            data    : {'uristring':datastr},
                 dataType: 'json',
            success: function(data){
            $(".delete_mem" + ref).fadeOut('slow');
                $('#cash').text(data.cash +'€');
               $('#totalbank').text(data.bank +'€');
                $('#totalticket').text(data.ticket +'€');
                $('#totalsale').text(data.total +'€');
      
            }
        });    
}
            
</script>
<script>
      function exmycheck() {
          $('#reset').click(function () {
    if (!$('#chk').is(':checked')) {
        swal({
          title: "Please Select a Record Only!",
         
          type: "warning",
         
          confirmButtonText: 'ok!'
        });
        return false;
    }
               else{
                   swal({
          title: "Are you sure?",
          text: "Your will not be able to recover this data again!",
          type: "warning",
          showCancelButton: true,
          confirmButtonClass: 'btn-danger',
          confirmButtonText: 'Yes, delete it!',
          closeOnConfirm: false,
          //closeOnCancel: false
        },
        function(){
                                                     var fav = [];
 $.each($("input[name='selected_item']:checked"), function(){ 
     
     
     
   myexpenseFunction($(this).val());
    //fav.push($(this).val());
     
 //alert(fav);
 
}); 
          swal("Deleted!", "Your data has been deleted!", "success");
                       
        });
                   
  
                   
               }   
 
          
});
     
    }
    </script>
</body>

</html>
