Skip to content

Commit

Permalink
ADD TotalBudget Display
Browse files Browse the repository at this point in the history
  • Loading branch information
Vuthy committed Aug 11, 2019
1 parent 9af518e commit 16625ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 9 additions & 2 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ module.exports.set = function(router, pool) {
})
});

router.get("/admin/user", ensureLoggedIn, User.isRole('admin'), (req, res) => {
router.get("/admin/user", ensureLoggedIn, User.isRole('admin'), async(req, res) => {
// Group account by apartment, sorted by username, all information from user turn into json then array aggreate


var totalBudget = await pool.query("SELECT sum(budget) as total_system_balance FROM account;");
totalBudget = totalBudget.rows[0].total_system_balance;

var query = {
text: " SELECT apartment, \
sum(budget) AS apartment_total_budget, \
array_agg(json_build_object(\
'username', username, \
'email', email, \
Expand All @@ -213,7 +219,8 @@ module.exports.set = function(router, pool) {
if (err) {res.send(err)}
else {
console.log(req.user)
res.render("admin/admin_user_profile", {user_info: result.rows, userData: req.user});
console.log(result.rows[0])
res.render("admin/admin_user_profile", {user_info: result.rows, userData: req.user, totalBudget: totalBudget});

}
})
Expand Down
22 changes: 17 additions & 5 deletions views/admin/admin_user_profile.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,35 @@
<div class="container" >
<br>
<div class="row zero-margin">
<div class="col l6">
<a class="waves-effect waves-light btn left blue"><i class="material-icons left">account_balance</i>Total balance: P{{totalBudget}}</a>
</div>
<div class="col l6">
<a href="#new" class="waves-effect waves-light btn right green" type="new"><i class="material-icons left">add</i>ADD NEW USER</a>
</div>
</div>

{{#each user_info}}
<ul class="collection with-header">
<li class="collection-header amber" >
<div class="row zero-margin">
<div class="col l8 s6 zero-padding">
<div class="col l4 s4 zero-padding">
{{#ifCondA apartment '!=' null}}
<h5>Apartment {{upperCase apartment}}</h5>
<h5>Apartment {{upperCase apartment}} </h5>

{{else}}
<h5>Others</h5>
{{/ifCondA}}
</div>
<div class="col l4 s4 zero-padding">
{{#ifCondA apartment '!=' null}}
<h6><a class="btn grey darken-4 left username">Total: P{{apartment_total_budget}}</a></h6>

{{/ifCondA}}
</div>
<!-- Send by apartment member modal trigger -->
<div class="col l4 s6 zero-padding">
<a href="#apartment" class="btn grey darken-4 right" apartment="{{apartment}}" type="apartment">Send All</a>
<div class="col l4 s4 zero-padding">
<h6><a href="#apartment" class="btn grey darken-4 right" apartment="{{apartment}}" type="apartment">Send All</a></h6>
</div>
</div>
</li>
Expand Down Expand Up @@ -67,7 +79,7 @@
{{/ifCondA}}
<span class="username white-text">{{username}}</span> <br><span class="amber-text">
{{#ifCondA role '==' 'senior_student'}}
Senior
First Generation
{{else}}
{{role}}
{{/ifCondA}}
Expand Down

0 comments on commit 16625ba

Please sign in to comment.