457 lines
27 KiB
PHP
457 lines
27 KiB
PHP
<main class="common_margin" id="main">
|
|
<div class="main-wrap">
|
|
<div class="dashboard-cover">
|
|
<div class="subsec_sec">
|
|
<div class="subject_l_new">
|
|
<div class="subject_lsec">
|
|
<a href="javascript:history.back()"><button class="btn btn-dark btn-sm">Back</button></a>
|
|
<div class="common-heading">
|
|
<h2>Issue Book</h2>
|
|
</div>
|
|
<?php if ($this->session->flashdata('success')) : ?>
|
|
<div class="alert alert-success"><strong>Success!</strong><?= $this->session->flashdata('success'); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($this->session->flashdata('failure')) : ?>
|
|
<div class="alert alert-danger"><strong>Failure!</strong><?= $this->session->flashdata('failure'); ?></div>
|
|
<?php endif; ?>
|
|
<form id="issuedBookForm">
|
|
<input type="hidden" id="divCount" value="1">
|
|
<input type="hidden" id="no_of_book_per_user" value="<?= $gSData['no_of_book_per_user']; ?>">
|
|
<div class="common-sub-heading">Student Details</div>
|
|
<div class="subject_lformarea book-form-area">
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="eu_id" id="eu_id" placeholder="Student ID" onkeyup="getEndUserData(this.value)" autocomplete="off">
|
|
<p class="form_err" id="error-eu_unique_id"></p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="student_class" id="student_class" placeholder="Class" readonly>
|
|
<p class="form_err" id="error-student_class"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="fname" id="fname" placeholder="First Name" readonly>
|
|
<p class="form_err" id="error-fname"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="lname" id="lname" placeholder="Last Name" readonly>
|
|
<p class="form_err" class="error-lname"></p>
|
|
</div>
|
|
</div>
|
|
<div style="color:red;font-size: small;" id="alertMsg"></div>
|
|
<input type="hidden" id="rem_issued_book_cnt" value="" />
|
|
<input type="hidden" id="ttl_issue_book_cnt" value="" />
|
|
<div class="common-sub-heading" id="bookDetailDiv">Book Details</div>
|
|
<div class="subject_lformarea book-form-area" id="hidebookDiv1">
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="book_id" id="book_id1" placeholder="ISBN" onkeyup="getBookData(this.value, 1)">
|
|
<p class="form_err" id="error-book_id"></p>
|
|
<i class="fas fa-barcode"></i>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="title" id="title1" placeholder="Book Title" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="category" id="category1" placeholder="Category" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="author" id="author1" placeholder="Author" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="publisher" id="publisher1" placeholder="Publisher" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="number" class="form-control txtData" name="year" id="year1" placeholder="Year" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="ttl_pages" id="ttl_pages1" placeholder="Total Pages" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control txtData" name="description" id="description1" placeholder="Description" readonly>
|
|
<p class="form_err"></p>
|
|
</div>
|
|
<div class="form-group assign_subject">
|
|
<select class="form-control txtData" name="book_health[]" id="book_health1">
|
|
<option value="">Select Book Health</option>
|
|
<option value="good">Good</option>
|
|
<option value="average">Average</option>
|
|
<option value="damaged">Damaged</option>
|
|
</select>
|
|
<p class="form_err" id="error-book_health"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="date" class="form-control txtData" name="issued_date[]" id="issued_date1" placeholder="Date of Issue" readonly>
|
|
<p class="form_err" id="error-issued_date"></p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="date" class="form-control txtData" name="return_date[]" id="return_date1" placeholder="Date of Return" readonly>
|
|
<p class="form_err" id="error-return_date"></p>
|
|
</div>
|
|
</div>
|
|
<p class="form_err" id="error-existingBook1"></p>
|
|
<div class="addBookWrap">
|
|
<button type="submit" id="button1" class="subject_addbtn add-btn-border" onclick="addMoreBook()">Add another book</button>
|
|
</div>
|
|
<div class="subject_lformarea book-form-area" id="moreBookDetailDiv"></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div class="sibject_r_new">
|
|
<div class="dashboard-cover-wrap">
|
|
<form id="iBForm" method="POST">
|
|
<input type="hidden" name="name" value="1">
|
|
<input type="hidden" name="id" id="id" value="<?= $idVal; ?>">
|
|
<input type="hidden" name="eu_unique_id" id="eu_unique_id" value="">
|
|
<input type="hidden" name="issueddate" id="issueddate" value="">
|
|
<input type="hidden" name="returndate" id="returndate" value="">
|
|
<input type="hidden" name="bookhealth" id="bookhealth" value="">
|
|
<input type="hidden" name="ttlrows" id="ttlrows" value="">
|
|
<table id="tbl" class="display dataTable table-responsive">
|
|
<thead>
|
|
<tr>
|
|
<th>Sl No.</th>
|
|
<th>ISBN</th>
|
|
<th>Title</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="contentBody"></tbody>
|
|
</table>
|
|
<div class="issue_book_btn">
|
|
<button type="submit" class="subject_addbtn" onclick="saveData()">Issue Book</button>
|
|
</div>
|
|
<p style="color:red;" id="error-msg"></p>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<!--End right-top side-->
|
|
</div>
|
|
<script defer src="<?= base_url(); ?>assets-lms/js/bootstrap-select.min.js"></script>
|
|
|
|
<script src="<?= base_url(); ?>assets-lms/js/jquery-3.4.1.min.js"></script>
|
|
<script src="<?= base_url(); ?>assets-lms/js/jquery.validate.js"></script>
|
|
<script src="<?= base_url(); ?>assets-lms/js/additional-methods.js"></script>
|
|
<script src="<?= base_url(); ?>assets-lms/js/bootstrap.min.js"></script>
|
|
<script src="<?= base_url(); ?>assets-lms/js/popper.min.js"></script>
|
|
<script defer src="<?= base_url(); ?>assets-lms/js/all.js"></script>
|
|
<script defer src="<?= base_url(); ?>assets-lms/js/main.js"></script>
|
|
<script src="<?= base_url(); ?>assets-lms/owl-carousel/js/owl.carousel.min.js"></script>
|
|
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$('.user-drpdown').click(function() {
|
|
$('.drpdown-items').toggle();
|
|
});
|
|
});
|
|
|
|
|
|
//table js
|
|
$('#tbl').DataTable({
|
|
"lengthMenu": [
|
|
[5, 10, 25, 50, -1],
|
|
[5, 10, 25, 50, "All"]
|
|
]
|
|
});
|
|
//table js end
|
|
//multiple select js start
|
|
$('select').selectpicker();
|
|
//multiple select js end
|
|
</script>
|
|
<script>
|
|
function getEndUserData(eu_id) {
|
|
$.ajax({
|
|
type: 'post',
|
|
url: '<?= base_url(); ?>LmsAdmin/getStudentDataById',
|
|
data: {
|
|
'id': eu_id
|
|
},
|
|
success: function(result) {
|
|
var obj = JSON.parse(result);
|
|
var stdname = obj.name.split(" ");
|
|
var rembook = (obj.ttl_issued_book_cnt) - (obj.eu_issued_book_cnt);
|
|
var html = "You have already issued " + obj.eu_issued_book_cnt + " book out of " + obj.ttl_issued_book_cnt + " books, remaining you can issue " + rembook + " book to this user.";
|
|
$('#student_class').val(obj.class_name);
|
|
$('#fname').val(stdname[0]);
|
|
$('#lname').val(stdname[1]);
|
|
$('#rem_issued_book_cnt').val(rembook);
|
|
$('#ttl_issue_book_cnt').val(obj.ttl_issued_book_cnt);
|
|
$('#alertMsg').text(html);
|
|
}
|
|
});
|
|
}
|
|
|
|
function getBookData(isbn, ref) {
|
|
var tableName = 'lms_books';
|
|
$.ajax({
|
|
type: 'post',
|
|
url: '<?= base_url(); ?>LmsAdmin/getDataById',
|
|
data: {
|
|
'id': isbn,
|
|
'tableName': tableName
|
|
},
|
|
success: function(result) {
|
|
var obj = JSON.parse(result);
|
|
//issed_for = obj.lending_days;
|
|
//issed_date = getTodayDate();
|
|
//return_date = getreturndate(issed_for);
|
|
|
|
var crrDateObj = NepaliFunctions.GetCurrentBsDate();
|
|
issed_date = crrDateObj.year + '-' + NepaliFunctions.Get2DigitNo(crrDateObj.month) + '-' + NepaliFunctions.Get2DigitNo(crrDateObj.day);
|
|
|
|
retDateObj = NepaliFunctions.BsAddDays(crrDateObj, Number(obj.lending_days));
|
|
return_date = retDateObj.year + '-' + NepaliFunctions.Get2DigitNo(retDateObj.month) + '-' + NepaliFunctions.Get2DigitNo(retDateObj.day);
|
|
|
|
$('#title' + ref).val(obj.title);
|
|
$('#category' + ref).val(obj.category_name);
|
|
$('#author' + ref).val(obj.author);
|
|
$('#publisher' + ref).val(obj.publisher);
|
|
$('#year' + ref).val(obj.published_year);
|
|
$('#ttl_pages' + ref).val(obj.total_no_of_pages);
|
|
$('#description' + ref).val(obj.description);
|
|
$('#issued_date' + ref).val(issed_date);
|
|
$('#return_date' + ref).val(return_date);
|
|
}
|
|
});
|
|
}
|
|
|
|
function getTodayDate() {
|
|
var today = new Date();
|
|
var dd = String(today.getDate()).padStart(2, '0');
|
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
|
var yyyy = today.getFullYear();
|
|
|
|
today = yyyy + '-' + mm + '-' + dd;
|
|
return today;
|
|
}
|
|
|
|
function getreturndate(issed_for) {
|
|
var today = new Date();
|
|
var newDate = addDays(today, issed_for);
|
|
if (issed_for == 0) {
|
|
var dd = String(today.getDate()).padStart(2, '0');
|
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
|
var yyyy = today.getFullYear();
|
|
} else if (issed_for > 0) {
|
|
var dd = String(newDate.getDate()).padStart(2, '0');
|
|
var mm = String(newDate.getMonth() + 1).padStart(2, '0');
|
|
var yyyy = newDate.getFullYear();
|
|
}
|
|
|
|
today = yyyy + '-' + mm + '-' + dd;
|
|
return today;
|
|
}
|
|
|
|
function addDays(theDate, days) {
|
|
return new Date(theDate.getTime() + days * 24 * 60 * 60 * 1000);
|
|
}
|
|
</script>
|
|
<script>
|
|
function addMoreBook() {
|
|
$("#issuedBookForm").validate({
|
|
errorClass: 'error',
|
|
rules: {
|
|
eu_id: {
|
|
required: true
|
|
},
|
|
book_id: {
|
|
required: true
|
|
},
|
|
book_health: {
|
|
required: {
|
|
depends: function(element) {
|
|
return $("#book_health").val() == '';
|
|
}
|
|
}
|
|
}
|
|
},
|
|
messages: {
|
|
eu_id: {
|
|
required: "Student Id is required"
|
|
},
|
|
book_id: {
|
|
required: "ISBN is required"
|
|
},
|
|
book_health: {
|
|
required: "Book Health is required"
|
|
}
|
|
},
|
|
errorPlacement: function(error, element) {
|
|
if (element.attr("name") == "eu_id") {
|
|
error.appendTo($("#error-eu_unique_id"));
|
|
} else if (element.attr("name") == "book_id") {
|
|
error.appendTo($("#error-book_id"));
|
|
} else if (element.attr("name") == "book_health") {
|
|
error.appendTo($("#error-book_health"));
|
|
} else {
|
|
error.appendTo(element);
|
|
}
|
|
},
|
|
submitHandler: function(form) {
|
|
var dcnts = $('#divCount').val();
|
|
var bookIsbn = $('#book_id' + dcnts).val();
|
|
$.ajax({
|
|
type: 'post',
|
|
url: '<?= base_url(); ?>LmsAdmin/checkExistingBook',
|
|
data: {
|
|
'isbn': bookIsbn
|
|
},
|
|
success: function(result) {
|
|
if (result == 0) {
|
|
$('#error-existingBook' + dcnts).text('The book is out of stock');
|
|
}
|
|
if (result == 1) {
|
|
$('#error-existingBook' + dcnts).html('');
|
|
|
|
var rem_issue_book = $('#rem_issued_book_cnt').val();
|
|
var ttl_issue_book = $('#ttl_issue_book_cnt').val();
|
|
var ttlrows = $('#contentBody tr').length;
|
|
$('#ttlrows').val(ttlrows);
|
|
var rowCount = $('#tbl tr').length;
|
|
if (rowCount <= ttl_issue_book) {
|
|
var eu_id = $('#eu_id').val();
|
|
var iDate = $("input[name='issued_date[]']").map(function() {
|
|
return $(this).val();
|
|
}).get();
|
|
var rDate = $("input[name='return_date[]']").map(function() {
|
|
return $(this).val();
|
|
}).get();
|
|
var bhealth = [];
|
|
$('select[name="book_health[]"] option:selected').each(function() {
|
|
bhealth.push($(this).val());
|
|
});
|
|
$('#eu_unique_id').val(eu_id);
|
|
$('#issueddate').val(iDate);
|
|
$('#returndate').val(rDate);
|
|
$('#bookhealth').val(bhealth);
|
|
|
|
var dcnt = $('#divCount').val();
|
|
var incval = Number(dcnt) + 1;
|
|
$('#divCount').val(incval);
|
|
|
|
var nobpu = Number($('#no_of_book_per_user').val());
|
|
if (dcnt == 1) {
|
|
var extval = dcnt;
|
|
} else {
|
|
var extvals = $('#divCount').val();
|
|
extval = extvals - 1;
|
|
}
|
|
var isbn = $('#book_id' + extval).val();
|
|
var title = $('#title' + extval).val();
|
|
|
|
htmll = '<tr id="rowcnt' + extval + '"><td><span class="text-center">' + extval + '</span></td><td>' + isbn + '</td><input type="hidden" name="isbn[]" id="isbn" value="' + isbn + '"><td>' + title + '</td><input type="hidden" name="title[]" id="title" value="' + title + '"><td><div class="sub_tabbtnsec"><div class="sub_delbtn"><i class="fa fa-trash" aria-hidden="true"></i></div></div></td></tr>';
|
|
$('#contentBody').append(htmll);
|
|
|
|
$('#button' + extval).hide();
|
|
|
|
var thestring = '#hidebookDiv' + incval;
|
|
var thenum = thestring.replace(/^\D+/g, '');
|
|
if (thenum >= dcnt) {
|
|
$('#hidebookDiv' + dcnt).hide();
|
|
}
|
|
|
|
if (extval <= nobpu) {
|
|
|
|
var html = '<div class="subject_lformarea book-form-area morediv" id="hidebookDiv' + incval + '"><div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="book_id" id="book_id' + incval + '" placeholder="ISBN" onkeyup="getBookData(this.value, ' + incval + ')" autocomplete="off">';
|
|
html += '<p class="form_err" id="error-book_id"></p>';
|
|
html += '<i class="fas fa-barcode"></i>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="title" id="title' + incval + '" placeholder="Book Title" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="category" id="category' + incval + '" placeholder="Category" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="author" id="author' + incval + '" placeholder="Author" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="publisher" id="publisher' + incval + '" placeholder="Publisher" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="number" class="form-control txtData" name="year" id="year' + incval + '" placeholder="Year" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="ttl_pages" id="ttl_pages' + incval + '" placeholder="Total Pages" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="text" class="form-control txtData" name="description" id="description' + incval + '" placeholder="Description" readonly>';
|
|
html += '<p class="form_err"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group assign_subject">';
|
|
html += '<select class="form-control txtData" name="book_health[]" id="book_health' + incval + '">';
|
|
html += '<option value="">Select Book Health</option>';
|
|
html += '<option value="good">Good</option>';
|
|
html += '<option value="average">Average</option>';
|
|
html += '<option value="damaged">Damaged</option>';
|
|
html += '</select><p class="form_err" id="error-book_health"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="date" class="form-control txtData" name="issued_date[]" id="issued_date' + incval + '" placeholder="Date of Issue" readonly>';
|
|
html += '<p class="form_err" id="error-issued_date"></p>';
|
|
html += '</div>';
|
|
html += '<div class="form-group">';
|
|
html += '<input type="date" class="form-control txtData" name="return_date[]" id="return_date' + incval + '" placeholder="Date of Return" readonly>';
|
|
html += '<p class="form_err" id="error-return_date"></p>';
|
|
html += '</div></div><p class="form_err" id="error-existingBook' + incval + '" ></p>';
|
|
html += '<div class="addBookWrap">';
|
|
html += '<button type="submit" id="button' + incval + '" class="subject_addbtn add-btn-border" onclick="addMoreBook()">Add another book</button>';
|
|
html += '</div>';
|
|
$('#moreBookDetailDiv').append(html);
|
|
}
|
|
} else {
|
|
if (rem_issue_book == 0) {
|
|
$('#error-existingBook' + dcnts).text('You can not issue book for this user.');
|
|
} else {
|
|
$('#error-existingBook' + dcnts).text('You can issue only ' + rem_issue_book + ' book for this user.');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<script>
|
|
$("#tbl").on('click', '.sub_delbtn', function() {
|
|
$(this).closest('tr').remove();
|
|
});
|
|
|
|
function saveData() {
|
|
var formdata = new FormData(form);
|
|
var eu_id = $()
|
|
var id = $('#id').val();
|
|
$.ajax({
|
|
type: 'post',
|
|
url: '<?= base_url(); ?>LmsAdmin/add_edit_issue_book/' + id,
|
|
data: formdata,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function(result) {
|
|
alert(result);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|