ria/app/Views/sales_invoice.php
2024-08-17 14:52:10 +05:30

343 lines
15 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 */
}
</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: center;"><?php echo $invoice->client_name ?></td>
<td style="text-align: center;"><?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; ?>')">
<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">
<h3 class="modal-title" id="invoiceModalLabel">Invoice Files</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<label for=""> Client Name :</label><span id="client_name_display_model"></span><br>
<label for=""> Date :</label><span id="date_display_model"></span><br>
<label for=""> Invoice Number :</label><span id="invoice_number_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"
value="<?php echo $value['file_name']; ?>" readonly>
</div>
<div class="col-md-1" style="margin-top: 25px;">
<a href="<?php echo base_url() . 'public/uploads/images/emp_files/' . $value['emp_file']; ?>"
download>
<i class="fa fa-download" aria-hidden="true"
style="font-size: 25px;"></i>
</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)">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 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, Date) {
$('#invoice_number_display_model').html(invoiceNumber);
$('#client_name_display_model').html(clientName);
$('#date_display_model').html(Date);
// document.getElementById('modalInvoiceNumber').innerText = invoiceNumber;
$('#day').show();
// $('#invoiceModal').modal('show');
url:"<?php echo base_url() ?>servicepurchaseorder/getPODetails",
$('#invoice_id_set').val(invoiceNumber);
$.ajax({
url: '<?php echo base_url() ?>getInvoiceAttachment',
type: 'GET',
data: { invoice_number: invoiceNumber },
success: function(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"
value="${attachmentName}" readonly>
</div>
<div class="col-md-1" style="margin-top: 25px;">
<a href="<?php echo base_url() . 'public/uploads/images/invoice_files/' ?>${fileName}" download>
<i class="fa fa-download" aria-hidden="true"
style="font-size: 25px;"></i>
</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)">Delete</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');
}
});
}
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" value="${data != null && data != '' ? data.file_name : ''}">
</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>