586 lines
26 KiB
PHP
Executable File
586 lines
26 KiB
PHP
Executable File
<!-- Include jQuery first -->
|
||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||
|
||
<!-- Include jQuery Validation plugin -->
|
||
<script src="https://cdn.jsdelivr.net/jquery.validation/1.19.3/jquery.validate.min.js"></script>
|
||
|
||
<style>
|
||
.form-group {
|
||
padding-bottom: 0%;
|
||
}
|
||
|
||
.expandable-td {
|
||
cursor: pointer;
|
||
}
|
||
|
||
|
||
.Date-filter-form {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
/* Adjust the gap as needed */
|
||
}
|
||
|
||
.Date-filter-form input,
|
||
.Date-filter-form button {
|
||
padding: 5px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.Date-filter-form button {
|
||
background-color: #007bff;
|
||
color: white;
|
||
border: none;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.Date-filter-form button:hover {
|
||
background-color: #0056b3;
|
||
}
|
||
|
||
.icon-button {
|
||
background: none;
|
||
border: none;
|
||
cursor: pointer;
|
||
color: #007bff;
|
||
font-size: 18px;
|
||
}
|
||
|
||
.icon-button:hover {
|
||
color: #0056b3;
|
||
}
|
||
|
||
.delete_button {
|
||
border: none;
|
||
background-color: white;
|
||
color: red;
|
||
}
|
||
</style>
|
||
<div class="content-page">
|
||
<div class="content">
|
||
<!-- Start Content-->
|
||
<div class="container-fluid">
|
||
<!-- start page title -->
|
||
<div>
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="page-title-box page-title-box-alt">
|
||
<div class="page-title-right">
|
||
<ol class="breadcrumb m-0">
|
||
<li class="breadcrumb-item"><a href="javascript: void(0);">Inward</a></li>
|
||
<li class="breadcrumb-item active">
|
||
<h4 class="page-title">Non IGR / Expense</h4>
|
||
</li>
|
||
</ol>
|
||
</div>
|
||
<a id="addExpense" class="btn btn-success" data-toggle="modal" href="#expenseModal">Add New Expense</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<form class="Date-filter-form" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;" method="post" action="<?= base_url('ListIGR'); ?>">
|
||
|
||
<label for="fromDate">From:</label>
|
||
<input class="form-control date_range form-date-search"
|
||
value="<?= $fromDate?>"
|
||
id="fromDate" name="fromDate" placeholder="Select From Date" autocomplete="off" required>
|
||
|
||
<label for="toDate">To:</label>
|
||
<input class="form-control date_range to-date-search"
|
||
value="<?= $toDate ?>"
|
||
id="toDate" name="toDate" placeholder="Select To Date" autocomplete="off" required>
|
||
|
||
<button type="submit" class="range_search_button" >
|
||
<i class="fe-search" aria-hidden="true" class="icon-button" title="Search"></i>
|
||
</button>
|
||
|
||
<i class="fe-rotate-cw range_reset_button"
|
||
style="cursor:pointer;"
|
||
aria-hidden="true" class="icon-button" id="resetButton" title="Reset"></i>
|
||
|
||
|
||
<div class="error" id="error"></div>
|
||
</form>
|
||
<div class="card-body" style="overflow-x:scroll;">
|
||
<table class="table table-bordered table-hover" id="expense_list_table" style="background-color:#fff;">
|
||
<thead>
|
||
<tr>
|
||
<th align="left" style="width: 10%;">Created Date</th>
|
||
<th align="left" style="width: 20%;">Supplier Name</th>
|
||
<th align="left" style="width: 25%;">Item Description</th>
|
||
<th align="left" style="width: 7%;">Cost</th>
|
||
<th align="left" style="width: 5%;">CGST</th>
|
||
<th align="left" style="width: 5%;">SGST</th>
|
||
<th align="left" style="width: 5%;">IGST</th>
|
||
<th align="left" style="width: 7%;">Total</th>
|
||
<th align="left" style="width: 8%;">Action</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php
|
||
if (!empty($expense_list)) {
|
||
foreach ($expense_list as $record) {
|
||
$fileExists = 0;
|
||
$fileUrl = '';
|
||
if ($record['transporter_file']) {
|
||
$fileExists = 1;
|
||
$fileUrl = base_url('uploads/') . $record['transporter_file'];
|
||
}
|
||
// Create download link and delete button
|
||
?>
|
||
<tr>
|
||
<?php if (date('d-m-Y', strtotime($record['created_on'])) == "30-11--0001") {
|
||
$cdate = '00-00-0000';
|
||
} else {
|
||
$cdate = date('d-m-Y', strtotime($record['created_on']));
|
||
}
|
||
?>
|
||
<td><?php echo $cdate; ?></td>
|
||
<!-- <td><?php echo $record['id']; ?></td> -->
|
||
<td class="expandable-td">
|
||
<div class="text-container" style="max-height: 20px; overflow: hidden;">
|
||
<?php echo $record['SupplierName']; ?>
|
||
</div>
|
||
</td>
|
||
|
||
<!-- Item Description with Clickable TD for Expand/Collapse -->
|
||
<td class="expandable-td">
|
||
<div class="text-container" style="max-height: 20px; overflow: hidden;">
|
||
<?php echo $record['item_description']; ?>
|
||
</div>
|
||
</td>
|
||
<td><?php echo $record['cost']; ?></td>
|
||
<td><?php echo $record['cgst']; ?></td>
|
||
<td><?php echo $record['sgst']; ?></td>
|
||
<td><?php echo $record['igst']; ?></td>
|
||
<td><?php echo $record['total']; ?></td>
|
||
<td>
|
||
<?php if ($fileExists == 1) { ?>
|
||
<button title="Download FIle" class="download_button" onclick="downloadFile('<?php echo $record['id']; ?>', '<?php echo $record['transporter_file']; ?>')" style="border: none;background-color: white;color: #02a8b5;">
|
||
<i class="fas fa-file-download"></i>
|
||
</button>
|
||
<button title="Delete File" id="deleteFile" class="delete_button" data-value="<?php echo $record['id'] ?>" data-id="<?php echo $record['id'] ?>" data-file="<?php echo $record['transporter_file'] ?>"><i class="fas fa-trash"></i></button>
|
||
|
||
<?php } ?>
|
||
<button title="Edit" class="edit-button" data-toggle="modal" data-target="#expenseModal" data-id="<?php echo $record['id']; ?>" style="border: none;background-color: white;color: #02a8b5;">
|
||
<i class="fas fa-pencil-alt"></i>
|
||
</button>
|
||
</td>
|
||
</tr>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</tbody>
|
||
</table>
|
||
</div> <!-- end card body-->
|
||
</div> <!-- end card -->
|
||
</div><!-- end col-->
|
||
</div>
|
||
</div>
|
||
</div> <!-- container -->
|
||
</div> <!-- content -->
|
||
</div>
|
||
|
||
|
||
<div id="expenseModal" class="modal fade" tabindex="-1" role="dialog"
|
||
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
|
||
<div class="modal-dialog modal-lg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title">Add Expense</h4>
|
||
<button type="button" class="close" data-dismiss="modal"
|
||
aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body p-4">
|
||
<form id="expenseForm" class="form-horizontal" role="form">
|
||
<input type="hidden" name="id" id="id">
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="supplierid" class="col-form-label">Supplier </label>
|
||
</div>
|
||
<div class="col">
|
||
<select name="supplierid" id="supplierid" class="form-control" required>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="supplierid" class="col-form-label">Item Description </label>
|
||
</div>
|
||
<div class="col">
|
||
<textarea name="item_description" id="item_description" class="form-control"></textarea>
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="cost" class="col-form-label">Cost</label>
|
||
</div>
|
||
<div class="col">
|
||
<input type="number" name="cost" id="cost" class="form-control" required onchange="totalCalculate()">
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="cost" class="col-form-label">CGST</label>
|
||
</div>
|
||
<div class="col">
|
||
<input type="number" name="cgst" id="cgst" class="form-control" onchange="totalCalculate()">
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="cost" class="col-form-label">SGST</label>
|
||
</div>
|
||
<div class="col">
|
||
<input type="number" name="sgst" id="sgst" class="form-control" onchange="totalCalculate()">
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="igst" class="col-form-label">IGST</label>
|
||
</div>
|
||
<div class="col">
|
||
<input type="number" name="igst" id="igst" class="form-control" onchange="totalCalculate()">
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="cost" class="col-form-label">Total</label>
|
||
</div>
|
||
<div class="col">
|
||
<input type="number" name="total" id="total" class="form-control">
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="transporterfile" class="col-form-label">Transporter File</label>
|
||
|
||
</div>
|
||
<div class="col">
|
||
<input type="file" name="transporterfile" id="transporterfile" class="form-control">
|
||
<input type="hidden" name="transporterfile_name" id="transporterfile_name">
|
||
<small id="fileHelp" class="form-text text-muted">
|
||
Current file: <span id="currentFileName"></span>
|
||
</small>
|
||
</div>
|
||
</div>
|
||
<div class="form-group row">
|
||
<div class="col-md-3">
|
||
<label for="note" class="col-form-label">Notes</label>
|
||
</div>
|
||
<div class="col">
|
||
<textarea name="remarks" id="remarks" class="form-control"></textarea>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Cancel</button>
|
||
<button type="button" class="btn btn-info waves-effect waves-light tempClick" id="tempClick">Submit</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal -->
|
||
|
||
<script>
|
||
function downloadFile(fileId, fileName) {
|
||
window.location.href = 'downloadFile/' + fileName;
|
||
}
|
||
$(document).ready(function() {
|
||
// Function to toggle payment method based on status
|
||
function togglePaymentMethod() {
|
||
var status = $('#status_id').val();
|
||
console.log(status);
|
||
|
||
if (status === 'Paid') {
|
||
$('#payment_method').prop('disabled', false); // Enable payment method
|
||
} else {
|
||
$('#payment_method').prop('disabled', true).val(''); // Disable payment method and clear value
|
||
}
|
||
}
|
||
|
||
// Trigger the toggle function on page load
|
||
togglePaymentMethod();
|
||
|
||
// Trigger the toggle function whenever the status changes
|
||
$('#status_id').on('change', function() {
|
||
togglePaymentMethod();
|
||
});
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
$('#supplierid').select2();
|
||
var formActionUrl = '';
|
||
|
||
// Event handler for file input change
|
||
$('#transporterfile').on('change', function() {
|
||
var fileName = $(this).val().split('\\').pop(); // Get the file name
|
||
$('#file-name-display').text(fileName); // Display the file name
|
||
});
|
||
|
||
function togglePaymentMethodEdit() {
|
||
var status = $('#status_id').val();
|
||
console.log(status);
|
||
|
||
if (status === 'Paid') {
|
||
$('#payment_method').prop('disabled', false); // Enable payment method
|
||
} else {
|
||
$('#payment_method').prop('disabled', true).val(''); // Disable payment method and clear value
|
||
}
|
||
}
|
||
$(document).on('click', '.edit-button', function() {
|
||
|
||
$('.modal-title').html('Edit Expense');
|
||
var expenseId = $(this).data('id');
|
||
var supplier_list = [<?php echo $supplier_list; ?>];
|
||
$('#supplierid').empty(); // Clear the supplier dropdown
|
||
$('#supplierid').append('<option value="0">Select Supplier</option>');
|
||
supplier_list[0].forEach(function(supplier) {
|
||
$('#supplierid').append('<option value="' + supplier.SupplierID + '">' + supplier.SupplierName + '</option>');
|
||
});
|
||
formActionUrl = '<?php echo base_url() . 'editExpense' ?>'; // Set action URL for adding
|
||
|
||
$('#loader').show();
|
||
$.ajax({
|
||
url: '<?php echo base_url() . 'getExpenseDetails'; ?>',
|
||
type: 'POST',
|
||
data: {
|
||
id: expenseId
|
||
},
|
||
success: function(response) {
|
||
var expense = JSON.parse(response);
|
||
$('#id').val(expense.id);
|
||
$('#transporterfile').val(''); // Clear the file input
|
||
$('#currentFileName').text(''); // Clear the file name display
|
||
$('#supplierid').val(expense.supplier_id).trigger('change');
|
||
$('#remarks').val(expense.remarks);
|
||
$('#item_description').val(expense.item_description);
|
||
$('#cost').val(expense.cost);
|
||
$('#cgst').val(expense.cgst);
|
||
$('#sgst').val(expense.sgst);
|
||
$('#igst').val(expense.igst);
|
||
$('#total').val(expense.total);
|
||
$('#status_id').val(expense.status);
|
||
|
||
// Clear any existing file link and delete button
|
||
$('#transporterfile').next('.download_button').remove();
|
||
$('#transporterfile').next('.delete_button').remove();
|
||
|
||
if (expense.transporter_file) {
|
||
$('#transporterfile_name').val(expense.transporter_file); // Set the hidden input value
|
||
$('#currentFileName').text(expense.transporter_file); // Display the existing file name
|
||
|
||
// Construct the full URL to the file
|
||
var fileUrl = '<?php echo base_url('uploads/'); ?>' + expense.transporter_file;
|
||
|
||
// Create download link and delete button
|
||
var fileLink = '<a class="download_button" href="' + fileUrl + '" target="_blank" download="' + expense.transporter_file + '"><i class=" fas fa-file-download"></i></a>';
|
||
var deleteButton = '<button id="deleteFile" class="delete_button" data-value="' + expense.id + '" data-id="' + expense.id + '" data-file="' + expense.transporter_file + '"><i class="fas fa-trash"></i></button>';
|
||
|
||
// Add the file link and delete button
|
||
$('#transporterfile').after(fileLink + ' ' + deleteButton);
|
||
} else {
|
||
$('#transporterfile_name').val(''); // Clear hidden input if no file
|
||
}
|
||
togglePaymentMethodEdit();
|
||
$('#loader').hide();
|
||
}
|
||
|
||
});
|
||
});
|
||
|
||
|
||
$(document).on('click', '#addExpense', function() {
|
||
$('.download_button').remove();
|
||
$('.delete_button').remove();
|
||
$('.modal-title').html('Add Expense');
|
||
$('#transporterfile').val(''); // Clear the file input
|
||
$('#currentFileName').text(''); // Clear the file name display
|
||
$('#supplierid').val('').trigger('change');
|
||
$('#remarks').val('');
|
||
$('#cost').val('');
|
||
$('#gst').val('');
|
||
$('#total').val('');
|
||
$('#status_id').val('');
|
||
$('#payment_method').val('');
|
||
var supplier_list = [<?php echo $supplier_list; ?>];
|
||
$('#supplierid').empty(); // Clear the supplier dropdown
|
||
$('#supplierid').append('<option value="0">Select Supplier</option>');
|
||
|
||
supplier_list[0].forEach(function(supplier) {
|
||
$('#supplierid').append('<option value="' + supplier.SupplierID + '">' + supplier.SupplierName + '</option>');
|
||
});
|
||
formActionUrl = '<?php echo base_url() . 'addExpense' ?>'; // Set action URL for adding
|
||
togglePaymentMethodEdit();
|
||
});
|
||
|
||
// Handle form submission
|
||
$('#tempClick').on('click', function(e) {
|
||
e.preventDefault();
|
||
|
||
if ($('#supplierid').val() != 0) {
|
||
// Native HTML5 form validation
|
||
if ($('#expenseForm')[0].checkValidity()) {
|
||
|
||
var formData = new FormData($('#expenseForm')[0]); // Use FormData to handle file upload
|
||
console.log(formActionUrl);
|
||
|
||
$('#loader').show();
|
||
$.ajax({
|
||
url: formActionUrl,
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(response) {
|
||
console.log(response);
|
||
|
||
if (response) {
|
||
$('#loader').hide();
|
||
$('#expenseForm')[0].reset();
|
||
$('#file-name-display').text(''); // Clear the file name display
|
||
window.location.reload();
|
||
} else {
|
||
$('#loader').hide();
|
||
|
||
console.log(response);
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
$('#loader').hide();
|
||
|
||
alert('An error occurred: ' + error);
|
||
}
|
||
});
|
||
} else {
|
||
// If form is invalid, show native validation messages
|
||
$('#expenseForm')[0].reportValidity();
|
||
}
|
||
} else {
|
||
alert("Select Supplier");
|
||
}
|
||
});
|
||
|
||
|
||
// DataTable initialization and date range filter logic (unchanged)
|
||
var table = $('#expense_list_table').DataTable({
|
||
dom: 'Blfrtip',
|
||
buttons: [
|
||
'excel', 'pdf'
|
||
],
|
||
pageLength: 10,
|
||
lengthMenu: [
|
||
[10, 20, 30, 50, -1],
|
||
[10, 20, 30, 50, "All"]
|
||
],
|
||
responsive: false,
|
||
order: false,
|
||
language: {
|
||
paginate: {
|
||
next: '<i class="fas fa-angle-right"></i>',
|
||
previous: '<i class="fas fa-angle-left"></i>'
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
|
||
$("#resetButton").click(function() {
|
||
$("#fromDate").val('');
|
||
$("#toDate").val('');
|
||
window.location="ListIGR"
|
||
});
|
||
});
|
||
|
||
$(document).on('click', '#deleteFile', function() {
|
||
var fileName = $(this).data('file');
|
||
var expenseId = $(this).data('value');
|
||
|
||
$('#loader').show();
|
||
$.ajax({
|
||
url: '<?php echo base_url('deleteFile'); ?>',
|
||
type: 'POST',
|
||
data: {
|
||
file_name: fileName,
|
||
expense_id: expenseId
|
||
},
|
||
success: function(response) {
|
||
console.log(response);
|
||
|
||
var result = JSON.parse(response);
|
||
if (result.success) {
|
||
$('#loader').hide();
|
||
|
||
alert('File deleted successfully.');
|
||
$('#currentFileName').text('');
|
||
$('#transporterfile_name').val('');
|
||
$('#deleteFile').remove(); // Remove the delete button
|
||
$('#transporterfile').next('a').remove(); // Remove the download link
|
||
} else {
|
||
$('#loader').hide();
|
||
|
||
alert('Failed to delete the file: ' + result.message);
|
||
}
|
||
},
|
||
error: function() {
|
||
$('#loader').hide();
|
||
|
||
alert('Error deleting the file.');
|
||
}
|
||
});
|
||
});
|
||
|
||
document.getElementById('transporterfile').addEventListener('change', function() {
|
||
var fileName = this.files[0].name;
|
||
document.getElementById('currentFileName').textContent = fileName;
|
||
});
|
||
|
||
function totalCalculate() {
|
||
var cost = parseFloat($('#cost').val()) || 0;
|
||
var cgst = parseFloat($('#cgst').val()) || 0;
|
||
var sgst = parseFloat($('#sgst').val()) || 0;
|
||
var igst = parseFloat($('#igst').val()) || 0;
|
||
|
||
var total = cgst + sgst + igst + cost;
|
||
// var totalTaxAmount = (cost * totalTaxPercentage) / 100;
|
||
// var total = cost + totalTaxAmount;
|
||
$('#total').val(total.toFixed(2));
|
||
}
|
||
|
||
$(document).ready(function() {
|
||
$('.expandable-td').on('click', function() {
|
||
var $textContainer = $(this).find('.text-container');
|
||
if ($textContainer.css('max-height') === '20px') {
|
||
// Expand the content
|
||
$textContainer.css('max-height', 'none');
|
||
} else {
|
||
// Collapse the content
|
||
$textContainer.css('max-height', '20px');
|
||
}
|
||
});
|
||
});
|
||
</script>
|
||
|
||
<script>
|
||
$(document).ready(function() {
|
||
$('#fromDate , #toDate').change(function() {
|
||
|
||
let fromDate = $('#fromDate').val();
|
||
let toDate = $('#toDate').val();
|
||
|
||
let fromDateObj = new Date(fromDate.split('-').reverse().join('-'));
|
||
let toDateObj = new Date(toDate.split('-').reverse().join('-'));
|
||
if (fromDateObj > toDateObj) {
|
||
alert('Incorrect Date Applied For Filter..!!');
|
||
$('#toDate').attr('min', fromDate);
|
||
$('#toDate').val('');
|
||
|
||
}
|
||
});
|
||
});
|
||
|
||
</script>
|