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

507 lines
20 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
/* Target the first child element of #datatable-buttons_wrapper */
#datatable-buttons_wrapper.dataTables_wrapper.dt-bootstrap4.no-footer> :nth-child(1) {
display: none;
}
/* Target the third child element of #datatable-buttons_wrapper */
#datatable-buttons_wrapper.dataTables_wrapper.dt-bootstrap4.no-footer> :nth-child(3) {
display: none;
}
.card_font_colorset_green {
font-size: 23.7215px;
font-weight: 500;
line-height: 1.2;
position: relative;
z-index: 1;
color: rgb(86, 166, 75);
}
.card_font_colorset_bule {
font-size: 23.7215px;
font-weight: 500;
line-height: 1.2;
position: relative;
z-index: 1;
color: rgb(31, 96, 196);
}
.card_font_colorset_red {
font-size: 23.7215px;
font-weight: 500;
line-height: 1.2;
position: relative;
z-index: 1;
color: rgb(173, 3, 23);
}
</style>
<style>
#Requisition_filter {
float: inline-end;
}
#Requisition_wrapper .row .col-sm-4 {
flex-basis: 50%;
float: inline-end;
}
#Requisition_paginate .pagination {
flex-basis: 50%;
float: inline-end;
margin: 0 0 15px;
}
#Requisition_wrapper .row:nth-child(3),
#Requisition_wrapper .row:nth-child(1) {
padding: 0 15px;
}
#Requisition_info {
margin-top: 5px;
}
.dataTables_wrapper {
padding-bottom: 0;
}
span.highlight {
background-color: yellow;
}
</style>
<style>
.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;
}
</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);">Sales</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Invoices List</h4>
</li>
</ol>
</div>
</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('sales_invoice'); ?>">
<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 id="datatable-buttosns" class="table dt-responsive nowrap w-100">
<thead>
<tr>
<th>Invoice Date</th>
<th>Invoice No</th>
<th>Client Name</th>
<th>Product</th>
<th>Rate</th>
<th>Quantity</th>
<th>Sub Total</th>
<th>GST</th>
<th>Total</th>
<th>Status</th>
<th>E-Invoice Number</th>
<th>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>
<td><?php echo date('d-m-Y', strtotime($invoice->invoice_date_created)); ?></td>
<td>
<?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><?php echo $invoice->client_name ?></td>
<td><?php echo $invoice->item_name ?></td>
<td><?php echo $invoice->item_price ?></td>
<td><?php echo number_format($invoice->item_quantity, 2, '.', ',') ?></td>
<td><?php echo number_format($subtotal, 2, '.', ',') ?></td>
<td><?php echo number_format($cgst_amount + $sgst_amount, 2, '.', ',') ?></td>
<td><?php echo number_format($total, 2, '.', ',') ?></td>
<td><?php echo $invoice->status ?></td>
<td><?php echo $invoice->e_invoice_number; ?></td>
<td>
<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> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div>
</div> <!-- container -->
</div> <!-- content -->
</div>
<!-- Modal Structure -->
<div class="modal fade" id="invoiceModal" tabindex="-1" role="dialog" aria-labelledby="invoiceModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header" style="display:block">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="standard-modalLabel">
<span id="invoice_number_display_model"></span> -
<span id="date_display_model"></span>
</h4>
<span id="client_name_display_model"></span>
<div class="col-md-12">
</div>
</div>
<div class="modal-body" style="margin-top: 23px;">
<div class="col-md-4">
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()" id="day">
Add New File
</button>
</div>
<div id="filesContainer">
<!-- Rows will be dynamically appended here -->
</div>
<?php if (isset($invoice_data)) {
foreach ($invoice_data as $key => $value) { ?>
<div class="row 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>
$(document).ready(function() {
// Initialize the DataTable
var table = $('#datatable-buttosns').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>', // Next button icon
previous: '<i class="fas fa-angle-left"></i>' // Previous button icon
}
}
});
// Reset button functionality
$("#resetButton").click(function() {
$("#fromDate").val('');
$("#toDate").val('');
window.location="sales_invoice"
});
});
function openInvoiceModal(invoiceNumber, clientName, invoiceDateCreated, invoiceId) {
$('#invoice_number_display_model').html(invoiceNumber);
$('#date_display_model').html(invoiceDateCreated);
$('#client_name_display_model').html(clientName);
$('#invoice_id_set').val(invoiceId);
// document.getElementById('modalInvoiceNumber').innerText = invoiceNumber;
$('#day').show();
// $('#invoiceModal').modal('show');
// url: "<?php echo base_url() ?>servicepurchaseorder/getPODetails",
$.ajax({
url: '<?php echo base_url() ?>getInvoiceAttachment',
type: 'GET',
data: {
invoice_number: 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="row 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="row 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() {
}
});
}
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.');
}
});
}
</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>