Auditing team sales report: GWM

This commit is contained in:
Gowtham M 2025-03-04 10:37:17 +05:30
parent cbf9c4e42e
commit 520572206f
10 changed files with 569 additions and 46 deletions

View File

@ -437,6 +437,7 @@ $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');
$routes->match(['GET', 'POST'], 'sales_report', 'Sales::sales_report');
// transporter Routes
$routes->get('transporterListing', 'Supplier::transporterListing');

View File

@ -118,6 +118,44 @@ class Sales extends BaseController
$this->loadViews("sales_invoice", $this->global, $data, NULL);
}
public function sales_report()
{
$headline = '';
$report = [];
if ($this->request->getMethod(true) === 'POST' && $this->request->getPost('btn_submit')) {
$from_date = $this->request->getPost('from_date');
$to_date = $this->request->getPost('to_date');
$hsn_number = $this->request->getPost('hsn_number');
$product_id = $this->request->getPost('product');
$client_id = $this->request->getPost('client');
$headline .= ((isset($from_date) && isset($to_date)) && (!empty($from_date) && !empty($to_date))) ? $from_date . ' to ' . $to_date. ', ' : '';
$headline .= (isset($hsn_number) && !empty($hsn_number)) ? $hsn_number . ', ' : '';
$headline .= (isset($product_id) && !empty($product_id)) ? $this->ipinvoice_model->getProductName($product_id) . ', ' : '';
$headline .= (isset($client_id) && !empty($client_id)) ? $this->ipinvoice_model->getClientName($client_id) . ', ' : '';
$report = $this->ipinvoice_model->sales_report($from_date, $to_date, $hsn_number, $product_id, $client_id);
}
$data['hsn'] = $this->ipinvoice_model->getHsn();
$data['product'] = $this->ipinvoice_model->getProducts();
$data['client'] = $this->ipinvoice_model->getClients();
$data['headline'] = $headline;
$data['sales_invoice'] = $report;
// Load the view
$this->global['pageTitle'] = 'Reports';
$this->loadviews("report_sales", $this->global, $data, NULL);
}
public function download_sales_invoice()
{
// Fetch data from the model

View File

@ -1368,6 +1368,10 @@ class User extends BaseController
$headers_new = $result['headers_new'];
$res = json_decode($result['data'], true);
$inv_array = $res['invoices'];
// $cteditNotes = getAllCreditNotes($date_today, $date_yesterday, $token);
// dd($cteditNotes);
// dd($inv_array);
// print_r($inv_array);
// echo "rrrr";
@ -1388,6 +1392,7 @@ class User extends BaseController
// dd($res2);
foreach ($res2 as $rs) {
$gst_no = $rs['gst_no'];
$customer_id = $rs['customer_id'];
$customer_name = $rs['customer_name'];
@ -1538,7 +1543,7 @@ class User extends BaseController
if (isset($rs['line_items']) && count($rs['line_items']) > 0) {
log_message('error', 'Processing line items' . count($rs['line_items']));
dd($rs);
// dd($rs);
for ($i = 0; $i < count($rs['line_items']); $i++) { //start insert line items
$sku = $rs['line_items'][$i]['sku'];

View File

@ -110,4 +110,94 @@ if (! function_exists('test_helper')) {
}
}
if (! function_exists('getAllCreditNotes')) {
// function getAllCreditNotes($date_today, $date_yesterday, $accesstoken)
// {
// // Initialize cURL
// $ch = curl_init();
// // Zoho API credentials
// $organization_id = '776847408';
// // $url_org = "https://books.zoho.com/api/v3/creditnotes?";
// $url_org = "https://www.zohoapis.com/books/v3/creditnotes?";
// // Construct query parameters
// $fields = array(
// "usestate" => "true",
// "organization_id" => $organization_id,
// "date_start" => $date_yesterday,
// "date_end" => $date_today
// );
// $data_all = http_build_query($fields);
// // Set headers
// $headers = array(
// 'Authorization: Zoho-oauthtoken '.$accesstoken,
// 'Content-Type: application/json'
// );
// // Construct URL
// $data_access = $url_org.$data_all;
// // Set cURL options
// curl_setopt($ch, CURLOPT_URL, $data_access);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// // Execute cURL request
// $result = curl_exec($ch);
// // Store headers and data
// $data['headers_new'] = $headers;
// $data['data'] = curl_exec($ch);
// // Return data
// return $data;
// }
function getAllCreditNotes($date_today, $date_yesterday, $accesstoken)
{
// Initialize cURL
$ch = curl_init();
var_dump($accesstoken);
// Zoho API credentials
$organization_id = '776847408';
$url_org = "https://books.zoho.com/api/v3/creditnotes?";
// Construct query parameters manually (Zoho might need raw values)
$query_string = "usestate=true&organization_id=$organization_id&date_start=$date_yesterday&date_end=$date_today";
// Set headers
$headers = array(
'Authorization: Zoho-oauthtoken ' . $accesstoken,
'Content-Type: application/json'
);
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url_org . $query_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL request
$result = curl_exec($ch);
// Check for errors
if ($result === false) {
return ['error' => curl_error($ch)];
}
// Close cURL session
curl_close($ch);
return [
'headers_new' => $headers,
'data' => $result
];
}
}
?>

View File

@ -410,6 +410,7 @@ class Inwardgateregister_model extends Model
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
LEFT JOIN t_revenue_tax tax ON tax.LineItemNo = POL.LineItemNo
WHERE IGRD.IGRNO = igr.IGRNO AND IGRD.QuantityAsPerInvoice != 0
GROUP BY POL.PONO
LIMIT 1
)
WHEN (PO.POType = 'service' OR (PO.POType = 'capital' AND PO.CapitalRange = '1')) THEN (
@ -421,6 +422,7 @@ class Inwardgateregister_model extends Model
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
LEFT JOIN t_service_tax tax ON tax.LineItemNo = POL.LineItemNo
WHERE IGRD.IGRNO = igr.IGRNO AND IGRD.QuantityAsPerInvoice != 0
GROUP BY POL.PONO
LIMIT 1
)

View File

@ -4,6 +4,7 @@ namespace App\Models;
use CodeIgniter\Model;
class Ipinvoice_model extends Model
{
@ -23,7 +24,7 @@ class Ipinvoice_model extends Model
ip_invoices.invoice_number, ip_invoices.invoice_terms, ip_invoices.status, ip_invoices.e_invoice_number, ip_invoices.invoice_url, ip_clients.client_name,
ip_payment_methods.payment_method_name, ip_users.user_name,
ip_products.product_name, ip_invoice_items.item_price, ip_products.cgst, ip_products.sgst,
ip_invoice_items.item_quantity, ip_invoice_items.item_price, ip_invoice_items.item_name, ip_invoice_items.item_quantity,
ip_invoice_items.item_quantity, ip_invoice_items.item_price, ip_invoice_items.item_name, ip_invoice_items.item_quantity,ip_invoice_items.hsn_or_sac,
ip_invoice_amounts.invoice_total, ip_invoice_amounts.invoice_item_subtotal, ip_invoice_amounts.invoice_item_tax_total
,ip_invoice_attachment.file_name , ip_invoices.received_qty')
->join('ip_payment_methods', 'ip_invoices.payment_method = ip_payment_methods.payment_method_id', 'left')
@ -41,47 +42,100 @@ class Ipinvoice_model extends Model
$result = $query->getResult();
// $results = $query->getResultArray();
return $result;
// $invoices = [];
// foreach ($results as $row) {
// $invoice_id = $row['invoice_id'];
// // If the invoice_id doesn't exist in the $invoices array, initialize it
// if (!isset($invoices[$invoice_id])) {
// $invoices[$invoice_id] = [
// 'invoice_id' => $row['invoice_id'],
// 'user_id' => $row['user_id'],
// 'client_id' => $row['client_id'],
// 'invoice_group_id' => $row['invoice_group_id'],
// 'invoice_status_id' => $row['invoice_status_id'],
// 'invoice_date_due' => $row['invoice_date_due'],
// 'invoice_date_created' => $row['invoice_date_created'],
// 'invoice_number' => $row['invoice_number'],
// 'invoice_terms' => $row['invoice_terms'],
// 'status' => $row['status'],
// 'e_invoice_number' => $row['e_invoice_number'],
// 'invoice_url' => $row['invoice_url'],
// 'client_name' => $row['client_name'],
// 'payment_method_name' => $row['payment_method_name'],
// 'user_name' => $row['user_name'],
// 'invoice_total' => $row['invoice_total'],
// 'invoice_item_subtotal' => $row['invoice_item_subtotal'],
// 'invoice_item_tax_total' => $row['invoice_item_tax_total'],
// 'products' => [] // Initialize the products array
// ];
// }
// // Add the product to the products array for the current invoice
// $invoices[$invoice_id]['products'][] = [
// 'product_name' => $row['product_name'],
// 'item_quantity' => $row['item_quantity'],
// 'item_price' => $row['item_price'],
// ];
// }
// // Return the grouped invoices
// return $invoices;
}
function getHsn()
{
return $this->db->table('ip_invoice_items')
->select('hsn_or_sac')
->distinct()
->get()
->getResult();
}
function getProducts()
{
return $this->db->table('ip_products')
->select('product_id,product_name')
->distinct()
->get()
->getResult();
}
function getProductName($id)
{
return $this->db->table('ip_products')
->select('product_id,product_name')
->where('product_id',$id)
->get()->getRow()->product_name;
}
function getClientName($id)
{
return $this->db->table('ip_clients')
->select('client_id,client_name')
->where('client_id',$id)
->get()->getRow()->client_name;
}
function getClients()
{
return $this->db->table('ip_clients')
->select('client_id,client_name')
->distinct()
->get()
->getResult();
}
public function sales_report($from_date, $to_date, $hsn_number, $product_id, $client_id)
{
$builder = $this->db->table('ip_invoices')
->select('ip_invoices.invoice_id, ip_invoices.user_id, ip_invoices.client_id,
ip_invoices.invoice_group_id, ip_invoices.invoice_status_id, ip_invoices.invoice_date_due, ip_invoices.invoice_date_created,
ip_invoices.invoice_number, ip_invoices.invoice_terms, ip_invoices.status, ip_invoices.e_invoice_number, ip_invoices.invoice_url, ip_clients.client_name,
ip_payment_methods.payment_method_name, ip_users.user_name,
ip_products.product_name, ip_invoice_items.item_price, ip_products.cgst, ip_products.sgst,
ip_invoice_items.item_quantity, ip_invoice_items.item_price, ip_invoice_items.item_name, ip_invoice_items.item_quantity,ip_invoice_items.hsn_or_sac,
ip_invoice_amounts.invoice_total, ip_invoice_amounts.invoice_item_subtotal, ip_invoice_amounts.invoice_item_tax_total,
ip_invoice_attachment.file_name, ip_invoices.received_qty')
->join('ip_payment_methods', 'ip_invoices.payment_method = ip_payment_methods.payment_method_id', 'left')
->join('ip_clients', 'ip_invoices.client_id = ip_clients.client_id', 'left')
->join('ip_users', 'ip_invoices.user_id = ip_users.user_id', 'left')
->join('ip_invoice_items', 'ip_invoices.invoice_id = ip_invoice_items.invoice_id', 'left')
->join('ip_products', 'ip_invoice_items.item_product_id = ip_products.product_id', 'left')
->join('ip_invoice_amounts', 'ip_invoices.invoice_id = ip_invoice_amounts.invoice_id', 'left')
->join('ip_invoice_attachment', 'ip_invoices.invoice_id = ip_invoice_attachment.invoice_id AND ip_invoice_attachment.is_active = 1', 'left');
// Apply filters only if values are provided
if (!empty($from_date) && !empty($to_date)) {
$from_date = get_date_time_dynamical_format('d-m-Y', 'Y-m-d', $from_date);
$to_date = get_date_time_dynamical_format('d-m-Y', 'Y-m-d', $to_date);
$builder->where('ip_invoices.invoice_date_created >=', $from_date);
$builder->where('ip_invoices.invoice_date_created <=', $to_date);
}
if (!empty($hsn_number)) {
$builder->where('ip_invoice_items.hsn_or_sac', $hsn_number);
}
if (!empty($product_id)) {
$builder->where('ip_invoice_items.item_product_id', $product_id);
}
if (!empty($client_id)) {
$builder->where('ip_invoices.client_id', $client_id);
}
// Order by invoice number in descending order
$builder->orderBy('ip_invoices.invoice_number', 'DESC');
$query = $builder->get();
return $query->getResult();
}

View File

@ -654,6 +654,7 @@
</a>
<div class="dropdown-menu" aria-labelledby="topnav-hr">
<a href="<?php echo base_url(); ?>sales_invoice" class="dropdown-item"><i class="ri-file-list-3-line align-middle mr-1"></i>Invoice</a>
<a href="<?php echo base_url(); ?>sales_report" class="dropdown-item"><i class="ri-file-list-3-line align-middle mr-1"></i>Invoice Report</a>
<?php if(session()->get('roleText') == 'System Administrator'){?>
<!-- <a href="<?php echo base_url(); ?>dashboard" class="dropdown-item"><i class="ri-refresh-line align-middle mr-1"></i>Sync With Zoho Books</a> -->

319
app/Views/report_sales.php Normal file
View File

@ -0,0 +1,319 @@
<script>
$(document).ready(function() {
$("#client").select2();
$("#product").select2();
$("#hsn_number").select2();
});
</script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.4.2/css/buttons.dataTables.min.css">
<style>
table{
width:auto;
}
.dataTables_filter input {
padding: 4px;
}
.dataTables_filter {
/* width: 50%; */
float: right;
text-align: right;
}
.dataTables_paginate {
width: 50%;
float: right;
text-align: right;
}
div.dt-buttons {
position: relative;
/* float: right; */
}
</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"><b> Sales Report </b></h4>
</li>
</ol>
</div>
</div>
</div>
<?php if(isset($headline)) : if(!empty($headline)) : ?>
<div class="col-12">
<div class="page-title-right">
<span>Result filter by : </span><h4 class="page-title" style="display: inline;"><?php echo $headline; ?></h4>
</div>
</div>
<?php endif; endif; ?>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<!-- <form class="Date-filter-form" id="DateRangeFilter" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;"> -->
<div class="card-body">
<form method="post" action="<?php echo base_url("sales_report"); ?>">
<div class="form-group">
<div class="row">
<div class="col-2">
<label for="from_date">
<?php echo 'From Date'; ?>
</label>
<div class="input-group">
<input name="from_date" id="max-date" class="form-control datepicker" autocomplete="off">
</div>
</div>
<div class="col-2">
<label for="to_date">
<?php echo 'To Date'; ?>
</label>
<div class="input-group">
<input name="to_date" id="min-date" class="form-control datepicker" autocomplete="off">
</div>
</div>
<div class="col-2">
<label for="hsn_number">
<?php echo 'HSN'; ?>
</label>
<select class="form-control" id="hsn_number" name="hsn_number">
<option value="">Select HSN</option>
<?php
foreach ($hsn as $val): { ?>
<option value="<?php echo $val->hsn_or_sac; ?>"><?php echo $val->hsn_or_sac; ?></option>
<?php }
endforeach; ?>
</select>
</div>
<div class="col-3">
<label for="product">
<?php echo 'Products'; ?>
</label>
<select class="form-control" id="product" name="product">
<option value="">Select Product</option>
<?php
foreach ($product as $val): { ?>
<option value="<?php echo $val->product_id; ?>"><?php echo $val->product_name; ?></option>
<?php }
endforeach; ?>
</select>
</div>
<div class="col-3">
<label for="client">
<?php echo 'Clients'; ?>
</label>
<select class="form-control" id="client" name="client">
<option value="">Select Client</option>
<?php
foreach ($client as $val): { ?>
<option value="<?php echo $val->client_id; ?>"><?php echo $val->client_name; ?></option>
<?php }
endforeach; ?>
</select>
</div>
<div class="col-md-6"></div>
<div class="col-md-6 text-right"><br>
<input type="submit" class="btn btn-success" name="btn_submit"
value="View Report">
</div>
</div>
</div>
<div class="form-group has-feedback">
</div>
</form>
<table id="cc" class="table table-bordered table-hover wrap" style="background-color:#fff;width: 100% !important;">
<thead>
<tr>
<th>Invoice Date</th>
<th>Invoice No</th>
<th>Client Name</th>
<th>Product</th>
<th>HSN</th>
<th>Quantity</th>
<th>Rate</th>
<th>Sub Total</th>
<th>GST</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php if (!empty($sales_invoice)) {
$tot = 0; $totGst = 0; $totSubTot = 0;
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->hsn_or_sac ?></td>
<td align="right"><?php echo number_format($invoice->item_quantity, 2, '.', ',') ?></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>
</tr>
<?php
$tot = $total + $tot;
$totGst = ($cgst_amount + $sgst_amount) + $totGst;
$totSubTot = $subtotal + $totSubTot;
} ?>
</tbody>
<tfoot width="100%">
<tr>
<td style="text-align:center;"><strong>Total</strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo '';}?></strong></td>
<td style="text-align:right"><strong><?php {echo number_format($totSubTot, 2, '.', ','); }?></strong></td>
<td style="text-align:right"><strong><?php {echo number_format($totGst, 2, '.', ','); }?></strong></td>
<td style="text-align:right"><strong><?php {echo number_format($tot, 2, '.', ','); }?></strong></td>
</td>
</tr>
</tfoot>
<?php
}
?>
</table>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div>
</div> <!-- container -->
</div> <!-- content -->
</div>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.colVis.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/datetime-moment.js"></script>
<script>
// Bootstrap datepicker
// Set up your table
$(document).ready(function() {
// Initialize the DataTable
var table = $('#cc').DataTable({
dom: 'Blfrtip', // Buttons, length menu, filter, table, information, pagination
buttons: [
'copy', 'csv' // Export buttons
],
pageLength: 10, // Default rows per page
lengthMenu: [
[10, 20, 30, 50, -1],
[10, 20, 30, 50, "All"]
], // Rows per page options
responsive: true, // Responsive table
order: [
[0, 'desc']
], // Default ordering (column index 0, descending)
language: {
paginate: {
next: '<i class="fas fa-angle-right"></i>', // Next button icon
previous: '<i class="fas fa-angle-left"></i>' // Previous button icon
}
}
});
});
$('#mySelect').on('change', function() {
table
.column(4)
.search(this.value)
.draw();
});
$(function() {
var dateFormat = 'dd-mm-yyyy';
// Initialize min-date (Start Date)
var from = $("#min-date").datepicker({
format: dateFormat,
autoclose: true,
todayHighlight: true,
clearBtn: true,
orientation: 'bottom'
}).on('changeDate', function(e) {
// When a date is selected in #min-date, update the minDate option for #max-date
// to.datepicker('setStartDate', e.date);
});
// Initialize max-date (End Date)
var to = $("#max-date").datepicker({
format: dateFormat,
// startDate: new Date(), // Start date cannot be in the past
autoclose: true,
todayHighlight: true,
clearBtn: true,
orientation: 'bottom'
}).on('changeDate', function(e) {
// When a date is selected in #max-date, update the endDate option for #min-date
from.datepicker('setStartDate', e.date);
});
});
</script>

View File

@ -239,6 +239,7 @@
<th>Received File</th>
<th>Client Name</th>
<th>Product</th>
<th>HSN</th>
<th>Quantity</th>
<th> Rec Qty </th>
<th>Rate</th>
@ -281,6 +282,7 @@
</td>
<td><?php echo $invoice->client_name ?></td>
<td><?php echo $invoice->item_name ?></td>
<td><?php echo $invoice->hsn_or_sac ?></td>
<td align="right"><?php echo number_format($invoice->item_quantity, 2, '.', ',') ?></td>
<td>
<a href="#"
@ -306,8 +308,7 @@
</a>
</td>
</tr>
<?php }
} ?>
<?php } } ?>
</tbody>
</table>
</div> <!-- end card body-->

