bb_sign/app/Views/service_list.php
2024-06-28 15:27:36 +05:30

356 lines
15 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- ============================================================== -->
<!-- Start Page Content here -->
<!-- ============================================================== -->
<div class="content-page">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Service List</h4>
<div class="page-title-right">
<a data-toggle="modal" data-target="#con-close-modal" class="btn btn-primary waves-effect waves-light">
Create Service
</a>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table id="service_table" class="table table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0" >
<thead class="bg-light">
<tr>
<th>Group Name</th>
<th>Service Name</th>
<th>Description</th>
<th>No Of Templates</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody class="font-14">
<?php foreach ($serviceList as $key => $value) { ?>
<tr>
<td><?php echo $value['group_name']; ?></td>
<td><?php echo $value['service_name']; ?></td>
<td><?php echo $value['notes']; ?></td>
<td><?php echo $value['template_count']; ?></td>
<td>
<?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">
<a class="dropdown-item" data-id="<?php echo $value['service_id']; ?>" onclick="getServiceData(this)" > <i class='mdi mdi-pencil-outline mr-1' style="margin-right: 16px !important;margin-left: 5px;"></i>Edit</a>
<?php if($value['is_active'] == 1): ?>
<a class="dropdown-item" data-id="<?php echo $value['service_id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Deactivate" onclick="statusChange(this)"><i class="ri-service-line"></i><i class="fa fa-times" style="font-size: x-small;margin-right:10px"></i>Deactivate</a>
<?php else: ?>
<a class="dropdown-item" data-id="<?php echo $value['service_id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Activate" onclick="statusChange(this)"><i class="ri-service-line" style="margin-right:10px"></i>Activate</a>
<?php endif; ?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
</div> <!-- container -->
</div> <!-- content -->
<div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Create Service</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="save-service" enctype="multipart/form-data">
<div class="modal-body p-4">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Group</label>
<select class="select2-dropdown form-control" name="service_group_id" required>
<option value="">Select Service Group</option>
<?php foreach ($serviceGroupData as $key => $value) { ?>
<option value="<?php echo $value['service_group_id']; ?>" ><?php echo $value['group_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Name</label>
<input type="text" class="form-control" name="service_name" >
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Notes</label>
<textarea class="form-control" name="notes"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect" style="color: #fff;background-color: #6c757d;border-color: #6c757d;" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-info waves-effect waves-light">Save</button>
</div>
</form>
</div>
</div>
</div><!-- /.modal -->
<a data-toggle="modal" id="edit_view" data-target="#con-close-modal2" class="btn btn-primary waves-effect waves-light" style="display: none;"> edit Service</a>
<div id="con-close-modal2" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Service</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="edit-service" enctype="multipart/form-data">
<div class="modal-body p-4">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Group</label>
<select class="select2-dropdown form-control" name="service_group_id" id="service_group_id" required>
<option value="">Select Service Group</option>
<?php foreach ($serviceGroupData as $key => $value) { ?>
<option value="<?php echo $value['service_group_id']; ?>" ><?php echo $value['group_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Name</label>
<input type="text" class="form-control" name="service_name" id="service_name">
<input type="hidden" class="form-control" name="service_id" id="service_id">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Notes</label>
<textarea class="form-control" name="notes" id="notes"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect" style="color: #fff;background-color: #6c757d;border-color: #6c757d;" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-info waves-effect waves-light">Save</button>
</div>
</form>
</div>
</div>
</div><!-- /.modal -->
<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0/js/select2.min.js"></script>
<script>
$(document).ready(function() {
datatable_bikeModel = $('#service_table').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [{extend: 'pdfHtml5',title: 'Service_List', text: 'PDF',},
{extend: 'print',title: 'Service_List',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
{extend: 'csv',text: 'CSV', title: 'Service_List', }],
"language": {
"search": "Search: " // Customize search label
},
});
$('.select2-dropdown').select2();
$('#save-service').submit(function(e) {
e.preventDefault(); // Prevent the form from submitting normally
// Create a FormData object
var formData = new FormData(this);
console.log(formData);
// Make an AJAX POST request
$.ajax({
url: '<?= base_url()."service_create"; ?>',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
if(response){
toastr.success('Data saved successfully ', 'Success');
window.location.reload();
}else{
toastr.warning('Something went wrong', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
});
});
$('#edit-service').submit(function(e) {
e.preventDefault(); // Prevent the form from submitting normally
// Create a FormData object
var formData = new FormData(this);
console.log(formData);
// Make an AJAX POST request
$.ajax({
url: '<?= base_url()."service_create"; ?>',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
if(response){
toastr.success('Data saved successfully ', 'Success');
window.location.reload();
}else{
toastr.warning('Something went wrong', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
});
});
});
function getServiceData(params) {
var service_id = params.getAttribute('data-id');
var formData = {
service_id: service_id
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."service_edit"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response.data);
if (response.success) {
$('#service_group_id').val(response.data.service_group_id).trigger('change');
$('#service_name').val(response.data.service_name);
$('#service_id').val(response.data.service_id);
$('#notes').val(response.data.notes);
$('#edit_view').click();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var service_id = params.getAttribute('data-id');
if(status == 1){
var is_active= 0;
}else{
var is_active= 1;
}
var formData = {
service_id: service_id,
is_active: is_active
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_service"?>',
data: formData,
dataType: 'json',
success: function(response) {
if (response.data) {
window.location.reload();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>