repzo-sap-absjo 1.0.29 → 1.0.31

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,6 +17,7 @@
17
17
  - [commands/rep] delete hard code of rep.warehouse for reps start with: [WS, RET, MT] @maramalshen
18
18
  - [commands/client] decide if client is cash or credit depend on PAYMENTTERM instead of CLIENTGROUP @maramalshen
19
19
  - [actions/**] update integration_meta using repzo.updateIntegrationMeta instead of using service.update method to avoid infinity looping @maramalshen
20
+ - [actions/create_invoice, actions/create_return_invoice] RefNum: advanced_serial_number ||serial_number.formatted @maramalshen
20
21
 
21
22
  ### Fixed
22
23
 
@@ -1,5 +1,5 @@
1
1
  import { EVENT, Config } from "../types";
2
- interface SAPOpenInvoice {
2
+ export interface SAPOpenInvoice {
3
3
  CustomerNumber: string;
4
4
  FatherCode: string;
5
5
  DocDate: string;
@@ -23,4 +23,3 @@ export declare const get_invoice_from_sap: (
23
23
  InvoiceId: string;
24
24
  }
25
25
  ) => Promise<SAPOpenInvoice[]>;
26
- export {};
@@ -333,7 +333,9 @@ export const create_invoice = async (event, options) => {
333
333
  });
334
334
  }
335
335
  const sap_invoice = {
336
- RefNum: repzo_invoice.serial_number.formatted,
336
+ RefNum:
337
+ repzo_invoice.advanced_serial_number ||
338
+ repzo_invoice.serial_number.formatted,
337
339
  SalPersCode:
338
340
  repzo_rep === null || repzo_rep === void 0
339
341
  ? void 0
@@ -4,7 +4,7 @@ import { v4 as uuid } from "uuid";
4
4
  import moment from "moment-timezone";
5
5
  import { get_invoice_from_sap } from "./create_invoice.js";
6
6
  export const create_payment = async (event, options) => {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
8
8
  const repzo = new Repzo(
9
9
  (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
10
10
  { env: options.env }
@@ -96,20 +96,55 @@ export const create_payment = async (event, options) => {
96
96
  ? void 0
97
97
  : repzo_payment.LinkedTxn
98
98
  ) {
99
- const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
100
- updatedAt: "",
101
- Status: "",
102
- InvoiceId:
103
- (_g =
104
- (_f =
105
- repzo_payment === null || repzo_payment === void 0
106
- ? void 0
107
- : repzo_payment.LinkedTxn) === null || _f === void 0
99
+ const repzo_inv_serial_number =
100
+ (_g =
101
+ (_f =
102
+ repzo_payment === null || repzo_payment === void 0
108
103
  ? void 0
109
- : _f.Txn_serial_number) === null || _g === void 0
104
+ : repzo_payment.LinkedTxn) === null || _f === void 0
110
105
  ? void 0
111
- : _g.formatted,
106
+ : _f.Txn_serial_number) === null || _g === void 0
107
+ ? void 0
108
+ : _g.formatted;
109
+ const repzo_invoices = await repzo.invoice.find({
110
+ "serial_number.formatted": repzo_inv_serial_number,
112
111
  });
112
+ const repzo_invoice =
113
+ (_h =
114
+ repzo_invoices === null || repzo_invoices === void 0
115
+ ? void 0
116
+ : repzo_invoices.data) === null || _h === void 0
117
+ ? void 0
118
+ : _h.find((inv) => {
119
+ var _a;
120
+ return (
121
+ ((_a = inv.serial_number) === null || _a === void 0
122
+ ? void 0
123
+ : _a.formatted) == repzo_inv_serial_number
124
+ );
125
+ });
126
+ if (!repzo_invoice) {
127
+ throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on Repzo`;
128
+ }
129
+ let sap_open_invoices = [];
130
+ if (repzo_invoice.advanced_serial_number) {
131
+ sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
132
+ updatedAt: "",
133
+ Status: "",
134
+ InvoiceId: repzo_invoice.advanced_serial_number,
135
+ });
136
+ }
137
+ if (
138
+ !(sap_open_invoices === null || sap_open_invoices === void 0
139
+ ? void 0
140
+ : sap_open_invoices.length)
141
+ ) {
142
+ sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
143
+ updatedAt: "",
144
+ Status: "",
145
+ InvoiceId: repzo_inv_serial_number,
146
+ });
147
+ }
113
148
  if (
114
149
  !(sap_open_invoices === null || sap_open_invoices === void 0
115
150
  ? void 0
@@ -119,12 +154,12 @@ export const create_payment = async (event, options) => {
119
154
  }
120
155
  sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
121
156
  sap_payment.InvoiceTotal =
122
- ((_h =
157
+ ((_j =
123
158
  repzo_payment === null || repzo_payment === void 0
124
159
  ? void 0
125
- : repzo_payment.LinkedTxn) === null || _h === void 0
160
+ : repzo_payment.LinkedTxn) === null || _j === void 0
126
161
  ? void 0
127
- : _h.Txn_invoice_total) / 1000;
162
+ : _j.Txn_invoice_total) / 1000;
128
163
  } else {
129
164
  sap_payment.InvoiceID = "";
130
165
  sap_payment.InvoiceTotal = "";
@@ -133,7 +168,7 @@ export const create_payment = async (event, options) => {
133
168
  // bank
134
169
  //@ts-ignore
135
170
  const repzo_bank = await repzo.bank.get(
136
- (_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank
171
+ (_k = repzo_payment.check) === null || _k === void 0 ? void 0 : _k.bank
137
172
  );
138
173
  if (!repzo_bank) {
139
174
  //@ts-ignore
@@ -141,39 +176,39 @@ export const create_payment = async (event, options) => {
141
176
  }
142
177
  sap_payment.PaymentType = "2";
143
178
  sap_payment.ChequeAccount =
144
- (_k =
179
+ (_l =
145
180
  repzo_rep === null || repzo_rep === void 0
146
181
  ? void 0
147
- : repzo_rep.integration_meta) === null || _k === void 0
182
+ : repzo_rep.integration_meta) === null || _l === void 0
148
183
  ? void 0
149
- : _k.USERCHECKACCTCODE;
184
+ : _l.USERCHECKACCTCODE;
150
185
  sap_payment.ChequeDate = moment(
151
- (_l = repzo_payment.check) === null || _l === void 0
186
+ (_m = repzo_payment.check) === null || _m === void 0
152
187
  ? void 0
153
- : _l.check_date,
188
+ : _m.check_date,
154
189
  "YYYY-MM-DD"
155
190
  ).format("YYYYMMDD");
156
191
  sap_payment.ChequeNumber =
157
- (_m = repzo_payment.check) === null || _m === void 0
192
+ (_o = repzo_payment.check) === null || _o === void 0
158
193
  ? void 0
159
- : _m.check_number;
194
+ : _o.check_number;
160
195
  sap_payment.BankCode =
161
- (_o = repzo_bank.integration_meta) === null || _o === void 0
196
+ (_p = repzo_bank.integration_meta) === null || _p === void 0
162
197
  ? void 0
163
- : _o.BANKCODE;
198
+ : _p.BANKCODE;
164
199
  sap_payment.CountryCode =
165
- (_p = repzo_bank.integration_meta) === null || _p === void 0
200
+ (_q = repzo_bank.integration_meta) === null || _q === void 0
166
201
  ? void 0
167
- : _p.COUNTRY;
202
+ : _q.COUNTRY;
168
203
  } else if (repzo_payment.payment_type == "cash") {
169
204
  sap_payment.PaymentType = "1";
170
205
  sap_payment.CashAccount =
171
- (_q =
206
+ (_r =
172
207
  repzo_rep === null || repzo_rep === void 0
173
208
  ? void 0
174
- : repzo_rep.integration_meta) === null || _q === void 0
209
+ : repzo_rep.integration_meta) === null || _r === void 0
175
210
  ? void 0
176
- : _q.USERCASHACCOUNT;
211
+ : _r.USERCASHACCOUNT;
177
212
  }
178
213
  // console.dir(sap_payment, { depth: null });
179
214
  actionLog.addDetail(
@@ -271,7 +271,9 @@ export const create_return_invoice = async (event, options) => {
271
271
  });
272
272
  }
273
273
  const sap_return_invoice = {
274
- RefNum: repzo_invoice.serial_number.formatted,
274
+ RefNum:
275
+ repzo_invoice.advanced_serial_number ||
276
+ repzo_invoice.serial_number.formatted,
275
277
  SalPersCode:
276
278
  repzo_rep === null || repzo_rep === void 0
277
279
  ? void 0
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.29",
4
+ "version": "1.0.31",
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.103",
48
+ "repzo": "^1.0.109",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -38,7 +38,7 @@ interface SAPInvoice {
38
38
  U_ISTDQR?: string;
39
39
  }
40
40
 
41
- interface SAPOpenInvoice {
41
+ export interface SAPOpenInvoice {
42
42
  CustomerNumber: string; // "400065-53";
43
43
  FatherCode: string; // "400065";
44
44
  DocDate: string; // "2022-12-14T21:00:00Z";
@@ -285,7 +285,9 @@ export const create_invoice = async (event: EVENT, options: Config) => {
285
285
  }
286
286
 
287
287
  const sap_invoice: SAPInvoice = {
288
- RefNum: repzo_invoice.serial_number.formatted,
288
+ RefNum:
289
+ repzo_invoice.advanced_serial_number ||
290
+ repzo_invoice.serial_number.formatted,
289
291
  SalPersCode: repzo_rep?.integration_id,
290
292
  DocDate: moment(repzo_invoice.issue_date, "YYYY-MM-DD").format(
291
293
  "YYYYMMDD"
@@ -4,7 +4,7 @@ import { _fetch, _create, _update, _delete } from "../util.js";
4
4
  import { Service } from "repzo/src/types";
5
5
  import { v4 as uuid } from "uuid";
6
6
  import moment from "moment-timezone";
7
- import { get_invoice_from_sap } from "./create_invoice.js";
7
+ import { get_invoice_from_sap, SAPOpenInvoice } from "./create_invoice.js";
8
8
 
9
9
  interface SAPPayment {
10
10
  PaymentID: string; // "PAY-1041-3";
@@ -87,11 +87,33 @@ export const create_payment = async (event: EVENT, options: Config) => {
87
87
  };
88
88
 
89
89
  if (repzo_payment?.LinkedTxn) {
90
- const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
91
- updatedAt: "",
92
- Status: "",
93
- InvoiceId: repzo_payment?.LinkedTxn?.Txn_serial_number?.formatted,
90
+ const repzo_inv_serial_number =
91
+ repzo_payment?.LinkedTxn?.Txn_serial_number?.formatted;
92
+ const repzo_invoices = await repzo.invoice.find({
93
+ "serial_number.formatted": repzo_inv_serial_number,
94
94
  });
95
+ const repzo_invoice = repzo_invoices?.data?.find(
96
+ (inv) => inv.serial_number?.formatted == repzo_inv_serial_number
97
+ );
98
+ if (!repzo_invoice) {
99
+ throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on Repzo`;
100
+ }
101
+
102
+ let sap_open_invoices: SAPOpenInvoice[] = [];
103
+ if (repzo_invoice.advanced_serial_number) {
104
+ sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
105
+ updatedAt: "",
106
+ Status: "",
107
+ InvoiceId: repzo_invoice.advanced_serial_number,
108
+ });
109
+ }
110
+ if (!sap_open_invoices?.length) {
111
+ sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
112
+ updatedAt: "",
113
+ Status: "",
114
+ InvoiceId: repzo_inv_serial_number,
115
+ });
116
+ }
95
117
  if (!sap_open_invoices?.length) {
96
118
  throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on SAP or was closed`;
97
119
  }
@@ -208,7 +208,9 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
208
208
  }
209
209
 
210
210
  const sap_return_invoice: SAPInvoice = {
211
- RefNum: repzo_invoice.serial_number.formatted,
211
+ RefNum:
212
+ repzo_invoice.advanced_serial_number ||
213
+ repzo_invoice.serial_number.formatted,
212
214
  SalPersCode: repzo_rep?.integration_id,
213
215
  DocDate: moment(repzo_invoice.issue_date, "YYYY-MM-DD").format(
214
216
  "YYYYMMDD"