diff options
Diffstat (limited to 'interface')
| -rw-r--r-- | interface/controllers/transactions.controller.js | 65 | ||||
| -rw-r--r-- | interface/public/beneficiaries.js | 6 | ||||
| -rw-r--r-- | interface/public/citizens.js | 4 | ||||
| -rw-r--r-- | interface/routes/index.js | 115 | ||||
| -rw-r--r-- | interface/routes/transactions.js | 85 | ||||
| -rw-r--r-- | interface/views/agriculture.ejs | 198 | ||||
| -rw-r--r-- | interface/views/hospital.ejs | 198 | ||||
| -rw-r--r-- | interface/views/lpg.ejs | 198 | ||||
| -rw-r--r-- | interface/views/nregs.ejs | 196 | ||||
| -rw-r--r-- | interface/views/partials/navbar.ejs | 18 | ||||
| -rw-r--r-- | interface/views/pension.ejs | 196 |
11 files changed, 1219 insertions, 60 deletions
diff --git a/interface/controllers/transactions.controller.js b/interface/controllers/transactions.controller.js new file mode 100644 index 0000000..2627a0f --- /dev/null +++ b/interface/controllers/transactions.controller.js @@ -0,0 +1,65 @@ +const {QueryTypes} = require('sequelize'); +const { sequelize } = require("../models"); + +const getAgricultureTransactions = (limit, offset) => { + const query = `SELECT * FROM getAggricultureDetails() limit ${limit} offset ${offset};`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getAgricultureTransactionsCount = () => { + const query = `SELECT count(*) as count FROM getAggricultureDetails();`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getHospitalTransactions = (limit, offset) => { + const query = `SELECT * FROM getHospitalDetails() limit ${limit} offset ${offset};`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getHospitalTransactionsCount = () => { + const query = `SELECT count(*) as count FROM getHospitalDetails();`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getLPGTransactions = (limit, offset) => { + const query = `SELECT * FROM getLPGDetails() limit ${limit} offset ${offset};`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getLPGTransactionsCount = () => { + const query = `SELECT count(*) as count FROM getLPGDetails();`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getNREGSTransactions = (limit, offset) => { + const query = `SELECT * FROM getNREGSDetails() limit ${limit} offset ${offset};`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getNREGSTransactionsCount = () => { + const query = `SELECT count(*) as count FROM getNREGSDetails();`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getPensionTransactions = (limit, offset) => { + const query = `SELECT * FROM getPensionDetails() limit ${limit} offset ${offset};`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +const getPensionTransactionsCount = () => { + const query = `SELECT count(*) as count FROM getPensionDetails();`; + return sequelize.query(query, { type: QueryTypes.SELECT }) +} + +module.exports = { + getAgricultureTransactions, + getAgricultureTransactionsCount, + getHospitalTransactions, + getHospitalTransactionsCount, + getLPGTransactions, + getLPGTransactionsCount, + getNREGSTransactions, + getNREGSTransactionsCount, + getPensionTransactions, + getPensionTransactionsCount +} diff --git a/interface/public/beneficiaries.js b/interface/public/beneficiaries.js index 4db118e..3b35e53 100644 --- a/interface/public/beneficiaries.js +++ b/interface/public/beneficiaries.js @@ -2,20 +2,20 @@ const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const page = urlParams.get("page") || 1; -const limit = urlParams.get("limit") || 10; +const limit = urlParams.get("limit") || 100; const numberOfPages = Math.ceil(count / limit); const pagination = $(".pagination"); const pageLeft = $('#pageLeft'); const pageRight = $('#pageRight'); if (page > 1) { pageLeft.removeClass("disabled"); - pageLeft.attr("href", `/beneficiaries?page=${page - 1}&limit=${limit}`); + pageLeft.attr("href", `/beneficiaries?page=${parseInt(page) - 1}&limit=${limit}`); } else { pageLeft.addClass("disabled"); } if (page < numberOfPages) { pageRight.removeClass("disabled"); - pageRight.attr("href", `/beneficiaries?page=${page + 1}&limit=${limit}`); + pageRight.attr("href", `/beneficiaries?page=${parseInt(page) + 1}&limit=${limit}`); } else { pageRight.addClass("disabled"); } diff --git a/interface/public/citizens.js b/interface/public/citizens.js index ebfcd74..8313765 100644 --- a/interface/public/citizens.js +++ b/interface/public/citizens.js @@ -18,13 +18,13 @@ const pageLeft = $('#pageLeft'); const pageRight = $('#pageRight'); if (page > 1) { pageLeft.removeClass("disabled"); - pageLeft.attr("href", `/citizens?page=${page - 1}&limit=${limit}`); + pageLeft.attr("href", `/citizens?page=${parseInt(page) - 1}&limit=${limit}`); } else { pageLeft.addClass("disabled"); } if (page < numberOfPages) { pageRight.removeClass("disabled"); - pageRight.attr("href", `/citizens?page=${page + 1}&limit=${limit}`); + pageRight.attr("href", `/citizens?page=${parseInt(page) + 1}&limit=${limit}`); } else { pageRight.addClass("disabled"); } diff --git a/interface/routes/index.js b/interface/routes/index.js index fd4a0d5..5b3ad05 100644 --- a/interface/routes/index.js +++ b/interface/routes/index.js @@ -1,70 +1,87 @@ const express = require("express"); const router = express.Router(); -const dashboardController = require('../controllers/dashboard.controller'); -const citizensController = require('../controllers/citizens.controller'); -const api = require('./api'); -const citizensAPI = require('./api/citizens'); -const geographyAPI = require('./api/geography'); +const dashboardController = require("../controllers/dashboard.controller"); +const citizensController = require("../controllers/citizens.controller"); +const api = require("./api"); +const citizensAPI = require("./api/citizens"); +const geographyAPI = require("./api/geography"); +const transactionsRoute = require("./transactions"); // Setup api routes -router.use('/api', api); -router.use('/api/citizens', citizensAPI); -router.use('/api/geography', geographyAPI); +router.use("/api", api); +router.use("/api/citizens", citizensAPI); +router.use("/api/geography", geographyAPI); +router.use("/transactions", transactionsRoute); - -router.get('/', (req, res) => { - Promise.all([dashboardController.genderDist(), dashboardController.ageDist(), dashboardController.casteDist(), - dashboardController.maritalDist(), dashboardController.disablePercentage(), dashboardController.citizensByDistrict()]).then(results => { - const [genderDist, ageDist, casteDist, maritalDist, disableDist, citizenDist] = results; - res.render('index', { - title: 'Home Page', - genderDist, - ageDist, - casteDist, - maritalDist, - disableDist, - citizenDist - }); +router.get("/", (req, res) => { + Promise.all([ + dashboardController.genderDist(), + dashboardController.ageDist(), + dashboardController.casteDist(), + dashboardController.maritalDist(), + dashboardController.disablePercentage(), + dashboardController.citizensByDistrict(), + ]).then((results) => { + const [ + genderDist, + ageDist, + casteDist, + maritalDist, + disableDist, + citizenDist, + ] = results; + res.render("index", { + title: "Home Page", + genderDist, + ageDist, + casteDist, + maritalDist, + disableDist, + citizenDist, }); + }); }); router.get("/citizens", (req, res) => { - // Get the limit and offset from the query string - const limit = parseInt(req.query.limit, 10) || 10; - const page = req.query.page ? (req.query.page - 1) * limit : 0; + // Get the limit and offset from the query string + const limit = parseInt(req.query.limit, 10) || 10; + const page = req.query.page ? (req.query.page - 1) * limit : 0; - // Get the citizens from the database - Promise.all([citizensController.findXCitizens(limit, page), citizensController.getCountOfCitizens()]).then(results => { - const [citizens, count] = results; - res.render('citizens', { - title: 'Citizens', - citizens, - count: count[0].count, - }); + // Get the citizens from the database + Promise.all([ + citizensController.findXCitizens(limit, page), + citizensController.getCountOfCitizens(), + ]).then((results) => { + const [citizens, count] = results; + res.render("citizens", { + title: "Citizens", + citizens, + count: count[0].count, }); + }); }); - router.get("/addUser", (req, res) => { - res.render("addUser", { - title: "Add User" - }); - } -); + res.render("addUser", { + title: "Add User", + }); +}); router.get("/beneficiaries", (req, res) => { - const limit = parseInt(req.query.limit, 10) || 100; - const page = req.query.page ? (req.query.page - 1) * limit : 0; - Promise.all([citizensController.getBeneficiaries(limit, page), citizensController.getCountOfCitizens()]).then(results => { - const [beneficiaries, count] = results; - res.render('beneficiaries', { - title: 'Beneficiaries', - beneficiaries, - count: count[0].count, - }); + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + citizensController.getBeneficiaries(limit, page), + citizensController.getCountOfCitizens(), + ]).then((results) => { + const [beneficiaries, count] = results; + res.render("beneficiaries", { + title: "Beneficiaries", + beneficiaries, + count: count[0].count, }); + }); }); - // export the router module.exports = router; diff --git a/interface/routes/transactions.js b/interface/routes/transactions.js new file mode 100644 index 0000000..751cc32 --- /dev/null +++ b/interface/routes/transactions.js @@ -0,0 +1,85 @@ +const express = require("express"); +const router = express.Router(); +const transactionsController = require("../controllers/transactions.controller"); + +router.get("/agriculture", (req, res) => { + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + transactionsController.getAgricultureTransactions(limit, page), + transactionsController.getAgricultureTransactionsCount(), + ]).then((results) => { + const [transactions, count] = results; + res.render("agriculture", { + title: "Agriculture Transactions", + transactions, + count: count[0].count, + }); + }); +}); + +router.get("/hospital", (req, res) => { + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + transactionsController.getHospitalTransactions(limit, page), + transactionsController.getHospitalTransactionsCount(), + ]).then((results) => { + const [transactions, count] = results; + res.render("hospital", { + title: "Hospital Transactions", + transactions, + count: count[0].count, + }); + }); +}); + +router.get("/lpg", (req, res) => { + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + transactionsController.getLPGTransactions(limit, page), + transactionsController.getLPGTransactionsCount(), + ]).then((results) => { + const [transactions, count] = results; + res.render("lpg", { + title: "LPG Transactions", + transactions, + count: count[0].count, + }); + }); +}); + +router.get("/nregs", (req, res) => { + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + transactionsController.getNREGSTransactions(limit, page), + transactionsController.getNREGSTransactionsCount(), + ]).then((results) => { + const [transactions, count] = results; + res.render("nregs", { + title: "NREGS Transactions", + transactions, + count: count[0].count, + }); + }); +}); + +router.get("/pension", (req, res) => { + const limit = parseInt(req.query.limit, 10) || 100; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + Promise.all([ + transactionsController.getPensionTransactions(limit, page), + transactionsController.getPensionTransactionsCount(), + ]).then((results) => { + const [transactions, count] = results; + res.render("pension", { + title: "Pension Transactions", + transactions, + count: count[0].count, + }); + }); +}); + +module.exports = router; diff --git a/interface/views/agriculture.ejs b/interface/views/agriculture.ejs new file mode 100644 index 0000000..95e3052 --- /dev/null +++ b/interface/views/agriculture.ejs @@ -0,0 +1,198 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <%- include('partials/head') %> + <style> + .ui.menu { + margin-top: 0; + } + .scrollY { + max-height: calc(100vh - 8rem); + margin-top: 1rem; + overflow-y: scroll; + } + .ui.table thead tr:first-child > th { + position: sticky !important; + top: 0; + z-index: 2; + } + .ui.table tfoot tr:first-child > th { + position: sticky !important; + bottom: 0; + z-index: 2; + } + </style> + </head> + + <body> + <%- include('partials/navbar') %> + + <!-- Drop down for selecting limit --> + + <div class="ui container"> + <div class="ui floating labeled icon dropdown button"> + <i class="list icon"></i> + <span class="text">Items</span> + <div class="menu"> + <div class="item" onclick="redirectToLimit(100)">100</div> + <div class="item" onclick="redirectToLimit(250)">250</div> + <div class="item" onclick="redirectToLimit(500)">500</div> + <div class="item" onclick="redirectToLimit(1000)">1000</div> + </div> + </div> + </div> + + <div class="scrollY"> + <table class="ui selectable table"> + <thead> + <tr> + <th>First Name</th> + <th>Last Name</th> + <th>Amount Remitted</th> + <th>Crop</th> + <th>Disbursed Date</th> + </tr> + </thead> + <tbody> + <% for(var i=0; i < transactions.length; i++) { %> + <tr> + <td><%= transactions[i].first_name %></td> + <td><%= transactions[i].last_name %></td> + <td><%= transactions[i].amount_remitted %></td> + <td><%= transactions[i].crop %></td> + <td><%= transactions[i].disbursed_date %></td> + <% } %> + </tr> + </tbody> + + <!-- Display a pagination --> + <tfoot> + <tr> + <th colspan="9"> + <div class="ui right floated pagination menu"> + <a class="icon item" id="pageLeft"> + <i class="left chevron disabled icon"></i> + </a> + + <a class="icon item" id="pageRight"> + <i class="right chevron disabled icon"></i> + </a> + </div> + </th> + </tr> + </tfoot> + </table> + </div> + </body> + <%- include('partials/scripts') %> + <script> + const count = "<%= count %>"; + </script> + <script> + // Get current page and limit query parameter + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const page = urlParams.get("page") || 1; + const limit = urlParams.get("limit") || 100; + const numberOfPages = Math.ceil(count / limit); + const pagination = $(".pagination"); + const pageLeft = $("#pageLeft"); + const pageRight = $("#pageRight"); + if (page > 1) { + pageLeft.removeClass("disabled"); + pageLeft.attr( + "href", + `/transactions/agriculture?page=${parseInt(page) - 1}&limit=${limit}` + ); + } else { + pageLeft.addClass("disabled"); + } + if (page < numberOfPages) { + pageRight.removeClass("disabled"); + pageRight.attr( + "href", + `/transactions/agriculture?page=${parseInt(page) + 1}&limit=${limit}` + ); + } else { + pageRight.addClass("disabled"); + } + + function redirectToLimit(limit) { + window.location.href = `/transactions/agriculture?page=1&limit=${limit}`; + } + + addPageNumbers(numberOfPages); + + function addPageNumbers(numberOfPages) { + // Add page numbers from current page to 2 pages before and 2 pages after, if there are more than 5 pages + if (numberOfPages > 5) { + let startingPoint = page - 2; + if (page < 3) { + startingPoint = 1; + } else if (page > numberOfPages - 2) { + startingPoint = numberOfPages - 4; + } else { + startingPoint = page - 2; + } + for (let i = startingPoint; i < startingPoint + 5; i++) { + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/agriculture?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + // add dots + const dots = document.createElement("a"); + dots.innerHTML = "..."; + dots.classList.add("item"); + pageRight.before(dots); + + // add first page if page > 3 + if (page > 3) { + const firstPage = document.createElement("a"); + firstPage.innerHTML = 1; + firstPage.setAttribute( + "href", + `/transactions/agriculture?page=1&limit=${limit}` + ); + firstPage.setAttribute("id", `page1`); + firstPage.classList.add("item"); + pageLeft.after(dots); + pageLeft.after(firstPage); + } + + // add last page + if (page != numberOfPages) { + const lastPage = document.createElement("a"); + lastPage.innerHTML = numberOfPages; + lastPage.setAttribute( + "href", + `/transactions/agriculture?page=${numberOfPages}&limit=${limit}` + ); + lastPage.classList.add("item"); + pageRight.before(lastPage); + } + } else { + // add page numbers + for (let i = 1; i <= numberOfPages; i++) { + // Insert before pageRight + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/agriculture?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + } + const currentPageElement = document.getElementById(`page${page}`); + currentPageElement.classList.add("active"); + } + </script> +</html> diff --git a/interface/views/hospital.ejs b/interface/views/hospital.ejs new file mode 100644 index 0000000..962c742 --- /dev/null +++ b/interface/views/hospital.ejs @@ -0,0 +1,198 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <%- include('partials/head') %> + <style> + .ui.menu { + margin-top: 0; + } + .scrollY { + max-height: calc(100vh - 8rem); + margin-top: 1rem; + overflow-y: scroll; + } + .ui.table thead tr:first-child > th { + position: sticky !important; + top: 0; + z-index: 2; + } + .ui.table tfoot tr:first-child > th { + position: sticky !important; + bottom: 0; + z-index: 2; + } + </style> + </head> + + <body> + <%- include('partials/navbar') %> + + <!-- Drop down for selecting limit --> + + <div class="ui container"> + <div class="ui floating labeled icon dropdown button"> + <i class="list icon"></i> + <span class="text">Items</span> + <div class="menu"> + <div class="item" onclick="redirectToLimit(100)">100</div> + <div class="item" onclick="redirectToLimit(250)">250</div> + <div class="item" onclick="redirectToLimit(500)">500</div> + <div class="item" onclick="redirectToLimit(1000)">1000</div> + </div> + </div> + </div> + + <div class="scrollY"> + <table class="ui selectable table"> + <thead> + <tr> + <th>First Name</th> + <th>Last Name</th> + <th>Disease Category</th> + <th>Disease Sub Category</th> + <th>Amount Charged</th> + </tr> + </thead> + <tbody> + <% for(var i=0; i < transactions.length; i++) { %> + <tr> + <td><%= transactions[i].first_name %></td> + <td><%= transactions[i].last_name %></td> + <td><%= transactions[i].disease_category %></td> + <td><%= transactions[i].disease_sub_category %></td> + <td><%= transactions[i].amount_charged %></td> + <% } %> + </tr> + </tbody> + + <!-- Display a pagination --> + <tfoot> + <tr> + <th colspan="9"> + <div class="ui right floated pagination menu"> + <a class="icon item" id="pageLeft"> + <i class="left chevron disabled icon"></i> + </a> + + <a class="icon item" id="pageRight"> + <i class="right chevron disabled icon"></i> + </a> + </div> + </th> + </tr> + </tfoot> + </table> + </div> + </body> + <%- include('partials/scripts') %> + <script> + const count = "<%= count %>"; + </script> + <script> + // Get current page and limit query parameter + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const page = urlParams.get("page") || 1; + const limit = urlParams.get("limit") || 100; + const numberOfPages = Math.ceil(count / limit); + const pagination = $(".pagination"); + const pageLeft = $("#pageLeft"); + const pageRight = $("#pageRight"); + if (page > 1) { + pageLeft.removeClass("disabled"); + pageLeft.attr( + "href", + `/transactions/hospital?page=${parseInt(page) - 1}&limit=${limit}` + ); + } else { + pageLeft.addClass("disabled"); + } + if (page < numberOfPages) { + pageRight.removeClass("disabled"); + pageRight.attr( + "href", + `/transactions/hospital?page=${parseInt(page) + 1}&limit=${limit}` + ); + } else { + pageRight.addClass("disabled"); + } + + function redirectToLimit(limit) { + window.location.href = `/transactions/hospital?page=1&limit=${limit}`; + } + + addPageNumbers(numberOfPages); + + function addPageNumbers(numberOfPages) { + // Add page numbers from current page to 2 pages before and 2 pages after, if there are more than 5 pages + if (numberOfPages > 5) { + let startingPoint = page - 2; + if (page < 3) { + startingPoint = 1; + } else if (page > numberOfPages - 2) { + startingPoint = numberOfPages - 4; + } else { + startingPoint = page - 2; + } + for (let i = startingPoint; i < startingPoint + 5; i++) { + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/hospital?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + // add dots + const dots = document.createElement("a"); + dots.innerHTML = "..."; + dots.classList.add("item"); + pageRight.before(dots); + + // add first page if page > 3 + if (page > 3) { + const firstPage = document.createElement("a"); + firstPage.innerHTML = 1; + firstPage.setAttribute( + "href", + `/transactions/hospital?page=1&limit=${limit}` + ); + firstPage.setAttribute("id", `page1`); + firstPage.classList.add("item"); + pageLeft.after(dots); + pageLeft.after(firstPage); + } + + // add last page + if (page != numberOfPages) { + const lastPage = document.createElement("a"); + lastPage.innerHTML = numberOfPages; + lastPage.setAttribute( + "href", + `/transactions/hospital?page=${numberOfPages}&limit=${limit}` + ); + lastPage.classList.add("item"); + pageRight.before(lastPage); + } + } else { + // add page numbers + for (let i = 1; i <= numberOfPages; i++) { + // Insert before pageRight + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/hospital?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + } + const currentPageElement = document.getElementById(`page${page}`); + currentPageElement.classList.add("active"); + } + </script> +</html> diff --git a/interface/views/lpg.ejs b/interface/views/lpg.ejs new file mode 100644 index 0000000..b91954f --- /dev/null +++ b/interface/views/lpg.ejs @@ -0,0 +1,198 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <%- include('partials/head') %> + <style> + .ui.menu { + margin-top: 0; + } + .scrollY { + max-height: calc(100vh - 8rem); + margin-top: 1rem; + overflow-y: scroll; + } + .ui.table thead tr:first-child > th { + position: sticky !important; + top: 0; + z-index: 2; + } + .ui.table tfoot tr:first-child > th { + position: sticky !important; + bottom: 0; + z-index: 2; + } + </style> + </head> + + <body> + <%- include('partials/navbar') %> + + <!-- Drop down for selecting limit --> + + <div class="ui container"> + <div class="ui floating labeled icon dropdown button"> + <i class="list icon"></i> + <span class="text">Items</span> + <div class="menu"> + <div class="item" onclick="redirectToLimit(100)">100</div> + <div class="item" onclick="redirectToLimit(250)">250</div> + <div class="item" onclick="redirectToLimit(500)">500</div> + <div class="item" onclick="redirectToLimit(1000)">1000</div> + </div> + </div> + </div> + + <div class="scrollY"> + <table class="ui selectable table"> + <thead> + <tr> + <th>First Name</th> + <th>Last Name</th> + <th>Booking Date</th> + <th>Amount Paid</th> + <th>Amount Remitted</th> + </tr> + </thead> + <tbody> + <% for(var i=0; i < transactions.length; i++) { %> + <tr> + <td><%= transactions[i].first_name %></td> + <td><%= transactions[i].last_name %></td> + <td><%= transactions[i].booking_date %></td> + <td><%= transactions[i].amount_paid %></td> + <td><%= transactions[i].amount_remitted %></td> + <% } %> + </tr> + </tbody> + + <!-- Display a pagination --> + <tfoot> + <tr> + <th colspan="9"> + <div class="ui right floated pagination menu"> + <a class="icon item" id="pageLeft"> + <i class="left chevron disabled icon"></i> + </a> + + <a class="icon item" id="pageRight"> + <i class="right chevron disabled icon"></i> + </a> + </div> + </th> + </tr> + </tfoot> + </table> + </div> + </body> + <%- include('partials/scripts') %> + <script> + const count = "<%= count %>"; + </script> + <script> + // Get current page and limit query parameter + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const page = urlParams.get("page") || 1; + const limit = urlParams.get("limit") || 100; + const numberOfPages = Math.ceil(count / limit); + const pagination = $(".pagination"); + const pageLeft = $("#pageLeft"); + const pageRight = $("#pageRight"); + if (page > 1) { + pageLeft.removeClass("disabled"); + pageLeft.attr( + "href", + `/transactions/lpg?page=${parseInt(page) - 1}&limit=${limit}` + ); + } else { + pageLeft.addClass("disabled"); + } + if (page < numberOfPages) { + pageRight.removeClass("disabled"); + pageRight.attr( + "href", + `/transactions/lpg?page=${parseInt(page) + 1}&limit=${limit}` + ); + } else { + pageRight.addClass("disabled"); + } + + function redirectToLimit(limit) { + window.location.href = `/transactions/lpg?page=1&limit=${limit}`; + } + + addPageNumbers(numberOfPages); + + function addPageNumbers(numberOfPages) { + // Add page numbers from current page to 2 pages before and 2 pages after, if there are more than 5 pages + if (numberOfPages > 5) { + let startingPoint = page - 2; + if (page < 3) { + startingPoint = 1; + } else if (page > numberOfPages - 2) { + startingPoint = numberOfPages - 4; + } else { + startingPoint = page - 2; + } + for (let i = startingPoint; i < startingPoint + 5; i++) { + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/lpg?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + // add dots + const dots = document.createElement("a"); + dots.innerHTML = "..."; + dots.classList.add("item"); + pageRight.before(dots); + + // add first page if page > 3 + if (page > 3) { + const firstPage = document.createElement("a"); + firstPage.innerHTML = 1; + firstPage.setAttribute( + "href", + `/transactions/lpg?page=1&limit=${limit}` + ); + firstPage.setAttribute("id", `page1`); + firstPage.classList.add("item"); + pageLeft.after(dots); + pageLeft.after(firstPage); + } + + // add last page + if (page != numberOfPages) { + const lastPage = document.createElement("a"); + lastPage.innerHTML = numberOfPages; + lastPage.setAttribute( + "href", + `/transactions/lpg?page=${numberOfPages}&limit=${limit}` + ); + lastPage.classList.add("item"); + pageRight.before(lastPage); + } + } else { + // add page numbers + for (let i = 1; i <= numberOfPages; i++) { + // Insert before pageRight + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/lpg?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + } + const currentPageElement = document.getElementById(`page${page}`); + currentPageElement.classList.add("active"); + } + </script> +</html> diff --git a/interface/views/nregs.ejs b/interface/views/nregs.ejs new file mode 100644 index 0000000..dd2a20d --- /dev/null +++ b/interface/views/nregs.ejs @@ -0,0 +1,196 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <%- include('partials/head') %> + <style> + .ui.menu { + margin-top: 0; + } + .scrollY { + max-height: calc(100vh - 8rem); + margin-top: 1rem; + overflow-y: scroll; + } + .ui.table thead tr:first-child > th { + position: sticky !important; + top: 0; + z-index: 2; + } + .ui.table tfoot tr:first-child > th { + position: sticky !important; + bottom: 0; + z-index: 2; + } + </style> + </head> + + <body> + <%- include('partials/navbar') %> + + <!-- Drop down for selecting limit --> + + <div class="ui container"> + <div class="ui floating labeled icon dropdown button"> + <i class="list icon"></i> + <span class="text">Items</span> + <div class="menu"> + <div class="item" onclick="redirectToLimit(100)">100</div> + <div class="item" onclick="redirectToLimit(250)">250</div> + <div class="item" onclick="redirectToLimit(500)">500</div> + <div class="item" onclick="redirectToLimit(1000)">1000</div> + </div> + </div> + </div> + + <div class="scrollY"> + <table class="ui selectable table"> + <thead> + <tr> + <th>First Name</th> + <th>Last Name</th> + <th>Days Attended</th> + <th>Amount Remitted</th> + </tr> + </thead> + <tbody> + <% for(var i=0; i < transactions.length; i++) { %> + <tr> + <td><%= transactions[i].first_name %></td> + <td><%= transactions[i].last_name %></td> + <td><%= transactions[i].days_of_attended %></td> + <td><%= transactions[i].amount_remitted %></td> + <% } %> + </tr> + </tbody> + + <!-- Display a pagination --> + <tfoot> + <tr> + <th colspan="9"> + <div class="ui right floated pagination menu"> + <a class="icon item" id="pageLeft"> + <i class="left chevron disabled icon"></i> + </a> + + <a class="icon item" id="pageRight"> + <i class="right chevron disabled icon"></i> + </a> + </div> + </th> + </tr> + </tfoot> + </table> + </div> + </body> + <%- include('partials/scripts') %> + <script> + const count = "<%= count %>"; + </script> + <script> + // Get current page and limit query parameter + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const page = urlParams.get("page") || 1; + const limit = urlParams.get("limit") || 100; + const numberOfPages = Math.ceil(count / limit); + const pagination = $(".pagination"); + const pageLeft = $("#pageLeft"); + const pageRight = $("#pageRight"); + if (page > 1) { + pageLeft.removeClass("disabled"); + pageLeft.attr( + "href", + `/transactions/nregs?page=${parseInt(page) - 1}&limit=${limit}` + ); + } else { + pageLeft.addClass("disabled"); + } + if (page < numberOfPages) { + pageRight.removeClass("disabled"); + pageRight.attr( + "href", + `/transactions/nregs?page=${parseInt(page) + 1}&limit=${limit}` + ); + } else { + pageRight.addClass("disabled"); + } + + function redirectToLimit(limit) { + window.location.href = `/transactions/nregs?page=1&limit=${limit}`; + } + + addPageNumbers(numberOfPages); + + function addPageNumbers(numberOfPages) { + // Add page numbers from current page to 2 pages before and 2 pages after, if there are more than 5 pages + if (numberOfPages > 5) { + let startingPoint = page - 2; + if (page < 3) { + startingPoint = 1; + } else if (page > numberOfPages - 2) { + startingPoint = numberOfPages - 4; + } else { + startingPoint = page - 2; + } + for (let i = startingPoint; i < startingPoint + 5; i++) { + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/nregs?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + // add dots + const dots = document.createElement("a"); + dots.innerHTML = "..."; + dots.classList.add("item"); + pageRight.before(dots); + + // add first page if page > 3 + if (page > 3) { + const firstPage = document.createElement("a"); + firstPage.innerHTML = 1; + firstPage.setAttribute( + "href", + `/transactions/nregs?page=1&limit=${limit}` + ); + firstPage.setAttribute("id", `page1`); + firstPage.classList.add("item"); + pageLeft.after(dots); + pageLeft.after(firstPage); + } + + // add last page + if (page != numberOfPages) { + const lastPage = document.createElement("a"); + lastPage.innerHTML = numberOfPages; + lastPage.setAttribute( + "href", + `/transactions/nregs?page=${numberOfPages}&limit=${limit}` + ); + lastPage.classList.add("item"); + pageRight.before(lastPage); + } + } else { + // add page numbers + for (let i = 1; i <= numberOfPages; i++) { + // Insert before pageRight + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/nregs?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + } + const currentPageElement = document.getElementById(`page${page}`); + currentPageElement.classList.add("active"); + } + </script> +</html> diff --git a/interface/views/partials/navbar.ejs b/interface/views/partials/navbar.ejs index 30289d2..816244f 100644 --- a/interface/views/partials/navbar.ejs +++ b/interface/views/partials/navbar.ejs @@ -33,17 +33,23 @@ <i class="dropdown icon"></i> <span class="text">Transactions</span> <div class="menu"> - <div class="item">Agricultural</div> - <div class="item">Hospital</div> - <div class="item">LPG</div> - <div class="item">NRegs</div> - <div class="item">Pension</div> + <div class="item" onclick="route('/transactions/agriculture')"> + Agricultural + </div> + <div class="item" onclick="route('/transactions/hospital')"> + Hospital + </div> + <div class="item" onclick="route('/transactions/lpg')">LPG</div> + <div class="item" onclick="route('/transactions/nregs')">NRegs</div> + <div class="item" onclick="route('/transactions/pension')">Pension</div> </div> </div> </div> </div> - <a class="item" onclick="route('beneficiaries')"> Scheme Wise Beneficiaries </a> + <a class="item" onclick="route('beneficiaries')"> + Scheme Wise Beneficiaries + </a> <a class="item" onclick="route('addUser')"> Add User </a> <div class="right menu"> diff --git a/interface/views/pension.ejs b/interface/views/pension.ejs new file mode 100644 index 0000000..8cab043 --- /dev/null +++ b/interface/views/pension.ejs @@ -0,0 +1,196 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <%- include('partials/head') %> + <style> + .ui.menu { + margin-top: 0; + } + .scrollY { + max-height: calc(100vh - 8rem); + margin-top: 1rem; + overflow-y: scroll; + } + .ui.table thead tr:first-child > th { + position: sticky !important; + top: 0; + z-index: 2; + } + .ui.table tfoot tr:first-child > th { + position: sticky !important; + bottom: 0; + z-index: 2; + } + </style> + </head> + + <body> + <%- include('partials/navbar') %> + + <!-- Drop down for selecting limit --> + + <div class="ui container"> + <div class="ui floating labeled icon dropdown button"> + <i class="list icon"></i> + <span class="text">Items</span> + <div class="menu"> + <div class="item" onclick="redirectToLimit(100)">100</div> + <div class="item" onclick="redirectToLimit(250)">250</div> + <div class="item" onclick="redirectToLimit(500)">500</div> + <div class="item" onclick="redirectToLimit(1000)">1000</div> + </div> + </div> + </div> + + <div class="scrollY"> + <table class="ui selectable table"> + <thead> + <tr> + <th>First Name</th> + <th>Last Name</th> + <th>Date of Disbursement</th> + <th>Pension Amount</th> + </tr> + </thead> + <tbody> + <% for(var i=0; i < transactions.length; i++) { %> + <tr> + <td><%= transactions[i].first_name %></td> + <td><%= transactions[i].last_name %></td> + <td><%= transactions[i].pen_date_disbursment %></td> + <td><%= transactions[i].pen_amount %></td> + <% } %> + </tr> + </tbody> + + <!-- Display a pagination --> + <tfoot> + <tr> + <th colspan="9"> + <div class="ui right floated pagination menu"> + <a class="icon item" id="pageLeft"> + <i class="left chevron disabled icon"></i> + </a> + + <a class="icon item" id="pageRight"> + <i class="right chevron disabled icon"></i> + </a> + </div> + </th> + </tr> + </tfoot> + </table> + </div> + </body> + <%- include('partials/scripts') %> + <script> + const count = "<%= count %>"; + </script> + <script> + // Get current page and limit query parameter + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const page = urlParams.get("page") || 1; + const limit = urlParams.get("limit") || 100; + const numberOfPages = Math.ceil(count / limit); + const pagination = $(".pagination"); + const pageLeft = $("#pageLeft"); + const pageRight = $("#pageRight"); + if (page > 1) { + pageLeft.removeClass("disabled"); + pageLeft.attr( + "href", + `/transactions/pension?page=${parseInt(page) - 1}&limit=${limit}` + ); + } else { + pageLeft.addClass("disabled"); + } + if (page < numberOfPages) { + pageRight.removeClass("disabled"); + pageRight.attr( + "href", + `/transactions/pension?page=${parseInt(page) + 1}&limit=${limit}` + ); + } else { + pageRight.addClass("disabled"); + } + + function redirectToLimit(limit) { + window.location.href = `/transactions/pension?page=1&limit=${limit}`; + } + + addPageNumbers(numberOfPages); + + function addPageNumbers(numberOfPages) { + // Add page numbers from current page to 2 pages before and 2 pages after, if there are more than 5 pages + if (numberOfPages > 5) { + let startingPoint = page - 2; + if (page < 3) { + startingPoint = 1; + } else if (page > numberOfPages - 2) { + startingPoint = numberOfPages - 4; + } else { + startingPoint = page - 2; + } + for (let i = startingPoint; i < startingPoint + 5; i++) { + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/pension?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + // add dots + const dots = document.createElement("a"); + dots.innerHTML = "..."; + dots.classList.add("item"); + pageRight.before(dots); + + // add first page if page > 3 + if (page > 3) { + const firstPage = document.createElement("a"); + firstPage.innerHTML = 1; + firstPage.setAttribute( + "href", + `/transactions/pension?page=1&limit=${limit}` + ); + firstPage.setAttribute("id", `page1`); + firstPage.classList.add("item"); + pageLeft.after(dots); + pageLeft.after(firstPage); + } + + // add last page + if (page != numberOfPages) { + const lastPage = document.createElement("a"); + lastPage.innerHTML = numberOfPages; + lastPage.setAttribute( + "href", + `/transactions/pension?page=${numberOfPages}&limit=${limit}` + ); + lastPage.classList.add("item"); + pageRight.before(lastPage); + } + } else { + // add page numbers + for (let i = 1; i <= numberOfPages; i++) { + // Insert before pageRight + const linkElement = document.createElement("a"); + linkElement.innerHTML = i; + linkElement.setAttribute( + "href", + `/transactions/pension?page=${i}&limit=${limit}` + ); + linkElement.setAttribute("id", `page${i}`); + linkElement.classList.add("item"); + pageRight.before(linkElement); + } + } + const currentPageElement = document.getElementById(`page${page}`); + currentPageElement.classList.add("active"); + } + </script> +</html> |
