Merge branch 'new_theme' of bitbucket.org:venbainformationtechnology/ria into new_theme

This commit is contained in:
vadivelJ96 2024-12-25 13:16:14 +05:30
commit c5cdee60ce
10 changed files with 240 additions and 62 deletions

View File

@ -412,6 +412,7 @@ $routes->get('deleteAttachment', 'Sales::deleteAttachment');
$routes->post('saveAttachment', 'Sales::saveAttachment');
$routes->get('sales_invoice', 'Sales::sales_invoice');
$routes->post('sales_invoice', 'Sales::sales_invoice');
$routes->post('download_sales_invoice', 'Sales::download_sales_invoice');
$routes->post('updateInvRecQty', 'Sales::updateInvRecQty');
// transporter Routes

View File

@ -48,8 +48,17 @@ class Expense extends BaseController
$this->loadViews("expense_list", $this->global, $data, NULL);
}
private function generateSerialNumber($financialYear, $lastSerial)
{
// If no last serial number exists, start with 00001
$lastNumber = $lastSerial ? (int)explode('/', $lastSerial)[1] : 0;
$newNumber = str_pad($lastNumber + 1, 5, '0', STR_PAD_LEFT);
return "$financialYear/$newNumber";
}
public function addExpense()
{
try{
$file = $this->request->getFile('transporterfile');
$fileName = '';
if ($file->isValid() && !$file->hasMoved()) {
@ -59,6 +68,28 @@ class Expense extends BaseController
$status = $this->request->getPost('status');
$paymentMethod = $status === 'Paid' ? $this->request->getPost('payment_method') : 0;
// Fetch the current month
$currentMonth = date('n'); // 'n' gives the month without leading zeros (1-12)
// Calculate the current financial year
if ($currentMonth >= 4) { // If it's April or later
$startYear = date('Y'); // Current year
$endYear = $startYear + 1; // Next year
} else { // If it's January, February, or March
$endYear = date('Y'); // Current year
$startYear = $endYear - 1; // Previous year
}
// Format the financial year as "yy-yy"
$financialYear = substr($startYear, -2) . '-' . substr($endYear, -2);
// Fetch the last serial number for the financial year
$lastSerial = $this->expense_model->getLastSerialNumber($financialYear);
// Generate the next serial number
$newSerialNumber = $this->generateSerialNumber($financialYear, $lastSerial);
$data = [
'transporter_file' => $fileName,
@ -70,14 +101,21 @@ class Expense extends BaseController
'sgst' => $this->request->getPost('sgst'),
'igst' => $this->request->getPost('igst'),
'total' => $this->request->getPost('total'),
'bill_no' => $this->request->getPost('bill_no'),
'bill_date' => $this->request->getPost('bill_date'),
'serial_number' => $newSerialNumber,
];
$insert_id = $this->expense_model->insertExpense($data);
if ($insert_id) {
return json_encode('true');
} else {
return json_encode('false');
}
} catch (\Exception $e) {
// Handle the exception
echo "Error: " . $e->getMessage();
}
}
public function getExpenseDetails()
@ -117,6 +155,8 @@ class Expense extends BaseController
'sgst' => $this->request->getPost('sgst'),
'igst' => $this->request->getPost('igst'),
'total' => $this->request->getPost('total'),
'bill_no' => $this->request->getPost('bill_no'),
'bill_date' => $this->request->getPost('bill_date'),
];
if(!empty($fileName)){
$data['transporter_file'] = $fileName;

View File

@ -8,6 +8,8 @@ use App\Models\Ipinvoice_model;
use App\Models\Ipattachment_model;
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Sales extends BaseController
{
@ -40,6 +42,7 @@ class Sales extends BaseController
return $formattedNumber;
}
public function sales_dashboard()
{
$this->global['pageTitle'] = 'Sales Dashboard';
@ -97,12 +100,12 @@ class Sales extends BaseController
{
$toDate = date('Y-m-d');
$fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate)));
} elseif ($this->request->getMethod() === 'POST') {
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
}
} elseif ($this->request->getMethod() === 'POST') {
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
}
$this->global['pageTitle'] = 'Sales Invoice';
$data['sales_invoice'] = $this->ipinvoice_model->saleInvoiceListing($fromDate , $toDate);
@ -114,6 +117,62 @@ class Sales extends BaseController
$this->loadViews("sales_invoice", $this->global, $data, NULL);
}
public function download_sales_invoice()
{
// Fetch data from the model
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
$sales_invoice = $this->ipinvoice_model->saleInvoiceListing($fromDate, $toDate);
// Start building the table
$html = '<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>Quantity</th>
<th>Rec Qty</th>
<th>Rate</th>
<th>Sub Total</th>
<th>GST</th>
<th>Total</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
foreach ($sales_invoice as $invoice) {
$subtotal = $invoice->item_price * $invoice->item_quantity;
$cgst_amount = ($subtotal * $invoice->cgst) / 100;
$sgst_amount = ($subtotal * $invoice->sgst) / 100;
$total = $subtotal + $cgst_amount + $sgst_amount;
$html .= '<tr>
<td>' . date('d-m-Y', strtotime($invoice->invoice_date_created)) . '</td>
<td>' . $invoice->invoice_number . '</td>
<td>' . $invoice->client_name . '</td>
<td>' . $invoice->item_name . '</td>
<td>' . number_format($invoice->item_quantity, 2, '.', ',') . '</td>
<td>' . (!empty($invoice->received_qty) ? $invoice->received_qty : '') . '</td>
<td>' . number_format($invoice->item_price, 2, '.', ',') . '</td>
<td>' . number_format($subtotal, 2, '.', ',') . '</td>
<td>' . number_format($cgst_amount + $sgst_amount, 2, '.', ',') . '</td>
<td>' . number_format($total, 2, '.', ',') . '</td>
<td>' . $invoice->status . '</td>
</tr>';
}
$html .= '</tbody></table>';
return $this->response->setJSON(['html' => $html]);
}
// View Invoice
function ViewInvoice($InvoiceNO = '')

