db->table('t_expense') ->select('serial_number') ->orderBy('id', 'DESC') ->limit(1) ->get() ->getRow('serial_number'); } // Retrieve all active expenses public function getAllExpense($fromDate,$toDate) { return $this->db->table('t_expense') ->select([ "t_expense.id","t_expense.serial_number","t_expense.transporter_file","t_expense.supplier_id","t_expense.item_description","t_expense.cost","t_expense.cgst","t_expense.sgst","t_expense.igst","t_expense.total","t_expense.remarks","t_expense.status","t_expense.payment_method","t_expense.created_on","t_expense.created_by","t_expense.updated_on","t_expense.updated_by","t_expense.isactive","t_expense.bill_no","t_expense.bill_date", "t_supplierdetailsn.SupplierName", "CONCAT_WS(' ', emp.FirstName, emp.LastName) as created_name" ]) ->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID', 'left') ->join('tbl_users as creator', ' t_expense.created_by = creator.userid', 'left') ->join('t_employee_details as emp', 'emp.empid=creator.empid', 'left') ->where('t_expense.isactive', 1) ->where('t_expense.created_on >=',"$fromDate") ->orderBy('t_expense.created_on', 'DESC') ->get()->getResult(); } // Insert new expense public function insertExpense($data) { return $this->insert($data) ? $this->insertID() : false; } // Get expense by ID public function getExpenseById($id) { return $this->where($this->primaryKey, $id)->first(); // Use primary key } // Update expense by ID public function updateExpense($id, $data) { return $this->update($id, $data); // Use primary key } public function deleteFile($expenseId) { // Update the database to set transporter_file to null return $this->update($expenseId, ['transporter_file' => null]); } } ?>