

<?php $__env->startSection('title'); ?>
Pending CS Approvals
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
<ol class="breadcrumb pull-right">
        <li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">CS Approval Pending</li>
      </ol>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('css'); ?>
 <link href="<?php echo e(asset('css/procurement_css.css')); ?>" rel="stylesheet">
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
    <div class="row">

    <div class="col-sm-12">
    <div class="white-box">


    <h3 style="text-align: right;" class="box-title m-b-5">
    <span style="float: left;    margin-bottom: 2rem;">Purchase Orders Approval Pending </span>
    </h3>

      <table id="myTable" class="table table-striped table-bordered dataTable color-table primary-table" role="grid" aria-describedby="myTable_info">
                <thead>
                <tr role="row">
                <th style="color:black;" class="sorting_asc" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Name: activate to sort column descending" style="width: 10px;">Id#</th>

                <th style="color:black;" class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 203px;">Department</th>


                <th style="color:black;" class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 100px;">Created By</th>


                <th style="color:black;" class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 150px;">Current Status</th>



                <th style="color:black;" class="sorting" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 200px;">Action</th>

                </tr>
                </thead>
                <tbody>
  
                   
                    <?php $__currentLoopData = $approval_pending_cs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                    $poid = 0; 
                    ?>
                    <?php $__currentLoopData = $list->cs_approval_status; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $po_id): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                      $poid = $po_id->purchase_order_id;
                    ?>
                     <tr role="row" class="odd">

                        <td>PR-<?php echo e($list->id); ?> 
                       
                      </td>


                    <td><?php echo e(\App\Department::withTrashed()->find($list->department_id)->department_name); ?>  </td>
                      <td><?php echo e($list->user->name); ?> </td>


                    <td>
                    <?php if($list->status == 0): ?>
                    <span style="color:#eab800;">Pending</span>
                    <?php elseif($list->status == 1): ?>
                    <span style="color:#ffbd02;">Approvals In Progress</span>
                    <?php elseif($list->status == 2): ?>
                    <span style="color:red;">Rejected</span>
                    <?php elseif($list->status == 3): ?>
                    <span style="color:#0d6efd;">RFQ</span>
                    <?php elseif($list->status == 4): ?>
                    <span style="color:#0d6efd;"><a target="_blank" href="<?php echo e(route('request-for-quotations.view' , [$list->id])); ?>">RFQ SEND</a></span>
                    <?php elseif($list->status == 5): ?>
                    <span style="color:#0d6efd;"><a target="_blank" href="<?php echo e(route('comparative-statements.view' , [$list->id])); ?>">CS Received</a></span>
                    <?php elseif($list->status == 6): ?>
                    <span style="color:#0d6efd;"><a target="_blank" href="<?php echo e(route('purchase-orders.view' , [$list->id])); ?>">PO Sent</a></span>
                    <?php elseif($list->status == 7): ?>
                    <?php
                    $getPrStatus = \App\PurchaseRequest::getPrStatus($list->id);
                    ?>


                    <?php if( $getPrStatus['pending_po'] > 0): ?>
                    <span style="color:#0d6efd;"><a style="font-size: 12px;" target="_blank" href="<?php echo e(route('purchase-orders.view' , [$list->id])); ?>">PO PENDING</a> <span style="padding: 0px 5px 0px 5px;border-radius: 50%;color: white;position: relative;bottom: 15px;background: red;"><?php echo e($getPrStatus['pending_po']); ?></span></span>
                    <?php elseif( $getPrStatus['pending_recipt'] > 0): ?>
                    <span style="color:#0d6efd;"><a  style="font-size: 12px;" target="_blank" href="<?php echo e(route('purchase-order-receipts.view' , [$list->id])); ?>">RECEIPT PENDING</a><span style="padding: 0px 5px 0px 5px;border-radius: 50%;color: white;position: relative;bottom: 15px;background: red;"><?php echo e($getPrStatus['pending_recipt']); ?></span></span>

                    <?php elseif($getPrStatus['total_rfq'] > $getPrStatus['total_cs']): ?>
                    <span style="color:#0d6efd;font-size: 12px;"><a target="_blank" href="<?php echo e(route('request-for-quotations.view' , [$list->id])); ?>">CS PENDING</a><span style="padding: 0px 5px 0px 5px;border-radius: 50%;color: white;position: relative;bottom: 15px;background: red;"><?php echo e($getPrStatus['total_rfq'] - $getPrStatus['total_cs']); ?></span></span>
                    <?php else: ?>
                    <span style="color:#0ef30e;">Complete</span>
                    <?php endif; ?>

                    <?php endif; ?>
                    </td>

                    
                    <td>
                    <a href="<?php echo e(route('comparative-statements-view-approval-pending', ['view' => $list->id,'user'=> $role_id , 'po' => $poid ])); ?>" target="_blank" class="btn btn-warning btn-xs" >View</a>
                    
                    <form method="POST" style="display: inline;" action="<?php echo e(route('purchase-order-approvals.change-cs-status')); ?>"  id="pr_approval_form_<?php echo e($list->id); ?>">
                    <?php echo e(csrf_field()); ?>

                    <input type="hidden" name="role_id" id="role_id" value="<?php echo e($role_id); ?>">
                    <input type="hidden" name="purchase_request_id" id="purchase_request_id" value="<?php echo e($list->id); ?>">
                    <input type="hidden" name="purchase_order_id" id="purchase_order_id" value="<?php echo e($poid); ?>">
                    <button type="submit" name="status" class="btn btn-success btn-xs" value="approve">Approved</button>
                    </form>

                    <a href="<?php echo e(route('purchase-orders.cancel' , [$poid])); ?>" onclick="return validate(this)" class="btn btn-danger btn-xs" >Cancel</a> 

                    </td>
                    </tr>
                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>   
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 


                </tbody>
                </table>




    </div>
    </div>
    </div>


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

