separado en archivos

This commit is contained in:
Javi Gallego 2017-05-04 07:59:28 +02:00
parent 0d97923630
commit 327406a955
7 changed files with 9586 additions and 9544 deletions

25
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Iniciar programa",
"program": "${file}",
"outFiles": []
},
{
"type": "node",
"request": "attach",
"name": "Asociar al puerto",
"address": "localhost",
"port": 5858,
"outFiles": []
}
]
}

12
connection.js Normal file
View File

@ -0,0 +1,12 @@
var db = require('node-mysql');
var config = require('./config.json');
var vnConn = new db.DB({
host : config.mySqlHost,
user : config.mySqlUser,
password : config.mySqlPass,
port: config.mySqlPort,
database : config.mySqlDatabase
});
exports.vnConn = vnConn;

22
objectToTable.js Normal file
View File

@ -0,0 +1,22 @@
var connection = require('./connection');
var queries = require('./queries');
function objectToTable(supplyResponse){
connection.vnConn.connect(function(conn, cb) {
var sql = queries.getInsertSupply();
var insertRows = queries.getValuesSupply(supplyResponse);
conn.query(sql,[insertRows],
function(res, rows, fields) {
console.log(rows);
cb();
}
);
}, function(err){
console.log('ao');
console.log(err.message);
});
}
exports.objectToTable = objectToTable;

View File

@ -7,6 +7,7 @@
"dependencies": {
"fecha": "^2.3.0",
"jsdom": "^9.12.0",
"node-mysql": "^0.4.2",
"soap": "^0.19.0",
"xml2js": "^0.4.17"
}

43
queries.js Normal file
View File

@ -0,0 +1,43 @@
function getInsertSupply(){
var sql = `INSERT INTO edi.supplyResponse( \
marketPlace, \
imageReference, \
supplierParty, \
productVnhCode, \
productDescription, \
quantity, \
incrementalOrderableQuantity, \
chargeAmount, \
unitCode, \
packageQuantity, \
earliestDespatch, \
latestDelivery, \
) VALUES ?`;
return sql;
}
function getValuesSupply(supplyResponse){
var insertRows = [];
for (let aux of supplyResponse.Body.SupplyResponseDetails.SupplyTradeLineItem){
insertRows.push(
[
aux.ID._,
aux.TradingTerms.MarketPlace.ID._,
aux.SupplierParty.PrimaryID._ ,
aux.Product.IndustryAssignedID._,
aux.Product.DescriptionText._,
aux.Quantity._,
aux.IncrementalOrderableQuantity._,
aux.Price.ChargeAmount._,
aux.Quantity.$.unitCode,
aux.Packing.Package.Quantity._,
aux.Delivery[0].LatestDeliveryDateTime,
aux.Delivery[0].LatestDeliveryDateTime
]);
}
return insertRows;
}
exports.getInsertSupply = getInsertSupply;
exports.getValuesSupply = getValuesSupply;

View File

@ -1,61 +1,59 @@
var querystring = require("querystring");
var xml2js = require('xml2js');
var soap = require('soap');
var IOXml = require('./IOXml');
var config = require('./config.json');
var soap = require('soap');
var objectToTable = require('./objectToTable');
function soapClient(xmlFile){
var url = 'http://services2-acc.floraholland.com/CommercialCustomer/CommercialCustomer_1p5.svc?wsdl';
var auth = "Basic " + new Buffer(config.user + ":" + config.pass).toString("base64");
var options =
{
wsdl_headers:{
Authorization: auth
},
attributesKey: '$',
valueKey: '_'
};
soap.createClient(url,options, function(err, client) {
if (err) {
console.log(err);
return;
}
var url = 'http://services2-acc.floraholland.com/CommercialCustomer/CommercialCustomer_1p5.svc?wsdl';
var auth = "Basic " + new Buffer(config.user + ":" + config.pass).toString("base64");
var options =
{
wsdl_headers:{
Authorization: auth
},
attributesKey: '$',
valueKey: '_'
};
soap.createClient(url,options, function(err, client) {
if (err) {
console.log(err);
return;
}
client.setSecurity(new soap.BasicAuthSecurity(config.user,config.pass));
console.log('no entra');
IOXml.getXml(xmlFile, function(err, data) {
if (err) {
console.log('err');
console.log(err);
return;
}
var parser = new xml2js.Parser();
parser.parseString(data, function (err, result) {
//extractedData = result['config']['data'];
console.dir(result,{
showHidden:true,
depth:null,
colors:true
});
console.log('GetSupply');
console.log(result);
console.log(result.SupplyRequest);
client.GetSupply(result.SupplyRequest,function(err, supply) {
console.log('last request: ', client.lastRequest)
if (err) {
console.log(err.message);
client.setSecurity(new soap.BasicAuthSecurity(config.user,config.pass));
console.log('no entra');
IOXml.getXml(xmlFile, function(err, data) {
if (err) {
console.log('err');
console.log(err);
return;
}
var builder = new xml2js.Builder();
var fileContent = builder.buildObject(supply);
IOXml.setXml('/xml_buyer/supplyresponse_getall.xml',fileContent,function(){
console.log('archivo creado');
});
}
var parser = new xml2js.Parser();
parser.parseString(data, function (err, result) {
//extractedData = result['config']['data'];
console.dir(result,{
showHidden:true,
depth:null,
colors:true
});
client.GetSupply(result.SupplyRequest,function(err, supply) {
objectToTable.objectToTable(supply);
if (err) {
console.log(err.message);
return;
}
/* var builder = new xml2js.Builder();
var fileContent = builder.buildObject(supply);
IOXml.setXml('/xml_buyer/supplyresponse_getall.xml',fileContent,function(){
console.log('archivo creado');
});*/
});
});
});
});
});
});
}
soapClient('/xml_buyer/supplyrequest_getall.xml');
soapClient('/xml_buyer/supplyrequest_getall.xml');

File diff suppressed because it is too large Load Diff