repzo-sap-absjo 1.0.38 → 1.0.39

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.
@@ -3,7 +3,7 @@ import _ from "lodash";
3
3
  import { update_bench_time, set_error } from "../util.js";
4
4
  import { get_sap_UoMs } from "./measureunit.js";
5
5
  export const sync_measureunit_family = async (commandEvent) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
7
7
  const repzo = new Repzo(
8
8
  (_a = commandEvent.app.formData) === null || _a === void 0
9
9
  ? void 0
@@ -19,6 +19,34 @@ export const sync_measureunit_family = async (commandEvent) => {
19
19
  );
20
20
  try {
21
21
  // console.log("sync_measureunit_family");
22
+ if (
23
+ (_b = commandEvent.app.formData) === null || _b === void 0
24
+ ? void 0
25
+ : _b.measureUnitInjections
26
+ ) {
27
+ try {
28
+ if (
29
+ typeof ((_c = commandEvent.app.formData) === null || _c === void 0
30
+ ? void 0
31
+ : _c.measureUnitInjections) == "string"
32
+ )
33
+ commandEvent.app.formData.measureUnitInjections = JSON.parse(
34
+ commandEvent.app.formData.measureUnitInjections
35
+ );
36
+ if (
37
+ !Array.isArray(
38
+ (_d = commandEvent.app.formData) === null || _d === void 0
39
+ ? void 0
40
+ : _d.measureUnitInjections
41
+ )
42
+ ) {
43
+ delete commandEvent.app.formData.measureUnitInjections;
44
+ }
45
+ } catch (e) {
46
+ console.error(e);
47
+ delete commandEvent.app.formData.measureUnitInjections;
48
+ }
49
+ }
22
50
  const new_bench_time = new Date().toISOString();
23
51
  const bench_time_key = "bench_time_measureunit_family";
24
52
  await commandLog.load(commandEvent.sync_id);
@@ -50,58 +78,58 @@ export const sync_measureunit_family = async (commandEvent) => {
50
78
  per_page: 50000,
51
79
  });
52
80
  result.repzo_UoM_total =
53
- (_b =
81
+ (_e =
54
82
  repzo_UoMs === null || repzo_UoMs === void 0
55
83
  ? void 0
56
- : repzo_UoMs.data) === null || _b === void 0
84
+ : repzo_UoMs.data) === null || _e === void 0
57
85
  ? void 0
58
- : _b.length;
86
+ : _e.length;
59
87
  await commandLog
60
88
  .addDetail(
61
89
  `${
62
- (_c =
90
+ (_f =
63
91
  repzo_UoMs === null || repzo_UoMs === void 0
64
92
  ? void 0
65
- : repzo_UoMs.data) === null || _c === void 0
93
+ : repzo_UoMs.data) === null || _f === void 0
66
94
  ? void 0
67
- : _c.length
95
+ : _f.length
68
96
  } Measure Units in Repzo`
69
97
  )
70
98
  .commit();
71
99
  if (
72
- !((_d =
100
+ !((_g =
73
101
  repzo_UoMs === null || repzo_UoMs === void 0
74
102
  ? void 0
75
- : repzo_UoMs.data) === null || _d === void 0
103
+ : repzo_UoMs.data) === null || _g === void 0
76
104
  ? void 0
77
- : _d.length)
105
+ : _g.length)
78
106
  ) {
79
107
  throw "measure units are not found or the nameSpace has more than one";
80
108
  }
81
109
  repzo_UoMs.data =
82
- (_e = repzo_UoMs.data) === null || _e === void 0
110
+ (_h = repzo_UoMs.data) === null || _h === void 0
83
111
  ? void 0
84
- : _e.filter((UoM) => UoM.integration_meta);
112
+ : _h.filter((UoM) => UoM.integration_meta);
85
113
  const repzo_UoMs_family = await repzo.measureunitFamily.find({
86
114
  disabled: false,
87
115
  per_page: 50000,
88
116
  });
89
117
  result.repzo_total =
90
- (_f =
118
+ (_j =
91
119
  repzo_UoMs_family === null || repzo_UoMs_family === void 0
92
120
  ? void 0
93
- : repzo_UoMs_family.data) === null || _f === void 0
121
+ : repzo_UoMs_family.data) === null || _j === void 0
94
122
  ? void 0
95
- : _f.length;
123
+ : _j.length;
96
124
  await commandLog
97
125
  .addDetail(
98
126
  `${
99
- (_g =
127
+ (_k =
100
128
  repzo_UoMs_family === null || repzo_UoMs_family === void 0
101
129
  ? void 0
102
- : repzo_UoMs_family.data) === null || _g === void 0
130
+ : repzo_UoMs_family.data) === null || _k === void 0
103
131
  ? void 0
104
- : _g.length
132
+ : _k.length
105
133
  } Measure Units Family in Repzo`
106
134
  )
107
135
  .commit();
@@ -118,9 +146,9 @@ export const sync_measureunit_family = async (commandEvent) => {
118
146
  sap_unique_family[key][uom_key] = 1;
119
147
  }
120
148
  result.sap_total =
121
- (_h = Object.keys(sap_unique_family)) === null || _h === void 0
149
+ (_l = Object.keys(sap_unique_family)) === null || _l === void 0
122
150
  ? void 0
123
- : _h.length;
151
+ : _l.length;
124
152
  await commandLog
125
153
  .addDetail(`${result.sap_total} Measure Units Family in SAP`)
126
154
  .commit();
@@ -134,7 +162,7 @@ export const sync_measureunit_family = async (commandEvent) => {
134
162
  : _a.id) == `${nameSpace}_${key}`
135
163
  );
136
164
  });
137
- let measureunits = [];
165
+ const measureunits = [];
138
166
  Object.keys(sap_family).forEach((unit) => {
139
167
  var _a;
140
168
  {
@@ -160,6 +188,51 @@ export const sync_measureunit_family = async (commandEvent) => {
160
188
  }
161
189
  }
162
190
  });
