Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getDateTime() {
- var date = new Date();
- var hour = date.getHours();
- hour = (hour < 10 ? "0" : "") + hour;
- var min = date.getMinutes();
- min = (min < 10 ? "0" : "") + min;
- var sec = date.getSeconds();
- sec = (sec < 10 ? "0" : "") + sec;
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- month = (month < 10 ? "0" : "") + month;
- var day = date.getDate();
- day = (day < 10 ? "0" : "") + day;
- return year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;
- }
- var Firebird = require('node-firebird');
- var options = {};
- // options.host = '127.0.0.1';
- options.host = '192.168.1.241';
- options.port = 3050;
- // options.database = '/Applications/Fishbowl/database/data/EXAMPLE.FDB';
- options.database = 'C:/Program Files/Fishbowl/database/data/HYSON1.FDB';
- options.user = 'gone';
- options.password = 'fishing';
- var sqlQTY = 'SELECT PRODUCT.ID, (SELECT SUM (QTYALLOCATED) FROM QTYINVENTORYTOTALS WHERE QTYINVENTORYTOTALS.PARTID = PRODUCT.PARTID) as QTYALLOCATED FROM PRODUCT';
- var sqlProd = 'SELECT PRODUCT.*, UOM.CODE, (SELECT SUM (QTYONHAND) FROM QTYINVENTORYTOTALS WHERE QTYINVENTORYTOTALS.PARTID = PRODUCT.PARTID) as qty FROM PRODUCT, UOM WHERE UOM.ID = PRODUCT.UOMID';
- var sqlCUSTOMFIELD = 'SELECT CUSTOMVARCHAR.INFO, CUSTOMVARCHAR.RECORDID, CUSTOMFIELD.NAME FROM CUSTOMVARCHAR, CUSTOMFIELD WHERE CUSTOMFIELD.ID = CUSTOMVARCHAR.CUSTOMFIELDID';
- var sqlOUT = "SELECT PRICINGRULE.PRODUCTINCLID AS ID, PRICINGRULE.PAAMOUNT AS OUT FROM PRICINGRULE WHERE DESCRIPTION = 'Out of State'";
- function runSQL() {
- var SEND = {};
- var CUSTOMFIELD = [];
- var QTY = [];
- var OUT = [];
- var Prod = [];
- var text = 'Connect to DB';
- $('#status').html(text);
- Firebird.attach(options, function(err, db) {
- if (err){
- text = text + ' ERROR Time ' + getDateTime();
- $('#status').html(text);
- $('#error').html($('#status').html());
- throw err;
- }
- // db = DATABASE
- text = text + '<br />QUERY 1';
- $('#status').html(text);
- db.query(sqlCUSTOMFIELD, function(err, result) {
- if (err){
- text = text + ' ERROR Time ' + getDateTime();
- $('#status').html(text);
- $('#error').html($('#status').html());
- throw err;
- }
- for (var i = 0; i < result.length; i++) {
- var INFO = new TextDecoder("utf-8").decode(result[i].INFO);
- var NAME = new TextDecoder("utf-8").decode(result[i].NAME);
- CUSTOMFIELD.push({"INFO": INFO, "NAME": NAME, "RECORDID": result[i].RECORDID});
- }
- text = text + '<br />QUERY 2';
- $('#status').html(text);
- db.query(sqlQTY, function(err, result) {
- if (err){
- text = text + ' ERROR Time ' + getDateTime();
- $('#status').html(text);
- $('#error').html($('#status').html());
- throw err;
- }
- for (var i = 0; i < result.length; i++) {
- var item = {
- "PARTID": result[i].PARTID,
- "QTYALLOCATED": result[i].QTYALLOCATED
- };
- QTY.push(item);
- }
- text = text + '<br />QUERY 3';
- $('#status').html(text);
- db.query(sqlOUT, function(err, result) {
- if (err){
- text = text + ' ERROR Time ' + getDateTime();
- $('#status').html(text);
- $('#error').html($('#status').html());
- throw err;
- }
- for (var i = 0; i < result.length; i++) {
- var item = {
- "PARTID": result[i].ID,
- "OUT": result[i].OUT
- };
- OUT.push(item);
- }
- text = text + '<br />QUERY 4';
- $('#status').html(text);
- db.query(sqlProd, function(err, result) {
- if (err){
- text = text + ' ERROR Time ' + getDateTime();
- $('#status').html(text);
- $('#error').html($('#status').html());
- throw err;
- }
- for (var i = 0; i < result.length; i++) {
- if (result[i].ACTIVEFLAG == 1) {
- var NUM = '';
- if (result[i].NUM !== null) {
- if (result[i].NUM.length > 0) {
- NUM = new TextDecoder("utf-8").decode(result[i].NUM);
- } else {
- NUM = result[i].NUM;
- }
- }
- var DESCRIPTION = '';
- if (result[i].DESCRIPTION !== null) {
- if (result[i].DESCRIPTION.length > 0) {
- DESCRIPTION = new TextDecoder("utf-8").decode(result[i].DESCRIPTION);
- } else {
- DESCRIPTION = result[i].DESCRIPTION;
- }
- }
- var WEIGHT = '';
- if (result[i].WEIGHT !== null) {
- if (result[i].WEIGHT.length > 0) {
- WEIGHT = new TextDecoder("utf-8").decode(result[i].WEIGHT);
- } else {
- WEIGHT = result[i].WEIGHT;
- }
- }
- var UOM = '';
- if (result[i].CODE !== null) {
- if (result[i].CODE.length > 0) {
- UOM = new TextDecoder("utf-8").decode(result[i].CODE);
- } else {
- UOM = result[i].UOM;
- }
- }
- Prod.push({"PARTID": result[i].ID, "UOM": UOM, "NUM": NUM, "DESCRIPTION": DESCRIPTION, "WEIGHT": WEIGHT, "PRICE": result[i].PRICE, "QTY": result[i].QTY});
- }
- }
- db.detach();
- SEND.time = getDateTime();
- SEND.prod = JSON.stringify(Prod);
- SEND.QTY = JSON.stringify(QTY);
- SEND.OUT = JSON.stringify(OUT);
- SEND.CUSTOMFIELD = JSON.stringify(CUSTOMFIELD);
- text = text + '<br />SENDING TO SERVER';
- $('#status').html(text);
- $.post('http://teariver-allequipped.rhcloud.com/fishApi.php', {send: SEND}, function(d, textStatus, xhr) {
- text = text + ' OK';
- $('#status').html(text);
- });
- });
- });
- });
- });
- });
- }
- window.onload = function() {
- $('.green').click(function(event) {
- runSQL();
- });
- setTimeout(runSQL, 5000);
- var interval = setInterval(function() {
- runSQL();
- }, 900000);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement