repzo-sap-absjo 1.0.1
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/README.md +3 -0
- package/changelog.md +17 -0
- package/lib/actions/create_invoice.d.ts +26 -0
- package/lib/actions/create_invoice.js +311 -0
- package/lib/actions/create_payment.d.ts +5 -0
- package/lib/actions/create_payment.js +177 -0
- package/lib/actions/create_proforma.d.ts +5 -0
- package/lib/actions/create_proforma.js +241 -0
- package/lib/actions/create_return_invoice.d.ts +5 -0
- package/lib/actions/create_return_invoice.js +268 -0
- package/lib/actions/create_transfer.d.ts +5 -0
- package/lib/actions/create_transfer.js +171 -0
- package/lib/actions/index.d.ts +3 -0
- package/lib/actions/index.js +31 -0
- package/lib/commands/adjust_inventory.d.ts +6 -0
- package/lib/commands/adjust_inventory.js +303 -0
- package/lib/commands/bank.d.ts +7 -0
- package/lib/commands/bank.js +301 -0
- package/lib/commands/basic.d.ts +2 -0
- package/lib/commands/basic.js +73 -0
- package/lib/commands/category.d.ts +4 -0
- package/lib/commands/category.js +193 -0
- package/lib/commands/channel.d.ts +4 -0
- package/lib/commands/channel.js +213 -0
- package/lib/commands/client.d.ts +39 -0
- package/lib/commands/client.js +410 -0
- package/lib/commands/client_disabled.d.ts +4 -0
- package/lib/commands/client_disabled.js +183 -0
- package/lib/commands/index.d.ts +23 -0
- package/lib/commands/index.js +82 -0
- package/lib/commands/join.d.ts +2 -0
- package/lib/commands/join.js +134 -0
- package/lib/commands/measureunit.d.ts +23 -0
- package/lib/commands/measureunit.js +314 -0
- package/lib/commands/measureunit_family.d.ts +12 -0
- package/lib/commands/measureunit_family.js +263 -0
- package/lib/commands/payment_term.d.ts +4 -0
- package/lib/commands/payment_term.js +217 -0
- package/lib/commands/price_list.d.ts +18 -0
- package/lib/commands/price_list.js +608 -0
- package/lib/commands/product.d.ts +39 -0
- package/lib/commands/product.js +454 -0
- package/lib/commands/product_disabled.d.ts +4 -0
- package/lib/commands/product_disabled.js +178 -0
- package/lib/commands/rep.d.ts +2 -0
- package/lib/commands/rep.js +246 -0
- package/lib/commands/tag.d.ts +2 -0
- package/lib/commands/tag.js +195 -0
- package/lib/commands/tax.d.ts +2 -0
- package/lib/commands/tax.js +198 -0
- package/lib/commands/warehouse.d.ts +4 -0
- package/lib/commands/warehouse.js +221 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.js +6 -0
- package/lib/test/actions/create_invoice.d.ts +1 -0
- package/lib/test/actions/create_invoice.js +214 -0
- package/lib/test/actions/create_payment.d.ts +1 -0
- package/lib/test/actions/create_payment.js +131 -0
- package/lib/test/actions/create_proforma.d.ts +1 -0
- package/lib/test/actions/create_proforma.js +242 -0
- package/lib/test/actions/create_return_invoice.d.ts +1 -0
- package/lib/test/actions/create_return_invoice.js +226 -0
- package/lib/test/actions/create_transfer.d.ts +1 -0
- package/lib/test/actions/create_transfer.js +142 -0
- package/lib/test/commands/adjust_inventory.d.ts +1 -0
- package/lib/test/commands/adjust_inventory.js +97 -0
- package/lib/test/commands/bank.d.ts +1 -0
- package/lib/test/commands/bank.js +97 -0
- package/lib/test/commands/basic.d.ts +1 -0
- package/lib/test/commands/basic.js +339 -0
- package/lib/test/commands/category.d.ts +1 -0
- package/lib/test/commands/category.js +97 -0
- package/lib/test/commands/channel.d.ts +1 -0
- package/lib/test/commands/channel.js +97 -0
- package/lib/test/commands/client.d.ts +1 -0
- package/lib/test/commands/client.js +97 -0
- package/lib/test/commands/client_disabled.d.ts +1 -0
- package/lib/test/commands/client_disabled.js +97 -0
- package/lib/test/commands/join.d.ts +1 -0
- package/lib/test/commands/join.js +339 -0
- package/lib/test/commands/measureunit.d.ts +1 -0
- package/lib/test/commands/measureunit.js +97 -0
- package/lib/test/commands/measureunit_family.d.ts +1 -0
- package/lib/test/commands/measureunit_family.js +97 -0
- package/lib/test/commands/payment_term.d.ts +1 -0
- package/lib/test/commands/payment_term.js +97 -0
- package/lib/test/commands/price_list.d.ts +1 -0
- package/lib/test/commands/price_list.js +97 -0
- package/lib/test/commands/product.d.ts +1 -0
- package/lib/test/commands/product.js +97 -0
- package/lib/test/commands/product_disabled.d.ts +1 -0
- package/lib/test/commands/product_disabled.js +97 -0
- package/lib/test/commands/rep.d.ts +1 -0
- package/lib/test/commands/rep.js +97 -0
- package/lib/test/commands/tag.d.ts +1 -0
- package/lib/test/commands/tag.js +97 -0
- package/lib/test/commands/tax.d.ts +1 -0
- package/lib/test/commands/tax.js +97 -0
- package/lib/test/commands/warehouse.d.ts +1 -0
- package/lib/test/commands/warehouse.js +97 -0
- package/lib/types.d.ts +77 -0
- package/lib/types.js +1 -0
- package/lib/util.d.ts +70 -0
- package/lib/util.js +164 -0
- package/package.json +51 -0
- package/src/actions/create_invoice.ts +275 -0
- package/src/actions/create_payment.ts +138 -0
- package/src/actions/create_proforma.ts +187 -0
- package/src/actions/create_return_invoice.ts +217 -0
- package/src/actions/create_transfer.ts +160 -0
- package/src/actions/index.ts +27 -0
- package/src/commands/adjust_inventory.ts +250 -0
- package/src/commands/bank.ts +243 -0
- package/src/commands/basic.ts +64 -0
- package/src/commands/category.ts +176 -0
- package/src/commands/channel.ts +219 -0
- package/src/commands/client.ts +368 -0
- package/src/commands/client_disabled.ts +158 -0
- package/src/commands/index.ts +87 -0
- package/src/commands/join.ts +80 -0
- package/src/commands/measureunit.ts +276 -0
- package/src/commands/measureunit_family.ts +209 -0
- package/src/commands/payment_term.ts +224 -0
- package/src/commands/price_list.ts +434 -0
- package/src/commands/product.ts +359 -0
- package/src/commands/product_disabled.ts +152 -0
- package/src/commands/rep.ts +209 -0
- package/src/commands/tag.ts +173 -0
- package/src/commands/tax.ts +178 -0
- package/src/commands/warehouse.ts +204 -0
- package/src/index.ts +7 -0
- package/src/test/actions/create_invoice.ts +214 -0
- package/src/test/actions/create_payment.ts +131 -0
- package/src/test/actions/create_proforma.ts +242 -0
- package/src/test/actions/create_return_invoice.ts +226 -0
- package/src/test/actions/create_transfer.ts +142 -0
- package/src/test/commands/adjust_inventory.ts +100 -0
- package/src/test/commands/bank.ts +100 -0
- package/src/test/commands/basic.ts +342 -0
- package/src/test/commands/category.ts +100 -0
- package/src/test/commands/channel.ts +100 -0
- package/src/test/commands/client.ts +100 -0
- package/src/test/commands/client_disabled.ts +100 -0
- package/src/test/commands/join.ts +342 -0
- package/src/test/commands/measureunit.ts +100 -0
- package/src/test/commands/measureunit_family.ts +100 -0
- package/src/test/commands/payment_term.ts +100 -0
- package/src/test/commands/price_list.ts +100 -0
- package/src/test/commands/product.ts +100 -0
- package/src/test/commands/product_disabled.ts +100 -0
- package/src/test/commands/rep.ts +100 -0
- package/src/test/commands/tag.ts +100 -0
- package/src/test/commands/tax.ts +100 -0
- package/src/test/commands/warehouse.ts +100 -0
- package/src/types.ts +76 -0
- package/src/util.ts +205 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import Repzo from "repzo";
|
|
2
|
+
import { _create, update_bench_time, set_error } from "../util.js";
|
|
3
|
+
import { get_sap_UoMs } from "./measureunit.js";
|
|
4
|
+
export const sync_price_list = async (commandEvent) => {
|
|
5
|
+
var _a,
|
|
6
|
+
_b,
|
|
7
|
+
_c,
|
|
8
|
+
_d,
|
|
9
|
+
_e,
|
|
10
|
+
_f,
|
|
11
|
+
_g,
|
|
12
|
+
_h,
|
|
13
|
+
_j,
|
|
14
|
+
_k,
|
|
15
|
+
_l,
|
|
16
|
+
_m,
|
|
17
|
+
_o,
|
|
18
|
+
_p,
|
|
19
|
+
_q,
|
|
20
|
+
_r,
|
|
21
|
+
_s,
|
|
22
|
+
_t,
|
|
23
|
+
_u,
|
|
24
|
+
_v,
|
|
25
|
+
_w,
|
|
26
|
+
_x;
|
|
27
|
+
const repzo = new Repzo(
|
|
28
|
+
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
29
|
+
? void 0
|
|
30
|
+
: _a.repzoApiKey,
|
|
31
|
+
{
|
|
32
|
+
env: commandEvent.env,
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
const commandLog = new Repzo.CommandLog(
|
|
36
|
+
repzo,
|
|
37
|
+
commandEvent.app,
|
|
38
|
+
commandEvent.command
|
|
39
|
+
);
|
|
40
|
+
try {
|
|
41
|
+
console.log("sync_price_list");
|
|
42
|
+
const new_bench_time = new Date().toISOString();
|
|
43
|
+
const bench_time_key = "bench_time_price_list";
|
|
44
|
+
await commandLog.load(commandEvent.sync_id);
|
|
45
|
+
await commandLog
|
|
46
|
+
.addDetail("Repzo SAP: Started Syncing Price Lists")
|
|
47
|
+
.commit();
|
|
48
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
49
|
+
const result = {
|
|
50
|
+
PL: { created: 0, updated: 0, failed: 0 },
|
|
51
|
+
PL_items: { created: 0, updated: 0, failed: 0 },
|
|
52
|
+
sap_total: 0,
|
|
53
|
+
repzo_total: 0,
|
|
54
|
+
repzo_PL_items: 0,
|
|
55
|
+
sap_UoMs_total: 0,
|
|
56
|
+
repzo_products_total: 0,
|
|
57
|
+
};
|
|
58
|
+
const failed_docs_report = [];
|
|
59
|
+
// Get SAP Price Lists
|
|
60
|
+
const sap_price_lists = await get_sap_price_list(
|
|
61
|
+
commandEvent.app.formData.sapHostUrl,
|
|
62
|
+
{ updateAt: commandEvent.app.options_formData[bench_time_key] }
|
|
63
|
+
);
|
|
64
|
+
result.sap_total =
|
|
65
|
+
sap_price_lists === null || sap_price_lists === void 0
|
|
66
|
+
? void 0
|
|
67
|
+
: sap_price_lists.length;
|
|
68
|
+
await commandLog
|
|
69
|
+
.addDetail(
|
|
70
|
+
`${result.sap_total} Price Lists in SAP changed since ${
|
|
71
|
+
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
72
|
+
}`
|
|
73
|
+
)
|
|
74
|
+
.commit();
|
|
75
|
+
// Get SAP UoMs
|
|
76
|
+
const sap_UoMs = await get_sap_UoMs(
|
|
77
|
+
commandEvent.app.formData.sapHostUrl,
|
|
78
|
+
{}
|
|
79
|
+
);
|
|
80
|
+
result.sap_UoMs_total =
|
|
81
|
+
sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
|
|
82
|
+
await commandLog
|
|
83
|
+
.addDetail(`${result.sap_total} Unit of Measures in SAP`)
|
|
84
|
+
.commit();
|
|
85
|
+
// Get Repzo Price Lists
|
|
86
|
+
const repzo_price_lists = await repzo.priceList.find({ per_page: 50000 });
|
|
87
|
+
result.repzo_total =
|
|
88
|
+
(_b =
|
|
89
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
90
|
+
? void 0
|
|
91
|
+
: repzo_price_lists.data) === null || _b === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: _b.length;
|
|
94
|
+
await commandLog
|
|
95
|
+
.addDetail(
|
|
96
|
+
`${
|
|
97
|
+
(_c =
|
|
98
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
99
|
+
? void 0
|
|
100
|
+
: repzo_price_lists.data) === null || _c === void 0
|
|
101
|
+
? void 0
|
|
102
|
+
: _c.length
|
|
103
|
+
} Price Lists in Repzo`
|
|
104
|
+
)
|
|
105
|
+
.commit();
|
|
106
|
+
// Get Repzo Products
|
|
107
|
+
const repzo_products = await repzo.product.find({
|
|
108
|
+
active: true,
|
|
109
|
+
withVariants: true,
|
|
110
|
+
per_page: 50000,
|
|
111
|
+
});
|
|
112
|
+
result.repzo_products_total =
|
|
113
|
+
(_d =
|
|
114
|
+
repzo_products === null || repzo_products === void 0
|
|
115
|
+
? void 0
|
|
116
|
+
: repzo_products.data) === null || _d === void 0
|
|
117
|
+
? void 0
|
|
118
|
+
: _d.length;
|
|
119
|
+
await commandLog
|
|
120
|
+
.addDetail(
|
|
121
|
+
`${
|
|
122
|
+
(_e =
|
|
123
|
+
repzo_products === null || repzo_products === void 0
|
|
124
|
+
? void 0
|
|
125
|
+
: repzo_products.data) === null || _e === void 0
|
|
126
|
+
? void 0
|
|
127
|
+
: _e.length
|
|
128
|
+
} Products in Repzo`
|
|
129
|
+
)
|
|
130
|
+
.commit();
|
|
131
|
+
// Get Repzo MeasureUnits
|
|
132
|
+
const repzo_UoMs = await repzo.measureunit.find({
|
|
133
|
+
disabled: false,
|
|
134
|
+
per_page: 50000,
|
|
135
|
+
});
|
|
136
|
+
result.repzo_total =
|
|
137
|
+
(_f =
|
|
138
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
139
|
+
? void 0
|
|
140
|
+
: repzo_UoMs.data) === null || _f === void 0
|
|
141
|
+
? void 0
|
|
142
|
+
: _f.length;
|
|
143
|
+
await commandLog
|
|
144
|
+
.addDetail(
|
|
145
|
+
`${
|
|
146
|
+
(_g =
|
|
147
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
148
|
+
? void 0
|
|
149
|
+
: repzo_UoMs.data) === null || _g === void 0
|
|
150
|
+
? void 0
|
|
151
|
+
: _g.length
|
|
152
|
+
} Measure Units in Repzo`
|
|
153
|
+
)
|
|
154
|
+
.commit();
|
|
155
|
+
if (
|
|
156
|
+
!((_h =
|
|
157
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
158
|
+
? void 0
|
|
159
|
+
: repzo_UoMs.data) === null || _h === void 0
|
|
160
|
+
? void 0
|
|
161
|
+
: _h.length)
|
|
162
|
+
)
|
|
163
|
+
throw "MeasureUnits in Repzo was not found";
|
|
164
|
+
const sap_unique_UoMs = {};
|
|
165
|
+
sap_UoMs.forEach((doc) => {
|
|
166
|
+
const key = `${doc.ITEMCODE}__${doc.ALTUOMCODE}`;
|
|
167
|
+
sap_unique_UoMs[key] = doc.ALTQTY;
|
|
168
|
+
});
|
|
169
|
+
// sort the data
|
|
170
|
+
const priceLists_withItems = {};
|
|
171
|
+
sap_price_lists.forEach((doc) => {
|
|
172
|
+
if (!priceLists_withItems[doc.PLDID])
|
|
173
|
+
priceLists_withItems[doc.PLDID] = [];
|
|
174
|
+
priceLists_withItems[doc.PLDID].push(doc);
|
|
175
|
+
});
|
|
176
|
+
// create priceLists
|
|
177
|
+
const priceLists_names = Object.keys(priceLists_withItems);
|
|
178
|
+
for (let i = 0; i < priceLists_names.length; i++) {
|
|
179
|
+
const price_list_name = priceLists_names[i];
|
|
180
|
+
const body = {
|
|
181
|
+
name: `PL_${price_list_name}`,
|
|
182
|
+
integration_meta: { id: `${nameSpace}_${price_list_name}` },
|
|
183
|
+
};
|
|
184
|
+
const repzo_price_list =
|
|
185
|
+
(_j =
|
|
186
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
187
|
+
? void 0
|
|
188
|
+
: repzo_price_lists.data) === null || _j === void 0
|
|
189
|
+
? void 0
|
|
190
|
+
: _j.find((pl) => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return (
|
|
193
|
+
((_a =
|
|
194
|
+
pl === null || pl === void 0
|
|
195
|
+
? void 0
|
|
196
|
+
: pl.integration_meta) === null || _a === void 0
|
|
197
|
+
? void 0
|
|
198
|
+
: _a.id) ==
|
|
199
|
+
((_b =
|
|
200
|
+
body === null || body === void 0
|
|
201
|
+
? void 0
|
|
202
|
+
: body.integration_meta) === null || _b === void 0
|
|
203
|
+
? void 0
|
|
204
|
+
: _b.id)
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
if (!repzo_price_list) {
|
|
208
|
+
// Create
|
|
209
|
+
try {
|
|
210
|
+
const created_price_list = await repzo.priceList.create(body);
|
|
211
|
+
result.PL.created++;
|
|
212
|
+
} catch (e) {
|
|
213
|
+
console.log(
|
|
214
|
+
"Create Price List Failed >> ",
|
|
215
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
216
|
+
body
|
|
217
|
+
);
|
|
218
|
+
failed_docs_report.push({
|
|
219
|
+
method: "create",
|
|
220
|
+
doc: body,
|
|
221
|
+
error_message: set_error(e),
|
|
222
|
+
});
|
|
223
|
+
result.PL.failed++;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
if (
|
|
227
|
+
(repzo_price_list === null || repzo_price_list === void 0
|
|
228
|
+
? void 0
|
|
229
|
+
: repzo_price_list.name) ==
|
|
230
|
+
(body === null || body === void 0 ? void 0 : body.name)
|
|
231
|
+
)
|
|
232
|
+
continue;
|
|
233
|
+
// Update
|
|
234
|
+
try {
|
|
235
|
+
const updated_price_list = await repzo.priceList.update(
|
|
236
|
+
repzo_price_list._id,
|
|
237
|
+
body
|
|
238
|
+
);
|
|
239
|
+
result.PL.updated++;
|
|
240
|
+
} catch (e) {
|
|
241
|
+
console.log(
|
|
242
|
+
"Update Price List Failed >> ",
|
|
243
|
+
(_k = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
244
|
+
_k === void 0
|
|
245
|
+
? void 0
|
|
246
|
+
: _k.data,
|
|
247
|
+
body
|
|
248
|
+
);
|
|
249
|
+
failed_docs_report.push({
|
|
250
|
+
method: "update",
|
|
251
|
+
doc_id:
|
|
252
|
+
repzo_price_list === null || repzo_price_list === void 0
|
|
253
|
+
? void 0
|
|
254
|
+
: repzo_price_list._id,
|
|
255
|
+
doc: body,
|
|
256
|
+
error_message: set_error(e),
|
|
257
|
+
});
|
|
258
|
+
result.PL.failed++;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Price List Items ***************************************
|
|
263
|
+
await commandLog
|
|
264
|
+
.addDetail(`Start Sync Price List Items From SAP to Repzo`)
|
|
265
|
+
.commit();
|
|
266
|
+
const repzo_all_priceLists = await repzo.priceList.find({
|
|
267
|
+
disabled: false,
|
|
268
|
+
per_page: 50000,
|
|
269
|
+
});
|
|
270
|
+
await commandLog
|
|
271
|
+
.addDetail(
|
|
272
|
+
`${
|
|
273
|
+
(_l =
|
|
274
|
+
repzo_all_priceLists === null || repzo_all_priceLists === void 0
|
|
275
|
+
? void 0
|
|
276
|
+
: repzo_all_priceLists.data) === null || _l === void 0
|
|
277
|
+
? void 0
|
|
278
|
+
: _l.length
|
|
279
|
+
} Price Lists in Repzo`
|
|
280
|
+
)
|
|
281
|
+
.commit();
|
|
282
|
+
if (
|
|
283
|
+
!((_m =
|
|
284
|
+
repzo_all_priceLists === null || repzo_all_priceLists === void 0
|
|
285
|
+
? void 0
|
|
286
|
+
: repzo_all_priceLists.data) === null || _m === void 0
|
|
287
|
+
? void 0
|
|
288
|
+
: _m.length)
|
|
289
|
+
)
|
|
290
|
+
throw `No Price Lists was found On Repzo`;
|
|
291
|
+
for (let priceList_name in priceLists_withItems) {
|
|
292
|
+
const repzo_PriceList =
|
|
293
|
+
(_o =
|
|
294
|
+
repzo_all_priceLists === null || repzo_all_priceLists === void 0
|
|
295
|
+
? void 0
|
|
296
|
+
: repzo_all_priceLists.data) === null || _o === void 0
|
|
297
|
+
? void 0
|
|
298
|
+
: _o.find((pl) => {
|
|
299
|
+
var _a;
|
|
300
|
+
return (
|
|
301
|
+
((_a = pl.integration_meta) === null || _a === void 0
|
|
302
|
+
? void 0
|
|
303
|
+
: _a.id) == `${nameSpace}_${priceList_name}`
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
if (!repzo_PriceList) {
|
|
307
|
+
console.log(
|
|
308
|
+
`Price list with PLDID: ${priceList_name} was not created or disabled`
|
|
309
|
+
);
|
|
310
|
+
failed_docs_report.push({
|
|
311
|
+
method: "create",
|
|
312
|
+
// doc: priceLists_withItems[priceList_name],
|
|
313
|
+
error_message: set_error(
|
|
314
|
+
`Failed Create PriceList Items: number of PL items: ${priceLists_withItems[priceList_name].length} => Because Price list with PLDID: ${priceList_name} was not created or disabled`
|
|
315
|
+
),
|
|
316
|
+
});
|
|
317
|
+
result.PL_items.failed +=
|
|
318
|
+
((_p = priceLists_withItems[priceList_name]) === null || _p === void 0
|
|
319
|
+
? void 0
|
|
320
|
+
: _p.length) || 0;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
const repzo_price_list_items = await repzo.priceListItem.find({
|
|
324
|
+
disabled: false,
|
|
325
|
+
pricelist_id:
|
|
326
|
+
repzo_PriceList === null || repzo_PriceList === void 0
|
|
327
|
+
? void 0
|
|
328
|
+
: repzo_PriceList._id,
|
|
329
|
+
per_page: 50000,
|
|
330
|
+
});
|
|
331
|
+
// Create Price list items
|
|
332
|
+
const priceList_items = {};
|
|
333
|
+
priceLists_withItems[priceList_name].forEach((doc) => {
|
|
334
|
+
if (!sap_unique_UoMs[`${doc.PLITEMID}__${doc.PLITEMUNIT}`]) {
|
|
335
|
+
console.log(
|
|
336
|
+
`error => ${doc.PLITEMID}__${doc.PLITEMUNIT} was not found on the Uom`
|
|
337
|
+
);
|
|
338
|
+
failed_docs_report.push({
|
|
339
|
+
method: "create",
|
|
340
|
+
// doc: priceLists_withItems[priceList_name],
|
|
341
|
+
error_message: set_error(
|
|
342
|
+
`Create PL items => PLITEMID: ${doc.PLITEMID}, PLITEMUNIT:${doc.PLITEMUNIT} was not found on the Uom`
|
|
343
|
+
),
|
|
344
|
+
});
|
|
345
|
+
result.PL_items.failed++;
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
doc.factor = sap_unique_UoMs[`${doc.PLITEMID}__${doc.PLITEMUNIT}`];
|
|
349
|
+
const key = `${doc.PLITEMID}`;
|
|
350
|
+
if (!priceList_items[key]) {
|
|
351
|
+
priceList_items[key] = doc;
|
|
352
|
+
} else {
|
|
353
|
+
const current_doc = priceList_items[key];
|
|
354
|
+
if (
|
|
355
|
+
(current_doc === null || current_doc === void 0
|
|
356
|
+
? void 0
|
|
357
|
+
: current_doc.factor) >
|
|
358
|
+
(doc === null || doc === void 0 ? void 0 : doc.factor)
|
|
359
|
+
) {
|
|
360
|
+
priceList_items[key] = doc;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
const priceListItems = Object.values(priceList_items);
|
|
365
|
+
for (let j = 0; j < priceListItems.length; j++) {
|
|
366
|
+
const item = priceListItems[j];
|
|
367
|
+
if (!item.factor && item.factor !== 0) {
|
|
368
|
+
failed_docs_report.push({
|
|
369
|
+
method: "create",
|
|
370
|
+
// doc: priceLists_withItems[priceList_name],
|
|
371
|
+
error_message: set_error(
|
|
372
|
+
`Price List: ${item.PLDID} of Product with PLITEMID: ${item.PLITEMID} does not have Uom`
|
|
373
|
+
),
|
|
374
|
+
});
|
|
375
|
+
result.PL_items.failed++;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const repzo_product =
|
|
379
|
+
(_q =
|
|
380
|
+
repzo_products === null || repzo_products === void 0
|
|
381
|
+
? void 0
|
|
382
|
+
: repzo_products.data) === null || _q === void 0
|
|
383
|
+
? void 0
|
|
384
|
+
: _q.find((product) => {
|
|
385
|
+
var _a;
|
|
386
|
+
return (
|
|
387
|
+
((_a =
|
|
388
|
+
product === null || product === void 0
|
|
389
|
+
? void 0
|
|
390
|
+
: product.integration_meta) === null || _a === void 0
|
|
391
|
+
? void 0
|
|
392
|
+
: _a.id) == `${nameSpace}_${item.PLITEMID}`
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
if (!repzo_product) {
|
|
396
|
+
failed_docs_report.push({
|
|
397
|
+
method: "create",
|
|
398
|
+
// doc: priceLists_withItems[priceList_name],
|
|
399
|
+
error_message: set_error(
|
|
400
|
+
`Price List: ${item.PLDID} of Product with PLITEMID: ${item.PLITEMID} was not found or disabled`
|
|
401
|
+
),
|
|
402
|
+
});
|
|
403
|
+
result.PL_items.failed++;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const repzo_product_uom =
|
|
407
|
+
(_r =
|
|
408
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
409
|
+
? void 0
|
|
410
|
+
: repzo_UoMs.data) === null || _r === void 0
|
|
411
|
+
? void 0
|
|
412
|
+
: _r.find((uom) => {
|
|
413
|
+
var _a, _b;
|
|
414
|
+
return (
|
|
415
|
+
((_a = uom === null || uom === void 0 ? void 0 : uom._id) ===
|
|
416
|
+
null || _a === void 0
|
|
417
|
+
? void 0
|
|
418
|
+
: _a.toString()) ==
|
|
419
|
+
((_b =
|
|
420
|
+
repzo_product === null || repzo_product === void 0
|
|
421
|
+
? void 0
|
|
422
|
+
: repzo_product.sv_measureUnit) === null || _b === void 0
|
|
423
|
+
? void 0
|
|
424
|
+
: _b.toString())
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
if (!repzo_product_uom) {
|
|
428
|
+
failed_docs_report.push({
|
|
429
|
+
method: "create",
|
|
430
|
+
// doc: priceLists_withItems[priceList_name],
|
|
431
|
+
error_message: set_error(
|
|
432
|
+
`Price List: ${item.PLDID} of MeasureUnit with _id: ${
|
|
433
|
+
(_s =
|
|
434
|
+
repzo_product === null || repzo_product === void 0
|
|
435
|
+
? void 0
|
|
436
|
+
: repzo_product.sv_measureUnit) === null || _s === void 0
|
|
437
|
+
? void 0
|
|
438
|
+
: _s.toString()
|
|
439
|
+
} was not found or disabled`
|
|
440
|
+
),
|
|
441
|
+
});
|
|
442
|
+
result.PL_items.failed++;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const price =
|
|
446
|
+
repzo_product_uom &&
|
|
447
|
+
(repzo_product_uom === null || repzo_product_uom === void 0
|
|
448
|
+
? void 0
|
|
449
|
+
: repzo_product_uom.factor) == 1
|
|
450
|
+
? Math.round(item.PLITEMPRICEVALUE * 1000)
|
|
451
|
+
: Math.round(
|
|
452
|
+
(item.PLITEMPRICEVALUE * 1000) / repzo_product_uom.factor
|
|
453
|
+
);
|
|
454
|
+
const variant =
|
|
455
|
+
(_t =
|
|
456
|
+
repzo_product === null || repzo_product === void 0
|
|
457
|
+
? void 0
|
|
458
|
+
: repzo_product.variants) === null || _t === void 0
|
|
459
|
+
? void 0
|
|
460
|
+
: _t.find((variant) => {
|
|
461
|
+
var _a;
|
|
462
|
+
return (
|
|
463
|
+
((_a =
|
|
464
|
+
variant === null || variant === void 0
|
|
465
|
+
? void 0
|
|
466
|
+
: variant.integration_meta) === null || _a === void 0
|
|
467
|
+
? void 0
|
|
468
|
+
: _a.id) == `${nameSpace}_${item.PLITEMID}`
|
|
469
|
+
);
|
|
470
|
+
});
|
|
471
|
+
if (!variant) {
|
|
472
|
+
console.log(
|
|
473
|
+
`Price List: ${item.PLDID} of Variant with PLITEMID: ${item.PLITEMID} was not found`
|
|
474
|
+
);
|
|
475
|
+
failed_docs_report.push({
|
|
476
|
+
method: "create",
|
|
477
|
+
// doc: priceLists_withItems[priceList_name],
|
|
478
|
+
error_message: set_error(
|
|
479
|
+
`Price List: ${item.PLDID} of Variant with PLITEMID: ${item.PLITEMID} was not found`
|
|
480
|
+
),
|
|
481
|
+
});
|
|
482
|
+
result.PL_items.failed++;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const body = {
|
|
486
|
+
integration_meta: {
|
|
487
|
+
id: `${nameSpace}_${item.PLDID}_${item.PLITEMID}`,
|
|
488
|
+
},
|
|
489
|
+
product_id: repzo_product._id,
|
|
490
|
+
variant_id: variant._id,
|
|
491
|
+
pricelist_id: repzo_PriceList._id,
|
|
492
|
+
price: price,
|
|
493
|
+
};
|
|
494
|
+
// console.log(data);
|
|
495
|
+
const is_found_in_repzo_db =
|
|
496
|
+
(_u =
|
|
497
|
+
repzo_price_list_items === null || repzo_price_list_items === void 0
|
|
498
|
+
? void 0
|
|
499
|
+
: repzo_price_list_items.data) === null || _u === void 0
|
|
500
|
+
? void 0
|
|
501
|
+
: _u.find((item) => {
|
|
502
|
+
var _a, _b;
|
|
503
|
+
return (
|
|
504
|
+
((_a =
|
|
505
|
+
item === null || item === void 0
|
|
506
|
+
? void 0
|
|
507
|
+
: item.integration_meta) === null || _a === void 0
|
|
508
|
+
? void 0
|
|
509
|
+
: _a.id) ==
|
|
510
|
+
((_b =
|
|
511
|
+
body === null || body === void 0
|
|
512
|
+
? void 0
|
|
513
|
+
: body.integration_meta) === null || _b === void 0
|
|
514
|
+
? void 0
|
|
515
|
+
: _b.id)
|
|
516
|
+
);
|
|
517
|
+
});
|
|
518
|
+
// console.log(`${data.integration_meta?.id} => ${is_found_in_repzo_db ? "create" : "update"}`)
|
|
519
|
+
if (!is_found_in_repzo_db) {
|
|
520
|
+
// Create
|
|
521
|
+
try {
|
|
522
|
+
const created_PL_item = await repzo.priceListItem.create(body);
|
|
523
|
+
result.PL_items.created++;
|
|
524
|
+
} catch (e) {
|
|
525
|
+
console.log(
|
|
526
|
+
"Create PL Item Failed >> ",
|
|
527
|
+
(_v = e === null || e === void 0 ? void 0 : e.response) ===
|
|
528
|
+
null || _v === void 0
|
|
529
|
+
? void 0
|
|
530
|
+
: _v.data,
|
|
531
|
+
body
|
|
532
|
+
);
|
|
533
|
+
failed_docs_report.push({
|
|
534
|
+
method: "create",
|
|
535
|
+
// doc: body,
|
|
536
|
+
error_message: set_error(e),
|
|
537
|
+
});
|
|
538
|
+
result.PL_items.failed++;
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
if (is_found_in_repzo_db.price == body.price) continue;
|
|
542
|
+
// Update
|
|
543
|
+
try {
|
|
544
|
+
const updated_PL_item = await repzo.priceListItem.update(
|
|
545
|
+
is_found_in_repzo_db._id,
|
|
546
|
+
body
|
|
547
|
+
);
|
|
548
|
+
result.PL_items.updated++;
|
|
549
|
+
} catch (e) {
|
|
550
|
+
console.log(
|
|
551
|
+
"Update Price List Item Failed >> ",
|
|
552
|
+
(_w = e === null || e === void 0 ? void 0 : e.response) ===
|
|
553
|
+
null || _w === void 0
|
|
554
|
+
? void 0
|
|
555
|
+
: _w.data,
|
|
556
|
+
body
|
|
557
|
+
);
|
|
558
|
+
failed_docs_report.push({
|
|
559
|
+
method: "update",
|
|
560
|
+
doc_id:
|
|
561
|
+
is_found_in_repzo_db === null || is_found_in_repzo_db === void 0
|
|
562
|
+
? void 0
|
|
563
|
+
: is_found_in_repzo_db._id,
|
|
564
|
+
doc: body,
|
|
565
|
+
error_message: set_error(e),
|
|
566
|
+
});
|
|
567
|
+
result.PL_items.failed++;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
// console.log(result);
|
|
573
|
+
await update_bench_time(
|
|
574
|
+
repzo,
|
|
575
|
+
commandEvent.app._id,
|
|
576
|
+
bench_time_key,
|
|
577
|
+
new_bench_time
|
|
578
|
+
);
|
|
579
|
+
await commandLog
|
|
580
|
+
.setStatus(
|
|
581
|
+
"success",
|
|
582
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
583
|
+
)
|
|
584
|
+
.setBody(result)
|
|
585
|
+
.commit();
|
|
586
|
+
return result;
|
|
587
|
+
} catch (e) {
|
|
588
|
+
//@ts-ignore
|
|
589
|
+
console.error(
|
|
590
|
+
((_x = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
591
|
+
_x === void 0
|
|
592
|
+
? void 0
|
|
593
|
+
: _x.data) || e
|
|
594
|
+
);
|
|
595
|
+
await commandLog.setStatus("fail", e).commit();
|
|
596
|
+
throw e;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
const get_sap_price_list = async (serviceEndPoint, query) => {
|
|
600
|
+
try {
|
|
601
|
+
const sap_price_lists = await _create(serviceEndPoint, "/PriceList", {
|
|
602
|
+
UpdateAt: query === null || query === void 0 ? void 0 : query.updateAt,
|
|
603
|
+
});
|
|
604
|
+
return sap_price_lists.PriceList;
|
|
605
|
+
} catch (e) {
|
|
606
|
+
throw e;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CommandEvent, Result } from "../types";
|
|
2
|
+
export interface SAPProduct {
|
|
3
|
+
ITEMBARCODE: string;
|
|
4
|
+
ITEMDESC: string;
|
|
5
|
+
ITEMAVALIABLEQTY: number;
|
|
6
|
+
ITEMTAX: number;
|
|
7
|
+
ITEMTAXCODE: string;
|
|
8
|
+
ITEMCODE: string;
|
|
9
|
+
Division: string;
|
|
10
|
+
"Parent Category": string;
|
|
11
|
+
"Sub-Category": string;
|
|
12
|
+
"Item Type": string;
|
|
13
|
+
DEFAULTITEMUOM: string;
|
|
14
|
+
DEFAULTSALEUOMID: number;
|
|
15
|
+
INVUOMID: number;
|
|
16
|
+
ITEMSALESUOMS: string;
|
|
17
|
+
ITEMQTY: number;
|
|
18
|
+
ITEMGROUPCODE: number;
|
|
19
|
+
PRICE: number;
|
|
20
|
+
ISSERIAL: "Y" | "N";
|
|
21
|
+
ITEMDESCF: string;
|
|
22
|
+
UOMGROUPENTRY: number;
|
|
23
|
+
MILCODE: string;
|
|
24
|
+
MODELNO: string;
|
|
25
|
+
BRAND: string;
|
|
26
|
+
ITEMSUBCATEGORY: string;
|
|
27
|
+
CREATEDATE: string;
|
|
28
|
+
UPDATEDATE: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SAPProducts {
|
|
31
|
+
result: "Success";
|
|
32
|
+
Items: SAPProduct[];
|
|
33
|
+
}
|
|
34
|
+
export declare const sync_product: (commandEvent: CommandEvent) => Promise<
|
|
35
|
+
Result & {
|
|
36
|
+
repzo_total_taxes: number;
|
|
37
|
+
repzo_total_categories: number;
|
|
38
|
+
}
|
|
39
|
+
>;
|