repzo-sap-absjo 1.0.9 → 1.0.10
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/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +206 -363
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +117 -200
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +155 -290
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +169 -321
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +136 -220
- 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 +326 -612
- 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 +334 -337
- 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_transfer.ts +2 -2
package/lib/commands/client.js
CHANGED
|
@@ -1,419 +1,259 @@
|
|
|
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_client = 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_client");
|
|
25
|
-
const new_bench_time = new Date().toISOString();
|
|
26
|
-
const bench_time_key = "bench_time_client";
|
|
27
|
-
await commandLog.load(commandEvent.sync_id);
|
|
28
|
-
await commandLog.addDetail("Repzo SAP: Started Syncing Clients").commit();
|
|
29
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
30
|
-
const result = {
|
|
31
|
-
sap_total: 0,
|
|
32
|
-
repzo_total: 0,
|
|
33
|
-
created: 0,
|
|
34
|
-
updated: 0,
|
|
35
|
-
failed: 0,
|
|
36
|
-
};
|
|
37
|
-
const failed_docs_report = [];
|
|
38
|
-
// Get SAP CLients to be created/updated
|
|
39
|
-
const sap_clients = await get_sap_clients(
|
|
40
|
-
commandEvent.app.formData.sapHostUrl,
|
|
41
|
-
{
|
|
42
|
-
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
43
|
-
GroupCode: commandEvent.app.formData.GroupCode,
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
result.sap_total =
|
|
47
|
-
sap_clients === null || sap_clients === void 0
|
|
48
|
-
? void 0
|
|
49
|
-
: sap_clients.length;
|
|
50
|
-
await commandLog
|
|
51
|
-
.addDetail(
|
|
52
|
-
`${result.sap_total} Customers in SAP changed since ${
|
|
53
|
-
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
54
|
-
}`
|
|
55
|
-
)
|
|
56
|
-
.commit();
|
|
57
|
-
// Get SAP CLients to be created/updated
|
|
58
|
-
const sap_all_clients = await get_sap_clients(
|
|
59
|
-
commandEvent.app.formData.sapHostUrl,
|
|
60
|
-
{}
|
|
61
|
-
);
|
|
62
|
-
result.sap_total =
|
|
63
|
-
sap_clients === null || sap_clients === void 0
|
|
64
|
-
? void 0
|
|
65
|
-
: sap_clients.length;
|
|
66
|
-
// Get Repzo Tags
|
|
67
|
-
const repzo_tags = await repzo.tag.find({
|
|
68
|
-
disabled: false,
|
|
69
|
-
per_page: 50000,
|
|
70
|
-
});
|
|
71
|
-
// Get Repzo Channels
|
|
72
|
-
const repzo_channels = await repzo.channel.find({
|
|
73
|
-
disabled: false,
|
|
74
|
-
per_page: 50000,
|
|
75
|
-
});
|
|
76
|
-
// Get Repzo PaymentTerms
|
|
77
|
-
const repzo_payment_terms = await repzo.paymentTerm.find({
|
|
78
|
-
disabled: false,
|
|
79
|
-
per_page: 50000,
|
|
80
|
-
});
|
|
81
|
-
// Get Repzo PriceLists
|
|
82
|
-
const repzo_price_lists = await repzo.priceList.find({
|
|
83
|
-
disabled: false,
|
|
84
|
-
per_page: 50000,
|
|
4
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
6
|
+
env: commandEvent.env,
|
|
85
7
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
? void 0
|
|
152
|
-
: _a.id) == `${nameSpace}_${sap_client.CLIENTGROUP}`
|
|
153
|
-
);
|
|
8
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
9
|
+
try {
|
|
10
|
+
// console.log("sync_client");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_client";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Clients").commit();
|
|
15
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
16
|
+
const result = {
|
|
17
|
+
sap_total: 0,
|
|
18
|
+
repzo_total: 0,
|
|
19
|
+
created: 0,
|
|
20
|
+
updated: 0,
|
|
21
|
+
failed: 0,
|
|
22
|
+
};
|
|
23
|
+
const failed_docs_report = [];
|
|
24
|
+
// Get SAP CLients to be created/updated
|
|
25
|
+
const sap_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {
|
|
26
|
+
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
27
|
+
GroupCode: commandEvent.app.formData.GroupCode,
|
|
28
|
+
});
|
|
29
|
+
result.sap_total = sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length;
|
|
30
|
+
await commandLog
|
|
31
|
+
.addDetail(`${result.sap_total} Customers in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
32
|
+
.commit();
|
|
33
|
+
// Get SAP CLients to be created/updated
|
|
34
|
+
const sap_all_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {});
|
|
35
|
+
result.sap_total = sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length;
|
|
36
|
+
// Get Repzo Tags
|
|
37
|
+
const repzo_tags = await repzo.tag.find({
|
|
38
|
+
disabled: false,
|
|
39
|
+
per_page: 50000,
|
|
40
|
+
});
|
|
41
|
+
// Get Repzo Channels
|
|
42
|
+
const repzo_channels = await repzo.channel.find({
|
|
43
|
+
disabled: false,
|
|
44
|
+
per_page: 50000,
|
|
45
|
+
});
|
|
46
|
+
// Get Repzo PaymentTerms
|
|
47
|
+
const repzo_payment_terms = await repzo.paymentTerm.find({
|
|
48
|
+
disabled: false,
|
|
49
|
+
per_page: 50000,
|
|
50
|
+
});
|
|
51
|
+
// Get Repzo PriceLists
|
|
52
|
+
const repzo_price_lists = await repzo.priceList.find({
|
|
53
|
+
disabled: false,
|
|
54
|
+
per_page: 50000,
|
|
55
|
+
});
|
|
56
|
+
// Get Repzo Clients
|
|
57
|
+
const repzo_clients = await repzo.client.find({
|
|
58
|
+
per_page: 50000,
|
|
59
|
+
project: ["_id", "integration_meta"],
|
|
60
|
+
});
|
|
61
|
+
result.repzo_total = (_b = repzo_clients === null || repzo_clients === void 0 ? void 0 : repzo_clients.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
62
|
+
await commandLog
|
|
63
|
+
.addDetail(`${(_c = repzo_clients === null || repzo_clients === void 0 ? void 0 : repzo_clients.data) === null || _c === void 0 ? void 0 : _c.length} Clients in Repzo`)
|
|
64
|
+
.commit();
|
|
65
|
+
for (let i = 0; i < (sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length); i++) {
|
|
66
|
+
const sap_client = sap_clients[i];
|
|
67
|
+
const repzo_client = repzo_clients.data.find((r_client) => { var _a; return ((_a = r_client.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_client.CLIENTID}`; });
|
|
68
|
+
const tag = (_d = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _d === void 0 ? void 0 : _d.find((tag) => { var _a; return ((_a = tag.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_client.TERRITORYID}`; });
|
|
69
|
+
const channel = (_e = repzo_channels === null || repzo_channels === void 0 ? void 0 : repzo_channels.data) === null || _e === void 0 ? void 0 : _e.find((channel) => {
|
|
70
|
+
var _a;
|
|
71
|
+
return ((_a = channel.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
72
|
+
`${nameSpace}_${sap_client.CLIENTGROUP}`;
|
|
154
73
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
: repzo_payment_terms.data) === null || _f === void 0
|
|
160
|
-
? void 0
|
|
161
|
-
: _f.find((paymentTerm) => {
|
|
162
|
-
var _a;
|
|
163
|
-
return (
|
|
164
|
-
((_a = paymentTerm.integration_meta) === null || _a === void 0
|
|
165
|
-
? void 0
|
|
166
|
-
: _a.id) == `${nameSpace}_${sap_client.PAYMENTTERM}`
|
|
167
|
-
);
|
|
74
|
+
const paymentTerm = (_f = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _f === void 0 ? void 0 : _f.find((paymentTerm) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return ((_a = paymentTerm.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
77
|
+
`${nameSpace}_${sap_client.PAYMENTTERM}`;
|
|
168
78
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
: repzo_price_lists.data) === null || _g === void 0
|
|
174
|
-
? void 0
|
|
175
|
-
: _g.find((pricelist) => {
|
|
176
|
-
var _a;
|
|
177
|
-
return (
|
|
178
|
-
((_a = pricelist.integration_meta) === null || _a === void 0
|
|
179
|
-
? void 0
|
|
180
|
-
: _a.id) == `${nameSpace}_${sap_client.CLIENTPRICELISTID}`
|
|
181
|
-
);
|
|
79
|
+
const priceList = (_g = repzo_price_lists === null || repzo_price_lists === void 0 ? void 0 : repzo_price_lists.data) === null || _g === void 0 ? void 0 : _g.find((pricelist) => {
|
|
80
|
+
var _a;
|
|
81
|
+
return ((_a = pricelist.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
82
|
+
`${nameSpace}_${sap_client.CLIENTPRICELISTID}`;
|
|
182
83
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
doc: body,
|
|
274
|
-
error_message: set_error(e),
|
|
275
|
-
});
|
|
276
|
-
result.failed++;
|
|
84
|
+
let parent;
|
|
85
|
+
if (sap_client.PARENTCODE) {
|
|
86
|
+
parent = sap_all_clients.find((c) => c.CLIENTID == sap_client.PARENTCODE);
|
|
87
|
+
}
|
|
88
|
+
const credit_limit = parent
|
|
89
|
+
? parent.CLIENTCREDITLIMIT
|
|
90
|
+
: sap_client.CLIENTCREDITLIMIT;
|
|
91
|
+
const client_credit_consumed = parent
|
|
92
|
+
? parent.CLIENTCREDITCONSUMED
|
|
93
|
+
: sap_client.CLIENTCREDITCONSUMED;
|
|
94
|
+
const body = {
|
|
95
|
+
integration_meta: {
|
|
96
|
+
id: `${nameSpace}_${sap_client.CLIENTID}`,
|
|
97
|
+
PAYMENTTERM: sap_client.PAYMENTTERM,
|
|
98
|
+
CLIENTCREDITCONSUMED: parent
|
|
99
|
+
? parent.CLIENTCREDITCONSUMED
|
|
100
|
+
: sap_client.CLIENTCREDITCONSUMED,
|
|
101
|
+
CLIENTMAXCHEQUEVALUE: parent
|
|
102
|
+
? parent.CLIENTMAXCHEQUEVALUE
|
|
103
|
+
: sap_client.CLIENTMAXCHEQUEVALUE,
|
|
104
|
+
CLIENTCREDITLIMIT: parent
|
|
105
|
+
? parent.CLIENTCREDITLIMIT
|
|
106
|
+
: sap_client.CLIENTCREDITLIMIT,
|
|
107
|
+
CLIENTPRICELISTID: sap_client.CLIENTPRICELISTID,
|
|
108
|
+
},
|
|
109
|
+
client_code: sap_client.CLIENTID,
|
|
110
|
+
name: sap_client.CLIENTDESC,
|
|
111
|
+
local_name: sap_client.CLIENTDESCF ? sap_client.CLIENTDESCF : undefined,
|
|
112
|
+
city: sap_client.CLIENTCITY,
|
|
113
|
+
state: sap_client.CLIENTCOUNTY,
|
|
114
|
+
country: sap_client.CLIENTCOUNTRY,
|
|
115
|
+
contact_name: sap_client.CLIENTCONTACTPERSON,
|
|
116
|
+
phone: sap_client.CLIENTPHONE1,
|
|
117
|
+
cell_phone: sap_client.CLIENTPHONE2,
|
|
118
|
+
comment: sap_client.CLIENTNOTE,
|
|
119
|
+
formatted_address: sap_client.CLIENTADDRESSID,
|
|
120
|
+
tags: tag ? [tag._id] : [],
|
|
121
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
122
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
123
|
+
: 1000000000,
|
|
124
|
+
financials: {
|
|
125
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
126
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
127
|
+
: 1000000000,
|
|
128
|
+
},
|
|
129
|
+
channel: channel ? channel._id : undefined,
|
|
130
|
+
paymentTerm: paymentTerm ? paymentTerm._id : undefined,
|
|
131
|
+
sv_priceList: priceList ? priceList._id : undefined,
|
|
132
|
+
disabled: sap_client.ACTIVE == "Y" ? false : true,
|
|
133
|
+
payment_type: sap_client.PAYMENTTERM ? "credit" : "cash",
|
|
134
|
+
integrated_client_balance: client_credit_consumed && Math.round(client_credit_consumed * 1000),
|
|
135
|
+
};
|
|
136
|
+
if (!repzo_client) {
|
|
137
|
+
// Create
|
|
138
|
+
try {
|
|
139
|
+
const created_client = await repzo.client.create(body);
|
|
140
|
+
result.created++;
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
// console.log("Create Client Failed >> ", e?.response, body);
|
|
144
|
+
failed_docs_report.push({
|
|
145
|
+
method: "create",
|
|
146
|
+
doc: body,
|
|
147
|
+
error_message: set_error(e),
|
|
148
|
+
});
|
|
149
|
+
result.failed++;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const repzo_original_doc = await repzo.client.get(repzo_client._id);
|
|
154
|
+
// console.log("match", is_matched(body, repzo_original_doc));
|
|
155
|
+
if (is_matched(body, repzo_original_doc)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
// Update
|
|
159
|
+
try {
|
|
160
|
+
const updated_client = await repzo.client.update(repzo_client._id, body);
|
|
161
|
+
result.updated++;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
// console.log("Update Client Failed >> ", e?.response?.data, body);
|
|
165
|
+
failed_docs_report.push({
|
|
166
|
+
method: "update",
|
|
167
|
+
doc_id: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client._id,
|
|
168
|
+
doc: body,
|
|
169
|
+
error_message: set_error(e),
|
|
170
|
+
});
|
|
171
|
+
result.failed++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
277
174
|
}
|
|
278
|
-
|
|
175
|
+
// console.log(result);
|
|
176
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
177
|
+
await commandLog
|
|
178
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
179
|
+
.setBody(result)
|
|
180
|
+
.commit();
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
//@ts-ignore
|
|
185
|
+
console.error(((_h = e === null || e === void 0 ? void 0 : e.response) === null || _h === void 0 ? void 0 : _h.data) || e);
|
|
186
|
+
await commandLog.setStatus("fail", e).commit();
|
|
187
|
+
throw e;
|
|
279
188
|
}
|
|
280
|
-
// console.log(result);
|
|
281
|
-
await update_bench_time(
|
|
282
|
-
repzo,
|
|
283
|
-
commandEvent.app._id,
|
|
284
|
-
bench_time_key,
|
|
285
|
-
new_bench_time
|
|
286
|
-
);
|
|
287
|
-
await commandLog
|
|
288
|
-
.setStatus(
|
|
289
|
-
"success",
|
|
290
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
291
|
-
)
|
|
292
|
-
.setBody(result)
|
|
293
|
-
.commit();
|
|
294
|
-
return result;
|
|
295
|
-
} catch (e) {
|
|
296
|
-
//@ts-ignore
|
|
297
|
-
console.error(
|
|
298
|
-
((_h = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
299
|
-
_h === void 0
|
|
300
|
-
? void 0
|
|
301
|
-
: _h.data) || e
|
|
302
|
-
);
|
|
303
|
-
await commandLog.setStatus("fail", e).commit();
|
|
304
|
-
throw e;
|
|
305
|
-
}
|
|
306
189
|
};
|
|
307
190
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
} catch (e) {
|
|
321
|
-
throw e;
|
|
322
|
-
}
|
|
191
|
+
try {
|
|
192
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
193
|
+
Active: "Y",
|
|
194
|
+
Frozen: "N",
|
|
195
|
+
UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
|
|
196
|
+
GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
197
|
+
});
|
|
198
|
+
return sap_clients.Customers;
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
323
203
|
};
|
|
324
204
|
const is_matched = (body_1, body_2) => {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
: body_1.integration_meta) === null || _c === void 0
|
|
376
|
-
? void 0
|
|
377
|
-
: _c[key]) === null || _d === void 0
|
|
378
|
-
? void 0
|
|
379
|
-
: _d.toString()) !==
|
|
380
|
-
((_f =
|
|
381
|
-
(_e =
|
|
382
|
-
body_2 === null || body_2 === void 0
|
|
383
|
-
? void 0
|
|
384
|
-
: body_2.integration_meta) === null || _e === void 0
|
|
385
|
-
? void 0
|
|
386
|
-
: _e[key]) === null || _f === void 0
|
|
387
|
-
? void 0
|
|
388
|
-
: _f.toString())
|
|
389
|
-
) {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
205
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
206
|
+
try {
|
|
207
|
+
const keys = [
|
|
208
|
+
"client_code",
|
|
209
|
+
"name",
|
|
210
|
+
"local_name",
|
|
211
|
+
"city",
|
|
212
|
+
"state",
|
|
213
|
+
"country",
|
|
214
|
+
"contact_name",
|
|
215
|
+
"phone",
|
|
216
|
+
"cell_phone",
|
|
217
|
+
"comment",
|
|
218
|
+
"formatted_address",
|
|
219
|
+
"tags",
|
|
220
|
+
"credit_limit",
|
|
221
|
+
// "financials",
|
|
222
|
+
"channel",
|
|
223
|
+
"paymentTerm",
|
|
224
|
+
"sv_priceList",
|
|
225
|
+
"disabled",
|
|
226
|
+
"payment_type",
|
|
227
|
+
"integrated_client_balance",
|
|
228
|
+
];
|
|
229
|
+
const integration_meta_keys = [
|
|
230
|
+
"id",
|
|
231
|
+
"PAYMENTTERM",
|
|
232
|
+
"CLIENTCREDITCONSUMED",
|
|
233
|
+
"CLIENTMAXCHEQUEVALUE",
|
|
234
|
+
"CLIENTCREDITLIMIT",
|
|
235
|
+
"CLIENTPRICELISTID",
|
|
236
|
+
];
|
|
237
|
+
for (let i = 0; i < keys.length; i++) {
|
|
238
|
+
const key = keys[i];
|
|
239
|
+
if (((_a = body_1[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (let i = 0; i < integration_meta_keys.length; i++) {
|
|
244
|
+
const key = keys[i];
|
|
245
|
+
if (((_d = (_c = body_1 === null || body_1 === void 0 ? void 0 : body_1.integration_meta) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.toString()) !==
|
|
246
|
+
((_f = (_e = body_2 === null || body_2 === void 0 ? void 0 : body_2.integration_meta) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.toString())) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (((_h = (_g = body_1 === null || body_1 === void 0 ? void 0 : body_1.integration_meta) === null || _g === void 0 ? void 0 : _g["financials"]) === null || _h === void 0 ? void 0 : _h.credit_limit) !==
|
|
251
|
+
((_k = (_j = body_2 === null || body_2 === void 0 ? void 0 : body_2.integration_meta) === null || _j === void 0 ? void 0 : _j["financials"]) === null || _k === void 0 ? void 0 : _k.credit_limit)) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
392
255
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
(_g =
|
|
396
|
-
body_1 === null || body_1 === void 0
|
|
397
|
-
? void 0
|
|
398
|
-
: body_1.integration_meta) === null || _g === void 0
|
|
399
|
-
? void 0
|
|
400
|
-
: _g["financials"]) === null || _h === void 0
|
|
401
|
-
? void 0
|
|
402
|
-
: _h.credit_limit) !==
|
|
403
|
-
((_k =
|
|
404
|
-
(_j =
|
|
405
|
-
body_2 === null || body_2 === void 0
|
|
406
|
-
? void 0
|
|
407
|
-
: body_2.integration_meta) === null || _j === void 0
|
|
408
|
-
? void 0
|
|
409
|
-
: _j["financials"]) === null || _k === void 0
|
|
410
|
-
? void 0
|
|
411
|
-
: _k.credit_limit)
|
|
412
|
-
) {
|
|
413
|
-
return false;
|
|
256
|
+
catch (e) {
|
|
257
|
+
throw e;
|
|
414
258
|
}
|
|
415
|
-
return true;
|
|
416
|
-
} catch (e) {
|
|
417
|
-
throw e;
|
|
418
|
-
}
|
|
419
259
|
};
|