<?php if(!empty($mode)){ ?>
	<div class="container-fluid">
		<div class="card card-body">
			<h4 class="card-title">Client Information</h4>
			<hr>
			<?php if(!empty($data_complaint)){ ?>
				<div class="row">
					<?php if($data_complaint[0]->complaint_for == 1){ ?>
						<div class="col">
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_internal" value="0" onchange="changeClientList(this)" disabled>
								<label class="form-check-label" for="complaint_client_type">Internal Client</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_external" value="1" onchange="changeClientList(this)" checked disabled>
								<label class="form-check-label" for="complaint_client_type">External Client</label>
							</div>
						</div>
					<?php }else{ ?>
						<div class="col">
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_internal" value="0" onchange="changeClientList(this)" checked disabled>
								<label class="form-check-label" for="complaint_client_type">Internal Client</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_external" value="1" onchange="changeClientList(this)" disabled>
								<label class="form-check-label" for="complaint_client_type">External Client</label>
							</div>
						</div>
					<?php } ?>
					<div class="col-1">
						<label for="" class="col-form-label-sm">Reference No.</label>
					</div>
					<div class="col-2">
						<input type="text" name="complaint_ref_no" id="complaint_ref_no" class="form-control form-control-sm" disabled placeholder="Auto-generated" value="<?php echo str_pad($data_complaint[0]->ref_no, 4,'0', STR_PAD_LEFT); ?>">
					</div>
					<div class="col-2">
						<label for="" class="col-form-label-sm">Register by / Receiver of Complaint</label>
					</div>
					<div class="col-4">
						<input type="text" name="complaint_recev" id="complaint_recev" class="form-control form-control-sm" disabled value="<?php echo $data_complaint[0]->reg_name; ?>">
					</div>
				</div>
				<div class="row">
					<div class="col-3">
						<label for="complaint_dept_id" class="col-form-label-sm">Department</label>
						<select id="complaint_dept_id" type="text" class="form-control form-control-sm" disabled>
							<option value="" selected="selected">Please Select</option>
							<?php if($department){ foreach($department as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->dept_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?> | <?php echo $value['branch_name']; ?></option>
							<?php }} ?>
						</select>
					</div>
					<div class="col-3">
						<label for="" class="col-form-label-sm">Services</label>
						<select id="services" type="text" class="form-control form-control-sm" onchange="changeJobList(this)" disabled>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_services){ foreach($data_services as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->services_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['service']; ?></option>
							<?php }} ?>
						</select>
					</div>
					<div class="col-3">
						<label for="" class="col-form-label-sm">Type of Job</label>
						<select id="job" type="text" class="form-control form-control-sm" disabled>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_job){ foreach($data_job as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->job_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['job']; ?></option>
							<?php }} ?>
						</select>
					</div>
					<?php if($data_complaint[0]->complaint_for == 1){ ?>
						<div class="col-3">
							<label for="complaint_client" class="col-form-label-sm">Client Name</label>
							<select id="complaint_client" type="text" class="form-control form-control-sm" onchange="changeClientDetails(this)" disabled>
								<option value="" selected="selected">Please Select</option>
								<?php if($data_client){ foreach($data_client as $key => $value) { ?>
									<option 
									<?php if($data_complaint[0]->client_id == $value['id']) { 
										echo 'selected';
									}?>
									value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
								<?php }} ?>
							</select>
						</div>
					<?php }else{ ?>
						<div class="col-3">
							<label for="complaint_client" class="col-form-label-sm">Client Name</label>
							<select id="complaint_client" type="text" class="form-control form-control-sm" onchange="changeClientDetails(this)" disabled>
								<option value="" selected="selected">Please Select</option>
								<?php if($department){ foreach($department as $key => $value) { ?>
									<option 
									<?php if($data_complaint[0]->client_id == $value['id']) { 
										echo 'selected';
									}?>
									value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?> | <?php echo $value['branch_name']; ?></option>
								<?php }} ?>
							</select>
						</div>
					<?php } ?>
				</div>
				<div class="row">
					<div class="col-3">
						<label for="complaint_client_address" class="col-form-label-sm">Client Address</label>
						<input type="text" name="complaint_client_address" id="complaint_client_address" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->client_address; ?>" disabled>
					</div>
					<div class="col-3">
						<label for="complaint_contact_name" class="col-form-label-sm">Contact Name</label>	

						<select id="complaint_contact_name" type="text" class="form-control form-control-sm" onchange="changeContactNo(this)" <?php if($data_complaint[0]->complaint_for == 1){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?> disabled>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_complaint_contact){ foreach($data_complaint_contact as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->contact_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
							<?php }} ?>
							<option value="9999" <?php if($data_complaint[0]->contact_id == 9999){ echo 'selected'; }?>>Others</option>
						</select>

						<input type="text" name="complaint_contact_name_oth" id="complaint_contact_name_oth" class="form-control form-control-sm" <?php if(($data_complaint[0]->complaint_for == 1) && ($data_complaint[0]->contact_id == 9999)){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?> value="<?php echo $data_complaint[0]->contact_name; ?>" disabled>	

						<select id="complaint_contact_name_int" type="text" class="form-control form-control-sm" onchange="changeStaffContactNo(this)" <?php if($data_complaint[0]->complaint_for == 0){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?> disabled>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_staff_contact){ foreach($data_staff_contact as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->contact_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
							<?php }} ?>
						</select>

					</div>
					<div class="col-3">
						<label for="complaint_contact_no" class="col-form-label-sm">Phone No.</label>
						<input type="text" name="complaint_contact_no" id="complaint_contact_no" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->phone_no; ?>" disabled>
					</div>
					<div class="col-3">
						<label for="complaint_contact_email" class="col-form-label-sm">Email</label>
						<input type="text" name="complaint_contact_email" id="complaint_contact_email" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->email; ?>" disabled>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm">Business Impact</label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_business_impact" disabled><?php echo $data_complaint[0]->business_impact; ?></textarea>
					</div>
				</div>
				<br>
				<h4 class="card-title">Complaint Information</h4>
				<hr>
				<div class="row">
					<div class="col">
						<label for="complaint_addressee" class="col-form-label-sm"><b>Addressee of the Complaint</b></label>
						<br>
						<select id="complaint_addressee" type="text" class="form-control form-control-sm" disabled>
							<option value="0" <?php if($data_complaint[0]->addressee_id == 0){ echo 'selected'; }?>>Please Select</option>
							<option value="1" <?php if($data_complaint[0]->addressee_id == 1){ echo 'selected'; }?>>CRM</option>
							<option value="2" <?php if($data_complaint[0]->addressee_id == 2){ echo 'selected'; }?>>Person In Charge</option>
							<option value="3" <?php if($data_complaint[0]->addressee_id == 3){ echo 'selected'; }?>>Department</option>
							<option value="4" <?php if($data_complaint[0]->addressee_id == 4){ echo 'selected'; }?>>Management</option>
						</select>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Complaint Date / Date of Problem Occurrence</b></label>
						<input id="complaint_date" type="text" class="form-control form-control-sm" value="<?php echo date('d-m-Y',strtotime($data_complaint[0]->date)); ?>" disabled>
					</div>
					<?php if($data_complaint[0]->complaint_type == 0){ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Complaint Type</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_initial" value="0" checked disabled>
								<label class="form-check-label" for="complaint_type" value="0">Initial Complaint</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_follow" value="1" disabled>
								<label class="form-check-label" for="complaint_type" value="1">Follow-up Complaint</label>
							</div>
						</div>
					<?php }else{ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Complaint Type</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_initial" value="0" disabled>
								<label class="form-check-label" for="complaint_type" value="0">Initial Complaint</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_follow" value="1" checked disabled>
								<label class="form-check-label" for="complaint_type" value="1">Follow-up Complaint</label>
							</div>
						</div>
					<?php } ?>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Method of Complaint</b></label>
						<br>
						<?php if($data_method){ foreach($data_method as $key => $value) { ?>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="checkbox" name="complaint_method" id="complaint_method" value="<?php echo $value['id']; ?>" 
								<?php if($data_complaint_method){
									foreach ($data_complaint_method as $key => $row) {
										if($row['method_id'] == $value['id']){
											echo 'checked';
										}
									}
								}?> onchange="openOthers_method(this)" disabled>
								<label class="form-check-label" for="inlineCheckbox1"> <?php echo $value['method']; ?> </label>
							</div>
						<?php }}?>
						<div class="form-check form-check-inline">
							<input disabled id="complaint_method_others" name="complaint_method_others" type="text" placeholder="Others.." class="form-control form-control-sm" size="100%" <?php if(!empty($row['others_details'])){ echo 'style="display: block;" value="'.$row['others_details'].'"'; } else { echo 'style="display: none;"';}?>>
						</div>
					</div>
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Complaint About</b></label>
						<br>
						<?php if($data_about){ foreach($data_about as $key => $value) { ?>
							<div class="form-check form-check-inline" >
								<input class="form-check-input" type="checkbox" name="complaint_about" id="complaint_about" value="<?php echo $value['id']; ?>" 
								<?php if($data_complaint_about){
									foreach ($data_complaint_about as $key => $row) {
										if($row['about_id'] == $value['id']){
											echo 'checked';
										}
									}
								}?> onchange="openOthers_about(this)" disabled>
								<label class="form-check-label" for="inlineCheckbox1"> <?php echo $value['about']; ?> </label>
							</div>
						<?php }}?>
						<div class="form-check form-check-inline">
							<input disabled id="complaint_about_others" name="complaint_about_others" type="text" placeholder="Others.." class="form-control form-control-sm" size="50%" <?php if(!empty($row['others_details'])){ echo 'style="display: block;" value="'.$row['others_details'].'"'; } else { echo 'style="display: none;"';}?>>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Case / Complaint Details</b></label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_details" disabled><?php echo $data_complaint[0]->complaint_details; ?></textarea>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Case Resolution Desired by Client</b></label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_reso" disabled><?php echo $data_complaint[0]->reso_desired; ?></textarea>
					</div>
				</div>
				<div class="row">
					<?php if($data_complaint[0]->urgency == 0){ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Reaction Urgency</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_yes" value="1" disabled>
								<label class="form-check-label" for="complaint_urgency">
								Yes
								</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_no" value="0" checked disabled>
								<label class="form-check-label" for="complaint_urgency">
								No
								</label>
							</div>
						</div>
						<div class="col">
							
						</div>
					<?php }else{ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Reaction Urgency</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_yes" value="1" checked disabled>
								<label class="form-check-label" for="complaint_urgency">
								Yes
								</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_no" value="0" disabled>
								<label class="form-check-label" for="complaint_urgency">
								No
								</label>
							</div>
						</div>
						<div class="col">
							
						</div>
					<?php } ?>
				</div>
				<br>
				<div class="row">
					<div class="col">
						<div class="row">
							<div class="col">
								<h4>Complaint Attachment</h4>
							</div>
							<div class="col text-right">
			                    <button class="btn btn-info btn-sm" data-toggle="modal" data-target="#attachmentModal" type="button"> <i class="fas fa-plus"></i> Add Attachment</button>
			                </div>
						</div>
						<hr>
						<div class="table-responsive">
		                    <table class="table table-bordered table-hover">
		                        <thead>
		                            <tr>
		                                <th class="text-center">#</th>
		                                <th class="text-center">Description</th>
		                                <th class="text-center">File Name</th>
		                                <th class="text-center">Action</th>
		                            </tr>
		                        </thead>
		                        <tbody>
		                        	<?php if($data_attachment_main){ foreach ($data_attachment_main as $key => $value) { ?>
	                        			<tr class="text-center">
			                        		<td><?php echo $key+1; ?></td>
			                        		<td><?php echo $value->description; ?></td>
			                        		<td><a target="_blank" href="<?php echo base_url($value->file_location.$value->filename); ?>"><?php echo $value->filename; ?></a></td>
			                        		<td>
			                        			<div class="btn-group btn-group-sm" role="group">
			                        				<a download href="<?php echo base_url($value->file_location.$value->filename); ?>" type="button" class="btn btn-primary" data-trigger="hover" data-toggle="tooltip" title="Download"><i class="fas fa-download"></i></a>
													<button type="button" class="btn btn-danger" onclick="deleteAttachment(<?php echo $value->id; ?>);" data-trigger="hover" data-toggle="tooltip" title="Delete" <?php if((($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin') && ($_SESSION['user']['id'] != $value->created_by))){echo 'disabled'; }?>><i class="fas fa-trash"></i></button>
												</div>
			                        		</td>
		                        		</tr>
		                        	<?php } } ?>
		                        </tbody>
		                    </table>
		                </div>
					</div>
				</div>
				<br>
				<div class="row">
					<?php if((($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin') || ($get_hod[0]->hod_id == $_SESSION['user']['id']) || ($_SESSION['user']['id'] == $data_complaint[0]->pic_id))){ ?>
						<div class="col">
							<label for="complaint_pic" class="col-form-label-sm"><b style="color: red;">*Person In Charge</b></label>
							<select id="complaint_pic" type="text" class="form-control form-control-sm" <?php if(($_SESSION['user']['id'] == $data_complaint[0]->pic_id) || ($data_complaint[0]->status >= 3)){ echo 'disabled'; }?>>
								<option value="" selected="selected">Please Select</option>
								<?php if($department_staff){ foreach($department_staff as $key => $value) { ?>
									<option 
									<?php if($data_complaint[0]->pic_id == $value['id']) { 
										echo 'selected';
									}?>
									value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
								<?php }} ?>
							</select>
						</div>
						<div class="col">
							<label for="complaint_remarks" class="col-form-label-sm"><b>HOD Remarks</b></label>
							<textarea class="form-control form-control-sm" rows="4" id="complaint_remarks" <?php if(($_SESSION['user']['id'] == $data_complaint[0]->pic_id) || ($data_complaint[0]->status >= 3)){ echo 'disabled'; }?>><?php echo $data_complaint[0]->remarks; ?></textarea>
						</div>
					<?php } ?>
				</div>
				<br>

				<?php if($data_complaint[0]->status >= 2){ ?>
					<?php $this->load->view('hr/policyprocedure/form/complaint_reso'); ?>
				<?php } ?>

				<br>
				<?php if((($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin') || ($_SESSION['user']['id'] == $data_complaint[0]->pic_id)) && ($data_complaint[0]->status < 2)){ ?>
					<button onclick="openComplaintReso(<?php echo $data_complaint[0]->id; ?>);" class="btn btn-primary" <?php if($data_complaint[0]->status != 1){ echo "disabled"; }?>> >>> Proceed to Complaint Handling >>> </button>
				<?php }else if(($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin') || ($get_hod[0]->hod_id == $_SESSION['user']['id'])){ ?>
					<div class="row">
						<div class="col-6">
							<button onclick="savePIC(<?php echo $data_complaint[0]->id; ?>);" class="btn btn-success btn-block" <?php if($data_complaint[0]->status >= 1){ echo "disabled"; }?>><?php if($data_complaint[0]->status == 0){ echo "Acknowledge Complaint"; }else{ echo "Complaint Acknowledged"; }?></button>
						</div>
						<div class="col-6">
							<button onclick="verifyComplaint(<?php echo $data_complaint[0]->id; ?>);" class="btn btn-success btn-block" <?php if($data_complaint[0]->status != 2){ echo "disabled"; }?>><?php if($data_complaint[0]->status <= 2){ echo "Verify Complaint"; }else{ echo "Complaint Verified"; } ?></button>
						</div>
					</div>
				<?php } ?>

				<br>
				<?php if((($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin')) && ($data_complaint[0]->status >= 3)){ ?>
                    <button id="approveButtonComplaint" type="button" class="btn btn-dark btn-block" onclick="approveComplaint(<?php echo $data_complaint[0]->id; ?>);" data-trigger="hover" data-tooltip="tooltip" title="Approve Complaint"><i class="fas fa-check-circle"></i> <?php if($data_complaint[0]->status == 3){ echo "Approve Complaint"; } else { echo "Complaint Approved"; } ?></button>
                <?php } ?>
			<?php }?>
		</div>
	</div>
	<br>
<?php } else { ?>
	<div class="container-fluid">
		<div class="card card-body">
			<h4 class="card-title">Client Information</h4>
			<hr>
			<?php if(!empty($data_complaint)){ ?>
				<div class="row">
					<?php if($data_complaint[0]->complaint_for == 1){ ?>
						<div class="col">
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_internal" value="0" onchange="changeClientList(this)">
								<label class="form-check-label" for="complaint_client_type">Internal Client</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_external" value="1" onchange="changeClientList(this)" checked>
								<label class="form-check-label" for="complaint_client_type">External Client</label>
							</div>
						</div>
					<?php }else{ ?>
						<div class="col">
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_internal" value="0" onchange="changeClientList(this)" checked>
								<label class="form-check-label" for="complaint_client_type">Internal Client</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_client_type" id="complaint_client_type_external" value="1" onchange="changeClientList(this)">
								<label class="form-check-label" for="complaint_client_type">External Client</label>
							</div>
						</div>
					<?php } ?>
					<div class="col-1">
						<label for="" class="col-form-label-sm">Reference No.</label>
					</div>
					<div class="col-2">
						<input type="text" name="complaint_ref_no" id="complaint_ref_no" class="form-control form-control-sm" disabled placeholder="Auto-generated" value="<?php echo str_pad($data_complaint[0]->ref_no, 4,'0', STR_PAD_LEFT); ?>">
					</div>
					<div class="col-2">
						<label for="" class="col-form-label-sm">Register by / Receiver of Complaint</label>
					</div>
					<div class="col-4">
						<input type="text" name="complaint_recev" id="complaint_recev" class="form-control form-control-sm" disabled value="<?php echo $data_complaint[0]->reg_name; ?>">
					</div>
				</div>
				<div class="row">
					<div class="col-3">
						<label for="complaint_dept_id" class="col-form-label-sm">Department</label>
						<select id="complaint_dept_id" type="text" class="form-control form-control-sm">
							<option value="" selected="selected">Please Select</option>
							<?php if($department){ foreach($department as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->dept_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?> | <?php echo $value['branch_name']; ?></option>
							<?php }} ?>
						</select>
					</div>
					<div class="col-3">
						<label for="" class="col-form-label-sm">Services</label>
						<select id="services" type="text" class="form-control form-control-sm" onchange="changeJobList(this)">
							<option value="" selected="selected">Please Select</option>
							<?php if($data_services){ foreach($data_services as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->services_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['service']; ?></option>
							<?php }} ?>
						</select>
					</div>
					<div class="col-3">
						<label for="" class="col-form-label-sm">Type of Job</label>
						<select id="job" type="text" class="form-control form-control-sm">
							<option value="" selected="selected">Please Select</option>
							<?php if($data_job){ foreach($data_job as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->job_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['job']; ?></option>
							<?php }} ?>
						</select>
					</div>

					<?php if($data_complaint[0]->complaint_for == 1){ ?>
						<div class="col-3">
							<label for="complaint_client" class="col-form-label-sm">Client Name</label>
							<select id="complaint_client" type="text" class="form-control form-control-sm" onchange="changeClientDetails(this)">
								<option value="" selected="selected">Please Select</option>
								<?php if($data_client){ foreach($data_client as $key => $value) { ?>
									<option 
									<?php if($data_complaint[0]->client_id == $value['id']) { 
										echo 'selected';
									}?>
									value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
								<?php }} ?>
							</select>
						</div>
					<?php }else{ ?>
						<div class="col-3">
							<label for="complaint_client" class="col-form-label-sm">Client Name</label>
							<select id="complaint_client" type="text" class="form-control form-control-sm" onchange="changeStaffDetails(this)">
								<option value="" selected="selected">Please Select</option>
								<?php if($department){ foreach($department as $key => $value) { ?>
									<option 
									<?php if($data_complaint[0]->client_id == $value['id']) { 
										echo 'selected';
									}?>
									value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?> | <?php echo $value['branch_name']; ?></option>
								<?php }} ?>
							</select>
						</div>
					<?php } ?>
				</div>
				<div class="row">
					<div class="col-3">
						<label for="complaint_client_address" class="col-form-label-sm">Client Address</label>
						<input type="text" name="complaint_client_address" id="complaint_client_address" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->client_address; ?>">
					</div>
					<div class="col-3">
						<label for="complaint_contact_name" class="col-form-label-sm">Contact Name</label>	

						<select id="complaint_contact_name" type="text" class="form-control form-control-sm" onchange="changeContactNo(this)" <?php if($data_complaint[0]->complaint_for == 1){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?>>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_complaint_contact){ foreach($data_complaint_contact as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->contact_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
							<?php }} ?>
							<option value="9999" <?php if($data_complaint[0]->contact_id == 9999){ echo 'selected'; }?>>Others</option>
						</select>

						<input type="text" name="complaint_contact_name_oth" id="complaint_contact_name_oth" class="form-control form-control-sm" <?php if(($data_complaint[0]->complaint_for == 1) && ($data_complaint[0]->contact_id == 9999)){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?> value="<?php echo $data_complaint[0]->contact_name; ?>">	

						<select id="complaint_contact_name_int" type="text" class="form-control form-control-sm" onchange="changeStaffContactNo(this)" <?php if($data_complaint[0]->complaint_for == 0){ echo 'style="display: block"'; }else{ echo 'style="display: none"'; }?>>
							<option value="" selected="selected">Please Select</option>
							<?php if($data_staff_contact){ foreach($data_staff_contact as $key => $value) { ?>
								<option 
								<?php if($data_complaint[0]->contact_id == $value['id']) { 
									echo 'selected';
								}?>
								value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
							<?php }} ?>
						</select>

					</div>
					<div class="col-3">
						<label for="complaint_contact_no" class="col-form-label-sm">Phone No.</label>
						<input type="text" name="complaint_contact_no" id="complaint_contact_no" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->phone_no; ?>">
					</div>
					<div class="col-3">
						<label for="complaint_contact_email" class="col-form-label-sm">Email</label>
						<input type="text" name="complaint_contact_email" id="complaint_contact_email" class="form-control form-control-sm" value="<?php echo $data_complaint[0]->email; ?>">
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm">Business Impact</label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_business_impact"><?php echo $data_complaint[0]->business_impact; ?></textarea>
					</div>
				</div>
				<br>
				<h4 class="card-title">Complaint Information</h4>
				<hr>
				<div class="row">
					<div class="col">
						<label for="complaint_addressee" class="col-form-label-sm"><b>Addressee of the Complaint</b></label>
						<br>
						<select id="complaint_addressee" type="text" class="form-control form-control-sm">
							<option value="0" <?php if($data_complaint[0]->addressee_id == 0){ echo 'selected'; }?>>Please Select</option>
							<option value="1" <?php if($data_complaint[0]->addressee_id == 1){ echo 'selected'; }?>>CRM</option>
							<option value="2" <?php if($data_complaint[0]->addressee_id == 2){ echo 'selected'; }?>>Person In Charge</option>
							<option value="3" <?php if($data_complaint[0]->addressee_id == 3){ echo 'selected'; }?>>Department</option>
							<option value="4" <?php if($data_complaint[0]->addressee_id == 4){ echo 'selected'; }?>>Management</option>
						</select>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Complaint Date / Date of Problem Occurrence</b></label>
						<input id="complaint_date" type="text" class="form-control form-control-sm" value="<?php echo date('d-m-Y',strtotime($data_complaint[0]->date)); ?>">
					</div>
					<?php if($data_complaint[0]->complaint_type == 0){ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Complaint Type</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_initial" value="0" checked>
								<label class="form-check-label" for="complaint_type" value="0">Initial Complaint</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_follow" value="1">
								<label class="form-check-label" for="complaint_type" value="1">Follow-up Complaint</label>
							</div>
						</div>
					<?php }else{ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Complaint Type</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_initial" value="0">
								<label class="form-check-label" for="complaint_type" value="0">Initial Complaint</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_type" id="complaint_type_follow" value="1" checked>
								<label class="form-check-label" for="complaint_type" value="1">Follow-up Complaint</label>
							</div>
						</div>
					<?php } ?>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Method of Complaint</b></label>
						<br>
						<?php if($data_method){ foreach($data_method as $key => $value) { ?>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="checkbox" name="complaint_method" id="complaint_method" value="<?php echo $value['id']; ?>" 
								<?php if($data_complaint_method){
									foreach ($data_complaint_method as $key => $row) {
										if($row['method_id'] == $value['id']){
											echo 'checked';
										}
									}
								}?> onchange="openOthers_method(this)">
								<label class="form-check-label" for="inlineCheckbox1"> <?php echo $value['method']; ?> </label>
							</div>
						<?php }}?>
						<div class="form-check form-check-inline">
							<input id="complaint_method_others" name="complaint_method_others" type="text" placeholder="Others.." class="form-control form-control-sm" size="100%" <?php if(!empty($row['others_details'])){ echo 'style="display: block;" value="'.$row['others_details'].'"'; } else { echo 'style="display: none;"';}?>>
						</div>
					</div>
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Complaint About</b></label>
						<br>
						<?php if($data_about){ foreach($data_about as $key => $value) { ?>
							<div class="form-check form-check-inline" >
								<input class="form-check-input" type="checkbox" name="complaint_about" id="complaint_about" value="<?php echo $value['id']; ?>" 
								<?php if($data_complaint_about){
									foreach ($data_complaint_about as $key => $row) {
										if($row['about_id'] == $value['id']){
											echo 'checked';
										}
									}
								}?> onchange="openOthers_about(this)">
								<label class="form-check-label" for="inlineCheckbox1"> <?php echo $value['about']; ?> </label>
							</div>
						<?php }}?>
						<div class="form-check form-check-inline">
							<input id="complaint_about_others" name="complaint_about_others" type="text" placeholder="Others.." class="form-control form-control-sm" size="50%" <?php if(!empty($row['others_details'])){ echo 'style="display: block;" value="'.$row['others_details'].'"'; } else { echo 'style="display: none;"';}?>>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Case / Complaint Details</b></label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_details"><?php echo $data_complaint[0]->complaint_details; ?></textarea>
					</div>
				</div>
				<div class="row">
					<div class="col">
						<label for="" class="col-form-label-sm"><b>Case Resolution Desired by Client</b></label>
						<textarea class="form-control form-control-sm" rows="4" id="complaint_reso"><?php echo $data_complaint[0]->reso_desired; ?></textarea>
					</div>
				</div>
				<div class="row">
					<?php if($data_complaint[0]->urgency == 0){ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Reaction Urgency</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_yes" value="1">
								<label class="form-check-label" for="complaint_urgency">
								Yes
								</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_no" value="0" checked>
								<label class="form-check-label" for="complaint_urgency">
								No
								</label>
							</div>
						</div>
					<?php }else{ ?>
						<div class="col">
							<label for="" class="col-form-label-sm"><b>Reaction Urgency</b></label>
							<br>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_yes" value="1" checked>
								<label class="form-check-label" for="complaint_urgency">
								Yes
								</label>
							</div>
							<div class="form-check form-check-inline">
								<input class="form-check-input" type="radio" name="complaint_urgency" id="complaint_urgency_no" value="0">
								<label class="form-check-label" for="complaint_urgency">
								No
								</label>
							</div>
						</div>
					<?php } ?>
				</div>
				<br>
				<div class="row">
					<div class="col">
						<div class="row">
							<div class="col">
								<h4>Complaint Attachment</h4>
							</div>
							<div class="col text-right">
			                    <button class="btn btn-info btn-sm" data-toggle="modal" data-target="#attachmentModal" type="button"> <i class="fas fa-plus"></i> Add attachment</button>
			                </div>
						</div>
						<hr>
						<div class="table-responsive">
		                    <table class="table table-bordered table-hover">
		                        <thead>
		                            <tr>
		                                <th class="text-center">#</th>
		                                <th class="text-center">Description</th>
		                                <th class="text-center">File Name</th>
		                                <th class="text-center">Action</th>
		                            </tr>
		                        </thead>
		                        <tbody>
		                        	<?php if($data_attachment_main){ foreach ($data_attachment_main as $key => $value) { ?>
	                        			<tr class="text-center">
			                        		<td><?php echo $key+1; ?></td>
			                        		<td><?php echo $value->description; ?></td>
			                        		<td><a target="_blank" href="<?php echo base_url($value->file_location.$value->filename); ?>"><?php echo $value->filename; ?></a></td>
			                        		<td>
			                        			<div class="btn-group btn-group-sm" role="group">
			                        				<a download href="<?php echo base_url($value->file_location.$value->filename); ?>" type="button" class="btn btn-primary" data-trigger="hover" data-toggle="tooltip" title="Download"><i class="fas fa-download"></i></a>
													<button type="button" class="btn btn-danger" onclick="deleteAttachment(<?php echo $value->id; ?>);" data-trigger="hover" data-toggle="tooltip" title="Delete" <?php if((($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin') && ($_SESSION['user']['id'] != $value->created_by))){echo 'disabled'; }?>><i class="fas fa-trash"></i></button>
												</div>
			                        		</td>
		                        		</tr>
		                        	<?php } } ?>
		                        </tbody>
		                    </table>
		                </div>
					</div>
				</div>
				<br>
				<button onclick="saveEditComplaint(<?php echo $data_complaint[0]->id; ?>);" class="btn btn-success" <?php if($data_complaint[0]->status != 0){echo 'disabled'; }?>>Edit Complaint</button>
			<?php } ?>
		</div>
	</div>
	<br>
<?php } ?>

<div class="modal fade" id="attachmentModal">
	<div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Add Attachment</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" id="attachmentForm" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="row">
                        <div class="col">
                            <label for="item"><b>Description</b></label>
                        </div>
                    </div>

                    <div class="row form-group">
                        <div class="col">
                           <textarea class="form-control" rows="5" id="complaint_attachment_desc" placeholder="Attachment's Descriptive Information "></textarea>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-lg-8">
                            <input type="file" class="form-control form-control-sm" placeholder="Upload Attachment" name="complaint_attachment" id="complaint_attachment">
                        </div>
                        <div class="col">
                            <button type="button" onclick="upload_complaint_attachment(<?php echo $data_complaint[0]->id; ?>);" class="btn btn-primary text-white btn-block">Save</button>
                        </div>
                    </div>  
                </div>
            </form>
        </div>
    </div>
</div>

<script>

	$('#complaint_date').datepicker({
			uiLibrary: 'bootstrap4',
			format: 'dd-mm-yyyy'
		});

 	function upload_complaint_attachment(id)
	{
		validateForm("#attachmentForm", "Are you sure you want to upload this attachment?", function(){
			if($('#complaint_attachment').prop('files').length > 0)
			{
				var attachment_data = new FormData();
				
				attachment_data.append("complaint_id", id);
				attachment_data.append("attachment", $('#complaint_attachment').prop('files')[0]);
				attachment_data.append("description", $('#complaint_attachment_desc').val());
				attachment_data.append("class_id", 1);

				$.ajax({
					url: "<?php echo base_url('hr/serviceform/upload_complaint_attachment'); ?>",
					type: "POST",
					data: attachment_data,
					dataType: "JSON",
					processData: false,
					contentType: false,
					success: function(data) {
						if(data.status == 'Success')
						{
							$('#attachmentModal').modal('hide');
							
							localStorage.setItem("status",data.status);
							localStorage.setItem("msg",data.msg);

							location.reload();
						}
					}
				});
			}
		});
	}

    function deleteAttachment(id)
	{
		toastConfirm("Are you sure you want to delete this attachment?", function(){
			$.ajax({
				type: 'POST',
				url: '<?php echo base_url('hr/serviceform/delete_complaint_attachment'); ?>',
				data: {
					'id' : id
				},
				dataType: 'JSON',
				success: function(data) {
					if(data.status == 'Success')
					{
						localStorage.setItem("status",data.status);
						localStorage.setItem("msg",data.msg);

						location.reload();
					}
				}
			});
		})
	}

	function changeClientList(obj)
	{
		var id = obj.value;

		$.ajax({
			type: "POST",
            url: "<?php echo base_url() ?>hr/ServiceForm/getClientList",
            data: "client_type=" + id,
            dataType: "json",
            success: function(content) {
            	if (content.status == "success") {
            		if(id == 1){

            			jQuery("#complaint_client").attr("onchange", "changeClientDetails(this)");
            			jQuery("#complaint_client").empty();
            			jQuery("#complaint_contact_name_int").hide();
            			jQuery("#complaint_contact_name").show();
	                    jQuery("#complaint_client_address").val('');
	                    jQuery("#complaint_contact_no").val('');

            			var items = [];
	                    items.push('<option>Please Select</option>');
	                    for (var i = 0; i < content.message.length; i++) {
	                        items.push('<option value="' + content.message[i].id + '">'
	                                + content.message[i].name + '</option>');
	                    }
	                    
	                    jQuery("#complaint_client").append(items.join('</br>'));
	                    
            		}else{

            			jQuery("#complaint_client").empty();
            			jQuery("#complaint_contact_name").hide();
            			jQuery("#complaint_contact_name_oth").hide();
            			jQuery("#complaint_contact_name_int").show();
	                    jQuery("#complaint_client_address").val('');
	                    jQuery("#complaint_contact_no").val('');

            			var items = [];
	                    items.push('<option>Please Select</option>');
	                    for (var i = 0; i < content.message.length; i++) {
	                        items.push('<option value="' + content.message[i].id + '">'
	                                + content.message[i].name + ' | ' + content.message[i].branch_name + '</option>');
	                    }
	                    
	                    jQuery("#complaint_client").append(items.join('</br>'));
	                    // jQuery("#complaint_client").removeAttr('onchange');
	                    jQuery("#complaint_client").attr("onchange", "changeStaffDetails(this)");
	                    
            		}
            	}else{
            		$("#error").html('<p>' + content.message + '</p>');
            	}
            }
		});
		return false;
	}

	function changeClientDetails(obj) 
    {
        var id = obj.value;

        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>hr/ServiceForm/getClientDetails",
            data: "client_id=" + id,
            dataType: "json",
            success: function(content) {
                if (content.status == "success") {

                	jQuery("#complaint_client_address").val('');
                	jQuery("#complaint_client_address").val(content.message.client_address[0].address1 + ', ' + content.message.client_address[0].address2 );

                	if(content.message.client_contact != null){

                		jQuery("#complaint_contact_name").empty();

		                var items = [];
		                items.push('<option>Please Select</option>');
		                for (var i = 0; i < content.message.client_contact.length; i++) {
		                    items.push('<option value="' + content.message.client_contact[i].id + '">'
		                            + content.message.client_contact[i].name + '</option>');
		                }
		                items.push('<option value="9999">Others</option>');
		                jQuery("#complaint_contact_name").append(items.join('</br>'));
		                jQuery("#complaint_contact_no").val('');

		            }else{

		            	jQuery("#complaint_contact_name").empty();

		            	var items2 = [];
		                items2.push('<option>Please Select</option>');

		                jQuery("#complaint_contact_name").append(items2.join('</br>'));
		                jQuery("#complaint_contact_no").val('');
		               
		            }

                } else {
                    $("#error").html('<p>' + content.message + '</p>');
                }
            }
        });
        return false;
    }

    function changeContactNo(obj)
    {
    	var id = obj.value;

    	if(id == 9999){
    		jQuery("#complaint_contact_name_oth").show();
    		jQuery("#complaint_contact_no").val('0');
    	}else{
    		jQuery("#complaint_contact_name_oth").hide();
			$.ajax({
	            type: "POST",
	            url: "<?php echo base_url() ?>hr/ServiceForm/getContactNo",
	            data: "contact_id=" + id,
	            dataType: "json",
	            success: function(content) {
	                if (content.status == "success") {

	                	jQuery("#complaint_contact_no").empty();
	                	jQuery("#complaint_contact_no").val(content.message[0].phone_mobile + '/ ' + content.message[0].phone_home);

	                } else {
	                    $("#error").html('<p>' + content.message + '</p>');
	                }
	            }
	        });
        	return false;
    	}
    }

    function changeStaffDetails(obj) 
    {
        var id = obj.value;

        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>hr/ServiceForm/getStaffDetails",
            data: "dept_id=" + id,
            dataType: "json",
            success: function(content) {
                if (content.status == "success") {

                	jQuery("#complaint_client_address").val('');
                	jQuery("#complaint_client_address").val(content.message.dept_branch.branch_name);

                	if(content.message.staff_list != null){

                		jQuery("#complaint_contact_name").hide();
                		jQuery("#complaint_contact_name_int").empty();

		                var items = [];
		                items.push('<option>Please Select</option>');
		                for (var i = 0; i < content.message.staff_list.length; i++) {
		                    items.push('<option value="' + content.message.staff_list[i].id + '">'
		                            + content.message.staff_list[i].name + '</option>');
		                }
		                jQuery("#complaint_contact_name_int").append(items.join('</br>'));
		                jQuery("#complaint_contact_no").val('');

		            }else{

		            	jQuery("#complaint_contact_name_int").empty();

		            	var items2 = [];
		                items2.push('<option>Please Select</option>');

		                jQuery("#complaint_contact_name_int").append(items2.join('</br>'));
		                jQuery("#complaint_contact_no").val('');
		               
		            }

                } else {
                    $("#error").html('<p>' + content.message + '</p>');
                }
            }
        });
        return false;
    }

    function changeStaffContactNo(obj)
    {
    	var id = obj.value;

		$.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>hr/ServiceForm/getStaffContactNo",
            data: "staff_id=" + id,
            dataType: "json",
            success: function(content) {
                if (content.status == "success") {

                	jQuery("#complaint_contact_no").empty();
                	jQuery("#complaint_contact_no").val(content.message.phone);

                } else {
                    $("#error").html('<p>' + content.message + '</p>');
                }
            }
        });
        return false;
    }

	function changeJobList(obj) 
    {
        var id = obj.value;

        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>crm/customer/getJob",
            data: "service_id=" + id,
            dataType: "json",
            success: function(content) {

                if (content.status == "success") {

                    var items = [];
                    items.push('<option>Please Select</option>');
                    for (var i = 0; i < content.message.length; i++) {
                        items.push('<option value="' + content.message[i].id + '">'
                                + content.message[i].job + '</option>');
                    }
                    jQuery("#job").empty();
                    jQuery("#job").append(items.join('</br>'));
                } else {
                    $("#error").html('<p>' + content.message + '</p>');
                }
            }
        });
        return false;
    }

    function openOthers_method(obj)
    {
    	var id = obj.value;

		if(id == 7){ //others
    		jQuery("#complaint_method_others").show();
    	}else{
    		jQuery("#complaint_method_others").hide();
    	}
    }

    function openOthers_about(obj)
    {
    	var id = obj.value;

		if(id == 8){ //others
    		jQuery("#complaint_about_others").show();
    	}else{
    		jQuery("#complaint_about_others").hide();
    	}
    }

    function saveComplaint()
	{
		if($('#complaint_client_type_internal').is(':checked')) {
			var complaint_for = 0; 
		} else if($('#complaint_client_type_external').is(':checked')) {
			var complaint_for = 1; 
		} else{
			return;
		}

		if($('#complaint_type_initial').is(':checked')) {
			var complaint_type = 0; 
		} else if($('#complaint_type_follow').is(':checked')) {
			var complaint_type = 1; 
		} else{
			return;
		}

		if($('#complaint_urgency_yes').is(':checked')) {
			var urgency = 1; 
		} else if($('#complaint_urgency_no').is(':checked')) {
			var urgency = 0; 
		} else{
			return;
		}

		var complaint_method = []
		$("input:checkbox[name=complaint_method]:checked").each(function(){
		    complaint_method.push($(this).val());
		}); 

		var complaint_about = []
		$("input:checkbox[name=complaint_about]:checked").each(function(){
		    complaint_about.push($(this).val());
		}); 

		if($('#complaint_contact_name').val() == 9999){
			var contact_name = $('#complaint_contact_name_oth').val();
		}else{
			var contact_name = $('#complaint_contact_name_int').val();
		}

		var postData = {
			'complaint_for' 	: complaint_for,
			'dept_id'			: $('#complaint_dept_id').val(),
			'services_id'		: $('#services').val(),
			'job_id'			: $('#job').val(),
			'client_id'			: $('#complaint_client').val(),
			'client_address'	: $('#complaint_client_address').val(),
			'contact_id'		: $('#complaint_contact_name').val(),
			'contact_name'		: contact_name,
			'phone_no' 			: $('#complaint_contact_no').val(),
			'business_impact'	: $('#complaint_business_impact').val(),
			'addressee_id'		: $('#complaint_addressee').val(),
			'date'				: $('#complaint_date').val(),
			'complaint_type'	: complaint_type,
			'complaint_details'	: $('#complaint_details').val(),
			'reso_desired'		: $('#complaint_reso').val(),
			'urgency'			: urgency,
			'complaint_method'	: complaint_method,
			'complaint_about'	: complaint_about,
			'complaint_method_others'	: $('#complaint_method_others').val(),
			'complaint_about_others'	: $('#complaint_about_others').val()
		};

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '<?php echo base_url(); ?>hr/ServiceForm/saveComplaint',
			data: postData,
			success: function(data) {
				window.location.href = "<?php echo base_url().'hr/serviceform/complaint_list'?>";
			}
		});
	}

	function savePIC($id)
	{
		var pic_id = $('#complaint_pic').val();
		
		if(pic_id == '' || pic_id == 0){
			alert('Please select Person In Charge');
			return;
		}

		var postData = {
			'id' 	  : $id,
			'pic_id'  : pic_id,
			'remarks' : $('#complaint_remarks').val()
		}

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '<?php echo base_url(); ?>hr/ServiceForm/saveComplaintPIC',
			data: postData,
			success: function(data) {
				window.location.href = "<?php echo base_url().'hr/serviceform/complaint_list'?>";
			}
		});
	}

	function openComplaintReso($id)
	{
		// window.location.href = "<?php //echo base_url().'hr/serviceform/complaint_reso/'?>" + $id;
		window.location.href = "<?php echo base_url().'hr/serviceform/complaint_reso/'?>" + $id + '/view';
	}

	function verifyComplaint($id)
	{
		var postData = {
			'id' 	  : $id,
			'remarks' : $('#complaint_remarks').val()
		}

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '<?php echo base_url(); ?>hr/ServiceForm/verifyComplaint',
			data: postData,
			success: function(data) {
				window.location.href = "<?php echo base_url().'hr/serviceform/complaint_list/'?>";
			}
		});
	}

	function saveEditComplaint($id)
	{
		if($('#complaint_client_type_internal').is(':checked')) {
			var complaint_for 	= 0; 
			var contact_id 		= $('#complaint_contact_name_int').val();
		} else if($('#complaint_client_type_external').is(':checked')) {
			var complaint_for 	= 1; 
			var contact_id 		= $('#complaint_contact_name').val();
		} else{
			return;
		}

		if($('#complaint_type_initial').is(':checked')) {
			var complaint_type = 0; 
		} else if($('#complaint_type_follow').is(':checked')) {
			var complaint_type = 1; 
		} else{
			return;
		}

		if($('#complaint_urgency_yes').is(':checked')) {
			var urgency = 1; 
		} else if($('#complaint_urgency_no').is(':checked')) {
			var urgency = 0; 
		} else{
			return;
		}

		var complaint_method = []
		$("input:checkbox[name=complaint_method]:checked").each(function(){
		    complaint_method.push($(this).val());
		}); 

		var complaint_about = []
		$("input:checkbox[name=complaint_about]:checked").each(function(){
		    complaint_about.push($(this).val());
		}); 

		if($('#complaint_contact_name').val() == 9999){
			var contact_name = $('#complaint_contact_name_oth').val();
		}else{
			var contact_name = 0;
		}

		var postData = {
			'id'				: $id,
			'complaint_for' 	: complaint_for,
			'ref_no'			: $('#complaint_ref_no').val(),
			'dept_id'			: $('#complaint_dept_id').val(),
			'services_id'		: $('#services').val(),
			'job_id'			: $('#job').val(),
			'client_id'			: $('#complaint_client').val(),
			'client_address'	: $('#complaint_client_address').val(),
			'contact_id'		: contact_id,
			'contact_name'		: contact_name,
			'phone_no' 			: $('#complaint_contact_no').val(),
			'email' 			: $('#complaint_contact_email').val(),
			'business_impact'	: $('#complaint_business_impact').val(),
			'addressee_id'		: $('#complaint_addressee').val(),
			'date'				: $('#complaint_date').val(),
			'complaint_type'	: complaint_type,
			'complaint_details'	: $('#complaint_details').val(),
			'reso_desired'		: $('#complaint_reso').val(),
			'urgency'			: urgency,
			'complaint_method'	: complaint_method,
			'complaint_about'	: complaint_about,
			'complaint_method_others'	: $('#complaint_method_others').val(),
			'complaint_about_others'	: $('#complaint_about_others').val()
			// 'attachments'		: attachments
		};

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '<?php echo base_url(); ?>hr/ServiceForm/saveEditComplaint',
			data: postData,
			success: function(data) {
				window.location.href = "<?php echo base_url().'hr/serviceform/complaint_form_edit/'?>"+$id;
			}
		});
	}

	function approveComplaint(id){
        toastConfirm('Are you sure you want to approve this Complaint?',function(){
            // var status = $('#complaint_client_satisfy').val();
            
            // if(status == '' || status == null){
            //     alert('Please select Client Satisfaction');
            //     return;
            // }

            var postData = {
                'complaint_id'  : id
                // 'status'        : status
            }

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '<?php echo base_url(); ?>hr/ServiceForm/approveComplaint',
                data: postData,
                success: function(data) {
                    localStorage.setItem("status", data.status);
                    localStorage.setItem("msg", data.msg);

                    location.reload();
                }
            });
        });
    }

</script>