364 lines
16 KiB
PHP
364 lines
16 KiB
PHP
<!-- ============================================================== -->
|
||
<!-- 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">Branch List</h4>
|
||
<div class="page-title-right">
|
||
<ol class="breadcrumb m-0">
|
||
<li class=""> <a href="#" id="add_branch_model_open" data-toggle="modal" data-target="#branch-create-modal" class="btn btn-primary waves-effect">
|
||
Add Branch
|
||
</a>
|
||
</ol>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- end page title -->
|
||
|
||
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
|
||
|
||
<table id="business_branch_table" class="table table-striped dt-responsive nowrap w-100">
|
||
<thead>
|
||
<tr>
|
||
<th>Branch Name</th>
|
||
<th>GST</th>
|
||
<th>Address</th>
|
||
<th>Contact</th>
|
||
<th>Status</th>
|
||
<th>Action</th>
|
||
</tr>
|
||
</thead>
|
||
|
||
|
||
<tbody>
|
||
|
||
<?php foreach ($branch as $value) : ?>
|
||
<tr>
|
||
<td><?= $value['branch_name']; ?></td>
|
||
<td><?= $value['gstno']; ?></td>
|
||
<td>
|
||
<?= $value['address']; ?></br>
|
||
<?= $value['city']; ?>
|
||
<?php if (!empty($value['state'])): ?>, <?= $value['state']; ?><?php endif; ?>
|
||
<?php if (!empty($value['pin_code'])): ?> - <?= $value['pin_code']; ?><?php endif; ?>
|
||
</td>
|
||
<td><?= $value['contact']; ?></td>
|
||
<td>
|
||
<?php if ($value['isactive'] == 0): ?>
|
||
<span style="color: red;">Inactive</span>
|
||
<?php else: ?>
|
||
<span style="color: green;">Active</span>
|
||
<?php endif; ?>
|
||
</td>
|
||
<!-- <td>
|
||
<a href="<?= base_url("user_list/" . $value['branch_id']) ?>" style="margin-left: 15px;">View</a>
|
||
</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 data-toggle="modal" data-target="#branch-create-modal" value="<?= $value['branch_id']; ?>" onclick="editBranch(this)" class="edit-button dropdown-item"><i
|
||
class="ri-pencil-line" style="margin-right: 16px !important;margin-left: 5px;"></i>Edit</a>
|
||
|
||
<?php if($value['isactive'] == 1): ?>
|
||
<a class="dropdown-item" data-id="<?php echo $value['branch_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Deactivate" onclick="statusChange(this)"><i class="fas fa-building"></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['branch_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Activate" onclick="statusChange(this)"><i class="fas fa-building" style="margin-right:10px"></i>Activate</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
|
||
|
||
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
|
||
</div> <!-- end card body-->
|
||
</div> <!-- end card -->
|
||
</div><!-- end col-->
|
||
</div>
|
||
|
||
|
||
|
||
</div> <!-- container -->
|
||
|
||
</div> <!-- content -->
|
||
|
||
|
||
<div id="branch-create-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-lg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 id="branch_action_type">Add Branch</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
|
||
<form id="model_form_data" class="px-4">
|
||
|
||
<input type="text" id="business_id" value="" hidden>
|
||
<input type="text" id="branch_id" hidden>
|
||
|
||
<div class="row">
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="branchname">Business</label>
|
||
<select name="business" id="business" class="form-control" required="">
|
||
<option value="0">Select Business</option>
|
||
<?php foreach ($business_list as $key => $value) { ?>
|
||
<option value="<?php echo $value['business_id'] ?>"><?php echo $value['business_name'] ?></option>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="branchname">Branch Name</label>
|
||
<input class="form-control" name="branch_name" type="text" id="branch_name" required="" placeholder="Branch Name">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="gstno">GST No</label>
|
||
<input class="form-control" name="gst_no" type="text" id="gst_no" required="" placeholder="GST No" pattern="[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}[Z]{1}[0-9A-Z]{1}">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="email">Email</label>
|
||
<input class="form-control" name="email" type="email" id="email" required="" placeholder="Email">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="contact">Contact</label>
|
||
<input class="form-control" name="contact" type="text" id="contact" required="" minlength="6" maxlength="16" placeholder="Contact">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="fas fa-map-marker-alt mr-1"></i> Address Details</h5>
|
||
<div class="row">
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="address">Address</label>
|
||
<textarea class="form-control" name="address" type="text" id="address" required="" placeholder="Address"></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="city">City</label>
|
||
<input class="form-control" name="city" type="text" id="city" required="" placeholder="City">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="state">State</label>
|
||
<input class="form-control" name="state" value="Tamil Nadu" type="text" id="state" required="" placeholder="State">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="pincode">Country</label>
|
||
<input class="form-control" name="country" value="India" type="text" id="country" required="" placeholder="Country">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label for="pincode">Pin Code</label>
|
||
<input class="form-control" name="pin_code" type="text" id="pin_code" required="" placeholder="PIN Code">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group text-right">
|
||
<button class="btn btn-info waves-effect waves-light" type="submit" id="business_branch_submit" onclick="submitBranch(this)">Submit</button>
|
||
</div>
|
||
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
|
||
|
||
<!-- ============================================================== -->
|
||
<!-- End Page content -->
|
||
<!-- ============================================================== -->
|
||
|
||
|
||
<script>
|
||
|
||
$(document).ready(function() {
|
||
|
||
datatable_bikeModel = $('#business_branch_table').DataTable({
|
||
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
|
||
"dom": 'Bfrtip', // Show export buttons
|
||
"buttons": [{extend: 'pdfHtml5',title: 'Branches', text: 'PDF',},
|
||
{extend: 'print',title: 'Branches',text: 'Print',},
|
||
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
|
||
{extend: 'csv',text: 'CSV', title: 'Branches', }],
|
||
"language": {
|
||
"search": "Search: " // Customize search label
|
||
},
|
||
});
|
||
|
||
$('#business').select2();
|
||
});
|
||
function submitBranch(params) {
|
||
|
||
if ($('#branch_id').val()) {
|
||
var url = '<?= base_url("edit_branch/"); ?>'+$('#branch_id').val();
|
||
}else{
|
||
var url = '<?= base_url("add_branch"); ?>';
|
||
}
|
||
var formDataValidate = $('#model_form_data').serialize(); // Serialize form data
|
||
|
||
if(!formDataValidate){
|
||
return ;
|
||
}
|
||
if($('#business').val() == 0){
|
||
event.preventDefault();
|
||
toastr.warning('Select Business');
|
||
$('#business').focus();
|
||
return;
|
||
}
|
||
var formData = {
|
||
business_id: $('#business').val(),
|
||
gstno: $('#gst_no').val(),
|
||
email: $('#email').val(),
|
||
contact: $('#contact').val(),
|
||
country: $('#country').val(),
|
||
state_code: $('#state_code').val(),
|
||
branch_name: $('#branch_name').val(),
|
||
address: $('#address').val(),
|
||
city: $('#city').val(),
|
||
state: $('#state').val(),
|
||
pin_code: $('#pin_code').val(),
|
||
mobile_no: $('#mobile_no').val()
|
||
};
|
||
|
||
var form = $(params).parent().parent();
|
||
// console.log(form);
|
||
var isValid = true;
|
||
form[0].querySelectorAll('[required]').forEach(function(element) {
|
||
if (!element.value.trim()) {
|
||
isValid = false;
|
||
}
|
||
});
|
||
|
||
if (!isValid) {
|
||
return;
|
||
}
|
||
var business_id = $('#business_id').val();
|
||
// console.log(formData);
|
||
|
||
$('#business_branch_submit').attr('disabled','true');
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: url,
|
||
data: formData,
|
||
dataType: 'json',
|
||
success: function(response) {
|
||
console.log(response);
|
||
$('#business_branch_submit').removeAttr('disabled');
|
||
|
||
$('#branch-create-modal').modal('hide');
|
||
|
||
window.location.reload();
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle error response here
|
||
console.error(xhr.responseText);
|
||
}
|
||
});
|
||
}
|
||
function editBranch(params) {
|
||
$('#branch_action_type').html('Edit Branch');
|
||
$.ajax({
|
||
type: 'GET',
|
||
url: '<?= base_url("get_branch/"); ?>' +params.getAttribute('value'),
|
||
dataType: 'json',
|
||
success: function(response) {
|
||
// console.log(response);
|
||
$('#business').val(response.business_id).trigger('change');
|
||
$('#branch_name').val(response.branch_name);
|
||
$('#gst_no').val(response.gstno);
|
||
$('#email').val(response.email);
|
||
$('#contact').val(response.contact);
|
||
$('#address').val(response.address);
|
||
$('#branch_id').val(response.branch_id);
|
||
$('#city').val(response.city);
|
||
$('#pin_code').val(response.pin_code);
|
||
$('#state').val(response.state);
|
||
$('#country').val(response.country);
|
||
$('#state_code').val(response.state_code);
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle error response here
|
||
console.error(xhr.responseText);
|
||
}
|
||
});
|
||
}
|
||
|
||
$('#add_branch_model_open').click( function(){
|
||
$('#branch_action_type').html('Add Branch');
|
||
$('#business').val(0).trigger('change');
|
||
$('#model_form_data')[0].reset();
|
||
})
|
||
|
||
function statusChange(params) {
|
||
var status = params.getAttribute('data-isactive');
|
||
var branch_id = params.getAttribute('data-id');
|
||
if(status == 1){
|
||
var isactive= 0;
|
||
}else{
|
||
var isactive= 1;
|
||
}
|
||
|
||
var formData = {
|
||
branch_id: branch_id,
|
||
isactive: isactive
|
||
};
|
||
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: '<?php echo base_url()."status_branch"?>',
|
||
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>
|