modify gl multi for jpath and lines and add post route as well

This commit is contained in:
Paul Trowbridge 2018-09-27 02:39:14 -04:00
parent f4ba1fbfd2
commit 4e7bbe1125

View File

@ -38,7 +38,7 @@ Postgres.FirstRow = function(inSQL,args, inResponse)
inResponse.json(res.rows[0]); inResponse.json(res.rows[0]);
return; return;
} }
inResponse.json(err.message); inResponse.json(err.stack);
}); });
}; };
Postgres.connect(); Postgres.connect();
@ -193,20 +193,56 @@ server.get("/doc_add_gl_offset_multi", bodyParser.json(), function (inReq, inRes
var l = 0; var l = 0;
console.log(inReq.body); console.log(inReq.body);
x = inReq.body; x = inReq.body;
x.GL = []; x.gl = {};
x.gl.lines = [];
x.gl.jpath = [];
for (var i in x.item){ for (var i in x.item){
var line = x.item[i]; var line = x.item[i];
x.GL.push(line); x.gl.lines.push(line);
var ref = [];
ref.push("{item,"+i+"}");
ref.push("{header}");
x.gl.jpath.push(ref);
//copy the existing line to the GL array //copy the existing line to the GL array
var ofs = JSON.parse(JSON.stringify(line)); var ofs = JSON.parse(JSON.stringify(line));
ofs.account = x.header.offset_account; ofs.account = x.header.account;
ofs.amount = -ofs.amount; ofs.amount = -ofs.amount;
//add another line the GL array using the offset account //add another line the GL array using the offset account
x.GL.push(ofs); x.gl.lines.push(ofs);
x.gl.jpath.push(ref);
} }
inRes.json(x); inRes.json(x);
}); });
//add ledger array and create offset account for every line
server.get("/add_gl_multi_and_post", bodyParser.json(), function (inReq, inRes)
{
var l = 0;
console.log(inReq.body);
x = inReq.body;
x.gl = {};
x.gl.lines = [];
x.gl.jpath = [];
for (var i in x.item){
var line = x.item[i];
x.gl.lines.push(line);
var ref = [];
ref.push("{item,"+i+"}");
ref.push("{header}");
x.gl.jpath.push(ref);
//copy the existing line to the GL array
var ofs = JSON.parse(JSON.stringify(line));
ofs.account = x.header.account;
ofs.amount = -ofs.amount;
//add another line the GL array using the offset account
x.gl.lines.push(ofs);
x.gl.jpath.push(ref);
}
var sql = "INSERT INTO evt.bpr (bpr) SELECT $1";
console.log(JSON.stringify(x));
Postgres.FirstRow(sql,[JSON.stringify(x)], inRes);
});
//add ledger array and create offset account for total of all lines //add ledger array and create offset account for total of all lines
server.get("/doc_add_gl_offset_single", bodyParser.json(), function (inReq, inRes) server.get("/doc_add_gl_offset_single", bodyParser.json(), function (inReq, inRes)
{ {
@ -230,8 +266,8 @@ server.get("/doc_add_gl_offset_single", bodyParser.json(), function (inReq, inRe
} }
if (bomb == false) { if (bomb == false) {
var ofs = JSON.parse(JSON.stringify(x.header)); var ofs = JSON.parse(JSON.stringify(x.header));
ofs.account = ofs.offset_account; ofs.account = ofs.account;
delete ofs.offset_account; delete ofs.account;
ofs.amount = -tot; ofs.amount = -tot;
x.GL.push(ofs); x.GL.push(ofs);
} }