337 lines
15 KiB
PHP
Executable File
337 lines
15 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">Outsourcing List</h4>
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<li class=""> <a href="#" data-toggle="modal" data-target="#os-add-modal" class="btn btn-primary waves-effect" onclick="clearDetials(this)"> Add Outsourcing</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-outsource" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;">
|
|
<thead>
|
|
<tr>
|
|
<th>Out Sourcing</th>
|
|
<th>Unit Price (Including Tax)</th>
|
|
<th>Tax</th>
|
|
<th>Labour Charge</th>
|
|
<th>Description</th>
|
|
<th hidden>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($out_source as $index => $value) :
|
|
$color = '';
|
|
if($value['is_active'] == 0){
|
|
$color ='red';
|
|
}?>
|
|
<tr class="outsource_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" >
|
|
<td><?= $value['name']; ?></td>
|
|
<td><?= $value['cost_with_tax']; ?></td>
|
|
<td><?= $value['tax']; ?></td>
|
|
<td><?= $value['labour_cost']; ?></td>
|
|
<td><?= $value['description']; ?></td>
|
|
<td hidden>
|
|
<?php if($value['is_active'] == 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['is_active'] == 1){ ?>
|
|
<a data-toggle="modal" data-target="#os-add-modal" data-value="<?php echo $value['id']; ?>" onclick="editOS(this), datatableOutSource('outsource_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['is_active'] == 1): ?>
|
|
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Deactivate" onclick="statusChange(this), datatableOutSource('outsource_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['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Activate" onclick="statusChange(this), datatableOutSource('outsource_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user mr-2" style="font-size:20px"></i>Activate</a>
|
|
<?php endif; ?> </div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
</div>
|
|
</div> <!-- end card -->
|
|
</div> <!-- end col -->
|
|
</div>
|
|
|
|
<!-- /.modal -->
|
|
<div id="os-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">Create Out Source</h4>
|
|
</div>
|
|
<form id="outsource_form" class="px-3">
|
|
<div class="form-group">
|
|
<label for="name">Name </label>
|
|
<input class="form-control" type="text" id="id" hidden>
|
|
<input class="form-control" type="text" id="name" required="" placeholder="Name">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="cost_with_tax">Unit Price (Including Tax)</label>
|
|
<input class="form-control" type="number" id="cost_with_tax" name="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="">Select Tax</option>
|
|
<option value="18">18%</option>
|
|
<option value="28" >28%</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="labour_cost">Labour Cost </label>
|
|
<input class="form-control" type="text" id="labour_cost" placeholder="Labour Charge" required readonly>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="description">Description </label>
|
|
<input class="form-control" type="text" id="description" placeholder="Description" >
|
|
</div>
|
|
<div class="form-group text-center">
|
|
<button class="btn btn-rounded btn-primary" type="submit" id="outsource_submit_button" onclick="submitComplaint(this, event)">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());
|
|
if(tax == ''){
|
|
toastr.warning('Please select Tax', 'Warning');
|
|
}else{
|
|
var labour_cost_with_tax = parseFloat($("#cost_with_tax").val());
|
|
var labour_cost = labour_cost_with_tax / parseFloat((tax / 100) + 1);
|
|
|
|
$("#labour_cost").val(labour_cost.toFixed(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function submitComplaint(params, event) {
|
|
$(params).attr('disabled', true).text('Processing...');
|
|
if (!$('#name').val() || !$('#labour_cost').val() ) {
|
|
return false;
|
|
}
|
|
if(!$('#cost_with_tax').val()){
|
|
return false;
|
|
}
|
|
|
|
var formData = {
|
|
id: $('#id').val(),
|
|
name: $('#name').val(),
|
|
labour_cost: $('#labour_cost').val(),
|
|
tax: $('#tax').val(),
|
|
cost_with_tax: $('#cost_with_tax').val(),
|
|
description: $('#description').val(),
|
|
};
|
|
$('#outsource_submit_button').attr('disabled', 'true');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."create_os"?>',
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
// $('#outsource_submit_button').removeAttr('disabled');
|
|
console.log(response);
|
|
// Reload the page after successful submission
|
|
if (response.code === 404) {
|
|
toastr.warning(response.data, 'Warning');
|
|
$(params).attr('disabled', false).text('Submit');
|
|
$('#outsource_form')[0].reset();
|
|
return;
|
|
}
|
|
|
|
if (response.code === 200 || response.status === 'success') {
|
|
toastr.success(response.data, 'Success');
|
|
window.location.reload();
|
|
} else {
|
|
toastr.warning(response.data || "Unexpected error occurred!", 'Warning');
|
|
$(params).attr('disabled', false).text('Submit');
|
|
$('#outsource_form')[0].reset();
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
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');
|
|
$('#outsource_form')[0].reset();
|
|
}
|
|
});
|
|
}
|
|
|
|
function editOS(params) {
|
|
var id = $(params).data('value');
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '<?php echo base_url()."edit_os/"?>' + id,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
console.log(response.os_data[0].id);
|
|
$('#form_add_edit').html(response.page_name)
|
|
$('#id').val(response.os_data[0].id);
|
|
$('#name').val(response.os_data[0].name);
|
|
$('#labour_cost').val(response.os_data[0].labour_cost);
|
|
$('#cost_with_tax').val(response.os_data[0].cost_with_tax);
|
|
$('#description').val(response.os_data[0].description);
|
|
|
|
var tax = parseFloat(response.os_data[0].tax);
|
|
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;
|
|
}
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
function clearDetials(params) {
|
|
$('#form_add_edit').text('Create Out Source');
|
|
$('#outsource_form')[0].reset();
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
var datatable_outsource ='';
|
|
$(document).ready(function() {
|
|
|
|
datatable_outsource = $('#datatable-outsource').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');
|
|
// console.log(savedPage);
|
|
// console.log(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_outsource.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_outsource.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 datatableOutSource(value) {
|
|
console.log(value);
|
|
|
|
var currentPage = datatable_outsource.page.info().page;
|
|
sessionStorage.setItem('currentPage', currentPage);
|
|
sessionStorage.setItem('hightlight_tr', value);
|
|
|
|
}
|
|
|
|
|
|
function statusChange(params) {
|
|
var status = params.getAttribute('data-isactive');
|
|
var outsource_id = params.getAttribute('data-id');
|
|
if(status == 1){
|
|
var isactive= 0;
|
|
}else{
|
|
var isactive= 1;
|
|
}
|
|
|
|
var formData = {
|
|
outsource_id: outsource_id,
|
|
isactive: isactive
|
|
};
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."status_outsource"?>',
|
|
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>
|