425 lines
17 KiB
PHP
425 lines
17 KiB
PHP
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<style>
|
|
.invoice-link {
|
|
text-decoration: underline;
|
|
color: #007bff; /* Adjust color as needed */
|
|
}
|
|
.custom-button {
|
|
display: inline-block;
|
|
padding: 6px 8px;
|
|
margin-bottom: 0;
|
|
font-size: 14px;
|
|
font-weight: normal;
|
|
line-height: 1.42857143;
|
|
text-align: center;
|
|
white-space: nowrap;
|
|
vertical-align: middle;
|
|
cursor: pointer;
|
|
background-color: #007bff;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
color: #fff;
|
|
text-decoration: none;
|
|
width: 72px;
|
|
margin-left: -12px;
|
|
margin-top: -3px;
|
|
height: 32px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.custom-button:hover {
|
|
color: #fff;
|
|
text-decoration: none;
|
|
/* color: #007bff !important; */
|
|
/* background-color: white; */
|
|
/* border: 1px solid; */
|
|
}
|
|
|
|
</style>
|
|
<div class="content-wrapper">
|
|
<!-- Content Header (Page header) -->
|
|
<section class="content-header">
|
|
<h1>
|
|
<center>Sales Invoice</center>
|
|
</h1>
|
|
</section>
|
|
<section class="content">
|
|
<div class="row">
|
|
<div class="col-xs-12 text-right">
|
|
<div class="form-group">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<div class="box">
|
|
<div class="box-header">
|
|
|
|
</div><!-- /.box-header -->
|
|
<div class="box-body">
|
|
<table id="datatable_sales_invoice_list" class="table table-striped dt-responsive nowrap w-100" style="background-color:#fff;font-size:12px;text-align: right;" >
|
|
<thead style="background-color: #ddd;">
|
|
<tr >
|
|
<th width="10%">Invoice Date</th>
|
|
<th width="10%">Invoice No</th>
|
|
<th width="10%">Client Name</th>
|
|
<th width="10%">Product</th>
|
|
<th width="10%">Rate</th>
|
|
<th width="10%">Quantity</th>
|
|
<th width="10%">Sub Total</th>
|
|
<th width="10%">GST</th>
|
|
<th width="10%">Total</th>
|
|
<th width="10%">Status</th>
|
|
<th width="10%" >E-Invoice Number</th>
|
|
<th width="5%">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<input type="text" id="invoice_id_set" name="invoice_id_set" hidden>
|
|
<?php if(!empty($sales_invoice)){ foreach($sales_invoice as $invoice){
|
|
|
|
$subtotal = $invoice->item_price * $invoice->item_quantity;
|
|
// Calculate CGST and SGST
|
|
$cgst_amount = ($subtotal * $invoice->cgst) / 100;
|
|
$sgst_amount = ($subtotal * $invoice->sgst) / 100;
|
|
$total = $subtotal + $cgst_amount + $sgst_amount;?>
|
|
<!-- Main invoice row -->
|
|
<tr class="parent-row">
|
|
<td style="text-align: center;"><?php echo date('d-m-Y', strtotime($invoice->invoice_date_created)); ?></td>
|
|
<td style="text-align: left;">
|
|
<?php if(!empty($invoice->invoice_url)){ ?>
|
|
<a href="<?php echo $invoice->invoice_url; ?>" target="_blank" class="invoice-link">
|
|
<?php } ?>
|
|
<?php echo $invoice->invoice_number; ?>
|
|
<?php if(!empty($invoice->invoice_url)){ ?>
|
|
</a>
|
|
<?php } ?>
|
|
</td>
|
|
<td style="text-align: left;"><?php echo $invoice->client_name ?></td>
|
|
<td style="text-align: left;"><?php echo $invoice->item_name ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->item_price ?></td>
|
|
<td style="text-align: center;"><?php echo number_format($invoice->item_quantity, 2 ,'.', ',' ) ?></td>
|
|
<td style="text-align: center;"><?php echo number_format($subtotal, 2, '.', ',') ?></td>
|
|
<td style="text-align: center;"><?php echo number_format($cgst_amount+$sgst_amount, 2, '.', ',') ?></td>
|
|
<td style="text-align: center;"><?php echo number_format($total, 2, '.', ',') ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->status ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->e_invoice_number; ?></td>
|
|
<td style="text-align: center;">
|
|
<a class="edit-button" style="cursor: pointer; display: inline-block;" title="Files Upload" onclick="openInvoiceModal('<?php echo $invoice->invoice_number; ?>', '<?php echo $invoice->client_name; ?>', '<?php echo $invoice->invoice_date_created; ?>', '<?php echo $invoice->invoice_id; ?>')">
|
|
<i class="fas fa-file-upload text-muted" style="font-size: 18px; vertical-align: middle;"></i>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php } } ?>
|
|
</tbody>
|
|
</table>
|
|
</div><!-- /.box-body -->
|
|
<!-- <div class="box-footer clearfix">
|
|
</div> -->
|
|
</div><!-- /.box -->
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<!-- Modal Structure -->
|
|
<div class="modal fade" id="invoiceModal" tabindex="-1" role="dialog" aria-labelledby="invoiceModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
<h3><span id="invoice_number_display_model"></span> - <span id="date_display_model"></span><br></h3>
|
|
<span id="client_name_display_model"></span>
|
|
|
|
|
|
<div class="col-md-12">
|
|
<div class="col-md-10"></div>
|
|
<div class="col-md-2">
|
|
<!-- <button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()" id="day" >
|
|
Add New File
|
|
</button> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-body" style="margin-top: 23px;">
|
|
<div id="filesContainer">
|
|
|
|
<!-- Rows will be dynamically appended here -->
|
|
</div>
|
|
|
|
<?php if(isset($invoice_data)){ foreach ($invoice_data as $key => $value) { ?>
|
|
|
|
<div class="col-md-12 pad ">
|
|
<div class="col-md-6">
|
|
<span>File Name</span>
|
|
<input type="text" maxlength="255" class="form-control file_name"
|
|
value="<?php echo $value['file_name']; ?>" readonly>
|
|
<div class="error-message"></div>
|
|
</div>
|
|
<div class="col-md-1" style="margin-top: 25px;">
|
|
|
|
<a class="custom-button" href="<?php echo base_url() . 'public/uploads/images/emp_files/' . $value['emp_file']; ?>"
|
|
download>
|
|
Download
|
|
</a>
|
|
</div>
|
|
<div class="col-md-5" style="margin-top: 23px;">
|
|
<button type="button" class="btn btn-danger btn-sm"
|
|
id="<?= $value['id']; ?>"
|
|
onclick="removeContact(this)" style="margin-left: 22px;">Delete </button>
|
|
</div>
|
|
</div>
|
|
|
|
<?php } } ?>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
<button type="button" onclick="saveAttachment()" class="btn btn-primary">Save changes</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="<?php echo base_url(); ?>public/assets/js/common.js" charset="utf-8"></script>
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
|
var table = $('#datatable_sales_invoice_list').DataTable({
|
|
"paging": true,
|
|
"lengthChange": true,
|
|
"searching": true,
|
|
"ordering": true,
|
|
"columnDefs": [{
|
|
"targets": 0,
|
|
"type": "date-eu"
|
|
}],
|
|
"aaSorting": [
|
|
[0, "desc"]
|
|
],
|
|
"info": true,
|
|
"autoWidth": true,
|
|
"pageLength": 10,
|
|
"lengthMenu": [10, 25, 50, 100],
|
|
"rowCallback": function(row, data, index) {
|
|
// Ignore child rows
|
|
if ($(row).hasClass('child-row')) {
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
function saveAttachment() {
|
|
|
|
var file_name_classes = $('.file_name');
|
|
var hasEmptyInput = false;
|
|
|
|
file_name_classes.each(function() {
|
|
if ($(this).val().trim() === '') {
|
|
hasEmptyInput = true;
|
|
$(this).focus(); // Focus on the empty input field
|
|
$(this).addClass('error'); // Add an error class to the empty input
|
|
$('.error-message').text('Please fill out this field.').show(); // Show the error message
|
|
return false; // Break the loop
|
|
}
|
|
});
|
|
if (!hasEmptyInput) {
|
|
$('.error-message').hide();
|
|
console.log('All inputs are filled.');
|
|
var formData = new FormData();
|
|
var invoiceId = $('#invoice_id_set').val();
|
|
formData.append('invoice_id', invoiceId);
|
|
|
|
// Append files
|
|
$('input[name="emp_file[]"]').each(function(index, input) {
|
|
var files = $(input)[0].files;
|
|
if (files.length > 0) {
|
|
formData.append('emp_file[]', files[0]);
|
|
}
|
|
});
|
|
|
|
// Append other fields
|
|
$('input[name="file_name[]"]').each(function(index, input) {
|
|
formData.append('file_name[]', $(input).val());
|
|
});
|
|
|
|
// AJAX request using FormData
|
|
$.ajax({
|
|
url: '<?php echo base_url() ?>saveAttachment',
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false, // Prevent jQuery from converting the data
|
|
contentType: false, // Prevent jQuery from overriding the content type
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response.success) {
|
|
$('#invoiceModal').modal('hide');
|
|
// Handle success
|
|
} else {
|
|
alert(response.message);
|
|
}
|
|
},
|
|
error: function() {
|
|
alert('An error occurred while saving the attachment.');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function openInvoiceModal(invoiceNumber, clientName, invoiceDate, invoiceId) {
|
|
|
|
function formatDate(date) {
|
|
let d = new Date(date); // Ensure the date is a Date object
|
|
let day = String(d.getDate()).padStart(2, '0');
|
|
let month = String(d.getMonth() + 1).padStart(2, '0'); // Months are 0-based
|
|
let year = d.getFullYear();
|
|
return `${day}/${month}/${year}`;
|
|
}
|
|
let formattedDate = formatDate(invoiceDate);
|
|
|
|
$('#invoice_number_display_model').html(invoiceNumber);
|
|
$('#client_name_display_model').html(clientName);
|
|
$('#date_display_model').html(formattedDate);
|
|
|
|
// document.getElementById('modalInvoiceNumber').innerText = invoiceNumber;
|
|
// $('#day').show();
|
|
// $('#invoiceModal').modal('show');
|
|
// url:"<?php echo base_url() ?>servicepurchaseorder/getPODetails",
|
|
$('#invoice_id_set').val(invoiceId);
|
|
// console.log(invoiceId);
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url() ?>getInvoiceAttachments',
|
|
type: 'GET',
|
|
data: { invoice_id: invoiceId },
|
|
success: function(response) {
|
|
console.log(response);
|
|
|
|
console.log(JSON.parse(response).invoiceAttachment);
|
|
var list = JSON.parse(response).invoiceAttachment;
|
|
var attachmentsHtml = '';
|
|
|
|
list.forEach(element => {
|
|
console.log(element);
|
|
var fileName = element.file_name;
|
|
var attachmentName = element.attachment_name;
|
|
attachmentsHtml += `
|
|
<div class="col-md-12 pad">
|
|
<div class="col-md-4">
|
|
<span>File Name</span>
|
|
<input type="text" maxlength="255" class="form-control file_name"
|
|
value="${attachmentName}" readonly>
|
|
<div class="error-message"></div>
|
|
|
|
</div>
|
|
<div class="col-md-1" style="margin-top: 25px;">
|
|
<a class="custom-button" href="<?php echo base_url() . 'public/uploads/images/invoice_files/' ?>${fileName}" download>
|
|
Download
|
|
</a>
|
|
</div>
|
|
<div class="col-md-5" style="margin-top: 23px;">
|
|
<button type="button" class="btn btn-danger btn-sm"
|
|
id="${element.invoice_attachment_id}"
|
|
onclick="removeContact(this)" style="margin-left: 22px;">Delete</button>
|
|
</div>
|
|
</div>`;
|
|
});
|
|
attachmentsHtml += `<div class="col-md-12 pad">
|
|
<div class="col-md-4">
|
|
<span for="file_name">File name</span>
|
|
<input type="text" id="file_name" name="file_name[]" maxlength="255" class="form-control file_name" value="">
|
|
<div class="error-message"></div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<span for="emp_file">File</span>
|
|
<input type="file" name="emp_file[]" class="form-control">
|
|
</div>
|
|
<div class="col-md-4" style="margin-top: 23px;">
|
|
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add</button>
|
|
</div>
|
|
</div>`;
|
|
$('#filesContainer').html(attachmentsHtml);
|
|
$('#invoiceModal').modal('show');
|
|
},
|
|
error: function() {
|
|
// Handle any errors during the AJAX request
|
|
$('#filesContainer').html('<p>There was an error loading the attachments.</p>');
|
|
$('#invoiceModal').modal('show');
|
|
}
|
|
});
|
|
console.log("day trigger works");
|
|
|
|
}
|
|
|
|
|
|
function appendFilesFileds(data) {
|
|
var newRowHtml = `
|
|
<div class="col-md-12 pad">
|
|
<div class="col-md-4">
|
|
<span for="file_name">File name</span>
|
|
<input type="text" id="file_name" name="file_name[]" maxlength="255" class="form-control file_name" value="${data != null && data != '' ? data.file_name : ''}">
|
|
<div class="error-message"></div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<span for="emp_file">File</span>
|
|
<input type="file" name="emp_file[]" class="form-control">
|
|
</div>
|
|
<div class="col-md-4" style="margin-top: 23px;">
|
|
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)">Remove</button>
|
|
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add</button>
|
|
</div>
|
|
</div>`;
|
|
|
|
// Append the new row to the container
|
|
$('#filesContainer').append(newRowHtml);
|
|
|
|
// Hide all "Add" buttons except the last one
|
|
$('.a1').hide();
|
|
$('#filesContainer .pad:last .a1').show();
|
|
}
|
|
|
|
function removeContact(button) {
|
|
|
|
$(button).closest('.pad').remove();
|
|
$('#filesContainer .a1').hide();
|
|
$('#filesContainer .pad:last .a1').show();
|
|
var len = $('#filesContainer .pad:last .a1')
|
|
var length = len.length;
|
|
if (length == 0) {
|
|
// $('#day').show()
|
|
} else {
|
|
$('#day').hide()
|
|
}
|
|
console.log("-------------------");
|
|
console.log(button);
|
|
console.log($(button).val());
|
|
console.log($(button).attr('id'));
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url() ?>deleteAttachment',
|
|
type: 'GET',
|
|
data: { invoice_attachment_id: $(button).attr('id') },
|
|
success: function(response) {
|
|
console.log(response);
|
|
},
|
|
error: function() {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|