979 lines
40 KiB
PHP
979 lines
40 KiB
PHP
<style>
|
||
.col-12 {
|
||
max-width: 98% !important;
|
||
}
|
||
.column-header {margin-right: 10px;}
|
||
|
||
.readonly-select {
|
||
pointer-events: none;
|
||
background-color: #f0f0f0;
|
||
color: #666;
|
||
}
|
||
|
||
.custom-dropdown-menu .dropdown-item:hover {
|
||
background-color: #f8f9fa !important;
|
||
color: #16181b !important;
|
||
cursor: pointer !important;
|
||
}
|
||
|
||
.btn-color{
|
||
background-color: rgba(52, 174, 178, 1);
|
||
color: white;
|
||
border:1px solid rgba(52, 174, 178, 1);
|
||
}
|
||
|
||
.btn-color:hover{
|
||
background-color: rgba(41, 139, 142, 1);
|
||
color: white;
|
||
border:1px solid rgba(41, 139, 142, 1);
|
||
}
|
||
.dataTables_length label {height: 21px !important;}
|
||
|
||
</style>
|
||
|
||
<?php
|
||
helper('datatable_view');
|
||
$vm_header_labels = [
|
||
'S.No', 'Owner Type', 'Owner Name', 'RC Book No', 'Vehicle No', 'Vehicle type', 'Description', 'Action',
|
||
];
|
||
$vm_col_count = count($vm_header_labels);
|
||
$vm_col_max_len = array_fill(0, $vm_col_count, 0);
|
||
for ($i = 0; $i < $vm_col_count; $i++) {
|
||
$vm_col_max_len[$i] = mb_strlen($vm_header_labels[$i]);
|
||
}
|
||
$vehicle_Master_Data = $vehicle_Master_Data ?? [];
|
||
$vehicle_des = $vehicle_des ?? [];
|
||
foreach ($vehicle_Master_Data as $index => $row) {
|
||
$vm_col_max_len[0] = max($vm_col_max_len[0], mb_strlen((string) ($index + 1)));
|
||
$vm_col_max_len[1] = max($vm_col_max_len[1], mb_strlen((string) ($row['owner_type'] ?: 'N/A')));
|
||
$vm_col_max_len[2] = max($vm_col_max_len[2], mb_strlen((string) ($row['owner_name'] ?: 'N/A')));
|
||
$vm_col_max_len[3] = max($vm_col_max_len[3], mb_strlen((string) ($row['rc'] ?: 'N/A')));
|
||
$vm_col_max_len[4] = max($vm_col_max_len[4], mb_strlen((string) ($row['vehicle_no'] ?: 'N/A')));
|
||
$vm_col_max_len[5] = max($vm_col_max_len[5], mb_strlen((string) ($row['vehicle_type'] ?: 'N/A')));
|
||
$descLabel = $vehicle_des[$row['description']] ?? 'N/A';
|
||
$vm_col_max_len[6] = max($vm_col_max_len[6], mb_strlen((string) $descLabel));
|
||
$vm_col_max_len[7] = max($vm_col_max_len[7], 4);
|
||
}
|
||
$vm_col_min_px = [48, 88, 120, 100, 100, 100, 120, 72];
|
||
$vm_col_max_px = [64, 160, 280, 180, 180, 200, 320, 88];
|
||
$vm_col_width_px = nhance_dt_column_widths_px($vm_header_labels, $vm_col_max_len, $vm_col_min_px, $vm_col_max_px);
|
||
?>
|
||
<style>
|
||
<?php for ($i = 0; $i < $vm_col_count; $i++) : ?>
|
||
#vehicle-master-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
|
||
#vehicle-master-list-table thead th:nth-child(<?= $i + 1 ?>) {
|
||
min-width: <?= (int) $vm_col_width_px[$i] ?>px;
|
||
width: <?= (int) $vm_col_width_px[$i] ?>px;
|
||
box-sizing: border-box;
|
||
vertical-align: middle;
|
||
overflow: visible !important;
|
||
}
|
||
#vehicle-master-list-table tbody td:nth-child(<?= $i + 1 ?>) {
|
||
width: <?= (int) $vm_col_width_px[$i] ?>px;
|
||
max-width: <?= (int) $vm_col_width_px[$i] ?>px;
|
||
min-width: <?= (int) $vm_col_width_px[$i] ?>px;
|
||
box-sizing: border-box;
|
||
vertical-align: middle;
|
||
}
|
||
<?php endfor; ?>
|
||
#vehicle-master-list-table tbody td:not(:last-child) {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
#vehicle-master-list-table tbody td:last-child {
|
||
overflow: visible;
|
||
text-overflow: clip;
|
||
}
|
||
#vehicle-master-list-table tbody td {
|
||
padding: 5px 11px !important;
|
||
font-size: 13px;
|
||
line-height: 1.25;
|
||
}
|
||
#vehicle-master-list-table thead th {
|
||
padding: 5px 2.35rem 5px 11px !important;
|
||
font-size: 13px;
|
||
line-height: 1.25;
|
||
}
|
||
</style>
|
||
|
||
<div class="row" id="client_list">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<!-- <div class="row" style="margin-bottom:1rem;">
|
||
<div class="col-6" style="align-self: center;">
|
||
<h4 style="position: relative;">Vehicle Master</h4>
|
||
</div>
|
||
</div> -->
|
||
<table data-custom-table-css="table" data-nhance-list-dt="1" id="vehicle-master-list-table" class="table mb-0 nowrap" cellspacing="0">
|
||
<thead class="bg-light">
|
||
<tr>
|
||
<th class="font-weight-medium">S.No </th>
|
||
<th class="font-weight-medium">Owner Type </th>
|
||
<th class="font-weight-medium">Owner Name </th>
|
||
<th class="font-weight-medium">RC Book No </th>
|
||
<th class="font-weight-medium">Vehicle No </th>
|
||
<th class="font-weight-medium">Vehicle type </th>
|
||
<th class="font-weight-medium">Description </th>
|
||
<th class="font-weight-medium text-center">Action </th>
|
||
</tr>
|
||
</thead>
|
||
|
||
<tbody>
|
||
<?php foreach($vehicle_Master_Data as $index => $row){ ?>
|
||
<tr>
|
||
<td><?php echo $index+1; ?></td>
|
||
<td><?php echo $row['owner_type'] ?: 'N/A'; ?></td>
|
||
<td><?php echo $row['owner_name'] ?: 'N/A'; ?></td>
|
||
<td><?php echo $row['rc'] ?: 'N/A'; ?></td>
|
||
<td><?php echo $row['vehicle_no'] ?: 'N/A'; ?></td>
|
||
<td><?php echo $row['vehicle_type'] ?: 'N/A'; ?></td>
|
||
<td><?php echo $vehicle_des[$row['description']] ?? "N/A"; ?></td>
|
||
<td class="text-center table-action-cell">
|
||
<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 class="dropdown-item" data-id="<?= $row['id'];?>"
|
||
onclick="getEditVehicleDetailsData(this)"> <i
|
||
class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||
<a class="dropdown-item" data-id="<?= $row['id'];?>"
|
||
onclick="removeVehicleMasterData(this)"><i
|
||
class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php } ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div><!-- end col -->
|
||
</div>
|
||
<!-- end row -->
|
||
|
||
|
||
<!-- modal content -->
|
||
|
||
<div class="modal fade" id="vehicle_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
|
||
aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered modal-lg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Add New Vehicle</h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-label="Close"
|
||
aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="parsley-examples" method="post" id="vehicle_form" enctype="multipart/form-data" data-parsley-validate>
|
||
<div class="form-group">
|
||
|
||
<input type="hidden" id="vehicle_primary_key" name="vehicle_primary_key">
|
||
|
||
<div class="form-row">
|
||
|
||
<div class="form-group col-md-6 client_type_div">
|
||
<label for="owner_type">Owner Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="Owner_type" name="Owner_type"
|
||
onchange="ownerTypeBasedShowAndHideOwnerBranch(this)" required>
|
||
<option value="">Select Owner type</option>
|
||
<option value="1">Group</option>
|
||
<option value="2">Individual</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="cost_center">Vehicle No<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="vehicle_no" placeholder="Enter Vehicle No"
|
||
name="vehicle_no" required
|
||
data-parsley-pattern="^[A-Z]{2}[0-9]{1,2}[A-Z]{1,2}[0-9]{4}$"
|
||
data-parsley-error-message="Invalid Vehicle Number. Example: TN22AB1234"
|
||
data-parsley-trigger="keyup">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="rc">RC Book <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="rc" placeholder="Enter RC Book No" name="rc" required data-parsley-trigger="keyup">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="type">Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="type" name="type" required>
|
||
<option value="">Select Type</option>
|
||
<?php
|
||
if (isset($vehicle_type) && count($vehicle_type)) {
|
||
foreach ($vehicle_type as $key => $value) {
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="description">Description<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="description" name="description" required>
|
||
<option value="">Select Description</option>
|
||
<?php
|
||
if (isset($vehicle_des) && count($vehicle_des)) {
|
||
foreach ($vehicle_des as $key => $value) {
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="rc"> Old Owner Name <span class="text-danger">(if exist)</span></label>
|
||
<input type="text" class="form-control" id="old_onwer" name="old_onwer" placeholder="Enter Old Owner Name" data-parsley-pattern="^[a-zA-Z0-9\s\.]+$" data-parsley-trigger="keyup">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="owner">Owner Name <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner" name="owner"
|
||
onchange="listOwnerBranch(this); addClient(this)" required>
|
||
<option value="">Select Owner</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-12 ownerbranchdiv">
|
||
<label for="client_branch">Branch<span class="text-danger"></span></label>
|
||
<select class="form-control" id="owner_branch" name="branch_id">
|
||
<option value="">Select Branch</option>
|
||
</select>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<div class="form-group d-flex justify-content-end m-b-0" id="hide_smbt_btn">
|
||
<button class="btn app-btn-outline-secondary mr-2" type="button" data-dismiss="modal" aria-hidden="true">Cancel</button>
|
||
<button type="submit" id="btnSubmit" class="btn app-btn-secondary waves-effect waves-light" id="cd_master_btn_Submit">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div>
|
||
|
||
<!-- /.modal -->
|
||
|
||
|
||
<!-- Client form content modal-->
|
||
|
||
<div class="modal fade" id="upload_enrollment_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
|
||
aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Add New Client</h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="parsley-examples" method="post" id="client_form" enctype="multipart/form-data" data-parsley-validate>
|
||
<div class="form-group">
|
||
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="client_type">Client type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="client_type" name="client_type"
|
||
onchange="ownerTypeBasedShowAndHideOwnerBranch(this)" required>
|
||
<option value="">Select Owner type</option>
|
||
<option value="1">Group</option>
|
||
<option value="2">Individual</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-12">
|
||
<label for="client_name">Client Name<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="client_name" name="client_name" required data-parsley-pattern="^[a-zA-Z0-9\s\.,\-_'&\(\)]+$" data-parsley-trigger="keyup">
|
||
</div>
|
||
<div class="form-group col-md-12">
|
||
<label for="short_name">Client Short name<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="short_name" name="short_name" required data-parsley-pattern="^[a-zA-Z0-9_\-]+$" data-parsley-trigger="keyup">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="cost_center">PAN<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="pan" placeholder="Enter PAN No" name="pan" required data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$" data-parsley-trigger="keyup">
|
||
</div>
|
||
</div>
|
||
|
||
<hr>
|
||
|
||
<!-- Individual Client HTML -->
|
||
<div class="form-row clienttypediv" style="display: none;">
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="dob">Date of Birth<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="dob" placeholder="DD/MM/YYYY" name="dob" data-parsley-pattern="^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$" data-parsley-pattern-message="Please enter a valid date in DD/MM/YYYY format.">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="cost_center">Mobile<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="phone" placeholder="Enter Mobile Number" name="phone" data-parsley-type="digits" data-parsley-length="[10,10]">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="cost_center">Email<span class="text-danger">*</span></label>
|
||
<input type="email" class="form-control" id="email" placeholder="Enter Email" name="email">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="aadhar">Aadhar<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadhaar No" name="aadhar" data-parsley-type="digits" data-parsley-length="[12,12]">
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<!-- Group client HTML -->
|
||
<div class="form-row branchdiv">
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="short_name">Entity Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="entity_type_id" name="entity_type_id">
|
||
<option value="" selected>Select Entity</option>
|
||
<?php
|
||
if (isset($entity) && count($entity)) {
|
||
foreach ($entity as $key => $value) {
|
||
echo "<option value=" . $value['id'] . ">" . $value['name'] . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="client_name">Branch Name<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="branch_name" name="branch_name" data-parsley-pattern="^[a-zA-Z0-9\s\.,\-_'&\(\)]+$">
|
||
</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" name="branch_code" data-parsley-pattern="^[a-zA-Z0-9_\-]+$">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="branch_code">Name<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="name" name="name" data-parsley-pattern="^[a-zA-Z\s\.]+$">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="branch_code">Mobile<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="mobile" name="mobile" data-parsley-type="digits" data-parsley-length="[10,10]">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<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" 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>
|
||
|
||
</div>
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div>
|
||
|
||
<!-- end of Client form content modal -->
|
||
|
||
<script>
|
||
var client_list = ''; // local variable for storing the client list
|
||
var branch_list = ''; // local variable for storing the client branch list
|
||
|
||
|
||
$(document).ready(function() {
|
||
getClientAndBranchAndPolicy()
|
||
$('#owner').select2();
|
||
$('#owner_branch').select2();
|
||
})
|
||
|
||
$(document).ready(function() {
|
||
|
||
var table = $('#vehicle-master-list-table');
|
||
if (table.length) {
|
||
nhanceListDataTableBeforeInit();
|
||
var dataTable = table.DataTable(nhanceMergeListDataTableOptions({
|
||
// dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
|
||
// "<'row'<'col-sm-12'tr>>" +
|
||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>",
|
||
dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
|
||
"<'row'<'col-sm-12'tr>>" +
|
||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||
buttons: [
|
||
{
|
||
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
|
||
className: 'btn app-btn-primary btn-color mr-2',
|
||
attr: {
|
||
id: 'btnAdd',
|
||
title: 'Add'
|
||
},
|
||
action: function () {
|
||
showModal('add')
|
||
}
|
||
},
|
||
{
|
||
extend: 'collection',
|
||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||
className: 'btn app-btn-secondary ',
|
||
buttons: [
|
||
{
|
||
extend: 'csv',
|
||
title: 'Vehicle-Master-List',
|
||
className: 'my_class',
|
||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||
className: 'app-btn-primary my_class',
|
||
exportOptions: {
|
||
columns: ':not(:last-child)'
|
||
},
|
||
},
|
||
{
|
||
extend: 'excel',
|
||
sheetName: 'Vehicle-Master',
|
||
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
|
||
exportOptions: {
|
||
orthogonal: 'sort'
|
||
},
|
||
className: 'app-btn-primary ',
|
||
}
|
||
]
|
||
}
|
||
],
|
||
language: {
|
||
search: `
|
||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||
_INPUT_
|
||
<i class="mdi mdi-magnify datatable-search-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||
</div>`,
|
||
searchPlaceholder: "Search",
|
||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||
},
|
||
paging: true,
|
||
pageLength: 10,
|
||
order: [[0, 'desc']],
|
||
columnDefs: [
|
||
<?php for ($i = 0; $i < $vm_col_count; $i++) : ?>
|
||
{ targets: <?= $i ?>, width: '<?= (int) $vm_col_width_px[$i] ?>px' },
|
||
<?php endfor; ?>
|
||
],
|
||
}));
|
||
nhanceListDataTableAfterInit();
|
||
nhanceListDataTableBindAdjust(dataTable);
|
||
|
||
function applyBottomRowDropup() {
|
||
if (!dataTable) return;
|
||
|
||
const currentRows = dataTable.rows({ page: 'current' }).nodes().toArray();
|
||
$('#vehicle-master-list-table tbody tr').removeClass('nh-force-dropup');
|
||
$('#vehicle-master-list-table tbody tr td.table-action-cell .btn-group.dropdown').removeClass('dropup');
|
||
|
||
const targetCount = Math.min(2, currentRows.length);
|
||
for (let i = 0; i < targetCount; i++) {
|
||
const row = currentRows[currentRows.length - 1 - i];
|
||
if (!row) continue;
|
||
$(row).addClass('nh-force-dropup');
|
||
$(row).find('td.table-action-cell .btn-group.dropdown').addClass('dropup');
|
||
}
|
||
}
|
||
applyBottomRowDropup();
|
||
$('#vehicle-master-list-table').on('draw.dt', applyBottomRowDropup);
|
||
|
||
} else {
|
||
console.error("Table atet found.");
|
||
}
|
||
});
|
||
|
||
function getEditVehicleDetailsData(input) {
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
var vehicle_id = $(input).attr('data-id');
|
||
$('#myCenterModalLabel').text('Update Vehicle Details');
|
||
|
||
showModal()
|
||
|
||
$.ajax({
|
||
url: '<?php echo base_url('master/vehicle/list/');?>' + vehicle_id,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log(res)
|
||
|
||
// $('#vehicle_form').attr('action', '<?php echo base_url('master/vehicle/edit');?>');
|
||
$('#vehicle_primary_key').val(res.data.id);
|
||
$('#Owner_type').val(res.data.client_type);
|
||
$('#vehicle_no').val(res.data.vehicle_no);
|
||
$('#rc').val(res.data.rc);
|
||
$('#type').val(res.data.type);
|
||
$('#description').val(res.data.description);
|
||
$('#owner').val(res.data.owner).addClass('readonly-select').change().select2('destroy');
|
||
setTimeout(function() {
|
||
$('#owner_branch').val(res.data.branch_id).addClass('readonly-select').change()
|
||
.select2('destroy');
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}, 1000)
|
||
$('#btnSubmit').text('Update');
|
||
|
||
if (res.data.client_type == 2) {
|
||
$('.ownerbranchdiv').hide();
|
||
} else {
|
||
$('.ownerbranchdiv').show();
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}
|
||
|
||
function showModal(type) {
|
||
|
||
if (type == 'add') {
|
||
$('#vehicle_form')[0].reset();
|
||
if ($('#vehicle_form').parsley()) {
|
||
$('#vehicle_form').parsley().reset();
|
||
}
|
||
$('#myCenterModalLabel').text('Add New Vehicle');
|
||
$('#owner').removeClass('readonly-select');
|
||
$('#owner_branch').removeClass('readonly-select');
|
||
$('#Owner_type').val('');
|
||
$('#vehicle_no').val('');
|
||
$('#rc').val('');
|
||
$('#type').val('');
|
||
$('#description').val('');
|
||
$('#owner').val('').select2();
|
||
$('#owner_branch').val('').select2();
|
||
$('#btnSubmit').text('Submit');
|
||
}
|
||
|
||
var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
myModal.show();
|
||
}
|
||
|
||
function removeVehicleMasterData(element) {
|
||
|
||
Swal.fire({
|
||
title: "Are you sure?",
|
||
text: "You need to remove this Vehicle.",
|
||
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/vehicle/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('Vehicle Data removed successfully.', 'Success');
|
||
location.reload();
|
||
} else {
|
||
toastr.warning('Failed to remove Vehicle Data.', 'Warning');
|
||
}
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.log('Something Wrong!', 'Warning');
|
||
}
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
}
|
||
|
||
function ownerTypeBasedShowAndHideOwnerBranch(input) {
|
||
var owner_type_id = $(input).val()
|
||
|
||
if (owner_type_id == 2) {
|
||
$('.ownerbranchdiv').hide();
|
||
$('#owner_branch').prop('required', false);
|
||
} else {
|
||
$('.ownerbranchdiv').show();
|
||
$('#owner_branch').prop('required', true);
|
||
}
|
||
|
||
// Clear and add default options for client
|
||
$('#owner').empty().append($('<option>', {
|
||
value: '',
|
||
text: 'Select Client'
|
||
}));
|
||
|
||
$('#owner').append($('<option>', {
|
||
value: 'add_owner',
|
||
text: '+ Add Owner'
|
||
}));
|
||
|
||
// Populate client options based on selected client type
|
||
if (owner_type_id) {
|
||
|
||
$.each(client_list, function(index, item) {
|
||
if (item.client_type == owner_type_id) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.client_name,
|
||
'data-cn': item.client_name,
|
||
'data-ct': item.client_type
|
||
});
|
||
$('#owner').append(option);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
// Initialize or refresh Select2 for both dropdowns
|
||
$('#owner').select2();
|
||
}
|
||
|
||
function addClient(input) {
|
||
|
||
let client_id = $(input).val();
|
||
console.log('client_id ----', client_id);
|
||
|
||
if (client_id === 'add_owner') {
|
||
|
||
// Initialize the modals
|
||
// $('.close').click();
|
||
var vehicleModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
var clientModal = new bootstrap.Modal(document.getElementById('upload_enrollment_model'));
|
||
|
||
// Clear the form fields
|
||
$('#entity_type_id').val('');
|
||
$('#branch_name').val('');
|
||
$('#client_branch_id').val('');
|
||
$('#branch_code').val('');
|
||
$('#name').val('');
|
||
$('#mobile').val('');
|
||
$('#gst').val('');
|
||
$('#dob').val('');
|
||
$('#phone').val('');
|
||
$('#email').val('');
|
||
$('#aadhar').val('');
|
||
$('#owner').val('').change();
|
||
|
||
// Hide the vehicle modal
|
||
// vehicleModal.hide();
|
||
clientModal.show();
|
||
|
||
|
||
// Once the vehicle modal is hidden, show the client modal
|
||
// document.getElementById('vehicle_modal').addEventListener('hidden.bs.modal', function () {
|
||
// console.log('vehicle_modal is hidden');
|
||
// clientModal.show();
|
||
// });
|
||
}
|
||
}
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------------
|
||
|
||
$("#vehicle_form").submit(function(event) {
|
||
|
||
event.preventDefault();
|
||
|
||
var isValid = $('#vehicle_form').parsley().validate();
|
||
if (!isValid) {
|
||
console.log('Form is Empty', 'Warning');
|
||
return;
|
||
}
|
||
|
||
form_action = '<?= base_url("util/createVehicleWithMinimalData"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
var formData = new FormData($('#vehicle_form')[0]);
|
||
|
||
$.ajax({
|
||
data: formData,
|
||
url: form_action,
|
||
type: "POST",
|
||
dataType: 'json',
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(res) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log('create Vehicle Data response', res);
|
||
|
||
if (res.status == true) {
|
||
toastr.success(res.message, 'Success');
|
||
window.location.reload()
|
||
} else {
|
||
toastr.error(res.message, 'Error');
|
||
}
|
||
|
||
$('.close').click();
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
if (xhr.status === 400) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
let errorMessages = "";
|
||
let seenMessages = []; // Array to store unique messages
|
||
if (response.errors) {
|
||
$.each(response.errors, function (field, message) {
|
||
if (!seenMessages.includes(message)) {
|
||
errorMessages += `• ${message}<br>`;
|
||
seenMessages.push(message); // Mark this message as "seen"
|
||
}
|
||
});
|
||
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||
} else {
|
||
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||
}
|
||
|
||
} else if (xhr.status === 403) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
toastr.error(response.message, 'Security Policy');
|
||
} else if (xhr.status === 500) {
|
||
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||
} else {
|
||
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#client_form").submit(function(event) {
|
||
|
||
event.preventDefault();
|
||
|
||
var isValid = $('#client_form').parsley().validate();
|
||
if (!isValid) {
|
||
console.log('Form is Empty', 'Warning');
|
||
return;
|
||
}
|
||
|
||
form_action = '<?= base_url("util/createClientWithMinimalData"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
var client_type = $('#client_type').val();
|
||
|
||
var formData = new FormData($('#client_form')[0]);
|
||
formData.append('client_type', client_type)
|
||
|
||
$.ajax({
|
||
data: formData,
|
||
url: form_action,
|
||
type: "POST",
|
||
dataType: 'json',
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(res) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log('create Client With Minimal Data response', res)
|
||
// console.log('create Client With Minimal Data response', res.data)
|
||
|
||
if (res.status == true) {
|
||
getClientAndBranchAndPolicy();
|
||
|
||
if (res.data.client_type == 2) {
|
||
$('.ownerbranchdiv').hide();
|
||
} else {
|
||
$('.ownerbranchdiv').show();
|
||
}
|
||
|
||
$('#Owner_type').val(res.data.client_type);
|
||
|
||
setTimeout(function() {
|
||
$('#owner').val(res.client_id).change();
|
||
setTimeout(function() {
|
||
$('#owner_branch').val(res.branch_id).select2();
|
||
}, 1000);
|
||
}, 2000)
|
||
|
||
toastr.success(res.message, 'Success');
|
||
} else {
|
||
toastr.error(res.message, 'Error');
|
||
}
|
||
|
||
$('.close').click();
|
||
|
||
showModal()
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
});
|
||
|
||
//----------------------------------------------------------------------------------------------------
|
||
|
||
$('#client_type').change(function() {
|
||
if ($(this).val() == 2) {
|
||
$('.branchdiv').hide();
|
||
$('.clienttypediv').show();
|
||
|
||
$('#entity_type_id').prop('required', false);
|
||
$('#branch_name').prop('required', false);
|
||
$('#client_branch_id').prop('required', false);
|
||
$('#branch_code').prop('required', false);
|
||
$('#name').prop('required', false);
|
||
$('#mobile').prop('required', false);
|
||
$('#gst').prop('required', false);
|
||
|
||
$('#dob').prop('required', true);
|
||
$('#phone').prop('required', true);
|
||
$('#email').prop('required', true);
|
||
$('#aadhar').prop('required', true);
|
||
|
||
} else {
|
||
$('.branchdiv').show();
|
||
$('.clienttypediv').hide();
|
||
|
||
$('#entity_type_id').prop('required', true);
|
||
$('#branch_name').prop('required', true);
|
||
$('#client_branch_id').prop('required', true);
|
||
$('#branch_code').prop('required', true);
|
||
$('#name').prop('required', true);
|
||
$('#mobile').prop('required', true);
|
||
$('#gst').prop('required', true);
|
||
|
||
$('#dob').prop('required', false);
|
||
$('#phone').prop('required', false);
|
||
$('#email').prop('required', false);
|
||
$('#aadhar').prop('required', false);
|
||
}
|
||
});
|
||
|
||
//----------------------------------------------------------------------------------------------------
|
||
|
||
function getClientAndBranchAndPolicy() {
|
||
$.ajax({
|
||
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
console.log('getClientAndBranchAndPolicy', res);
|
||
if (res.status == true) {
|
||
client_list = res.client_data;
|
||
branch_list = res.branch_data;
|
||
appendOwner(client_list)
|
||
} else {
|
||
console.log('No data found');
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}
|
||
|
||
function appendOwner(data) {
|
||
$('#owner').empty();
|
||
|
||
$('#owner').append($('<option>', {
|
||
value: '',
|
||
text: 'Select Owner'
|
||
}));
|
||
|
||
$('#owner').append($('<option>', {
|
||
value: 'add_owner',
|
||
text: '+ Add Owner'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.client_name,
|
||
});
|
||
|
||
$('#owner').append(option);
|
||
});
|
||
|
||
}
|
||
|
||
function listOwnerBranch(input) {
|
||
|
||
let owner_id = $(input).val();
|
||
console.log('owner_id', owner_id);
|
||
|
||
if (branch_list != '') {
|
||
// console.log(branch_list[client_id]);
|
||
let data = branch_list[owner_id];
|
||
appendOwnerBranch(data);
|
||
}
|
||
}
|
||
|
||
function appendOwnerBranch(data) {
|
||
|
||
$('#owner_branch').empty();
|
||
|
||
$('#owner_branch').append($('<option>', {
|
||
value: '',
|
||
text: 'Select Branch'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.branch_name
|
||
});
|
||
$('#owner_branch').append(option);
|
||
});
|
||
}
|
||
|
||
function onlyNumbers(event) {
|
||
var charcode;
|
||
charcode = event.which || event.keyCode;
|
||
if (charcode >= 48 && charcode <= 57 || charcode == 46) return true;
|
||
return false;
|
||
}
|
||
</script>
|