<?php $__env->startSection('content'); ?>
<div class="common-content">
          <div class="page-content">
                <div class="page-heading">
                    <div class="headings">
                        <h6>Product Listing</h6>
                    </div>
                </div>
              
                <!--<a href="<?php echo e(url('vendors/addvendorproducts')); ?>"><button class="btn btn-success" style="margin-top: 10px;margin-bottom: 10px;margin-left: 815px;">Add Vendor Products</button></a>-->
        <?php if(count($productlist) !=0): ?>
		
		<table id="example" class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>
                <th>Id</th>
                <th>Product Name</th>
                <th>Registration No</th>
                <th>Product Code</th>
				 <!--<th>Status</th>-->
                <th>Criticality rating</th>
                <th>Assigned Users</th>
                 <th>Action</th>
            </tr>
        </thead>
        <tbody>
        <?php $__currentLoopData = $productlist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$products): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
		
												<?php if($products->type=='approve'): ?>
													   <?php
														$pname  			= App\Helpers\CustomHelper::product_name($products->product_id);
													   ?>
													   <?php
														$pdetails  			= App\Helpers\CustomHelper::vendorproduct_details($products->product_id);
														$modelno 			= $pdetails->product_code;
													   ?>
												 <?php else: ?>
													 <?php
													   $pname  			= App\Helpers\CustomHelper::product_existing_name($products->existing_product_id);
													 ?>
													  <?php
													  $modelno 			= $products->product_code_existing;
													 ?>
												 <?php endif; ?>
		
            <tr>
                <td><?php echo e($key+1); ?></td>
                <td><?php echo e(ucfirst($pname)); ?></td>
                <td><?php echo e($products->rtegisterid); ?>

                <td><?php echo e($modelno); ?></td>
                
               <!--<td> <?php // if($products->product_status  == '0'){ ?>
                        Inactive 
                    <?php // }elseif($products->product_status  == '1'){  ?>
                        Active
                    <?php // }elseif($products->product_status  == '2'){  ?>
                        Rejected
                   <?php // } ?>
                   </td>-->
				<td>
				
					<?php if($products->current_value >= 1 && $products->current_value <= 3): ?> 
						
					   <button style="background-color:green;WIDTH: 100PX;PADDING: 7PX;border: none;"></button>
					
					<?php elseif($products->current_value >= 4 && $products->current_value <= 5): ?> 
					
					 <button style="background-color:orange;WIDTH: 100PX;PADDING: 7PX;border: none;"></button>
					<?php elseif($products->current_value >= 6 && $products->current_value <= 7): ?> 
					
					 <button style="background-color:blue;WIDTH: 100PX;PADDING: 7PX;border:none;"></button>
					<?php else: ?>
						 <button style="background-color:red;WIDTH: 100PX;PADDING: 7PX;border:none;"></button>
					<?php endif; ?>			
				</td>
                <td>

                    

                    <?php if($products->type=='existing'): ?>

                        <?php
                        $assigned  = App\Helpers\CustomHelper::assigned_product($products->existing_product_id,$products->type,$products->department_id);
                        ?>


                    <?php else: ?>

                        <?php
                        $assigned  = App\Helpers\CustomHelper::assigned_product($products->product_id,$products->type,$products->department_id);
                        ?>

                    <?php endif; ?>


                    
                    <?php $string='';?>
                    <?php $__currentLoopData = $assigned['userlist']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                        <?php $string .=$user->first_name.',';?>

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

                    <?php echo e(rtrim($string, ',')); ?>

               </td>

				<td>
                    <a href="https://meddbot.com/buyers/department_product_detail/<?php echo e($products->rtegisterid); ?>"><button class="btn common-btn green-btn"><i class="fa fa-eye" aria-hidden="true"></i>  View  </button></a> 
                    <?php if($products->type=='existing'): ?>
                    <a href="#" id="assign"><button class="btn common-btn green-btn" onClick="assign('<?php echo e($products->type); ?>','<?php echo e($products->existing_product_id); ?>','<?php echo e($products->department_id); ?>','<?php echo e($products->rtegisterid); ?>','<?php echo e($products->register_sold_id); ?>')"><i class="fa fa-eye" aria-hidden="true"></i>  Assign  </button></a> 
                    <?php else: ?>
                    <a href="#" id="assign"><button class="btn common-btn green-btn" onClick="assign('<?php echo e($products->type); ?>','<?php echo e($products->product_id); ?>','<?php echo e($products->department_id); ?>','<?php echo e($products->rtegisterid); ?>','<?php echo e($products->register_sold_id); ?>')"><i class="fa fa-eye" aria-hidden="true"></i>  Assign  </button></a> 
                    <?php endif; ?>
                
                </td>
            </tr>
            
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>    
            
            
            
        </tbody>
        <!-- <tfoot>
            <tr>
                <th>Id</th>
                <th>Product Name</th>
                <th>Product Code</th>
                <th>Action</th>
            </tr>
        </tfoot> -->
    </table>
	
	<?php endif; ?>


          </div>


          <div class="modal fade" id="myModalcontact" role="dialog"  >
            <div class="modal-dialog ">
                <input type="hidden"  id="type_pop">
                <input type="hidden"  id="product_pop">
                <input type="hidden"  id="depart_pop">
                <input type="hidden"  id="registerid_pop">
                <input type="hidden"  id="soldid_pop">
                <input name="_token" type="hidden" id="token_buyer" value="<?php echo e(csrf_token()); ?>">
               <!-- Modal content-->
               <div class="modal-content">
                   <div class="modal-header">
                          <h5 class="modal-title" id="exampleModalLabel">Department Users</h5>
                          <button type="button" class="close close_message" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                          </button>
                      </div>
                  <div class="modal-body">
                     <div class="row manufacturerlist manufacturerlist-rs">
                        <div class="col-sm-12 col-xs-12">
                           <div class="form-inputs">
                                <div class="form-group userlistpop" >

                               

                                </div>
                             </div>
                           </div>
                        </div>
            
                        <div class="modal-footer usersave">
                          <button type="submit" class="btn btn-primary sendmessage" id="btnMultiple">
                                      <?php echo e(__('Save')); ?>

                                    </button>
                          </div>  
                     </div>
         
               </div>
           
         </div>
         </div>
         <!-- Modal -->


