nhance/app/Views/client_basic_info.php

225 lines
11 KiB
PHP

<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-4">
<label for="client_name">Client Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="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-4">
<label for="short_name">Client Short Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="short_name"
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="pan">PAN<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="pan"
placeholder="Enter PAN Number" value="<?= isset($client['pan']) ? $client['pan'] : '' ?>" name="pan" required>
</div>
<div class="form-group col-md-6">
<label for="gst">GST<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="gst"
placeholder="Enter GST Number" value="<?= isset($client['gst']) ? $client['gst'] : '' ?>" name="gst" required>
</div>
</div>
<hr>
<div class="form-row">
<div class="form-group col-md-6">
<label for="address1">Address 1<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="address1"
placeholder="Enter Address 1" value="<?= isset($client['address1']) ? $client['address1'] : '' ?>" name="address1" required>
</div>
<div class="form-group col-md-6">
<label for="address2">Address 2<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="address2"
placeholder="Enter Address 2" value="<?= isset($client['address2']) ? $client['address2'] : '' ?>" name="address2" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="city">City<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="city"
placeholder="Enter City" value="<?= isset($client['city']) ? $client['city'] : '' ?>" name="city" required>
</div>
<div class="form-group col-md-4">
<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) { ?>
<?php if(isset($client['state'])){ ?>
<?php if($value['id'] == $client['state']) { ?>
<option value="<?= $value['id'] ?>" selected><?= $value['state'] ?></option>
<?php } else { ?>
<option value="<?= $value['id'] ?>"><?= $value['state'] ?></option>
<?php } ?>
<?php } else { ?>
<option value="<?= $value['id'] ?>"><?= $value['state'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="pincode">Pincode<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="pincode"
placeholder="Enter Pincode" value="<?= isset($client['pincode']) ? $client['pincode'] : '' ?>" name="pincode" maxlength="6" required>
</div>
</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> <!-- end col-->
</div>
</div>
<!-- end -->
<script>
$(document).ready(function () {
$("#general_form").submit(function(event) {
event.preventDefault();
var isValid = validateForm();
var PrimaryKey = $('#general_PrimaryKey').val();
var form_action = '';
if (isValid) {
if(PrimaryKey === ''){
form_action = '<?= base_url("client/general/create"); ?>';
}else{
form_action = '<?= base_url("client/general/edit"); ?>';
}
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);
$('#client_id').val(res.data.id);
$('#client_id_relation').val(res.data.id);
$('#client_id_branch').val(res.data.id);
$('#client_id_police').val(res.data.id);
$('#client_id_kyc').val(res.data.id);
$('#kyc_tab').click();
$.toast({
text: 'Client General Info',
heading: "Submitted Sucessfully",
position: 'top-right',
icon: 'success',
bgColor: !1,
});
$.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(res);
$.each(res.data, function(index, item) {
OptionsHTML1 += '<option value="' + item.id + '">' + item.file_name + '</option>';
});
$('#kyc_docs').html(OptionsHTML1);
},
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);
}
});
}
});
function validateForm() {
var isValid = true;
// Perform validation for each field
$('#general_form input, #general_form select').each(function() {
// Check for empty text inputs and selects
if ($(this).is('input[type="text"]') || $(this).is('select')) {
if ($.trim($(this).val()) == '') {
alert('Please fill in all fields');
isValid = false;
return false; // Exit the loop early
}
}
// Check for file inputs (assuming image files)
if ($(this).is('input[type="file"]')) {
var fileInput = $(this)[0];
if (fileInput.files.length === 0) {
alert('Please select an image file');
isValid = false;
return false; // Exit the loop early
}
}
});
return isValid;
}
});
</script>