repzo-sap-absjo 1.0.6 → 1.0.8
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 +4 -0
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +216 -336
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +125 -171
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +165 -268
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +177 -295
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +143 -198
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +47 -66
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +327 -571
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +243 -425
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -164
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- 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 -90
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- 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 +60 -83
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +35 -0
- package/src/actions/create_payment.ts +35 -0
- package/src/actions/create_proforma.ts +35 -0
- package/src/actions/create_return_invoice.ts +35 -0
- package/src/actions/create_transfer.ts +34 -0
- package/src/commands/price_list.ts +40 -4
- package/src/test/commands/price_list.ts +263 -13
|
@@ -1,210 +1,131 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
3
|
-
_create,
|
|
4
|
-
update_bench_time,
|
|
5
|
-
date_formatting,
|
|
6
|
-
set_error,
|
|
7
|
-
} from "../util.js";
|
|
2
|
+
import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
|
|
8
3
|
export const sync_payment_term = async (commandEvent) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
? void 0
|
|
13
|
-
: _a.repzoApiKey,
|
|
14
|
-
{
|
|
15
|
-
env: commandEvent.env,
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
const commandLog = new Repzo.CommandLog(
|
|
19
|
-
repzo,
|
|
20
|
-
commandEvent.app,
|
|
21
|
-
commandEvent.command
|
|
22
|
-
);
|
|
23
|
-
try {
|
|
24
|
-
// console.log("sync_payment_term");
|
|
25
|
-
const new_bench_time = new Date().toISOString();
|
|
26
|
-
const bench_time_key = "bench_time_payment_term";
|
|
27
|
-
await commandLog.load(commandEvent.sync_id);
|
|
28
|
-
await commandLog
|
|
29
|
-
.addDetail("Repzo SAP: Started Syncing Payments Term")
|
|
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_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
|
-
const sap_unique_payment_terms = {};
|
|
48
|
-
sap_clients === null || sap_clients === void 0
|
|
49
|
-
? void 0
|
|
50
|
-
: sap_clients.forEach((client) => {
|
|
51
|
-
const paymentTerm = client.PAYMENTTERM;
|
|
52
|
-
sap_unique_payment_terms[paymentTerm] = true;
|
|
53
|
-
});
|
|
54
|
-
const sap_payment_terms = Object.keys(sap_unique_payment_terms);
|
|
55
|
-
result.sap_total =
|
|
56
|
-
sap_payment_terms === null || sap_payment_terms === void 0
|
|
57
|
-
? void 0
|
|
58
|
-
: sap_payment_terms.length;
|
|
59
|
-
await commandLog
|
|
60
|
-
.addDetail(
|
|
61
|
-
`${result.sap_total} Payments Term in SAP changed since ${
|
|
62
|
-
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
63
|
-
}`
|
|
64
|
-
)
|
|
65
|
-
.commit();
|
|
66
|
-
const repzo_payment_terms = await repzo.paymentTerm.find({
|
|
67
|
-
per_page: 50000,
|
|
4
|
+
var _a, _b, _c, _d;
|
|
5
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
6
|
+
env: commandEvent.env,
|
|
68
7
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
:
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
? void 0
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
result.failed++;
|
|
8
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
9
|
+
try {
|
|
10
|
+
// console.log("sync_payment_term");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_payment_term";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog
|
|
15
|
+
.addDetail("Repzo SAP: Started Syncing Payments Term")
|
|
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_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
|
+
const sap_unique_payment_terms = {};
|
|
31
|
+
sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.forEach((client) => {
|
|
32
|
+
const paymentTerm = client.PAYMENTTERM;
|
|
33
|
+
sap_unique_payment_terms[paymentTerm] = true;
|
|
34
|
+
});
|
|
35
|
+
const sap_payment_terms = Object.keys(sap_unique_payment_terms);
|
|
36
|
+
result.sap_total = sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length;
|
|
37
|
+
await commandLog
|
|
38
|
+
.addDetail(`${result.sap_total} Payments Term in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
39
|
+
.commit();
|
|
40
|
+
const repzo_payment_terms = await repzo.paymentTerm.find({
|
|
41
|
+
per_page: 50000,
|
|
42
|
+
});
|
|
43
|
+
result.repzo_total = (_b = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
44
|
+
await commandLog
|
|
45
|
+
.addDetail(`${(_c = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _c === void 0 ? void 0 : _c.length} Payments Term in Repzo`)
|
|
46
|
+
.commit();
|
|
47
|
+
for (let i = 0; i < (sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length); i++) {
|
|
48
|
+
const sap_payment_term = sap_payment_terms[i];
|
|
49
|
+
const repzo_payment_term = repzo_payment_terms.data.find((r_payment_term) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return ((_a = r_payment_term.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
52
|
+
`${nameSpace}_${sap_payment_term}`;
|
|
53
|
+
});
|
|
54
|
+
const body = {
|
|
55
|
+
name: sap_payment_term.toString(),
|
|
56
|
+
due_days: Number(sap_payment_term),
|
|
57
|
+
integration_meta: {
|
|
58
|
+
id: `${nameSpace}_${sap_payment_term}`,
|
|
59
|
+
},
|
|
60
|
+
company_namespace: [nameSpace],
|
|
61
|
+
};
|
|
62
|
+
if (!repzo_payment_term) {
|
|
63
|
+
// Create
|
|
64
|
+
try {
|
|
65
|
+
const created_payment_term = await repzo.paymentTerm.create(body);
|
|
66
|
+
result.created++;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// console.log("Create Payment Term Failed >> ", e?.response, body);
|
|
70
|
+
failed_docs_report.push({
|
|
71
|
+
method: "create",
|
|
72
|
+
doc: body,
|
|
73
|
+
error_message: set_error(e),
|
|
74
|
+
});
|
|
75
|
+
result.failed++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if ((repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.name) == (body === null || body === void 0 ? void 0 : body.name) &&
|
|
80
|
+
(repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.due_days) == (body === null || body === void 0 ? void 0 : body.due_days))
|
|
81
|
+
continue;
|
|
82
|
+
// Update
|
|
83
|
+
try {
|
|
84
|
+
const updated_payment_term = await repzo.paymentTerm.update(repzo_payment_term._id, body);
|
|
85
|
+
result.updated++;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
// console.log(
|
|
89
|
+
// "Update Payment Term Failed >> ",
|
|
90
|
+
// e?.response?.data,
|
|
91
|
+
// body
|
|
92
|
+
// );
|
|
93
|
+
failed_docs_report.push({
|
|
94
|
+
method: "update",
|
|
95
|
+
doc_id: repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term._id,
|
|
96
|
+
doc: body,
|
|
97
|
+
error_message: set_error(e),
|
|
98
|
+
});
|
|
99
|
+
result.failed++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
164
102
|
}
|
|
165
|
-
|
|
103
|
+
// console.log(result);
|
|
104
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
105
|
+
await commandLog
|
|
106
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
107
|
+
.setBody(result)
|
|
108
|
+
.commit();
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
//@ts-ignore
|
|
113
|
+
console.error(((_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) || e);
|
|
114
|
+
await commandLog.setStatus("fail", e).commit();
|
|
115
|
+
throw e;
|
|
166
116
|
}
|
|
167
|
-
// console.log(result);
|
|
168
|
-
await update_bench_time(
|
|
169
|
-
repzo,
|
|
170
|
-
commandEvent.app._id,
|
|
171
|
-
bench_time_key,
|
|
172
|
-
new_bench_time
|
|
173
|
-
);
|
|
174
|
-
await commandLog
|
|
175
|
-
.setStatus(
|
|
176
|
-
"success",
|
|
177
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
178
|
-
)
|
|
179
|
-
.setBody(result)
|
|
180
|
-
.commit();
|
|
181
|
-
return result;
|
|
182
|
-
} catch (e) {
|
|
183
|
-
//@ts-ignore
|
|
184
|
-
console.error(
|
|
185
|
-
((_d = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
186
|
-
_d === void 0
|
|
187
|
-
? void 0
|
|
188
|
-
: _d.data) || e
|
|
189
|
-
);
|
|
190
|
-
await commandLog.setStatus("fail", e).commit();
|
|
191
|
-
throw e;
|
|
192
|
-
}
|
|
193
117
|
};
|
|
194
118
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
} catch (e) {
|
|
208
|
-
throw e;
|
|
209
|
-
}
|
|
119
|
+
try {
|
|
120
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
121
|
+
Active: "Y",
|
|
122
|
+
Frozen: "N",
|
|
123
|
+
UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
|
|
124
|
+
GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
125
|
+
});
|
|
126
|
+
return sap_clients.Customers;
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
210
131
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { CommandEvent } from "../types";
|
|
2
2
|
export declare const sync_price_list: (commandEvent: CommandEvent) => Promise<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
PL: {
|
|
4
|
+
created: number;
|
|
5
|
+
updated: number;
|
|
6
|
+
failed: number;
|
|
7
|
+
};
|
|
8
|
+
PL_items: {
|
|
9
|
+
created: number;
|
|
10
|
+
updated: number;
|
|
11
|
+
failed: number;
|
|
12
|
+
};
|
|
13
|
+
sap_total: number;
|
|
14
|
+
repzo_total: number;
|
|
15
|
+
repzo_PL_items: number;
|
|
16
|
+
sap_UoMs_total: number;
|
|
17
|
+
repzo_products_total: number;
|
|
18
18
|
}>;
|