repzo-sap-absjo 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +2 -0
- package/lib/actions/create_invoice.d.ts +19 -13
- package/lib/actions/create_invoice.js +356 -208
- package/lib/actions/create_payment.d.ts +4 -1
- package/lib/actions/create_payment.js +191 -117
- package/lib/actions/create_proforma.d.ts +4 -1
- package/lib/actions/create_proforma.js +285 -155
- package/lib/actions/create_return_invoice.d.ts +4 -1
- package/lib/actions/create_return_invoice.js +312 -169
- package/lib/actions/create_transfer.d.ts +4 -1
- package/lib/actions/create_transfer.js +223 -136
- package/lib/actions/index.js +23 -15
- package/lib/commands/adjust_inventory.d.ts +4 -2
- package/lib/commands/adjust_inventory.js +290 -160
- package/lib/commands/bank.d.ts +4 -2
- package/lib/commands/bank.js +279 -157
- package/lib/commands/basic.js +66 -47
- package/lib/commands/category.d.ts +3 -1
- package/lib/commands/category.js +178 -104
- package/lib/commands/channel.d.ts +3 -1
- package/lib/commands/channel.js +198 -117
- package/lib/commands/client.d.ts +34 -32
- package/lib/commands/client.js +404 -244
- package/lib/commands/client_disabled.d.ts +3 -1
- package/lib/commands/client_disabled.js +163 -94
- package/lib/commands/index.d.ts +15 -11
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +192 -66
- package/lib/commands/measureunit.d.ts +19 -14
- package/lib/commands/measureunit.js +289 -191
- package/lib/commands/measureunit_family.d.ts +10 -8
- package/lib/commands/measureunit_family.js +250 -138
- package/lib/commands/payment_term.d.ts +3 -1
- package/lib/commands/payment_term.js +202 -123
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +612 -326
- package/lib/commands/product.d.ts +32 -30
- package/lib/commands/product.js +426 -243
- package/lib/commands/product_disabled.d.ts +3 -1
- package/lib/commands/product_disabled.js +164 -94
- package/lib/commands/rep.js +221 -141
- package/lib/commands/tag.js +174 -109
- package/lib/commands/tax.js +177 -112
- package/lib/commands/warehouse.d.ts +3 -1
- package/lib/commands/warehouse.js +207 -119
- package/lib/index.d.ts +21 -12
- package/lib/test/actions/create_invoice.js +193 -188
- package/lib/test/actions/create_payment.js +112 -107
- package/lib/test/actions/create_proforma.js +220 -216
- package/lib/test/actions/create_return_invoice.js +205 -200
- package/lib/test/actions/create_transfer.js +120 -115
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +328 -327
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +355 -353
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +328 -327
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +337 -334
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +346 -344
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +83 -60
- package/lib/util.d.ts +70 -19
- package/lib/util.js +170 -144
- package/package.json +2 -2
- package/src/actions/create_invoice.ts +11 -16
- package/src/actions/create_payment.ts +11 -16
- package/src/actions/create_proforma.ts +19 -24
- package/src/actions/create_return_invoice.ts +11 -16
- package/src/actions/create_transfer.ts +23 -28
- package/src/commands/product.ts +1 -0
|
@@ -1,101 +1,170 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
_create,
|
|
4
|
+
update_bench_time,
|
|
5
|
+
date_formatting,
|
|
6
|
+
set_error,
|
|
7
|
+
} from "../util.js";
|
|
3
8
|
export const sync_disabled_client = async (commandEvent) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const new_bench_time = new Date().toISOString();
|
|
12
|
-
const bench_time_key = "bench_time_disabled_client";
|
|
13
|
-
await commandLog.load(commandEvent.sync_id);
|
|
14
|
-
await commandLog
|
|
15
|
-
.addDetail("Repzo SAP: Started Syncing Disabled Clients")
|
|
16
|
-
.commit();
|
|
17
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
18
|
-
const result = {
|
|
19
|
-
sap_total: 0,
|
|
20
|
-
repzo_total: 0,
|
|
21
|
-
created: 0,
|
|
22
|
-
updated: 0,
|
|
23
|
-
failed: 0,
|
|
24
|
-
};
|
|
25
|
-
const failed_docs_report = [];
|
|
26
|
-
const sap_disabled_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {
|
|
27
|
-
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
28
|
-
GroupCode: commandEvent.app.formData.GroupCode,
|
|
29
|
-
});
|
|
30
|
-
result.sap_total = sap_disabled_clients === null || sap_disabled_clients === void 0 ? void 0 : sap_disabled_clients.length;
|
|
31
|
-
await commandLog
|
|
32
|
-
.addDetail(`${result.sap_total} Disabled Clients in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
33
|
-
.commit();
|
|
34
|
-
const sap_client_query = sap_disabled_clients === null || sap_disabled_clients === void 0 ? void 0 : sap_disabled_clients.map((client) => `${nameSpace}_${client.CLIENTID}`);
|
|
35
|
-
const repzo_disabled_clients = await repzo.patchAction.create({
|
|
36
|
-
slug: "client",
|
|
37
|
-
readQuery: [
|
|
38
|
-
{ key: "disabled", value: [false], operator: "eq" },
|
|
39
|
-
{
|
|
40
|
-
key: "integration_meta.id",
|
|
41
|
-
value: sap_client_query,
|
|
42
|
-
operator: "in",
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
}, { per_page: 50000, project: ["_id", "integration_meta"] });
|
|
46
|
-
result.repzo_total = (_b = repzo_disabled_clients.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
47
|
-
await commandLog
|
|
48
|
-
.addDetail(`${result.repzo_total} Matched Active Clients in Repzo`)
|
|
49
|
-
.commit();
|
|
50
|
-
for (let i = 0; i < (sap_disabled_clients === null || sap_disabled_clients === void 0 ? void 0 : sap_disabled_clients.length); i++) {
|
|
51
|
-
const sap_client = sap_disabled_clients[i];
|
|
52
|
-
const repzo_client = (_c = repzo_disabled_clients.data) === null || _c === void 0 ? void 0 : _c.find((r_client) => { var _a; return ((_a = r_client.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_client.CLIENTID}`; });
|
|
53
|
-
if (repzo_client) {
|
|
54
|
-
// Update
|
|
55
|
-
try {
|
|
56
|
-
const disabled_client = await repzo.client.remove(repzo_client._id);
|
|
57
|
-
result.updated++;
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
// console.log("Disable Client Failed >> ", e?.response?.data, {
|
|
61
|
-
// CLIENTID: sap_client.CLIENTID,
|
|
62
|
-
// });
|
|
63
|
-
failed_docs_report.push({
|
|
64
|
-
method: "delete",
|
|
65
|
-
doc_id: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client._id,
|
|
66
|
-
doc: { CLIENTID: sap_client.CLIENTID },
|
|
67
|
-
error_message: set_error(e),
|
|
68
|
-
});
|
|
69
|
-
result.failed++;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// console.log(result);
|
|
74
|
-
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
75
|
-
await commandLog
|
|
76
|
-
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
77
|
-
.setBody(result)
|
|
78
|
-
.commit();
|
|
79
|
-
return result;
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
const repzo = new Repzo(
|
|
11
|
+
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
12
|
+
? void 0
|
|
13
|
+
: _a.repzoApiKey,
|
|
14
|
+
{
|
|
15
|
+
env: commandEvent.env,
|
|
80
16
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
17
|
+
);
|
|
18
|
+
const commandLog = new Repzo.CommandLog(
|
|
19
|
+
repzo,
|
|
20
|
+
commandEvent.app,
|
|
21
|
+
commandEvent.command
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
// console.log("sync_disabled_client");
|
|
25
|
+
const new_bench_time = new Date().toISOString();
|
|
26
|
+
const bench_time_key = "bench_time_disabled_client";
|
|
27
|
+
await commandLog.load(commandEvent.sync_id);
|
|
28
|
+
await commandLog
|
|
29
|
+
.addDetail("Repzo SAP: Started Syncing Disabled Clients")
|
|
30
|
+
.commit();
|
|
31
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
32
|
+
const result = {
|
|
33
|
+
sap_total: 0,
|
|
34
|
+
repzo_total: 0,
|
|
35
|
+
created: 0,
|
|
36
|
+
updated: 0,
|
|
37
|
+
failed: 0,
|
|
38
|
+
};
|
|
39
|
+
const failed_docs_report = [];
|
|
40
|
+
const sap_disabled_clients = await get_sap_clients(
|
|
41
|
+
commandEvent.app.formData.sapHostUrl,
|
|
42
|
+
{
|
|
43
|
+
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
44
|
+
GroupCode: commandEvent.app.formData.GroupCode,
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
result.sap_total =
|
|
48
|
+
sap_disabled_clients === null || sap_disabled_clients === void 0
|
|
49
|
+
? void 0
|
|
50
|
+
: sap_disabled_clients.length;
|
|
51
|
+
await commandLog
|
|
52
|
+
.addDetail(
|
|
53
|
+
`${result.sap_total} Disabled Clients in SAP changed since ${
|
|
54
|
+
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
55
|
+
}`
|
|
56
|
+
)
|
|
57
|
+
.commit();
|
|
58
|
+
const sap_client_query =
|
|
59
|
+
sap_disabled_clients === null || sap_disabled_clients === void 0
|
|
60
|
+
? void 0
|
|
61
|
+
: sap_disabled_clients.map(
|
|
62
|
+
(client) => `${nameSpace}_${client.CLIENTID}`
|
|
63
|
+
);
|
|
64
|
+
const repzo_disabled_clients = await repzo.patchAction.create(
|
|
65
|
+
{
|
|
66
|
+
slug: "client",
|
|
67
|
+
readQuery: [
|
|
68
|
+
{ key: "disabled", value: [false], operator: "eq" },
|
|
69
|
+
{
|
|
70
|
+
key: "integration_meta.id",
|
|
71
|
+
value: sap_client_query,
|
|
72
|
+
operator: "in",
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{ per_page: 50000, project: ["_id", "integration_meta"] }
|
|
77
|
+
);
|
|
78
|
+
result.repzo_total =
|
|
79
|
+
(_b = repzo_disabled_clients.data) === null || _b === void 0
|
|
80
|
+
? void 0
|
|
81
|
+
: _b.length;
|
|
82
|
+
await commandLog
|
|
83
|
+
.addDetail(`${result.repzo_total} Matched Active Clients in Repzo`)
|
|
84
|
+
.commit();
|
|
85
|
+
for (
|
|
86
|
+
let i = 0;
|
|
87
|
+
i <
|
|
88
|
+
(sap_disabled_clients === null || sap_disabled_clients === void 0
|
|
89
|
+
? void 0
|
|
90
|
+
: sap_disabled_clients.length);
|
|
91
|
+
i++
|
|
92
|
+
) {
|
|
93
|
+
const sap_client = sap_disabled_clients[i];
|
|
94
|
+
const repzo_client =
|
|
95
|
+
(_c = repzo_disabled_clients.data) === null || _c === void 0
|
|
96
|
+
? void 0
|
|
97
|
+
: _c.find((r_client) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return (
|
|
100
|
+
((_a = r_client.integration_meta) === null || _a === void 0
|
|
101
|
+
? void 0
|
|
102
|
+
: _a.id) == `${nameSpace}_${sap_client.CLIENTID}`
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
if (repzo_client) {
|
|
106
|
+
// Update
|
|
107
|
+
try {
|
|
108
|
+
const disabled_client = await repzo.client.remove(repzo_client._id);
|
|
109
|
+
result.updated++;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
// console.log("Disable Client Failed >> ", e?.response?.data, {
|
|
112
|
+
// CLIENTID: sap_client.CLIENTID,
|
|
113
|
+
// });
|
|
114
|
+
failed_docs_report.push({
|
|
115
|
+
method: "delete",
|
|
116
|
+
doc_id:
|
|
117
|
+
repzo_client === null || repzo_client === void 0
|
|
118
|
+
? void 0
|
|
119
|
+
: repzo_client._id,
|
|
120
|
+
doc: { CLIENTID: sap_client.CLIENTID },
|
|
121
|
+
error_message: set_error(e),
|
|
122
|
+
});
|
|
123
|
+
result.failed++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
86
126
|
}
|
|
127
|
+
// console.log(result);
|
|
128
|
+
await update_bench_time(
|
|
129
|
+
repzo,
|
|
130
|
+
commandEvent.app._id,
|
|
131
|
+
bench_time_key,
|
|
132
|
+
new_bench_time
|
|
133
|
+
);
|
|
134
|
+
await commandLog
|
|
135
|
+
.setStatus(
|
|
136
|
+
"success",
|
|
137
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
138
|
+
)
|
|
139
|
+
.setBody(result)
|
|
140
|
+
.commit();
|
|
141
|
+
return result;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
//@ts-ignore
|
|
144
|
+
console.error(
|
|
145
|
+
((_d = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
146
|
+
_d === void 0
|
|
147
|
+
? void 0
|
|
148
|
+
: _d.data) || e
|
|
149
|
+
);
|
|
150
|
+
await commandLog.setStatus("fail", e).commit();
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
87
153
|
};
|
|
88
154
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
155
|
+
try {
|
|
156
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
157
|
+
Active: "N",
|
|
158
|
+
Frozen: "N",
|
|
159
|
+
UpdateAt: date_formatting(
|
|
160
|
+
query === null || query === void 0 ? void 0 : query.updateAt,
|
|
161
|
+
"YYYYMMDD:HHmmss"
|
|
162
|
+
),
|
|
163
|
+
GroupCode:
|
|
164
|
+
(query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
165
|
+
});
|
|
166
|
+
return sap_clients.Customers;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
throw e;
|
|
169
|
+
}
|
|
101
170
|
};
|
package/lib/commands/index.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { Command, CommandEvent, Result } from "./../types";
|
|
2
|
-
export declare const commands: (CommandEvent: CommandEvent) => Promise<
|
|
3
|
-
|
|
2
|
+
export declare const commands: (CommandEvent: CommandEvent) => Promise<
|
|
3
|
+
| void
|
|
4
|
+
| Result
|
|
5
|
+
| {
|
|
6
|
+
PL: {
|
|
4
7
|
created: number;
|
|
5
8
|
updated: number;
|
|
6
9
|
failed: number;
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
};
|
|
11
|
+
PL_items: {
|
|
9
12
|
created: number;
|
|
10
13
|
updated: number;
|
|
11
14
|
failed: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
};
|
|
16
|
+
sap_total: number;
|
|
17
|
+
repzo_total: number;
|
|
18
|
+
repzo_PL_items: number;
|
|
19
|
+
sap_UoMs_total: number;
|
|
20
|
+
repzo_products_total: number;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
19
23
|
export declare const commandsList: Command[];
|
package/lib/commands/index.js
CHANGED
|
@@ -17,66 +17,66 @@ import { sync_client } from "./client.js";
|
|
|
17
17
|
import { sync_disabled_client } from "./client_disabled.js";
|
|
18
18
|
import { adjust_inventory } from "./adjust_inventory.js";
|
|
19
19
|
export const commands = async (CommandEvent) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
20
|
+
switch (CommandEvent.command) {
|
|
21
|
+
case "join":
|
|
22
|
+
return await join(CommandEvent);
|
|
23
|
+
case "basic":
|
|
24
|
+
return await basic(CommandEvent);
|
|
25
|
+
case "warehouse":
|
|
26
|
+
return await sync_warehouse(CommandEvent);
|
|
27
|
+
case "rep":
|
|
28
|
+
return await sync_rep(CommandEvent);
|
|
29
|
+
case "tax":
|
|
30
|
+
return await sync_tax(CommandEvent);
|
|
31
|
+
case "tag":
|
|
32
|
+
return await sync_tag(CommandEvent);
|
|
33
|
+
case "measureunit":
|
|
34
|
+
return await sync_measureunit(CommandEvent);
|
|
35
|
+
case "measureunit_family":
|
|
36
|
+
return await sync_measureunit_family(CommandEvent);
|
|
37
|
+
case "category":
|
|
38
|
+
return await sync_category(CommandEvent);
|
|
39
|
+
case "channel":
|
|
40
|
+
return await sync_channel(CommandEvent);
|
|
41
|
+
case "payment_term":
|
|
42
|
+
return await sync_payment_term(CommandEvent);
|
|
43
|
+
case "bank":
|
|
44
|
+
return await sync_bank(CommandEvent);
|
|
45
|
+
case "product":
|
|
46
|
+
return await sync_product(CommandEvent);
|
|
47
|
+
case "disabled_product":
|
|
48
|
+
return await sync_disabled_product(CommandEvent);
|
|
49
|
+
case "price_list":
|
|
50
|
+
return await sync_price_list(CommandEvent);
|
|
51
|
+
case "client":
|
|
52
|
+
return await sync_client(CommandEvent);
|
|
53
|
+
case "disabled_client":
|
|
54
|
+
return await sync_disabled_client(CommandEvent);
|
|
55
|
+
case "adjust_inventory":
|
|
56
|
+
return await adjust_inventory(CommandEvent);
|
|
57
|
+
default:
|
|
58
|
+
throw `Route: ${CommandEvent.command} not found`;
|
|
59
|
+
}
|
|
60
60
|
};
|
|
61
61
|
export const commandsList = [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
62
|
+
{
|
|
63
|
+
command: "basic",
|
|
64
|
+
name: "Full Sync",
|
|
65
|
+
description: "",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
command: "join",
|
|
69
|
+
name: "Join",
|
|
70
|
+
description: "",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
command: "warehouse",
|
|
74
|
+
name: "Sync Warehouse",
|
|
75
|
+
description: "Sync warehouses From SAP to Repzo",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
command: "rep",
|
|
79
|
+
name: "Sync Reps",
|
|
80
|
+
description: "Sync Reps From SAP to Repzo",
|
|
81
|
+
},
|
|
82
82
|
];
|