191
+ if (
192
+ (_o =
193
+ (_m = commandEvent.app.formData) === null || _m === void 0
194
+ ? void 0
195
+ : _m.measureUnitInjections) === null || _o === void 0
196
+ ? void 0
197
+ : _o.length
198
+ ) {
199
+ const related_uom_s =
200
+ commandEvent.app.formData.measureUnitInjections.filter(
201
+ (doc) =>
202
+ (doc === null || doc === void 0 ? void 0 : doc.itemCode) == key
203
+ );
204
+ related_uom_s.forEach((related_uom) => {
205
+ var _a;
206
+ const UoM =
207
+ (_a =
208
+ repzo_UoMs === null || repzo_UoMs === void 0
209
+ ? void 0
210
+ : repzo_UoMs.data) === null || _a === void 0
211
+ ? void 0
212
+ : _a.find((repzo_uom) => {
213
+ var _a;
214
+ return (
215
+ (repzo_uom === null || repzo_uom === void 0
216
+ ? void 0
217
+ : repzo_uom.name) ==
218
+ (related_uom === null || related_uom === void 0
219
+ ? void 0
220
+ : related_uom.uom) &&
221
+ ((_a =
222
+ repzo_uom === null || repzo_uom === void 0
223
+ ? void 0
224
+ : repzo_uom.integration_meta) === null || _a === void 0
225
+ ? void 0
226
+ : _a.ITEMCODE) == key
227
+ );
228
+ });
229
+ if (UoM) {
230
+ if (!measureunits.includes(UoM._id.toString())) {
231
+ measureunits.push(UoM._id.toString());
232
+ }
233
+ }
234
+ });
235
+ }
163
236
  const body = {
164
237
  name: key,
165
238
  disabled: false,
@@ -188,20 +261,20 @@ export const sync_measureunit_family = async (commandEvent) => {
188
261
  } else {
189
262
  if (
190
263
  repzo_family.name == body.name &&
191
- !((_k = _.xor(
192
- ((_j =
264
+ !((_q = _.xor(
265
+ ((_p =
193
266
  repzo_family === null || repzo_family === void 0
194
267
  ? void 0
195
- : repzo_family.measureunits) === null || _j === void 0
268
+ : repzo_family.measureunits) === null || _p === void 0
196
269
  ? void 0
197
- : _j.map((m) =>
270
+ : _p.map((m) =>
198
271
  m === null || m === void 0 ? void 0 : m.toString()
199
272
  )) || [],
200
273
  (body === null || body === void 0 ? void 0 : body.measureunits) ||
201
274
  []
202
- )) === null || _k === void 0
275
+ )) === null || _q === void 0
203
276
  ? void 0
204
- : _k.length)
277
+ : _q.length)
205
278
  ) {
206
279
  continue;
207
280
  }
@@ -249,10 +322,10 @@ export const sync_measureunit_family = async (commandEvent) => {
249
322
  } catch (e) {
250
323
  //@ts-ignore
251
324
  console.error(
252
- ((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
253
- _l === void 0
325
+ ((_r = e === null || e === void 0 ? void 0 : e.response) === null ||
326
+ _r === void 0
254
327
  ? void 0
255
- : _l.data) || e
328
+ : _r.data) || e
256
329
  );
257
330
  await commandLog.setStatus("fail", e).commit();
258
331
  throw e;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,393 @@
1
+ import { Commands } from "../../index.js";
2
+ let commandEvent = {
3
+ app: {
4
+ _id: "639f0bf52070c5be595e955c",
5
+ name: "SAP",
6
+ disabled: false,
7
+ available_app: {
8
+ _id: "6391a268db71ef64357195da",
9
+ name: "repzo-sap-absjo",
10
+ title: "SAP ABS JO",
11
+ logo: "https://prod-repzo-media-service.s3.us-east-1.amazonaws.com/repzo/image/2022/12/18/3f73de7d-1920-4786-90db-57c76d18acci-SAP_EBS_JO.png",
12
+ description:
13
+ "SAP Jordan. We provide real value to SMEs by understanding their business and driving their vision forward with SAP Business One",
14
+ disabled: false,
15
+ JSONSchema: {
16
+ title: "SAP Integration Settings",
17
+ type: "object",
18
+ required: ["repzoApiKey", "sapHostUrl"],
19
+ properties: {
20
+ repzoApiKey: { type: "string", title: "Repzo API KEY" },
21
+ sapHostUrl: { type: "string", title: "SAP Host Url" },
22
+ errorEmail: {
23
+ type: "string",
24
+ format: "email",
25
+ title: "Email in case of error",
26
+ },
27
+ GroupCode: {
28
+ type: "string",
29
+ format: "string",
30
+ title: "Customers GroupCode",
31
+ },
32
+ warehouseDefaultUpdateDate: {
33
+ type: "string",
34
+ format: "date",
35
+ title: "Warehouse: Default Update Date",
36
+ },
37
+ DepartmentCode: {
38
+ type: "string",
39
+ format: "string",
40
+ title: "Invoice/Return Department Code",
41
+ },
42
+ return_reason: {
43
+ type: "string",
44
+ format: "string",
45
+ title: "Return Reason Array",
46
+ },
47
+ measureUnitInjections: {
48
+ type: "string",
49
+ format: "string",
50
+ title: "Uom Injection Array",
51
+ },
52
+ defaultWarehouseForSalesOrder: {
53
+ type: "string",
54
+ format: "string",
55
+ title: "Default Warehouse Code For Sales Orders",
56
+ },
57
+ SalPersCode: {
58
+ type: "string",
59
+ format: "string",
60
+ title: "Default Sales Person Code For Sales Orders",
61
+ },
62
+ SalesPersonCode: {
63
+ type: "string",
64
+ format: "string",
65
+ title: "Default Sales Person Code For Transfer",
66
+ },
67
+ invoices: {
68
+ type: "object",
69
+ title: "Invoices",
70
+ required: ["createInvoiceHook", "createReturnInvoiceHook"],
71
+ properties: {
72
+ createInvoiceHook: {
73
+ type: "boolean",
74
+ title: "Live Sync Invoices from Repzo to SAP",
75
+ default: false,
76
+ },
77
+ createReturnInvoiceHook: {
78
+ type: "boolean",
79
+ title: "Live Sync Return Invoice from Repzo to SAP",
80
+ default: false,
81
+ },
82
+ },
83
+ },
84
+ payments: {
85
+ type: "object",
86
+ title: "Payments",
87
+ required: ["createPaymentHook"],
88
+ properties: {
89
+ createPaymentHook: {
90
+ type: "boolean",
91
+ title: "Live Sync Payments from Repzo to SAP",
92
+ default: false,
93
+ },
94
+ },
95
+ },
96
+ proformas: {
97
+ type: "object",
98
+ title: "Sales Orders",
99
+ required: ["createApprovedProformaHook"],
100
+ properties: {
101
+ createApprovedProformaHook: {
102
+ type: "boolean",
103
+ title: "Live Sync Approved Sales Orders from Repzo to SAP",
104
+ default: false,
105
+ },
106
+ },
107
+ },
108
+ transfers: {
109
+ type: "object",
110
+ title: "Transfers",
111
+ required: ["createApprovedTransferHook"],
112
+ properties: {
113
+ createApprovedTransferHook: {
114
+ type: "boolean",
115
+ title: "Live Sync Approved Transfers from Repzo to SAP",
116
+ default: false,
117
+ },
118
+ adjustInventoryInFailedTransfer: {
119
+ type: "boolean",
120
+ title:
121
+ "Adjust Inventories in Repzo if creation Transfer Failed in SAP",
122
+ default: false,
123
+ },
124
+ },
125
+ },
126
+ },
127
+ },
128
+ options_JSONSchema: {
129
+ title: "SAP Integration Optional Settings",
130
+ type: "object",
131
+ required: [],
132
+ properties: {
133
+ bench_time_warehouse: {
134
+ title: "Bench Time: Warehouse",
135
+ type: "string",
136
+ format: "date",
137
+ },
138
+ bench_time_channel: {
139
+ title: "Bench Time: Channels",
140
+ type: "string",
141
+ format: "date-time",
142
+ },
143
+ bench_time_payment_term: {
144
+ title: "Bench Time: Payment Terms",
145
+ type: "string",
146
+ format: "date-time",
147
+ },
148
+ bench_time_product: {
149
+ title: "Bench Time: Products",
150
+ type: "string",
151
+ format: "date-time",
152
+ },
153
+ bench_time_product_disabled: {
154
+ title: "Bench Time: Inactive Products",
155
+ type: "string",
156
+ format: "date-time",
157
+ },
158
+ bench_time_price_list: {
159
+ title: "Bench Time: Price List",
160
+ type: "string",
161
+ format: "date-time",
162
+ },
163
+ bench_time_client: {
164
+ title: "Bench Time: Clients",
165
+ type: "string",
166
+ format: "date-time",
167
+ },
168
+ bench_time_disabled_client: {
169
+ title: "Bench Time: Inactive Clients",
170
+ type: "string",
171
+ format: "date-time",
172
+ },
173
+ },
174
+ },
175
+ app_settings: {
176
+ repo: "",
177
+ serviceEndPoint: "",
178
+ _id: "6391a268db71ef64357195db",
179
+ },
180
+ app_category: "6249fa8466312f76e595634a",
181
+ commands: [
182
+ {
183
+ command: "basic",
184
+ name: "Full Sync",
185
+ description: "Exclude Join & Adjust Inventories",
186
+ group_sync: false,
187
+ _id: "6391a268db71ef64357195dc",
188
+ },
189
+ {
190
+ command: "join",
191
+ name: "Join",
192
+ description: "",
193
+ group_sync: false,
194
+ _id: "6391a268db71ef64357195dd",
195
+ },
196
+ {
197
+ command: "warehouse",
198
+ name: "Sync Warehouse",
199
+ description: "Sync Warehouses From SAP to Repzo",
200
+ group_sync: false,
201
+ _id: "6391c42a1b0f4f7a30e40f40",
202
+ },
203
+ {
204
+ command: "rep",
205
+ name: "Sync Representatives",
206
+ description: "Sync Representatives From SAP to Repzo",
207
+ group_sync: false,
208
+ _id: "639715c2bee5dd4b6b11e129",
209
+ },
210
+ {
211
+ command: "tax",
212
+ name: "Sync Taxes",
213
+ description: "Sync Taxes From SAP to Repzo",
214
+ group_sync: false,
215
+ _id: "639715c2bee5dd4b6b11e12a",
216
+ },
217
+ {
218
+ command: "tag",
219
+ name: "Sync Area Tags",
220
+ description: "Sync Area Tags From SAP to Repzo",
221
+ group_sync: false,
222
+ _id: "639715c2bee5dd4b6b11e12b",
223
+ },
224
+ {
225
+ command: "measureunit",
226
+ name: "Sync Measure Units",
227
+ description: "Sync Measure Units From SAP to Repzo",
228
+ group_sync: false,
229
+ _id: "639817eaedafde008af0ad0e",
230
+ },
231
+ {
232
+ command: "measureunit_family",
233
+ name: "Sync Measure Units Family",
234
+ description: "Sync Measure Units Family From SAP to Repzo",
235
+ group_sync: false,
236
+ _id: "63982d09edafde008af0f698",
237
+ },
238
+ {
239
+ command: "category",
240
+ name: "Sync Product Category",
241
+ description: "Sync Product Categories From SAP to Repzo",
242
+ group_sync: false,
243
+ _id: "63984085edafde008af2f689",
244
+ },
245
+ {
246
+ command: "brand",
247
+ name: "Sync Product Brand",
248
+ description: "Sync Product Brands From SAP to Repzo",
249
+ group_sync: false,
250
+ _id: "63984085edafde008af2f689",
251
+ },
252
+ {
253
+ command: "channel",
254
+ name: "Sync Client's Channels",
255
+ description: "Sync Client's Channels From SAP to Repzo",
256
+ group_sync: false,
257
+ _id: "63984085edafde008af2f689",
258
+ },
259
+ {
260
+ command: "payment_term",
261
+ name: "Sync Payments Term",
262
+ description: "Sync Payments Term From SAP to Repzo",
263
+ group_sync: false,
264
+ _id: "63984085edafde008af2f68a",
265
+ },
266
+ {
267
+ command: "bank",
268
+ name: "Sync Banks",
269
+ description: "Sync Banks From SAP to Repzo",
270
+ group_sync: false,
271
+ _id: "63986018333b84929c538570",
272
+ },
273
+ {
274
+ command: "product",
275
+ name: "Sync Products",
276
+ description: "Sync Active Products From SAP to Repzo",
277
+ group_sync: false,
278
+ _id: "63987139333b84929c53a293",
279
+ },
280
+ {
281
+ command: "disabled_product",
282
+ name: "Sync Inactive Products",
283
+ description: "Sync Inactive Products From SAP to Repzo",
284
+ group_sync: false,
285
+ _id: "6399714d0242db686d496466",
286
+ },
287
+ {
288
+ command: "price_list",
289
+ name: "Sync Price Lists",
290
+ description: "Sync Price Lists From SAP to Repzo",
291
+ group_sync: false,
292
+ _id: "639972d6e8a1cfdd26deaa7e",
293
+ },
294
+ {
295
+ command: "price_list_disabled",
296
+ name: "Sync Disbaled Price List Items",
297
+ description: "Sync Disbaled Price List Items From SAP to Repzo",
298
+ group_sync: false,
299
+ _id: "656ed4098961a3f97182773f",
300
+ },
301
+ {
302
+ command: "client",
303
+ name: "Sync Clients",
304
+ description: "Sync Clients From SAP to Repzo",
305
+ group_sync: false,
306
+ _id: "63997615e8a1cfdd26ded7d1",
307
+ },
308
+ {
309
+ command: "disabled_client",
310
+ name: "Sync Inactive Clients",
311
+ description: "Sync Inactive Clients From SAP to Repzo",
312
+ group_sync: false,
313
+ _id: "639ac554e157f1c63770c1bc",
314
+ },
315
+ {
316
+ command: "adjust_inventory",
317
+ name: "Adjust Inventories",
318
+ description: "Adjust Inventories From SAP to Repzo",
319
+ group_sync: false,
320
+ _id: "639ac56fe157f1c63770c2eb",
321
+ },
322
+ ],
323
+ actions: [
324
+ {
325
+ action: "create_invoice",
326
+ name: "Sync Invoices",
327
+ description: "Sync Invoices From Repzo to SAP",
328
+ _id: "639ebeacdbba64d7af94520c",
329
+ },
330
+ {
331
+ action: "create_return_invoice",
332
+ name: "Sync Return Invoices",
333
+ description: "Sync Return Invoices From Repzo to SAP",
334
+ _id: "639ebeacdbba64d7af94520d",
335
+ },
336
+ {
337
+ action: "create_proforma",
338
+ name: "Sync Approved Sales Orders",
339
+ description: "Sync Approved Sales Orders From Repzo to SAP",
340
+ _id: "639ebeacdbba64d7af94520e",
341
+ },
342
+ {
343
+ action: "create_payment",
344
+ name: "Sync Paymants",
345
+ description: "Sync Paymants From Repzo to SAP",
346
+ _id: "639ebeacdbba64d7af94520f",
347
+ },
348
+ {
349
+ action: "create_transfer",
350
+ name: "Sync Approved Transfers",
351
+ description: "Sync Approved Transfers From Repzo to SAP",
352
+ _id: "639ebeacdbba64d7af945210",
353
+ },
354
+ ],
355
+ createdAt: "2022-12-08T08:38:00.915Z",
356
+ updatedAt: "2025-09-01T08:32:54.793Z",
357
+ __v: 0,
358
+ subscription_billing_mode: "free",
359
+ },
360
+ company_namespace: ["unipaljo"],
361
+ formData: {
362
+ repzoApiKey: "seCTdOxk1zYljAZZRJaqWga2Hc6zjzWscf6FfaP9eE8",
363
+ sapHostUrl: "http://unipal.b1pro.com:8083/api",
364
+ invoices: { createInvoiceHook: false, createReturnInvoiceHook: false },
365
+ payments: { createPaymentHook: false },
366
+ proformas: { createApprovedProformaHook: false },
367
+ transfers: {
368
+ createApprovedTransferHook: false,
369
+ adjustInventoryInFailedTransfer: false,
370
+ },
371
+ warehouseDefaultUpdateDate: "2015-01-01",
372
+ DepartmentCode: "D2",
373
+ return_reason:
374
+ '[{sap_id:1,sap_name:"BarcodeIssue",repzo_name:"Barcodeissue",repzo_id:"62b074972b332895edf114fc"},{sap_id:2,sap_name:"Damaged",repzo_name:"Damaged",repzo_id:"62b074ace96258fb745982e4"},{sap_id:3,sap_name:"Nearexpiry",repzo_name:"Nearexpiry",repzo_id:"62b074c0a066173bd1c1ea0d"},{sap_id:4,sap_name:"Wrongprinting",repzo_name:"Wrongprinting",repzo_id:"62b074d79e7f41f306a4cb42"},{sap_id:5,sap_name:"experied",repzo_name:"Experied",repzo_id:"62b074faa066173bd1c1eec0"}]',
375
+ SalPersCode: "111",
376
+ SalesPersonCode: "111",
377
+ measureUnitInjections: '[{ "itemCode": "010-KEA-JU0003", "uom": "PC" }]',
378
+ },
379
+ options_formData: {},
380
+ createdAt: "2022-12-18T12:47:49.096Z",
381
+ updatedAt: "2023-12-05T09:35:00.366Z",
382
+ __v: 0,
383
+ subscription_billing_mode: "free",
384
+ },
385
+ end_of_day: "04:00",
386
+ nameSpace: ["unipaljo"],
387
+ timezone: "Asia/Amman",
388
+ meta: "",
389
+ env: "staging",
390
+ sync_id: "774ed706-1868-49bc-9982-d320796babff",
391
+ command: "measureunit_family",
392
+ };
393
+ Commands(commandEvent);
package/lib/types.d.ts CHANGED
@@ -78,8 +78,68 @@ export interface AvailableApp {
78
78
  };
79
79
  app_category: string;
80
80
  }
81
+ export interface FormData {
82
+ repzoApiKey: string;
83
+ sapHostUrl: string;
84
+ warehouseDefaultUpdateDate?: string;
85
+ DepartmentCode?: string;
86
+ GroupCode?: string;
87
+ return_reasons?:
88
+ | {
89
+ sap_id: number;
90
+ sap_name: string;
91
+ repzo_name: string;
92
+ repzo_id: StringId;
93
+ }[]
94
+ | string;
95
+ defaultWarehouseForSalesOrder?: string;
96
+ SalPersCode?: string;
97
+ SalesPersonCode?: string;
98
+ measureUnitInjections?: {
99
+ itemCode: string;
100
+ uom: string;
101
+ }[];
102
+ invoices?: {
103
+ createInvoiceHook?: boolean;
104
+ createReturnInvoiceHook?: boolean;
105
+ };
106
+ payments?: {
107
+ createPaymentHook?: boolean;
108
+ };
109
+ proformas?: {
110
+ createApprovedProformaHook?: boolean;
111
+ };
112
+ transfers?: {
113
+ createApprovedTransferHook?: boolean;
114
+ adjustInventoryInFailedTransfer?: boolean;
115
+ };
116
+ }
117
+ interface OptionsFormData {
118
+ bench_time_warehouse?: string;
119
+ bench_time_channel?: string;
120
+ bench_time_payment_term?: string;
121
+ bench_time_product?: string;
122
+ bench_time_product_disabled?: string;
123
+ bench_time_price_list?: string;
124
+ bench_time_client?: string;
125
+ bench_time_disabled_client?: string;
126
+ bench_time_rep?: string;
127
+ bench_time_tax?: string;
128
+ bench_time_tag?: string;
129
+ bench_time_measureunit?: string;
130
+ bench_time_measureunit_family?: string;
131
+ bench_time_category?: string;
132
+ bench_time_bank?: string;
133
+ bench_time_brand?: string;
134
+ bench_time_price_list_disabled?: string;
135
+ }
136
+ interface AppWithCustomFormData
137
+ extends Service.App.Schema_with_populated_AvailableApp {
138
+ formData: FormData;
139
+ options_formData: OptionsFormData;
140
+ }
81
141
  export interface CommandEvent {
82
- app: Service.App.Schema_with_populated_AvailableApp;
142
+ app: AppWithCustomFormData;
83
143
  command: CommandType | string;
84
144
  nameSpace: NameSpaces;
85
145
  meta?: any;
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.38",
4
+ "version": "1.0.39",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -21,7 +21,7 @@
21
21
  "lint": "npx --yes prettier --write .",
22
22
  "build": "tsc && npm run lint",
23
23
  "test": "mocha",
24
- "mac": "npm run build && node ./lib/test/commands/***.js",
24
+ "mac": "npm run build && node ./lib/test/commands/test.js",
25
25
  "prepublishOnly": "npm run build"
26
26
  },
27
27
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "jsonwebtoken": "^8.5.1",
46
46
  "lodash": "^4.17.21",
47
47
  "moment-timezone": "^0.5.34",
48
- "repzo": "^1.0.152",
48
+ "repzo": "^1.0.182",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -28,6 +28,21 @@ export const sync_measureunit_family = async (commandEvent: CommandEvent) => {
28
28
  try {
29
29
  // console.log("sync_measureunit_family");
30
30
 
31
+ if (commandEvent.app.formData?.measureUnitInjections) {
32
+ try {
33
+ if (typeof commandEvent.app.formData?.measureUnitInjections == "string")
34
+ commandEvent.app.formData.measureUnitInjections = JSON.parse(
35
+ commandEvent.app.formData.measureUnitInjections
36
+ );
37
+ if (!Array.isArray(commandEvent.app.formData?.measureUnitInjections)) {
38
+ delete commandEvent.app.formData.measureUnitInjections;
39
+ }
40
+ } catch (e) {
41
+ console.error(e);
42
+ delete commandEvent.app.formData.measureUnitInjections;
43
+ }
44
+ }
45
+
31
46
  const new_bench_time = new Date().toISOString();
32
47
  const bench_time_key = "bench_time_measureunit_family";
33
48
 
@@ -107,7 +122,7 @@ export const sync_measureunit_family = async (commandEvent: CommandEvent) => {
107
122
  (r_family) => r_family.integration_meta?.id == `${nameSpace}_${key}`
108
123
  );
109
124
 
110
- let measureunits: string[] = [];
125
+ const measureunits: string[] = [];
111
126
  Object.keys(sap_family).forEach((unit) => {
112
127
  {
113
128
  const UoM = repzo_UoMs?.data?.find(
@@ -119,6 +134,25 @@ export const sync_measureunit_family = async (commandEvent: CommandEvent) => {
119
134
  }
120
135
  });
121
136
 
137
+ if (commandEvent.app.formData?.measureUnitInjections?.length) {
138
+ const related_uom_s =
139
+ commandEvent.app.formData.measureUnitInjections.filter(
140
+ (doc) => doc?.itemCode == key
141
+ );
142
+ related_uom_s.forEach((related_uom) => {
143
+ const UoM = repzo_UoMs?.data?.find(
144
+ (repzo_uom) =>
145
+ repzo_uom?.name == related_uom?.uom &&
146
+ repzo_uom?.integration_meta?.ITEMCODE == key
147
+ );
148
+ if (UoM) {
149
+ if (!measureunits.includes(UoM._id.toString())) {
150
+ measureunits.push(UoM._id.toString());
151
+ }
152
+ }
153
+ });
154
+ }
155
+
122
156
  const body:
123
157
  | Service.MeasureUnitFamily.Create.Body
124
158
  | Service.MeasureUnitFamily.Update.Body = {
@@ -0,0 +1,396 @@
1
+ import { CommandEvent } from "../../types";
2
+ import { Commands } from "../../index.js";
3
+
4
+ let commandEvent: CommandEvent | any = {
5
+ app: {
6
+ _id: "639f0bf52070c5be595e955c",
7
+ name: "SAP",
8
+ disabled: false,
9
+ available_app: {
10
+ _id: "6391a268db71ef64357195da",
11
+ name: "repzo-sap-absjo",
12
+ title: "SAP ABS JO",
13
+ logo: "https://prod-repzo-media-service.s3.us-east-1.amazonaws.com/repzo/image/2022/12/18/3f73de7d-1920-4786-90db-57c76d18acci-SAP_EBS_JO.png",
14
+ description:
15
+ "SAP Jordan. We provide real value to SMEs by understanding their business and driving their vision forward with SAP Business One",
16
+ disabled: false,
17
+ JSONSchema: {
18
+ title: "SAP Integration Settings",
19
+ type: "object",
20
+ required: ["repzoApiKey", "sapHostUrl"],
21
+ properties: {
22
+ repzoApiKey: { type: "string", title: "Repzo API KEY" },
23
+ sapHostUrl: { type: "string", title: "SAP Host Url" },
24
+ errorEmail: {
25
+ type: "string",
26
+ format: "email",
27
+ title: "Email in case of error",
28
+ },
29
+ GroupCode: {
30
+ type: "string",
31
+ format: "string",
32
+ title: "Customers GroupCode",
33
+ },
34
+ warehouseDefaultUpdateDate: {
35
+ type: "string",
36
+ format: "date",
37
+ title: "Warehouse: Default Update Date",
38
+ },
39
+ DepartmentCode: {
40
+ type: "string",
41
+ format: "string",
42
+ title: "Invoice/Return Department Code",
43
+ },
44
+ return_reason: {
45
+ type: "string",
46
+ format: "string",
47
+ title: "Return Reason Array",
48
+ },
49
+ measureUnitInjections: {
50
+ type: "string",
51
+ format: "string",
52
+ title: "Uom Injection Array",
53
+ },
54
+ defaultWarehouseForSalesOrder: {
55
+ type: "string",
56
+ format: "string",
57
+ title: "Default Warehouse Code For Sales Orders",
58
+ },
59
+ SalPersCode: {
60
+ type: "string",
61
+ format: "string",
62
+ title: "Default Sales Person Code For Sales Orders",
63
+ },
64
+ SalesPersonCode: {
65
+ type: "string",
66
+ format: "string",
67
+ title: "Default Sales Person Code For Transfer",
68
+ },
69
+ invoices: {
70
+ type: "object",
71
+ title: "Invoices",
72
+ required: ["createInvoiceHook", "createReturnInvoiceHook"],
73
+ properties: {
74
+ createInvoiceHook: {
75
+ type: "boolean",
76
+ title: "Live Sync Invoices from Repzo to SAP",
77
+ default: false,
78
+ },
79
+ createReturnInvoiceHook: {
80
+ type: "boolean",
81
+ title: "Live Sync Return Invoice from Repzo to SAP",
82
+ default: false,
83
+ },
84
+ },
85
+ },
86
+ payments: {
87
+ type: "object",
88
+ title: "Payments",
89
+ required: ["createPaymentHook"],
90
+ properties: {
91
+ createPaymentHook: {
92
+ type: "boolean",
93
+ title: "Live Sync Payments from Repzo to SAP",
94
+ default: false,
95
+ },
96
+ },
97
+ },
98
+ proformas: {
99
+ type: "object",
100
+ title: "Sales Orders",
101
+ required: ["createApprovedProformaHook"],
102
+ properties: {
103
+ createApprovedProformaHook: {
104
+ type: "boolean",
105
+ title: "Live Sync Approved Sales Orders from Repzo to SAP",
106
+ default: false,
107
+ },
108
+ },
109
+ },
110
+ transfers: {
111
+ type: "object",
112
+ title: "Transfers",
113
+ required: ["createApprovedTransferHook"],
114
+ properties: {
115
+ createApprovedTransferHook: {
116
+ type: "boolean",
117
+ title: "Live Sync Approved Transfers from Repzo to SAP",
118
+ default: false,
119
+ },
120
+ adjustInventoryInFailedTransfer: {
121
+ type: "boolean",
122
+ title:
123
+ "Adjust Inventories in Repzo if creation Transfer Failed in SAP",
124
+ default: false,
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ options_JSONSchema: {
131
+ title: "SAP Integration Optional Settings",
132
+ type: "object",
133
+ required: [],
134
+ properties: {
135
+ bench_time_warehouse: {
136
+ title: "Bench Time: Warehouse",
137
+ type: "string",
138
+ format: "date",
139
+ },
140
+ bench_time_channel: {
141
+ title: "Bench Time: Channels",
142
+ type: "string",
143
+ format: "date-time",
144
+ },
145
+ bench_time_payment_term: {
146
+ title: "Bench Time: Payment Terms",
147
+ type: "string",
148
+ format: "date-time",
149
+ },
150
+ bench_time_product: {
151
+ title: "Bench Time: Products",
152
+ type: "string",
153
+ format: "date-time",
154
+ },
155
+ bench_time_product_disabled: {
156
+ title: "Bench Time: Inactive Products",
157
+ type: "string",
158
+ format: "date-time",
159
+ },
160
+ bench_time_price_list: {
161
+ title: "Bench Time: Price List",
162
+ type: "string",
163
+ format: "date-time",
164
+ },
165
+ bench_time_client: {
166
+ title: "Bench Time: Clients",
167
+ type: "string",
168
+ format: "date-time",
169
+ },
170
+ bench_time_disabled_client: {
171
+ title: "Bench Time: Inactive Clients",
172
+ type: "string",
173
+ format: "date-time",
174
+ },
175
+ },
176
+ },
177
+ app_settings: {
178
+ repo: "",
179
+ serviceEndPoint: "",
180
+ _id: "6391a268db71ef64357195db",
181
+ },
182
+ app_category: "6249fa8466312f76e595634a",
183
+ commands: [
184
+ {
185
+ command: "basic",
186
+ name: "Full Sync",
187
+ description: "Exclude Join & Adjust Inventories",
188
+ group_sync: false,
189
+ _id: "6391a268db71ef64357195dc",
190
+ },
191
+ {
192
+ command: "join",
193
+ name: "Join",
194
+ description: "",
195
+ group_sync: false,
196
+ _id: "6391a268db71ef64357195dd",
197
+ },
198
+ {
199
+ command: "warehouse",
200
+ name: "Sync Warehouse",
201
+ description: "Sync Warehouses From SAP to Repzo",
202
+ group_sync: false,
203
+ _id: "6391c42a1b0f4f7a30e40f40",
204
+ },
205
+ {
206
+ command: "rep",
207
+ name: "Sync Representatives",
208
+ description: "Sync Representatives From SAP to Repzo",
209
+ group_sync: false,
210
+ _id: "639715c2bee5dd4b6b11e129",
211
+ },
212
+ {
213
+ command: "tax",
214
+ name: "Sync Taxes",
215
+ description: "Sync Taxes From SAP to Repzo",
216
+ group_sync: false,
217
+ _id: "639715c2bee5dd4b6b11e12a",
218
+ },
219
+ {
220
+ command: "tag",
221
+ name: "Sync Area Tags",
222
+ description: "Sync Area Tags From SAP to Repzo",
223
+ group_sync: false,
224
+ _id: "639715c2bee5dd4b6b11e12b",
225
+ },
226
+ {
227
+ command: "measureunit",
228
+ name: "Sync Measure Units",
229
+ description: "Sync Measure Units From SAP to Repzo",
230
+ group_sync: false,
231
+ _id: "639817eaedafde008af0ad0e",
232
+ },
233
+ {
234
+ command: "measureunit_family",
235
+ name: "Sync Measure Units Family",
236
+ description: "Sync Measure Units Family From SAP to Repzo",
237
+ group_sync: false,
238
+ _id: "63982d09edafde008af0f698",
239
+ },
240
+ {
241
+ command: "category",
242
+ name: "Sync Product Category",
243
+ description: "Sync Product Categories From SAP to Repzo",
244
+ group_sync: false,
245
+ _id: "63984085edafde008af2f689",
246
+ },
247
+ {
248
+ command: "brand",
249
+ name: "Sync Product Brand",
250
+ description: "Sync Product Brands From SAP to Repzo",
251
+ group_sync: false,
252
+ _id: "63984085edafde008af2f689",
253
+ },
254
+ {
255
+ command: "channel",
256
+ name: "Sync Client's Channels",
257
+ description: "Sync Client's Channels From SAP to Repzo",
258
+ group_sync: false,
259
+ _id: "63984085edafde008af2f689",
260
+ },
261
+ {
262
+ command: "payment_term",
263
+ name: "Sync Payments Term",
264
+ description: "Sync Payments Term From SAP to Repzo",
265
+ group_sync: false,
266
+ _id: "63984085edafde008af2f68a",
267
+ },
268
+ {
269
+ command: "bank",
270
+ name: "Sync Banks",
271
+ description: "Sync Banks From SAP to Repzo",
272
+ group_sync: false,
273
+ _id: "63986018333b84929c538570",
274
+ },
275
+ {
276
+ command: "product",
277
+ name: "Sync Products",
278
+ description: "Sync Active Products From SAP to Repzo",
279
+ group_sync: false,
280
+ _id: "63987139333b84929c53a293",
281
+ },
282
+ {
283
+ command: "disabled_product",
284
+ name: "Sync Inactive Products",
285
+ description: "Sync Inactive Products From SAP to Repzo",
286
+ group_sync: false,
287
+ _id: "6399714d0242db686d496466",
288
+ },
289
+ {
290
+ command: "price_list",
291
+ name: "Sync Price Lists",
292
+ description: "Sync Price Lists From SAP to Repzo",
293
+ group_sync: false,
294
+ _id: "639972d6e8a1cfdd26deaa7e",
295
+ },
296
+ {
297
+ command: "price_list_disabled",
298
+ name: "Sync Disbaled Price List Items",
299
+ description: "Sync Disbaled Price List Items From SAP to Repzo",
300
+ group_sync: false,
301
+ _id: "656ed4098961a3f97182773f",
302
+ },
303
+ {
304
+ command: "client",
305
+ name: "Sync Clients",
306
+ description: "Sync Clients From SAP to Repzo",
307
+ group_sync: false,
308
+ _id: "63997615e8a1cfdd26ded7d1",
309
+ },
310
+ {
311
+ command: "disabled_client",
312
+ name: "Sync Inactive Clients",
313
+ description: "Sync Inactive Clients From SAP to Repzo",
314
+ group_sync: false,
315
+ _id: "639ac554e157f1c63770c1bc",
316
+ },
317
+ {
318
+ command: "adjust_inventory",
319
+ name: "Adjust Inventories",
320
+ description: "Adjust Inventories From SAP to Repzo",
321
+ group_sync: false,
322
+ _id: "639ac56fe157f1c63770c2eb",
323
+ },
324
+ ],
325
+ actions: [
326
+ {
327
+ action: "create_invoice",
328
+ name: "Sync Invoices",
329
+ description: "Sync Invoices From Repzo to SAP",
330
+ _id: "639ebeacdbba64d7af94520c",
331
+ },
332
+ {
333
+ action: "create_return_invoice",
334
+ name: "Sync Return Invoices",
335
+ description: "Sync Return Invoices From Repzo to SAP",
336
+ _id: "639ebeacdbba64d7af94520d",
337
+ },
338
+ {
339
+ action: "create_proforma",
340
+ name: "Sync Approved Sales Orders",
341
+ description: "Sync Approved Sales Orders From Repzo to SAP",
342
+ _id: "639ebeacdbba64d7af94520e",
343
+ },
344
+ {
345
+ action: "create_payment",
346
+ name: "Sync Paymants",
347
+ description: "Sync Paymants From Repzo to SAP",
348
+ _id: "639ebeacdbba64d7af94520f",
349
+ },
350
+ {
351
+ action: "create_transfer",
352
+ name: "Sync Approved Transfers",
353
+ description: "Sync Approved Transfers From Repzo to SAP",
354
+ _id: "639ebeacdbba64d7af945210",
355
+ },
356
+ ],
357
+ createdAt: "2022-12-08T08:38:00.915Z",
358
+ updatedAt: "2025-09-01T08:32:54.793Z",
359
+ __v: 0,
360
+ subscription_billing_mode: "free",
361
+ },
362
+ company_namespace: ["unipaljo"],
363
+ formData: {
364
+ repzoApiKey: "seCTdOxk1zYljAZZRJaqWga2Hc6zjzWscf6FfaP9eE8",
365
+ sapHostUrl: "http://unipal.b1pro.com:8083/api",
366
+ invoices: { createInvoiceHook: false, createReturnInvoiceHook: false },
367
+ payments: { createPaymentHook: false },
368
+ proformas: { createApprovedProformaHook: false },
369
+ transfers: {
370
+ createApprovedTransferHook: false,
371
+ adjustInventoryInFailedTransfer: false,
372
+ },
373
+ warehouseDefaultUpdateDate: "2015-01-01",
374
+ DepartmentCode: "D2",
375
+ return_reason:
376
+ '[{sap_id:1,sap_name:"BarcodeIssue",repzo_name:"Barcodeissue",repzo_id:"62b074972b332895edf114fc"},{sap_id:2,sap_name:"Damaged",repzo_name:"Damaged",repzo_id:"62b074ace96258fb745982e4"},{sap_id:3,sap_name:"Nearexpiry",repzo_name:"Nearexpiry",repzo_id:"62b074c0a066173bd1c1ea0d"},{sap_id:4,sap_name:"Wrongprinting",repzo_name:"Wrongprinting",repzo_id:"62b074d79e7f41f306a4cb42"},{sap_id:5,sap_name:"experied",repzo_name:"Experied",repzo_id:"62b074faa066173bd1c1eec0"}]',
377
+ SalPersCode: "111",
378
+ SalesPersonCode: "111",
379
+ measureUnitInjections: '[{ "itemCode": "010-KEA-JU0003", "uom": "PC" }]',
380
+ },
381
+ options_formData: {},
382
+ createdAt: "2022-12-18T12:47:49.096Z",
383
+ updatedAt: "2023-12-05T09:35:00.366Z",
384
+ __v: 0,
385
+ subscription_billing_mode: "free",
386
+ },
387
+ end_of_day: "04:00",
388
+ nameSpace: ["unipaljo"],
389
+ timezone: "Asia/Amman",
390
+ meta: "",
391
+ env: "staging",
392
+ sync_id: "774ed706-1868-49bc-9982-d320796babff",
393
+ command: "measureunit_family",
394
+ };
395
+
396
+ Commands(commandEvent);
package/src/types.ts CHANGED
@@ -78,8 +78,64 @@ export interface AvailableApp {
78
78
  app_category: string;
79
79
  }
80
80
 
81
+ export interface FormData {
82
+ repzoApiKey: string;
83
+ sapHostUrl: string;
84
+ warehouseDefaultUpdateDate?: string; // "2015-01-01",
85
+ DepartmentCode?: string; // "D2";
86
+ GroupCode?: string;
87
+ return_reasons?:
88
+ | {
89
+ sap_id: number;
90
+ sap_name: string;
91
+ repzo_name: string;
92
+ repzo_id: StringId;
93
+ }[]
94
+ | string;
95
+ defaultWarehouseForSalesOrder?: string; // "1";
96
+ SalPersCode?: string; // "111";
97
+ SalesPersonCode?: string; // "111";
98
+ measureUnitInjections?: { itemCode: string; uom: string }[];
99
+ invoices?: {
100
+ createInvoiceHook?: boolean;
101
+ createReturnInvoiceHook?: boolean;
102
+ };
103
+ payments?: { createPaymentHook?: boolean };
104
+ proformas?: { createApprovedProformaHook?: boolean };
105
+ transfers?: {
106
+ createApprovedTransferHook?: boolean;
107
+ adjustInventoryInFailedTransfer?: boolean;
108
+ };
109
+ }
110
+
111
+ interface OptionsFormData {
112
+ bench_time_warehouse?: string;
113
+ bench_time_channel?: string;
114
+ bench_time_payment_term?: string;
115
+ bench_time_product?: string;
116
+ bench_time_product_disabled?: string;
117
+ bench_time_price_list?: string;
118
+ bench_time_client?: string;
119
+ bench_time_disabled_client?: string;
120
+ bench_time_rep?: string;
121
+ bench_time_tax?: string;
122
+ bench_time_tag?: string;
123
+ bench_time_measureunit?: string;
124
+ bench_time_measureunit_family?: string;
125
+ bench_time_category?: string;
126
+ bench_time_bank?: string;
127
+ bench_time_brand?: string;
128
+ bench_time_price_list_disabled?: string;
129
+ }
130
+
131
+ interface AppWithCustomFormData
132
+ extends Service.App.Schema_with_populated_AvailableApp {
133
+ formData: FormData;
134
+ options_formData: OptionsFormData;
135
+ }
136
+
81
137
  export interface CommandEvent {
82
- app: Service.App.Schema_with_populated_AvailableApp;
138
+ app: AppWithCustomFormData;
83
139
  command: CommandType | string;
84
140
  nameSpace: NameSpaces;
85
141
  meta?: any;