repzo-sap-absjo 1.0.40 → 1.0.42

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
@@ -4,6 +4,18 @@
4
4
 
5
5
  ### Added
6
6
 
7
+ - [RDT-3412/RDT-3415] Update invoice processing to send as sales order to SAP when setting enabled @maramalshen
8
+
9
+ ### Changed
10
+
11
+ ### Fixed
12
+
13
+ ### Removed
14
+
15
+ ## [v1.0.41 (2025-09-01)](https://github.com/Repzo/repzo-sap-absjo.git)
16
+
17
+ ### Added
18
+
7
19
  - [util] in method: getUniqueConcatenatedValues, also add the promotions for items.buy @maramalshen
8
20
  - [actions/***] add 2 keys in integration_meta: sync_to_sap_started & sync_to_sap_succeeded @maramalshen
9
21
  - [commands/product] assign Foreign Name (ITEMDESCF) in SAP to local_name in Repzo @maramalshen
@@ -1,9 +1,30 @@
1
1
  import Repzo from "repzo";
2
- import { _create, getUniqueConcatenatedValues } from "../util.js";
2
+ 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, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
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 }
@@ -363,7 +384,67 @@ export const create_invoice = async (event, options) => {
363
384
  `Repzo => SAP: Invoice - ${repzo_serial_number}`,
364
385
  sap_invoice
365
386
  );
366
- const result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
387
+ let treating_invoice_as_proforma_for_etax = false;
388
+ if (
389
+ ((_r = body === null || body === void 0 ? void 0 : body.creator) ===
390
+ null || _r === void 0
391
+ ? void 0
392
+ : _r.type) == "rep" &&
393
+ ((_s =
394
+ repzo_rep === null || repzo_rep === void 0
395
+ ? void 0
396
+ : repzo_rep.settings) === null || _s === void 0
397
+ ? void 0
398
+ : _s.treating_invoice_as_proforma_for_etax)
399
+ ) {
400
+ const company = await repzo.safeCrud.create({
401
+ collection: "company",
402
+ filters: { name_space: repzo_invoice.company_namespace },
403
+ });
404
+ if (
405
+ (_u =
406
+ (_t =
407
+ company === null || company === void 0 ? void 0 : company.data) ===
408
+ null || _t === void 0
409
+ ? void 0
410
+ : _t[0]) === null || _u === void 0
411
+ ? void 0
412
+ : _u.allow_treating_invoice_as_proforma_for_etax
413
+ ) {
414
+ treating_invoice_as_proforma_for_etax = true;
415
+ }
416
+ }
417
+ let result;
418
+ if (treating_invoice_as_proforma_for_etax) {
419
+ actionLog.addDetail(
420
+ `Repzo => SAP: Invoice - ${repzo_serial_number} - Treat Invoice as SalesOrder for eTax`,
421
+ sap_invoice
422
+ );
423
+ try {
424
+ result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
425
+ } catch (e) {
426
+ if (
427
+ typeof ((_v = set_error(e)) === null || _v === void 0
428
+ ? void 0
429
+ : _v.message) === "string" &&
430
+ ((_x =
431
+ (_w = set_error(e)) === null || _w === void 0
432
+ ? void 0
433
+ : _w.message) === null || _x === void 0
434
+ ? void 0
435
+ : _x.includes("this Sales Order is allready existed"))
436
+ ) {
437
+ result = {
438
+ success: true,
439
+ message: `Sales Order ${repzo_serial_number} already exists`,
440
+ };
441
+ } else {
442
+ throw e;
443
+ }
444
+ }
445
+ } else {
446
+ result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
447
+ }
367
448
  // console.log(result);
368
449
  try {
369
450
  await repzo.updateIntegrationMeta.create(
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.40",
4
+ "version": "1.0.42",
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.184",
48
+ "repzo": "^1.0.186",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -5,6 +5,7 @@ import {
5
5
  _create,
6
6
  _update,
7
7
  _delete,
8
+ set_error,
8
9
  getUniqueConcatenatedValues,
9
10
  } from "../util.js";
10
11
  import { Service } from "repzo/src/types";
@@ -316,7 +317,46 @@ export const create_invoice = async (event: EVENT, options: Config) => {
316
317
  sap_invoice
317
318
  );
318
319
 
319
- const result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
320
+ let treating_invoice_as_proforma_for_etax: boolean = false;
321
+ if (
322
+ body?.creator?.type == "rep" &&
323
+ repzo_rep?.settings?.treating_invoice_as_proforma_for_etax
324
+ ) {
325
+ const company = await repzo.safeCrud.create({
326
+ collection: "company",
327
+ filters: { name_space: repzo_invoice.company_namespace },
328
+ });
329
+ if (company?.data?.[0]?.allow_treating_invoice_as_proforma_for_etax) {
330
+ treating_invoice_as_proforma_for_etax = true;
331
+ }
332
+ }
333
+
334
+ let result;
335
+ if (treating_invoice_as_proforma_for_etax) {
336
+ actionLog.addDetail(
337
+ `Repzo => SAP: Invoice - ${repzo_serial_number} - Treat Invoice as SalesOrder for eTax`,
338
+ sap_invoice
339
+ );
340
+ try {
341
+ result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
342
+ } catch (e: any) {
343
+ if (
344
+ typeof set_error(e)?.message === "string" &&
345
+ set_error(e)?.message?.includes(
346
+ "this Sales Order is allready existed"
347
+ )
348
+ ) {
349
+ result = {
350
+ success: true,
351
+ message: `Sales Order ${repzo_serial_number} already exists`,
352
+ };
353
+ } else {
354
+ throw e;
355
+ }
356
+ }
357
+ } else {
358
+ result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
359
+ }
320
360
 
321
361
  // console.log(result);
322
362