306 lines
12 KiB
PHP
306 lines
12 KiB
PHP
|
|
|
|
<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-bordered table-hover" style="background-color:#fff;font-size:12px;text-align: right;" >
|
|
<thead style="background-color: #ddd;">
|
|
<tr >
|
|
<th width="10%">Invoice No</th>
|
|
<th width="10%">Invoice Date Created</th>
|
|
<th width="10%">Invoice Date Due</th>
|
|
<th width="10%">Client Name</th>
|
|
<th width="10%">User Name</th>
|
|
<th width="10%">Product Name</th>
|
|
<th width="10%" >Payment Method</th>
|
|
<th width="10%">Invoice Total</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){ ?>
|
|
<tr style="cursor: pointer;" onclick="openInvoiceModal('<?php echo $invoice->invoice_number; ?>')">
|
|
<td style="text-align: left;">
|
|
<?php echo $invoice->invoice_number; ?>
|
|
</td>
|
|
<td style="text-align: center;"><?php echo date('d/m/y', strtotime($invoice->invoice_date_created)); ?>
|
|
<td style="text-align: center;"><?php echo date('d/m/y', strtotime($invoice->invoice_date_due)); ?>
|
|
</td>
|
|
<td style="text-align: center;"><?php echo $invoice->client_name ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->user_name ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->product_name ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->payment_method_name; ?></td>
|
|
<td style="text-align: center;"><?php echo $invoice->invoice_total ?></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>
|
|
<label for=""> Invoice Number :</label><span id="invoice_number_display_model"></span>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
<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">
|
|
|
|
$(function () {
|
|
|
|
$('#datatable_sales_invoice_list').DataTable({
|
|
"paging": true,
|
|
"lengthChange": true,
|
|
"searching": true,
|
|
"ordering": true,
|
|
"columnDefs": [{
|
|
"targets": 0,
|
|
"type": "date-eu"
|
|
}],
|
|
"aaSorting": [
|
|
[1, "desc"]
|
|
],
|
|
"info": true,
|
|
"autoWidth": true,
|
|
"pageLength": 10,
|
|
"lengthMenu": [10, 25, 50, 100],
|
|
});
|
|
});
|
|
</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) {
|
|
$('#invoice_number_display_model').html(invoiceNumber);
|
|
// 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>
|
|
|