<?php $__env->startSection('title','Purchase Order'); ?>
<?php $__env->startSection('css'); ?>
    <style>
        @media  print{
            .no-print{
                display:non;
            }
        }
    </style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.css">

    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">

            </div>
        </div><!-- /.container-fluid -->
    </section>
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Purchase Order</h1>
                </div>
                <div class="col-sm-6">
                    <button onclick="window.open('<?php echo e(url('Inventory/print-po-no')); ?>','_blank')" style="float: right" class="btn btn-primary"><i class="fa fa-print"></i> Print</button>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="col-lg-12">
            <div class="card"><br>
                <div class="card-body">

                    <div class="row">
                        <div class="form-group col-md-3">
                            <input type="text" id="purchase_no" onkeyup="myTableSearch('purchase')" class="form-control" name="style" placeholder="Enter Purchase No">
                        </div>
                        <div class="form-group col-md-3">
                            <input type="text" id="requistion_no" onkeyup="myTableSearch('requisition')" class="form-control" name="style" placeholder="Enter Requisition No">
                        </div>
                        <div class="col-lg-12 table-responsive">

                            <div class="table-responsive">

                                <table class="table table-hover table-striped table-bordered text-center" id="myTable">
                                    <thead>
                                        <tr class="bg-info">
                                            <td> #SL</td>
                                            <td> Purchased No</td>
                                            <td> Requisition No</td>
                                            
                                            <td> Authorized By</td>
                                            <td> Date & Time</td>
                                            <td> Ordered Duration </td>
                                            <td class="no-print"> Action </td>
                                        </tr>
                                    </thead>

                                    <tbody class="bodyItem" id="requisition_items">
                                    <?php if($purchases->count()>0): ?>
                                        <?php $__currentLoopData = $purchases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $purchase): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            
                                            <tr id="tr-<?php echo e($purchase->id); ?>">
                                                
                                                <td><?php echo e($key + 1); ?></td>
                                                <td> <?php echo e($purchase->purchase_no); ?> </td>
                                                <td> <?php echo e($purchase->new_requisition ? $purchase->new_requisition->requisition->requisition_id : null); ?> </td>
                                                
                                                <td class="text-center"> <label class="badge badge-success"> <?php echo e($purchase->user? $purchase->user->name :''); ?> </label> </td>
                                                <td> <?php echo e(\Carbon\Carbon::parse($purchase->created_at)->format('d-M-Y -- h:i:s A')); ?> </td>
                                                <td> <?php echo e($purchase->created_at->diffForHumans()); ?> </td>
                                                <td class="no-print">
                                                    <a href="<?php echo e(route('inventory.purchase.mail',$purchase->id)); ?>" class="btn btn-info"><i class="fa fa-envelope"></i> Mail</a>

                                                    <a href="<?php echo e(route('inventory.purchase.print',$purchase->id)); ?>"  class="btn btn-info"><i class="fa fa-info-circle"></i> Details</a>
                                                    <?php if(Auth::id() == 28): ?>
                                                        <?php if($purchase->mrr_status == 0): ?>
                                                            <button onclick="Delete('<?php echo e($purchase->id); ?>')" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</button>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                    
                                                    
                                                </td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php else: ?>
                                        <tr>
                                            <td colspan="12" class=" bg-danger text-center"> No Purchase Record found</td>
                                        </tr>
                                    <?php endif; ?>
                                    </tbody>
                                </table>
                                
                                <br>
                                <br>
                                <br>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->

<?php $__env->stopSection(); ?>

<?php $__env->startSection('style'); ?>
    <!-- DataTables -->
    
<?php $__env->stopSection(); ?>

<?php $__env->startSection('plugin_for_datatable_buttons'); ?>
    
<?php $__env->stopSection(); ?>
<?php $__env->startSection('plugin'); ?>
    <!-- DataTables -->
    <script src="<?php echo e(asset('plugins/datatables/dataTables.bootstrap4.js')); ?>"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <!-- page script -->
    <script type="text/javascript">

        $(document).ready(function () {
            window.setTimeout(function() {
                $(".alert").slideUp(1000, function(){
                    $(this).remove();
                });
            }, 1200);

        });


        function myTableSearch(index) {
          // Declare variables 
          var input, filter, table, tr, i, j, column_length, count_td, null_tr = 0;
          column_length = document.getElementById('myTable').rows[0].cells.length;
          input = index == 'purchase' ? document.getElementById("purchase_no") : document.getElementById("requistion_no");
          filter = input.value.toUpperCase();
          
          j = index == 'purchase' ? 1 : 2;
          table = document.getElementById("myTable");
          tr = table.getElementsByTagName("tr");
          for (i = 1; i < tr.length; i++) { // except first(heading) row
            count_td = 0;
            // for(j = 1; j < column_length-1; j++){ // except first column
                td = tr[i].getElementsByTagName("td")[j];
                /* ADD columns here that you want you to filter to be used on */
                if (td) {
                  if ( td.innerHTML.toUpperCase().indexOf(filter) > -1)  {            
                    count_td++;
                  }
                }
            // }
            console.log(count_td)
            if(count_td > 0){
                tr[i].style.display = "";
            } else {
                null_tr++;
                tr[i].style.display = "none";
            }
          }
          
        }

      function Delete(id) {
        $.confirm({
            title: 'Confirm!',
            content: '<hr><strong class="text-danger">Are you sure to delete ?</strong><hr>',
            buttons: {
                confirm: function () {
                    $.ajax({
                      headers: { 'X-CSRF-TOKEN' : '<?php echo e(csrf_token()); ?>' },
                      url: "<?php echo e(url('Inventory/delete-purchase-summary')); ?>/"+id,
                      type: 'DELETE',
                      dataType: 'json',
                      data: {},
                      success:function(response) {
                        if(response.success){
                          $('#tr-'+id).fadeOut();
                        }else{
                          $.alert({
                            title:"Whoops!",
                            content:"<hr><strong class='text-danger'>Something Went Wrong!</strong><hr>",
                            type:"red"
                          });
                        }
                      }
                    });
                },
                cancel: function () {

                }
            }
        });   
      }
    </script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.fixed', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/welluugs/purchase.wellgrouperp.com/resources/views/inventory/purchase/summary-purchase.blade.php ENDPATH**/ ?>