Uitwisseling met Gheeraert transport
This commit is contained in:
1 parent
fd27956fe5
commit
b140307141
1 file changed
+220
@@ -0,0 +1,220 @@
|
||||
{
|
||||
"name": "Gheereart Workflow 1 - orders export",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "// n8n Code node: Transpas TPE XML -> Gheeraert XML\n// Mode: Run Once for All Items\n//\n// Verwacht:\n// - TPE XML als binary property \"data\"\n// OF\n// - XML tekst in json.xml / json.data / json.body\n//\n// Output:\n// - 1 Gheeraert XML-bestand per <shipment>\n// - binary property: data\n\n// ---------- CONFIG ----------\nconst CONFIG = {\n INPUT_BINARY_PROPERTY: 'data',\n OUTPUT_BINARY_PROPERTY: 'data',\n\n FILE_PREFIX: 'PORTAL',\n\n BILL_TO: {\n name: 'De Wit Transport & Logistics',\n street: '',\n pc: '',\n city: '',\n country: 'NL',\n phone: '',\n email: '',\n comment: '',\n vat: 'NL007697168B01',\n },\n\n TRANSPORT_TYPE: 'SHIPMENT',\n\n DEFAULT_GOOD_CODE: 'PALLDM',\n GOOD_CODE_MAP: {\n 'EUROPALLET': 'EUR',\n 'EURO PALLET': 'EUR',\n 'EUR': 'EUR',\n\n 'BLOKPALLET': 'BLOK',\n 'BLOK PALLET': 'BLOK',\n 'BLOK': 'BLOK',\n\n 'PALLETS': 'PALLDM',\n 'PALLET': 'PALLDM',\n 'VRACHT': 'PALLDM',\n 'COLLI': 'COLLI',\n\n 'CC-TAG6': 'CC',\n 'CC TAG6': 'CC',\n },\n\n FIXED_HOUR_WHEN_EXACT_TIME: false,\n};\n\n// ---------- XML HELPERS ----------\nconst AMP_FIX_RE = /&(?!amp;|lt;|gt;|quot;|apos;|#\\d+;|#x[0-9A-Fa-f]+;)/g;\n\nfunction xmlEsc(value) {\n return String(value ?? '')\n .replace(AMP_FIX_RE, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\nfunction xmlDecode(value) {\n return String(value ?? '')\n .replace(/&#x([0-9a-fA-F]+);/g, (_, h) => String.fromCodePoint(parseInt(h, 16)))\n .replace(/&#(\\d+);/g, (_, d) => String.fromCodePoint(parseInt(d, 10)))\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/&/g, '&');\n}\n\nfunction clean(value) {\n return xmlDecode(value)\n .replace(/\\r\\n/g, '\\n')\n .replace(/\\r/g, '\\n')\n .split('\\n')\n .map(s => s.trim())\n .filter(Boolean)\n .join('\\n')\n .trim();\n}\n\nfunction firstBlock(xmlText, tag) {\n const re = new RegExp(`<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/${tag}>`, 'i');\n const m = String(xmlText || '').match(re);\n return m ? m[1] : '';\n}\n\nfunction allBlocks(xmlText, tag) {\n const re = new RegExp(`<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/${tag}>`, 'gi');\n const out = [];\n let m;\n while ((m = re.exec(String(xmlText || ''))) !== null) {\n out.push(m[1]);\n }\n return out;\n}\n\nfunction tagText(xmlText, tag) {\n const re = new RegExp(`<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/${tag}>|<${tag}\\\\b[^>]*/>`, 'i');\n const m = String(xmlText || '').match(re);\n if (!m) return '';\n return clean(m[1] || '');\n}\n\nfunction allTagTexts(xmlText, tag) {\n const re = new RegExp(`<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/${tag}>`, 'gi');\n const out = [];\n let m;\n while ((m = re.exec(String(xmlText || ''))) !== null) {\n const value = clean(m[1] || '');\n if (value) out.push(value);\n }\n return out;\n}\n\nfunction isTrueFlag(value) {\n const v = String(value ?? '').trim().toLowerCase();\n return ['true', '1', 'yes', 'ja', 'y'].includes(v);\n}\n\nfunction boolText(value) {\n return isTrueFlag(value) ? 'true' : 'false';\n}\n\nfunction isBeneluxCountry(country) {\n const c = String(country || '').trim().toUpperCase();\n return ['NL', 'BE', 'LU'].includes(c);\n}\n\nfunction formatDate(value) {\n const v = String(value ?? '').trim();\n if (!v) return '';\n\n const iso = v.match(/^(\\d{4})-(\\d{2})-(\\d{2})/);\n if (iso) return `${iso[3]}/${iso[2]}/${iso[1]}`;\n\n const dmy = v.match(/^(\\d{2})\\/(\\d{2})\\/(\\d{4})$/);\n if (dmy) return v;\n\n return v;\n}\n\nfunction formatTime(value) {\n const v = String(value ?? '').trim();\n if (!v) return '';\n\n const m = v.match(/^(\\d{1,2}):(\\d{2})/);\n if (!m) return '';\n\n return `${m[1].padStart(2, '0')}:${m[2]}`;\n}\n\nfunction minutes(value) {\n const t = formatTime(value);\n if (!t) return null;\n\n const [h, m] = t.split(':').map(Number);\n return h * 60 + m;\n}\n\nfunction numberText(value, fallback = '') {\n const v = String(value ?? '').trim().replace(',', '.');\n if (!v) return fallback;\n\n const n = Number(v);\n return Number.isFinite(n) ? String(n) : fallback;\n}\n\nfunction integerText(value, fallback = '') {\n const v = String(value ?? '').trim().replace(',', '.');\n if (!v) return fallback;\n\n const n = Number(v);\n return Number.isFinite(n) ? String(Math.round(n)) : fallback;\n}\n\nfunction safeFilePart(value) {\n return String(value || '')\n .replace(/[^a-zA-Z0-9._-]+/g, '_')\n .replace(/^_+|_+$/g, '')\n .slice(0, 80) || 'shipment';\n}\n\nfunction nowStamp() {\n const d = new Date();\n const p = n => String(n).padStart(2, '0');\n\n return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}_${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}_${String(d.getMilliseconds()).padStart(3, '0')}`;\n}\n\nfunction uniqueSuffix(index) {\n reLine truncated
|
||||
},
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
-384,
|
||||
-128
|
||||
],
|
||||
"id": "3e4ddb57-9298-4a1b-b486-ccb8a595d979",
|
||||
"name": "Code in JavaScript"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"path": "={{ $json.path }}",
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.ftp",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
-848,
|
||||
-128
|
||||
],
|
||||
"id": "05f19f00-8d96-469a-ad3d-d67e4d44a69e",
|
||||
"name": "Download file",
|
||||
"credentials": {
|
||||
"ftp": {
|
||||
"id": "oLAZ4OgmkOopMHAq",
|
||||
"name": "FTP De Wit Transport"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"rule": {
|
||||
"interval": [
|
||||
{
|
||||
"field": "cronExpression",
|
||||
"expression": "*/15 6-22 * * 1-5"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.scheduleTrigger",
|
||||
"typeVersion": 1.2,
|
||||
"position": [
|
||||
-1280,
|
||||
-128
|
||||
],
|
||||
"id": "d651ca8c-2559-4824-af10-84782d60d8a3",
|
||||
"name": "Schedule Trigger"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "list",
|
||||
"path": "/prod/FromTP/tpe_export/",
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.ftp",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
-1056,
|
||||
-128
|
||||
],
|
||||
"id": "e26a6649-67a5-4e2b-949a-fec7ef8b5ad3",
|
||||
"name": "List files",
|
||||
"credentials": {
|
||||
"ftp": {
|
||||
"id": "oLAZ4OgmkOopMHAq",
|
||||
"name": "FTP De Wit Transport"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "xml",
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
-608,
|
||||
-128
|
||||
],
|
||||
"id": "7dda404f-ba0f-4d7e-84f5-45fba7d9a9dd",
|
||||
"name": "Extract from File"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "INSERT INTO public.ghe_order_log (\n purchase_order_number,\n transpas_legnr,\n transpas_reference,\n file_name,\n file_uploaded_at,\n file_upload_status,\n next_status_poll_at\n)\nVALUES (\n $1::varchar,\n $2::varchar,\n $3::varchar,\n $4::varchar,\n CURRENT_TIMESTAMP,\n 'sent',\n CURRENT_TIMESTAMP + INTERVAL '10 minutes'\n)\nON CONFLICT (purchase_order_number)\nDO UPDATE SET\n transpas_legnr = EXCLUDED.transpas_legnr,\n transpas_reference = EXCLUDED.transpas_reference,\n file_name = EXCLUDED.file_name,\n file_uploaded_at = EXCLUDED.file_uploaded_at,\n file_upload_status = EXCLUDED.file_upload_status,\n file_upload_error = NULL,\n next_status_poll_at = EXCLUDED.next_status_poll_at;",
|
||||
"options": {
|
||||
"queryReplacement": "={{ $json.shipmentReference }}, {{ $json.shipmentEdiReference }}, {{ $json.tripReference }}, {{ $json.fileName }}"
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.postgres",
|
||||
"typeVersion": 2.6,
|
||||
"position": [
|
||||
32,
|
||||
-128
|
||||
],
|
||||
"id": "c4b0ec24-abc1-4916-84a2-a3aa3334f085",
|
||||
"name": "Execute a SQL query",
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "pxziuCOuNpsUFKrm",
|
||||
"name": "transpas_n8n_gheeraert"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"protocol": "sftp",
|
||||
"operation": "upload",
|
||||
"path": "=/IN/{{ $json.fileName }}",
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.ftp",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
-176,
|
||||
-128
|
||||
],
|
||||
"id": "91d2ac28-5258-468a-b14c-b5a7bbd44815",
|
||||
"name": "FTP",
|
||||
"credentials": {
|
||||
"sftp": {
|
||||
"id": "dDY78xgQa87mHl4J",
|
||||
"name": "FTP Gheeraert prod"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"pinData": {},
|
||||
"connections": {
|
||||
"Download file": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract from File",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Schedule Trigger": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "List files",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"List files": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Download file",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Extract from File": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Code in JavaScript",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Code in JavaScript": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "FTP",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"FTP": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Execute a SQL query",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1",
|
||||
"binaryMode": "separate"
|
||||
},
|
||||
"versionId": "97d8fd4d-3d5a-4492-ac09-66b1da5b35f7",
|
||||
"meta": {
|
||||
"templateCredsSetupCompleted": true,
|
||||
"instanceId": "bef8d409866a58c0777dfe7cca1b9c2400fd051c056d361501393ab423006b5f"
|
||||
},
|
||||
"nodeGroups": [],
|
||||
"id": "0E0ESANYP27dlue7",
|
||||
"tags": []
|
||||
}
|
||||
Reference in new issue
Block a user