nhance-enrollment/app/Views/client_basic_info.php
2026-02-26 15:43:34 +05:30

395 lines
17 KiB
PHP
Executable File

<style>
.switch {
position: relative;
display: inline-block;
width: 54px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 19px;
width: 19px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<div class="tab-pane fade active show" id="general-q-tab">
<div class="row">
<div class="col-12">
<div class="card-body">
<form role="form" class="parsley-examples" method="post" id="general_form" enctype="multipart/form-data">
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="general_PrimaryKey" value="<?= isset($client['id']) ? $client['id'] : '' ?>"/>
<input type="hidden" name="client_id" id="client_id" />
<div class="form-group">
<div class="form-row">
<!-- <div class="form-group col-md-4">
<label for="entity_type_id">Entity Type <span
class="text-danger">*</span></label>
<select class="form-control" id="entity_type" name="entity_type_id" required>
<option value="">Select Entity</option>
<?php foreach($entity as $value) { ?>
<?php if(isset($client['entity_type_id'])){ ?>
<?php if($value['id'] == $client['entity_type_id']) { ?>
<option value="<?= $value['id'] ?>" selected><?= $value['name'] ?></option>
<?php } else { ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php } ?>
<?php } else { ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div> -->
<div class="form-group col-md-6">
<label for="client_name">Client Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="client_name" data-old-name="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>"
placeholder="Enter Client Name" value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" name="client_name" required>
</div>
<div class="form-group col-md-6">
<label for="short_name">Client Short Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="short_name"
data-old-short="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>"
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" onkeyup="validateInput(this, 'clients', 'short_name', 'clientBtnSubmit')" required>
</div>
</div>
<!-- <div class="form-row"> -->
<!-- <div class="form-group col-md-4">
<label for="pan">PAN<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="pan" placeholder="Enter PAN Number" data-parsley-error-message="Invalid PAN Number. Example: ABCDE1234F" value="<?= isset($client['pan']) ? $client['pan'] : '' ?>" name="pan" data-parsley-trigger="change" data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$" required>
</div> -->
<!-- <div class="form-group col-md-4">
<label for="gst">GST<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="gst" placeholder="Enter GST Number" data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6" value="<?= isset($client['gst']) ? $client['gst'] : '' ?>" name="gst" data-parsley-trigger="change" data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$" required>
</div> -->
<!-- </div> -->
<hr>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="gst">Logo</label>
<input type="file" name="client_logo" id="client_logo" accept="image/*" onchange="PreviewImage();"><br>
<i class="text">( Image dimensions 100 x 100 pixels and size of 200KB. )</i>
</div>
<div class="form-group col-md-6 float-right" style="position: relative;top: 20px;">
<img src="<?= isset($client['client_logo']) && !empty($client['client_logo']) ? base_url() . "public/uploads/logo/" . $client['client_logo'] : base_url()."public/assets/images/avatar_2x.png" ?>" width="100" height="100" id="uploadPreview" class="avatar img-circle img-thumbnail" alt="avatar"/>
</div>
</div>
<div>
<label class="switch">
<input id="is_download_btn" type="checkbox" name="is_download_btn" <?= (isset($client['is_download_btn']) && $client['is_download_btn'] == 1) ? 'checked' : '' ?>>
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_download_btn" style=" position: relative;bottom: 5px;">Enable Client Export Option</label>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="clientBtnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack"
id="btnBack">Cancel</button>
</div>
</form>
</div>
</div> <!-- end col-->
</div>
</div>
<!-- end -->
<script>
document.addEventListener("DOMContentLoaded", function() {
const switchCheckbox = document.getElementById('switch-checkbox');
const switchInner = document.querySelector('.switch-inner');
if (switchInner) {
switchInner.addEventListener('click', function() {
switchCheckbox.checked = !switchCheckbox.checked;
switchInner.style.transform = switchCheckbox.checked ? 'translateX(100%)' : 'translateX(0)';
});
}
});
</script>
<script>
var PrimaryKey = $('#general_PrimaryKey').val();
var form_action = '';
$(document).ready(function() {
$('#client_logo').change(function() {
validateFile(this);
});
});
$(document).ready(function () {
$("#general_form").submit(function(event) {
event.preventDefault();
var $submitButton = $('#general_form').find('button[type="submit"]');
$submitButton.prop('disabled', true); // Disable the submit button
var isValid = $('#general_form').parsley().validate();
if (!isValid) {
$submitButton.prop('disabled', false);
console.log('Form is Empty', 'Warning');
return ;
}
if(PrimaryKey === ''){
form_action = '<?= base_url("client/general/create"); ?>';
}else{
form_action = '<?= base_url("client/general/edit"); ?>';
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = new FormData($('#general_form')[0]);
var OptionsHTML1 = ''
$.ajax({
data:formData,
url: form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
console.log(res);
console.log($('#general_PrimaryKey').val());
if($('#general_PrimaryKey').val() == ""){
window.location.href = '<?= base_url("client/list/"); ?>' + res.data.id;
}
if(res){
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$('#kyc_tab').click();
$('#btnBranchAdd').show();
$('#BtnAdd').show();
$('#relation_form').show();
$('#btnBranchAdd').show();
var message = (PrimaryKey === '') ? 'Client General Info Created successfully' : 'Client General Info Updated successfully';
toastr.success(message, 'Success');
$submitButton.prop('disabled', false);
let client_name = res.data.client_name ? (' - ' + res.data.client_name) : '';
$('#client_heading').text(client_name);
}, 1000);
}
var idToUse = res.data.id ? res.data.id : res.data.PrimaryKey;
$('#client_id').val(idToUse);
$('#general_PrimaryKey').val(idToUse);
$('#client_id_relation').val(idToUse);
$('#relation_PrimaryKey').val(idToUse);
$('#client_id_branch').val(idToUse);
$('#client_id_for_client_branch').val(idToUse);
$('#client_id_policy').val(idToUse);
$('#policy_PrimaryKey').val(idToUse);
$('#client_id_kyc').val(idToUse);
$('#kyc_PrimaryKey').val(idToUse);
$('#Client_id').val(idToUse);
$('#entity_type').val(res.data.entity_type_id);
var client_id_for_file = res.data.id;
if(PrimaryKey === ''){
$.ajax({
url: '<?= base_url("client/kyc/list/"); ?>' + res.data.entity_type_id,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function (res) {
console.log('kyc docs', res);
var tbody = $('#tbody');
tbody.empty();
$.each(res.data, function (index, item) {
var row = `<tr>
<td> ${item.file_name}</td>
<td id="form_${item.id}" style=""><form class="ajax" ><input class="file-input__input" type="file" name="file_name">
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" class="form-control" value="${item.id}" name="kyc_doc_type_id" />
<input type="hidden" name="client_id" id="id_for_kyc_file" value="${client_id_for_file}"/>
<button class="btn btn-sm btn-primary submit" style="position: relative;right: 80px;">Submit</button></form></td>
<td id="name_${item.id}" style="display:none;"></td>
<td><i data-id="${item.id}" class="mdi mdi-delete btnKycDelete" style="font-size:18px;"></i></td>
</tr>`;
tbody.append(row);
});
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$submitButton.prop('disabled', false);
if (xhr.status === 404) {
toastr.warning('Resource not found', 'Warning');
} else if (xhr.status === 500) {
toastr.warning('Internal server error', 'Warning');
} else {
toastr.warning('Unknown error occurred', 'Warning');
}
}, 1000);
}
});
});
});
function onlyNumbers(event){
var charcode;
charcode = event.which || event.keyCode;
if(charcode>= 48 && charcode <= 57)return true;
return false;
}
function PreviewImage() {
console.log('function called');
var fileInput = document.getElementById("client_logo");
var file = fileInput.files[0];
if (file) {
var allowedExtensions = ["jpg", "jpeg", "png"];
var fileExtension = file.name.split('.').pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension) || file.size > 200 * 1024) {
toastr.warning('Maximum file size allowed is 200KB.', 'File size exceeds limit.');
fileInput.value = ""; // Clear the file input
document.getElementById("uploadPreview").src = "http://ssl.gstatic.com/accounts/ui/avatar_2x.png"; // Remove the preview image
} else {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (event) {
document.getElementById("uploadPreview").src = event.target.result;
};
}
}
}
function validateFile(input) {
const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png"];
const fileExtension = file.name.split(".").pop().toLowerCase();
// Check if the file extension is allowed
if (!allowedExtensions.includes(fileExtension)) {
toastr.warning('Only JPG, JPEG, PNG files are allowed.', 'Invalid file type.');
$("#uploadPreview").attr("src", "http://ssl.gstatic.com/accounts/ui/avatar_2x.png");
input.value = "";
}
// Check file size
const fileSize = file.size / 1024; // in KB
if (fileSize > 200) {
toastr.warning('Maximum file size allowed is 200KB.', 'File size exceeds limit.');
$("#uploadPreview").attr("src", "http://ssl.gstatic.com/accounts/ui/avatar_2x.png");
input.value = "";
}
// Check image dimensions
const img = new Image();
img.onload = function() {
if (this.width !== 100 || this.height !== 100) {
toastr.warning('Image dimensions should be 100x100 pixels.', 'Invalid image dimensions.');
$("#uploadPreview").attr("src", "http://ssl.gstatic.com/accounts/ui/avatar_2x.png");
}
// If both size and dimensions are valid, you can proceed with your logic here
// For example, you can display the image
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById("uploadPreview").src = e.target.result;
};
reader.readAsDataURL(file);
};
img.src = URL.createObjectURL(file);
}
</script>