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.
Files changed (39) hide show
  1. package/lib/actions/create_client.js +1 -0
  2. package/lib/actions/create_invoice.d.ts +1 -1
  3. package/lib/actions/create_invoice.js +55 -8
  4. package/lib/actions/create_payment.d.ts +1 -1
  5. package/lib/actions/create_proforma.d.ts +1 -1
  6. package/lib/actions/create_proforma.js +67 -40
  7. package/lib/actions/create_return_invoice.d.ts +1 -1
  8. package/lib/actions/create_return_invoice.js +46 -2
  9. package/lib/actions/create_transfer.d.ts +1 -1
  10. package/lib/actions/index.d.ts +1 -1
  11. package/lib/commands/adjust_inventory.js +221 -4
  12. package/lib/commands/rep.js +65 -29
  13. package/lib/commands/warehouse.js +149 -4
  14. package/lib/index.d.ts +1 -1
  15. package/lib/types.d.ts +4 -0
  16. package/lib/util.d.ts +4 -4
  17. package/package.json +1 -1
  18. package/src/actions/create_client.ts +3 -2
  19. package/src/actions/create_invoice.ts +13 -4
  20. package/src/actions/create_proforma.ts +12 -6
  21. package/src/actions/create_return_invoice.ts +10 -1
  22. package/src/commands/adjust_inventory.ts +169 -2
  23. package/src/commands/bank.ts +5 -1
  24. package/src/commands/brand.ts +2 -2
  25. package/src/commands/category.ts +2 -2
  26. package/src/commands/channel.ts +2 -2
  27. package/src/commands/client.ts +2 -2
  28. package/src/commands/client_disabled.ts +2 -2
  29. package/src/commands/measureunit.ts +2 -2
  30. package/src/commands/payment_term.ts +2 -2
  31. package/src/commands/price_list.ts +2 -2
  32. package/src/commands/price_list_disabled.ts +2 -2
  33. package/src/commands/product.ts +8 -4
  34. package/src/commands/product_disabled.ts +8 -4
  35. package/src/commands/rep.ts +26 -2
  36. package/src/commands/tag.ts +2 -2
  37. package/src/commands/tax.ts +2 -2
  38. package/src/commands/warehouse.ts +136 -3
  39. package/src/types.ts +4 -0
@@ -2,7 +2,7 @@ import Repzo from "repzo";
2
2
  import DataSet from "data-set-query";
3
3
  import { _create, update_bench_time, set_error } from "../util.js";
