nhance/app/Views/insurer_branch.php
2026-02-09 12:57:17 +05:30

848 lines
38 KiB
PHP
Executable File
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.

<style>
.modal-subtitle {
font-weight: 500;
font-style: normal;
font-size: 18px;
line-height: 100%;
letter-spacing: 0%;
text-align: center;
margin-top: 5px;
color: #6c757d;
}
</style>
<!-- Optional CSS -->
<style>
/* Make modal really XL and scrollable */
#insurerBranchModal .modal-dialog.modal-xl {
max-width: 90%;
height: 90vh;
}
#insurerBranchModal .modal-content {
height: 100%;
overflow: hidden;
}
#insurerBranchModal .modal-body {
overflow-y: auto;
max-height: 80vh;
}
</style>
<div class="tab-pane fade" id="branch-tab" style="padding-left: 25px;">
<div class="row float-right" style="padding-bottom: 10px;position: relative;">
<a href="#" id="btnBranchAdd" class="btn app-btn-primary mr-2"><span class="mdi mdi-plus" aria-hidden="true" style="padding: 5px 10px;"></span>Add Branch</a>
</div>
<div class="table-responsive" id="branch_table" >
<table data-custom-table-css="table" class="table table-borderless table-nowrap mb-0" id="branch-datatable">
<thead class="">
<tr>
<th>Branch Name</th>
<th>Branch Code</th>
<th>Action</th>
</tr>
</thead>
<tbody id="insurer_branch_list">
</tbody>
</table>
</div>
<!-- <div class="row" id="add_branch">
<div class="col-12">
<div class="card-body">
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
<button type="button" id="btnBranchBack" class="btn btn-primary waves-effect waves-light btn-sm btnBack"><span class="mdi mdi-format-list-bulleted" aria-hidden="true" style="padding: 5px 10px;"></span>Back To List</button>
</div>
<hr>
<form role="form" class="parsley-examples" method="post" id="insurer_branch_form"
enctype="multipart/form-data">
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="insurer_Branch_PrimaryKey" />
<input type="hidden" name="insurer_id" id="insurer_id_branch" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>"/>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="branch_name">Branch Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_name"
placeholder="Enter Branch Name" name="branch_name" required>
</div>
<div class="form-group col-md-6">
<label for="branch_code">Branch Code<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_code"
placeholder="Enter Branch Code" name="branch_code" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="address1">Address Line 1<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="address1" name="address1" placeholder="Enter Address 1" required>
</div>
<div class="form-group col-md-6">
<label for="address2">Address Line 2<span class="text-danger"></span></label>
<input type="text" class="form-control" id="address2" placeholder="Enter Address 2" name="address2">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="state">State<span
class="text-danger">*</span></label>
<select class="form-control" id="state" name="state" required>
<option value="">Select State</option>
<?php foreach($state as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['state'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="district">District<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="district"
placeholder="Enter District" name="district" required>
</div>
<div class="form-group col-md-3">
<label for="city">City<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_city"
placeholder="Enter City" name="city" required>
</div>
<div class="form-group col-md-3">
<label for="gst">Pincode<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="pincode" placeholder="Enter Pincode" name="pincode" required>
</div>
</div>
<hr>
<h6 class="header-title">Contact 1</h6>
<br>
<div class="form-row">
<input type="hidden" name="primarykey[]" id="contact_id_1" value=""/>
<div class="form-group col-md-6">
<label for="first_name">Name<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" id="name" required>
</div>
<div class="form-group col-md-6">
<label for="designation">Designation<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" id="designation" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="last_name">Email<span class="text-danger">*</span></label>
<input value="" type="email" data-parsley-type="email" class="form-control" placeholder="Enter Contact Email" name="email[]" id="email" required>
</div>
<div class="form-group col-md-6">
<label for="mobile">Mobile<span class="text-danger">*</span></label>
<input name="mobile[]" pattern="[0-9]{10}" value="" type="tel" data-parsley-type="number" data-parsley-length="[10,10]" class="form-control" placeholder="Enter Contact Mobile" id="mobile" required>
</div>
</div>
<div class="form-group" style="display: flex;">
<button style="margin-right: 10px;" type="button" class="btn btn-primary btn-sm ac" onclick="appendContactHtml()" id="add">Add Contact</button>
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)" id="${uniqueId}_remove">Remove</button>
</div>
<div id="container"></div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack"
id="btnBack">Cancel</button>
</div>
</form>
</div>
</div>
</div> !-- end col-- -->
</div>
<!-- end -->
<!-- Modal -->
<div class="modal fade" id="insurerBranchModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" style="max-width: 1140px !important;">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header flex-column">
<div class="d-flex w-100 justify-content-between align-items-center">
<h4 class="modal-title mb-0" id="modalLabel">New Branch</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
</div>
<!-- Modal Body -->
<div class="modal-body" style="overflow-y:auto; max-height:80vh;">
<form id="insurer_branch_form" role="form" class="parsley-examples" method="post" action="" enctype="multipart/form-data">
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="insurer_Branch_PrimaryKey" />
<input type="hidden" name="insurer_id" id="insurer_id_branch" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>"/>
<div class="row">
<!-- Left Section: Branch Details -->
<div class="col-md-8 d-flex flex-column" style="max-height: calc(80vh - 50px);">
<!-- Branch Name & Code -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="branch_name">Branch Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_name"
placeholder="Enter Branch Name" name="branch_name" required>
</div>
<div class="form-group col-md-6">
<label for="branch_code">Branch Code <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_code"
placeholder="Enter Branch Code" name="branch_code" required>
</div>
</div>
<!-- Address Lines -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="address1">Address Line 1 <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="address1" name="address1" placeholder="Enter Address 1" required>
</div>
<div class="form-group col-md-6">
<label for="address2">Address Line 2</label>
<input type="text" class="form-control" id="address2" placeholder="Enter Address 2" name="address2">
</div>
</div>
<!-- State & District -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="state">State <span class="text-danger">*</span></label>
<select class="form-control" id="state" name="state" required>
<option value="">Select State</option>
<?php foreach($state as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['state'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-6">
<label for="district">District <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="district"
placeholder="Enter District" name="district" required>
</div>
</div>
<!-- City & Pincode -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="branch_city">City <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_city"
placeholder="Enter City" name="city" required>
</div>
<div class="form-group col-md-6">
<label for="pincode">Pincode <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="pincode" placeholder="Enter Pincode" name="pincode" required>
</div>
</div>
<!-- Submit / Cancel -->
<div class="form-row">
<!-- <div class="form-group col-md-12 mt-2"> -->
<div style="margin-top: 85px;">
<button type="submit" class="btn btn-primary mr-2" id="btnSubmit">Submit</button>
<button type="button" class="btn app-btn-outline-secondary btnBack" id="btnBack" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
<!-- </div> -->
</div>
</div>
<!-- Right Section: Contact Details -->
<div class="col-md-4" style="background:#f8f9fa; max-height: calc(80vh - 50px); overflow-y:auto; border-radius:8px; padding:10px;">
<!-- First Contact -->
<div id="contact_1_wrapper" class="bg-white p-2 mb-2 rounded contact-block">
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="modal-subtitle mb-0">Contact 1</h6>
<div class="d-flex align-items-center">
<i class="mdi mdi-trash-can text-danger" style="cursor:pointer; font-size:24px !important;" onclick="removeContact(this)" id="${uniqueId}_remove"></i>
</div>
</div>
<!-- Contact Form Fields -->
<div class="form-row">
<!-- <input type="hidden" name="primarykey[]" id="contact_id_1" value=""/> -->
<div class="form-group col-md-12">
<label for="name">Name <span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" id="name" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="designation">Designation <span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" id="designation" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="email">Email <span class="text-danger">*</span></label>
<input value="" type="email" data-parsley-type="email" data-parsley-trigger="change"class="form-control" placeholder="Enter Contact Email" name="email[]" id="email" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="mobile">Mobile <span class="text-danger">*</span></label>
<!-- <input name="mobile[]" pattern="[0-9]{10}" value="" type="tel" data-parsley-type="number" data-parsley-length="[10,10]" class="form-control" placeholder="Enter Contact Mobile" id="mobile" required> -->
<!-- oninput="this.value = this.value.replace(/[^0-9]/g,'');" maxlength="10" -->
<input value="" name="mobile[]" value="" data-parsley-type="digits" data-parsley-length="[10,10]" data-parsley-trigger="change" type="text" class="form-control" placeholder="Enter Contact Mobile" id="mobile" required maxlength="10" inputmode="numeric">
</div>
</div>
</div>
<!-- Container for dynamically added contacts -->
<div id="container"></div>
<div>
<button type="button" class="btn btn-primary btn-sm ac me-3" style="width: 100%;" onclick="appendContactHtml()" id="add"><i class="mdi mdi-plus"></i> Add Contact</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var contactCount = 1;
var insurer_branch_form_action = '';
var insurer_Branch_PrimaryKey = $('#insurer_id_branch').val();
$(document).ready(function () {
insurer_Branch_PrimaryKey = $('#insurer_id_branch').val();
var myModal = new bootstrap.Modal(document.getElementById('insurerBranchModal'));
myModal.hide();
// $('#add_branch').hide();
// $('.btnBack').hide();
if(insurer_Branch_PrimaryKey !== ''){
var branchTable = '';
var data = <?= isset($insuer_branch) ? json_encode($insuer_branch) : '[]' ?>;
console.log("insurer branch data", data);
$.each(data, function(index, item) {
branchTable += `
<tr>
<td>${item.branch_name}</td>
<td>${item.branch_code}</td>
<td>
<a class="mdi mdi-lead-pencil btnBranchEdit" href="#" data-id="${item.id}" style="font-size:18px;"></a>
<a style="color:#02a8b5" data-id="${item.id}" onclick="removeInsurerBranch(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
</td>
</tr>
`;
});
$('#insurer_branch_list').append(branchTable);
}
$('#branch-datatable').DataTable({
paging: true ,
searching: true
});
});
$('#btnBranchAdd').click(function(){
$("#insurer_branch_form")[0].reset();
contactCount = 1
insurer_branch_form_action = '<?= base_url("master/insurer/branch/create"); ?>';
var myModal = new bootstrap.Modal(document.getElementById('insurerBranchModal'));
myModal.show();
// $('#add_branch').show();
// $('#branch_table').hide();
// $('.btnBack').show();
// $('#btnBranchAdd').hide();
$('#branch_name').val('');
$('#branch_code').val('');
$('#state').val('');
$('#district').val('');
$('#branch_city').val('');
$('#name').val('');
$('#email').val('');
$('#mobile').val('');
$('#designation').val('');
contactCount = 1
var addButton = document.getElementById('add');
if (addButton.style.display === 'none') {
addButton.style.display = 'block';
}
var buttonIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
for (var i = 0; i < buttonIds.length; i++) {
var firstElement = buttonIds[i].split('_')[0];
console.log(firstElement);
// Find the element by its ID
var elementToRemove = document.getElementById(firstElement);
console.log(elementToRemove);
if (elementToRemove) {
console.log(elementToRemove);
elementToRemove.parentNode.removeChild(elementToRemove);
}
localStorage.removeItem('buttonIds')
}
})
$('.btnBack').click(function(){
$("#insurer_branch_form")[0].reset();
contactCount = 1
$('.close').click();
// $('#add_branch').hide();
// $('#branch_table').show();
// $('.btnBack').hide();
// $('#btnBranchAdd').show();
$('#branch_name').val('');
$('#branch_code').val('');
$('#state').val('');
$('#district').val('');
$('#branch_city').val('');
$('#name').val('');
$('#email').val('');
$('#mobile').val('');
$('#designation').val('');
$('#container').empty(); $('#contact_1_wrapper input').val('');
})
$("#insurer_branch_form").submit(function(events) {
console.log(1, insurer_branch_form_action);
events.preventDefault();
var isValid = $('#insurer_branch_form').parsley().validate();
if (isValid) {
var formData = new FormData($('#insurer_branch_form')[0]);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
data: formData,
url: insurer_branch_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
beforeSend: function() {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
},
success: function(res) {
$("#insurer_branch_form")[0].reset();
console.log(res);
$('#insurer_branch_list tr').remove();
var insurerBranchTableInsert = ''
$.each(res.data, function(index, item) {
insurerBranchTableInsert += `
<tr>
<td>${item.branch_name}</td>
<td>${item.branch_code}</td>
<td>
<a class="mdi mdi-lead-pencil btnBranchEdit" href="#" data-id="${item.id}" style="font-size:18px;"></a>
<a style="color:#02a8b5" data-id="${item.id}" onclick="removeInsurerBranch(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
</td>
</tr>
`;
});
$('#insurer_branch_list').append(insurerBranchTableInsert);
$('#container').empty(); $('#contact_1_wrapper input').val('');
$('.close').click();
// window.location.reload();
// $('#add_branch').hide();
// $('#branch_table').show();
// $('.btnBack').hide();
// $('#btnBranchAdd').show();
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Wrong!', 'warning');
}, 1000);
},
complete: function() {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
$('.close').click();
}
});
}
});
$('body').on('click', '.btnBranchEdit', function () {
$('#container').html("");
contactCount = 1;
var branch_id = $(this).attr('data-id');
$('#insurer_Branch_PrimaryKey').val(branch_id);
insurer_branch_form_action = '<?= base_url("master/insurer/branch/edit"); ?>';
console.log(insurer_branch_form_action)
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('master/insurer/branch/editget/');?>'+branch_id,
type: "GET",
dataType: 'json',
success: function (res) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
var myModal = new bootstrap.Modal(document.getElementById('insurerBranchModal'));
myModal.show();
// $('#add_branch').show();
// $('#branch_table').show();
// $('.btnBack').show();
// $('#btnBranchAdd').hide();
console.log("res.levelcontact[0].id"+res.levelcontact[0].id);
$('#branch_name').val(res.insurerbranch.branch_name);
$('#branch_code').val(res.insurerbranch.branch_code);
$('#state option[value="' + res.insurerbranch.state + '"]').prop('selected', true);
$('#district').val(res.insurerbranch.district);
$('#branch_city').val(res.insurerbranch.city);
$('#pincode').val(res.insurerbranch.pincode);
$('#address1').val(res.insurerbranch.address1);
$('#address2').val(res.insurerbranch.address2);
$('#contact_id_1').val(res.levelcontact[0].id);
$('.form-row').find('#name').val(res.levelcontact[0].name);
$('#email').val(res.levelcontact[0].email);
$('#mobile').val(res.levelcontact[0].mobile);
$('#designation').val(res.levelcontact[0].designation);
res.levelcontact.shift();
$.each(res.levelcontact, function(index, contact) {
if (contact !== undefined) {
appendContactHtml(contact);
}
});
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Wrong!', 'Warning');
}, 1000);
}
});
});
// function appendContactHtml(contact = false, reset = false) {
// console.log('appendContactHtml function called ')
// contactCount++;
// var container = document.getElementById('container');
// var uniqueId = Date.now().toString();
// var html = `
// <div id="${uniqueId}" class="bg-white p-2 mb-2 rounded">
// <div class="d-flex justify-content-between align-items-center mb-2">
// <h6 class="modal-subtitle mb-0">Contact ${contactCount}</h6>
// <div class="d-flex align-items-center">
// <i class="mdi mdi-trash-can text-danger" style="cursor:pointer; font-size:24px !important;" onclick="removeContact(this)" id="${uniqueId}_remove"></i>
// </div>
// </div>
// <br>
// <div class="form-row">
// <input type="hidden" name="primarykey[]" id="contact_id_1" value="${contact !== undefined && contact !== false ? contact.id : ''}"/>
// <div class="form-group col-md-12">
// <label for="${uniqueId}_first_name">Name<span class="text-danger">*</span></label>
// <input value="${contact !== undefined && contact !== false ? contact.name : ''}" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" id="${uniqueId}_name" required>
// </div>
// </div>
// <div class="form-row">
// <div class="form-group col-md-12">
// <label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
// <input data-parsley-type="email" value="${contact !== undefined && contact !== false ? contact.email : ''}" type="email" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" required>
// </div>
// </div>
// <div class="form-row">
// <div class="form-group col-md-12">
// <label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
// <input data-parsley-type="number" data-parsley-length="[10,10]" pattern="[0-9]{10}" value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="tel" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" required>
// </div>
// </div>
// <div class="form-row">
// <div class="form-group col-md-12">
// <label for="${uniqueId}_designation">Designation<span class="text-danger">*</span></label>
// <input value="${contact !== undefined && contact !== false ? contact.designation : ''}" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" id="${uniqueId}_designation" required>
// </div>
// </div>
// </div>
// `;
// if(reset == false){
// container.insertAdjacentHTML('beforeend', html);
// storeButtonId(uniqueId + '_add');
// if (contactCount >= 3) {
// hideStoredAddButtons();
// }
// }
// }
// function removeContact(button) {
// var uniqueId = button.id.split("_")[0];
// var contactSection = document.getElementById(uniqueId);
// if (contactSection) {
// contactSection.parentNode.removeChild(contactSection);
// contactCount --;
// if (contactCount < 3) {
// var addButton = document.querySelector('.ac');
// if (addButton) {
// addButton.style.display = 'block';
// }
// }
// }
// }
// function storeButtonId(id) {
// var buttonIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
// buttonIds.push(id);
// localStorage.setItem('buttonIds', JSON.stringify(buttonIds));
// }
// function hideStoredAddButtons() {
// var storedIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
// storedIds.forEach(function(id) {
// var addButton = document.getElementById(id);
// var first_addButton = document.querySelector('.ac')
// if (addButton) {
// addButton.style.display = 'none';
// first_addButton.style.display = 'none';
// }
// });
// }
function renumberContacts() {
var contacts = document.querySelectorAll('.contact-block');
contacts.forEach(function(contact, index) {
let title = contact.querySelector('.modal-subtitle');
if (title) {
title.textContent = "Contact " + (index + 1); // auto numbering
}
});
contactCount = contacts.length; // keep global in sync
}
function appendContactHtml(contact = false, reset = false) {
console.log('appendContactHtml function called ');
var container = document.getElementById('container');
var uniqueId = Date.now().toString();
// <input type="hidden" name="primarykey[]" id="contact_id_1" value="${contact !== undefined && contact !== false ? contact.id : ''}"/>
var html = `
<div id="${uniqueId}" class="bg-white p-2 mb-2 rounded contact-block">
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="modal-subtitle mb-0"></h6>
<div class="d-flex align-items-center">
<i class="mdi mdi-trash-can text-danger" style="cursor:pointer; font-size:24px !important;" onclick="removeContact(this)" id="${uniqueId}_remove"></i>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>Name<span class="text-danger">*</span></label>
<input value="${contact ? contact.name : ''}" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>Designation<span class="text-danger">*</span></label>
<input value="${contact ? contact.designation : ''}" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>Email<span class="text-danger">*</span></label>
<input value="${contact ? contact.email : ''}" type="email" data-parsley-type="email" data-parsley-trigger="change"class="form-control" placeholder="Enter Contact Email" name="email[]" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>Mobile<span class="text-danger">*</span></label>
<input value="${contact ? contact.mobile : ''}" name="mobile[]" value="" data-parsley-type="digits" data-parsley-length="[10,10]" data-parsley-trigger="change" type="text" class="form-control" placeholder="Enter Contact Mobile" id="mobile" required maxlength="10" inputmode="numeric">
</div>
</div>
</div>
`;
if(!reset){
container.insertAdjacentHTML('beforeend', html);
renumberContacts(); // ✅ fix numbering
toggleAddButton();
}
}
function removeContact(btn){
var $block = $(btn).closest('.contact-block');
var isFirst = $block.attr('id') === 'contact_1_wrapper';
if (isFirst) {
var $next = $('#container .contact-block').first();
if ($next.length){
$block.replaceWith($next);
$next.attr('id','contact_1_wrapper');
$next.find('.modal-subtitle').text('Contact 1');
} else {
$block.find('input').val('');
return;
}
} else {
$block.remove();
}
renumberContacts();
toggleAddButton();
}
function toggleAddButton() {
var totalContacts = document.querySelectorAll('.contact-block, #contact_1_wrapper').length;
var addButton = document.querySelector('.ac');
if (totalContacts >= 3) {
addButton.style.display = 'none';
} else {
addButton.style.display = 'block';
}
}
function showNextAddButton() {
var storedIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
var addButtonShown = false;
// Iterate through the stored IDs to find the next "Add" button to show
storedIds.forEach(function(id) {
if (!addButtonShown) {
var addButton = document.getElementById(id);
if (addButton && addButton.style.display === 'none') {
addButton.style.display = 'block';
addButtonShown = true; // Set to true once an "Add" button is shown
}
}
});
}
function validateForm() {
var isValid = true;
$('#insurer_branch_form input, #insurer_branch_form select').each(function() {
if ($(this).is('input[name="emial[]"]') || $(this).is('input[type="text"]') || $(this).is('select') ) {
if ($.trim($(this).val()) == '') {
isValid = false;
return false;
}
}
});
return isValid;
}
function removeInsurerBranch(element) {
Swal.fire({
title: "Are you sure?",
text: "You need to remove this insurer branch.",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
var id = element.getAttribute('data-id');
var form_action = '<?= base_url("master/insurer/branch/remove/") ?>' + id;
$.ajax({
url: form_action,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
// console.log(res.status == true);
if(res){
if (res.status == true) {
toastr.success('Insurer branch removed successfully', 'Success');
location.reload();
} else {
toastr.warning('Failed to remove insurer branch', 'Warning');
}
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Failed to remove insurer branch', 'Warning');
}
});
}
});
}
</script>