439 lines
20 KiB
PHP
439 lines
20 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">Client 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="#client_branch_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="client_branch_table" class="table table-striped dt-responsive nowrap w-100">
|
||
<thead>
|
||
<tr>
|
||
<th>Client</th>
|
||
<th>Branch Name</th>
|
||
<th>GST</th>
|
||
<th>Mobile</th>
|
||
<th>Email</th>
|
||
<th>Address</th>
|
||
<th>Active</th>
|
||
<th>Action</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($clientBranchList as $value) :?>
|
||
<tr>
|
||
<td><?= $value['client_name']; ?></td>
|
||
<td> <?php if($value['individual'] == 1) { ?><?= 'Individual' ?><?php }else{ ?> <?= $value['name']; ?><?php } ?></td>
|
||
<td><?= $value['gst_no']; ?></td>
|
||
<td> <?php if($value['individual'] == 1) { ?><?= $value['client_mobile_no']; ?><?php }else{ ?> <?= $value['mobile_no']; ?><?php } ?></td>
|
||
<td><?php if($value['individual'] == 1) { ?><?= $value['client_email']; ?><?php }else{ ?> <?= $value['email']; ?><?php } ?></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>
|
||
<?php if ($value['is_active'] == 0): ?>
|
||
<span style="color: red;">Inactive</span>
|
||
<?php else: ?>
|
||
<span style="color: green;">Active</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 data-toggle="modal" data-target="#client_branch_modal" value="<?= $value['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['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)"><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['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Activate" onclick="statusChange(this)"><i class="fas fa-building" style="margin-right:10px"></i>Activate</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
<?php endforeach; ?>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
</div> <!-- end card body-->
|
||
</div> <!-- end card -->
|
||
</div><!-- end col-->
|
||
</div>
|
||
|
||
|
||
|
||
</div> <!-- container -->
|
||
|
||
</div> <!-- content -->
|
||
|
||
|
||
<div id="client_branch_modal" aria-hidden="true" aria-modal="true" data-backdrop="static" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-xg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 id="branch_type">Add Branch </h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button></div>
|
||
<div class="modal-body" style="margin-top: -29px;">
|
||
<div class="text-center mt-2 mb-4">
|
||
</div>
|
||
<form id="client_branch_model_form_data" class="px-4">
|
||
|
||
<input type="text" id="id" hidden>
|
||
<input type="text" id="individual" hidden>
|
||
|
||
<div class="row branch_hide_edit">
|
||
<div class="col-md-4">
|
||
<div class="form-group">
|
||
<label for="client">Client</label>
|
||
<select name="client" id="client" class="form-control select2" style="width: auto;" required="true">
|
||
<option value="0">Select Client</option>
|
||
<?php foreach ($client_list as $key => $value) { ?>
|
||
<option value="<?php echo $value['client_id']; ?>"><?php echo $value['name']; ?></option>
|
||
<?php } ?>
|
||
</select>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="col-md-4">
|
||
<div class="form-group">
|
||
<label for="branchname">Branch Name</label>
|
||
<input class="form-control" name="branch_name" type="text" id="branch_name" required="true" placeholder="Branch Name">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-4">
|
||
<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-4">
|
||
<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-4">
|
||
<div class="form-group">
|
||
<label for="mobile_no">Mobile No</label>
|
||
<input class="form-control" name="mobile_no" type="text" id="mobile_no" required="" minlength="6" maxlength="16" placeholder="Mobile No">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="mdi mdi-office-building 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>
|
||
<div class="col-md-3">
|
||
<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-3">
|
||
<div class="form-group">
|
||
<label for="state">State</label>
|
||
<input class="form-control" name="state" type="text" id="state" value="Tamil Nadu" required="" placeholder="State">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-3">
|
||
<div class="form-group">
|
||
<label for="country">Country</label>
|
||
<input class="form-control" name="country" type="text" value="India" id="country" required="" placeholder="Country">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-3">
|
||
<div class="form-group">
|
||
<label for="postalcode">PIN Code</label>
|
||
<input class="form-control" name="pin_code" type="text" id="pin_code" required="" placeholder="Pin Code">
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="row">
|
||
<div class="col-md-12">
|
||
|
||
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="fas fa-bell mr-1"></i> Notification</h5>
|
||
</div>
|
||
<div class="col-md-2">
|
||
<div class="form-group">
|
||
<label for="sms">SMS</label>
|
||
<input style="float:right;width: 20px;height: 20px;" name="sms" type="checkbox" id="sms" checked>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-2">
|
||
|
||
</div>
|
||
<div class="col-md-2">
|
||
<div class="form-group">
|
||
<label for="whatsapp">WhatsApp</label>
|
||
<input style="float:right;width: 20px;height: 20px;" name="whatsapp" type="checkbox" id="whatsapp" checked>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
<div class="form-group text-right">
|
||
<button class="btn btn-info waves-effect waves-light" type="submit" id="client_branch_submit" onclick="submitBranch(event,this)">Submit</button>
|
||
</div>
|
||
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
|
||
<script>
|
||
|
||
$(document).ready(function() {
|
||
|
||
datatable_bikeModel = $('#client_branch_table').DataTable({
|
||
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
|
||
"dom": 'Bfrtip', // Show export buttons
|
||
"buttons": [{extend: 'pdfHtml5',title: 'Client_Branches', text: 'PDF',},
|
||
{extend: 'print',title: 'Client_Branches',text: 'Print',},
|
||
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
|
||
{extend: 'csv',text: 'CSV', title: 'Client_Branches', }],
|
||
"language": {
|
||
"search": "Search: " // Customize search label
|
||
},
|
||
});
|
||
$('.select2').select2();
|
||
});
|
||
|
||
function statusChange(params) {
|
||
var status = params.getAttribute('data-isactive');
|
||
var client_branch_id = params.getAttribute('data-id');
|
||
if(status == 1){
|
||
var is_active= 0;
|
||
}else{
|
||
var is_active= 1;
|
||
}
|
||
|
||
var formData = {
|
||
client_branch_id: client_branch_id,
|
||
is_active: is_active
|
||
};
|
||
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: '<?php echo base_url()."status_client_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);
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
|
||
$('#add_branch_model_open').click(function () {
|
||
$('#branch_type').html('Create Branch');
|
||
$('#client').val(0).trigger('change');
|
||
$('#client_branch_model_form_data')[0].reset(); // Reset form elements
|
||
})
|
||
|
||
function submitBranch(event,params) {
|
||
event.preventDefault();
|
||
console.log($('#sms').is(':checked'));
|
||
|
||
if($('#individual').val() != 1){
|
||
if ($('#client').val() == 0) {
|
||
toastr.warning('Select Client');
|
||
return;
|
||
}
|
||
}
|
||
|
||
if($('#individual').val() != 1){
|
||
var formData = {
|
||
client_id: $('#client').val(),
|
||
gst_no: $('#gst_no').val(),
|
||
email: $('#email').val(),
|
||
contact: $('#contact').val(),
|
||
country: $('#country').val(),
|
||
state_code: $('#state_code').val(),
|
||
name: $('#branch_name').val(),
|
||
address: $('#address').val(),
|
||
city: $('#city').val(),
|
||
state: $('#state').val(),
|
||
pin_code: $('#pin_code').val(),
|
||
mobile_no: $('#mobile_no').val(),
|
||
sms: $('#sms').prop('checked'),
|
||
whatsapp: $('#whatsapp').prop('checked'),
|
||
};
|
||
}else{
|
||
var formData = {
|
||
country: $('#country').val(),
|
||
address: $('#address').val(),
|
||
city: $('#city').val(),
|
||
state: $('#state').val(),
|
||
pin_code: $('#pin_code').val(),
|
||
sms: $('#sms').prop('checked'),
|
||
whatsapp: $('#whatsapp').prop('checked'),
|
||
};
|
||
}
|
||
|
||
|
||
|
||
if ($('#id').val()) {
|
||
var url = '<?= base_url("edit_client_branch"); ?>';
|
||
formData['id'] = $('#id').val();
|
||
}else{
|
||
var url = '<?= base_url("add_client_branch"); ?>';
|
||
}
|
||
|
||
var formDataValidate = $('#client_branch_model_form_data').serialize(); // Serialize form data
|
||
|
||
if(!formDataValidate){
|
||
return ;
|
||
}
|
||
|
||
var form = $(params).parent().parent();
|
||
var isValid = true;
|
||
form[0].querySelectorAll('[required]').forEach(function(element) {
|
||
if (!element.value.trim()) {
|
||
isValid = false;
|
||
}
|
||
});
|
||
|
||
if (!isValid) {
|
||
return;
|
||
}
|
||
|
||
if (!$('#sms').is(':checked') && !$('#whatsapp').is(':checked')) {
|
||
toastr.warning('One Notification is must');
|
||
return;
|
||
}
|
||
$('#client_branch_submit').attr('disabled','true');
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: url,
|
||
data: formData,
|
||
dataType: 'json',
|
||
success: function(response) {
|
||
console.log(response);
|
||
$('#client_branch_submit').removeAttr('disabled');
|
||
if(response == true){
|
||
toastr.success('Branch Added Successfully');
|
||
$('#client_branch_modal').modal('hide');
|
||
window.location.reload();
|
||
}else if(response == 'update'){
|
||
toastr.success('Branch Updated Successfully');
|
||
$('#client_branch_modal').modal('hide');
|
||
window.location.reload();
|
||
}else{
|
||
toastr.warning('GST Number Already Exists');
|
||
event.preventDefault();
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle error response here
|
||
console.error(xhr.responseText);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
function editBranch(params) {
|
||
$('#branch_type').html('Edit Branch');
|
||
$.ajax({
|
||
type: 'GET',
|
||
url: '<?= base_url("get_client_branch/"); ?>' +params.getAttribute('value'),
|
||
dataType: 'json',
|
||
success: function(response) {
|
||
console.log(response);
|
||
|
||
if(response.sms == 1){
|
||
$('#sms').prop('checked', true);
|
||
}else{
|
||
$('#sms').prop('checked', false);
|
||
}
|
||
if(response.whatsapp == 1){
|
||
$('#whatsapp').prop('checked', true);
|
||
}else{
|
||
$('#whatsapp').prop('checked', false);
|
||
}
|
||
|
||
if(response.individual == 1){
|
||
$('#individual').val(1);
|
||
$('.branch_hide_edit').hide();
|
||
$('#client').prop('required', false);
|
||
$('#branch_name').prop('required', false);
|
||
$('#gst_no').prop('required', false);
|
||
$('#email').prop('required', false);
|
||
$('#mobile_no').prop('required', false);
|
||
}else{
|
||
$('.branch_hide_edit').show();
|
||
$('#individual').val('');
|
||
$('#branch_name').val(response.name);
|
||
$('#gst_no').val(response.gst_no);
|
||
$('#email').val(response.email);
|
||
$('#mobile_no').val(response.mobile_no);
|
||
}
|
||
$('#client').val(response.client_id).trigger('change');
|
||
$('#address').val(response.address);
|
||
$('#id').val(response.id);
|
||
$('#city').val(response.city);
|
||
$('#pin_code').val(response.pin_code);
|
||
$('#state').val(response.state);
|
||
$('#country').val(response.country);
|
||
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle error response here
|
||
console.error(xhr.responseText);
|
||
}
|
||
});
|
||
}
|
||
</script>
|
||
|
||
|