4
4
  export const sync_rep = async (commandEvent) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
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
@@ -20,6 +20,13 @@ export const sync_rep = async (commandEvent) => {
20
20
  console.log("sync_rep");
21
21
  const new_bench_time = new Date().toISOString();
22
22
  const bench_time_key = "bench_time_rep";
23
+ const consider_virtual_warehouse =
24
+ ((_c =
25
+ (_b = commandEvent.app.formData) === null || _b === void 0
26
+ ? void 0
27
+ : _b.virtualWarehouses) === null || _c === void 0
28
+ ? void 0
29
+ : _c.consider_virtual_warehouse) || false;
23
30
  await commandLog.load(commandEvent.sync_id);
24
31
  await commandLog.addDetail("Repzo SAP: Started Syncing Reps").commit();
25
32
  const nameSpace = commandEvent.nameSpace.join("_");
@@ -36,11 +43,11 @@ export const sync_rep = async (commandEvent) => {
36
43
  {}
37
44
  );
38
45
  result.sap_total =
39
- (_b =
46
+ (_d =
40
47
  sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
41
- null || _b === void 0
48
+ null || _d === void 0
42
49
  ? void 0
43
- : _b.length;
50
+ : _d.length;
44
51
  await commandLog.addDetail(`${result.sap_total} reps in SAP`).commit();
45
52
  // hard code ************************************
46
53
  // sap_reps?.Users?.forEach((sap_rep) => {
@@ -64,25 +71,27 @@ export const sync_rep = async (commandEvent) => {
64
71
  USERCHECKACCTCODE: true,
65
72
  USERWHSCODE: true,
66
73
  INVOICESTATUS: true,
74
+ VIRTUALWAREHOUSECODE: true,
75
+ VIRTUALWAREHOUSENAME: true,
67
76
  });
68
77
  db.load(sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users);
69
78
  const repzo_reps = await repzo.rep.find({ per_page: 50000 });
70
79
  result.repzo_total =
71
- (_c =
80
+ (_e =
72
81
  repzo_reps === null || repzo_reps === void 0
73
82
  ? void 0
74
- : repzo_reps.data) === null || _c === void 0
83
+ : repzo_reps.data) === null || _e === void 0
75
84
  ? void 0
76
- : _c.length;
85
+ : _e.length;
77
86
  await commandLog
78
87
  .addDetail(
79
88
  `${
80
- (_d =
89
+ (_f =
81
90
  repzo_reps === null || repzo_reps === void 0
82
91
  ? void 0
83
- : repzo_reps.data) === null || _d === void 0
92
+ : repzo_reps.data) === null || _f === void 0
84
93
  ? void 0
85
- : _d.length
94
+ : _f.length
86
95
  } reps in Repzo`
87
96
  )
88
97
  .commit();
@@ -94,11 +103,11 @@ export const sync_rep = async (commandEvent) => {
94
103
  for (
95
104
  let i = 0;
96
105
  i <
97
- ((_e =
106
+ ((_g =
98
107
  sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
99
- null || _e === void 0
108
+ null || _g === void 0
100
109
  ? void 0
101
- : _e.length);
110
+ : _g.length);
102
111
  i++
103
112
  ) {
104
113
  const sap_rep = sap_reps.Users[i];
@@ -119,23 +128,42 @@ export const sync_rep = async (commandEvent) => {
119
128
  // await repzo.warehouse.find({ code: sap_rep.USERWHSCODE });
120
129
  if (warehouse_res) warehouse = warehouse_res._id;
121
130
  }
131
+ let virtual_warehouse;
132
+ if (consider_virtual_warehouse && sap_rep.VIRTUALWAREHOUSECODE) {
133
+ const virtual_warehouse_res =
134
+ repzo_warehouses === null || repzo_warehouses === void 0
135
+ ? void 0
136
+ : repzo_warehouses.data.find((w) => {
137
+ var _a;
138
+ return (
139
+ ((_a = w.integration_meta) === null || _a === void 0
140
+ ? void 0
141
+ : _a.is_virtual_warehouse) &&
142
+ w.code == `Virtual ${sap_rep.VIRTUALWAREHOUSECODE}`
143
+ );
144
+ });
145
+ if (virtual_warehouse_res)
146
+ virtual_warehouse = virtual_warehouse_res._id;
147
+ }
122
148
  const body = {
123
149
  name: sap_rep.USERDESC,
124
150
  password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
125
151
  username: nameSpace + sap_rep.USERID,
126
152
  integration_id:
127
- (_f = sap_rep.USERID) === null || _f === void 0
153
+ (_h = sap_rep.USERID) === null || _h === void 0
128
154
  ? void 0
129
- : _f.toString(),
155
+ : _h.toString(),
130
156
  integration_meta: {
131
157
  DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
132
158
  USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
133
159
  USERCHECKACCTCODE: sap_rep.USERCHECKACCTCODE,
134
160
  USERWHSCODE: sap_rep.USERWHSCODE,
135
161
  INVOICESTATUS: sap_rep.INVOICESTATUS,
162
+ VIRTUALWAREHOUSECODE: sap_rep.VIRTUALWAREHOUSECODE,
163
+ VIRTUALWAREHOUSENAME: sap_rep.VIRTUALWAREHOUSENAME,
136
164
  id: `${nameSpace}_${sap_rep.USERID}`,
137
165
  },
138
- assigned_warehouse: warehouse,
166
+ assigned_warehouse: virtual_warehouse || warehouse,
139
167
  company_namespace: [nameSpace],
140
168
  "settings.treating_invoice_as_proforma_for_etax":
141
169
  sap_rep.INVOICESTATUS === "Y" ? true : false,
@@ -159,25 +187,33 @@ export const sync_rep = async (commandEvent) => {
159
187
  USERID: repzo_rep.integration_id,
160
188
  USERDESC: repzo_rep.name,
161
189
  DEPARTMENTCODE:
162
- (_g = repzo_rep.integration_meta) === null || _g === void 0
190
+ (_j = repzo_rep.integration_meta) === null || _j === void 0
163
191
  ? void 0
164
- : _g.DEPARTMENTCODE,
192
+ : _j.DEPARTMENTCODE,
165
193
  USERCASHACCOUNT:
166
- (_h = repzo_rep.integration_meta) === null || _h === void 0
194
+ (_k = repzo_rep.integration_meta) === null || _k === void 0
167
195
  ? void 0
168
- : _h.USERCASHACCOUNT,
196
+ : _k.USERCASHACCOUNT,
169
197
  USERCHECKACCTCODE:
170
- (_j = repzo_rep.integration_meta) === null || _j === void 0
198
+ (_l = repzo_rep.integration_meta) === null || _l === void 0
171
199
  ? void 0
172
- : _j.USERCHECKACCTCODE,
200
+ : _l.USERCHECKACCTCODE,
173
201
  USERWHSCODE:
174
- (_k = repzo_rep.integration_meta) === null || _k === void 0
202
+ (_m = repzo_rep.integration_meta) === null || _m === void 0
175
203
  ? void 0
176
- : _k.USERWHSCODE,
204
+ : _m.USERWHSCODE,
177
205
  INVOICESTATUS:
178
- (_l = repzo_rep.integration_meta) === null || _l === void 0
206
+ (_o = repzo_rep.integration_meta) === null || _o === void 0
207
+ ? void 0
208
+ : _o.INVOICESTATUS,
209
+ VIRTUALWAREHOUSECODE:
210
+ (_p = repzo_rep.integration_meta) === null || _p === void 0
211
+ ? void 0
212
+ : _p.VIRTUALWAREHOUSECODE,
213
+ VIRTUALWAREHOUSENAME:
214
+ (_q = repzo_rep.integration_meta) === null || _q === void 0
179
215
  ? void 0
180
- : _l.INVOICESTATUS,
216
+ : _q.VIRTUALWAREHOUSENAME,
181
217
  });
182
218
  if (found_identical_docs.length) continue;
183
219
  // Update
@@ -219,10 +255,10 @@ export const sync_rep = async (commandEvent) => {
219
255
  } catch (e) {
220
256
  //@ts-ignore
221
257
  console.error(
222
- ((_m = e === null || e === void 0 ? void 0 : e.response) === null ||
223
- _m === void 0
258
+ ((_r = e === null || e === void 0 ? void 0 : e.response) === null ||
259
+ _r === void 0
224
260
  ? void 0
225
- : _m.data) || e
261
+ : _r.data) || e
226
262
  );
227
263
  await commandLog.setStatus("fail", e).commit();
228
264
  throw e;
@@ -7,7 +7,7 @@ import {
7
7
  set_error,
8
8
  } from "../util.js";
9
9
  export const sync_warehouse = async (commandEvent) => {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
11
11
  const repzo = new Repzo(
12
12
  (_a = commandEvent.app.formData) === null || _a === void 0
13
13
  ? void 0
@@ -77,6 +77,8 @@ export const sync_warehouse = async (commandEvent) => {
77
77
  db.createIndex({
78
78
  WAREHOUSECODE: true,
79
79
  WAREHOUSENAME: true,
80
+ VIRTUALWAREHOUSECODE: true,
81
+ VIRTUALWAREHOUSENAME: true,
80
82
  });
81
83
  db.load(
82
84
  sap_warehouses === null || sap_warehouses === void 0
@@ -133,6 +135,11 @@ export const sync_warehouse = async (commandEvent) => {
133
135
  ? "van"
134
136
  : "main",
135
137
  disabled: sap_warehouse.INACTIVE == "N" ? false : true,
138
+ integration_meta: {
139
+ is_virtual_warehouse: false,
140
+ VIRTUALWAREHOUSECODE: sap_warehouse.VIRTUALWAREHOUSECODE,
141
+ VIRTUALWAREHOUSENAME: sap_warehouse.VIRTUALWAREHOUSENAME,
142
+ },
136
143
  };
137
144
  if (!repzo_warehouse) {
138
145
  // Create
@@ -152,6 +159,14 @@ export const sync_warehouse = async (commandEvent) => {
152
159
  const found_identical_docs = db.search({
153
160
  WAREHOUSECODE: repzo_warehouse.code,
154
161
  WAREHOUSENAME: repzo_warehouse.name,
162
+ VIRTUALWAREHOUSECODE:
163
+ (_j = repzo_warehouse.integration_meta) === null || _j === void 0
164
+ ? void 0
165
+ : _j.VIRTUALWAREHOUSECODE,
166
+ VIRTUALWAREHOUSENAME:
167
+ (_k = repzo_warehouse.integration_meta) === null || _k === void 0
168
+ ? void 0
169
+ : _k.VIRTUALWAREHOUSENAME,
155
170
  });
156
171
  if (found_identical_docs.length) continue; // Nothing has changed so no need for updates
157
172
  // Update
@@ -176,6 +191,136 @@ export const sync_warehouse = async (commandEvent) => {
176
191
  }
177
192
  }
178
193
  }
194
+ if (
195
+ (_m =
196
+ (_l = commandEvent.app.formData) === null || _l === void 0
197
+ ? void 0
198
+ : _l.virtualWarehouses) === null || _m === void 0
199
+ ? void 0
200
+ : _m.consider_virtual_warehouse
201
+ ) {
202
+ await commandLog
203
+ .addDetail("Repzo SAP: Started Syncing Virtual Warehouses")
204
+ .commit();
205
+ const unique_virtual_warehouses = {};
206
+ (_o =
207
+ sap_warehouses === null || sap_warehouses === void 0
208
+ ? void 0
209
+ : sap_warehouses.Warehouses) === null || _o === void 0
210
+ ? void 0
211
+ : _o.forEach((sap_warehouse) => {
212
+ if (
213
+ sap_warehouse.VIRTUALWAREHOUSECODE &&
214
+ sap_warehouse.VIRTUALWAREHOUSENAME
215
+ ) {
216
+ if (
217
+ !unique_virtual_warehouses[sap_warehouse.VIRTUALWAREHOUSECODE]
218
+ ) {
219
+ unique_virtual_warehouses[sap_warehouse.VIRTUALWAREHOUSECODE] =
220
+ {
221
+ code: sap_warehouse.VIRTUALWAREHOUSECODE,
222
+ name: sap_warehouse.VIRTUALWAREHOUSENAME,
223
+ main_warehouses_codes: [sap_warehouse.WAREHOUSECODE],
224
+ };
225
+ } else {
226
+ unique_virtual_warehouses[
227
+ sap_warehouse.VIRTUALWAREHOUSECODE
228
+ ].main_warehouses_codes.push(sap_warehouse.WAREHOUSECODE);
229
+ }
230
+ }
231
+ });
232
+ const sap_virtual_warehouses = Object.values(unique_virtual_warehouses);
233
+ await commandLog
234
+ .addDetail(
235
+ `${
236
+ sap_virtual_warehouses === null || sap_virtual_warehouses === void 0
237
+ ? void 0
238
+ : sap_virtual_warehouses.length
239
+ } virtual warehouses changed since ever`
240
+ )
241
+ .commit();
242
+ const db_2 = new DataSet([], { autoIndex: false });
243
+ db_2.createIndex({ name: true, code: true, main_warehouses_codes: true });
244
+ db_2.load(Object.values(sap_virtual_warehouses));
245
+ for (let i = 0; i < sap_virtual_warehouses.length; i++) {
246
+ const sap_warehouse = sap_virtual_warehouses[i];
247
+ const repzo_warehouse = repzo_warehouses.data.find((r_warehouse) => {
248
+ var _a, _b;
249
+ return (
250
+ ((_a = r_warehouse.integration_meta) === null || _a === void 0
251
+ ? void 0
252
+ : _a.is_virtual_warehouse) &&
253
+ (((_b = r_warehouse.integration_meta) === null || _b === void 0
254
+ ? void 0
255
+ : _b.code) == `Virtual ${sap_warehouse.code}` ||
256
+ r_warehouse.name == sap_warehouse.name)
257
+ );
258
+ });
259
+ const body = {
260
+ _id:
261
+ repzo_warehouse === null || repzo_warehouse === void 0
262
+ ? void 0
263
+ : repzo_warehouse._id,
264
+ name: sap_warehouse.name,
265
+ code: `Virtual ${sap_warehouse.code}`,
266
+ type: "main",
267
+ disabled: false,
268
+ integration_meta: {
269
+ is_virtual_warehouse: true,
270
+ main_warehouses_codes:
271
+ unique_virtual_warehouses[sap_warehouse.code]
272
+ .main_warehouses_codes,
273
+ VIRTUALWAREHOUSECODE: sap_warehouse.code,
274
+ VIRTUALWAREHOUSENAME: sap_warehouse.name,
275
+ },
276
+ };
277
+ if (!repzo_warehouse) {
278
+ // Create
279
+ try {
280
+ const created_warehouse = await repzo.warehouse.create(body);
281
+ result.created++;
282
+ } catch (e) {
283
+ // console.log("Create warehouse Failed >> ", e?.response, body);
284
+ failed_docs_report.push({
285
+ method: "create",
286
+ doc: body,
287
+ error_message: set_error(e),
288
+ });
289
+ result.failed++;
290
+ }
291
+ } else {
292
+ const found_identical_docs = db_2.search({
293
+ code: repzo_warehouse.code,
294
+ name: repzo_warehouse.name,
295
+ main_warehouses_codes:
296
+ ((_p = repzo_warehouse.integration_meta) === null || _p === void 0
297
+ ? void 0
298
+ : _p.main_warehouses_codes) || [],
299
+ });
300
+ if (found_identical_docs.length) continue; // Nothing has changed so no need for updates
301
+ // Update
302
+ try {
303
+ const updated_warehouse = await repzo.warehouse.update(
304
+ repzo_warehouse._id,
305
+ body
306
+ );
307
+ result.updated++;
308
+ } catch (e) {
309
+ // console.log("Update warehouse Failed >> ", e, body);
310
+ failed_docs_report.push({
311
+ method: "update",
312
+ doc_id:
313
+ repzo_warehouse === null || repzo_warehouse === void 0
314
+ ? void 0
315
+ : repzo_warehouse._id,
316
+ doc: body,
317
+ error_message: set_error(e),
318
+ });
319
+ result.failed++;
320
+ }
321
+ }
322
+ }
323
+ }
179
324
  // console.log(result);
180
325
  await update_bench_time(
181
326
  repzo,
@@ -195,10 +340,10 @@ export const sync_warehouse = async (commandEvent) => {
195
340
  } catch (e) {
196
341
  //@ts-ignore
197
342
  console.error(
198
- ((_j = e === null || e === void 0 ? void 0 : e.response) === null ||
199
- _j === void 0
343
+ ((_q = e === null || e === void 0 ? void 0 : e.response) === null ||
344
+ _q === void 0
200
345
  ? void 0
201
- : _j.data) || e
346
+ : _q.data) || e
202
347
  );
203
348
  await commandLog.setStatus("fail", e).commit();
204
349
  throw e === null || e === void 0 ? void 0 : e.response;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare const Actions: (
2
2
  event: any,
3
3
  options: import("./types.js").Config
4
- ) => Promise<any>;
4
+ ) => Promise<unknown>;
5
5
  export declare const ActionsList: import("./types.js").Action[];
6
6
  export declare const Commands: (
7
7
  CommandEvent: import("./types.js").CommandEvent
package/lib/types.d.ts CHANGED
@@ -99,6 +99,10 @@ export interface FormData {
99
99
  itemCode: string;
100
100
  uom: string;
101
101
  }[];
102
+ virtualWarehouses?: {
103
+ consider_virtual_warehouse: boolean;
104
+ absolute_qty_for_virtual_warehouses_before_accumulation: boolean;
105
+ };
102
106
  invoices?: {
103
107
  createInvoiceHook?: boolean;
104
108
  createReturnInvoiceHook?: boolean;
package/lib/util.d.ts CHANGED
@@ -16,27 +16,27 @@ export declare const _fetch: (
16
16
  path: string,
17
17
  headers?: Headers,
18
18
  params?: Params
19
- ) => Promise<any>;
19
+ ) => Promise<unknown>;
20
20
  export declare const _create: (
21
21
  baseUrl: string,
22
22
  path: string,
23
23
  body: Data,
24
24
  headers?: Headers,
25
25
  params?: Params
26
- ) => Promise<any>;
26
+ ) => Promise<unknown>;
27
27
  export declare const _update: (
28
28
  baseUrl: string,
29
29
  path: string,
30
30
  body: Data,
31
31
  headers?: Headers,
32
32
  params?: Params
33
- ) => Promise<any>;
33
+ ) => Promise<unknown>;
34
34
  export declare const _delete: (
35
35
  baseUrl: string,
36
36
  path: string,
37
37
  headers?: Headers,
38
38
  params?: Params
39
- ) => Promise<any>;
39
+ ) => Promise<unknown>;
40
40
  export declare const update_bench_time: (
41
41
  repzo: Repzo,
42
42
  app_id: string,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "repzo-sap-absjo",
3
3
  "description": "repzo SAP ABS jo integration",
4
- "version": "1.0.53",
4
+ "version": "1.0.55",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -6,7 +6,7 @@ import { v4 as uuid } from "uuid";
6
6
 
7
7
  interface SAPCustomer {
8
8
  AdditionalID: string; // "68eb85af0a28bf5038627c91";
9
- CardName?: string; // "ÄBD";
9
+ CardName: string; // "ÄBD";
10
10
  Phone1?: string; // "0788877776";
11
11
  cellular?: string; // "234567";
12
12
  CLIENTID?: string; // "CL01483";
@@ -95,6 +95,7 @@ export const create_client = async (event: EVENT, options: Config) => {
95
95
  );
96
96
 
97
97
  const sap_customer: SAPCustomer = {
98
+ CardName: repzo_client.name,
98
99
  AdditionalID: repzo_client._id,
99
100
  CLIENTID: repzo_client.client_code,
100
101
  CLIENTDESCF: repzo_client.local_name,
@@ -136,7 +137,7 @@ export const create_client = async (event: EVENT, options: Config) => {
136
137
  const result: {
137
138
  result: "Success";
138
139
  message: string | "The Customer already Exists in SAP";
139
- } = await _create(SAP_HOST_URL, "/AddCustomer", sap_customer);
140
+ } = (await _create(SAP_HOST_URL, "/AddCustomer", sap_customer)) as any;
140
141
 
141
142
  // console.log(result);
142
143
 
@@ -150,7 +150,7 @@ export const create_invoice = async (event: EVENT, options: Config) => {
150
150
  }
151
151
 
152
152
  // Get Repzo Rep
153
- let repzo_rep;
153
+ let repzo_rep: Service.Rep.Data | undefined;
154
154
  if (repzo_invoice.creator.type == "rep") {
155
155
  repzo_rep = await repzo.rep.get(repzo_invoice?.creator?._id);
156
156
  if (!repzo_rep)
@@ -295,6 +295,15 @@ export const create_invoice = async (event: EVENT, options: Config) => {
295
295
  });
296
296
  }
297
297
 
298
+ let WarehouseCode = repzo_warehouse.code;
299
+ if (options.data?.virtualWarehouses?.consider_virtual_warehouse) {
300
+ if (repzo_warehouse.integration_meta?.is_virtual_warehouse) {
301
+ if (repzo_rep?.integration_meta?.USERWHSCODE) {
302
+ WarehouseCode = repzo_rep.integration_meta.USERWHSCODE;
303
+ }
304
+ }
305
+ }
306
+
298
307
  const sap_invoice: SAPInvoice = {
299
308
  RepzoSerial: repzo_invoice.serial_number.formatted,
300
309
  RefNum:
@@ -314,7 +323,7 @@ export const create_invoice = async (event: EVENT, options: Config) => {
314
323
  ClientCode: repzo_client.client_code,
315
324
  DiscountPerc: "0",
316
325
  Note: repzo_invoice.comment,
317
- WarehouseCode: repzo_warehouse.code,
326
+ WarehouseCode: WarehouseCode || repzo_warehouse.code,
318
327
  LinesDetails: items,
319
328
  U_ISTDQR: repzo_invoice.ubl_qr
320
329
  ? repzo_invoice.ubl_qr
@@ -402,7 +411,7 @@ export const get_invoice_from_sap = async (
402
411
  query?: { updatedAt: string; Status: string; InvoiceId: string }
403
412
  ): Promise<SAPOpenInvoice[]> => {
404
413
  try {
405
- const sap_openInvoices: SAPOpenInvoices = await _create(
414
+ const sap_openInvoices: SAPOpenInvoices = (await _create(
406
415
  serviceEndPoint,
407
416
  "/OpenInvoices",
408
417
  {
@@ -410,7 +419,7 @@ export const get_invoice_from_sap = async (
410
419
  Status: query?.Status,
411
420
  InvoiceId: query?.InvoiceId,
412
421
  }
413
- );
422
+ )) as SAPOpenInvoices;
414
423
  return sap_openInvoices?.OpenInvoices;
415
424
  } catch (e: any) {
416
425
  throw e;
@@ -95,12 +95,18 @@ export const create_proforma = async (event: EVENT, options: Config) => {
95
95
  | Service.Warehouse.WarehouseSchema["code"]
96
96
  | undefined;
97
97
  if (repzo_rep && repzo_rep?.assigned_warehouse) {
98
- rep_warehouse_code = (
99
- repzo_rep?.assigned_warehouse as Pick<
100
- Service.Warehouse.WarehouseSchema,
101
- "_id" | "code"
102
- >
103
- )?.code;
98
+ const warehouse = repzo_rep?.assigned_warehouse as Pick<
99
+ Service.Warehouse.WarehouseSchema,
100
+ "_id" | "code" | "name" | "integration_meta"
101
+ >;
102
+ rep_warehouse_code = warehouse?.code;
103
+ if (options.data?.virtualWarehouses?.consider_virtual_warehouse) {
104
+ if (warehouse.integration_meta?.is_virtual_warehouse) {
105
+ if (repzo_rep?.integration_meta?.USERWHSCODE) {
106
+ rep_warehouse_code = repzo_rep.integration_meta.USERWHSCODE;
107
+ }
108
+ }
109
+ }
104
110
  }
105
111
 
106
112
  // Get Repzo Client
@@ -208,6 +208,15 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
208
208
  });
209
209
  }
210
210
 
211
+ let WarehouseCode = repzo_warehouse.code;
212
+ if (options.data?.virtualWarehouses?.consider_virtual_warehouse) {
213
+ if (repzo_warehouse.integration_meta?.is_virtual_warehouse) {
214
+ if (repzo_rep?.integration_meta?.USERWHSCODE) {
215
+ WarehouseCode = repzo_rep.integration_meta.USERWHSCODE;
216
+ }
217
+ }
218
+ }
219
+
211
220
  const sap_return_invoice: SAPInvoice = {
212
221
  RepzoSerial: repzo_invoice.serial_number.formatted,
213
222
  RefNum:
@@ -223,7 +232,7 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
223
232
  ClientCode: repzo_client.client_code,
224
233
  DiscountPerc: "0",
225
234
  Note: repzo_invoice.comment,
226
- WarehouseCode: repzo_warehouse.code,
235
+ WarehouseCode: WarehouseCode || repzo_warehouse.code,
227
236
  LinesDetails: return_items,
228
237
  U_ISTDQR: repzo_invoice.ubl_qr
229
238
  ? repzo_invoice.ubl_qr