<?php $__env->startSection('content'); ?>
<style>
label.error{
	color:red;
}
#error_status{
	color:red;
}
sup {
  color:red;
}
td.details-control {
    background: url('https://www.datatables.net/examples/resources/details_open.png') no-repeat center center;
    cursor: pointer;
}
tr.shown td.details-control {
    background: url('https://www.datatables.net/examples/resources/details_close.png') no-repeat center center;
}

</style>
<div class="common-content">

		  <div class="page-content">

          <div class="page-heading" style="margin-bottom: 15px; ">
             <div class="headings">
                <h6>Quality Management</h6>
             </div>
          </div>
              
         <div class="tableBox wraper Quality">       
              <div class="hack1">
                  <div class="hack2">
  
<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th style="width: 50px !important;" >More info</th>			
            <th>Complaint Id</th>
			<th>Posted date</th>
			<th>Status</th>
			<th>Action</th>
        </tr>
    </thead>
    <tbody>
		<?php $i=1;?>
            <?php $__currentLoopData = $complaintlist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $complaintlist): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

			

			<?php if($complaintlist->type=='approve'): ?>

					<?php
					$pname  			= App\Helpers\CustomHelper::product_name($complaintlist->productid);
					?>
					<?php
					$pdetails  			= App\Helpers\CustomHelper::vendorproduct_details($complaintlist->productid);
					$modelno 			= $pdetails->product_code;
					?>
				<?php else: ?>
					<?php
						$pname  			= App\Helpers\CustomHelper::product_existing_name($complaintlist->existing_product_id);
					?>
					<?php
					$modelno 			= $complaintlist->product_code_existing;
					?>
				<?php endif; ?>


				<?php
		  
				 $current_date 			= date('d-m-Y');
				 $product_warranty 		=$complaintlist->warrenty;		
		 		 $dayswarrenty  		= App\Helpers\CustomHelper::dateDiffInDays($current_date,$product_warranty);
			  ?>

					<?php if(strtotime($product_warranty) >= strtotime($current_date)): ?>
					  	<?php $status_warrenty = '<span class="status green">In Warranty</span>';?>
					<?php else: ?>   
					<?php $status_warrenty = '<span class="status red">Out of Warranty</span>';?>					   
					<?php endif; ?>





					 <?php if($complaintlist->complaint_type=='manual'): ?>

					 <?php $naturecomplaint ='<span class="status green">Equipment Malfunction</span>';?>
					
					<?php endif; ?>
   
					<?php if($complaintlist->complaint_type=='inspection_request'): ?>
   
					<?php $naturecomplaint ='<span class="status green">Inspection Request</span>';?>
					
					<?php endif; ?>
					
					<?php if($complaintlist->complaint_type=='amc_cmc_activation'): ?>
   
					<?php $naturecomplaint = '<span class="status green">' . strtoupper($complaintlist->activate_val) . ' Activation</span>'; ?>
					<?php endif; ?>
   
					<?php if($complaintlist->complaint_type=='amc_cmc_rene'): ?>
   
					<?php $naturecomplaint = '<span class="status green">Renew ' . strtoupper($complaintlist->activate_val) . '</span>'; ?>
					<?php endif; ?>
   
					<?php if($complaintlist->complaint_type=='validation_date'): ?>
   
					  <?php $naturecomplaint = '<span class="status green">Validation Request</span>'; ?>
					<?php endif; ?>
					<?php if($complaintlist->complaint_type=='installation_date'): ?>
					<?php $naturecomplaint = '<span class="status green">Installation request</span>'; ?>

					 <?php endif; ?>
   
   
					 <?php if($complaintlist->complaint_type=='preventive_contract'): ?>
   
					 <?php $naturecomplaint = '<span class="status green">Preventive Maintenance Contract</span>'; ?>

					 <?php endif; ?>

					 <tr data-child='<?php echo e(json_encode([
						"pname" => $pname, 
						"modelno" => $modelno,
						"sno" => $complaintlist->product_serial_no,
						"cname" => ucfirst($complaintlist->customername),
						"status" => $status_warrenty,
						"ncomplaint" => $naturecomplaint
					])); ?>'>
            <td></td>

            
			<td><?php echo e($complaintlist->id); ?></td>
            <td><?php echo e(date('d-m-Y', strtotime($complaintlist->date))); ?></td>
			
			<td>
				<?php
					$statusMap = [
						0 => '<button class="status red">Pending</button>',
						14 => '<span class="status red">Pending</span>',
						3 => '<span class="status green">Submit Service Charge</span>',
						2 => '<span class="status red">Rejected</span>',
						4 => '<span class="status green" style="cursor: inherit;">Scheduled</span>',
						1 => '<span class="status green">Approved</span>',
						5 => $complaintlist->servicecharge_status == 1 && $complaintlist->reopen_status == 0
							? '<span class="status green">Collected Charges</span>'
							: '<span class="status green">Complaint Resolved</span>',
						6 => '<span class="status orange">Under Observation</span>',
						7 => '<span class="status grey">Closed</span>',
						8 => '<span class="status grey">Complaint Accepted</span>',
						10 => '<span class="status grey">Complaint Reopened</span>',
						9 => '<span class="status grey">Complaint Rejected</span>',
						21 => $complaintlist->complaint_type == 'validation_date'
							? '<span class="status grey">Validation Date Rejected</span>'
							: '<span class="status grey">' . ucfirst($complaintlist->activate_val) . ' Rejected</span>',
						20 => $complaintlist->complaint_type == 'validation_date'
							? '<span class="status grey">Validation Date Submitted</span>'
							: '<span class="status grey">' . ucfirst($complaintlist->activate_val) . ' Submitted</span>',
						22 => $complaintlist->complaint_type == 'validation_date'
							? '<span class="status green">Renewed Validation Date</span>'
							: '<span class="status green">' . ucfirst($complaintlist->activate_val) . ' Activated</span>',
						13 => '<span class="status red">Rejected</span>',
						12 => '<span class="status green">Scheduled</span>',
						15 => '<span class="status green">Quotation Submitted</span>',
						16 => '<span class="status red">Quotation Rejected</span>',
						17 => '<span class="status green">Quotation Approved</span>',
						30 => '<span class="status green">' . ucfirst($complaintlist->activate_val) . ' Renewed</span>',
					];
			
					// Default status if none of the conditions match
					$status = $statusMap[$complaintlist->status] ?? '<span class="status green">Renewed Validation Date</span>';
				?>
			
				<?php echo $status; ?>

			</td>
			
			<td>
			  <div class="d-flex justify-content-center">
				
				<?php if(($complaintlist->status==5)||($complaintlist->status==20)||($complaintlist->status==21)): ?>
								<?php if($complaintlist->complaint_type=='validation_date'): ?>

									
											  <?php if(($complaintlist->validation_date_status==1)||($complaintlist->validation_date_status==4)): ?>
												  <a href="#" onclick="updatevalidation_date(<?php echo e($complaintlist->id); ?>,<?php echo e($complaintlist->regsold_id); ?>)"><span class="btn common-btn green-btn">Update Validation Date</span></a>
											  <?php endif; ?>
										 
									 <?php endif; ?>
							
							<?php if($complaintlist->complaint_type=='amc_cmc_rene'): ?>
									<?php if($complaintlist->amc_cmc_flow==1): ?>
									<?php if(($complaintlist->status==5)||($complaintlist->status==21)): ?>
										<a href="#" onclick="updateamc_cmc(<?php echo e($complaintlist->id); ?>,<?php echo e($complaintlist->regsold_id); ?>,'<?php echo e(ucfirst($complaintlist->activate_val)); ?>','renew')"><span class="btn common-btn green-btn">Update <?php echo e(strtoupper($complaintlist->activate_val)); ?></span></a>
								<?php endif; ?>
									<?php endif; ?>
						   <?php endif; ?>
							
							
									
												<?php if($complaintlist->complaint_type=='amc_cmc_activation'): ?>
													<?php if(($complaintlist->status==5)||($complaintlist->status==21)): ?>
														<a href="#" onclick="updateamc_cmc(<?php echo e($complaintlist->id); ?>,<?php echo e($complaintlist->regsold_id); ?>,'<?php echo e(ucfirst($complaintlist->activate_val)); ?>','activation')"><span class="btn common-btn green-btn">Update <?php echo e(strtoupper($complaintlist->activate_val)); ?></span></a>
													<?php endif; ?>
													
												<?php endif; ?>
												
												
												
											
									
					
					<?php endif; ?>
			
						<?php if(Auth::user()->user_type == '3'): ?>
						<a href="<?php echo e(url('/manufacturers/view_complaint/'.$complaintlist->id)); ?>"><button class="btn common-btn green-btn"><i class="fa fa-eye" aria-hidden="true"></i> <?php if($complaintlist->status==1): ?>Schedule <?php elseif($complaintlist->status==9): ?>Schedule  <?php elseif($complaintlist->status==10): ?>Schedule <?php else: ?> View <?php endif; ?> </button></a>
						<?php endif; ?>
						<?php if(Auth::user()->user_type == '2'): ?>

						<a href="<?php echo e(url('/vendors/view_complaint/'.$complaintlist->id)); ?>"><button class="btn common-btn green-btn"><i class="fa fa-eye" aria-hidden="true"></i> <?php if($complaintlist->status==1): ?>Schedule <?php elseif($complaintlist->status==9): ?>Schedule  <?php elseif($complaintlist->status==10): ?>Schedule <?php else: ?> View <?php endif; ?> </button></a>

						<?php endif; ?>
				
				
					   
						<?php if($complaintlist->type=='approve'): ?>
							<a href="<?php echo e(url('/message_vendor_complaint/'.$complaintlist->id.'/'.$complaintlist->productid.'/'.$complaintlist->buyer_id)); ?>"><span class="btn common-btn green-btn">Send Message</span></a>
						 <?php else: ?>
							   <a href="<?php echo e(url('/message_vendor_complaint/'.$complaintlist->id.'/'.$complaintlist->existing_product_id.'/'.$complaintlist->buyer_id)); ?>"><span class="btn common-btn green-btn">Send Message</span></a>
						 <?php endif; ?>
				  </div>

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


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

