<link rel="stylesheet" href="https://cdn.datatables.net/1.13.1/css/dataTables.bootstrap5.min.css">
<style>
    .orderLists.newDesg .imgBoxs {
        height: 170px;
        object-fit: cover;
        width: 120px;
    }

    p.msg-sts {
        padding: 6px 10px !important;
    }

    button.submit-popup.create,
    button.submit-popup.createinpack.mt-3 {
        margin-top: 50px !important;
    }

    .main-popup-contents .rs-flex {
        width: 100%;
    }

    .main-popup-contents p {
        margin-bottom: 30px;
        font-weight: 600;
        font-size: 20px;
    }

    input#datepickerinproduction,
    #datepickerinpackage,
    #datepicker {
        border-radius: 30px;
    }

    span.no-d {
        display: none;
    }
</style>

<?php $__env->startSection('content'); ?>
    <?php $printId = 1; ?>
    <div class="common-content">
        <div class="page-content">
            <div class="page-heading">
                <div class="headings">
                    <h6>Purchase Order Summary</h6>
                    <input name="_token" type="hidden" id="token_po" value="<?php echo e(csrf_token()); ?>">
                </div>
            </div>
            <div class="dashboard-cnts">
                <div class="row">
                    <div class="col-12">
                        <div class="boxings po-sum noShadow" style="border-radius: 15px;">
                            <div class="tab-content meddbot-tabcontent">
                                <div id="home" class="tab-pane fade in active show">
                                    <?php if(count($po_productlist) != 0): ?>
                                        <?php $__currentLoopData = $po_productlist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $summary): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="purchase-order js-category-filterable"
                                                data-category="<?php echo $summary->individual_buyerid; ?>">
                                                <div class="O_id">
                                                    <?php if($summary->dispatch_to==2): ?>
                                                <div class="order-id d-flex justify-content-end">
                                                    <h4 class="batch" >Batch 
                                                    </h4>
                                                </div>
                                                <?php endif; ?>
                                                    <div class="order-id d-flex justify-content-end">
                                                    <h4>Order ID <span class="green-order"><?php echo e($summary->po_id); ?></span>
                                                        <input type="hidden" id="predispatch_inspection" name="predispatch_inspection" value="<?php echo e($predispatch_inspection); ?>">
                                                    </h4>
                                                </div>
                                                
                                                </div>
                                                <div class="product_details-grd">
                                                    <div class="product-image">
                                                        <?php if(!empty($summary->photo)): ?>
                                                            <img src="<?php echo e(url('product_files')); ?>/<?php echo e($summary->photo); ?>">
                                                        <?php else: ?>
                                                            <img
                                                                src="<?php echo e(url('assets/images/1200px-No-Image-Placeholder.svg.png')); ?>">
                                                        <?php endif; ?>
                                                    </div>
                                                    <div class="product-details">
                                                         <h4 class="product-name">
                                                                    <?php echo e(ucfirst($summary->product_name)); ?></h4>
                                                        <div class="po-pRdt-sum" >
                                                            <ul>
                                                           
                                                          
                                                            <li><label class="p-o-label">Product Code</label>:
                                                                <span><?php echo e($summary->product_code); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Delivery Days</label>:
                                                                <span><?php echo e($summary->delivery_days); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Quantity</label>:
                                                                <span><?php echo e($summary->quantity); ?></span>
                                                            </li>
                                                         
                                                        </ul>
                                                    <ul>
                                                           
                                                           
                                                           
                                                            <li><label class="p-o-label">Price per quantity</label>:
                                                                <span><?php echo e($summary->price); ?> INR</span>
                                                            </li>
                                                            <li><label class="p-o-label">Tax</label>:
                                                                <span><?php echo e($summary->tax); ?>%</span>
                                                            </li>
                                                            <li><label class="p-o-label">Total Price (Including
                                                                    tax)</label>:
                                                                <span><?php echo e(number_format(($summary->price + $summary->price * ($summary->tax / 100)) * $summary->quantity, 2)); ?>

                                                                    INR</span>
                                                            </li>
                                                        </ul>
                                                            
                                                        </div>
                                                         <div class="product-description">
                                                    <label class="p-o-label">Product Description</label>
                                                    <p><?php echo e($summary->product_description); ?></p>
                                                </div>
                                                       <div class="prdStatus" >
     
                                                <?php
                                                    $poproducts  			= App\Helpers\CustomHelper::product_status_list($summary->id);
                                                ?>
                                                <?php if($poproducts['register_pending']!=0): ?>
                                                <span><span style="color:red">Pending to Register</span>:<span style="color:red"><?php echo e($poproducts['register_pending']); ?></span></span>
                                                <?php else: ?>
                                                <span style="color:green">All Equipment Registration Completed</span>
                                                <?php endif; ?>
                                                <?php if($poproducts['dispatch_pending']!=0): ?>
                                                <span><span style="color:red">Pending to Dispatch</span>:<span style="color:red"><?php echo e($poproducts['dispatch_pending']); ?></span></span>
                                                <?php else: ?>
                                                <span style="color:green">All Equipment Dispatch Completed</span>
                                                <?php endif; ?>
                                                <?php if($predispatch_inspection==1): ?>
                                                <span style="color:orange">Pre-Dispatch inspection required</span>
                                                <?php endif; ?>
                                            </div> 
                                                    </div>
                                                </div>

                                                <?php
                                                    $pbgcount  			= App\Helpers\CustomHelper::pbgapprovecount($summary->po_id);
                                                ?>
                                                
                                            
                                <div class="product-description po-buttonGroup nW-btnGrp btn-grp-po">
                                                            
                                                                <button class="btn medd-buttons medd-blue rounded" onclick="openBarcodeModal([<?php $__currentLoopData = $summary->poProductDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> '<?php echo e($item->barcode); ?>', <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>])"><i class="fa fa-barcode" aria-hidden="true"></i> View Barcode</button>
                                                   
                                                  
                                                   
                                                        <?php if($pbgcount==1): ?>

                                                            <?php if($summary->require_pre_requisites==0): ?>
                                                                <button class="btn medd-buttons new-preq  px-3 py-2" style="background-color: red !important; color:#fff !important;" onclick="prerequisites(<?php echo e($summary->id); ?>,<?php echo e($summary->po_id); ?>,<?php echo e($summary->product_id); ?>)"><i class="fa fa-sort" aria-hidden="true"></i>Pre-Requisites Order</button>
                                                            <?php else: ?>
                                                            <?php $Date = $summary->delivery_date;
                                                            $date1  =date('d-m-Y', strtotime($Date. ' + 1 days'));?>

                                                            <?php if($summary->require_pre_requisites==2): ?>
                                                            <?php else: ?> 

                                                                <?php if($summary->requites_ready==0): ?>
                                                                <button class="btn medd-buttons px-3 py-2 new-preq" style="background-color:red !important; color:#fff !important;"   onclick="prerequisites_details(<?php echo e($summary->id); ?>,'<?php echo e($date1); ?>')"><i class="fa fa-list" aria-hidden="true"></i>Pre-Requisites Details</button>
                                                                <?php else: ?>
                                                                <button class="btn medd-buttons px-3 py-2 new-preq" style="background-color:green !important; color:#fff !important;"   onclick="prerequisites_details(<?php echo e($summary->id); ?>,'<?php echo e($date1); ?>')"><i class="fa fa-list" aria-hidden="true"></i>Pre-Requisites Details</button>

                                                                <?php endif; ?>
                                                            
                                                           <?php endif; ?>
                                                     <?php endif; ?>      
                                                            

                                                         <?php if(($pbgcount==1)): ?>

                                                         <?php if(($summary->require_pre_requisites==2)||($summary->require_pre_requisites==1)): ?>
                                                            

                                                         <?php if($poproducts['register_pending']!=0): ?>
                                                             <button class="btn medd-buttons medd-blue rounded" onclick="opensoldModal([<?php $__currentLoopData = $summary->poProductDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if($item->sold_approve==0): ?> '<?php echo e($item->barcode.'-'.$item->id); ?>',  <?php endif; ?>  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>])">Register Sold</button>
                                                         <?php endif; ?>
                                                             <button class="btn medd-buttons medd-blue rounded" onclick="openstatusModal(<?php echo e($summary->id); ?>,<?php echo e($summary->po_id); ?>,<?php echo e($summary->product_id); ?>)">Production Dispatch</button>
                                                             
                                                         <?php endif; ?>    
                                                         <?php endif; ?>

                                                             <button class="btn medd-buttons medd-blue rounded"
                                                                onclick="openEquipmentModal([<?php $__currentLoopData = $summary->poProductDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'<?php echo e($item->barcode.'-'.$item->id); ?>', <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>])">Equipment Details</button>

                                                            <?php endif; ?>
                                                            
                                                            
                                                        </div>
                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php else: ?>
                                        <div class="col-lg-12 col-md-6 col-sm-12 col-xs-12">
                                            <div class="product-display">
                                                <ul>
                                                    <li>
                                                        <div class="details">
                                                            <div>
                                                                <h6>
                                                                    No Products available
                                                                </h6>
                                                            </div>
                                                        </div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
 

            <div class="modal fade  new-modal" id="prerequie_details" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg cutom-modal">
                  <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                      </button>
                      <div class="purchase-order">
                                               
                                               <div class="product_details-grd custom">
                                                   <div class="product-details custom">
                                                      <h5 class="mb-3">Pre-Requisites Details</h5>
                                                       <ul class="custom-details pbg-details-pop" >
                                                           <li><label class="p-o-label">Tentative Date</label>: <span id="pre_tendate"></span></li>
                                                           <li><label class="p-o-label">Pre-Requisites</label>: <span id="pre_status"></span></li>
                                                           <li id="reqdetails"><label class="p-o-label">Pre-Requisites Items</label>: <span id="pre_items"></span></li>
                                                    
                                                        </ul>
                                                        
                                                        <div id="readyitems">

                                                        </div>

                                                       <div id="exdates" class="mt-3">
                                                            <form id="changedate" method="POST" action="<?php echo e(url('vendors/changedate')); ?>" enctype="multipart/form-data"> <?php echo csrf_field(); ?>
                                                            
                                                                <input type="hidden" class="form-control" name="po_products_id" id="po_products_id">
                                                                <input type="hidden" class="form-control" name="change_mainbuyerid" id="change_mainbuyerid">
                                                                <input type="hidden" class="form-control" name="change_product_id" id="change_product_id">
                                                                <input type="hidden" class="form-control" name="change_orderid" id="change_orderid">
                                                                
                                                                <div class="modal-content">
                                                                <div class="modal-body">
                                                                <div class="otp">
                                                                        <h5>Change Date</h5>
                                                                        <div class="row pbg-itms pb-2 align-items-end">
                                                                            <div class="col-lg-6">
                                                                                <div class="form-group">
                                                                                <label>Extension Date <sub>*</sub></label>
                                                                                <input type="text" class="form-control" name="delivery_date_edit" id="delivery_date_edit">
                                                                                </div>
                                                                            </div>
                                                                            <div class="col-lg-6">
                                                                                <div class="form-group">
                                                                                     <button class="exp-date-btn  btn medd-blue medd-buttons ml-2" style="margin-right: 10px;">Submit</button>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
            <!--
                                                                    <div class="medd-pop-buttons">
                                                                        <button class="btn medd-blue medd-buttons ml-2" style="margin-right: 10px;" >Submit</button>
                                                                    </div>
            -->
                                                                </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                        <div id="exdate" class="mt-3">
                                                            <h5 class="mb-3">Extension date Details</h5>
                                                            <ul class="custom-details pbg-details-pop" >
                                                                <li><label class="p-o-label">Extension Date</label>: <span id="pre_exdate"></span></li>
                                                                <li><label class="p-o-label">Approval</label>: <span id="pre_apstatus"></span></li>
                                                                <li id="rejreason" style="display:none;"><label class="p-o-label">Rejected Reason</label>: <span id="pre_rejreason"></span></li>
                                                                <li id="extenddays" style="display:none;"><label class="p-o-label">Extended days</label>: <span id="ext_days"></span></li>
                                                            </ul>
                                                    
                                                        </div>
                                                   </div>
                                               </div>
                                           </div> 
                        
                    </div>
                  </div>
                </div>
              </div> 




 
    <div class="modal fade  new-modal" id="pre" tabindex="-1" aria-labelledby="exampleModalLabel"
            aria-hidden="true">
            <div class="modal-dialog modal-lg cutom-modal">
                <form id="prerequitesform" method="POST" action="<?php echo e(url('vendors/add_prerequites')); ?>"
                    enctype="multipart/form-data"> <?php echo csrf_field(); ?>
                    <div class="modal-content">
                        <div class="modal-body">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <div class="otp">
                                <h5>Pre-Requisites</h5>
   <div class="row pbg-itms gey-section">
                                    <div class="col-lg-6">
                                        <div class="form-group">
                                            <label style="font-size: 15px;    font-weight: 600;">Pre-Requisites
                                                <sub>*</sub></label>
                                            <label class="radio-inline ml-4" id="startClientFromWeb" style="margin-right: 10px;">
                                                <input value="1" style="margin-right:5px;" type="radio"
                                                    name="requites_status" checked>Yes
                                            </label>
                                            <label class="radio-inline" style=" margin-right: 10px;">
                                                <input value="0" type="radio" name="requites_status"
                                                    style="margin-right:5px;">No
                                            </label>
                                        </div>
                                    </div>

                                  

                                    
                                    <div class="col-lg-12 p-0 m-0" >
                                        <div id="amitems">
                                           
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 p-0" id="prediv">
                                        <div class="form-inputs app-vend f-adj">
                                            <div class="form-group">
                                                <div class="green-button green-button2 d-flex justify-content-start add-pre">
                                                    <button id="creates"  class="add prereq" onclick="addprereq()"><i class="fa fa-plus" aria-hidden="true"></i>Add New Pre-Requisites</button>
                                                </div>
                                                
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row pbg-itms pb-2">
                                    <div class="col-lg-6">
                                        <div class="form-group" id="tendiv">
                                            <label>Tentative Date <sub>*</sub></label>
                                            <input type="text" class="form-control" name="delivery_date"
                                                id="delivery_date">
                                        
                                        </div>

                                        <input type="hidden" class="form-control" name="pre_orderid"
                                        id="pre_orderid">
                                    <input type="hidden" class="form-control" name="product_id"
                                        id="product_id">
                                    <input type="hidden" class="form-control" name="pre_product_id"
                                        id="pre_product_id">
                                    </div>
                                </div>
                             
                            </div>
                            <div class="medd-pop-buttons">
                                <button class="btn medd-blue medd-buttons ml-2"
                                    style="margin-right: 10px;">Submit</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
  
          
            <div class="modal new-modal fade" id="barcodeModal" tabindex="-1" role="dialog"
                aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                            <div class="otp">
                                <h4>BARCODE</h4>
                                <p class="mb-0">Select Barcode</p>
                                <div class="modal-body imageArea" id="demo">
                                    <div class="form-group">
                                        <select class="form-control" id='barcode_view_options' onchange="renderBarcode()"></select>
                                    </div>
                                    <div id='print_barcode'>
                                        <img style="text-align: center;    border: 1px solid #ccc;     padding: 48px 2px;   margin: 0 auto;display: block;"
                                        id="barcode" />
                                    </div>
                                </div>
                            </div>
                            <div class="medd-pop-buttons justify-content-center">
                                <input type="hidden" name="order_id" id="order_id" value="">
                                <button class="btn medd-blue medd-buttons" id="printBtn">Print</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
  
        <div class="modal new-modal fade" id="equipmentModal" tabindex="-1" role="dialog"
        aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <div class="otp">
                       
                        <p class="mb-0">Select barcode</p>
                        <div class="modal-body imageArea" id="demo">
                            <div class="form-group">
                                <select class="form-control" id='barcode_view_options_details' onchange="renderBarcode()"></select>
                            </div>
                        </div>
                    </div>
                    <div class="medd-pop-buttons justify-content-center">
                        <input type="hidden" name="order_id" id="order_id" value="">
                        <button class="btn medd-blue medd-buttons" id="equipment">Equipment details</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
            

            <div class="modal new-modal fade" id="statusModal" tabindex="-1" role="dialog"
            aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl">
                <div class="modal-content">
                    <div class="modal-body pt-5">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    <div class="table-responsive">
                        <table id="status" class="display text-center align-middle" style="width:100%">
                                <thead>
                                    <tr>

                                        <th>Barcode</th>
                                        <th>Inproduction
                                            <div class="form-check">
                                              <button id="checkAllinproduction" class="checkAllinproduction btn btn-primary">Check all</button>
                                              <button id="uncheckAllinproduction" class="uncheckAllinproduction btn btn-primary">UnCheck all</button>
                                              
                                            </div>
                                        </th>
                                        <th>Inpackage
                                            <div class="form-check">
                                              <button id="checkAllinpackage" class="checkAllinpackage btn btn-primary">Check all</button>
                                              <button id="uncheckAllinpackage" class="uncheckAllinpackage btn btn-primary">UnCheck all</button>
                                            </div>
                                        </th>
                                     

                                       
                                        <?php if($predispatch_inspection==1): ?>

                                        <th  id="column-abc"> Pre Dispatch
                                            <div class="form-check">
                                                <button id="checkAllpredispatch" class="checkAllpredispatch btn btn-primary">Check all</button>
                                                <button id="uncheckAllpredispatch" class="uncheckAllpredispatch btn btn-primary">UnCheck all</button>
                                            
                                            
                                            </div>
                                        </th>

                                        <?php endif; ?>

                                        <th>Dispatch
                                            <div class="form-check">
                                                <button id="checkAlldispatch" class="checkAlldispatch btn btn-primary">Check all</button>
                                                <button id="uncheckAlldispatch" class="uncheckAlldispatch btn btn-primary">UnCheck all</button>
                                            </div>
                                        </th>

                            
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody class="tablebody">
                                  
                                </tbody>
                            </table>
                        </div>
                        <form id="form"  method="post" enctype="multipart/form-data">
                        
                        <div class="medd-pop-buttons justify-content-center">
                            <input type="hidden" id="status_po_id" name="status_po_id" value="">
                            <input type="hidden" id="status_po_products_id" name="status_po_products_id" value="">
                            <input type="hidden" id="product_id" name="product_id" value="">
                           
                            <button class="btn medd-blue medd-buttons" id="statussubmit">Submit</button>
                            <?php if($predispatch_inspection==1): ?>
                            <input type="file" name="predoc" id="predoc">
                            <?php endif; ?>

                            <div id="viewdoc"></div>
                        </div>
                        </form>
                     
                    </div>
                </div>
            </div>
        </div>

            <div class="modal new-modal fade" id="soldModal" tabindex="-1" role="dialog"
                aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                            <div class="otp">
                               
                                <p class="mb-0">Select barcode</p>
                                <div class="modal-body imageArea" id="demo">
                                    <div class="form-group">
                                        <select class="form-control" id='barcode_view_options_sold' onchange="renderBarcode()"></select>
                                    </div>
                                </div>
                            </div>
                            <span style="color:red;font-style: italic;">Note: Please confirm you have attached the barcode to the equipment</span>
                            <div class="medd-pop-buttons justify-content-center">
                                <input type="hidden" name="order_id" id="order_id" value="">
                                <button class="btn medd-blue medd-buttons" id="sold">Go</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
        <?php $__env->stopSection(); ?>
        <?php $__env->startSection('scripts'); ?>
            <script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/jsbarcode/3.5.9/JsBarcode.all.min.js"></script>
