csrtechnew.ohctech.in/add_placement_feedback.php
2025-08-29 16:30:39 +05:30

439 lines
20 KiB
PHP

<style>
/* Enhanced modal styling */
.modal-content {
border-radius: 8px;
overflow: hidden;
}
.modal-header {
border-bottom: 1px solid #ddd;
padding: 16px;
}
.modal-body {
padding: 24px;
}
.form-group {
margin-bottom: 1.5rem;
}
.btn-info,
.btn-danger {
border-radius: 4px;
}
.form-control {
border-radius: 4px;
}
.widget-title {
font-size: 1.25rem;
font-weight: bold;
}
</style>
<div class="modal fade" id="modal-add-placement_feedback" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalLabel">Placement Follow Up</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="placement_feedback_form" name="placement_feedback_form" action="#" method="post">
<div class="modal-body">
<div class="form-row">
<div class="form-group col-sm-6">
<label for="batch_name">Batch Name</label>
<select class="form-control select2" name="batch_name" id="batch_name" onchange="fetch_beneficiary()">
<option value="" disabled selected>Please Select Batch Name</option>
<?php
$ohc_type_id = $_SESSION['current_ohcttype'];
$voa = "VOA";
$option_query = "SELECT batch_id FROM training_batch_enrollment WHERE status = '$voa' AND ohc_type_id = '$ohc_type_id'";
$option_arry = mysqli_query($conn, $option_query);
while ($op = mysqli_fetch_array($option_arry)) {
echo generateOptionWithWhereClause('training_batch_master', 'batch_name', 'batch_id', $row['batch_name'], '', 'batch_id', $op['batch_id']);
}
?>
</select>
</div>
<div class="form-group col-sm-6">
<label for="beneficiary">Beneficiary</label>
<select id="beneficiary" name="beneficiary" class="test form-control select2" onchange="check_followup();setDOJ();">
<option value="" selected disabled>Please Select Beneficiary</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">
<label for="placement_name">Supplier/Employer Name</label>
<select id="placement_name" name="placement_name" class="form-control select2" onchange="fetchPlacementInfo(this.value);selfEmployer();">
<option value="">Please Select Placement Employer Name</option>
<?php
$sql = "SELECT p.partner_id, p.partner_name, p.partner_location, cm.client_name FROM partners p INNER JOIN client_master cm ON p.partner_name = cm.id";
$result = mysqli_query($conn, $sql);
if ($result && mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['partner_id'] . "'>" . $row['client_name'] . " (" . $row['partner_location'] . ")</option>";
}
}
?>
</select>
</div>
<div id="self_emplyer_show" style="display: none;">
<div class="form-group col-sm-6">
<label for="location">Location</label>
<input class="form-control" type="text" id="location" name="location" placeholder="Enter Location">
</div>
</div>
<div class="form-group col-sm-6">
<label for="staff_id">Placement Coordinator</label>
<select id="staff_id" name="staff_id" class="form-control select2">
<option value="" selected disabled>Please Select Placement Coordinator</option>
<?php echo generateOptionWithWhereClause('staff_master', 'staff_name', 'staff_id', '', '', 'ohc_type', $ohc_type_id); ?>
</select>
</div>
<div id="self_emplyer_hide" style="display: none;">
<div class="form-group col-sm-6">
<label for="beneficiary">Contact Person Name</label>
<input class="form-control" type="text" id="person" name="person" placeholder="Contact Person Name" disabled>
</div>
<div class="form-group col-sm-6">
<label for="beneficiary">Contact Number</label>
<input class="form-control" type="text" id="contact" name="contact" placeholder="Contact Number" disabled>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">
<input type="hidden" name="feedback_id" id="feedback_id" />
<label for="follow_up_routine">Follow Up Routine</label>
<select id="follow_up_routine" name="follow_up_routine" class="form-control select2" onchange="check_followup();check_salary();">
<option value="" selected disabled>Please Select Follow Up Routine</option>
<option value="First Follow Up">First Follow Up</option>
<option value="Second Follow Up">Second Follow Up</option>
<option value="Third Follow Up">Third Follow Up</option>
</select>
</div>
<div class="form-group col-sm-6">
<label for="salary">Date Of Joining</label>
<input type="text" class="form-control" name="doj" id="doj" placeholder="Date Of Joining" disabled />
</div>
<div class="form-group col-sm-6">
<label for="salary">Previous Salary</label>
<input type="text" class="form-control" name="salary" id="salary" placeholder="Previous Salary" />
</div>
</div>
<!-- <div class="form-row">
<div class="form-group col-sm-6">
<label for="technical_skill">Technical Skill</label>
<select id="technical_skill" name="technical_skill" class="form-control select2">
<option value="" selected disabled>Please Select Technical Skill Feedback</option>
<?php for ($i = 1; $i <= 10; $i++) {
echo "<option value='$i'>$i</option>";
} ?>
</select>
</div>
<div class="form-group col-sm-6">
<label for="behaviour">Behaviour</label>
<select id="behaviour" name="behaviour" class="form-control select2">
<option value="" selected disabled>Please Select Behaviour Feedback</option>
<?php for ($i = 1; $i <= 10; $i++) {
echo "<option value='$i'>$i</option>";
} ?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">
<label for="communication">Communication</label>
<select id="communication" name="communication" class="form-control select2">
<option value="" selected disabled>Please Select Communication Feedback</option>
<?php for ($i = 1; $i <= 10; $i++) {
echo "<option value='$i'>$i</option>";
} ?>
</select>
</div>
<div class="form-group col-sm-6">
<label for="performance">Performance</label>
<select id="performance" name="performance" class="form-control select2">
<option value="" selected disabled>Please Select Performance Feedback</option>
<?php for ($i = 1; $i <= 10; $i++) {
echo "<option value='$i'>$i</option>";
} ?>
</select>
</div>
</div> -->
<div class="form-row">
<div class="form-group col-sm-6">
<label for="promotion">Promoted</label>
<select id="promotion" name="promotion" class="form-control" onchange="promotionStatus()">
<option value="" selected disabled>Select Promotion Status</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Not Retained">Not Retained</option>
</select>
</div>
<div id="pmr_field" style="display: none;">
<div class="form-group col-sm-6">
<label for="remark">New Salary</label>
<input type="number" class="form-control" name="new_salary" id="new_salary" placeholder="New Salary" />
</div>
<div class="form-group col-sm-6">
<label for="remark">Post</label>
<input type="text" class="form-control" name="post" id="post" placeholder="Enter Post" />
</div>
</div>
<div class="form-group col-sm-6">
<label for="remark">Remarks</label>
<input type="text" class="form-control" name="remark" id="remark" maxlength="100" placeholder="Add Remarks" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" onclick="validate();">Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
</div>
<script>
function selfEmployer() {
var partner_name = $('#placement_name').val();
if (partner_name == 27) {
$('#self_emplyer_hide').hide();
$('#self_emplyer_show').show();
} else {
$('#self_emplyer_hide').show();
$('#self_emplyer_show').hide();
}
}
function fetchPlacementInfo(partnerName) {
$.ajax({
url: 'fetchPlacementInfo.php',
data: {
partner_id: partnerName, // Send partner ID
},
type: 'POST',
dataType: 'json',
success: function(response) {
// Assuming the response is already in JSON format
$('#contact').val(response.partner_phone);
$('#person').val(response.contact_person);
},
error: function() {
BootstrapDialog.alert('Error Populating Check Registration Function');
}
});
}
function validate() {
var isValid = true;
$('.text-danger').text(''); // Clear previous error messages
// Check required fields
if ($('#batch_name').val() === '') {
BootstrapDialog.alert('Please select Batch Name.');
isValid = false;
} else if ($('#follow_up_routine').val() === '') {
BootstrapDialog.alert('Please select Follow Up Routine.');
isValid = false;
} else if ($('#placement_name').val() === '') {
BootstrapDialog.alert('Please select Placement Employer Name.');
isValid = false;
} else if ($('#beneficiary').val() === '') {
BootstrapDialog.alert('Please select Beneficiary.');
isValid = false;
} else if ($('#salary').val() === '') {
BootstrapDialog.alert('Salary is required.');
isValid = false;
} else if (isNaN($('#salary').val())) {
BootstrapDialog.alert('Please enter a valid positive number for the salary.');
isValid = false;
} else if ($('#remark').val() === '') {
BootstrapDialog.alert('Remarks are required.');
isValid = false;
}
// Submit form if all fields are valid
if (isValid) {
save_feedback();
}
}
function fetch_beneficiary() {
var batchid = $('#batch_name').val();
var beneficiary = <?php
$beneficiary = [];
if ($result = $conn->query("SELECT beneficiary_id, batch_id FROM training_batch_enrollment_beneficiary")) {
while ($row = $result->fetch_assoc()) {
$beneficiary_name = getFieldFromTable('patient_name', 'patient_master', 'id', $row['beneficiary_id']);
$beneficiary[$row['batch_id']][] = ['beneficiary_id' => $row['beneficiary_id'], 'beneficiary_name' => $beneficiary_name];
}
}
echo json_encode($beneficiary);
?>;
$('.test').empty().append('<option value="" disabled selected>Select Beneficiary</option>');
if (beneficiary[batchid]) {
$.each(beneficiary[batchid], function(index, ben) {
$('.test').append('<option value="' + ben.beneficiary_id + '">' + ben.beneficiary_name + '</option>');
});
}
}
function check_followup() {
var batchid = $('#batch_name').val();
var beneficiary = $('#beneficiary').val();
var follow_up_routine = $('#follow_up_routine').val();
// Validate that necessary fields are not empty or invalid
if (batchid && beneficiary && follow_up_routine) {
$.ajax({
url: 'check_followup.php',
data: {
batchid: batchid,
beneficiary: beneficiary,
follow_up_routine: follow_up_routine
},
type: 'POST',
dataType: 'json',
success: function(data) {
if (data.complete === 'yes') {
BootstrapDialog.alert(follow_up_routine + ' has already been completed.');
$('#beneficiary').val("").trigger('change'); // Clear and reset select2
$('#follow_up_routine').val("").select2(); // Clear and reset select2
return;
}
if (data.follow_up === 'not_completed') {
BootstrapDialog.alert('Previous Follow-up has not been completed.');
$('#follow_up_routine').val("").select2(); // Clear and reset select2
return;
}
},
error: function(xhr, status, error) {
// Provide a more detailed error message based on the response status
var errorMessage = 'An error occurred. Please try again.';
if (xhr.status === 404) {
errorMessage = 'Requested resource not found (404).';
} else if (xhr.status === 500) {
errorMessage = 'Server error occurred. Please contact support (500).';
} else if (xhr.status === 0) {
errorMessage = 'Network error. Please check your internet connection.';
}
BootstrapDialog.alert(errorMessage);
}
});
}
}
function check_salary() {
var batchid = $('#batch_name').val();
var beneficiary = $('#beneficiary').val();
// alert(beneficiary);
// alert(batchid);
// var follow_up_routine = $('#follow_up_routine').val();
// Make sure that necessary inputs are not empty
if (batchid && beneficiary) {
$.ajax({
url: 'check_salary.php',
data: {
batchid: batchid,
beneficiary: beneficiary,
},
type: 'POST',
dataType: 'json',
success: function(data) {
if (data.salary) {
$('#salary').val(data.salary); // Correct selector
} else {
// Handle case where no salary data is returned
$('#salary').val('0000');
}
},
error: function(xhr, status, error) {
// Log error to the console or display an error message
console.error('Error: ' + status + ' - ' + error);
$('#salary').val('Error fetching salary');
}
});
} else {
// Optionally handle the case where the form is incomplete
$('#salary').val('');
}
}
function promotionStatus() {
var promotion = $('#promotion').val();
if (promotion == 'Yes') {
$('#pmr_field').show();
} else {
$('#pmr_field').hide();
}
}
function setDOJ() {
var batchid = $('#batch_name').val();
var beneficiary = $('#beneficiary').val();
// Ensure both batchid and beneficiary are selected
if (batchid && beneficiary) {
$.ajax({
url: 'check_doj.php',
data: {
batchid: batchid,
beneficiary: beneficiary,
},
type: 'POST',
dataType: 'json',
success: function(data) {
// Check if 'data.doj' exists, otherwise set to 'NA' or handle accordingly
if (data.doj) {
$('#doj').val(data.doj); // Set the Date of Joining value
} else {
$('#doj').val('NA'); // Handle case when no DOJ is returned
}
},
error: function(xhr, status, error) {
// Handle AJAX request failure
console.error('Error fetching DOJ: ' + error);
$('#doj').val('Error'); // Optionally, show error message in the field
}
});
} else {
// If batchid or beneficiary is not selected, reset the DOJ field
$('#doj').val('');
}
}
</script>