</div>



<!-- Modal AMC/CMC Updation -->
<div class="modal fade" id="amc_cmc_updation" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog"> 
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="amc_cmc_updation_title"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body imageArea" id="demo1">
	     
		  <form name="update_amc_cmc" id="update_amc_cmc" method="POST" action="<?php echo e(url('vendors/update_amc_cmc_complaint')); ?>"  enctype="multipart/form-data">
			   <?php echo csrf_field(); ?>
			 <div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>Start Date <sup>*</sup></label>
						
						 <input id="start_date" type="text" class="form-control" data-zdp_readonly_element="false" name="start_date">
						 <input id="amccomplaint_update_id" type="hidden" class="form-control"  name="amccomplaint_update_id" value="">
						 <input id="ctype" type="hidden" class="form-control"  name="ctype" value="">
						  <input id="amcregsold_id" type="hidden" class="form-control"  name="amcregsold_id" value="">
						</div>
					  </div>
					</div>
				</div>
				<div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>End Date <sup>*</sup></label>
						
						 <input id="end_date" type="text" class="form-control" data-zdp_readonly_element="false" name="end_date" >
						 
					  </div>
					  </div>
					</div>
				</div>
				<div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>Price <sup>*</sup></label>
						
						 <input id="price" type="text" class="form-control" data-zdp_readonly_element="false" name="price">
						
						
					  </div>
					  </div>
					</div>
				</div>
				
				<div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>Upload Certificate <sup>*</sup></label>
						  <input id="certificate" name="certificate" type="file" class="form-control">
						 
					  </div>
					  </div>
					</div>
				</div>
		  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-secondary closemessage" data-dismiss="modal" id="closebar">Close</button>
				<button type="submit" class="btn btn-primary sendmessage" id="sendobservation">
							  <?php echo e(__('Send')); ?>

						   </button>
			  </div>
		  </form>
	  
      </div>
