[{"id":"6e9e4a88.0261c4","type":"tab","label":"Order Sync to ERP","disabled":false,"info":""},{"id":"78904ae2.44df94","type":"function","z":"6e9e4a88.0261c4","name":"Payload is not empty","func":" var SCBASICSYNC = global.get('appconfig').oracledbschema + `.` + global.get('appconfig').tableSCBASICSYNC;\n \n var orderbpmid = msg.payload.ORDERBPMID;\n var query = `select * from ` + SCBASICSYNC + ` where ORDERBPMID = '` + orderbpmid + `'`\n msg.payload.query = query;\n \n return msg;","outputs":1,"noerr":0,"x":840,"y":120,"wires":[["3616ad47.4b78e2","a8cef2f0.294d4"]]},{"id":"7e9b30c2.38f23","type":"http in","z":"6e9e4a88.0261c4","name":"","url":"/vaighaibpm/api/v1/order","method":"post","upload":false,"swaggerDoc":"","x":190,"y":320,"wires":[["99d55aeb.c99618","7c671e31.74dd3","e9313e2a.46105"]]},{"id":"82142567.202868","type":"inject","z":"6e9e4a88.0261c4","name":"","topic":"","payload":"{\"ORDERNUMBER\":\"VA-2859\",\"ORDERBPMID\":\"482e3042-6731-47d6-b397-a17bc7fad91f\",\"PARTYMASTID\":\"40344000058123\",\"PARTYMASTBMPID\":\"a16d7df8-f29c-48fe-a075-c515c489b123\",\"ITEMMASTERID\":\"\",\"ITEMMASTERBPMID\":\"f872197f-2dd7-4f03-8449-df54e3518123\",\"UNIT\":\"Metric Ton\",\"QTY\":\"0.3\",\"ABCGRADE\":\"\",\"RATE\":\"00\",\"AMOUNT\":\"00\",\"REMARKS\":\"\",\"DUEDATE\":\"2019-11-02T16:55:00\",\"ASTATUS\":\"Pending\",\"USERCTRL\":\"abc\",\"SALETYPE\":\"abc\",\"SECTOR\":\"abc\",\"SCBASICID\":\"0\",\"CONTRACTDOCID\":\"\",\"CONTRACTBPMID\":\"\",\"ORDSYNCSTATUS\":\"pending\",\"ITEMID\":\"OIL (4-7)\",\"ITEMDESC\":\"OIL: FFA (4-7)\",\"PRIUNIT\":\"10002000000123\",\"LASTUPDATED\":\"\",\"PLANT\":\"Madurai\",\"BRANCHMASTID\":\"40139000007123\",\"ORDERSYNCID\":\"123\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":240,"wires":[["99d55aeb.c99618","e9313e2a.46105"]]},{"id":"99d55aeb.c99618","type":"switch","z":"6e9e4a88.0261c4","name":"Checking SCBasicSync has same record","property":"payload","propertyType":"msg","rules":[{"t":"nempty"},{"t":"empty"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":160,"wires":[["78904ae2.44df94"],["980e025.79a3f"]]},{"id":"980e025.79a3f","type":"function","z":"6e9e4a88.0261c4","name":"Payload is empty","func":"var SCBASICSYNC = global.get('appconfig').oracledbschema + `.` + global.get('appconfig').tableSCBASICSYNC;\nreturn null;","outputs":1,"noerr":0,"x":830,"y":200,"wires":[["8041fedb.bdef8"]]},{"id":"e45e70e8.32a5a","type":"http response","z":"6e9e4a88.0261c4","name":"Failure response","statusCode":"400","headers":{},"x":550,"y":320,"wires":[]},{"id":"8041fedb.bdef8","type":"function","z":"6e9e4a88.0261c4","name":"Failure message","func":"msg.payload = {};\n\nmsg.payload.status=\"failed\";\n\nmsg.payload.message = \"Failed to Post data check input data\"\n\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":260,"wires":[["e45e70e8.32a5a"]]},{"id":"7c671e31.74dd3","type":"debug","z":"6e9e4a88.0261c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":290,"y":400,"wires":[]},{"id":"e9313e2a.46105","type":"link out","z":"6e9e4a88.0261c4","name":"","links":["56aac221.3df85c"],"x":335,"y":100,"wires":[]},{"id":"3616ad47.4b78e2","type":"debug","z":"6e9e4a88.0261c4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":950,"y":60,"wires":[]},{"id":"a8cef2f0.294d4","type":"oracle-db","z":"6e9e4a88.0261c4","name":"","x":1090,"y":220,"wires":[["c28afcb8.e34da","a576932c.476c6"]]},{"id":"c28afcb8.e34da","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1210,"y":140,"wires":[]},{"id":"9f5457ea.8184f8","type":"function","z":"6e9e4a88.0261c4","name":"Insert Query","func":"msg.action = 'Insert';\n\nvar SCBASICSYNC = global.get('appconfig').oracledbschema + `.` + global.get('appconfig').tableSCBASICSYNC;\n\nif (msg.payload) {\n node.log(\"msg.payload==>\" + JSON.stringify(msg.payload))\n var lastupdated= msg.payload.dateoutput;\n // node.log(\"lastupdated===>\" + lastupdated);\n var duedate = msg.payload.dueoutput;\n // node.log(\"duedate===>\" + duedate);\n\n // var values = `('` + msg.payload.ORDERBPMID + `','` + msg.payload.ORDERNUMBER + `',` + msg.payload.PARTYMASTID + `,\n // '` + msg.payload.PARTYMASTBMPID + `',` + msg.payload.ITEMMASTERID + `,'` + msg.payload.ITEMMASTERBPMID + `',\n // '` + msg.payload.UNIT + `',` + msg.payload.QTY + `,'` + msg.payload.ABCGRADE + `',` + msg.payload.RATE + `,\n // ` + msg.payload.AMOUNT + `,'` + msg.payload.REMARKS + `',TO_TIMESTAMP('` + duedate + `', 'YYYY-MM-DD HH24:MI:SS.FF'),\n // '` + msg.payload.ASTATUS + `','` + msg.payload.USERCTRL + `','` + msg.payload.SALETYPE + `','` + msg.payload.SECTOR + `',\n // ` + msg.payload.SCBASICID + `,'` + msg.payload.CONTRACTDOCID + `','` + msg.payload.CONTRACTBPMID + `',\n // '` + msg.payload.ORDSYNCSTATUS + `','` + msg.payload.ITEMID + `','` + msg.payload.ITEMDESC + `',\n // ` + msg.payload.PRIUNIT + `,TO_TIMESTAMP('` + lastupdated + `', 'YYYY-DD-MM HH24:MI:SS.FF'),\n // '` + msg.payload.PLANT + `',` + msg.payload.BRANCHMASTID + `, ` + msg.payload.ORDERSYNCID + ` )\n // `;\n var values = `('` + msg.payload.ORDERBPMID + `','` + msg.payload.ORDERNUMBER + `','` + msg.payload.PARTYMASTID + `',\n '` + msg.payload.PARTYMASTBMPID + `','` + msg.payload.ITEMMASTERID + `','` + msg.payload.ITEMMASTERBPMID + `',\n '` + msg.payload.UNIT + `',` + msg.payload.QTY + `,'` + msg.payload.ABCGRADE + `',` + msg.payload.RATE + `,\n ` + msg.payload.AMOUNT + `,'` + msg.payload.REMARKS + `',TO_TIMESTAMP('` + duedate + `', 'YYYY-MM-DD HH24:MI:SS.FF'),\n '` + msg.payload.ASTATUS + `','` + msg.payload.USERCTRL + `','` + msg.payload.SALETYPE + `','` + msg.payload.SECTOR + `',\n '` + msg.payload.SCBASICID + `','` + msg.payload.CONTRACTDOCID + `','` + msg.payload.CONTRACTBPMID + `',\n '` + msg.payload.ORDSYNCSTATUS + `','` + msg.payload.ITEMID + `','` + msg.payload.ITEMDESC + `',\n '` + msg.payload.PRIUNIT + `',TO_TIMESTAMP('` + lastupdated + `', 'YYYY-DD-MM HH24:MI:SS.FF'),\n '` + msg.payload.PLANT + `','` + msg.payload.BRANCHMASTID + `', '` + msg.payload.ORDERSYNCID + `')`;\n\n var query = `INSERT INTO ` + SCBASICSYNC + `(ORDERBPMID, ORDERNUMBER, PARTYMASTID, PARTYMASTBMPID, ITEMMASTERID,\n ITEMMASTERBPMID, UNIT, QTY, ABCGRADE, RATE, AMOUNT, REMARKS, DUEDATE, ASTATUS, USERCTRL, SALETYPE, SECTOR, SCBASICID,\n CONTRACTDOCID, CONTRACTBPMID,ORDSYNCSTATUS,ITEMID,ITEMDESC,PRIUNIT,LASTUPDATED,PLANT,BRANCHMASTID,ORDERSYNCID) VALUES ` + values;\n\n msg.payload.query = query;\n // node.log(\"queryResult===>\", msg.payload.query);\n \n\n}\n return msg;\n","outputs":1,"noerr":0,"x":490,"y":660,"wires":[["d03c291b.f51cd8","49ee800d.c3c47"]]},{"id":"d03c291b.f51cd8","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":670,"y":620,"wires":[]},{"id":"49ee800d.c3c47","type":"oracle-db","z":"6e9e4a88.0261c4","name":"","x":770,"y":700,"wires":[["25476c8c.c007f4","1a533e2d.840c42"]]},{"id":"295b7b61.e9e194","type":"http response","z":"6e9e4a88.0261c4","name":"Response","statusCode":"200","headers":{},"x":980,"y":800,"wires":[]},{"id":"25476c8c.c007f4","type":"function","z":"6e9e4a88.0261c4","name":"Set response","func":"\nvar res = {};\n\nvar message ='';\n\nmessage = msg.action == 'Insert' ? 'Order Inserted succesfully':'Order Updated Succesfully'\n\nres.status = 'success';\n\nres.message = message\n\nmsg.payload = res;\n\nreturn msg;","outputs":1,"noerr":0,"x":970,"y":700,"wires":[["295b7b61.e9e194","8856fc1f.c5807"]]},{"id":"1a533e2d.840c42","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":640,"wires":[]},{"id":"a2ca86b.679dd78","type":"function","z":"6e9e4a88.0261c4","name":"Update Query","func":"\nmsg.action = 'Update';\n\nvar SCBASICSYNC = global.get('appconfig').oracledbschema + `.` + global.get('appconfig').tableSCBASICSYNC;\n\nif (msg.payload) {\n \n var lastupdated= msg.payload.dateoutput;\n // node.log(\"lastupdated===>\", +lastupdated);\n var duedate = msg.payload.dueoutput;\n \n msg.payload.query = '';\n\n var query = `UPDATE ` + SCBASICSYNC + ` SET ORDERNUMBER ='` + msg.payload.ORDERNUMBER + `', \n PARTYMASTID = '` + msg.payload.PARTYMASTID + `', PARTYMASTBMPID = '` + msg.payload.PARTYMASTBMPID + `', ITEMMASTERID = '` + msg.payload.ITEMMASTERID + `', \n ITEMMASTERBPMID = '` + msg.payload.ITEMMASTERBPMID + `', UNIT = '` + msg.payload.UNIT + `', QTY = ` + msg.payload.QTY + `, \n ABCGRADE = '` + msg.payload.ABCGRADE + `',\n RATE = ` + msg.payload.RATE + `, AMOUNT = ` + msg.payload.AMOUNT + `, REMARKS = '` + msg.payload.REMARKS + `',\n DUEDATE = TO_TIMESTAMP('` + duedate + `', 'YYYY-MM-DD HH24:MI:SS.FF'), \n ASTATUS = '` + msg.payload.ASTATUS + `', USERCTRL = '` + msg.payload.USERCTRL + `', SALETYPE = '` + msg.payload.SALETYPE + `',\n SECTOR = '` + msg.payload.SECTOR + `', SCBASICID = '` + msg.payload.SCBASICID + `', CONTRACTDOCID = '` + msg.payload.CONTRACTDOCID + `',\n CONTRACTBPMID = '` + msg.payload.CONTRACTBPMID + `',ORDSYNCSTATUS = '` + msg.payload.ORDSYNCSTATUS + `',\n ITEMID = '` + msg.payload.ITEMID + `',ITEMDESC = '` + msg.payload.ITEMDESC + `',\n PRIUNIT = '` + msg.payload.PRIUNIT + `',LASTUPDATED = TO_TIMESTAMP('` + lastupdated + `', 'YYYY-DD-MM HH24:MI:SS.FF'),\n PLANT = '` + msg.payload.PLANT + `', BRANCHMASTID = '` + msg.payload.BRANCHMASTID + `', ORDERSYNCID = '` + msg.payload.ORDERSYNCID + `'\n WHERE ORDERBPMID = '` + msg.payload.ORDERBPMID + `' `;\n \n// PARTYMASTID = ` + msg.payload.PARTYMASTID + `, PARTYMASTBMPID = '` + msg.payload.PARTYMASTBMPID + `', ITEMMASTERID = ` + msg.payload.ITEMMASTERID + `, \n// ITEMMASTERBPMID = '` + msg.payload.ITEMMASTERBPMID + `', UNIT = '` + msg.payload.UNIT + `', QTY = ` + msg.payload.QTY + `, \n// ABCGRADE = '` + msg.payload.ABCGRADE + `',\n// RATE = ` + msg.payload.RATE + `, AMOUNT = ` + msg.payload.AMOUNT + `, REMARKS = '` + msg.payload.REMARKS + `',\n// DUEDATE = TO_TIMESTAMP('` + duedate + `', 'YYYY-MM-DD HH24:MI:SS.FF'), \n// ASTATUS = '` + msg.payload.ASTATUS + `', USERCTRL = '` + msg.payload.USERCTRL + `', SALETYPE = '` + msg.payload.SALETYPE + `',\n// SECTOR = '` + msg.payload.SECTOR + `', SCBASICID = ` + msg.payload.SCBASICID + `, CONTRACTDOCID = '` + msg.payload.CONTRACTDOCID + `',\n// CONTRACTBPMID = '` + msg.payload.CONTRACTBPMID + `',ORDSYNCSTATUS = '` + msg.payload.ORDSYNCSTATUS + `',\n// ITEMID = '` + msg.payload.ITEMID + `',ITEMDESC = '` + msg.payload.ITEMDESC + `',\n// PRIUNIT = ` + msg.payload.PRIUNIT + `,LASTUPDATED = TO_TIMESTAMP('` + lastupdated + `', 'YYYY-DD-MM HH24:MI:SS.FF'),\n// PLANT = '` + msg.payload.PLANT + `', BRANCHMASTID = ` + msg.payload.BRANCHMASTID + `, ORDERSYNCID = ` + msg.payload.ORDERSYNCID + `\n// WHERE ORDERBPMID = '` + msg.payload.ORDERBPMID + `' `;\n// // TO_TIMESTAMP('` + duedate + `', 'YYYY-MM-DD HH24:MI:SS.FF')\n\n msg.payload.query = query;\n\n return msg;\n\n}\n","outputs":1,"noerr":0,"x":480,"y":760,"wires":[["9e39df1c.ee48e","49ee800d.c3c47"]]},{"id":"9e39df1c.ee48e","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":840,"wires":[]},{"id":"a6d6b465.e03bb8","type":"switch","z":"6e9e4a88.0261c4","name":"Deciding Insert and Update","property":"responsedata.length","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":220,"y":720,"wires":[["9f5457ea.8184f8"],["a2ca86b.679dd78"]]},{"id":"2126e034.72074","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1130,"y":360,"wires":[]},{"id":"8856fc1f.c5807","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1161.6666666666665,"y":663.3333333333333,"wires":[]},{"id":"b8d60623.93c718","type":"debug","z":"6e9e4a88.0261c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":870,"y":520,"wires":[]},{"id":"a576932c.476c6","type":"moment","z":"6e9e4a88.0261c4","name":"","topic":"","input":"","inputType":"date","inTz":"Asia/Calcutta","adjAmount":0,"adjType":"hours","adjDir":"add","format":"YYYY-DD-MM HH:mm:ss","locale":"en_US","output":"payload.dateoutput","outputType":"msg","outTz":"Asia/Calcutta","x":900,"y":360,"wires":[["2126e034.72074","17c74a15.b7dc76","17c74a15.b7dc76"]],"outputLabels":["YYYY DD MM HH:mm:ss"]},{"id":"17c74a15.b7dc76","type":"moment","z":"6e9e4a88.0261c4","name":"","topic":"","input":"payload.DUEDATE","inputType":"msg","inTz":"Asia/Calcutta","adjAmount":0,"adjType":"hours","adjDir":"add","format":"YYYY-MM-DD HH:mm:ss","locale":"en_US","output":"payload.dueoutput","outputType":"msg","outTz":"Asia/Calcutta","x":520,"y":500,"wires":[["a6d6b465.e03bb8","b8d60623.93c718"]],"outputLabels":["YYYY DD MM HH:mm:ss"]}]