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

396 lines
18 KiB
PHP
Raw 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 Group 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 New
</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_group_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>No Of Business</th>
<th>No Of Service</th>
<th>Action</th>
</tr>
</thead>
<tbody class="font-14">
<?php foreach ($serviceGroupList as $key => $value) { ?>
<tr>
<td><?php echo $value['group_name']; ?></td>
<td class="business-count" data-toggle="modal" data-target="#business_list_view_modal" data-business-list='<?php echo json_encode($value['business_list']); ?>'>
<span><?php echo $value['business_count']; ?></span>
</td>
<td class="service-count" data-toggle="modal" data-target="#service_list_view_modal" data-service-list='<?php echo json_encode($value['service_list']); ?>'>
<span><?php echo $value['service_count']; ?></span>
</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_group_id']; ?>" onclick="getGroupData(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_group_id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Deactivate" onclick="statusChange(this)"><i class="ri-shield-user-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_group_id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Activate" onclick="statusChange(this)"><i class="ri-shield-user-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 Group</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="save-service-group" 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">Business</label>
<select name="business[]" id="business" class="form-control Select2" multiple required>
<?php foreach ($business_list as $key => $value) { ?>
<option value="<?= $value['business_id'] ?>"><?= $value['business_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Group Name</label>
<input type="text" class="form-control" name="group_name" required>
</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"> </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 Group</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="edit-service-group" 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">Business</label>
<select name="business[]" id="business_edit" class="form-control Select2" multiple required>
<?php foreach ($business_list as $key => $value) { ?>
<option value="<?= $value['business_id'] ?>"><?= $value['business_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="field-1" class="control-label">Service Group Name</label>
<input type="text" class="form-control" name="group_name" id="group_name">
<input type="hidden" class="form-control" name="service_group_id" id="service_group_id">
</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 -->
<!-- Business List Modal -->
<div class="modal fade" id="business_list_view_modal" tabindex="-1" role="dialog" aria-labelledby="businessListModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="businessListModalLabel">Business List</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table table-striped">
<thead>
<tr>
<th>Business Name</th>
</tr>
</thead>
<tbody id="business-list">
<!-- Business list items will be appended here by JavaScript -->
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Service List Modal -->
<div class="modal fade" id="service_list_view_modal" tabindex="-1" role="dialog" aria-labelledby="serviceListModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="serviceListModalLabel">Service List</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table table-striped">
<thead>
<tr>
<th>Service Name</th>
</tr>
</thead>
<tbody id="service-list">
<!-- Service list items will be appended here by JavaScript -->
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- 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() {
// Event listener for business count click
$('.business-count').on('click', function() {
var businessList = $(this).data('business-list'); // Get the business list data
var businessListContainer = $('#business-list'); // Get the table body container
// Clear any existing list items
businessListContainer.empty();
// Append each business to the table
businessList.forEach(function(business) {
businessListContainer.append('<tr><td>' + business.business_name + '</td></tr>');
});
});
// Event listener for service count click
$('.service-count').on('click', function() {
var serviceList = $(this).data('service-list'); // Get the service list data
console.log(serviceList);
var serviceListContainer = $('#service-list'); // Get the table body container
// Clear any existing list items
serviceListContainer.empty();
// Append each service to the table
serviceList.forEach(function(service) {
console.log(service);
serviceListContainer.append('<tr><td>' + service + '</td></tr>');
});
});
});
$(document).ready(function() {
$('.Select2').select2({
placeholder: "Select Business",
allowClear: true
});
datatable_bikeModel = $('#service_group_table').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [{extend: 'pdfHtml5',title: 'Service_Group', text: 'PDF',},
{extend: 'print',title: 'Service_Group',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Service_Group',},
{extend: 'csv',text: 'CSV', title: 'Service_Group', }],
"language": {
"search": "Search: " // Customize search label
},
});
$('#save-service-group').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_group_create"; ?>',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
console.log(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-group').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_group_create"; ?>',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
console.log("------------");
console.log(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 getGroupData(params) {
var service_group_id = params.getAttribute('data-id');
var formData = {
service_group_id: service_group_id
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."service_group_edit"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response.data);
if (response.success) {
$('#group_name').val(response.data.group_name);
$('#service_group_id').val(response.data.service_group_id);
var selectedBusinesses = JSON.parse(response.data.business_id); // Assuming this is an array of selected business IDs
$('#business_edit').val(selectedBusinesses).trigger('change');
$('#edit_view').click();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>