<?php

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

?>
<!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><a class="btn-menu"  href="<?php echo base_url('invoice/create');?>">New Invoice</a></li>
          <li><a class="btn-menu"  href="<?php echo base_url('invoice/details');?>">All Invoice</a></li> 
               
              </ul>
           
            </div>
              <div class="panel-heading headingnone">
              <h2 class="transac">All Trash Invoice</h2>
           
            </div>
          <div class="main-content">
           
          
           
         
            <div class="panel-body " id="printableArea" >
              <div class="tab-content">
                <div id="home" >
                  <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>Company Name</th>
                        <th>Invoice Number</th>
                       <th>Total</th>
                        
                        <th class="ac">ACTION</th>
                      </tr>
                      <input class="savebtn btn btn-danger" id="reset" type="submit" onclick="dmycheck()" value="Delete all"/>
                    </thead>
                    <tbody>
                      <?php
                    
                 
                        for ($i = 0; $i < count($invoice_detail); ++$i)     
                          { 
                      ?>
                            <tr class="delete_mem<?php echo $invoice_detail[$i]->id; ?>">
                              <td class="ac"><input type="checkbox"  class="chk" name="selected_item" value="<?php echo  $invoice_detail[$i]->id; ?>" /></td>
                              <td class="ac"><?php echo date('d F Y',strtotime($invoice_detail[$i]->invoice_date)) ; ?></td>
                                 <td class="ac"><?php echo $invoice_detail[$i]->company_name; ?></td>
                              <td class="ac"><?php echo $invoice_detail[$i]->invoice_id; ?></td>
                             
                              <td class="ac"><?php echo number_format($invoice_detail[$i]->total,2);  ?>&nbsp;€</td>
                              <td class="ac"><a class="btn" href="<?php echo base_url('invoice/pdfview/'.$invoice_detail[$i]->id);?>" target="_blank" >View Pdf</a><a class="btn edit" href="<?php echo base_url('invoice/edit/'.$invoice_detail[$i]->id);?>" >Edit</a> <a id="printpagebutton" class="btn  btn-xs" onclick="deleteFunction(<?php echo $invoice_detail[$i]->id;?>)" >Recover</a></td>  
                            </tr>
                                 
                           
                         
                         <?php  }?>
                          
                       
                        </tbody>
                      </table>
                    </div>
                   
                      </div>
                    </div>
                    
                   
                     
            
                  </div>
             
              </div>
            </div>
          </div>
          <div class="pagi" >
           <?php //echo $pagination_link;?>   
          </div>
          
          <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 src="https://code.jquery.com/jquery-1.9.1.js"></script>
          <script>
      function deleteFunction(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;
     
            $.ajax({
            url: "<?php echo base_url()?>invoice/recover", 
            type: "POST",
            dataType: 'json',
            data    : {'uristring':datastr},
               
           success: function(data){
               
        
                
  }
        });
  swal("Deleted!", "Your data has been recovered.", "success");
         $(".delete_mem" +ref).fadeOut('slow');
           //$('#totalcash').val(data.cash);
           
           
    
});
 }
    </script>
     <script>
     function dmycheck() {
          $('#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,
        },
        function(){
                                                     var fav = [];
 $.each($("input[name='selected_item']:checked"), function(){ 
          
   myFunction($(this).val());

 
}); 
          swal("Deleted!", "Your data has been deleted!", "success");
                       
        });
                           
               }       
});
     
    }

    </script>
        <script>
   function myFunction(ref) {
                var datastr=ref;
     
            $.ajax({
            url: "<?php echo base_url()?>invoice/perdelete", 
            type: "POST",
            data    : {'uristring':datastr},
                 dataType: 'json',
            success: function(data){
            $(".delete_mem" + ref).fadeOut('slow');
               
      
            }
        });    
}
            
</script>
</body>
</html>