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

  }
if($tabsearch ){
     
     $tabactv='';
     
 }
else{
   
  $tabactv='active';
   $tabsearch='';   
}
?>

<!DOCTYPE html>
<html lang="en">

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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().'purchases/trash' ?>">All Purchases Trash</a></li>
               
                <?php
                $type=$this->db->query("select * from purchases_type where  buisness_type='$b_type'  
                 and status=1 ");
                $data='';
//$type='';
                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 style="'.$background.'"   href="'.base_url().'purchases/trash/'.$data.'">'. ucfirst($type).'</a> </li>';

                }
                ?>
                </ul>
        
                </div>
          <div class="panel-heading headingnone">
              <h2 class="transac">Purchase Trash</h2> 
            <div class="panel panel-success neworder">
          
            
            </div> 
            </div> 
          <div class="main-content">
           
            
              

            <!-- /.panel-heading -->
            <form method="post" action="<?php echo site_url('purchases/trash/'.$tabsearch.'');?>">
              <div  class="input dashboard-input" style="padding-top: 83px;">
                <label>From
                <input class="form-control" type="date" name="from" id="from" value="<?php echo $from ?>"></label>

                <label>To
                <input class="form-control" type="date" name="to" id="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 class="action_btn dashboard-actbtn" >
                 

                

                  <button class="p-btn" title="Print" onclick="printDiv('printableArea')" value="Print Invoice" data-toggle="tooltip"><span class="glyphicon glyphicon-print"></span></button>
                      
                </div> 
              <div id="status-area" class="f-message" style="display:none; background: #2fffea;" ></div>

            </form>

            <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>CATEGORY</th>
                        <th>INVOICE</th>
                        <th>TOTAL ORDERS</th>
                        <th style="text-align: left;">PAY TYPE</th>
                        <th>PAY TOTAL</th>
                        
                        <th>DUE BALANCE</th>
                        
                       
                        <th class="ac">ACTION</th>
                        
                      </tr>
                       <input class="savebtn btn btn-danger" id="reset" type="submit" onclick="myallcheck()" value="Delete all"/>
                    </thead>
                    <tbody>

                      <?php
                       
                      
                           $pay=0.0;
                          $order=0.0;
                          $due=0.0;
                          $due_pay=0.0;
                        for ($i = 0; $i < count($deptlist); ++$i) 

                          { ?>


                            <tr class="delete_mem<?php echo $deptlist[$i]->id; ?>">

                              <td class="ac"><input type="checkbox"  class="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]->purchases_type); ?></td>
                               <td class="center"><?php echo  ($deptlist[$i]->invoice_number); ?></td>
                               <td class="center"><?php echo number_format($deptlist[$i]->total_order, 2); ?>€</td>
                             <td style="text-align: left;"><?php echo ucfirst($deptlist[$i]->pay_type) ; ?></td>
                             
                              <td class="center"><?php echo  number_format($deptlist[$i]->pay_total, 2); ?>€</td>
                              
                              <td class="center"><?php echo  number_format($deptlist[$i]->due_balance, 2); ?>€</td>
                                
                                 
                              <td class="ac"><a class="btn ac"  data-toggle="modal" data-target="#myModal"  onclick="mytrash(<?php echo $deptlist[$i]->id;?>)">Recover</a> <a  class="btn btn-danger btn-xs ac" onclick="mytrashFunction(<?php echo $deptlist[$i]->id;?>)" >Remove</a></td>

                            </tr>
                             <?php
                        
                       
                         
                                    
                                    
                                   
                           $pay+=$deptlist[$i]->pay_total;
                            $order+=$deptlist[$i]->total_order;
                            $due+=$deptlist[$i]->due_balance;
                               $due_pay+=$deptlist[$i]->due_pay;        
                                      
                        $due_balance=$due_pay+$due;
                       
                          ?>
                            
                            <?php }?>
                       
                        </tbody>
                      </table>







                    </div>
                    <!--   bank tab-->
                     
                     


                    <!-- end-->

                 
            </div>
          <div class="pagi" style ="float:right;">
           <?php echo $this->pagination->create_links(); ?>   
          </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 mytrashFunction(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;
            $.ajax({
            url: "<?php echo base_url()?>purchases/trash_delete", 
            type: "POST",
            data    : {'uristring':datastr},
           success: function(data){
    
    
      
  }
        });
  swal("Deleted!", "Your data has been deleted.", "success");
          $(".delete_mem" + ref).fadeOut('slow');
    
});
  
      // alert(ref);
       
      
 
    }

    </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()?>purchases/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 myallcheck() {
          $('#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(){ 
     
     
     
   myFunction($(this).val());
    //fav.push($(this).val());
     
 //alert(fav);
 
}); 
          swal("Deleted!", "Your data has been deleted!", "success");
                       
        });
                   
  
                   
               }   
 
          
});
     
    }
    </script>
       <script>
            function myFunction(ref) {
                var datastr=ref;
       
            $.ajax({
            url: "<?php echo base_url()?>purchases/trash_delete", 
            type: "POST",
            dataType: 'json',
            data    : {'uristring':datastr},
            success: function(data){
            $(".delete_mem" + ref).fadeOut('slow');
                $('#pay').text(data.cash +'€');
               $('#order').text(data.bank +'€');
                $('#due').text(data.ticket +'€');
               
            }
        });    
}
</script>

</body>

</html>
