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
package/lib/commands/client.js
CHANGED
|
@@ -1,259 +1,419 @@
|
|
|
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_client = async (commandEvent) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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,
|
|
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,
|
|
7
85
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
// Get Repzo Clients
|
|
87
|
+
const repzo_clients = await repzo.client.find({
|
|
88
|
+
per_page: 50000,
|
|
89
|
+
project: ["_id", "integration_meta"],
|
|
90
|
+
});
|
|
91
|
+
result.repzo_total =
|
|
92
|
+
(_b =
|
|
93
|
+
repzo_clients === null || repzo_clients === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: repzo_clients.data) === null || _b === void 0
|
|
96
|
+
? void 0
|
|
97
|
+
: _b.length;
|
|
98
|
+
await commandLog
|
|
99
|
+
.addDetail(
|
|
100
|
+
`${
|
|
101
|
+
(_c =
|
|
102
|
+
repzo_clients === null || repzo_clients === void 0
|
|
103
|
+
? void 0
|
|
104
|
+
: repzo_clients.data) === null || _c === void 0
|
|
105
|
+
? void 0
|
|
106
|
+
: _c.length
|
|
107
|
+
} Clients in Repzo`
|
|
108
|
+
)
|
|
109
|
+
.commit();
|
|
110
|
+
for (
|
|
111
|
+
let i = 0;
|
|
112
|
+
i <
|
|
113
|
+
(sap_clients === null || sap_clients === void 0
|
|
114
|
+
? void 0
|
|
115
|
+
: sap_clients.length);
|
|
116
|
+
i++
|
|
117
|
+
) {
|
|
118
|
+
const sap_client = sap_clients[i];
|
|
119
|
+
const repzo_client = repzo_clients.data.find((r_client) => {
|
|
120
|
+
var _a;
|
|
121
|
+
return (
|
|
122
|
+
((_a = r_client.integration_meta) === null || _a === void 0
|
|
123
|
+
? void 0
|
|
124
|
+
: _a.id) == `${nameSpace}_${sap_client.CLIENTID}`
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
const tag =
|
|
128
|
+
(_d =
|
|
129
|
+
repzo_tags === null || repzo_tags === void 0
|
|
130
|
+
? void 0
|
|
131
|
+
: repzo_tags.data) === null || _d === void 0
|
|
132
|
+
? void 0
|
|
133
|
+
: _d.find((tag) => {
|
|
134
|
+
var _a;
|
|
135
|
+
return (
|
|
136
|
+
((_a = tag.integration_meta) === null || _a === void 0
|
|
137
|
+
? void 0
|
|
138
|
+
: _a.id) == `${nameSpace}_${sap_client.TERRITORYID}`
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
const channel =
|
|
142
|
+
(_e =
|
|
143
|
+
repzo_channels === null || repzo_channels === void 0
|
|
144
|
+
? void 0
|
|
145
|
+
: repzo_channels.data) === null || _e === void 0
|
|
146
|
+
? void 0
|
|
147
|
+
: _e.find((channel) => {
|
|
148
|
+
var _a;
|
|
149
|
+
return (
|
|
150
|
+
((_a = channel.integration_meta) === null || _a === void 0
|
|
151
|
+
? void 0
|
|
152
|
+
: _a.id) == `${nameSpace}_${sap_client.CLIENTGROUP}`
|
|
153
|
+
);
|
|
73
154
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
155
|
+
const paymentTerm =
|
|
156
|
+
(_f =
|
|
157
|
+
repzo_payment_terms === null || repzo_payment_terms === void 0
|
|
158
|
+
? void 0
|
|
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
|
+
);
|
|
78
168
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
169
|
+
const priceList =
|
|
170
|
+
(_g =
|
|
171
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
172
|
+
? void 0
|
|
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
|
+
);
|
|
83
182
|
});
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
183
|
+
let parent;
|
|
184
|
+
if (sap_client.PARENTCODE) {
|
|
185
|
+
parent = sap_all_clients.find(
|
|
186
|
+
(c) => c.CLIENTID == sap_client.PARENTCODE
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const credit_limit = parent
|
|
190
|
+
? parent.CLIENTCREDITLIMIT
|
|
191
|
+
: sap_client.CLIENTCREDITLIMIT;
|
|
192
|
+
const client_credit_consumed = parent
|
|
193
|
+
? parent.CLIENTCREDITCONSUMED
|
|
194
|
+
: sap_client.CLIENTCREDITCONSUMED;
|
|
195
|
+
const body = {
|
|
196
|
+
integration_meta: {
|
|
197
|
+
id: `${nameSpace}_${sap_client.CLIENTID}`,
|
|
198
|
+
PAYMENTTERM: sap_client.PAYMENTTERM,
|
|
199
|
+
CLIENTCREDITCONSUMED: parent
|
|
200
|
+
? parent.CLIENTCREDITCONSUMED
|
|
201
|
+
: sap_client.CLIENTCREDITCONSUMED,
|
|
202
|
+
CLIENTMAXCHEQUEVALUE: parent
|
|
203
|
+
? parent.CLIENTMAXCHEQUEVALUE
|
|
204
|
+
: sap_client.CLIENTMAXCHEQUEVALUE,
|
|
205
|
+
CLIENTCREDITLIMIT: parent
|
|
206
|
+
? parent.CLIENTCREDITLIMIT
|
|
207
|
+
: sap_client.CLIENTCREDITLIMIT,
|
|
208
|
+
CLIENTPRICELISTID: sap_client.CLIENTPRICELISTID,
|
|
209
|
+
},
|
|
210
|
+
client_code: sap_client.CLIENTID,
|
|
211
|
+
name: sap_client.CLIENTDESC,
|
|
212
|
+
local_name: sap_client.CLIENTDESCF ? sap_client.CLIENTDESCF : undefined,
|
|
213
|
+
city: sap_client.CLIENTCITY,
|
|
214
|
+
state: sap_client.CLIENTCOUNTY,
|
|
215
|
+
country: sap_client.CLIENTCOUNTRY,
|
|
216
|
+
contact_name: sap_client.CLIENTCONTACTPERSON,
|
|
217
|
+
phone: sap_client.CLIENTPHONE1,
|
|
218
|
+
cell_phone: sap_client.CLIENTPHONE2,
|
|
219
|
+
comment: sap_client.CLIENTNOTE,
|
|
220
|
+
formatted_address: sap_client.CLIENTADDRESSID,
|
|
221
|
+
tags: tag ? [tag._id] : [],
|
|
222
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
223
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
224
|
+
: 1000000000,
|
|
225
|
+
financials: {
|
|
226
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
227
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
228
|
+
: 1000000000,
|
|
229
|
+
},
|
|
230
|
+
channel: channel ? channel._id : undefined,
|
|
231
|
+
paymentTerm: paymentTerm ? paymentTerm._id : undefined,
|
|
232
|
+
sv_priceList: priceList ? priceList._id : undefined,
|
|
233
|
+
disabled: sap_client.ACTIVE == "Y" ? false : true,
|
|
234
|
+
payment_type: sap_client.PAYMENTTERM ? "credit" : "cash",
|
|
235
|
+
integrated_client_balance:
|
|
236
|
+
client_credit_consumed && Math.round(client_credit_consumed * 1000),
|
|
237
|
+
};
|
|
238
|
+
if (!repzo_client) {
|
|
239
|
+
// Create
|
|
240
|
+
try {
|
|
241
|
+
const created_client = await repzo.client.create(body);
|
|
242
|
+
result.created++;
|
|
243
|
+
} catch (e) {
|
|
244
|
+
// console.log("Create Client Failed >> ", e?.response, body);
|
|
245
|
+
failed_docs_report.push({
|
|
246
|
+
method: "create",
|
|
247
|
+
doc: body,
|
|
248
|
+
error_message: set_error(e),
|
|
249
|
+
});
|
|
250
|
+
result.failed++;
|
|
174
251
|
}
|
|
175
|
-
|
|
176
|
-
await
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
252
|
+
} else {
|
|
253
|
+
const repzo_original_doc = await repzo.client.get(repzo_client._id);
|
|
254
|
+
// console.log("match", is_matched(body, repzo_original_doc));
|
|
255
|
+
if (is_matched(body, repzo_original_doc)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
// Update
|
|
259
|
+
try {
|
|
260
|
+
const updated_client = await repzo.client.update(
|
|
261
|
+
repzo_client._id,
|
|
262
|
+
body
|
|
263
|
+
);
|
|
264
|
+
result.updated++;
|
|
265
|
+
} catch (e) {
|
|
266
|
+
// console.log("Update Client Failed >> ", e?.response?.data, body);
|
|
267
|
+
failed_docs_report.push({
|
|
268
|
+
method: "update",
|
|
269
|
+
doc_id:
|
|
270
|
+
repzo_client === null || repzo_client === void 0
|
|
271
|
+
? void 0
|
|
272
|
+
: repzo_client._id,
|
|
273
|
+
doc: body,
|
|
274
|
+
error_message: set_error(e),
|
|
275
|
+
});
|
|
276
|
+
result.failed++;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
188
279
|
}
|
|
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
|
+
}
|
|
189
306
|
};
|
|
190
307
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
308
|
+
try {
|
|
309
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
310
|
+
Active: "Y",
|
|
311
|
+
Frozen: "N",
|
|
312
|
+
UpdateAt: date_formatting(
|
|
313
|
+
query === null || query === void 0 ? void 0 : query.updateAt,
|
|
314
|
+
"YYYYMMDD:HHmmss"
|
|
315
|
+
),
|
|
316
|
+
GroupCode:
|
|
317
|
+
(query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
318
|
+
});
|
|
319
|
+
return sap_clients.Customers;
|
|
320
|
+
} catch (e) {
|
|
321
|
+
throw e;
|
|
322
|
+
}
|
|
203
323
|
};
|
|
204
324
|
const is_matched = (body_1, body_2) => {
|
|
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
|
-
|
|
325
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
326
|
+
try {
|
|
327
|
+
const keys = [
|
|
328
|
+
"client_code",
|
|
329
|
+
"name",
|
|
330
|
+
"local_name",
|
|
331
|
+
"city",
|
|
332
|
+
"state",
|
|
333
|
+
"country",
|
|
334
|
+
"contact_name",
|
|
335
|
+
"phone",
|
|
336
|
+
"cell_phone",
|
|
337
|
+
"comment",
|
|
338
|
+
"formatted_address",
|
|
339
|
+
"tags",
|
|
340
|
+
"credit_limit",
|
|
341
|
+
// "financials",
|
|
342
|
+
"channel",
|
|
343
|
+
"paymentTerm",
|
|
344
|
+
"sv_priceList",
|
|
345
|
+
"disabled",
|
|
346
|
+
"payment_type",
|
|
347
|
+
"integrated_client_balance",
|
|
348
|
+
];
|
|
349
|
+
const integration_meta_keys = [
|
|
350
|
+
"id",
|
|
351
|
+
"PAYMENTTERM",
|
|
352
|
+
"CLIENTCREDITCONSUMED",
|
|
353
|
+
"CLIENTMAXCHEQUEVALUE",
|
|
354
|
+
"CLIENTCREDITLIMIT",
|
|
355
|
+
"CLIENTPRICELISTID",
|
|
356
|
+
];
|
|
357
|
+
for (let i = 0; i < keys.length; i++) {
|
|
358
|
+
const key = keys[i];
|
|
359
|
+
if (
|
|
360
|
+
((_a = body_1[key]) === null || _a === void 0
|
|
361
|
+
? void 0
|
|
362
|
+
: _a.toString()) !==
|
|
363
|
+
((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())
|
|
364
|
+
) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
for (let i = 0; i < integration_meta_keys.length; i++) {
|
|
369
|
+
const key = keys[i];
|
|
370
|
+
if (
|
|
371
|
+
((_d =
|
|
372
|
+
(_c =
|
|
373
|
+
body_1 === null || body_1 === void 0
|
|
374
|
+
? void 0
|
|
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
|
+
}
|
|
255
392
|
}
|
|
256
|
-
|
|
257
|
-
|
|
393
|
+
if (
|
|
394
|
+
((_h =
|
|
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;
|
|
258
414
|
}
|
|
415
|
+
return true;
|
|
416
|
+
} catch (e) {
|
|
417
|
+
throw e;
|
|
418
|
+
}
|
|
259
419
|
};
|