<?php $user_id=$this->session->userdata('user_id');

if(!$user_id){
  redirect('user/login_view', 'refresh');
}
?>
<?php
error_reporting(0);
$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 OR $tabpagi){
  
      $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().'user/trash/' ?>">All Sale Trash</a></li>
                 <?php
                $type=$this->db->query("select * from sale_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().'user/trash/'.$data.'">'. ucfirst($type).'</a> </li>';
                }
                ?>
                                </ul>
                      
                            </div>
                       <div class="panel-heading headingnone">
                                <h2 class="transac">Sale Trash</h2>
                                <!--<button class="transaction btn btn-success" onclick="add_transaction()"  data-toggle="modal" data-target="#myModal">New Transaction</button>-->
                            </div>
                        <div class="main-content">
                          
                            
                            <form method="post" action="<?php echo site_url('user/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 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>TYPE</th>

                                                    <?php  $type=$this->db->query("select * from bank_name  where  status=1 and record=1 
                                    and buisness_id='$b_type'  ");
                                   
                                    foreach ($type->result() as $key => $type){
                                      echo 
                                      '<th>'.ucfirst($type->type).'</th>';
                                    }
                                    ?>



                                                    <th>TOTAL</th>

                                                    <th class="ac">ACTION</th>
                                                </tr>
                                                <!--<button class="transaction btn btn-success" style="margin-top: -4px;" onclick="window.location='<?php //echo site_url("user/trash");?>'">[Trash]</button>-->
                                                <input class="savebtn btn btn-danger" id="reset" type="submit" onclick="dmycheck()" value="Delete all" />
                                            </thead>
                                            <tbody id="result">
                                                <?php
                 
                    
                        
                                   $cash=0.0;
                                    $card=0.0;
                                    $tr=0.0;
                                    $total=0.0;
                          //$value=(unserialize($deptlist->bank_info));
                         
                      for ($i = 0; $i < count($deptlist); ++$i) 
                           
                          { 
                       ?>
                           <div id="start">
                            <tr class="delete_mem<?php echo $deptlist[$i]->id; ?>">
                              <td class="ac"><input type="checkbox"  class="ac" 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]->saletype); ?></td>
                            
                             
                              
                                  
                             <?php  $type=$this->db->query("select * from bank_name  where status=1 
                                      and record=1 and buisness_id='$b_type'");
              
                                  $value=(unserialize($deptlist[$i]->bank_info));
          
                                  //print_r($value);
                                    foreach ($type->result() as $key => $type){
                                       
                                    //echo $type->id;
                                        if($value[$type->id]){
                                      //foreach ($value as $key => $bankval) 
                            
                                       //{ 
                                           
                                        //if($type->id==$key){
      
                                            echo '<td>'.number_format($value[$type->id],2).' €'.'</td>';
                                            $sum[$type->id]+=($value[$type->id]);
                                         //}
                                        
                                           
                                         
        
                                     // } 
                                        }
                                    else{
                                         echo '<td>0.00 €</td>';
                                        $sum[$type->id]+=0.0;
                                    }
                                        
                                    }
                         
                                    
                                    ?>
                          
                              
                           
                                <td class="center ticket"><?php echo number_format($deptlist[$i]->total,2); ?>&nbsp;€</td>
                            
                              
                              <td class="ac"><a class="btn ac edit" data-toggle="modal" data-target="#myModal"  onclick="mytrash(<?php echo $deptlist[$i]->id;?>)">Recover</a> <a  class="btn ac btn-danger btn-xs" onclick="myFunction(<?php echo $deptlist[$i]->id;?>)" >Delete</a></td> 
                              
                            </tr>
                            </div>
                             <?php
            
                                    $cash+=$deptlist[$i]->cash_sale;
                                     
                                        $tr+=$deptlist[$i]->ticket;
                                         $total+=$deptlist[$i]->total;
                                       
                                    }
                       
                          ?>

                       

                                            </tbody>
                                        </table>
                                    </div>
                                   
                   
                            </div> 

                            <div>
                                <?php echo $pagination_link; ?>
                            </div>
                            <div class="pagi">

                            </div>
                            </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 page(value) {

                                    $('#pagelimit').val(value);
                                    $.ajax({
                                        url: "<?php echo base_url()?>user/pagelimit",
                                        type: "POST",
                                        data: {
                                            'limit': value
                                        },
                                        dataType: 'json',
                                        success: function(data) {
                                            $('#pagevalue').val(data.limit);
                                        }
                                    });
                                }
                            </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()?>user/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()?>user/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 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 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() {

                                                        allmyFunction($(this).val());


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

                                                });

                                        }
                                    });

                                }
                            </script>
                            <script>
                                function allmyFunction(ref) {
                                    var datastr = ref;

                                    $.ajax({
                                        url: "<?php echo base_url()?>user/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>
                            </script>


    </body>

    </html>