<script src="<?php echo e(URL::to('assets/js/vendorsnew.js')); ?>"></script>
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js" crossorigin="anonymous"></script>  
<script src="https://cdn.datatables.net/1.13.1/js/dataTables.bootstrap5.min.js" crossorigin="anonymous"></script> 
<script>
$(document).ready(function (e) {
    $("#form").on('submit',(function(e) {
        e.preventDefault();

        var arraystatus=[];
  
        for (let item of statusarray) {
            var arr=item.split('-',2);
            if($("input[name=check_"+item+"]:checked").val()!=null){
                arraystatus.push($("input[name=check_"+item+"]:checked").val());
            }   
        }
        if(arraystatus.length==0){
            swal("Please select at least one item status");
        }
        else{



                var formData = new FormData($("form#form")[0]);
                formData.append('_token', '<?php echo e(csrf_token()); ?>');

                formData.append('status',JSON.stringify(arraystatus));
                formData.append('status_po_id', $("#status_po_id").val());
                formData.append('po_products_id',$("#status_po_products_id").val());
                formData.append('product_id',$("#product_id").val());

                $.ajax({
                                url: baseurl + 'vendors/productstatus_change',
                                type: "POST",
                                data:formData ,
                                contentType: false,
                                cache: false,
                                processData:false,
                                success: function (res) {
                                    swal({
                                        title: "",
                                        text: "Successfully Changed",
                                        type: "success",
                                        showCancelButton: false,
                                        dangerMode: false,
                                        confirmButtonText: 'OK'
                                    },function () {
                                        window.location = baseurl + 'vendors/po_products/'+$("#status_po_id").val();
                                    })

                                }

                            });

        }






    

       
    
    }));
});

                var counter         = 1;
                var statusarray=[];
                var checkall_inpr='disabled';
                var checkall_inpack='';
                var checkall_dispatch='';
              
                function openstatusModal(po_product_id,order_id,product_id) {

                    var table = $('#status').DataTable();
                    
                   // $('#status').DataTable();
                   
                    statusarray=[];
                    var data = {
                    _token	         :$('#token_po').val(),
                    po_product_id    :po_product_id,
                    order_id         :order_id,
                    }
                    $("#status_po_id").val(order_id);
                    $("#status_po_products_id").val(po_product_id);
                    $("#product_id").val(product_id);

                    var predispatch_inspection=$("#predispatch_inspection").val();

                    $.ajax({
                        url: baseurl + 'vendors/getproductstatus',
                        type: "POST",
                        data: data,
                        success: function (res) {
                            var obj = jQuery.parseJSON(res);
                            console.log(obj);
                            var arrcount = obj.poproductsitemd.length;
                            var x='';
                            if (arrcount != 0) {
                                var j=1;
                                for (i = 0; i < arrcount; i++) {

                                    statusarray.push(obj.poproductsitemd[i].barcode);
                                    var status='';
                                   
                                    if(obj.poproductsitemd[i].dispatch_status==1){
                                        status='Inproduction';
                                        
                                    }
                                    else if(obj.poproductsitemd[i].dispatch_status==2){
                                        status='Inpackage';
                                       
                                    }
                                    else if(obj.poproductsitemd[i].dispatch_status==3){
                                        status='Dispatched';
                                        
                                    }
                                    else if(obj.poproductsitemd[i].dispatch_status==5){
                                        status='Pre-Dispatched';
                                        
                                    }
                                    else if(obj.poproductsitemd[i].dispatch_status==4){
                                        status='Received';
                                        
                                    }
                                    else{

                                        status='Pending';
                                     }

                        
                                x+='<tr><td>'+obj.poproductsitemd[i].barcode+'</td>';
                                x+='<td><div class="form-check">';

                                if((obj.poproductsitemd[i].dispatch_status==1)||(obj.poproductsitemd[i].dispatch_status==2)||(obj.poproductsitemd[i].dispatch_status==3)||(obj.poproductsitemd[i].dispatch_status==4)||(obj.poproductsitemd[i].dispatch_status==5)){
                                
                                    x+='<i class="fa fa-check" aria-hidden="true"></i>';
                                }
                                else{

                                    x+='<input class="form-check-input productstatus inproduction" type="radio" name="check_'+obj.poproductsitemd[i].barcode+'" value="1_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault4">';

                                }
                                
                                x+='</div></td>';
                                x+='<td><div class="form-check">';

                            if((obj.poproductsitemd[i].dispatch_status==5)||(obj.poproductsitemd[i].dispatch_status==2)||(obj.poproductsitemd[i].dispatch_status==3)||(obj.poproductsitemd[i].dispatch_status==4)){
                                x+='<i class="fa fa-check" aria-hidden="true"></i>';
                               
                            }else{

                                x+='<input class="form-check-input productstatus inpackage" type="radio" name="check_'+obj.poproductsitemd[i].barcode+'" value="2_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault4">';

                            } 
                            x+='</div></td>';

                                if(predispatch_inspection==1){

                                  
                                x+='<td><div class="form-check">';

                                if((obj.poproductsitemd[i].dispatch_status==5)||(obj.poproductsitemd[i].dispatch_status==3)||(obj.poproductsitemd[i].dispatch_status==4)){
                                    x+='<i class="fa fa-check" aria-hidden="true"></i>';
                                }else{
                                x+='<input class="form-check-input productstatus predispatch" type="radio"  name="check_'+obj.poproductsitemd[i].barcode+'"value="5_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault5">';

                                }

                                x+='</div></td>';

                            }

                            x+='<td><div class="form-check">';

                            if((obj.poproductsitemd[i].dispatch_status==3)||(obj.poproductsitemd[i].dispatch_status==4)){
                                x+='<i class="fa fa-check" aria-hidden="true"></i>';
                            }else{

                                    if(predispatch_inspection==1){

                                        if((obj.poproductsitemd[i].dispatch_status==0)||(obj.poproductsitemd[i].dispatch_status==1)||(obj.poproductsitemd[i].dispatch_status==2)){
                                            x+='<input class="form-check-input productstatus dispatch" type="radio" disabled  name="check_'+obj.poproductsitemd[i].barcode+'"value="3_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault4">';
                                        }
                                        if((obj.poproductsitemd[i].dispatch_status==5)){

                                            x+='<input class="form-check-input productstatus dispatch" type="radio"   name="check_'+obj.poproductsitemd[i].barcode+'"value="3_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault4">';

                                        }

                                        
                                    }else{

                                        x+='<input class="form-check-input productstatus dispatch" type="radio"  name="check_'+obj.poproductsitemd[i].barcode+'"value="3_'+obj.poproductsitemd[i].id+'" id="flexCheckDefault4">';

                                    }

                           

                            }

                            x+='</div></td>';

                                x+='<td>'+status+'</td>';
                                j++;

                                }

                                $('#status').DataTable().destroy();
                                $('#status').find('tbody').html(x);
                                $('#status').DataTable().draw();

                                if(obj.po_products.predoc!=null){

                                    $("#viewdoc").html('<a href="https://www.meddbot.com/uploads/predoc/'+obj.po_products.predoc+'" target="_blank">view Pre-Dispatch doc</a>');

                                }
                                else{
                                    $("#viewdoc").html('');
                                }

                                

                               // $('#status').dataTable().fnClearTable();
                                //$('#status').dataTable().fnAddData(x);

                               // $(".tablebody").html(x);
                               
                                $('#statusModal').modal({
                                    backdrop: 'static',
                                    keyboard: false
                                });

                            }
                            else{
                                swal("Registration required");
                            }

                        }
                    });
                    }
