Skip to content

Commit

Permalink
Merge pull request #70 from VuthyVey/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
KetyaNop authored Nov 20, 2017
2 parents 8dc2562 + a184361 commit d995d7c
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 55 deletions.
9 changes: 7 additions & 2 deletions lib/email.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// var credentials = {
// user:'[email protected]',
// pass:'zxivzkliyluhagcq'
// };

var credentials = {
user:'[email protected]',
pass:'zxivzkliyluhagcq'
user:'[email protected]',
pass:'yoywnomlwolmysjk'
};

var sEmail = false;
Expand Down
7 changes: 5 additions & 2 deletions routes/apartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ module.exports.set = function(router, pool) {
var apartmentTransferBudget = 0;
var emailsList = [];

for(var i = 0; i < emails.rows.length; i++){
emailsList.push(emails.rows[i].email);
var emailToRemove = await pool.query("SELECT email FROM account WHERE role = 'senior_student' or role = 'apartment' or email = '[email protected]' or role = 'central_bank' ORDER BY role, username");

for(var i = 0; i < emailToRemove.rows.length; i++){
emailsList.push(emailToRemove.rows[i].email);
}
console.log(emailsList);
if(apartmentTransfer.rows){
for(var i = 0; i < apartmentTransfer.rows.length; i++){
apartmentTransferBudget += parseFloat(apartmentTransfer.rows[i].amount);
Expand Down
67 changes: 48 additions & 19 deletions routes/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,69 @@ module.exports.set = function(router, pool) {
// console.log("came in here \n\n\n\n");
console.log('"'+exchangeLog.reason+'"');

// //get total amount for that day
// var totalExchange = await pool.query("SELECT amount FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]);
// //sum it all up
// var exchangeSum;

// for (var i = 0 ; i < totalExchange.rows.length; i++){
// exchangeSum += parseFloat(totalExchange.rows[i].amount);
// console.log("for i "+i+" amount "+parseFloat(totalExchange.rows[i].amount);
// }
// console.log("total: "+exchangeSum);
var notValid = exchangeLog.amount > 20 && exchangeLog.reason == "";
var over20 = exchangeLog.amount > 20;
//get total amount for that day
var totalExchange = await pool.query("SELECT * FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]);
//sum it all up
var exchangeSum = 0;

for (var i = 0 ; i < totalExchange.rows.length; i++){
exchangeSum += parseFloat(totalExchange.rows[i].amount);
console.log("for i "+i+" amount "+parseFloat(totalExchange.rows[i].amount));
}
exchangeSum += parseFloat(exchangeLog.amount);
console.log("total: "+exchangeSum);
var notValid = exchangeSum > 20 && exchangeLog.reason == "";
var over20 = exchangeSum > 20;
if (notValid){
res.send("Reason Required!");
console.log("Reason Required!");
return;
}


pool.query(getApartment, function(apartmentErr, apartmentResult){
pool.query(getApartment, async function(apartmentErr, apartmentResult){
if(apartmentErr){console.log(apartmentErr);}
else{
var apartment = apartmentResult.rows[0].apartment;




//get existing apptdate
var existingApptDate = await pool.query("SELECT * FROM exchange_list WHERE email = $1 and apptDate = $2", [exchangeLog.email, apptDate]);

console.log("existingApptDate = "+existingApptDate);
if (existingApptDate.rows[0] == null){
var apptDateExist = false;
}else{
var apptDateExist = true;
}

if (apptDateExist){
pool.query("DELETE FROM exchange_list WHERE id = $1;", [totalExchange.rows[0].id], async function(errDel, resultDel) {
console.log("Deleting ID: "+ totalExchange.rows[0].id);
if(err){
res.send(errDel);
}
});
console.log("Appointment Date Exist");
}else{
console.log("Appointment Date Doesn't Exist");
}

// console.log("apptDateExist = "+apptDateExist+"\ninsertData = "+ insertData);
const insertData = {
text: "INSERT INTO exchange_list (timeCreated, person, email, type, amount, result, reason, apptdate, apartment)\
VALUES (CURRENT_TIMESTAMP(2), $1, $2, $3, $4::float8::numeric::money, $5::float8::numeric::money, $6, $7, $8) returning id as id;",
values: [exchangeLog.person, exchangeLog.email, exchangeLog.type, exchangeLog.amount, exchangeLog.result, exchangeLog.reason, apptDate, apartment]
text: "INSERT INTO exchange_list (timeCreated, person, email, type, amount, result, reason, apptdate, apartment)\
VALUES (CURRENT_TIMESTAMP(2), $1, $2, $3, $4::float8::numeric::money, $5::float8::numeric::money, $6, $7, $8) returning id as id;",
values: [exchangeLog.person, exchangeLog.email, exchangeLog.type, exchangeSum, exchangeSum, exchangeLog.reason, apptDate, apartment]
};


pool.query(insertData, async function(insertErr, insertResult) {
if (insertErr) {
if (insertErr) {
console.log(insertErr);
} else {
console.log("inserted data with id = "+ insertResult.rows[0].id);

if (exchangeLog.type == "pedro-dollar"){
if (!over20){
Expand All @@ -122,6 +149,8 @@ module.exports.set = function(router, pool) {
});
}



/*
send email to all re
"Subject: Exchange Request
Expand All @@ -136,7 +165,7 @@ module.exports.set = function(router, pool) {
*/

//get email recipient / all re emails
var emailRecipientData = await pool.query("SELECT email FROM account WHERE role = $1",["re"]);
var emailRecipientData = await pool.query("SELECT email FROM account WHERE role = $1",['re']);

//get requester's email
//exchangeLog.email;
Expand Down Expand Up @@ -186,7 +215,7 @@ module.exports.set = function(router, pool) {
//send to requester
email.sendEmail(exchangeLog.email, "Exchange Request Sent", contentToRequester);
// email.sendEmail("[email protected]", "Exchange Request Sent", contentToRequester+"<br>Target: "+exchangeLog.email);
}else{
}else{//if type isn't pedro to dollar
//get requester's email
//exchangeLog.email;

Expand Down
12 changes: 9 additions & 3 deletions routes/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ module.exports.set = function(router, pool) {
pool.query(getAccount, function(accErr, accresult) {
if(accErr){console.log(accErr);}
else{
pool.query(getAccountAll, function(allAccErr, allAccResult) {
pool.query(getAccountAll, async function(allAccErr, allAccResult) {
if(allAccErr){console.log(allAccErr);}
else{
var emailsList = [];
for(var i = 0; i < allAccResult.rows.length; i++){
emailsList.push(allAccResult.rows[i].email);


var emailToRemove = await pool.query("SELECT email FROM account WHERE role = 'senior_student' or role = 'apartment' or email = '[email protected]' or role = 'central_bank' ORDER BY role, username");

for(var i = 0; i < emailToRemove.rows.length; i++){
emailsList.push(emailToRemove.rows[i].email);
}
console.log(emailsList);

console.log("About to query!");
pool.query(getExchange, function(exchangeErr, exchangeResult) {
if(exchangeErr){console.log(exchangeErr);}
Expand Down
23 changes: 11 additions & 12 deletions views/overview.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.collection a.collection-item {
transition: .25s;
color: black;
background: transparent;
background-color: #546e7a;
}
body {
Expand All @@ -17,9 +17,9 @@ body {
<div class="row">
<div class="col l12">
<div class="col l6 m6 s12">
<div class="card amber ">
<div class="card white-text blue-grey darken-1">
<div class="card-content">
<span class="card-title"><i class="material-icons white-text right">grade</i>{{bankName}} Current Budget </span>
<span class="card-title white-text"><i class="material-icons white-text right">grade</i><strong>{{bankName}} Current Budget </strong></span>
<h4 class="white-text">P{{bankBudget}}</h4>
</div>

Expand All @@ -28,12 +28,12 @@ body {
</div>
{{#ifCondA recentTransfer '!=' null}}
<div class="col l6 m6 s12">
<div class="card green ">
<div class="card blue-grey darken-1">
<div class="card-content">
<span class="card-title">Recent Transfer </span>
<ul class="collection transparent">
<span class="card-title white-text"><Strong>Recent Transfer </Strong></span>
<ul class="collection">
{{#each recentTransfer}}
<a href="/{{lowerCase ../bankName}}/transfer_logs" class="collection-item">{{sender_username}} sent P{{amount}} <span class="right">{{formatDate date 'short'}}</span></a>
<a href="/{{lowerCase ../bankName}}/transfer_logs" class="collection-item"><strong>{{sender_username}} sent P{{amount}} <span class="right">{{formatDate date 'short'}}</strong></span></a>
{{/each}}
</ul>
</div>
Expand All @@ -47,16 +47,15 @@ body {
<div class="row">
{{#each apartmentData}}
<div class="col l4 m6 s12">
<div class="card grey darken-4">
<div class="card blue-grey lighten-2">
<div class="card-content white-text">
<span class="card-title">{{#ifCondA apartment '!=' null}}Apartment {{upperCase apartment}}{{else}}Non-apartment accounts{{/ifCondA}}</span>
<h4 class="amber-text">Total Sent {{sum}}</h4>
<span class="card-title"><strong>{{#ifCondA apartment '!=' null}}Apartment {{upperCase apartment}}{{else}}Non-apartment accounts{{/ifCondA}}</span>
<h4 class="black-text">Total Sent {{sum}}</strong></h4>
</div>
<div class="card-action grey darken-4"><a href="" class="white-text">View More</a></div>
<div class="card-action white-text"><a href="" class="white-text">View More</a></div>
</div>
</div>
{{/each}}
</div>
</div>
</main>
{{> mainFooter}}
4 changes: 2 additions & 2 deletions views/partials/dashboardSideNav.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@
</ul>
{{/with}}
<nav class="top-nav black-text" style="background-color: #D0D3D4; color: black">
<nav class="top-nav white-text" style="background-color: #F63131">
<div class="container">
<div class="nav-wrapper">
<a href="#!" id="title" class="center brand-logo" style="font-size: 24px"></a>
<a href="/" id="title" class="center brand-logo" style="font-size: 24px"></a>
<!-- <a href="" class="center" style="font-size: 22px;">Liger Digital Currency</a> -->
<a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons">menu</i></a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions views/partials/keeperNav.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<i class="large material-icons">menu</i>
</a>
<ul>
<li class="waves-effect waves-light"><a href="/keeper/p/d">Exchange Pedro to Dollar</a></li>
<li class="waves-effect waves-light"><a href="/keeper/d/p">Exchange Dollar to Pedro</a></li>
<li class="waves-effect waves-light"><a href="/keeper/p/d">Withdrawal</a></li>
<li class="waves-effect waves-light"><a href="/keeper/d/p">Deposit</a></li>
</ul>
</div>
{{/if}}
14 changes: 9 additions & 5 deletions views/partials/mainNav.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@
</ul>
</div>
{{else ifCond data 'keeper'}}
<li class="green right"><a href="/keeper/p/d"><i class="material-icons">store</i></a></li>
<li class="red left"><center><a href="/keeper/p/d" style="font-family: Calibri; width: 400px; font-size: 25px;">Return to Maintenance Page</a></center>
</li>
{{else ifCond data 're'}}
<li class="green right"><a href="/residence/overview"><i class="material-icons">store</i></a></li>
<li class="red left"><center><a href="/residence/overview" style="font-family: Calibri; width: 400px; font-size: 25px;">Return to Maintenance Page</a></center>
</li>
{{else ifCond data 'catering_manager'}}
<li class="green right"><a href="/catering/overview"><i class="material-icons">shopping_cart</i></a></li>
<li class="red left"><center><a href="/catering/overview" style="font-family: Calibri; width: 400px; font-size: 25px;">Return to Catering Page</a></center>
</li>
{{else ifCond data 'maintenance_manager'}}
<li class="green right"><a href="/maintenance/overview"><i class="material-icons">build</i></a></li>
<li class="red left"><center><a href="/maintenance/overview" style="font-family: Calibri; width: 400px; font-size: 25px;">Back to Maintenance Page</a></center>
</li>
{{else ifCond data 'admin'}}
<li class="green right"><a href="/admin/user">Admin</a></li>
<li class="red left"><center><a href="/admin/user" style="font-family: Calibri; width: 400px; font-size: 25px;">Back to Admin Page</a></center></li>
{{/ifCond}}


Expand Down
12 changes: 6 additions & 6 deletions views/personal/exchanging.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
<div class="row zero-margin">
<div class="col l12 s12 m4">
<div class="card">
<div class="card-content">
<span class="card-title black-text">Exchanging Rate:</span>
<h4 class="center black-text">P1 = $1</h4>
<div class="card-content" style="background-color: #3498DB">
<span class="card-title white-text"><strong>Exchanging Rate:</strong></span>
<h4 class="center white-text">P1 = $1</h4>
</div>
</div>
</div>
<div class="col l12 s12 m4">

<div class="card" style="background-color: #3498DB">
<div class="card" style="background-color: #C92828">
<div class="card-content">
<span class="card-title">Total Budget: </span>
<span class="card-title white-text"><strong>Total Budget: </strong></span>
<h4 class="center white-text">P {{budget}}</h4>
</div>
</div>
Expand All @@ -46,7 +46,7 @@
<div class="col l12 s12 m4">
<div class="card" style="background-color: #3498DB">
<div class="card-content">
<span class="card-title">Pending Budget: </span>
<span class="card-title white-text"><strong>Pending Budget: </strong></span>
<h4 class="center white-text">P {{pendingBudget}}</h4>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions views/personal/history_personal.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
</div>
<div class="col s4 m4">
{{#ifCondA this.type '==' 'pedro-dollar'}}
<span class="new badge red left" data-badge-caption="">Pedro to Dollar</span>
<span class="new badge red left" data-badge-caption=""><Strong>Withdrawal</Strong></span>
{{else}}
<span class="new badge blue left" data-badge-caption="">Dollar to Pedro</span>
<span class="new badge blue left" data-badge-caption=""><strong>Deposit</strong></span>
{{/ifCondA}}
</div>
<div class="col s4 m3">
Expand Down

0 comments on commit d995d7c

Please sign in to comment.