repzo-sap-absjo 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -17,9 +17,11 @@
17
17
 
18
18
  ### Fixed
19
19
 
20
+ - [command/measureunit] if product has multi measureUnits, the base_measureunit should be PC, POUCH or CARD @maramalshen
20
21
  - [command/measureunit-family] use _.xor instead or _.difference @maramalshen
21
22
  - [command/price_list] fix bug in priceList-item @maramalshen
22
23
  - [actions/**] don't update integration_meta.sync_to_sap_succeeded if it is already true @maramalshen
24
+ - [actions/create_invoice] include item.get_promotion in MEO_Serial & Promotion_Name @maramalshen
23
25
 
24
26
  ### Removed
25
27
 
@@ -3,7 +3,7 @@ import { _create, 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, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
7
  const repzo = new Repzo(
8
8
  (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
9
9
  { env: options.env }
@@ -197,28 +197,42 @@ export const create_invoice = async (event, options) => {
197
197
  },
198
198
  { per_page: 50000 }
199
199
  );
200
+ const all_promotions = {};
201
+ (_g =
202
+ repzo_invoice === null || repzo_invoice === void 0
203
+ ? void 0
204
+ : repzo_invoice.promotions) === null || _g === void 0
205
+ ? void 0
206
+ : _g.forEach((promo) => {
207
+ if (!promo) return;
208
+ all_promotions[promo._id] = {
209
+ _id: promo._id,
210
+ name: promo.name,
211
+ ref: promo.ref,
212
+ };
213
+ });
200
214
  // Prepare SAP_invoice_items
201
215
  const items = [];
202
216
  for (
203
217
  let i = 0;
204
218
  i <
205
- ((_g =
219
+ ((_h =
206
220
  repzo_invoice === null || repzo_invoice === void 0
207
221
  ? void 0
208
- : repzo_invoice.items) === null || _g === void 0
222
+ : repzo_invoice.items) === null || _h === void 0
209
223
  ? void 0
210
- : _g.length);
224
+ : _h.length);
211
225
  i++
212
226
  ) {
213
227
  const item = repzo_invoice.items[i];
214
228
  // Get Repzo Tax
215
229
  const repzo_tax =
216
- (_h =
230
+ (_j =
217
231
  repzo_taxes === null || repzo_taxes === void 0
218
232
  ? void 0
219
- : repzo_taxes.data) === null || _h === void 0
233
+ : repzo_taxes.data) === null || _j === void 0
220
234
  ? void 0
221
- : _h.find((t) => {
235
+ : _j.find((t) => {
222
236
  var _a, _b, _c;
223
237
  return (
224
238
  ((_a = t._id) === null || _a === void 0
@@ -235,12 +249,12 @@ export const create_invoice = async (event, options) => {
235
249
  if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
236
250
  // Get Repzo UoM
237
251
  const repzo_measureunit =
238
- (_j =
252
+ (_k =
239
253
  repzo_measureunits === null || repzo_measureunits === void 0
240
254
  ? void 0
241
- : repzo_measureunits.data) === null || _j === void 0
255
+ : repzo_measureunits.data) === null || _k === void 0
242
256
  ? void 0
243
- : _j.find((m) => {
257
+ : _k.find((m) => {
244
258
  var _a, _b, _c;
245
259
  return (
246
260
  ((_a = m._id) === null || _a === void 0
@@ -256,16 +270,16 @@ export const create_invoice = async (event, options) => {
256
270
  });
257
271
  if (!repzo_measureunit)
258
272
  throw `Uom with _id: ${
259
- (_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id
273
+ (_l = item.measureunit) === null || _l === void 0 ? void 0 : _l._id
260
274
  } not found in Repzo`;
261
275
  // Get Repzo Product
262
276
  const repzo_product =
263
- (_l =
277
+ (_m =
264
278
  repzo_products === null || repzo_products === void 0
265
279
  ? void 0
266
- : repzo_products.data) === null || _l === void 0
280
+ : repzo_products.data) === null || _m === void 0
267
281
  ? void 0
268
- : _l.find((p) => {
282
+ : _m.find((p) => {
269
283
  var _a, _b, _c;
270
284
  return (
271
285
  ((_a = p._id) === null || _a === void 0
@@ -282,30 +296,40 @@ export const create_invoice = async (event, options) => {
282
296
  if (!repzo_product)
283
297
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
284
298
  items.push({
285
- MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
286
- Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
299
+ MEO_Serial: getUniqueConcatenatedValues(
300
+ item,
301
+ "ref",
302
+ " | ",
303
+ all_promotions
304
+ ),
305
+ Promotion_Name: getUniqueConcatenatedValues(
306
+ item,
307
+ "name",
308
+ " | ",
309
+ all_promotions
310
+ ),
287
311
  ItemCode: item.variant.variant_name,
288
312
  Quantity: item.qty,
289
313
  TaxCode: repzo_tax.integration_meta.TaxCode,
290
314
  UnitPrice: (item.price * repzo_measureunit.factor) / 1000,
291
- DiscountPerc: "0", // ??
315
+ DiscountPerc: "0",
292
316
  //@ts-ignore
293
317
  LineTotal: item.total_before_tax / 1000,
294
318
  UomCode: repzo_measureunit.integration_meta.ALTUOMID,
295
319
  Brand:
296
- (_m = repzo_product.integration_meta) === null || _m === void 0
320
+ (_o = repzo_product.integration_meta) === null || _o === void 0
297
321
  ? void 0
298
- : _m.BRAND, // "B1", // ??
322
+ : _o.BRAND,
299
323
  Department:
300
- ((_o =
324
+ ((_p =
301
325
  repzo_rep === null || repzo_rep === void 0
302
326
  ? void 0
303
- : repzo_rep.integration_meta) === null || _o === void 0
327
+ : repzo_rep.integration_meta) === null || _p === void 0
304
328
  ? void 0
305
- : _o.DEPARTMENTCODE) ||
306
- ((_p = options.data) === null || _p === void 0
329
+ : _p.DEPARTMENTCODE) ||
330
+ ((_q = options.data) === null || _q === void 0
307
331
  ? void 0
308
- : _p.DepartmentCode), // "D2",
332
+ : _q.DepartmentCode), // "D2",
309
333
  });
310
334
  }
311
335
  const sap_invoice = {
@@ -3,7 +3,7 @@ import { _create, getUniqueConcatenatedValues } from "../util.js";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import moment from "moment-timezone";
5
5
  export const create_proforma = async (event, options) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
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 = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
9
9
  { env: options.env }
@@ -137,28 +137,42 @@ export const create_proforma = async (event, options) => {
137
137
  },
138
138
  { per_page: 50000 }
139
139
  );
140
+ const all_promotions = {};
141
+ (_g =
142
+ repzo_proforma === null || repzo_proforma === void 0
143
+ ? void 0
144
+ : repzo_proforma.promotions) === null || _g === void 0
145
+ ? void 0
146
+ : _g.forEach((promo) => {
147
+ if (!promo) return;
148
+ all_promotions[promo._id] = {
149
+ _id: promo._id,
150
+ name: promo.name,
151
+ ref: promo.ref,
152
+ };
153
+ });
140
154
  // Prepare SAP_invoice_items
141
155
  const items = [];
142
156
  for (
143
157
  let i = 0;
144
158
  i <
145
- ((_g =
159
+ ((_h =
146
160
  repzo_proforma === null || repzo_proforma === void 0
147
161
  ? void 0
148
- : repzo_proforma.items) === null || _g === void 0
162
+ : repzo_proforma.items) === null || _h === void 0
149
163
  ? void 0
150
- : _g.length);
164
+ : _h.length);
151
165
  i++
152
166
  ) {
153
167
  const item = repzo_proforma.items[i];
154
168
  // Get Repzo Tax
155
169
  const repzo_tax =
156
- (_h =
170
+ (_j =
157
171
  repzo_taxes === null || repzo_taxes === void 0
158
172
  ? void 0
159
- : repzo_taxes.data) === null || _h === void 0
173
+ : repzo_taxes.data) === null || _j === void 0
160
174
  ? void 0
161
- : _h.find((t) => {
175
+ : _j.find((t) => {
162
176
  var _a, _b, _c;
163
177
  return (
164
178
  ((_a = t._id) === null || _a === void 0
@@ -175,12 +189,12 @@ export const create_proforma = async (event, options) => {
175
189
  if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
176
190
  // Get Repzo UoM
177
191
  const repzo_measureunit =
178
- (_j =
192
+ (_k =
179
193
  repzo_measureunits === null || repzo_measureunits === void 0
180
194
  ? void 0
181
- : repzo_measureunits.data) === null || _j === void 0
195
+ : repzo_measureunits.data) === null || _k === void 0
182
196
  ? void 0
183
- : _j.find((m) => {
197
+ : _k.find((m) => {
184
198
  var _a, _b, _c;
185
199
  return (
186
200
  ((_a = m._id) === null || _a === void 0
@@ -196,16 +210,16 @@ export const create_proforma = async (event, options) => {
196
210
  });
197
211
  if (!repzo_measureunit)
198
212
  throw `Uom with _id: ${
199
- (_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id
213
+ (_l = item.measureunit) === null || _l === void 0 ? void 0 : _l._id
200
214
  } not found in Repzo`;
201
215
  // Get Repzo Product
202
216
  const repzo_product =
203
- (_l =
217
+ (_m =
204
218
  repzo_products === null || repzo_products === void 0
205
219
  ? void 0
206
- : repzo_products.data) === null || _l === void 0
220
+ : repzo_products.data) === null || _m === void 0
207
221
  ? void 0
208
- : _l.find((p) => {
222
+ : _m.find((p) => {
209
223
  var _a, _b, _c;
210
224
  return (
211
225
  ((_a = p._id) === null || _a === void 0
@@ -222,8 +236,18 @@ export const create_proforma = async (event, options) => {
222
236
  if (!repzo_product)
223
237
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
224
238
  items.push({
225
- MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
226
- Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
239
+ MEO_Serial: getUniqueConcatenatedValues(
240
+ item,
241
+ "ref",
242
+ " | ",
243
+ all_promotions
244
+ ),
245
+ Promotion_Name: getUniqueConcatenatedValues(
246
+ item,
247
+ "name",
248
+ " | ",
249
+ all_promotions
250
+ ),
227
251
  ItemCode: item.variant.variant_name,
228
252
  Quantity: item.qty,
229
253
  TaxCode: repzo_tax.integration_meta.TaxCode,
@@ -233,28 +257,28 @@ export const create_proforma = async (event, options) => {
233
257
  LineTotal: item.total_before_tax / 1000,
234
258
  UomCode: repzo_measureunit.integration_meta.ALTUOMID,
235
259
  Brand:
236
- (_m = repzo_product.integration_meta) === null || _m === void 0
260
+ (_o = repzo_product.integration_meta) === null || _o === void 0
237
261
  ? void 0
238
- : _m.BRAND,
262
+ : _o.BRAND,
239
263
  Department:
240
- ((_o =
264
+ ((_p =
241
265
  repzo_rep === null || repzo_rep === void 0
242
266
  ? void 0
243
- : repzo_rep.integration_meta) === null || _o === void 0
267
+ : repzo_rep.integration_meta) === null || _p === void 0
244
268
  ? void 0
245
- : _o.DEPARTMENTCODE) ||
246
- ((_p = options.data) === null || _p === void 0
269
+ : _p.DEPARTMENTCODE) ||
270
+ ((_q = options.data) === null || _q === void 0
247
271
  ? void 0
248
- : _p.DepartmentCode), // "D2"
272
+ : _q.DepartmentCode), // "D2"
249
273
  });
250
274
  }
251
275
  const sap_invoice = {
252
276
  RefNum: repzo_proforma.serial_number.formatted,
253
277
  SalPersCode: repzo_rep
254
278
  ? repzo_rep.integration_id
255
- : (_q = options.data) === null || _q === void 0
279
+ : (_r = options.data) === null || _r === void 0
256
280
  ? void 0
257
- : _q.SalPersCode, // "111",
281
+ : _r.SalPersCode,
258
282
  DocDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format(
259
283
  "YYYYMMDD"
260
284
  ),
@@ -101,9 +101,14 @@ export const sync_measureunit = async (commandEvent) => {
101
101
  }
102
102
  });
103
103
  if (max_unit.sap_product_UoMs.length > 1) {
104
- max_unit.default_unit = max_unit.sap_product_UoMs.find(
105
- (u) => u.ALTUOMCODE == "PC"
104
+ const PC = max_unit.sap_product_UoMs.find((u) => u.ALTUOMCODE == "PC");
105
+ const POUCH = max_unit.sap_product_UoMs.find(
106
+ (u) => u.ALTUOMCODE == "POUCH"
106
107
  );
108
+ const CARD = max_unit.sap_product_UoMs.find(
109
+ (u) => u.ALTUOMCODE == "CARD"
110
+ );
111
+ max_unit.default_unit = PC || POUCH || CARD;
107
112
  if (!max_unit.default_unit) {
108
113
  // console.log(
109
114
  // "Create/Update Measure Unit Failed >> ",
@@ -197,7 +202,7 @@ export const sync_measureunit = async (commandEvent) => {
197
202
  const body = {
198
203
  parent: repzo_parent_id,
199
204
  name: sap_UoM.ALTUOMCODE,
200
- factor: sap_UoM.repzo_factor || 0, // ??????
205
+ factor: sap_UoM.repzo_factor || 0,
201
206
  disabled: false,
202
207
  integration_meta: {
203
208
  id: `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`,
@@ -299,7 +299,7 @@ export const sync_product = async (commandEvent) => {
299
299
  {
300
300
  disabled: false,
301
301
  name: sap_product.ITEMCODE,
302
- price: 0, // Math.round(sap_product.PRICE * 1000),
302
+ price: 0,
303
303
  integration_meta: {
304
304
  id: `${nameSpace}_${sap_product.ITEMCODE}`,
305
305
  ITEMCODE: sap_product.ITEMCODE,
@@ -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;
6
6
  const repzo = new Repzo(
7
7
  (_a = commandEvent.app.formData) === null || _a === void 0
8
8
  ? void 0
@@ -85,6 +85,11 @@ export const sync_rep = async (commandEvent) => {
85
85
  } reps in Repzo`
86
86
  )
87
87
  .commit();
88
+ // Get Repzo Warehouse
89
+ const repzo_warehouses = await repzo.warehouse.find({
90
+ per_page: 50000,
91
+ disabled: false,
92
+ });
88
93
  for (
89
94
  let i = 0;
90
95
  i <
@@ -106,27 +111,21 @@ export const sync_rep = async (commandEvent) => {
106
111
  });
107
112
  let warehouse;
108
113
  if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
109
- const warehouse_res = await repzo.warehouse.find({
110
- code: sap_rep.USERWHSCODE,
111
- });
112
- if (
113
- (_f =
114
- warehouse_res === null || warehouse_res === void 0
115
- ? void 0
116
- : warehouse_res.data) === null || _f === void 0
114
+ const warehouse_res =
115
+ repzo_warehouses === null || repzo_warehouses === void 0
117
116
  ? void 0
118
- : _f.length
119
- )
120
- warehouse = warehouse_res.data[0]._id;
117
+ : repzo_warehouses.data.find((w) => w.code == sap_rep.USERWHSCODE);
118
+ // await repzo.warehouse.find({ code: sap_rep.USERWHSCODE });
119
+ if (warehouse_res) warehouse = warehouse_res._id;
121
120
  }
122
121
  const body = {
123
122
  name: sap_rep.USERDESC,
124
123
  password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
125
124
  username: nameSpace + sap_rep.USERID,
126
125
  integration_id:
127
- (_g = sap_rep.USERID) === null || _g === void 0
126
+ (_f = sap_rep.USERID) === null || _f === void 0
128
127
  ? void 0
129
- : _g.toString(),
128
+ : _f.toString(),
130
129
  integration_meta: {
131
130
  DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
132
131
  USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
@@ -156,21 +155,21 @@ export const sync_rep = async (commandEvent) => {
156
155
  USERID: repzo_rep.integration_id,
157
156
  USERDESC: repzo_rep.name,
158
157
  DEPARTMENTCODE:
159
- (_h = repzo_rep.integration_meta) === null || _h === void 0
158
+ (_g = repzo_rep.integration_meta) === null || _g === void 0
160
159
  ? void 0
161
- : _h.DEPARTMENTCODE,
160
+ : _g.DEPARTMENTCODE,
162
161
  USERCASHACCOUNT:
163
- (_j = repzo_rep.integration_meta) === null || _j === void 0
162
+ (_h = repzo_rep.integration_meta) === null || _h === void 0
164
163
  ? void 0
165
- : _j.USERCASHACCOUNT,
164
+ : _h.USERCASHACCOUNT,
166
165
  USERCHECKACCTCODE:
167
- (_k = repzo_rep.integration_meta) === null || _k === void 0
166
+ (_j = repzo_rep.integration_meta) === null || _j === void 0
168
167
  ? void 0
169
- : _k.USERCHECKACCTCODE,
168
+ : _j.USERCHECKACCTCODE,
170
169
  USERWHSCODE:
171
- (_l = repzo_rep.integration_meta) === null || _l === void 0
170
+ (_k = repzo_rep.integration_meta) === null || _k === void 0
172
171
  ? void 0
173
- : _l.USERWHSCODE,
172
+ : _k.USERWHSCODE,
174
173
  });
175
174
  if (found_identical_docs.length) continue;
176
175
  // Update
@@ -212,10 +211,10 @@ export const sync_rep = async (commandEvent) => {
212
211
  } catch (e) {
213
212
  //@ts-ignore
214
213
  console.error(
215
- ((_m = e === null || e === void 0 ? void 0 : e.response) === null ||
216
- _m === void 0
214
+ ((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
215
+ _l === void 0
217
216
  ? void 0
218
- : _m.data) || e
217
+ : _l.data) || e
219
218
  );
220
219
  await commandLog.setStatus("fail", e).commit();
221
220
  throw e;
@@ -96,7 +96,7 @@ export const sync_tax = async (commandEvent) => {
96
96
  const body = {
97
97
  name: sap_tax.TaxName,
98
98
  rate: Number(sap_tax.TaxRate / 100),
99
- type: "additive", // hardcode
99
+ type: "additive",
100
100
  disabled: sap_tax.Inactive === "N" ? false : true,
101
101
  integration_meta: {
102
102
  id: `${nameSpace}_${sap_tax.TaxCode}`,
@@ -6,7 +6,7 @@ Actions(
6
6
  rawPath: "/actions",
7
7
  rawQueryString: "app=repzo-sap-absjo&action=create_invoice",
8
8
  headers: {
9
- action_sync_id: "Actions-0000001", // SYNC_ID
9
+ action_sync_id: "Actions-0000001",
10
10
  accept: "*/*",
11
11
  "accept-encoding": "gzip, deflate",
12
12
  "content-length": "3658",
@@ -6,7 +6,7 @@ Actions(
6
6
  rawPath: "/actions",
7
7
  rawQueryString: "app=repzo-sap-absjo&action=create_payment",
8
8
  headers: {
9
- action_sync_id: "Actions-0000004", // SYNC_ID
9
+ action_sync_id: "Actions-0000004",
10
10
  accept: "*/*",
11
11
  "accept-encoding": "gzip, deflate",
12
12
  "content-length": "3658",
@@ -6,7 +6,7 @@ Actions(
6
6
  rawPath: "/actions",
7
7
  rawQueryString: "app=repzo-sap-absjo&action=create_proforma",
8
8
  headers: {
9
- action_sync_id: "Actions-0000003", // SYNC_ID
9
+ action_sync_id: "Actions-0000003",
10
10
  accept: "*/*",
11
11
  "accept-encoding": "gzip, deflate",
12
12
  "content-length": "3658",
@@ -6,7 +6,7 @@ Actions(
6
6
  rawPath: "/actions",
7
7
  rawQueryString: "app=repzo-sap-absjo&action=create_return_invoice",
8
8
  headers: {
9
- action_sync_id: "Actions-0000002", // SYNC_ID
9
+ action_sync_id: "Actions-0000002",
10
10
  accept: "*/*",
11
11
  "accept-encoding": "gzip, deflate",
12
12
  "content-length": "3658",
@@ -6,7 +6,7 @@ Actions(
6
6
  rawPath: "/actions",
7
7
  rawQueryString: "app=repzo-sap-absjo&action=create_transfer",
8
8
  headers: {
9
- action_sync_id: "Actions-0000005", // SYNC_ID
9
+ action_sync_id: "Actions-0000005",
10
10
  accept: "*/*",
11
11
  "accept-encoding": "gzip, deflate",
12
12
  "content-length": "3658",
@@ -87,7 +87,7 @@ let commandEvent = {
87
87
  __v: 0,
88
88
  },
89
89
  end_of_day: "04:00",
90
- nameSpace: ["unisap"], // demosv
90
+ nameSpace: ["unisap"],
91
91
  timezone: "Asia/Amman",
92
92
  meta: "",
93
93
  env: "staging",
@@ -87,7 +87,7 @@ let commandEvent = {
87
87
  __v: 0,
88
88
  },
89
89
  end_of_day: "04:00",
90
- nameSpace: ["unisap"], // demosv
90
+ nameSpace: ["unisap"],
91
91
  timezone: "Asia/Amman",
92
92
  meta: "",
93
93
  env: "staging",
@@ -87,7 +87,7 @@ let commandEvent = {
87
87
  __v: 0,
88
88
  },
89
89
  end_of_day: "04:00",
90
- nameSpace: ["unisap"], // demosv
90
+ nameSpace: ["unisap"],
91
91
  timezone: "Asia/Amman",
92
92
  meta: "",
93
93
  env: "staging",
@@ -87,7 +87,7 @@ let commandEvent = {
87
87
  __v: 0,
88
88
  },
89
89
  end_of_day: "04:00",
90
- nameSpace: ["unisap"], // demosv
90
+ nameSpace: ["unisap"],
91
91
  timezone: "Asia/Amman",
92
92
  meta: "",
93
93
  env: "staging",
@@ -341,7 +341,7 @@ let commandEvent = {
341
341
  timezone: "Asia/Amman",
342
342
  meta: "",
343
343
  env: "staging",
344
- sync_id: "9811c42a-d26e-41e0-bee5-e75260c04767", // should change
344
+ sync_id: "9811c42a-d26e-41e0-bee5-e75260c04767",
345
345
  command: "price_list",
346
346
  };
347
347
  Commands(commandEvent);
@@ -353,7 +353,7 @@ let commandEvent = {
353
353
  timezone: "Asia/Amman",
354
354
  meta: "",
355
355
  env: "staging",
356
- sync_id: "a7e620b6-c5a2-44f7-b44b-3599b3ea1b54", // should change
356
+ sync_id: "a7e620b6-c5a2-44f7-b44b-3599b3ea1b54",
357
357
  command: "price_list_disabled",
358
358
  };
359
359
  Commands(commandEvent);
@@ -87,7 +87,7 @@ let commandEvent = {
87
87
  __v: 0,
88
88
  },
89
89
  end_of_day: "04:00",
90
- nameSpace: ["unisap"], // demosv
90
+ nameSpace: ["unisap"],
91
91
  timezone: "Asia/Amman",
92
92
  meta: "",
93
93
  env: "staging",
package/lib/util.d.ts CHANGED
@@ -83,6 +83,13 @@ export declare const send_command_to_marketplace: ({
83
83
  export declare const getUniqueConcatenatedValues: (
84
84
  item: Service.Item.Schema,
85
85
  key: "name" | "ref",
86
- delimiter: string
86
+ delimiter: string,
87
+ all_promos: {
88
+ [promo_id: string]: {
89
+ _id: string;
90
+ name: string;
91
+ ref?: string | undefined;
92
+ };
93
+ }
87
94
  ) => string;
88
95
  export {};
package/lib/util.js CHANGED
@@ -192,10 +192,27 @@ export const send_command_to_marketplace = async ({
192
192
  throw e;
193
193
  }
194
194
  };
195
- export const getUniqueConcatenatedValues = function (item, key, delimiter) {
195
+ export const getUniqueConcatenatedValues = function (
196
+ item,
197
+ key,
198
+ delimiter,
199
+ all_promos
200
+ ) {
201
+ var _a, _b, _c;
196
202
  item.general_promotions = item.general_promotions || [];
197
203
  item.used_promotions = item.used_promotions || [];
198
204
  const allPromotions = [...item.general_promotions, ...item.used_promotions];
205
+ if ((_a = item.promotions) === null || _a === void 0 ? void 0 : _a.isGet) {
206
+ const promo_id =
207
+ (_c =
208
+ (_b = item.promotions.bookings) === null || _b === void 0
209
+ ? void 0
210
+ : _b[0]) === null || _c === void 0
211
+ ? void 0
212
+ : _c.promotion;
213
+ if (promo_id && all_promos[promo_id])
214
+ allPromotions.push(all_promos[promo_id]);
215
+ }
199
216
  const uniqueValues = new Set(
200
217
  allPromotions.map((promotion) => promotion[key]).filter((value) => value)
201
218
  );
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.22",
4
+ "version": "1.0.24",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -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.29",
48
+ "repzo": "^1.0.33",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -217,6 +217,18 @@ export const create_invoice = async (event: EVENT, options: Config) => {
217
217
  { per_page: 50000 }
218
218
  );
219
219
 
220
+ const all_promotions: {
221
+ [promo_id: string]: { _id: string; name: string; ref?: string };
222
+ } = {};
223
+ repzo_invoice?.promotions?.forEach((promo) => {
224
+ if (!promo) return;
225
+ all_promotions[promo._id] = {
226
+ _id: promo._id,
227
+ name: promo.name,
228
+ ref: promo.ref,
229
+ };
230
+ });
231
+
220
232
  // Prepare SAP_invoice_items
221
233
  const items = [];
222
234
 
@@ -244,8 +256,18 @@ export const create_invoice = async (event: EVENT, options: Config) => {
244
256
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
245
257
 
246
258
  items.push({
247
- MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
248
- Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
259
+ MEO_Serial: getUniqueConcatenatedValues(
260
+ item,
261
+ "ref",
262
+ " | ",
263
+ all_promotions
264
+ ),
265
+ Promotion_Name: getUniqueConcatenatedValues(
266
+ item,
267
+ "name",
268
+ " | ",
269
+ all_promotions
270
+ ),
249
271
  ItemCode: item.variant.variant_name,
250
272
  Quantity: item.qty,
251
273
  TaxCode: repzo_tax.integration_meta.TaxCode,
@@ -143,6 +143,18 @@ export const create_proforma = async (event: EVENT, options: Config) => {
143
143
  { per_page: 50000 }
144
144
  );
145
145
 
146
+ const all_promotions: {
147
+ [promo_id: string]: { _id: string; name: string; ref?: string };
148
+ } = {};
149
+ repzo_proforma?.promotions?.forEach((promo) => {
150
+ if (!promo) return;
151
+ all_promotions[promo._id] = {
152
+ _id: promo._id,
153
+ name: promo.name,
154
+ ref: promo.ref,
155
+ };
156
+ });
157
+
146
158
  // Prepare SAP_invoice_items
147
159
  const items: SAPProformaItem[] = [];
148
160
 
@@ -170,8 +182,18 @@ export const create_proforma = async (event: EVENT, options: Config) => {
170
182
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
171
183
 
172
184
  items.push({
173
- MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
174
- Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
185
+ MEO_Serial: getUniqueConcatenatedValues(
186
+ item,
187
+ "ref",
188
+ " | ",
189
+ all_promotions
190
+ ),
191
+ Promotion_Name: getUniqueConcatenatedValues(
192
+ item,
193
+ "name",
194
+ " | ",
195
+ all_promotions
196
+ ),
175
197
  ItemCode: item.variant.variant_name,
176
198
  Quantity: item.qty,
177
199
  TaxCode: repzo_tax.integration_meta.TaxCode,
@@ -39,7 +39,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
39
39
  const commandLog = new Repzo.CommandLog(
40
40
  repzo,
41
41
  commandEvent.app,
42
- commandEvent.command
42
+ commandEvent.command,
43
43
  );
44
44
  try {
45
45
  // console.log("sync_measureunit");
@@ -64,7 +64,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
64
64
 
65
65
  const sap_UoMs: SAPUoM[] = await get_sap_UoMs(
66
66
  commandEvent.app.formData.sapHostUrl,
67
- {}
67
+ {},
68
68
  );
69
69
  result.sap_total = sap_UoMs?.length;
70
70
 
@@ -114,9 +114,15 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
114
114
  });
115
115
 
116
116
  if (max_unit.sap_product_UoMs.length > 1) {
117
- max_unit.default_unit = max_unit.sap_product_UoMs.find(
118
- (u) => u.ALTUOMCODE == "PC"
117
+ const PC = max_unit.sap_product_UoMs.find((u) => u.ALTUOMCODE == "PC");
118
+ const POUCH = max_unit.sap_product_UoMs.find(
119
+ (u) => u.ALTUOMCODE == "POUCH",
119
120
  );
121
+ const CARD = max_unit.sap_product_UoMs.find(
122
+ (u) => u.ALTUOMCODE == "CARD",
123
+ );
124
+ max_unit.default_unit = PC || POUCH || CARD;
125
+
120
126
  if (!max_unit.default_unit) {
121
127
  // console.log(
122
128
  // "Create/Update Measure Unit Failed >> ",
@@ -129,7 +135,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
129
135
  max_unit?.sap_product_UoMs[0]?.ITEMCODE || units[0]?.ITEMCODE,
130
136
  doc: units,
131
137
  error_message: set_error(
132
- `Create/Update Measure Unit Failed >> ${max_unit?.sap_product_UoMs[0]?.ITEMCODE} Could not found the base_unit`
138
+ `Create/Update Measure Unit Failed >> ${max_unit?.sap_product_UoMs[0]?.ITEMCODE} Could not found the base_unit`,
133
139
  ),
134
140
  });
135
141
  result.failed++;
@@ -170,7 +176,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
170
176
  const repzo_UoM = repzo_UoMs.data.find(
171
177
  (r_UoM) =>
172
178
  r_UoM.integration_meta?.id ==
173
- `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`
179
+ `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`,
174
180
  );
175
181
 
176
182
  const body:
@@ -192,7 +198,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
192
198
  // Create
193
199
  try {
194
200
  const created_UoM = await repzo.measureunit.create(
195
- body as Service.MeasureUnit.Create.Body
201
+ body as Service.MeasureUnit.Create.Body,
196
202
  );
197
203
  result.created++;
198
204
  } catch (e: any) {
@@ -216,7 +222,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
216
222
  try {
217
223
  const updated_UoM = await repzo.measureunit.update(
218
224
  repzo_UoM._id,
219
- body as Service.MeasureUnit.Update.Body
225
+ body as Service.MeasureUnit.Update.Body,
220
226
  );
221
227
  result.updated++;
222
228
  } catch (e: any) {
@@ -242,12 +248,12 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
242
248
  repzo,
243
249
  commandEvent.app._id,
244
250
  bench_time_key,
245
- new_bench_time
251
+ new_bench_time,
246
252
  );
247
253
  await commandLog
248
254
  .setStatus(
249
255
  "success",
250
- failed_docs_report.length ? failed_docs_report : null
256
+ failed_docs_report.length ? failed_docs_report : null,
251
257
  )
252
258
  .setBody(result)
253
259
  .commit();
@@ -262,7 +268,7 @@ export const sync_measureunit = async (commandEvent: CommandEvent) => {
262
268
 
263
269
  export const get_sap_UoMs = async (
264
270
  serviceEndPoint: string,
265
- query?: { updateAt?: string }
271
+ query?: { updateAt?: string },
266
272
  ): Promise<SAPUoM[]> => {
267
273
  try {
268
274
  const sap_UoMs: SAPUoMs = await _create(serviceEndPoint, "/Uom", {
@@ -93,6 +93,12 @@ export const sync_rep = async (commandEvent: CommandEvent) => {
93
93
  .addDetail(`${repzo_reps?.data?.length} reps in Repzo`)
94
94
  .commit();
95
95
 
96
+ // Get Repzo Warehouse
97
+ const repzo_warehouses = await repzo.warehouse.find({
98
+ per_page: 50000,
99
+ disabled: false,
100
+ });
101
+
96
102
  for (let i = 0; i < sap_reps?.Users?.length; i++) {
97
103
  const sap_rep: SAPRep = sap_reps.Users[i];
98
104
  const repzo_rep = repzo_reps.data.find(
@@ -102,10 +108,11 @@ export const sync_rep = async (commandEvent: CommandEvent) => {
102
108
 
103
109
  let warehouse;
104
110
  if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
105
- const warehouse_res = await repzo.warehouse.find({
106
- code: sap_rep.USERWHSCODE,
107
- });
108
- if (warehouse_res?.data?.length) warehouse = warehouse_res.data[0]._id;
111
+ const warehouse_res = repzo_warehouses?.data.find(
112
+ (w) => w.code == sap_rep.USERWHSCODE
113
+ );
114
+ // await repzo.warehouse.find({ code: sap_rep.USERWHSCODE });
115
+ if (warehouse_res) warehouse = warehouse_res._id;
109
116
  }
110
117
 
111
118
  const body: Service.Rep.Create.Body | Service.Rep.Update.Body = {
package/src/util.ts CHANGED
@@ -245,7 +245,10 @@ export const send_command_to_marketplace = async ({
245
245
  export const getUniqueConcatenatedValues = function (
246
246
  item: Service.Item.Schema,
247
247
  key: "name" | "ref",
248
- delimiter: string
248
+ delimiter: string,
249
+ all_promos: {
250
+ [promo_id: string]: { _id: string; name: string; ref?: string };
251
+ }
249
252
  ): string {
250
253
  item.general_promotions = item.general_promotions || [];
251
254
  item.used_promotions = item.used_promotions || [];
@@ -253,6 +256,11 @@ export const getUniqueConcatenatedValues = function (
253
256
  ...item.general_promotions,
254
257
  ...item.used_promotions,
255
258
  ];
259
+ if (item.promotions?.isGet) {
260
+ const promo_id = item.promotions.bookings?.[0]?.promotion;
261
+ if (promo_id && all_promos[promo_id])
262
+ allPromotions.push(all_promos[promo_id]);
263
+ }
256
264
  const uniqueValues = new Set(
257
265
  allPromotions.map((promotion) => promotion[key]).filter((value) => value)
258
266
  );