BBnepal-Accounts/hostel/application/views/hms-admin/rooms.php

330 lines
10 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<style>
.bed-input {
background-color: #fff !important;
}
label.error {
color : red;
text-align: left;
display: block;
}
#bed_name_err {
color : red;
text-align: center;
}
</style>
<div class="row dash-main-row">
<div class="col-md-10 col-lg-10 p-0">
<ul class="nav nav-pills mb-3 rooms-sections row" id="pills-tab" role="tablist">
<li class="nav-item section-sec col-md-3 p-0">
<a class="nav-link sec-head " href="<?php echo base_url() ?>blocks" role="tab" aria-controls="pills-blocks" aria-selected="true">Blocks</a>
</li>
<li class="nav-item section-sec col-md-3 p-0">
<a class="nav-link sec-head " href="<?php echo base_url() ?>floors" aria-selected="false">Floors</a>
</li>
<li class="nav-item section-sec col-md-3 p-0">
<a class="nav-link sec-head active" href="<?php echo base_url() ?>rooms" aria-selected="false">Rooms</a>
</li>
<li class="nav-item section-sec col-md-3 p-0">
<a class="nav-link sec-head" href="<?php echo base_url() ?>beds" aria-selected="false">Beds</a>
</li>
</ul>
</div>
</div>
<div class="row dash-main-row mt-4 mb-4">
<div class="col-md-12 col-lg-12 p-0">
<?php if ($this->session->flashdata('success')) { ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<p><?php echo $this->session->flashdata('success') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<?php if ($this->session->flashdata('failed')) { ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<p><?php echo $this->session->flashdata('failed') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<table class="example text-center" style="width : 100%" class="table dash-table">
<thead>
<tr>
<th scope="col" class="dash-th">SI.No</th>
<th scope="col" class="dash-th rooms-th">Room No</th>
<th scope="col" class="dash-th rooms-th">Floor Name</th>
<th scope="col" class="dash-th rooms-th">Block</th>
<th scope="col" class="dash-th rooms-th">Room Type</th>
<th scope="col" class="dash-th rooms-th">Total Beds</th>
<th scope="col" class="dash-th-action">Actions</th>
</tr>
</thead>
<tfoot class="text-center">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($rooms_data as $key => $value) {
?>
<tr>
<td ><?= $key + 1 ?></td>
<td id="td-room" class="rooms-td"><?= $value['room_name'] ?></td>
<td id="td-floor" class="rooms-td"><?= $value['floor_name'] ?></td>
<td id="td-block" class="rooms-td"><?= $value['block_name'] ?></td>
<td class="rooms-td"><?= $value['room_ac'] ?></td>
<td class="rooms-td"><?= $value['beds_count'] ?></td>
<td class="preview-img">
<img class="action-img" onClick="set_room_id(<?= $value['id'] ?>,this)" src="<?php echo base_url() ?>assets-hms/images/dashboard/edit-icon.svg" data-toggle="modal" data-target="#EditRoomsCenter" alt="" data-backdrop="static" data-keyboard="false">
<img src="<?php echo base_url() ?>assets-hms/images/dashboard/delete-icon.svg" alt="" onclick ="roomdel(<?php echo $value['id'] ?>)" data-toggle="modal" data-target="#DeleteRoomsCenter" data-backdrop="static" data-keyboard="false">
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="EditRoomsCenter" tabindex="-1" role="dialog" aria-labelledby="EditRoomsCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form id="rooms-bed-form" method="post">
<div class="modal-header add-block-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit Rooms</h5>
</div>
<input type="hidden" name="room_id" id="room_id">
<div class="modal-body add-block-body">
<div class="block-floor-info d-flex justify-content-around mb-4">
<p><b>Block Name: </b><span id="pop_block_name">Block 1</span></p>
<p><b>Floor Name: </b><span id="pop_floor_name">Floor 1</span></p>
</div>
<p>Room Name</p>
<input type="text" value="A101" placeholder="A101" readonly class="room-name form-control add-block-input">
<div class="edit-floor-titles">
<div class="d-flex" style="width: 90%;">
<p>Add Beds</p>
<i onclick="addInputField(this)" class="fas fa-plus add-icon"></i>
</div>
</div>
<div class="beds-container">
</div>
</div>
<div id="bed_name_err"></div>
<div class="modal-footer add-block-footer">
<button type="submit" id="submit-beds" class="btn btn-primary add-block-blue">Update</button>
<button type="button" class="btn btn-secondary add-block-cancel" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
</div>
<!-- Delete Modal -->
<div class="modal fade" id="DeleteRoomsCenter" tabindex="-1" role="dialog" aria-labelledby="DeleteRoomsCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header add-block-header">
<h5 class="modal-title" id="exampleModalLongTitle">Delete Room</h5>
</div>
<div class="modal-body add-block-body">
<input type="hidden" id="room_del_id" />
<h6>Are you sure you want to delete ?</h6>
</div>
<div class="modal-footer add-block-footer">
<button type="button" onclick="deletedata($('#room_del_id').val());" class="btn btn-danger ">Yes</button>
<button type="button" class="btn btn-dark " data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
<script>
let idCount = 0;
let room_id;
let block_name,floor_name,room_name;
const set_room_id = (id, ele) => {
room_id = id;
let current = ele;
while($(current).prop("tagName") != 'TR' ) {
current = $(current).parent();
}
block_name = $(current).children('#td-block').text();
floor_name = $(current).children('#td-floor').text();
room_name = $(current).children('#td-room').text();
$('#pop_floor_name').text(floor_name);
$('#pop_block_name').text(block_name);
$('.room-name').val(room_name);
}
function roomdel(icn){
$('#room_del_id').val(icn);
}
function deletedata(id){
window.location.href = "<?php echo base_url(); ?>HmsAdmin/delete_room/" + id;
}
const addInputField = (ele) => {
$('#empty-bed-err').hide();
$('#submit-beds').attr('disabled', false);
let roomName = $('.room-name').val();
let checkForAdd = $('.bed-input').length;
let inputContainer = '<div class="edit-rooms-input beds-inner-container mt-3"><input type="text" value="'+(roomName+'-'+(checkForAdd+1))+'" name="bed_names['+(checkForAdd+1)+']" readOnly class="form-control bed-input add-rooms-inputs"><img onClick="deleteInput(this)" class="edit-rooms-ico" src="<?php echo base_url() ?>assets-hms/images/dashboard/delete-icon.svg" alt=""></div>';
$('.beds-container').append(inputContainer);
idCount++;
}
const deleteInput = (ele) => {
$(ele).parent().remove();
}
// Before Modal Event
$("#EditRoomsCenter").on('show.bs.modal', function(e){
$('.beds-container').empty();
$.ajax({
url : '<?php echo base_url() ?>' + 'HmsAdmin/ajax_get_rooms_bed_info',
data : {
id : room_id
},
type : 'POST',
async : false,
success: function(data){
if(data == '') {
$('.beds-container').empty();
$('.beds-container').append('<p id="empty-bed-err" style="color:red" class="mt-2">This Room doesn\'t have any bed</p>');
$('#submit-beds').attr('disabled', true);
} else {
$('.beds-container').append(data);
}
}
});
});
//
jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || /^[a-z0-9\-\s]+$/i.test(value);
}, "Please enter alphanumeric Characters only");
// Edit Form Validation
$("#rooms-bed-form").validate({
ignore: ':hidden',
rules: {
<?php for($i = 0; $i <= 20; $i++) {
echo "'bed_names[$i]' : {
required : true,
alphanumeric : true
},";
}?>
},
submitHandler: function(form,e) {
e.preventDefault();
$(form).attr('action', "<?php echo base_url() ?>HmsAdmin/ae_beds/"+room_id);
$('#room_id').val(room_id);
form.submit();
}
});
const deleteInputFromDb = (ele,room_id) => {
$.ajax({
url : '<?php echo base_url() ?>' + 'HmsAdmin/ajax_delete_row',
data : {
id : room_id,
table : 'hms_beds'
},
type : 'POST',
async : false,
success: function(data){
if(data){
$(ele).parent().remove();
} else {
$('#bed_name_err').text('Bed could not be deleted as it is linked with rooms');
}
}
});
}
$(document).ready(function() {
$('.example').DataTable( {
initComplete: function () {
this.api().columns([1, 2, 3, 4, 5]).every( function () {
var column = this;
var select = $('<select><option value="">Filter</option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
} );
})
</script>