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

                        
?>
<?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;

  }
?>
<!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 active" ><a data-toggle="tab" href="#home">All Trash</a></li>
                
              </ul>
                <div class="panel-heading headingnone">
              <h2 class="transac">Balance Transfer</h2>
              
            </div>
            </div>
          <div class="main-content">
           
            
        
            <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 class="ac"><p><label><input type="checkbox" id="checkAll" name="check_list[]"/> </label></p></th>
                        <th>DATE</th>
                        <th>FROM</th>
                        <th>AMOUNT</th>
                      
                        <th>TO</th>
                        <th>TOTAL</th>
                        <th class="ac">ACTION</th>
                      </tr>
                    
                      <input class="savebtn btn btn-danger" id="reset" type="submit" onclick="exmycheck()" value="Delete all"/>
                    </thead>
                    <tbody id="result">
                      <?php
                      if($from AND $to){
                          $cash=0.0;
                                    $card=0.0;
                                    $tr=0.0;
                                    $total=0.0;
                          $cheque=0.0;
                        $query=$this->db->query("select * from transfer where (date BETWEEN '".$from."' AND '".$to."' ) and  status=0 and buisness_type='$b_type' ORDER BY `id` 
                         LIMIT ".$limit." ");
                        foreach ($query->result() as $key => $value){
                            $id=$value->id;
                            
                                    $cash+=$value->cash_pay;
                                       $card+=$value->bank_card;
                                        $cheque+=$value->cheque_pay;
                                       $total+=$value->total;
                            
                          echo '  <tr class="delete_mem'.$value->id.' ?>">
                          <td class="ac">'.'<input type="checkbox" id="chk" name="selected_item" value="'.$value->id.'" />'.'</td>
                          <td>'. date('d F,Y',strtotime($value->date)).'</td>
                          <td>'. ucfirst($value->bank_from).'</td>
                          <td>'. number_format($value->amount,2).'€'.'</td>
                          <td class="center">'. number_format($value->bank_to,2).'€'.'</td>
                          
                          <td class="center">'. number_format($value->total,2).'€'.'</td>
                          <td class="ac"><a class="btn edit" data-toggle="modal" data-target="#myModal"  onclick="mytrash('.$id.')">Edit</a> <a class="btn btn-danger btn-xs" onclick="myexpenseFunction('.$id.')" >Delete</a></td>
                          </tr>';
                        }
                         
                        
                      } 
                      else {
                                   $cash=0.0;
                                    $card=0.0;
                                    $tr=0.0;
                                    $total=0.0;
                        for ($i = 0; $i < count($deptlist); ++$i)     
                          { $value=(unserialize($deptlist[$i]->bank_info)); 
                        ?>
                           <div id="start">
                            <tr class="delete_mem<?php echo $deptlist[$i]->id; ?>">
                              <td class="ac"><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]->bank_from); ?></td>
                              <td ><?php echo number_format($deptlist[$i]->amount,2) ; ?>€</td>
                             
                              <td class="center ticket"><?php echo ucfirst($deptlist[$i]->bank_to); ?></td>
                              <td class="center total"><?php echo  number_format($deptlist[$i]->total,2); ?>&nbsp;€</td>
                              
                              <td class="ac"><a class="btn edit"  onclick="mytrash(<?php echo $deptlist[$i]->id;?>)">Recover</a> <a  class="btn btn-danger btn-xs" onclick="myexpenseFunction(<?php echo $deptlist[$i]->id;?>)" >Delete</a></td> 
                              
                            </tr>
                            </div>
                             <?php
            
                                    $amount+=$deptlist[$i]->amount;
                                      
                                       
                                    }
                       
                          ?>
                             
                            <?php }
                          ?>
                        
                        
                        </tbody>
                      </table>
                    </div>
                   
                      </div>
                    </div>
                    
                   
                     
               
                  </div>
               
              </div>
            </div>
          </div>
    <div class="pagi" style ="float:right;">
           <?php echo $this->pagination->create_links(); ?>   
          </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()?>Balance/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: "You 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()?>Balance/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()?>Balance/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>