View File

@ -262,7 +262,7 @@
<td align="right"><?php echo (int)$record->NetWeight ?></td>
<td align="right"><?php echo (int)$record->taxable_value ?></td>
<td align="right"><?php echo (int)$record->gst_amount ?></td>
<td align="right"><?php echo ((int)$record->gst_amount + (int)$record->gst_amount) ?></td>
<td align="right"><?php echo ((int)$record->taxable_value + (int)$record->gst_amount) ?></td>
<td><?php echo $record->VehicleNo ?></td>
<td><?php echo $record->DriverName ?></td>
@ -1808,6 +1808,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.13.6/sorting/datetime-moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<script>
// $(document).ready(function() {
@ -1935,6 +1936,14 @@
}
$(document).ready(function() {
// this code for table date filed ordering
$.fn.dataTable.ext.type.order['date-dd-mm-yyyy-pre'] = function(date) {
if (!date) return 0;
var parts = date.split('-'); // Split the date into parts (DD, MM, YYYY)
return new Date(parts[2], parts[1] - 1, parts[0]).getTime(); // Convert to timestamp
};
var orderColumnIndex = <?php echo (session()->get('roleText') == 'Auditor') ? 6 : 0; ?>;
table = $('#view_inward_gate_register').DataTable({
dom: 'Blfrtip',
@ -1953,7 +1962,10 @@
[10, 20, 30, 50, "All"]
],
responsive: false,
ordering:true,
ordering: true,
columnDefs: [
{ targets: parseInt(orderColumnIndex), type: 'date-dd-mm-yyyy' } // Apply custom sorting
],
order: [[parseInt(orderColumnIndex), 'desc']],
language: {
paginate: {