Skip to content

Commit

Permalink
Bank can query through time
Browse files Browse the repository at this point in the history
  • Loading branch information
Vuthy committed Sep 7, 2019
1 parent a244362 commit 530ccad
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
29 changes: 25 additions & 4 deletions routes/catering.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var moment = require('moment');

module.exports.set = function(router, pool) {
router.get('/section/:section', Section.isSection(['catering', 'maintenance', 'utilities', 'residence']), (req, res) => {
res.redirect('/section/'+ req.params.section + '/overview');
res.redirect('/section/'+ req.params.section + '/overview/');
});

router.get('/section/:section/transfer_logs', Section.isSection(['catering', 'maintenance', 'utilities', 'residence']), ensureLoggedIn, User.isRole('admin', 'maintenance_manager', 'catering_manager','re'), (req, res) => {
Expand Down Expand Up @@ -112,12 +112,29 @@ module.exports.set = function(router, pool) {

router.get('/section/:section/overview', Section.isSection(['catering', 'maintenance', 'utilities', 'residence']), ensureLoggedIn, User.isRole('admin', 'maintenance_manager', 'catering_manager','re'), (req, res) => {
var section = req.params.section;

//Default query
var query = {
after: moment('01-01-2019', 'DD-MM-YYYY').unix(), //01-01-2019
before: moment().unix() //today
}

if (req.query.after) {
query.after = moment(req.query.after, "DD-MM-YYYY").unix();
}

if (req.query.before) {
query.before = moment(req.query.before, "DD-MM-YYYY").unix();
}

console.log(query.after)
var sectionEmail = req.params.section + "@ligercambodia.org";

var selectCatering = {
text: "SELECT budget FROM account WHERE email = $1;",
values: [sectionEmail]
}

var bankBudget;
pool.query(selectCatering, (err, result) => {
if(err) {return res.send(err)}
Expand Down Expand Up @@ -148,19 +165,23 @@ module.exports.set = function(router, pool) {
FROM transfer_logs \
JOIN (SELECT email, username, CASE WHEN role != 'apartment' THEN null ELSE username END AS apartment FROM account) AS account \
ON (transfer_logs.sender = account.email) \
WHERE transfer_logs.recipient = $1 \
WHERE transfer_logs.recipient = $1 AND (timestamp > $2 AND timestamp < $3) \
GROUP BY account.apartment ORDER BY account.apartment;",
values: [sectionEmail]
values: [sectionEmail, query.after, query.before]
}

pool.query(select, (err, result) => {
if (err) {res.send(err)}
else {
console.log("My Before is this: ", moment.unix(query.before).format("DD-MM-YYYY"))
res.render('overview', {bankName: section.toUpperCase(),
sectionName: section,
bankBudget: bankBudget,
apartmentData: result.rows,
recentTransfer: recentTransferData,
userData: req.user})
userData: req.user,
before: moment.unix(query.before).format("DD-MM-YYYY"),
after: moment.unix(query.after).format("DD-MM-YYYY")})
}
})

Expand Down
27 changes: 27 additions & 0 deletions views/overview.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ body {
</div>
{{/ifCondA}}
</div>
<div class="row">
<form action="/section/{{sectionName}}/overview" method="get">
<div class="input-field col l4 ">
<i class="material-icons prefix">date_range</i>
<input type="date" value={{after}} name="after" id="after" class="datepicker">
<label for="after">After</label>
</div>
<div class="input-field col l4 ">
<i class="material-icons prefix">date_range</i>
<input type="date" value={{before}} name="before" id="before" class="datepicker" required="required">
<label for="before">Before</label>
</div>
<div class="col l4 m4 s8 ">
<input type="submit" class="btn blue submit-button">
</div>
</form>
</div>
<div class="row">
{{#each apartmentData}}
<div class="col l4 m6 s12">
Expand All @@ -59,3 +76,13 @@ body {
</div>
</div>
</main>

<script type="text/javascript">
$('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 10, // Creates a dropdown of 15 years to control year
firstDay: 1,
format: 'dd-mm-yyyy'
});
</script>
37 changes: 37 additions & 0 deletions views/partials/dashboardSideNav.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@
</style>

<header>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- jquery has to go first. -->
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>

<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.99.0/css/materialize.min.css">

<link rel="stylesheet" type="text/css" href="/css/new_main.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.99.0/js/materialize.min.js"></script>

<!-- Icons -->
<link rel="icon" type="image/png" sizes="192x192" href="../img/pedroFile/pedro_logo.png">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<!-- typeIt -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery.typeit/3.0.1/typeit.min.js"></script>

<!--validation-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.js"></script>

<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">

<!-- validate plugin
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>-->

<!-- Auto-filtering
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>-->

<!-- Auth0
<script src="https://cdn.auth0.com/w2/auth0-7.6.1.min.js"></script>-->

{{#with userData}}
<ul id="slide-out" class="side-nav fixed">
<li><div class="user-view">
Expand Down

0 comments on commit 530ccad

Please sign in to comment.