<!--
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" id="closebar">Close</button>
        
      </div>
-->
    </div>
  </div>
<!-- Modal -->




<!-- Modal Under observation -->
<div class="modal fade" id="exampleModal_updatevalidationdate" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog"> 
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Update Validation Date</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body imageArea" id="demo">
	     
		  <form name="update_validationdate" id="update_validationdate" method="POST" action="<?php echo e(url('vendors/validationdate_update')); ?>"  enctype="multipart/form-data">
			   <?php echo csrf_field(); ?>
			 <div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>Validation Date <sup>*</sup></label>
						
						 <input id="validation_date" type="text" class="form-control" data-zdp_readonly_element="false" name="validation_date" readonly>
						 <input id="complaint_update_id" type="hidden" class="form-control"  name="complaint_update_id">
						  <input id="regsold_id" type="hidden" class="form-control"  name="regsold_id">
						
						
					  </div>
					  </div>
					</div>
				</div>
				<div class="row manufacturerlist manufacturerlist-rs">
				<div class="col-sm-12 col-xs-12">
					<div class="form-inputs">
					  <div class="form-group">
						 <label>Upload Certificate <sup>*</sup></label>
						  <input id="document" name="document" type="file" class="form-control">
						 
					  </div>
					  </div>
					</div>
				</div>
		  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-secondary closemessage" data-dismiss="modal" id="closebar">Close</button>
				<button type="submit" class="btn btn-primary sendmessage" id="sendobservation">
							  <?php echo e(__('Send')); ?>

						   </button>
			  </div>
		  </form>
	  
      </div>
