--- a/backend/notificationManager.js
+++ b/backend/notificationManager.js
@@ -6,7 +6,7 @@
var email = require('../controllers/emailer');
var logger = require('../config/logger.js');
-module.exports.notificationsCheck= function(body, callback) {
+module.exports.notificationsCheck= function(body, emailTo, token, callback) {
var handler = "backend.controllers.notificationManager";
@@ -20,840 +20,809 @@
//Auxiliary Variables
var AllData= [{}];
var flag = false;
- var aux = 0;
- var cnt = 1;
- var keys = [];
- var values = [];
endoftwoweeks.setDate(endoftwoweeks.getDate() + 14);
endofweek.setDate(endofweek.getDate() + 7);
endofthreedays.setDate(endofthreedays.getDate() + 3);
-
- for(var k in body){
- keys.push(k);
- values.push(body[k]);
- }
-
- for(var i = keys.length - 1; i >= 0; i--) {
- if(keys[i] === "emailTo" || keys[i] === "token") {
- keys.splice(i, 1);
- values.splice(i, 1);
- }
- }
-
- for(var check = 0; check < keys.length; check = check + 2){
- var stringSubject = "subject_" + cnt;
- var stringSubjectValue = "subjectValue_" + cnt;
- if(keys[check] != stringSubject || keys[check + 1] != stringSubjectValue){
- flag = true;
- break;
- }
- cnt++;
- }
- if(flag == false){
- mysql.getRulesListByToken(body.token, function(isOK, ruleslist){
- if(!isOK){
- callback(false);
- }else if(ruleslist){
- for(j = 0; j <= values.length / 2; j = j + 2){
- var parameter = values[j];
- var valueNotification = parseFloat(values[j + 1]);
- for(i = 0; i < ruleslist.length; i++){
- var valueRules = parseFloat(ruleslist[i].controlValue);
- if(ruleslist[i].conditionValue == ">"){
- if((valueNotification > valueRules) && (parameter == ruleslist[i].parameter)){
- if(ruleslist[i].notificationType == 1){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, lastDayOfMonth.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 2){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endoftwoweeks.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 3){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofweek.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 4){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofthreedays.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 5){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, today.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalN = ruleslist[i].totalNotifications + 1;
- var totalApplyRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalN;
- var percentage = (totalApplyRules * 100 ) / totalN;
- mysql.updateValues(totalN, totalApplyRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- }else if(valueNotification > valueRules || (parameter != ruleslist[i].parameter)){
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Parameter is not valid";
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- else{
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Value within the limits of the Rules";
+ mysql.getRulesListByToken(token, function(isOK, ruleslist){
+ if(!isOK){
+ callback(false);
+ }else if(ruleslist){
+ for(j = 0; j < body.length; j++){
+ var parameter = body[j].subject;
+ var valueNotification = parseFloat(body[j].subjectValue);
+ for(i = 0; i < ruleslist.length; i++){
+ var valueRules = parseFloat(ruleslist[i].controlValue);
+ if(ruleslist[i].conditionValue == ">"){
+ if((valueNotification > valueRules) && (parameter == ruleslist[i].parameter)){
+ if(ruleslist[i].notificationType == 1){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, lastDayOfMonth.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 2){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endoftwoweeks.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 3){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofweek.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 4){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofthreedays.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 5){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, today.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
var totalN = ruleslist[i].totalNotifications + 1;
- var totalApplyRules = ruleslist[i].totalNotificationsApplyByRules;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = (totalValue / totalN).toFixed(2);
- var percentage = ((totalApplyRules * 100 ) / totalN).toFixed(2);
+ var totalApplyRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalN;
+ var percentage = (totalApplyRules * 100 ) / totalN;
mysql.updateValues(totalN, totalApplyRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- } else if(ruleslist[i].conditionValue == ">="){
- if((valueNotification >= valueRules) && (parameter == ruleslist[i].parameter)){
- if(ruleslist[i].notificationType == 1){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, lastDayOfMonth.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 2){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endoftwoweeks.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 3){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofweek.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 4){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofthreedays.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 5){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, today.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- }else if(valueNotification >= valueRules || (parameter != ruleslist[i].parameter)){
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Parameter is not valid";
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- else{
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Value within the limits of the Rules";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- } else if(ruleslist[i].conditionValue == "<"){
- if((valueNotification < valueRules) && (parameter == ruleslist[i].parameter)){
- if(ruleslist[i].notificationType == 1){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, lastDayOfMonth.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 2){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endoftwoweeks.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 3){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofweek.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 4){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofthreedays.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 5){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, today.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- }else if(valueNotification < valueRules || (parameter != ruleslist[i].parameter)){
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Parameter is not valid";
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- else{
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Value within the limits of the Rules";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- } else{
- if((valueNotification <= valueRules) && (parameter == ruleslist[i].parameter)){
- if(ruleslist[i].notificationType == 1){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, lastDayOfMonth.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 2){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endoftwoweeks.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 3){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofweek.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 4){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, endofthreedays.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }else if(ruleslist[i].notificationType == 5){
- strSubject = parameter + " = " + valueNotification;
- cronjob(body.emailTo, strSubject, today.getDate());
- var data = {
- emailTo: body.emailTo,
- subject: parameter,
- subjectValue: valueNotification,
- token: body.token
- };
- flag = true;
- AllData[aux] = strSubject + " : Success";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- mysql.insertNotification(data, function(isOK, data){
- if(!isOK) {
- logger.error(handler + " InsertNotification",data);
- }else {
- logger.info(handler + " InsertNotification",data);
- }
- });
-
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- }else if(valueNotification <= valueRules || (parameter != ruleslist[i].parameter)){
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Parameter is not valid";
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
- }
- }
- else{
- strSubject = parameter + " = " + valueNotification;
- AllData[aux] = strSubject + " : Value within the limits of the Rules";
- var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
- var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
- var totalValue = valueNotification + ruleslist[i].totalValue;
- var averageValue = totalValue / totalNotifications;
- var percentage = (totalApplyByRules * 100 ) / totalNotifications;
- mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
- if(j == values.length / 2){
- if(flag == true){
- callback(true, AllData);
- }
- else{
- callback(false, AllData);
- }
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ }else if(valueNotification > valueRules || (parameter != ruleslist[i].parameter)){
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Parameter is not valid";
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ else{
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Value within the limits of the Rules";
+ var totalN = ruleslist[i].totalNotifications + 1;
+ var totalApplyRules = ruleslist[i].totalNotificationsApplyByRules;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = (totalValue / totalN).toFixed(2);
+ var percentage = ((totalApplyRules * 100 ) / totalN).toFixed(2);
+ mysql.updateValues(totalN, totalApplyRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ } else if(ruleslist[i].conditionValue == ">="){
+ if((valueNotification >= valueRules) && (parameter == ruleslist[i].parameter)){
+ if(ruleslist[i].notificationType == 1){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, lastDayOfMonth.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 2){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endoftwoweeks.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 3){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofweek.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 4){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofthreedays.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 5){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, today.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ }else if(valueNotification >= valueRules || (parameter != ruleslist[i].parameter)){
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Parameter is not valid";
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ else{
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Value within the limits of the Rules";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ } else if(ruleslist[i].conditionValue == "<"){
+ if((valueNotification < valueRules) && (parameter == ruleslist[i].parameter)){
+ if(ruleslist[i].notificationType == 1){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, lastDayOfMonth.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 2){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endoftwoweeks.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 3){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofweek.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 4){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofthreedays.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 5){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, today.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ }else if(valueNotification < valueRules || (parameter != ruleslist[i].parameter)){
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Parameter is not valid";
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ else{
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Value within the limits of the Rules";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ } else{
+ if((valueNotification <= valueRules) && (parameter == ruleslist[i].parameter)){
+ if(ruleslist[i].notificationType == 1){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, lastDayOfMonth.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 2){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endoftwoweeks.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 3){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofweek.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 4){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, endofthreedays.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }else if(ruleslist[i].notificationType == 5){
+ strSubject = parameter + " = " + valueNotification;
+ cronjob(emailTo, strSubject, today.getDate());
+ var data = {
+ emailTo: emailTo,
+ subject: parameter,
+ subjectValue: valueNotification,
+ token: token
+ };
+ flag = true;
+ AllData[j] = strSubject + " : Success";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules + 1;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ mysql.insertNotification(data, function(isOK, data){
+ if(!isOK) {
+ logger.error(handler + " InsertNotification",data);
+ }else {
+ logger.info(handler + " InsertNotification",data);
+ }
+ });
+
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ }else if(valueNotification <= valueRules || (parameter != ruleslist[i].parameter)){
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Parameter is not valid";
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
+ }
+ }
+ }
+ else{
+ strSubject = parameter + " = " + valueNotification;
+ AllData[j] = strSubject + " : Value within the limits of the Rules";
+ var totalNotifications = ruleslist[i].totalNotificationsReceived + 1;
+ var totalApplyByRules = ruleslist[i].totalNotificationsApplyByRules;
+ var totalValue = valueNotification + ruleslist[i].totalValue;
+ var averageValue = totalValue / totalNotifications;
+ var percentage = (totalApplyByRules * 100 ) / totalNotifications;
+ mysql.updateValues(totalNotifications, totalApplyByRules, totalValue, averageValue, percentage, ruleslist[i].rulesID);
+ if(j == body.length - 1){
+ if(flag == true){
+ callback(true, AllData);
+ }
+ else{
+ callback(false, AllData);
}
}
}
}
- aux++;
}
}
-
- });
- }else{
- callback(false, "JSON Key with wrong format");
- }
+ }
+
+ });
}
function cronjob(emailTo, subject, day){