<?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 Invoice</h2>
           
            </div>
          <div class="main-content">
          
           
           
           <button class="p-btn" title="Trash" data-toggle="tooltip" style="margin-top: 16px; float:right;    margin-right: 43px;" onclick="window.location='<?php echo site_url("invoice/trash");?>'"><span class="glyphicon glyphicon-trash"></span></button>
            <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 class="total">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
                    $total=0.0;
                // print_r($invoice_detail);
                        for ($i = 0; $i < count($invoice_detail); ++$i)     
                          { 
                            $total+=$invoice_detail[$i]->total;
                      ?>
                           
                            <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 title="Pdf" href="<?php echo base_url('invoice/pdfview/'.$invoice_detail[$i]->id);?>" target="_blank" ><i class="fa fa-file-pdf-o in-pdf"></i></a><a class="btn edit" href="<?php echo base_url('invoice/edit/'.$invoice_detail[$i]->id);?>" >Edit</a> <a id="printpagebutton" class="btn btn-danger btn-xs" onclick="deleteFunction(<?php echo $invoice_detail[$i]->id;?>)" >Delete</a></td>  
                            </tr>
                                 
                           
                         
                         <?php  }?>
                          
                        <tr class="total-value">
                            <td class="ac">
                            </td>
                            <td></td>
                            <td></td>
                            
                            <td class="total-val">Total</td>
                            
                            <td id="cash" class="total"><?php echo number_format($total,2) ;?>&nbsp;€</td>
                            
                            <td class="ac"></td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                   
                      </div>
                    </div>
                    
                   
                     
            
                  </div>
            
              </div>
            </div>
            <div class="pagi" >
           <?php echo $pagination;?>   
          </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 src="https://code.jquery.com/jquery-1.9.1.js"></script>
          <script>
      function deleteFunction(ref) {
        
        swal({
          
  title: "Are you sure?",
  text: "You will be able to recover the data from trash!",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
              var datastr=ref;
     
            $.ajax({
            url: "<?php echo base_url()?>invoice/delete", 
            type: "POST",
            dataType: 'json',
            data    : {'uristring':datastr},
               
           success: function(data){
               
        
                
  }
        });
  swal("Deleted!", "Your data has been deleted.", "success");
         $(".delete_mem" +ref).fadeOut('slow');
           //$('#totalcash').val(data.cash);
           $('#wrapper').load(location.href +'#dataTables-example' );
           
    
});
 }
    </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: "You will be able to recover the data from trash!",
          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/delete", 
            type: "POST",
            data    : {'uristring':datastr},
                 dataType: 'json',
            success: function(data){
            $(".delete_mem" + ref).fadeOut('slow');
                
            }
        });    
}
            
</script>
</body>
</html>