<!--
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" id="closebar">Close</button>
        
      </div>
-->
    </div>
  </div>
<!-- Modal -->




<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?>
<script>
<?php if(Session::has('message')): ?>
      swal({
        title: "",
        text: "<?php echo e(Session::get('message')); ?>",
        type: "success",
        showCancelButton: false,
        dangerMode: false,
        confirmButtonText: 'OK',

    });
<?php endif; ?>




$('#validation_date').Zebra_DatePicker({
    format: 'd-m-Y'
    });
	
$('#start_date').Zebra_DatePicker({
    format: 'd-m-Y',
	direction:1
    });

$('#end_date').Zebra_DatePicker({
    format: 'd-m-Y',
	direction:1
    });	
	
	
	
	
function updatevalidation_date(complaintid,regsold_id){
	$("#complaint_update_id").val(complaintid);
	$("#regsold_id").val(regsold_id);
	$('#exampleModal_updatevalidationdate').modal({backdrop: 'static', keyboard: false});
	
}

function updateamc_cmc(complaintid,regsold_id,activateval,ctype){
	
	$("#amccomplaint_update_id").val(complaintid);
	$("#ctype").val(ctype);
	$("#amcregsold_id").val(regsold_id);
	$("#amc_cmc_updation_title").html('Update '+activateval+' '+'details');
	$('#amc_cmc_updation').modal({backdrop: 'static', keyboard: false});
	
}

$(document).ready( function () {
    $('#table_id').DataTable();
} );
</script>

<script>
   $(document).ready(function() {
    var table = $('#example').DataTable({
        "columnDefs": [
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": '',
                "targets": 0
            }
        ],
        "order": [[1, 'asc']]
    });

	

// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
    var tr = $(this).closest('tr');
    var row = table.row(tr);

    if (row.child.isShown()) {
        // This row is already open - close it
        row.child.hide();
        tr.removeClass('shown');
    } else {
        // Open this row
        var data = JSON.parse(tr.attr('data-child'));  // Ensure valid JSON parsing
console.log(data); 
        row.child(format(data)).show();
        tr.addClass('shown');
    }
});


});

function format(d) {

	console.log(d);
    return `
        <table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">
            <tr>
                <td>Product Name:</td>
                <td>${d.pname}</td>
            </tr>
            <tr>
                <td>Model Number:</td>
                <td>${d.modelno}</td>
            </tr>
			<tr>
                <td>Serial No:</td>
                <td>${d.sno}</td>
            </tr>
			<tr>
                <td>Customer Name:</td>
                <td>${d.cname}</td>
            </tr>
			<tr>
                <td>Product Status:</td>
                <td>${d.status}</td>
            </tr>
			<tr>
                <td>Nature of the complaint:</td>
                <td>${d.ncomplaint}</td>
            </tr>


			

			
            
        </table>`;
}


</script>




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

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