the_mechanic/app/Views/complaint_list.php

351 lines
16 KiB
PHP
Executable File

<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Complaints List</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class=""> <a href="#" data-toggle="modal" data-target="#complaint-add-modal" class="btn btn-primary waves-effect" onclick="clearDetials(this)"> Add Complaint</a></li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<table id="datatable-complaint" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;">
<thead>
<tr>
<th>Complaint</th>
<th>Unit Price (Including Tax)</th>
<th>Tax</th>
<th>Labour Charge</th>
<th hidden>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($complaint as $index => $value) :
$color = '';
if($value['isactive'] == 0){
$color ='red';
}
$cubiccapacity_name = ''; // Default to empty if no match
// Loop through $cubiccapacity to find a match
foreach ($cubiccapacity as $cc) {
if ($cc['id'] == $value['cubic_capacity_id']) {
$cubiccapacity_name = ' ( '.$cc['value'].' )'; // Get the name of the matching cubiccapacity
break;
}
}
?>
<tr class="complaint_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" > <td><?= $value['name'].$cubiccapacity_name;; ?></td>
<td><?= $value['labour_cost_with_tax'] ?></td>
<td><?= $value['tax']; ?></td>
<td><?= $value['labour_charge']; ?></td>
<td hidden>
<?php if($value['isactive'] == 1): ?>
<span style="color:green">Active</span>
<?php else: ?>
<span style="color:red">Inactive</span>
<?php endif; ?>
</td>
<td>
<div class="btn-group dropdown">
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<?php if($value['isactive'] == 1){ ?>
<a data-toggle="modal" data-target="#complaint-add-modal" data-value="<?php echo $value['complaint_id']; ?>" onclick="editComplaint(this), datatableComplaint('complaint_tr_<?php echo $index+1; ?>')" class="dropdown-item edit-button"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<?php } if($value['isactive'] == 1): ?>
<a class="dropdown-item" data-id="<?php echo $value['complaint_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Deactivate" onclick="statusChange(this), datatableComplaint('complaint_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user " style="font-size:20px"></i><i class="fa fa-times mr-2" style="font-size: x-small;" style="font-size:20px"></i>Deactivate</a>
<?php else: ?>
<a class="dropdown-item" data-id="<?php echo $value['complaint_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Activate" onclick="statusChange(this), datatableComplaint('complaint_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user mr-2" style="font-size:20px"></i>Activate</a>
<?php endif; ?> </div>
</div>
</td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<!-- /.modal -->
<div id="complaint-add-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="text-center mt-2 mb-4">
<h4 id="form_add_edit">Add Complaint</h4>
</div>
<form id="model_form_data" class="px-3">
<div class="form-group">
<label for="name">Complaint </label>
<input class="form-control" type="text" id="complaint_id" hidden>
<input class="form-control" type="text" id="name" required="" placeholder="Complaint">
</div>
<div class="form-group">
<label for="cubic_capacity">Cubic capacity</label>
<select class="form-control" id="cubic_capacity" name="cubic_capacity" required data-toggle="select2">
<option value="0">Select Cubic capacity</option>
<?php foreach ($cubiccapacity as $item): ?>
<option value="<?= $item['id'] ?>"><?= $item['value'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="labour_cost_with_tax">Unit Price (Including Tax)</label>
<input class="form-control" type="number" id="labour_cost_with_tax" name="labour_cost_with_tax" placeholder="Total Price" step="0.01" min="0" onkeyup="ReverseCalculation()" required>
</div>
<div class="form-group">
<label for="labour_charge">Tax </label>
<select class="form-control status-select" id="tax" name="tax" required data-toggle="select2" onchange="ReverseCalculation()">
<option value="0">Select Tax</option>
<option value="18">18%</option>
<option value="28" >28%</option>
</select>
</div>
<div class="form-group">
<label for="labour_charge">Labour Charge </label>
<input class="form-control" type="text" id="labour_charge" placeholder="Labour Charge" required readonly>
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitComplaint(this)">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php include('layout/footer.php'); ?>
<script>
function ReverseCalculation() {
var tax = parseFloat($("#tax").val());
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
if(labour_cost_with_tax == ''){
toastr.warning('Please select Tax', 'Warning');
return;
}else{
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
var labour_cost = labour_cost_with_tax / parseFloat((tax / 100) + 1);
$("#labour_charge").val(labour_cost.toFixed(2));
}
}
function submitComplaint(params) {
// console.log(':)',$('#cubic_capacity_id').val());return false;
if (!$('#name').val() || !$('#labour_charge').val()) {
return false;
}
console.log($('#cubic_capacity_id').val());
var tax = parseFloat($("#tax").val());
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
if(labour_cost_with_tax == '' || tax == ''){
toastr.warning('Please select Tax', 'Warning');
return;
}
// if($(!'#cubic_capacity').val()){
// toastr.warning('Please select Cubic capacity', 'Warning');
// return;
// }
var formData = {
name: $('#name').val(),
labour_charge: $('#labour_charge').val(),
tax: tax,
labour_cost_with_tax: labour_cost_with_tax,
cubic_capacity_id: $('#cubic_capacity').val(),
};
var complaint_id = $('#complaint_id').val();
if (!complaint_id) {
complaint_id = 0;
}
$(params).attr('disabled', true).text('Processing...');
$.ajax({
type: 'POST',
url: '<?php echo base_url()."create_complaint/"?>' + complaint_id,
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.code === 404) {
toastr.warning(response.data, 'Warning');
$(params).attr('disabled', false).text('Submit');
return;
}
if (response.code === 200) {
toastr.success(response.data, 'Success');
window.location.reload();
} else {
toastr.warning(response.data || "Unexpected error occurred!", 'Warning');
$(params).attr('disabled', false).text('Submit');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
let errorMessage = "An error occurred while processing your request.";
if (xhr.responseJSON && xhr.responseJSON.data) {
errorMessage = xhr.responseJSON.data;
}
toastr.warning(errorMessage, 'Warning');
$(params).attr('disabled', false).text('Submit');
}
});
}
function editComplaint(params) {
var complaint_id = $(params).data('value');
$.ajax({
type: 'GET',
url: '<?php echo base_url()."edit_complaint/"?>' + complaint_id,
dataType: 'json',
success: function(response) {
$('#form_add_edit').html(response.page_name)
$('#complaint_id').val(response.complaint[0].complaint_id);
$('#name').val(response.complaint[0].name);
$('#labour_charge').val(response.complaint[0].labour_charge);
$('#labour_cost_with_tax').val(response.complaint[0].labour_cost_with_tax);
var cc_id = response.complaint[0].cubic_capacity_id;
var tax = parseFloat(response.complaint[0].cgst) + parseFloat(response.complaint[0].sgst);
var selectElement = document.getElementById('tax');
var options = selectElement.options;
for (var i = 0; i < options.length; i++) {
if (parseInt(options[i].value) === tax) {
options[i].selected = true;
break;
}
}
var selectElementForCC = document.getElementById('cubic_capacity');
var ccOptions = selectElementForCC.options;
for (var j = 0; j < ccOptions.length; j++) {
if (ccOptions[j].value === cc_id) {
ccOptions[j].selected = true;
break;
}
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function clearDetials(params) {
$('#form_add_edit').text('Add Complaint');
$('#model_form_data')[0].reset();
}
</script>
<script>
var datatable_complaint ='';
$(document).ready(function() {
datatable_complaint = $('#datatable-complaint').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF',},
{extend: 'print',title: 'Products',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
{extend: 'csv',text: 'CSV', title: 'Products', }],
"language": {
"search": "Search: " // Customize search label
},
});
//Start DataTable Paging is session is set
var savedPage = sessionStorage.getItem('currentPage');
var hightlight_tr = sessionStorage.getItem('hightlight_tr');
// Ensure savedPage is a number
savedPage = parseInt(savedPage);
// Check if savedPage is not null and adjust if necessary
if (savedPage !== null && !isNaN(savedPage)) {
// Check if the saved page number is within the bounds of the current DataTable
var totalPages = datatable_complaint.page.info().pages; // Total number of pages in the DataTable
if (savedPage >= totalPages) {
// adjust to the last page of the DataTable
savedPage = totalPages > 0 ? totalPages - 1 : 0;
}
// Move DataTable to the saved page and draw
datatable_complaint.page(savedPage).draw(false);
// Select the highlighted row
var $row = $('.' + hightlight_tr);
// Smoothly scroll to the row and center it in the viewport
$('html, body').animate({
scrollTop: $row.offset().top - ($(window).height() / 2) + ($row.height() / 2)
}, 500, function() {
// After focusing, change background color
$row.css('background', '#faf6ca');
// Remove background color after 4 seconds
setTimeout(function() {
$row.css('background', '');
}, 4000);
});
}
sessionStorage.removeItem('currentPage');
sessionStorage.removeItem('hightlight_tr');
//End DataTable Paging is session is set
})
function datatableComplaint(value) {
console.log(value);
var currentPage = datatable_complaint.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var complaint_id = params.getAttribute('data-id');
if(status == 1){
var isactive= 0;
}else{
var isactive= 1;
}
var formData = {
complaint_id: complaint_id,
isactive: isactive
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_complaint"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.status == "success") {
window.location.reload();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>