View File

@ -9,9 +9,20 @@ class Expense_model extends Model
protected $primaryKey = 'id'; // Primary key
protected $allowedFields = [
'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total',
'serial_number' , 'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total', 'bill_no' ,'bill_date'
];
public function getLastSerialNumber($financialYear)
{
return $this->db->table('t_expense')
->select('serial_number')
->like('serial_number', "$financialYear/", 'after')
->orderBy('serial_number', 'DESC')
->limit(1)
->get()
->getRow('serial_number');
}
// Retrieve all active expenses
public function getAllExpense($fromDate,$toDate) {
return $this->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID')

View File

@ -47,25 +47,7 @@
align-items: center;
}
.dataTables_wrapper .dataTables_length {
/* float: left; */
}
.dataTables_wrapper .dt-buttons,
.dataTables_wrapper .dataTables_filter {
/* float: right; */
/* margin-left: 10px; */
}
.dataTables_wrapper .dt-buttons {
/* margin-top: 10px; */
/* margin-bottom: 10px; */
}
.dataTables_wrapper .dataTables_filter {
/* margin-top: 10px; */
/* margin-bottom: 10px; */
}
</style>
@ -267,7 +249,13 @@
var table = $('#po_list').DataTable({
dom: 'Blfrtip',
buttons: [
'excel', 'pdf'
{
extend: 'excel',
text: 'Excel',
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
}
],
pageLength: 10,
lengthMenu: [

View File

@ -55,6 +55,11 @@
background-color: white;
color: red;
}
th,
td {
white-space: nowrap;
}
</style>
<div class="content-page">
<div class="content">
@ -108,8 +113,11 @@
<thead>
<tr>
<th align="left" style="width: 10%;">Created Date</th>
<th align="left" style="width: 10%;">Non-IGRNO</th>
<th align="left" style="width: 20%;">Supplier Name</th>
<th align="left" style="width: 25%;">Item Description</th>
<th align="left" style="width: 20%;">Bill No</th>
<th align="left" style="width: 20%;">Bill Date</th>
<th align="left" style="width: 7%;">Cost</th>
<th align="left" style="width: 5%;">CGST</th>
<th align="left" style="width: 5%;">SGST</th>
@ -138,7 +146,7 @@
}
?>
<td><?php echo $cdate; ?></td>
<!-- <td><?php echo $record['id']; ?></td> -->
<td><?php echo $record['serial_number']; ?></td>
<td class="expandable-td">
<div class="text-container" style="max-height: 20px; overflow: hidden;">
<?php echo $record['SupplierName']; ?>
@ -151,6 +159,13 @@
<?php echo $record['item_description']; ?>
</div>
</td>
<td><?php echo $record['bill_no']; ?></td>
<td>
<?php
$date = new DateTime($record['bill_date']);
echo $date->format('d-m-Y');
?>
</td>
<td><?php echo $record['cost']; ?></td>
<td><?php echo $record['cgst']; ?></td>
<td><?php echo $record['sgst']; ?></td>
@ -214,12 +229,29 @@
<textarea name="item_description" id="item_description" class="form-control"></textarea>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<label for="bill_no" class="col-form-label">Bill No</label>
</div>
<div class="col">
<input type="text" name="bill_no" id="bill_no" class="form-control">
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<label for="bill_date" class="col-form-label">Bill Date</label>
</div>
<div class="col">
<input type="date" name="bill_date" id="bill_date" class="form-control" required>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<label for="cost" class="col-form-label">Cost</label>
</div>
<div class="col">
<input type="number" name="cost" id="cost" class="form-control" required onchange="totalCalculate()">
<input type="text" name="cost" id="cost" class="form-control" required onchange="totalCalculate()">
</div>
</div>
<div class="form-group row">
@ -227,7 +259,7 @@
<label for="cost" class="col-form-label">CGST</label>
</div>
<div class="col">
<input type="number" name="cgst" id="cgst" class="form-control" onchange="totalCalculate()">
<input type="text" name="cgst" id="cgst" class="form-control" onchange="totalCalculate()">
</div>
</div>
<div class="form-group row">
@ -235,7 +267,7 @@
<label for="cost" class="col-form-label">SGST</label>
</div>
<div class="col">
<input type="number" name="sgst" id="sgst" class="form-control" onchange="totalCalculate()">
<input type="text" name="sgst" id="sgst" class="form-control" onchange="totalCalculate()">
</div>
</div>
<div class="form-group row">
@ -243,7 +275,7 @@
<label for="igst" class="col-form-label">IGST</label>
</div>
<div class="col">
<input type="number" name="igst" id="igst" class="form-control" onchange="totalCalculate()">
<input type="text" name="igst" id="igst" class="form-control" onchange="totalCalculate()">
</div>
</div>
<div class="form-group row">
@ -251,7 +283,7 @@
<label for="cost" class="col-form-label">Total</label>
</div>
<div class="col">
<input type="number" name="total" id="total" class="form-control">
<input type="text" name="total" id="total" class="form-control">
</div>
</div>
<div class="form-group row">
@ -287,6 +319,13 @@
</div><!-- /.modal -->
<script>
const dateInput = document.getElementById('bill_date');
dateInput.addEventListener('change', function () {
const date = new Date(dateInput.value);
const formattedDate = date.toLocaleDateString('en-GB').split('/').join('-');
console.log('Formatted Date:', formattedDate);
});
function downloadFile(fileId, fileName) {
window.location.href = 'downloadFile/' + fileName;
}
@ -365,6 +404,8 @@
$('#igst').val(expense.igst);
$('#total').val(expense.total);
$('#status_id').val(expense.status);
$('#bill_no').val(expense.bill_no);
$('#bill_date').val(expense.bill_date);
// Clear any existing file link and delete button
$('#transporterfile').next('.download_button').remove();
@ -470,7 +511,13 @@
var table = $('#expense_list_table').DataTable({
dom: 'Blfrtip',
buttons: [
'excel', 'pdf'
{
extend: 'excel',
text: 'Excel',
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
}
],
pageLength: 10,
lengthMenu: [

View File

@ -59,12 +59,7 @@
<script src="<?php echo base_url(); ?>public/new_assets/js/pages/form-wizard.init.js"></script>
<!-- Plugins js -->
<script src="<?php echo base_url(); ?>public/new_assets/libs/moment/min/moment.min.js"></script>
<script src="<?php echo base_url(); ?>public/new_assets/libs/x-editable/bootstrap-editable/js/bootstrap-editable.min.js"></script>
<!-- Init js-->
<script src="<?php echo base_url(); ?>public/new_assets/js/pages/form-xeditable.init.js"></script>
<script>
$(document).ready(function() {
$('select').addClass('form-control');
@ -73,7 +68,7 @@
autoclose: true,
orientation: 'bottom',
format: 'dd-mm-yyyy',
todayHighlight: true });
todayHighlight: true });
form = $(".form-date-search")
.datepicker({
autoclose: true,

View File

@ -217,14 +217,7 @@
/* Darker red on hover */
color: white;
}
.editableform{
position: relative;
}
.editableform .editable-buttons{
position: absolute;
right: 0;
top: 0;
}
</style>
<style>

View File

@ -190,6 +190,9 @@
<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'); ?>">
@ -213,7 +216,16 @@
<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>
@ -367,12 +379,13 @@
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.0/xlsx.full.min.js"></script>
<script>
$(document).ready(function () {
// Handle click on the <a> tag
$(document).on('click', '.editable-field', function (e) {
e.preventDefault();
const $link = $(this);
@ -424,6 +437,46 @@ $(document).ready(function () {
$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.');
}
});
});
});
@ -431,10 +484,8 @@ $(document).ready(function () {
$(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,
@ -566,7 +617,7 @@ $(document).ready(function () {
invoice_attachment_id: $(button).attr('id')
},
success: function(response) {
console.log(response);
window.location.reload();
},
error: function() {

View File

@ -1729,13 +1729,6 @@
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
},
{
extend: 'pdf',
text: 'PDF',
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
}
],
pageLength: 10,