<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?>


<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.js"></script>

<script>

function assign(product_type,product_id,department_id,register_id,sold_id){

    $("#type_pop").val(product_type);
    $("#product_pop").val(product_id);
    $("#depart_pop").val(department_id);
    $("#registerid_pop").val(register_id);
    $("#soldid_pop").val(sold_id);

    var data = {
					_token	:$('#token_buyer').val(),
					product_id:product_id,
					department_id:department_id,
                    product_type:product_type,
                    register_id:register_id,
                    sold_id:sold_id
                   
				}

          $.ajax({
					url:'https://www.meddbot.com/buyers/product_users',
					type: "POST",
					data: data,
					success: function (res) {

                        console.log(res);

                        if(res=='nodata'){

                            $(".userlistpop").html('<span style="color:red">Please add Department users</span>');
                            $(".usersave").hide();

                        }
                        else{

                            $(".userlistpop").html(res);
                            $(".usersave").show();

                        }

                    

					}
				});
$('#myModalcontact').modal({backdrop: 'static', keyboard: false});
}
$(document).ready(function() {
    $('#example').DataTable();


 $('#btnMultiple').click(function(){
  		var userlist = [];
  		$("input:checkbox[name='departuser']:checked").each(function(){    
  			userlist.push($(this).val());    		
  		});
  		userlist.join(", ");


        if(userlist.length ==0){

            swal({
					title: "",
					text: "Please select atleast one user",
					type: "warning",
					showCancelButton: false,
					dangerMode: false,
					confirmButtonText: 'OK',

				});


        }
        else{


            var data = {
					_token	:$('#token_buyer').val(),
					product_id:$("#product_pop").val(),
					depart_id:$("#depart_pop").val(),
                    type:$("#type_pop").val(),
                    register_id:$("#registerid_pop").val(),
                    sold_id:$("#soldid_pop").val(),
                    userlist:userlist
				}

          $.ajax({
					url:'https://www.meddbot.com/buyers/assign_product_user',
					type: "POST",
					data: data,
					success: function (res) {
						
						console.log(res);
						swal({
								title: "",
								text: "Successfully Assigned",
								type: "success",
								showCancelButton: false,
								dangerMode: false,
								confirmButtonText: 'OK'
							},function () {
								window.location = baseurl + 'buyers/department_product/'+$("#depart_pop").val();
							})
						
					}
				});

        }

         
	});


} );
</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/buyers/product_department.blade.php ENDPATH**/ ?>