repzo-sap-absjo 1.0.53 → 1.0.55
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_client.js +1 -0
- package/lib/actions/create_invoice.d.ts +1 -1
- package/lib/actions/create_invoice.js +55 -8
- package/lib/actions/create_payment.d.ts +1 -1
- package/lib/actions/create_proforma.d.ts +1 -1
- package/lib/actions/create_proforma.js +67 -40
- package/lib/actions/create_return_invoice.d.ts +1 -1
- package/lib/actions/create_return_invoice.js +46 -2
- package/lib/actions/create_transfer.d.ts +1 -1
- package/lib/actions/index.d.ts +1 -1
- package/lib/commands/adjust_inventory.js +221 -4
- package/lib/commands/rep.js +65 -29
- package/lib/commands/warehouse.js +149 -4
- package/lib/index.d.ts +1 -1
- package/lib/types.d.ts +4 -0
- package/lib/util.d.ts +4 -4
- package/package.json +1 -1
- package/src/actions/create_client.ts +3 -2
- package/src/actions/create_invoice.ts +13 -4
- package/src/actions/create_proforma.ts +12 -6
- package/src/actions/create_return_invoice.ts +10 -1
- package/src/commands/adjust_inventory.ts +169 -2
- package/src/commands/bank.ts +5 -1
- package/src/commands/brand.ts +2 -2
- package/src/commands/category.ts +2 -2
- package/src/commands/channel.ts +2 -2
- package/src/commands/client.ts +2 -2
- package/src/commands/client_disabled.ts +2 -2
- package/src/commands/measureunit.ts +2 -2
- package/src/commands/payment_term.ts +2 -2
- package/src/commands/price_list.ts +2 -2
- package/src/commands/price_list_disabled.ts +2 -2
- package/src/commands/product.ts +8 -4
- package/src/commands/product_disabled.ts +8 -4
- package/src/commands/rep.ts +26 -2
- package/src/commands/tag.ts +2 -2
- package/src/commands/tax.ts +2 -2
- package/src/commands/warehouse.ts +136 -3
- package/src/types.ts +4 -0
|
@@ -3,7 +3,28 @@ import { _create, set_error, getUniqueConcatenatedValues } from "../util.js";
|
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
export const create_invoice = async (event, options) => {
|
|
6
|
-
var _a,
|
|
6
|
+
var _a,
|
|
7
|
+
_b,
|
|
8
|
+
_c,
|
|
9
|
+
_d,
|
|
10
|
+
_e,
|
|
11
|
+
_f,
|
|
12
|
+
_g,
|
|
13
|
+
_h,
|
|
14
|
+
_j,
|
|
15
|
+
_k,
|
|
16
|
+
_l,
|
|
17
|
+
_m,
|
|
18
|
+
_o,
|
|
19
|
+
_p,
|
|
20
|
+
_q,
|
|
21
|
+
_r,
|
|
22
|
+
_s,
|
|
23
|
+
_t,
|
|
24
|
+
_u,
|
|
25
|
+
_v,
|
|
26
|
+
_w,
|
|
27
|
+
_x;
|
|
7
28
|
const repzo = new Repzo(
|
|
8
29
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
9
30
|
{ env: options.env }
|
|
@@ -338,6 +359,32 @@ export const create_invoice = async (event, options) => {
|
|
|
338
359
|
: _q.DepartmentCode), // "D2",
|
|
339
360
|
});
|
|
340
361
|
}
|
|
362
|
+
let WarehouseCode = repzo_warehouse.code;
|
|
363
|
+
if (
|
|
364
|
+
(_s =
|
|
365
|
+
(_r = options.data) === null || _r === void 0
|
|
366
|
+
? void 0
|
|
367
|
+
: _r.virtualWarehouses) === null || _s === void 0
|
|
368
|
+
? void 0
|
|
369
|
+
: _s.consider_virtual_warehouse
|
|
370
|
+
) {
|
|
371
|
+
if (
|
|
372
|
+
(_t = repzo_warehouse.integration_meta) === null || _t === void 0
|
|
373
|
+
? void 0
|
|
374
|
+
: _t.is_virtual_warehouse
|
|
375
|
+
) {
|
|
376
|
+
if (
|
|
377
|
+
(_u =
|
|
378
|
+
repzo_rep === null || repzo_rep === void 0
|
|
379
|
+
? void 0
|
|
380
|
+
: repzo_rep.integration_meta) === null || _u === void 0
|
|
381
|
+
? void 0
|
|
382
|
+
: _u.USERWHSCODE
|
|
383
|
+
) {
|
|
384
|
+
WarehouseCode = repzo_rep.integration_meta.USERWHSCODE;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
341
388
|
const sap_invoice = {
|
|
342
389
|
RepzoSerial: repzo_invoice.serial_number.formatted,
|
|
343
390
|
RefNum:
|
|
@@ -360,7 +407,7 @@ export const create_invoice = async (event, options) => {
|
|
|
360
407
|
ClientCode: repzo_client.client_code,
|
|
361
408
|
DiscountPerc: "0",
|
|
362
409
|
Note: repzo_invoice.comment,
|
|
363
|
-
WarehouseCode: repzo_warehouse.code,
|
|
410
|
+
WarehouseCode: WarehouseCode || repzo_warehouse.code,
|
|
364
411
|
LinesDetails: items,
|
|
365
412
|
U_ISTDQR: repzo_invoice.ubl_qr
|
|
366
413
|
? repzo_invoice.ubl_qr
|
|
@@ -396,15 +443,15 @@ export const create_invoice = async (event, options) => {
|
|
|
396
443
|
result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
|
|
397
444
|
} catch (e) {
|
|
398
445
|
if (
|
|
399
|
-
typeof ((
|
|
446
|
+
typeof ((_v = set_error(e)) === null || _v === void 0
|
|
400
447
|
? void 0
|
|
401
|
-
:
|
|
402
|
-
((
|
|
403
|
-
(
|
|
448
|
+
: _v.message) === "string" &&
|
|
449
|
+
((_x =
|
|
450
|
+
(_w = set_error(e)) === null || _w === void 0
|
|
404
451
|
? void 0
|
|
405
|
-
:
|
|
452
|
+
: _w.message) === null || _x === void 0
|
|
406
453
|
? void 0
|
|
407
|
-
:
|
|
454
|
+
: _x.includes("this Sales Order is allready existed"))
|
|
408
455
|
) {
|
|
409
456
|
result = {
|
|
410
457
|
success: true,
|
|
@@ -23,7 +23,10 @@ export const create_proforma = async (event, options) => {
|
|
|
23
23
|
_t,
|
|
24
24
|
_u,
|
|
25
25
|
_v,
|
|
26
|
-
_w
|
|
26
|
+
_w,
|
|
27
|
+
_x,
|
|
28
|
+
_y,
|
|
29
|
+
_z;
|
|
27
30
|
const repzo = new Repzo(
|
|
28
31
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
29
32
|
{ env: options.env }
|
|
@@ -97,13 +100,37 @@ export const create_proforma = async (event, options) => {
|
|
|
97
100
|
? void 0
|
|
98
101
|
: repzo_rep.assigned_warehouse)
|
|
99
102
|
) {
|
|
103
|
+
const warehouse =
|
|
104
|
+
repzo_rep === null || repzo_rep === void 0
|
|
105
|
+
? void 0
|
|
106
|
+
: repzo_rep.assigned_warehouse;
|
|
100
107
|
rep_warehouse_code =
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
warehouse === null || warehouse === void 0 ? void 0 : warehouse.code;
|
|
109
|
+
if (
|
|
110
|
+
(_g =
|
|
111
|
+
(_f = options.data) === null || _f === void 0
|
|
103
112
|
? void 0
|
|
104
|
-
:
|
|
113
|
+
: _f.virtualWarehouses) === null || _g === void 0
|
|
105
114
|
? void 0
|
|
106
|
-
:
|
|
115
|
+
: _g.consider_virtual_warehouse
|
|
116
|
+
) {
|
|
117
|
+
if (
|
|
118
|
+
(_h = warehouse.integration_meta) === null || _h === void 0
|
|
119
|
+
? void 0
|
|
120
|
+
: _h.is_virtual_warehouse
|
|
121
|
+
) {
|
|
122
|
+
if (
|
|
123
|
+
(_j =
|
|
124
|
+
repzo_rep === null || repzo_rep === void 0
|
|
125
|
+
? void 0
|
|
126
|
+
: repzo_rep.integration_meta) === null || _j === void 0
|
|
127
|
+
? void 0
|
|
128
|
+
: _j.USERWHSCODE
|
|
129
|
+
) {
|
|
130
|
+
rep_warehouse_code = repzo_rep.integration_meta.USERWHSCODE;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
107
134
|
}
|
|
108
135
|
// Get Repzo Client
|
|
109
136
|
const repzo_client = await repzo.client.get(
|
|
@@ -116,9 +143,9 @@ export const create_proforma = async (event, options) => {
|
|
|
116
143
|
const repzo_tax_ids = {};
|
|
117
144
|
const repzo_measureunit_ids = {};
|
|
118
145
|
const repzo_product_ids = {};
|
|
119
|
-
(
|
|
146
|
+
(_k = repzo_proforma.items) === null || _k === void 0
|
|
120
147
|
? void 0
|
|
121
|
-
:
|
|
148
|
+
: _k.forEach((item) => {
|
|
122
149
|
var _a, _b, _c;
|
|
123
150
|
if (item) {
|
|
124
151
|
repzo_tax_ids[
|
|
@@ -176,12 +203,12 @@ export const create_proforma = async (event, options) => {
|
|
|
176
203
|
{ per_page: 50000 }
|
|
177
204
|
);
|
|
178
205
|
const all_promotions = {};
|
|
179
|
-
(
|
|
206
|
+
(_l =
|
|
180
207
|
repzo_proforma === null || repzo_proforma === void 0
|
|
181
208
|
? void 0
|
|
182
|
-
: repzo_proforma.promotions) === null ||
|
|
209
|
+
: repzo_proforma.promotions) === null || _l === void 0
|
|
183
210
|
? void 0
|
|
184
|
-
:
|
|
211
|
+
: _l.forEach((promo) => {
|
|
185
212
|
if (!promo) return;
|
|
186
213
|
all_promotions[promo._id] = {
|
|
187
214
|
_id: promo._id,
|
|
@@ -194,23 +221,23 @@ export const create_proforma = async (event, options) => {
|
|
|
194
221
|
for (
|
|
195
222
|
let i = 0;
|
|
196
223
|
i <
|
|
197
|
-
((
|
|
224
|
+
((_m =
|
|
198
225
|
repzo_proforma === null || repzo_proforma === void 0
|
|
199
226
|
? void 0
|
|
200
|
-
: repzo_proforma.items) === null ||
|
|
227
|
+
: repzo_proforma.items) === null || _m === void 0
|
|
201
228
|
? void 0
|
|
202
|
-
:
|
|
229
|
+
: _m.length);
|
|
203
230
|
i++
|
|
204
231
|
) {
|
|
205
232
|
const item = repzo_proforma.items[i];
|
|
206
233
|
// Get Repzo Tax
|
|
207
234
|
const repzo_tax =
|
|
208
|
-
(
|
|
235
|
+
(_o =
|
|
209
236
|
repzo_taxes === null || repzo_taxes === void 0
|
|
210
237
|
? void 0
|
|
211
|
-
: repzo_taxes.data) === null ||
|
|
238
|
+
: repzo_taxes.data) === null || _o === void 0
|
|
212
239
|
? void 0
|
|
213
|
-
:
|
|
240
|
+
: _o.find((t) => {
|
|
214
241
|
var _a, _b, _c;
|
|
215
242
|
return (
|
|
216
243
|
((_a = t._id) === null || _a === void 0
|
|
@@ -227,12 +254,12 @@ export const create_proforma = async (event, options) => {
|
|
|
227
254
|
if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
|
|
228
255
|
// Get Repzo UoM
|
|
229
256
|
const repzo_measureunit =
|
|
230
|
-
(
|
|
257
|
+
(_p =
|
|
231
258
|
repzo_measureunits === null || repzo_measureunits === void 0
|
|
232
259
|
? void 0
|
|
233
|
-
: repzo_measureunits.data) === null ||
|
|
260
|
+
: repzo_measureunits.data) === null || _p === void 0
|
|
234
261
|
? void 0
|
|
235
|
-
:
|
|
262
|
+
: _p.find((m) => {
|
|
236
263
|
var _a, _b, _c;
|
|
237
264
|
return (
|
|
238
265
|
((_a = m._id) === null || _a === void 0
|
|
@@ -248,16 +275,16 @@ export const create_proforma = async (event, options) => {
|
|
|
248
275
|
});
|
|
249
276
|
if (!repzo_measureunit)
|
|
250
277
|
throw `Uom with _id: ${
|
|
251
|
-
(
|
|
278
|
+
(_q = item.measureunit) === null || _q === void 0 ? void 0 : _q._id
|
|
252
279
|
} not found in Repzo`;
|
|
253
280
|
// Get Repzo Product
|
|
254
281
|
const repzo_product =
|
|
255
|
-
(
|
|
282
|
+
(_r =
|
|
256
283
|
repzo_products === null || repzo_products === void 0
|
|
257
284
|
? void 0
|
|
258
|
-
: repzo_products.data) === null ||
|
|
285
|
+
: repzo_products.data) === null || _r === void 0
|
|
259
286
|
? void 0
|
|
260
|
-
:
|
|
287
|
+
: _r.find((p) => {
|
|
261
288
|
var _a, _b, _c;
|
|
262
289
|
return (
|
|
263
290
|
((_a = p._id) === null || _a === void 0
|
|
@@ -301,19 +328,19 @@ export const create_proforma = async (event, options) => {
|
|
|
301
328
|
LineTotal: item.total_before_tax / 1000,
|
|
302
329
|
UomCode: repzo_measureunit.integration_meta.ALTUOMID,
|
|
303
330
|
Brand:
|
|
304
|
-
(
|
|
331
|
+
(_s = repzo_product.integration_meta) === null || _s === void 0
|
|
305
332
|
? void 0
|
|
306
|
-
:
|
|
333
|
+
: _s.BRAND,
|
|
307
334
|
Department:
|
|
308
|
-
((
|
|
335
|
+
((_t =
|
|
309
336
|
repzo_rep === null || repzo_rep === void 0
|
|
310
337
|
? void 0
|
|
311
|
-
: repzo_rep.integration_meta) === null ||
|
|
338
|
+
: repzo_rep.integration_meta) === null || _t === void 0
|
|
312
339
|
? void 0
|
|
313
|
-
:
|
|
314
|
-
((
|
|
340
|
+
: _t.DEPARTMENTCODE) ||
|
|
341
|
+
((_u = options.data) === null || _u === void 0
|
|
315
342
|
? void 0
|
|
316
|
-
:
|
|
343
|
+
: _u.DepartmentCode), // "D2"
|
|
317
344
|
});
|
|
318
345
|
}
|
|
319
346
|
const sap_invoice = {
|
|
@@ -322,9 +349,9 @@ export const create_proforma = async (event, options) => {
|
|
|
322
349
|
ExternalSerial: repzo_proforma.external_serial_number,
|
|
323
350
|
SalPersCode: repzo_rep
|
|
324
351
|
? repzo_rep.integration_id
|
|
325
|
-
: (
|
|
352
|
+
: (_v = options.data) === null || _v === void 0
|
|
326
353
|
? void 0
|
|
327
|
-
:
|
|
354
|
+
: _v.SalPersCode, // "111",
|
|
328
355
|
DocDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format(
|
|
329
356
|
"YYYYMMDD"
|
|
330
357
|
),
|
|
@@ -339,9 +366,9 @@ export const create_proforma = async (event, options) => {
|
|
|
339
366
|
Note: repzo_proforma.comment,
|
|
340
367
|
WarehouseCode:
|
|
341
368
|
rep_warehouse_code ||
|
|
342
|
-
((
|
|
369
|
+
((_w = options.data) === null || _w === void 0
|
|
343
370
|
? void 0
|
|
344
|
-
:
|
|
371
|
+
: _w.defaultWarehouseForSalesOrder), // "1",
|
|
345
372
|
LinesDetails: items,
|
|
346
373
|
};
|
|
347
374
|
// console.dir(sap_invoice, { depth: null });
|
|
@@ -354,15 +381,15 @@ export const create_proforma = async (event, options) => {
|
|
|
354
381
|
result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
|
|
355
382
|
} catch (e) {
|
|
356
383
|
if (
|
|
357
|
-
typeof ((
|
|
384
|
+
typeof ((_x = set_error(e)) === null || _x === void 0
|
|
358
385
|
? void 0
|
|
359
|
-
:
|
|
360
|
-
((
|
|
361
|
-
(
|
|
386
|
+
: _x.message) === "string" &&
|
|
387
|
+
((_z =
|
|
388
|
+
(_y = set_error(e)) === null || _y === void 0
|
|
362
389
|
? void 0
|
|
363
|
-
:
|
|
390
|
+
: _y.message) === null || _z === void 0
|
|
364
391
|
? void 0
|
|
365
|
-
:
|
|
392
|
+
: _z.includes("this Sales Order is allready existed"))
|
|
366
393
|
) {
|
|
367
394
|
result = { success: true, message: "Sales Order already exists" };
|
|
368
395
|
} else {
|
|
@@ -3,7 +3,25 @@ import { _create } from "../util.js";
|
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
export const create_return_invoice = async (event, options) => {
|
|
6
|
-
var _a,
|
|
6
|
+
var _a,
|
|
7
|
+
_b,
|
|
8
|
+
_c,
|
|
9
|
+
_d,
|
|
10
|
+
_e,
|
|
11
|
+
_f,
|
|
12
|
+
_g,
|
|
13
|
+
_h,
|
|
14
|
+
_j,
|
|
15
|
+
_k,
|
|
16
|
+
_l,
|
|
17
|
+
_m,
|
|
18
|
+
_o,
|
|
19
|
+
_p,
|
|
20
|
+
_q,
|
|
21
|
+
_r,
|
|
22
|
+
_s,
|
|
23
|
+
_t,
|
|
24
|
+
_u;
|
|
7
25
|
const repzo = new Repzo(
|
|
8
26
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
9
27
|
{ env: options.env }
|
|
@@ -270,6 +288,32 @@ export const create_return_invoice = async (event, options) => {
|
|
|
270
288
|
: item_return_reason.sap_id,
|
|
271
289
|
});
|
|
272
290
|
}
|
|
291
|
+
let WarehouseCode = repzo_warehouse.code;
|
|
292
|
+
if (
|
|
293
|
+
(_s =
|
|
294
|
+
(_r = options.data) === null || _r === void 0
|
|
295
|
+
? void 0
|
|
296
|
+
: _r.virtualWarehouses) === null || _s === void 0
|
|
297
|
+
? void 0
|
|
298
|
+
: _s.consider_virtual_warehouse
|
|
299
|
+
) {
|
|
300
|
+
if (
|
|
301
|
+
(_t = repzo_warehouse.integration_meta) === null || _t === void 0
|
|
302
|
+
? void 0
|
|
303
|
+
: _t.is_virtual_warehouse
|
|
304
|
+
) {
|
|
305
|
+
if (
|
|
306
|
+
(_u =
|
|
307
|
+
repzo_rep === null || repzo_rep === void 0
|
|
308
|
+
? void 0
|
|
309
|
+
: repzo_rep.integration_meta) === null || _u === void 0
|
|
310
|
+
? void 0
|
|
311
|
+
: _u.USERWHSCODE
|
|
312
|
+
) {
|
|
313
|
+
WarehouseCode = repzo_rep.integration_meta.USERWHSCODE;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
273
317
|
const sap_return_invoice = {
|
|
274
318
|
RepzoSerial: repzo_invoice.serial_number.formatted,
|
|
275
319
|
RefNum:
|
|
@@ -288,7 +332,7 @@ export const create_return_invoice = async (event, options) => {
|
|
|
288
332
|
ClientCode: repzo_client.client_code,
|
|
289
333
|
DiscountPerc: "0",
|
|
290
334
|
Note: repzo_invoice.comment,
|
|
291
|
-
WarehouseCode: repzo_warehouse.code,
|
|
335
|
+
WarehouseCode: WarehouseCode || repzo_warehouse.code,
|
|
292
336
|
LinesDetails: return_items,
|
|
293
337
|
U_ISTDQR: repzo_invoice.ubl_qr
|
|
294
338
|
? repzo_invoice.ubl_qr
|
package/lib/actions/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Repzo from "repzo";
|
|
|
2
2
|
import { v4 as uuid } from "uuid";
|
|
3
3
|
import { _create, set_error } from "../util.js";
|
|
4
4
|
export const adjust_inventory = async (commandEvent) => {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
6
6
|
const repzo = new Repzo(
|
|
7
7
|
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
8
8
|
? void 0
|
|
@@ -268,6 +268,223 @@ export const adjust_inventory = async (commandEvent) => {
|
|
|
268
268
|
result.failed++;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
const consider_virtual_warehouse =
|
|
272
|
+
((_m =
|
|
273
|
+
(_l = commandEvent.app.formData) === null || _l === void 0
|
|
274
|
+
? void 0
|
|
275
|
+
: _l.virtualWarehouses) === null || _m === void 0
|
|
276
|
+
? void 0
|
|
277
|
+
: _m.consider_virtual_warehouse) || false;
|
|
278
|
+
if (consider_virtual_warehouse) {
|
|
279
|
+
const absolute_qty_for_virtual_warehouses_before_accumulation =
|
|
280
|
+
((_p =
|
|
281
|
+
(_o = commandEvent.app.formData) === null || _o === void 0
|
|
282
|
+
? void 0
|
|
283
|
+
: _o.virtualWarehouses) === null || _p === void 0
|
|
284
|
+
? void 0
|
|
285
|
+
: _p.consider_virtual_warehouse) || true;
|
|
286
|
+
const repzo_virtual_warehouses =
|
|
287
|
+
repzo_warehouses === null || repzo_warehouses === void 0
|
|
288
|
+
? void 0
|
|
289
|
+
: repzo_warehouses.data.filter((wh) => {
|
|
290
|
+
var _a, _b, _c;
|
|
291
|
+
return (
|
|
292
|
+
((_a = wh.integration_meta) === null || _a === void 0
|
|
293
|
+
? void 0
|
|
294
|
+
: _a.is_virtual_warehouse) &&
|
|
295
|
+
((_c =
|
|
296
|
+
(_b = wh.integration_meta) === null || _b === void 0
|
|
297
|
+
? void 0
|
|
298
|
+
: _b.main_warehouses_codes) === null || _c === void 0
|
|
299
|
+
? void 0
|
|
300
|
+
: _c.length) > 0
|
|
301
|
+
);
|
|
302
|
+
});
|
|
303
|
+
await commandLog
|
|
304
|
+
.addDetail(
|
|
305
|
+
`${
|
|
306
|
+
repzo_virtual_warehouses === null ||
|
|
307
|
+
repzo_virtual_warehouses === void 0
|
|
308
|
+
? void 0
|
|
309
|
+
: repzo_virtual_warehouses.length
|
|
310
|
+
} Virtual Warehouse(s) in Repzo`
|
|
311
|
+
)
|
|
312
|
+
.commit();
|
|
313
|
+
for (let i = 0; i < repzo_virtual_warehouses.length; i++) {
|
|
314
|
+
try {
|
|
315
|
+
const repzo_warehouse = repzo_virtual_warehouses[i];
|
|
316
|
+
const sap_related_inventories = sap_inventories.filter(
|
|
317
|
+
(inventory) => {
|
|
318
|
+
var _a, _b;
|
|
319
|
+
return (_b =
|
|
320
|
+
(_a = repzo_warehouse.integration_meta) === null ||
|
|
321
|
+
_a === void 0
|
|
322
|
+
? void 0
|
|
323
|
+
: _a.main_warehouses_codes) === null || _b === void 0
|
|
324
|
+
? void 0
|
|
325
|
+
: _b.includes(inventory.STOREID);
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
// Get Repzo Inventory
|
|
329
|
+
const repzo_inventory = await repzo.inventory.find({
|
|
330
|
+
warehouse_id: repzo_warehouse._id,
|
|
331
|
+
per_page: 50000,
|
|
332
|
+
});
|
|
333
|
+
const shared_inventory = {};
|
|
334
|
+
sap_related_inventories.forEach((sap_inventory) => {
|
|
335
|
+
sap_inventory.items.forEach((item) => {
|
|
336
|
+
const key = `${item.ITEMID}__${item.UNITID}__${item.UNITNAME}`;
|
|
337
|
+
const QTY = item.QTY;
|
|
338
|
+
if (!shared_inventory[key]) {
|
|
339
|
+
shared_inventory[key] = item;
|
|
340
|
+
shared_inventory[key].QTY = 0;
|
|
341
|
+
}
|
|
342
|
+
if (absolute_qty_for_virtual_warehouses_before_accumulation) {
|
|
343
|
+
shared_inventory[key].QTY += QTY > 0 ? QTY : 0;
|
|
344
|
+
} else {
|
|
345
|
+
shared_inventory[key].QTY += QTY;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
let variants = Object.values(shared_inventory).map((sap_item) => {
|
|
350
|
+
var _a, _b, _c;
|
|
351
|
+
try {
|
|
352
|
+
const variant =
|
|
353
|
+
(_a =
|
|
354
|
+
repzo_variants === null || repzo_variants === void 0
|
|
355
|
+
? void 0
|
|
356
|
+
: repzo_variants.data) === null || _a === void 0
|
|
357
|
+
? void 0
|
|
358
|
+
: _a.find((variant) => {
|
|
359
|
+
var _a;
|
|
360
|
+
return (
|
|
361
|
+
((_a = variant.integration_meta) === null ||
|
|
362
|
+
_a === void 0
|
|
363
|
+
? void 0
|
|
364
|
+
: _a.ITEMCODE) == sap_item.ITEMID
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
if (!variant) {
|
|
368
|
+
// console.log(
|
|
369
|
+
// `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`
|
|
370
|
+
// );
|
|
371
|
+
throw `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`;
|
|
372
|
+
}
|
|
373
|
+
const measureUnit =
|
|
374
|
+
(_b =
|
|
375
|
+
repzo_measureunits === null || repzo_measureunits === void 0
|
|
376
|
+
? void 0
|
|
377
|
+
: repzo_measureunits.data) === null || _b === void 0
|
|
378
|
+
? void 0
|
|
379
|
+
: _b.find((measure_unit) => {
|
|
380
|
+
var _a, _b;
|
|
381
|
+
return (
|
|
382
|
+
measure_unit._id.toString() ==
|
|
383
|
+
((_b =
|
|
384
|
+
(_a = variant.product) === null || _a === void 0
|
|
385
|
+
? void 0
|
|
386
|
+
: _a.sv_measureUnit) === null || _b === void 0
|
|
387
|
+
? void 0
|
|
388
|
+
: _b.toString())
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
if (!measureUnit) {
|
|
392
|
+
// console.log(
|
|
393
|
+
// `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`
|
|
394
|
+
// );
|
|
395
|
+
throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
|
|
396
|
+
}
|
|
397
|
+
const qty = measureUnit.factor * sap_item.QTY;
|
|
398
|
+
const match_item_in_repzo_inventory =
|
|
399
|
+
(_c =
|
|
400
|
+
repzo_inventory === null || repzo_inventory === void 0
|
|
401
|
+
? void 0
|
|
402
|
+
: repzo_inventory.data) === null || _c === void 0
|
|
403
|
+
? void 0
|
|
404
|
+
: _c.find(
|
|
405
|
+
(repzo_item) =>
|
|
406
|
+
repzo_item.variant_id.toString() ==
|
|
407
|
+
variant._id.toString()
|
|
408
|
+
);
|
|
409
|
+
if (match_item_in_repzo_inventory) {
|
|
410
|
+
//@ts-ignore
|
|
411
|
+
match_item_in_repzo_inventory.has_match_in_SAP = true;
|
|
412
|
+
}
|
|
413
|
+
// const diff_qty = match_item_in_repzo_inventory
|
|
414
|
+
// ? qty - match_item_in_repzo_inventory.qty
|
|
415
|
+
// : qty;
|
|
416
|
+
return {
|
|
417
|
+
variant: variant._id,
|
|
418
|
+
qty: qty,
|
|
419
|
+
match_item_in_repzo_inventory,
|
|
420
|
+
};
|
|
421
|
+
} catch (e) {
|
|
422
|
+
// console.log(e);
|
|
423
|
+
failed_docs_report.push({
|
|
424
|
+
method: "fetchingData",
|
|
425
|
+
doc_id: sap_item.UNITNAME,
|
|
426
|
+
doc: {
|
|
427
|
+
...sap_item,
|
|
428
|
+
virtual_repzo_warehouse: repzo_warehouse.code,
|
|
429
|
+
},
|
|
430
|
+
error_message: set_error(e),
|
|
431
|
+
});
|
|
432
|
+
result.items_failed++;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
const unit_variants = {};
|
|
436
|
+
variants
|
|
437
|
+
.filter((i) => i)
|
|
438
|
+
.forEach((item) => {
|
|
439
|
+
if (!unit_variants[item.variant]) {
|
|
440
|
+
unit_variants[item.variant] = item;
|
|
441
|
+
} else {
|
|
442
|
+
unit_variants[item.variant].qty += item.qty;
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
variants = Object.values(unit_variants)
|
|
446
|
+
.map((item) => {
|
|
447
|
+
item.qty = item.match_item_in_repzo_inventory
|
|
448
|
+
? item.qty - item.match_item_in_repzo_inventory.qty
|
|
449
|
+
: item.qty;
|
|
450
|
+
return item;
|
|
451
|
+
})
|
|
452
|
+
.concat(
|
|
453
|
+
...((_q =
|
|
454
|
+
repzo_inventory === null || repzo_inventory === void 0
|
|
455
|
+
? void 0
|
|
456
|
+
: repzo_inventory.data) === null || _q === void 0
|
|
457
|
+
? void 0
|
|
458
|
+
: _q
|
|
459
|
+
.filter((item) => !item.has_match_in_SAP)
|
|
460
|
+
.map((item) => {
|
|
461
|
+
return { variant: item.variant_id, qty: -1 * item.qty };
|
|
462
|
+
}))
|
|
463
|
+
)
|
|
464
|
+
.filter((item) => item && item.qty);
|
|
465
|
+
const body = {
|
|
466
|
+
time: Date.now(),
|
|
467
|
+
sync_id: uuid(),
|
|
468
|
+
to: repzo_warehouse._id,
|
|
469
|
+
//@ts-ignore
|
|
470
|
+
variants: variants,
|
|
471
|
+
};
|
|
472
|
+
// console.log(body);
|
|
473
|
+
if (!body.variants.length) continue;
|
|
474
|
+
const res = await repzo.adjustInventory.create(body);
|
|
475
|
+
result.created++;
|
|
476
|
+
} catch (e) {
|
|
477
|
+
// console.log(e);
|
|
478
|
+
failed_docs_report.push({
|
|
479
|
+
method: "fetchingData",
|
|
480
|
+
doc_id: repzo_virtual_warehouses[i]._id,
|
|
481
|
+
doc: { virtual_repzo_warehouse: repzo_virtual_warehouses[i].code },
|
|
482
|
+
error_message: set_error(e),
|
|
483
|
+
});
|
|
484
|
+
result.failed++;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
271
488
|
// console.log(result);
|
|
272
489
|
await commandLog
|
|
273
490
|
.setStatus(
|
|
@@ -280,10 +497,10 @@ export const adjust_inventory = async (commandEvent) => {
|
|
|
280
497
|
} catch (e) {
|
|
281
498
|
//@ts-ignore
|
|
282
499
|
console.error(
|
|
283
|
-
((
|
|
284
|
-
|
|
500
|
+
((_r = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
501
|
+
_r === void 0
|
|
285
502
|
? void 0
|
|
286
|
-
:
|
|
503
|
+
: _r.data) || e
|
|
287
504
|
);
|
|
288
505
|
await commandLog.setStatus("fail", e).commit();
|
|
289
506
|
throw e;
|