<?php $__env->startSection('js'); ?>  
<script src="<?php echo e(asset('pusher/pusher.min.js')); ?>"></script>

<script type="text/javascript">
 // Enable pusher logging - don't include this in production
  Pusher.logToConsole = false;
  var pusher = new Pusher('<?php echo e(env('PUSHER_APP_KEY')); ?>' , {
  cluster: '<?php echo e(env('PUSHER_APP_CLUSTER')); ?>'
  });
  var channel = pusher.subscribe('approval-channel');
  channel.bind('<?php echo e($role_id); ?>', function(data) 
    {   
    
     getPoData();
     playSound("<?php echo e(url('bell/bell.mp3')); ?>");
  });   


function getPoData() 
{
  var role_id = '<?php echo e($role_id); ?>';
  $.ajaxSetup({
        headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
        });
        $.ajax({
        url:"<?php echo e(route('purchase-orders.get-latest-po-for-approval')); ?>",
        method:'POST',
        dataType:'json',
        data: {role_id:role_id },
        success:function(data)
        {

            if (data.total > 0) 
            {
                var output = '';

                $.each(data.response, function(key, value) 
                {
                    output += '<tr>';
                    output += '<td>PR-'+value.id+'</td>';
                    output += '<td>'+value.department+'</td>';
                    output += '<td>'+value.created_by+'</td>';
                    output += '<td>'+value.action+'</td>';
                    output += '</tr> ';
                });

            }
            else
            {
               var output = '<tr><td><center>No data found</center></td></tr>';
             }

             $('#pr-appro-tbl-body').html(output)

          }
        })
            

 return false;
}



function playSound(soundFile)         
{               
  var audioElement = document.createElement('audio');   
  audioElement.setAttribute('src', soundFile);   
  audioElement.play(); 
}



    function validate()
    { 
        if(!confirm('Are you sure you want to reject this Pr?'))
        {
            return false;
        } 
    }
</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\akram-city.projecterp.net\resources\views/procurement/approval-pending/cs-approval-pending.blade.php ENDPATH**/ ?>