diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 400d5d1a..50725be6 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -278,6 +278,7 @@ $routes->post('inwardgateregister/edituploadfile', 'Inwardgateregister::edituplo // Non IGR / Expense $routes->get('ListIGR', 'Expense::index'); +$routes->post('ListIGR', 'Expense::index'); //for filter usage $routes->post('addExpense', 'Expense::addExpense'); $routes->post('editExpense', 'Expense::editExpense'); $routes->post('getExpenseDetails', 'Expense::getExpenseDetails'); diff --git a/app/Controllers/Expense.php b/app/Controllers/Expense.php index ce09ab38..a9be54aa 100755 --- a/app/Controllers/Expense.php +++ b/app/Controllers/Expense.php @@ -24,9 +24,27 @@ class Expense extends BaseController public function index() { - $data['expense_list'] = $this->expense_model->getAllExpense(); + + if ($this->request->getMethod() === 'GET') + { + $currentYear = date('Y'); + $currentMonth = date('m'); + $startOfMonth = "$currentYear-$currentMonth-01"; + $endOfMonth = date('Y-m-t'); + $fromDate = $startOfMonth; + $toDate = $endOfMonth; + } else if ($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)); + } + + $data['expense_list'] = $this->expense_model->getAllExpense($fromDate,$toDate); $data['supplier_list'] = json_encode($this->supplier_model->supplierlisting()); $this->global['pageTitle'] = 'Non IGR / Expense List'; + $data['fromDate'] = date('d-m-Y', strtotime($fromDate)); + $data['toDate'] = date('d-m-Y', strtotime($toDate)); $this->loadViews("expense_list", $this->global, $data, NULL); } diff --git a/app/Controllers/Purchaseorder.php b/app/Controllers/Purchaseorder.php index ae1b784f..ac0417e5 100755 --- a/app/Controllers/Purchaseorder.php +++ b/app/Controllers/Purchaseorder.php @@ -118,7 +118,7 @@ class Purchaseorder extends BaseController $endOfMonth = date('Y-m-t'); $fromDate = $startOfMonth; $toDate = $endOfMonth; - } elseif ($this->request->getMethod() === 'POST') { + } else if ($this->request->getMethod() === 'POST') { $fromDate = $this->request->getPost('fromDate'); $toDate = $this->request->getPost('toDate'); $fromDate = date('Y-m-d', strtotime($fromDate)); diff --git a/app/Models/Expense_model.php b/app/Models/Expense_model.php index f3090317..d328b7ee 100755 --- a/app/Models/Expense_model.php +++ b/app/Models/Expense_model.php @@ -13,9 +13,11 @@ class Expense_model extends Model ]; // Retrieve all active expenses - public function getAllExpense() { + public function getAllExpense($fromDate,$toDate) { return $this->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID') ->where('t_expense.isactive', 1) + ->where('t_expense.created_on >=',"$fromDate") + ->where('t_expense.created_on <=',"$toDate") ->orderBy('t_expense.created_on', 'DESC') ->findAll(); } diff --git a/app/Views/expense_list.php b/app/Views/expense_list.php index a5e88c9b..de397c4a 100755 --- a/app/Views/expense_list.php +++ b/app/Views/expense_list.php @@ -80,18 +80,29 @@
-
- - - + + + + - - + + - - -
-
+ + + + + +
+
@@ -460,7 +471,7 @@ var table = $('#expense_list_table').DataTable({ dom: 'Blfrtip', buttons: [ - 'copy', 'csv', 'excel', 'pdf', 'print' + 'csv', 'excel', 'pdf' ], pageLength: 10, lengthMenu: [ @@ -477,60 +488,14 @@ } }); - $.fn.dataTable.ext.search.push( - function(settings, data, dataIndex) { - var fromDate = $('#fromDate').val(); - var toDate = $('#toDate').val(); - console.log(fromDate); // e.g., 01-09-2024 - console.log(toDate); // e.g., 08-09-2024 - - if (!fromDate || !toDate) { - return true; // If no dates selected, don't filter - } - - // Convert the fromDate and toDate from dd-mm-yyyy to Date objects - var fromParts = fromDate.split("-"); - var toParts = toDate.split("-"); - - var startDate = new Date(fromParts[2], fromParts[1] - 1, fromParts[0]); // Year, month (0-based), day - var endDate = new Date(toParts[2], toParts[1] - 1, toParts[0]); - - // Adjust startDate to include the day before the selected fromDate - startDate.setDate(startDate.getDate() - 1); - - // Ensure endDate includes the entire end date by setting time to the end of the day - endDate.setHours(23, 59, 59, 999); - - // Get the date from the DataTable row (assuming it's in the first column in dd-mm-yyyy format) - var dateStr = data[0]; - var dateParts = dateStr.split("-"); - var rowDate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); - - // Return true if the row date is within the range - return rowDate >= startDate && rowDate <= endDate; - } - ); - - $("#DateRangeFilter").submit(function(e) { - e.preventDefault(); - table.draw(); - }); + $("#resetButton").click(function() { $("#fromDate").val(''); $("#toDate").val(''); - table.draw(); + window.location="ListIGR" }); - - document.getElementById('fromDate').addEventListener('change', function() { - var fromDate = this.value; - var toDateInput = document.getElementById('toDate'); - toDateInput.min = fromDate; - if (toDateInput.value < fromDate) { - toDateInput.value = fromDate; - } - }); - }); + }); $(document).on('click', '#deleteFile', function() { var fileName = $(this).data('file'); diff --git a/app/Views/viewinwardgateregister.php b/app/Views/viewinwardgateregister.php index aeb4fbca..920170e9 100755 --- a/app/Views/viewinwardgateregister.php +++ b/app/Views/viewinwardgateregister.php @@ -1649,46 +1649,6 @@ } } }); - // Date range filter function - $.fn.dataTable.ext.search.push( - function(settings, data, dataIndex) { - var fromDate = $('#fromDate').val(); - var toDate = $('#toDate').val(); - console.log(fromDate); // e.g., 01-09-2024 - console.log(toDate); // e.g., 08-09-2024 - - if (!fromDate || !toDate) { - return true; // If no dates selected, don't filter - } - - // Convert the fromDate and toDate from dd-mm-yyyy to Date objects - var fromParts = fromDate.split("-"); - var toParts = toDate.split("-"); - - var startDate = new Date(fromParts[2], fromParts[1] - 1, fromParts[0]); // Year, month (0-based), day - var endDate = new Date(toParts[2], toParts[1] - 1, toParts[0]); - - // Adjust startDate to include the day before the selected fromDate - startDate.setDate(startDate.getDate() - 1); - - // Ensure endDate includes the entire end date by setting time to the end of the day - endDate.setHours(23, 59, 59, 999); - - // Get the date from the DataTable row (assuming it's in the first column in dd-mm-yyyy format) - var dateStr = data[0]; - var dateParts = dateStr.split("-"); - var rowDate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); - - // Return true if the row date is within the range - return rowDate >= startDate && rowDate <= endDate; - } - ); - - // Handle form submission for the date range filter - $("#DateRangeFilter").submit(function(e) { - e.preventDefault(); - table.draw(); // Redraw the table to apply the filter - }); // Reset button functionality $("#resetButton").click(function() {