ria/app/Views/sales_invoice.php
2025-03-26 12:18:41 +05:30

714 lines
28 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>
.edit-container {
display: inline-flex;
align-items: center;
gap: 10px;
}
.edit-input-field {
padding: 2px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
width: 150px;
}
.edit-input-field:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.save-btn, .cancel-btn {
border: none;
background: none;
cursor: pointer;
font-size: 16px;
display: flex;
align-items: center;
justify-content: center;
width: 30px;
height: 30px;
border-radius: 50%;
transition: background-color 0.3s ease;
}
.save-btn {
color: #28a745;
background-color: #e8f5e9;
}
.save-btn:hover {
background-color: #c3e6cb;
}
.cancel-btn {
color: #dc3545;
background-color: #f8d7da;
}
.cancel-btn:hover {
background-color: #f5c6cb;
}
/* 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">
<div class="row">
<div class="col-md-10">
<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>
<div class="col-md-2 text-right" style="padding-right: 36px !important;">
<button class="btn btn-secondary" id="excel-download" style="margin-top: 14px; margin-bottom: -11px; " type="button"><span>Excel</span></button>
</div>
</div>
<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>Received File</th>
<th>Client Name</th>
<th>Product</th>
<th>HSN</th>
<th>Driver</th>
<th>Vehicle</th>
<th>Quantity</th>
<th> Rec Qty </th>
<th>Rate</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 style="text-align: center;">
<?php if (!empty($invoice->file_name)) { ?>
<a title="click to preview" href=" <?php echo base_url('public/uploads/images/invoice_files/').$invoice->file_name; ?>">
<i class="fa-solid fa-file-pdf"></i>
</a>
<?php } ?>
</td>
<td><?php echo $invoice->client_name ?></td>
<td><?php echo $invoice->item_name ?></td>
<td><?php echo $invoice->hsn_or_sac ?></td>
<td><?php echo $invoice->deiver_name ?></td>
<td><?php echo $invoice->vehicle_no ?></td>
<td align="right"><?php echo number_format($invoice->item_quantity, 2, '.', ',') ?></td>
<td>
<a href="#"
class="editable-field"
data-invoice-id="<?php echo $invoice->invoice_id; ?>">
<?php echo !empty($invoice->received_qty) ? $invoice->received_qty : "0"; ?>
</a>
<div class="edit-container" style="display:none;">
<input type="text" class="edit-input-field" />
<button class="save-btn">✔</button>
<button class="cancel-btn">✖</button>
</div>
</td>
<td align="right"><?php echo number_format($invoice->item_price, 2, '.', ',') ?></td>
<td align="right"><?php echo number_format($subtotal, 2, '.', ',') ?></td>
<td align="right"><?php echo number_format($cgst_amount + $sgst_amount, 2, '.', ',') ?></td>
<td align="right"><?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;">
<?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 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>
</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 src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.0/xlsx.full.min.js"></script>
<script>
$(document).ready(function () {
$(document).on('click', '.editable-field', function (e) {
e.preventDefault();
const $link = $(this);
const value = $link.text().trim();
// Hide the <a> tag and show the edit container
$link.hide();
const $editContainer = $link.siblings('.edit-container');
$editContainer.find('.edit-input-field').val(value);
$editContainer.show();
});
// Handle click on the tick (save) button
$(document).on('click', '.save-btn', function (e) {
e.preventDefault();
const $btn = $(this);
const $editContainer = $btn.closest('.edit-container');
const $input = $editContainer.find('.edit-input-field');
const value = $input.val().trim();
const $link = $editContainer.siblings('.editable-field');
const invoiceId = $link.data('invoice-id');
$('#loader').show();
// Save logic (API call)
$.ajax({
url: '<?php echo base_url() ?>updateInvRecQty',
method: 'POST',
data: { invoice_id: invoiceId, received_qty: value },
success: function (response) {
// Show success and update the <a> tag value
$link.text(value).show();
$editContainer.hide();
$('#loader').hide();
},
error: function (xhr) {
$('#loader').hide();
alert('Failed to save the value.');
}
});
});
// Handle click on the close (cancel) button
$(document).on('click', '.cancel-btn', function (e) {
e.preventDefault();
const $btn = $(this);
const $editContainer = $btn.closest('.edit-container');
const $link = $editContainer.siblings('.editable-field');
// Hide the edit container and show the <a> tag
$editContainer.hide();
$link.show();
});
document.getElementById("excel-download").addEventListener("click", function () {
const fromDate = document.getElementById("fromDate").value;
const toDate = document.getElementById("toDate").value;
if (!fromDate || !toDate) {
alert("Please select both From and To dates.");
return;
}
$('#loader').show();
$.ajax({
url: '<?php echo base_url() ?>download_sales_invoice',
method: 'POST',
data: { fromDate: fromDate, toDate: toDate },
success: function (response) {
const html = response.html;
// Create a temporary DOM element to hold the table HTML
const tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
// Get the table
const table = tempDiv.querySelector('table');
// Use SheetJS to create an Excel file from the HTML table
const wb = XLSX.utils.table_to_book(table, {sheet: "Invoice Data"});
// Generate Excel file and trigger download
XLSX.writeFile(wb, 'Sales_Invoice_Report.xlsx');
$('#loader').hide();
},
error: function (xhr) {
$('#loader').hide();
alert('Failed to Download.');
}
});
});
});
$(document).ready(function() {
// Initialize the DataTable
var table = $('#datatable-buttosns').DataTable({
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) {
var list = JSON.parse(response).invoiceAttachment;
var attachmentsHtml = '';
if(list.length){ $('#day').hide(); }
list.forEach(element => {
console.log(element);
var fileName = element.file_name;
var attachmentName = element.attachment_name;
attachmentsHtml += ` <br>
<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>
</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) {
window.location.reload();
},
error: function() {
}
});
}
function saveAttachment() {
var formData = new FormData();
var invoiceId = $('#invoice_id_set').val();
formData.append('invoice_id', invoiceId);
var hasFiles = false;
// 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]);
hasFiles = true; // At least one file is selected
}
});
if (!hasFiles) {
alert('Please select file.');
return;
}
var hasFileName = true;
// Append other fields
$('input[name="file_name[]"]').each(function(index, input) {
var fileName = $(input).val().trim();
if (!fileName) {
hasFileName = false;
}
formData.append('file_name[]', $(input).val());
});
if (!hasFileName) {
alert('Please enter a file name for selected files.');
return;
}
// 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');
window.location.reload();
// 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>