Skip to content

Commit

Permalink
Merge pull request #71 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 d995d7c + fc65794 commit 185f68c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
12 changes: 12 additions & 0 deletions lib/fixROE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function fixRoundOffError(toFix){
toFix = Math.round((toFix * 100))/100;
toFix = toFix.toString();
if (toFix[toFix.indexOf(".")+2] == undefined && toFix[toFix.indexOf(".")] != undefined){
toFix = toFix.concat("0");
}
return parseFloat(toFix);
}

module.exports = {
fixROE: fixRoundOffError
}
33 changes: 21 additions & 12 deletions routes/apartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var createdFun = require('../lib/objFuns');
var Validator = require('../lib/validator');
var createdFun = require('../lib/objFuns');
var moment = require('moment');
var momentTZ = require('moment-timezone')
var momentTZ = require('moment-timezone');
var fix = require('../lib/fixROE');

module.exports.set = function(router, pool) {

Expand Down Expand Up @@ -36,20 +37,13 @@ module.exports.set = function(router, pool) {
apartmentTransferBudget += parseFloat(apartmentTransfer.rows[i].amount);
}
}

var budgetRemain = parseFloat(apartmentData.rows[0].budget) - apartmentTransferBudget;

budgetRemain = Math.round((budgetRemain * 100))/100;
budgetRemain = fix.fixROE(budgetRemain);

budgetRemain = budgetRemain.toString();
if (budgetRemain[budgetRemain.indexOf(".")+2] == undefined){
budgetRemain = budgetRemain.concat("0");
}
apartmentTransferBudget = fix.fixROE(apartmentTransferBudget);

apartmentTransferBudget = Math.round((apartmentTransferBudget * 100))/100;
apartmentTransferBudget = apartmentTransferBudget.toString();
if (apartmentTransferBudget[apartmentTransferBudget.indexOf(".")+2] == undefined){
apartmentTransferBudget = apartmentTransferBudget.concat("0");
}
response.render('apartment/apartment_transfer', {
emails: emailsList,
user: request.user,
Expand Down Expand Up @@ -92,6 +86,11 @@ module.exports.set = function(router, pool) {
}

var budgetRemain = parseFloat(apartmentData.rows[0].budget) - apartmentTransferBudget;

budgetRemain = fix.fixROE(budgetRemain);

apartmentTransferBudget = fix.fixROE(apartmentTransferBudget);

response.render('apartment/apartment_approve', {
email: email,
user: request.user,
Expand All @@ -108,7 +107,7 @@ module.exports.set = function(router, pool) {
response.redirect('notFound');
}
});

router.get('/apartment_history', ensureLoggedIn, async function(request, response){
var email = request.user.email;
var personality = await pool.query("SELECT * FROM account WHERE email = $1;", [email]);
Expand Down Expand Up @@ -143,6 +142,11 @@ module.exports.set = function(router, pool) {
}
}
var budgetRemain = parseFloat(apartmentData.rows[0].budget) - apartmentTransferBudget;

budgetRemain = fix.fixROE(budgetRemain);

apartmentTransferBudget = fix.fixROE(apartmentTransferBudget);

response.render('apartment/apartment_history', {
user: request.user,
data: personality.rows[0].role,
Expand Down Expand Up @@ -195,6 +199,11 @@ module.exports.set = function(router, pool) {
dataCollection.push([]);
dataCollection[i].push(shr.rows[i].person, parseFloat(shr.rows[i].result), shr.rows[i].id, exportDate(shr.rows[i].apptdate));
}

budgetRemain = fix.fixROE(budgetRemain);

apartmentTransferBudget = fix.fixROE(apartmentTransferBudget);

response.render('apartment/apartment_memberExchange', {
exData: dataCollection,
user: request.user,
Expand Down

0 comments on commit 185f68c

Please sign in to comment.