$(document).ready(function() {

    $("#equipment").click(function() {
        var poproductsitemsid= $("#barcode_view_options_details").val();
        window.location      = baseurl + 'vendors/equipment_status/' + poproductsitemsid;

    });








     $("#sold").click(function() {
           var poproductsitemsid= $("#barcode_view_options_sold").val();
         window.location = baseurl + 'vendors/register_po/' + poproductsitemsid;
    });
});

                $(document).on("click", ".remove", function() {


                    var productSpan = $(this).closest('.amcs');
                    if ($('.amcs').length > 1) {   
                        $(this).closest('.amcs').remove();
                    } else {
                        var divElement = document.getElementById("creates");
                        divElement.classList.add("prereq");
                        $(this).closest('.amcs').remove();
                    }
                    counter--;
                })

                function addprereq(e) {


                    var divElement = document.getElementById("creates");
                    divElement.classList.remove("prereq");
                    

                    var addoption = '';
                    addoption += '<div class="row amcs">';
                    addoption += '<div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">';
                    addoption += '<div class="form-inputs">';
                    addoption += '<div class="form-group">';
                    addoption += ' <label>Pre-Requisites Item<sub>*</sub></label>';
                    addoption += ' <input  type="text" class="form-control prer"  id="prereq' + counter + '" name="prereq[]" value="" >';
                    addoption += '</div>';
                    addoption += '</div>';
                    addoption += '</div>';
                    addoption += '<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">';
                    addoption += '<div class="form-inputs">';
                    addoption += '<div class="green-button rem">';
                    addoption +='<button class="product-submit remove"><i class="fa fa-minus" aria-hidden="true"></i>Remove</button>';
                    addoption += '</div>';
                    addoption += '</div>';
                    addoption += '</div>';
                    addoption += '</div>';
                    if (counter < 5) {
                        $("#amitems").append(addoption);
                        counter++;
                    }
                    return false;
                }
                $(function() {
                    $('#delivery_date_edit').Zebra_DatePicker({
                        format: 'd-m-Y',
                        direction:1
                    });
                    $('#delivery_date').Zebra_DatePicker({
                        format: 'd-m-Y',
                        direction: 1
                    });
                    $('#issue_date').Zebra_DatePicker({
                        format: 'd-m-Y'
                    });
                    $('#expiry_date').Zebra_DatePicker({
                        format: 'd-m-Y'
                    });
                    $('#issue_date_edit').Zebra_DatePicker({
                        format: 'd-m-Y'
                    });
                    $('#expiry_date_edit').Zebra_DatePicker({
                        format: 'd-m-Y'
                    });
                    $('.file-input1').on('change', function(e) {
                        var file = this.files[0]
                        $("#file-list-x1").html('');
                        $('#file-list-' + $(this).data('id')).append('<span>' + file.name + '</span>')
                    })
                    $('.file-input-button1').on('click', function(e) {
                        $('#file-input-' + $(this).data('id')).trigger('click');
                    })
                    $('.file-input').on('change', function(e) {
                        var file = this.files[0]
                        //$("#file-list-x").html('');
                        $('#file-list-' + $(this).data('id')).append('<span>' + file.name + '</span>')
                    })
                    $('.file-input-button').on('click', function(e) {
                        $('#file-input-' + $(this).data('id')).trigger('click');
                    })
                })
 
                $(function() {
                    $('#buyer_filter').change(function() {
                        var $select = $(this);
                        if ($select.val() == 'all') {
                            // No filter selected.  Show all categories
                            $('.js-category-filterable').show();
                            //$('.js-current-category').text('All');
                        } else {
                            var x = 0;
                            $('.js-category-filterable').each(function() {
                                if ($(this).data('category') == $select.val()) {
                                    x = 1;
                                    $(this).show();
                                } else {
                                    $(this).hide();
                                    x = 0;
                                }
                                if (x == 0) {
                                    $(".not").css("display", "block");
                                } else {
                                    $(".not").css("display", "none");
                                }
                            });
                        }
                    });
                });

                function downloadpdf(oid) {
                    window.location = baseurl + 'generate-pdf?id=' + oid;
                }


                function openEquipmentModal(items){
                    var str = '';
                    for (let item of items) {
                        var arr=item.split('-',2);
                        str += "<option value='"+arr[1]+"'>" + arr[0] + "</option>"
                    }

                    console.log(str);
                    document.getElementById("barcode_view_options_details").innerHTML = str;
                    //renderBarcode();
                    
                    $('#equipmentModal').modal({
                        backdrop: 'static',
                        keyboard: false
                    });
                }

                function renderBarcode() {
                    $('#barcode').JsBarcode(document.getElementById("barcode_view_options").value, {
                        width: 1,
                        height: 40
                    });
                }
                
                function openBarcodeModal(items) {
                    var str = '';
                    for (let item of items) {
                        str += "<option>" + item + "</option>"
                    }
                    document.getElementById("barcode_view_options").innerHTML = str;
                    renderBarcode();
                    $('#barcodeModal').modal({
                        backdrop: 'static',
                        keyboard: false
                    });
                }
               
                function opensoldModal(items) {

                    var str = '';
                    for (let item of items) {
                        var arr=item.split('-',2);
                        str += "<option value='"+arr[1]+"'>" + arr[0] + "</option>"
                    }

                    console.log(str);
                    document.getElementById("barcode_view_options_sold").innerHTML = str;
                    //renderBarcode();
                    
                    $('#soldModal').modal({
                        backdrop: 'static',
                        keyboard: false
                    });
                }
           
                <?php if(Session::has('message')): ?>
                    swal({
                        title: "",
                        text: "<?php echo e(Session::get('message')); ?>",
                        type: "success",
                        showCancelButton: false,
                        dangerMode: false,
                        confirmButtonText: 'OK',
                    });
                <?php endif; ?>
                <?php if(Session::has('errormessage')): ?>
                    swal({
                        title: "",
                        text: "<?php echo e(Session::get('errormessage')); ?>",
                        type: "error",
                        showCancelButton: false,
                        dangerMode: true,
                        confirmButtonText: 'OK',
                    });
                <?php endif; ?>
            </script>
            <script>
                function generateBarcode(data) {
                    $('#barcode').JsBarcode(data, {
                        width: 1,
                        height: 40
                    });
                    $('#barcodeModal').modal('show');
                }
                $(document).ready(function() {
                    $("#printBtn").click(function() {
                        var divToPrint = document.getElementById('print_barcode');
                        var newWin = window.open('', 'Print-Window');
                        newWin.document.open();
                        newWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML +
                            '</body></html>');
                        newWin.document.close();
                        setTimeout(function() {
                            newWin.close();
                        }, 10);
                    });

                    $(".checkAllinproduction").click(function() {

                        //alert(1);

                        $(".inproduction").prop("checked", true);
                        

                    });
                    $(".uncheckAllinproduction").click(function() {


                        //alert(2);
                        $(".inproduction").prop("checked", false);


                    });


                    $(".checkAllinpackage").click(function() {

                        $(".inpackage").prop("checked", true);


                        });
                        $(".uncheckAllinpackage").click(function() {

                        $(".inpackage").prop("checked", false);


                    });


                    $(".checkAlldispatch").click(function() {

                        $(".dispatch").prop("checked", true);


                        });

                    $(".checkAllpredispatch").click(function() {

                        $(".predispatch").prop("checked", true);


                    });

                    $(".uncheckAllpredispatch").click(function() {

                            $(".predispatch").prop("checked", false);


                    });



                     $(".uncheckAlldispatch").click(function() {

                        $(".dispatch").prop("checked", false);


                    });



            $(".checkall_dispatch").click(function() {

                //alert();
                    var chkItem=$("#flexCheckDefault3");
                        if($(chkItem).is(":checked"))
                        {
                            $(".dispatch").prop("checked", true);
                        }
                        else{
                            $(".dispatch").prop("checked", false);

                        }

                    });
            $(".checkall_inpackage").click(function() {

                                        
                    var chkItem=$("#flexCheckDefault2");

                    if($(chkItem).is(":checked"))
                        {
                            $(".inpackage").prop("checked", true);
                        }
                        else{
                            $(".inpackage").prop("checked", false);

                        }

            });


                });

                function printPdf(id) {
                    var getMyFrame = document.getElementById(id);
                    getMyFrame.focus();
                    getMyFrame.contentWindow.print();
                }
            </script>
        <?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/meddbot/public_html/resources/views/vendors/po_products_vendor.blade.php ENDPATH**/ ?>