Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `use strict`
  2. var server = require('diet')
  3. var mysql = require('mysql')
  4. var connection = mysql.createConnection({
  5.     host: 'localhost',
  6.     user: 'root',
  7.     password: 'pass'
  8. });
  9. var app = server()
  10. app.listen('ip:port/')
  11. //clients
  12. app.get('/clients.get', function($) {
  13.     connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
  14.         $.json({
  15.             rows
  16.         })
  17.     })
  18. })
  19. app.get('/clients.getarr', function($) {
  20.     connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
  21.         var arr = rows.map(function(row) {
  22.             return [row.name + "," + row.email + "," + row.type + "," + row.added]
  23.         })
  24.         $.end(arr)
  25.     })
  26. })
  27. app.get('/clients.getsum', function($) {
  28.     connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
  29.         $.json({
  30.             "rows": [{
  31.                 'clients': rows.length
  32.             }]
  33.         })
  34.     })
  35. })
  36. app.get('/client.getbyid', function($) {
  37.     connection.query("SELECT * FROM `get`.`clients` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  38.         $.json({
  39.             rows
  40.         })
  41.     })
  42. })
  43. app.get('/clients.getbyid', function($) {
  44.     connection.query("SELECT * FROM `get`.`clients` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  45.         $.json({
  46.             rows
  47.         })
  48.     })
  49. })
  50. app.get('/clients.new', function($) {
  51.     connection.query("INSERT INTO `get`.`clients`(`name`, `email`, `phone`, `manager_id`, `type`, `added`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.email) + "," + connection.escape($.query.phone) + "," + connection.escape($.query.manager_id) + "," + connection.escape($.query.type) + ", CURRENT_DATE())", function(err, rows, fields) {
  52.         if (!err) {
  53.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  54.             $.end('Success')
  55.         } else {
  56.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  57.             $.end(err)
  58.         }
  59.     })
  60. })
  61. app.get('/clients.delete', function($) {
  62.     connection.query("DELETE FROM `get`.`clients` WHERE `id` =" + connection.escape($.query.id), function(err, rows, fields) {
  63.         if (!err) {
  64.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  65.             $.end('Success')
  66.         } else {
  67.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  68.             $.end(err)
  69.         }
  70.     })
  71. })
  72. //comments
  73. app.get('/comment.add', function($) {
  74.     connection.query("INSERT INTO `get`.`comments`(`task_id`, `user_id`, `comment`, `date`) VALUES (" + connection.escape($.query.task_id) + "," + connection.escape($.query.user_id) + "," + connection.escape($.query.comment) + ", NOW())", function(err, rows, fields) {
  75.         if (!err) {
  76.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  77.             $.end('Success')
  78.         } else {
  79.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  80.             $.end(err)
  81.         }
  82.     })
  83. })
  84. app.get('/comments.get', function($) {
  85.     connection.query("SELECT * FROM `get`.`comments` WHERE `task_id` =" + connection.escape($.query.id) + " ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
  86.         $.json({
  87.             rows
  88.         })
  89.     })
  90. })
  91.  
  92. app.get('/comments.getall', function($) {
  93.     connection.query("SELECT * FROM `get`.`comments` WHERE 1 ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
  94.         $.json({
  95.             rows
  96.         })
  97.     })
  98. })
  99. app.get('/comments.getdev', function($) {
  100.     connection.query("SELECT * FROM `get`.`tasks` WHERE `developer_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  101.         var tasks = rows.map(function(row) {
  102.                 return row.id
  103.         })
  104.        
  105.         connection.query("SELECT * FROM `get`.`comments` WHERE `task_id` IN ("+tasks+") ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
  106.             if(!err) {
  107.                 $.json({
  108.                 rows
  109.                 })
  110.                 } else {
  111.                     $.end(err)
  112.                 }
  113.            
  114.         })
  115.     })
  116. })
  117. app.get('/comments.getbyuser', function($) {
  118.     connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  119.         var tasks = rows.map(function(row) {
  120.                 return row.id
  121.         })
  122.        
  123.         connection.query("SELECT * FROM `get`.`comments` WHERE `task_id` IN ("+tasks+") ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
  124.             if(!err) {
  125.                 $.json({
  126.                 rows
  127.                 })
  128.                 } else {
  129.                     $.end(err)
  130.                 }
  131.            
  132.         })
  133.     })
  134. })
  135. //developers
  136. app.get('/developers.get', function($) {
  137.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `group` = 'developer'", function(err, rows, fields) {
  138.         $.json({
  139.             rows
  140.         })
  141.     })
  142. })
  143. app.get('/designers.get', function($) {
  144.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `group` = 'designer'", function(err, rows, fields) {
  145.         $.json({
  146.             rows
  147.         })
  148.     })
  149. })
  150. app.get('/editors.get', function($) {
  151.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `group` = 'editor'", function(err, rows, fields) {
  152.         $.json({
  153.             rows
  154.         })
  155.     })
  156. })
  157. app.get('/developers.getactive', function($) {
  158.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `group` = 'developer' AND `status` = 1", function(err, rows, fields) {
  159.         $.json({
  160.             rows
  161.         })
  162.     })
  163. })
  164. app.get('/developers.setactive', function($) {
  165.     connection.query("UPDATE `get`.`tbl_users` SET `status` = 1 WHERE `userID` = "+connection.escape($.query.id), function(err, rows, fields) {
  166.        $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  167.         $.json({
  168.            
  169.             rows
  170.         })
  171.     })
  172. })
  173. app.get('/developers.setinactive', function($) {
  174.     connection.query("UPDATE `get`.`tbl_users` SET `status` = 0 WHERE `userID` = "+connection.escape($.query.id), function(err, rows, fields) {
  175.          $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  176.         $.json({
  177.            
  178.             rows
  179.         })
  180.     })
  181. })
  182. //history
  183. app.get('/history.get', function($) {
  184.     connection.query("SELECT * FROM `get`.`history` WHERE `task_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  185.         $.json({
  186.             rows
  187.         })
  188.     })
  189. })
  190. app.get('/history.getall', function($) {
  191.     connection.query("SELECT * FROM `get`.`history` WHERE 1 ORDER BY `history`.`id` DESC", function(err, rows, fields) {
  192.         $.json({
  193.             rows
  194.         })
  195.     })
  196. })
  197. app.get('/history.getbyuser', function($) {
  198.     connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  199.         var tasks = rows.map(function(row) {
  200.                 return row.id
  201.         })
  202.         connection.query("SELECT * FROM `get`.`history` WHERE `task_id` IN ("+tasks+") ORDER BY `history`.`id` DESC", function(err, rows, fields) {
  203.             $.json({
  204.                 rows
  205.             })
  206.         })
  207.     })
  208. })
  209. app.get('/history.getdev', function($) {
  210.     connection.query("SELECT * FROM `get`.`tasks` WHERE `developer_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  211.         var tasks = rows.map(function(row) {
  212.                 return row.id
  213.         })
  214.         connection.query("SELECT * FROM `get`.`history` WHERE `task_id` IN ("+tasks+") ORDER BY `history`.`id` DESC", function(err, rows, fields) {
  215.             $.json({
  216.                 rows
  217.             })
  218.         })
  219.     })
  220. })
  221. //price
  222. app.get('/price.get', function($) {
  223.     connection.query("SELECT * FROM `get`.`price_head` WHERE 1", function(err, rows, fields) {
  224.         $.json({
  225.             rows
  226.         })
  227.     })
  228. })
  229. app.get('/price.getbyid', function($) {
  230.     connection.query("SELECT * FROM `get`.`price_head` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  231.         $.json({
  232.             rows
  233.         })
  234.     })
  235. })
  236. app.get('/price.delete', function($) {
  237.     connection.query("DELETE FROM `get`.`price_head` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  238.         if (!err) {
  239.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  240.             $.end('Success')
  241.         } else {
  242.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  243.             $.end(err)
  244.         }
  245.     })
  246. })
  247. app.get('/price.update', function($) {
  248.     connection.query("UPDATE `get`.`price_head` SET `name`=" + connection.escape($.query.name) + ",`cost`=" + connection.escape($.query.cost) +",`days`=" + connection.escape($.query.days) + " WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  249.         if (!err) {
  250.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  251.             $.end('Success')
  252.         } else {
  253.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  254.             $.end(err)
  255.         }
  256.     })
  257. })
  258. app.get('/price.updateabout', function($) {
  259.     connection.query("UPDATE `get`.`price_head` SET `about`=" + connection.escape($.query.about) + " WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  260.         if (!err) {
  261.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  262.             $.end('Success')
  263.         } else {
  264.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  265.             $.end(err)
  266.         }
  267.     })
  268. })
  269. app.get('/price.add', function($) {
  270.     connection.query("INSERT INTO `get`.`price_head`(`name`, `cost`, `days`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.cost) + connection.escape($.query.days) + ")", function(err, rows, fields) {
  271.         if (!err) {
  272.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  273.             $.end('Success')
  274.         } else {
  275.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  276.             $.end(err)
  277.         }
  278.     })
  279. })
  280. //statuses
  281. app.get('/status.get', function($) {
  282.     connection.query("SELECT * FROM `get`.`statuses` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  283.         $.json({
  284.             rows
  285.         })
  286.     })
  287. })
  288. app.get('/statuses', function($) {
  289.     connection.query("SELECT * FROM `get`.`statuses` WHERE 1", function(err, rows, fields) {
  290.         $.json({
  291.             rows
  292.         })
  293.     })
  294. })
  295. app.get('/status.update', function($) {
  296.     connection.query("UPDATE `get`.`tasks` SET `status`=" + connection.escape($.query.status) + " WHERE `id`=" + connection.escape($.query.task_id), function(err, rows, fields) {
  297.         if (!err) {
  298.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  299.             connection.query("INSERT INTO `get`.`history`(`task_id`, `user_id`, `info`, `date`) VALUES (" + connection.escape($.query.task_id) + "," + connection.escape($.query.user_id) + "," + connection.escape($.query.info) + ", NOW())", function(err, rows, fields) {
  300.                 if (!err) {
  301.                     $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  302.                     $.end('Success')
  303.                 } else {
  304.                     $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  305.                     $.end(err)
  306.                 }
  307.             })
  308.         } else {
  309.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  310.             $.end(err)
  311.         }
  312.     })
  313. })
  314. //subprice
  315. app.get('/subprice.delete', function($) {
  316.     connection.query("DELETE FROM `get`.`price_sub` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  317.         if (!err) {
  318.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  319.             $.end('Success')
  320.         } else {
  321.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  322.             $.end(err)
  323.         }
  324.     })
  325. })
  326. app.get('/subprice.update', function($) {
  327.     connection.query("UPDATE `get`.`price_sub` SET `name`=" + connection.escape($.query.name) + ",`cost`=" + connection.escape($.query.cost) + " WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  328.         if (!err) {
  329.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  330.             $.end('Success')
  331.         } else {
  332.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  333.             $.end(err)
  334.         }
  335.     })
  336. })
  337. app.get('/subprice.add', function($) {
  338.     connection.query("INSERT INTO `get`.`price_sub`(`name`, `cost`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.cost) + ")", function(err, rows, fields) {
  339.         if (!err) {
  340.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  341.             $.end('Success')
  342.         } else {
  343.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  344.             $.end(err)
  345.         }
  346.     })
  347. })
  348. app.get('/subprice.get', function($) {
  349.     connection.query("SELECT * FROM `get`.`price_sub` WHERE 1", function(err, rows, fields) {
  350.         $.json({
  351.             rows
  352.         })
  353.     })
  354. })
  355. app.get('/sub.get', function($) {
  356.     connection.query("SELECT * FROM `get`.`price_sub` WHERE `id`in (" + $.query.id + ")", function(err, rows, fields) {
  357.         $.json({
  358.             rows
  359.         })
  360.     })
  361. })
  362. //tasks
  363. app.get('/tasks.get', function($) {
  364.     connection.query("SELECT * FROM `get`.`tasks` WHERE 1", function(err, rows, fields) {
  365.         $.json({
  366.             rows
  367.         })
  368.     })
  369. })
  370. app.get('/tasks.getbyid', function($) {
  371.     connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id`=" + connection.escape($.query.id), function(err, rows, fields) {
  372.         $.json({
  373.             rows
  374.         })
  375.     })
  376. })
  377. app.get('/tasks.getbydev', function($) {
  378.     connection.query("SELECT * FROM `get`.`tasks` WHERE `developer_id`=" + connection.escape($.query.id), function(err, rows, fields) {
  379.         $.json({
  380.             rows
  381.         })
  382.     })
  383. })
  384. app.get('/tasks.getbyclient', function($) {
  385.     connection.query("SELECT * FROM `get`.`tasks` WHERE `client_id`=" + connection.escape($.query.id), function(err, rows, fields) {
  386.         $.json({
  387.             rows
  388.         })
  389.     })
  390. })
  391. app.get('/tasks.oneid', function($) {
  392.     connection.query("SELECT * FROM `get`.`tasks` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
  393.         $.json({
  394.             rows
  395.         })
  396.     })
  397. })
  398. app.get('/tasks.getsumbyid', function($) {
  399.     connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  400.         var not_payed = rows.map(function(row) {
  401.             if (row.status == '1') {
  402.                 return row.status
  403.             }
  404.         }).filter(function(x) {
  405.             return typeof x !== 'undefined';
  406.         })
  407.         var payed = rows.map(function(row) {
  408.             if (row.status == '2') {
  409.                 return row.status
  410.             }
  411.         }).filter(function(x) {
  412.             return typeof x !== 'undefined';
  413.         })
  414.         var in_development = rows.map(function(row) {
  415.             if (row.status == '3') {
  416.                 return row.status
  417.             }
  418.         }).filter(function(x) {
  419.             return typeof x !== 'undefined';
  420.         })
  421.         var done = rows.map(function(row) {
  422.             if (row.status == '4') {
  423.                 return row.status
  424.             }
  425.         }).filter(function(x) {
  426.             return typeof x !== 'undefined';
  427.         })
  428.         var ended = rows.map(function(row) {
  429.             if (row.status == '5') {
  430.                 return row.status
  431.             }
  432.         }).filter(function(x) {
  433.             return typeof x !== 'undefined';
  434.         })
  435.  
  436.         var re_edit = rows.map(function(row) {
  437.             if (row.status == '6') {
  438.                 return row.status
  439.             }
  440.         }).filter(function(x) {
  441.             return typeof x !== 'undefined';
  442.         })
  443.         var actual_inc = rows.map(function(row) {
  444.             if (row.status == '5') {
  445.                 return row.sum
  446.             }
  447.         }).filter(function(x) {
  448.             return typeof x !== 'undefined';
  449.         })
  450.         var actual_income = 0;
  451.         for (var i = 0; i < actual_inc.length; i++) {
  452.             actual_income = actual_income + parseInt(actual_inc[i]);
  453.         }
  454.  
  455.         var real_inc = rows.map(function(row) {
  456.             if (row.status == '5') {
  457.                 return row.salesum
  458.             }
  459.         }).filter(function(x) {
  460.             return typeof x !== 'undefined';
  461.         })
  462.         var real_income = 0;
  463.         for (var i = 0; i < real_inc.length; i++) {
  464.             real_income = real_income + parseInt(real_inc[i]);
  465.         }
  466.  
  467.  
  468.         var perspective_act = rows.map(function(row) {
  469.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  470.                 return row.sum
  471.             }
  472.         }).filter(function(x) {
  473.             return typeof x !== 'undefined';
  474.         })
  475.         var perspective_actual = 0;
  476.         for (var i = 0; i < perspective_act.length; i++) {
  477.             perspective_actual = perspective_actual + parseInt(perspective_act[i]);
  478.         }
  479.         var perspective_rea = rows.map(function(row) {
  480.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  481.                 return row.salesum
  482.             }
  483.         }).filter(function(x) {
  484.             return typeof x !== 'undefined';
  485.         })
  486.         var perspective_real = 0;
  487.         for (var i = 0; i < perspective_rea.length; i++) {
  488.             perspective_real = perspective_real + parseInt(perspective_rea[i]);
  489.         }
  490.  
  491.         var manager_salary = real_income * 0.2
  492.         var developer_salary = actual_income * 0.05
  493.  
  494.         $.json({
  495.             "rows": [{
  496.                 'tasks': rows.length,
  497.                 'not_payed': not_payed.length,
  498.                 'payed': payed.length,
  499.                 'in_development': in_development.length,
  500.                 'done': done.length,
  501.                 'ended': ended.length,
  502.                 're_edit': re_edit.length,
  503.                 'actual_income': actual_income,
  504.                 'real_income': real_income,
  505.                 'perspective_actual': perspective_actual,
  506.                 'perspective_real': perspective_real,
  507.                 'manager_salary': manager_salary,
  508.                 'developer_salry': developer_salary
  509.             }]
  510.         })
  511.     })
  512. })
  513. app.get('/tasks.getsumbydev', function($) {
  514.     connection.query("SELECT * FROM `get`.`tasks` WHERE `developer_id` =" + connection.escape($.query.id), function(err, rows, fields) {
  515.         var not_payed = rows.map(function(row) {
  516.             if (row.status == '1') {
  517.                 return row.status
  518.             }
  519.         }).filter(function(x) {
  520.             return typeof x !== 'undefined';
  521.         })
  522.         var payed = rows.map(function(row) {
  523.             if (row.status == '2') {
  524.                 return row.status
  525.             }
  526.         }).filter(function(x) {
  527.             return typeof x !== 'undefined';
  528.         })
  529.         var in_development = rows.map(function(row) {
  530.             if (row.status == '3') {
  531.                 return row.status
  532.             }
  533.         }).filter(function(x) {
  534.             return typeof x !== 'undefined';
  535.         })
  536.         var done = rows.map(function(row) {
  537.             if (row.status == '4') {
  538.                 return row.status
  539.             }
  540.         }).filter(function(x) {
  541.             return typeof x !== 'undefined';
  542.         })
  543.         var ended = rows.map(function(row) {
  544.             if (row.status == '5') {
  545.                 return row.status
  546.             }
  547.         }).filter(function(x) {
  548.             return typeof x !== 'undefined';
  549.         })
  550.  
  551.         var re_edit = rows.map(function(row) {
  552.             if (row.status == '6') {
  553.                 return row.status
  554.             }
  555.         }).filter(function(x) {
  556.             return typeof x !== 'undefined';
  557.         })
  558.         var actual_inc = rows.map(function(row) {
  559.             if (row.status == '5') {
  560.                 return row.sum
  561.             }
  562.         }).filter(function(x) {
  563.             return typeof x !== 'undefined';
  564.         })
  565.         var actual_income = 0;
  566.         for (var i = 0; i < actual_inc.length; i++) {
  567.             actual_income = actual_income + parseInt(actual_inc[i]);
  568.         }
  569.  
  570.         var real_inc = rows.map(function(row) {
  571.             if (row.status == '5') {
  572.                 return row.salesum
  573.             }
  574.         }).filter(function(x) {
  575.             return typeof x !== 'undefined';
  576.         })
  577.         var real_income = 0;
  578.         for (var i = 0; i < real_inc.length; i++) {
  579.             real_income = real_income + parseInt(real_inc[i]);
  580.         }
  581.  
  582.  
  583.         var perspective_act = rows.map(function(row) {
  584.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  585.                 return row.sum
  586.             }
  587.         }).filter(function(x) {
  588.             return typeof x !== 'undefined';
  589.         })
  590.         var perspective_actual = 0;
  591.         for (var i = 0; i < perspective_act.length; i++) {
  592.             perspective_actual = perspective_actual + parseInt(perspective_act[i]);
  593.         }
  594.         var perspective_rea = rows.map(function(row) {
  595.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  596.                 return row.salesum
  597.             }
  598.         }).filter(function(x) {
  599.             return typeof x !== 'undefined';
  600.         })
  601.         var perspective_real = 0;
  602.         for (var i = 0; i < perspective_rea.length; i++) {
  603.             perspective_real = perspective_real + parseInt(perspective_rea[i]);
  604.         }
  605.  
  606.         var manager_salary = real_income * 0.2
  607.         var developer_salary = actual_income * 0.05
  608.  
  609.         $.json({
  610.             "rows": [{
  611.                 'tasks': rows.length,
  612.                 'not_payed': not_payed.length,
  613.                 'payed': payed.length,
  614.                 'in_development': in_development.length,
  615.                 'done': done.length,
  616.                 'ended': ended.length,
  617.                 're_edit': re_edit.length,
  618.                 'actual_income': actual_income,
  619.                 'real_income': real_income,
  620.                 'perspective_actual': perspective_actual,
  621.                 'perspective_real': perspective_real,
  622.                 'manager_salary': manager_salary,
  623.                 'developer_salry': developer_salary
  624.             }]
  625.         })
  626.     })
  627. })
  628.  
  629. app.get('/tasks.getsum', function($) {
  630.     connection.query("SELECT * FROM `get`.`tasks` WHERE 1", function(err, rows, fields) {
  631.         var not_payed = rows.map(function(row) {
  632.             if (row.status == '1') {
  633.                 return row.status
  634.             }
  635.         }).filter(function(x) {
  636.             return typeof x !== 'undefined';
  637.         })
  638.         var payed = rows.map(function(row) {
  639.             if (row.status == '2') {
  640.                 return row.status
  641.             }
  642.         }).filter(function(x) {
  643.             return typeof x !== 'undefined';
  644.         })
  645.         var in_development = rows.map(function(row) {
  646.             if (row.status == '3') {
  647.                 return row.status
  648.             }
  649.         }).filter(function(x) {
  650.             return typeof x !== 'undefined';
  651.         })
  652.         var done = rows.map(function(row) {
  653.             if (row.status == '4') {
  654.                 return row.status
  655.             }
  656.         }).filter(function(x) {
  657.             return typeof x !== 'undefined';
  658.         })
  659.         var ended = rows.map(function(row) {
  660.             if (row.status == '5') {
  661.                 return row.status
  662.             }
  663.         }).filter(function(x) {
  664.             return typeof x !== 'undefined';
  665.         })
  666.  
  667.         var re_edit = rows.map(function(row) {
  668.             if (row.status == '6') {
  669.                 return row.status
  670.             }
  671.         }).filter(function(x) {
  672.             return typeof x !== 'undefined';
  673.         })
  674.         var actual_inc = rows.map(function(row) {
  675.             if (row.status == '5') {
  676.                 return row.sum
  677.             }
  678.         }).filter(function(x) {
  679.             return typeof x !== 'undefined';
  680.         })
  681.         var actual_income = 0;
  682.         for (var i = 0; i < actual_inc.length; i++) {
  683.             actual_income = actual_income + parseInt(actual_inc[i]);
  684.         }
  685.  
  686.         var real_inc = rows.map(function(row) {
  687.             if (row.status == '5') {
  688.                 return row.salesum
  689.             }
  690.         }).filter(function(x) {
  691.             return typeof x !== 'undefined';
  692.         })
  693.         var real_income = 0;
  694.         for (var i = 0; i < real_inc.length; i++) {
  695.             real_income = real_income + parseInt(real_inc[i]);
  696.         }
  697.  
  698.  
  699.         var perspective_act = rows.map(function(row) {
  700.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  701.                 return row.sum
  702.             }
  703.         }).filter(function(x) {
  704.             return typeof x !== 'undefined';
  705.         })
  706.         var perspective_actual = 0;
  707.         for (var i = 0; i < perspective_act.length; i++) {
  708.             perspective_actual = perspective_actual + parseInt(perspective_act[i]);
  709.         }
  710.         var perspective_rea = rows.map(function(row) {
  711.             if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
  712.                 return row.salesum
  713.             }
  714.         }).filter(function(x) {
  715.             return typeof x !== 'undefined';
  716.         })
  717.         var perspective_real = 0;
  718.         for (var i = 0; i < perspective_rea.length; i++) {
  719.             perspective_real = perspective_real + parseInt(perspective_rea[i]);
  720.         }
  721.  
  722.         var manager_salary = real_income * 0.2
  723.         var developer_salary = actual_income * 0.05
  724.  
  725.         $.json({
  726.             "rows": [{
  727.                 'tasks': rows.length,
  728.                 'not_payed': not_payed.length,
  729.                 'payed': payed.length,
  730.                 'in_development': in_development.length,
  731.                 'done': done.length,
  732.                 'ended': ended.length,
  733.                 're_edit': re_edit.length,
  734.                 'actual_income': actual_income,
  735.                 'real_income': real_income,
  736.                 'perspective_actual': perspective_actual,
  737.                 'perspective_real': perspective_real,
  738.                 'manager_salary': manager_salary,
  739.                 'developer_salry': developer_salary
  740.             }]
  741.         })
  742.     })
  743. })
  744. app.get('/task.new', function($) {
  745.     connection.query("INSERT INTO `get`.`tasks`(`name`, `about`, `manager_id`, `client_id`, `developer_id`, `category`, `sub`, `status`, `sum`, `salesum`, `date`, `exp_date`) VALUES (" + connection.escape($.query.name) + ", " + connection.escape($.query.about) + ", " + connection.escape($.query.man_id) + ", " + connection.escape($.query.client_id) + ", " + connection.escape($.query.dev_id) + ", " + connection.escape($.query.cat) + ", " + connection.escape($.query.dops) + ", " + connection.escape($.query.status) + ", " + connection.escape($.query.pay_price) + ", " + connection.escape($.query.sale_sum) + ", CURRENT_DATE(), " + connection.escape($.query.exp_date) + ")", function(err, rows, fields) {
  746.         if (!err) {
  747.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  748.             $.end('Success')
  749.         } else {
  750.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  751.             $.end(err + "<br>" + rows)
  752.         }
  753.     })
  754. })
  755. //users
  756. app.get('/user.add', function($) {
  757.     connection.query("INSERT INTO `get`.`tbl_users`(`userName`, `userEmail`, `userPass`, `userStatus`, `group`, `tokenCode`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.mail) + "," + connection.escape($.query.pass) + ", 'Y', " + connection.escape($.query.group) + "," + connection.escape($.query.token) + ")", function(err, rows, fields) {
  758.         if (!err) {
  759.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  760.             $.end('Success')
  761.         } else {
  762.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  763.             $.end(err)
  764.         }
  765.     })
  766. })
  767. app.get('/users.get', function($) {
  768.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userStatus` = 'Y'", function(err, rows, fields) {
  769.         $.json({
  770.             rows
  771.         })
  772.     })
  773. })
  774. app.get('/users.getbyid', function($) {
  775.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userID` =" + connection.escape($.query.id), function(err, rows, fields) {
  776.         $.json({
  777.             rows
  778.         })
  779.     })
  780. })
  781. app.get('/users.getsum', function($) {
  782.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE 1", function(err, rows, fields) {
  783.         var developers = rows.map(function(row) {
  784.             if (row.group == 'developer') {
  785.                 return row.group
  786.             }
  787.         }).filter(function(x) {
  788.             return typeof x !== 'undefined';
  789.         })
  790.         var managers = rows.map(function(row) {
  791.             if (row.group == 'manager') {
  792.                 return row.group
  793.             }
  794.         }).filter(function(x) {
  795.             return typeof x !== 'undefined';
  796.         })
  797.         var admins = rows.map(function(row) {
  798.             if (row.group == 'admin') {
  799.                 return row.group
  800.             }
  801.         }).filter(function(x) {
  802.             return typeof x !== 'undefined';
  803.         })
  804.  
  805.         $.json({
  806.             "rows": [{
  807.                 'users': rows.length,
  808.                 'developers': developers.length,
  809.                 'managerts': managers.length,
  810.                 'admins': admins.length
  811.  
  812.             }]
  813.         })
  814.     })
  815. })
  816. app.get('/users.getin', function($) {
  817.     connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userStatus` = 'N'", function(err, rows, fields) {
  818.         $.json({
  819.             rows
  820.         })
  821.     })
  822. })
  823. app.get('/user.update', function($) {
  824.     connection.query("UPDATE `get`.`tbl_users` SET `userName`=" + connection.escape($.query.name) + ",`userEmail`=" + connection.escape($.query.email) + ",`group`=" + connection.escape($.query.group) + " WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
  825.         if (!err) {
  826.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  827.             $.end('Success')
  828.         } else {
  829.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  830.             $.end(err)
  831.         }
  832.     })
  833. })
  834. app.get('/user.inactive', function($) {
  835.     connection.query("UPDATE `get`.`tbl_users` SET `userStatus`= 'N' WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
  836.         if (!err) {
  837.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  838.             $.end('Success')
  839.         } else {
  840.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  841.             $.end(err)
  842.         }
  843.     })
  844. })
  845. app.get('/user.active', function($) {
  846.     connection.query("UPDATE `get`.`tbl_users` SET `userStatus`= 'Y' WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
  847.         if (!err) {
  848.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  849.             $.end('Success')
  850.         } else {
  851.             $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
  852.             $.end(err)
  853.         }
  854.     })
  855. })
  856.  
  857. function conn() {
  858.     connection.query("SELECT * FROM `get`.`history` WHERE  1", function(err, rows, fields) {
  859.         console.log(rows)
  860.     })
  861. }
  862. setInterval(conn, 24000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement