@accounter/server 0.0.9-alpha-20251216144137-dc7316f892e1fcf0e350cfbbaa9ca0746e1c6c50 → 0.0.9-alpha-20251216161545-668306e40cf3aed663f444e0004246489fbec6d4

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 (51) hide show
  1. package/CHANGELOG.md +5 -28
  2. package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1 -1
  3. package/dist/server/src/__generated__/types.d.ts +301 -282
  4. package/dist/server/src/__generated__/types.js.map +1 -1
  5. package/dist/server/src/modules/app-providers/green-invoice-client.d.ts +3 -3
  6. package/dist/server/src/modules/documents/__generated__/types.d.ts +7 -121
  7. package/dist/server/src/modules/documents/__generated__/types.js.map +1 -1
  8. package/dist/server/src/modules/documents/helpers/common.helper.d.ts +0 -2
  9. package/dist/server/src/modules/documents/helpers/common.helper.js +0 -20
  10. package/dist/server/src/modules/documents/helpers/common.helper.js.map +1 -1
  11. package/dist/server/src/modules/documents/index.js +2 -9
  12. package/dist/server/src/modules/documents/index.js.map +1 -1
  13. package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +135 -6
  14. package/dist/server/src/modules/green-invoice/__generated__/types.js +2 -0
  15. package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
  16. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.d.ts +7 -0
  17. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +53 -0
  18. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -0
  19. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.d.ts +27 -21
  20. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js +146 -151
  21. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js.map +1 -1
  22. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.d.ts +19 -0
  23. package/dist/server/src/modules/{documents → green-invoice}/helpers/issue-document.helper.js +11 -59
  24. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.js.map +1 -0
  25. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +347 -4
  26. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
  27. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +512 -4
  28. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
  29. package/dist/shaam-uniform-format-generator/src/generator/records/b110.d.ts +35 -35
  30. package/dist/shaam-uniform-format-generator/src/types/enums.d.ts +71 -71
  31. package/package.json +1 -1
  32. package/src/__generated__/types.ts +620 -327
  33. package/src/modules/documents/__generated__/types.ts +7 -121
  34. package/src/modules/documents/helpers/common.helper.ts +0 -21
  35. package/src/modules/documents/index.ts +2 -9
  36. package/src/modules/green-invoice/__generated__/types.ts +137 -6
  37. package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +69 -0
  38. package/src/modules/green-invoice/helpers/green-invoice.helper.ts +199 -183
  39. package/src/modules/{documents → green-invoice}/helpers/issue-document.helper.ts +44 -96
  40. package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +520 -5
  41. package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +512 -4
  42. package/dist/server/src/modules/documents/helpers/issue-document.helper.d.ts +0 -21
  43. package/dist/server/src/modules/documents/helpers/issue-document.helper.js.map +0 -1
  44. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.d.ts +0 -2
  45. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js +0 -346
  46. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js.map +0 -1
  47. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.d.ts +0 -2
  48. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js +0 -228
  49. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js.map +0 -1
  50. package/src/modules/documents/resolvers/documents-issuing.resolver.ts +0 -529
  51. package/src/modules/documents/typeDefs/documents-issuing.graphql.ts +0 -228
@@ -1,28 +1,34 @@
1
1
  import { Injector } from 'graphql-modules';
2
- import type { _DOLLAR_defs_Country, _DOLLAR_defs_Currency, _DOLLAR_defs_Document, _DOLLAR_defs_DocumentInputNew_Input, _DOLLAR_defs_DocumentLang, _DOLLAR_defs_DocumentType, _DOLLAR_defs_ExpenseDocumentType, _DOLLAR_defs_VatType, query_getDocument_payment_items_cardType, query_getDocument_payment_items_type, queryInput_previewDocument_input_discount_type, queryInput_previewDocument_input_linkType } from '../../../../../green-invoice-graphql/src/index.js';
3
- import type { DocumentDiscountType, DocumentIssueInput, DocumentLanguage, DocumentLinkType, DocumentPaymentRecordCardType, DocumentVatType, PaymentType, ResolversTypes } from '../../../__generated__/types.js';
2
+ import type { _DOLLAR_defs_Document, _DOLLAR_defs_DocumentInputNew_Input, _DOLLAR_defs_DocumentLang, _DOLLAR_defs_ExpenseDocumentType, _DOLLAR_defs_VatType, _DOLLAR_defs_Currency as GreenInvoiceCurrency, _DOLLAR_defs_DocumentType as GreenInvoiceDocumentType, query_getDocument_payment_items_appType, query_getDocument_payment_items_cardType, query_getDocument_payment_items_dealType, query_getDocument_payment_items_subType, query_getDocument_payment_items_type, queryInput_previewDocument_input_discount_type, queryInput_previewDocument_input_linkType } from '../../../../../green-invoice-graphql/src/index.js';
3
+ import type { GreenInvoiceCountry, GreenInvoiceDiscountType, GreenInvoiceDocumentLang, GreenInvoiceLinkType, GreenInvoicePaymentAppType, GreenInvoicePaymentCardType, GreenInvoicePaymentDealType, GreenInvoicePaymentSubType, GreenInvoicePaymentType, GreenInvoiceVatType, NewDocumentInput, ResolversTypes } from '../../../__generated__/types.js';
4
4
  import { CountryCode, Currency, DocumentType } from '../../../shared/enums.js';
5
5
  import type { document_status } from '../../documents/types.js';
6
- export declare function normalizeGreenInvoiceDocumentType(rawType?: _DOLLAR_defs_DocumentType | _DOLLAR_defs_ExpenseDocumentType | number | null): DocumentType;
7
- export declare function getGreenInvoiceDocumentType(documentType: DocumentType): _DOLLAR_defs_DocumentType;
8
- export declare function getTypeFromGreenInvoiceDocument(documentType: _DOLLAR_defs_DocumentType): DocumentType;
9
- export declare function getDocumentNameFromGreenInvoiceType(documentType: _DOLLAR_defs_DocumentType): string;
10
- export declare function getGreenInvoiceDocumentLanguage(lang: DocumentLanguage): _DOLLAR_defs_DocumentLang;
11
- export declare function getLanguageFromGreenInvoiceDocument(lang: _DOLLAR_defs_DocumentLang): DocumentLanguage;
12
- export declare function getGreenInvoiceDocumentVatType(vatType: DocumentVatType): _DOLLAR_defs_VatType;
13
- export declare function getVatTypeFromGreenInvoiceDocument(vatType: _DOLLAR_defs_VatType): DocumentVatType;
14
- export declare function getGreenInvoiceDocumentDiscountType(discountType: DocumentDiscountType): queryInput_previewDocument_input_discount_type;
15
- export declare function getGreenInvoiceDocumentPaymentType(type: PaymentType): query_getDocument_payment_items_type;
16
- export declare function getTypeFromGreenInvoiceDocumentPayment(type: query_getDocument_payment_items_type): PaymentType;
17
- export declare function getGreenInvoiceDocumentPaymentCardType(cardType: DocumentPaymentRecordCardType): query_getDocument_payment_items_cardType;
18
- export declare function getCardTypeFromGreenInvoiceDocumentPayment(cardType: query_getDocument_payment_items_cardType): DocumentPaymentRecordCardType;
19
- export declare function getGreenInvoiceDocumentLinkType(linkType: DocumentLinkType): queryInput_previewDocument_input_linkType;
20
- export declare function convertCurrencyToGreenInvoice(currency: Currency): _DOLLAR_defs_Currency;
21
- export declare function greenInvoiceCountryToCountryCode(country: _DOLLAR_defs_Country): CountryCode;
22
- export declare function countryCodeToGreenInvoiceCountry(countryCode: CountryCode): _DOLLAR_defs_Country;
6
+ export declare function normalizeDocumentType(rawType?: GreenInvoiceDocumentType | _DOLLAR_defs_ExpenseDocumentType | number | null): DocumentType;
7
+ export declare function getGreenInvoiceDocumentType(documentType: DocumentType): GreenInvoiceDocumentType;
8
+ export declare function getTypeFromGreenInvoiceDocument(documentType: GreenInvoiceDocumentType): DocumentType;
9
+ export declare function getGreenInvoiceDocumentNameFromType(documentType: DocumentType | GreenInvoiceDocumentType): string;
10
+ export declare function getGreenInvoiceDocumentLanguage(lang: GreenInvoiceDocumentLang): _DOLLAR_defs_DocumentLang;
11
+ export declare function getLanguageFromGreenInvoiceDocument(lang: _DOLLAR_defs_DocumentLang): GreenInvoiceDocumentLang;
12
+ export declare function getGreenInvoiceDocumentVatType(vatType: GreenInvoiceVatType): _DOLLAR_defs_VatType;
13
+ export declare function getVatTypeFromGreenInvoiceDocument(vatType: _DOLLAR_defs_VatType): GreenInvoiceVatType;
14
+ export declare function getGreenInvoiceDocumentDiscountType(discountType: GreenInvoiceDiscountType): queryInput_previewDocument_input_discount_type;
15
+ export declare function getGreenInvoiceDocumentPaymentType(type: GreenInvoicePaymentType): query_getDocument_payment_items_type;
16
+ export declare function getTypeFromGreenInvoiceDocumentPayment(type: query_getDocument_payment_items_type): GreenInvoicePaymentType;
17
+ export declare function getGreenInvoiceDocumentPaymentSubType(subType: GreenInvoicePaymentSubType): query_getDocument_payment_items_subType;
18
+ export declare function getSubTypeFromGreenInvoiceDocumentPayment(subType: query_getDocument_payment_items_subType): GreenInvoicePaymentSubType;
19
+ export declare function getGreenInvoiceDocumentPaymentAppType(appType: GreenInvoicePaymentAppType): query_getDocument_payment_items_appType;
20
+ export declare function getPaymentAppTypeFromGreenInvoiceDocument(appType: query_getDocument_payment_items_appType): GreenInvoicePaymentAppType;
21
+ export declare function getGreenInvoiceDocumentPaymentCardType(cardType: GreenInvoicePaymentCardType): query_getDocument_payment_items_cardType;
22
+ export declare function getCardTypeFromGreenInvoiceDocumentPayment(cardType: query_getDocument_payment_items_cardType): GreenInvoicePaymentCardType;
23
+ export declare function getGreenInvoiceDocumentPaymentDealType(dealType: GreenInvoicePaymentDealType): query_getDocument_payment_items_dealType;
24
+ export declare function getDealTypeFromGreenInvoiceDocumentPayment(dealType: query_getDocument_payment_items_dealType): GreenInvoicePaymentDealType;
25
+ export declare function getGreenInvoiceDocumentLinkType(linkType: GreenInvoiceLinkType): queryInput_previewDocument_input_linkType;
26
+ export declare function convertCurrencyToGreenInvoice(currency: Currency): GreenInvoiceCurrency;
27
+ export declare function greenInvoiceCountryToCountryCode(country: GreenInvoiceCountry): CountryCode;
28
+ export declare function countryCodeToGreenInvoiceCountry(countryCode: CountryCode): GreenInvoiceCountry;
23
29
  export declare function greenInvoiceToDocumentStatus(greenInvoiceStatus: number): document_status;
24
30
  export declare function getLinkedDocuments(injector: Injector, externalDocumentId: string): Promise<string[] | null>;
25
31
  export declare function insertNewDocumentFromGreenInvoice(injector: Injector, greenInvoiceDoc: _DOLLAR_defs_Document, ownerId: string, preDictatedChargeId?: string | null): Promise<import("../../documents/types.js").IInsertDocumentsResult>;
26
32
  export declare function getGreenInvoiceDocuments(injector: Injector, recursive?: boolean): Promise<_DOLLAR_defs_Document[]>;
27
- export declare function convertDocumentInputIntoGreenInvoiceInput(initialInput: DocumentIssueInput, injector: Injector): Promise<_DOLLAR_defs_DocumentInputNew_Input>;
28
- export declare function convertGreenInvoiceDocumentToDocumentDraft(greenInvoiceDocument: _DOLLAR_defs_Document, injector: Injector): Promise<ResolversTypes['DocumentDraft']>;
33
+ export declare function convertDocumentInputIntoGreenInvoiceInput(initialInput: NewDocumentInput, injector: Injector): Promise<_DOLLAR_defs_DocumentInputNew_Input>;
34
+ export declare function convertGreenInvoiceDocumentToLocalDocumentInfo(greenInvoiceDocument: _DOLLAR_defs_Document): ResolversTypes['NewDocumentInfo'];
@@ -8,7 +8,7 @@ import { DocumentsProvider } from '../../documents/providers/documents.provider.
8
8
  import { IssuedDocumentsProvider } from '../../documents/providers/issued-documents.provider.js';
9
9
  import { validateClientIntegrations } from '../../financial-entities/helpers/clients.helper.js';
10
10
  import { ClientsProvider } from '../../financial-entities/providers/clients.provider.js';
11
- export function normalizeGreenInvoiceDocumentType(rawType) {
11
+ export function normalizeDocumentType(rawType) {
12
12
  if (!rawType) {
13
13
  return DocumentType.Unprocessed;
14
14
  }
@@ -77,16 +77,21 @@ export function getTypeFromGreenInvoiceDocument(documentType) {
77
77
  throw new Error(`Unsupported document type: ${documentType}`);
78
78
  }
79
79
  }
80
- export function getDocumentNameFromGreenInvoiceType(documentType) {
80
+ export function getGreenInvoiceDocumentNameFromType(documentType) {
81
81
  switch (documentType) {
82
+ case DocumentType.Invoice:
82
83
  case '_305':
83
84
  return 'Tax Invoice';
85
+ case DocumentType.Proforma:
84
86
  case '_300':
85
87
  return 'Proforma Invoice';
88
+ case DocumentType.InvoiceReceipt:
86
89
  case '_320':
87
90
  return 'Invoice / Receipt';
91
+ case DocumentType.CreditInvoice:
88
92
  case '_330':
89
93
  return 'Credit Note';
94
+ case DocumentType.Receipt:
90
95
  case '_400':
91
96
  return 'Receipt';
92
97
  default:
@@ -195,94 +200,86 @@ export function getTypeFromGreenInvoiceDocumentPayment(type) {
195
200
  throw new Error(`Unsupported payment type: ${type}`);
196
201
  }
197
202
  }
198
- // export function getGreenInvoiceDocumentPaymentSubType(
199
- // subType: GreenInvoicePaymentSubType,
200
- // ): query_getDocument_payment_items_subType {
201
- // switch (subType) {
202
- // case 'BITCOIN':
203
- // return '_1';
204
- // case 'BUYME_VOUCHER':
205
- // return '_7';
206
- // case 'ETHEREUM':
207
- // return '_6';
208
- // case 'GIFT_CARD':
209
- // return '_4';
210
- // case 'MONEY_EQUAL':
211
- // return '_2';
212
- // case 'NII_EMPLOYEE_DEDUCTION':
213
- // return '_5';
214
- // case 'PAYONEER':
215
- // return '_8';
216
- // case 'V_CHECK':
217
- // return '_3';
218
- // default:
219
- // throw new Error(`Unsupported payment sub-type: ${subType}`);
220
- // }
221
- // }
222
- // export function getSubTypeFromGreenInvoiceDocumentPayment(
223
- // subType: query_getDocument_payment_items_subType,
224
- // ): GreenInvoicePaymentSubType {
225
- // switch (subType) {
226
- // case '_1':
227
- // return 'BITCOIN';
228
- // case '_7':
229
- // return 'BUYME_VOUCHER';
230
- // case '_6':
231
- // return 'ETHEREUM';
232
- // case '_4':
233
- // return 'GIFT_CARD';
234
- // case '_2':
235
- // return 'MONEY_EQUAL';
236
- // case '_5':
237
- // return 'NII_EMPLOYEE_DEDUCTION';
238
- // case '_8':
239
- // return 'PAYONEER';
240
- // case '_3':
241
- // return 'V_CHECK';
242
- // default:
243
- // throw new Error(`Unsupported payment sub-type: ${subType}`);
244
- // }
245
- // }
246
- // export function getGreenInvoiceDocumentPaymentAppType(
247
- // appType: GreenInvoicePaymentAppType,
248
- // ): query_getDocument_payment_items_appType {
249
- // switch (appType) {
250
- // case 'APPLE_PAY':
251
- // return '_6';
252
- // case 'BIT':
253
- // return '_1';
254
- // case 'CULO':
255
- // return '_4';
256
- // case 'GOOGLE_PAY':
257
- // return '_5';
258
- // case 'PAYBOX':
259
- // return '_3';
260
- // case 'PAY_BY_PEPPER':
261
- // return '_2';
262
- // default:
263
- // throw new Error(`Unsupported payment app type: ${appType}`);
264
- // }
265
- // }
266
- // export function getPaymentAppTypeFromGreenInvoiceDocument(
267
- // appType: query_getDocument_payment_items_appType,
268
- // ): GreenInvoicePaymentAppType {
269
- // switch (appType) {
270
- // case '_6':
271
- // return 'APPLE_PAY';
272
- // case '_1':
273
- // return 'BIT';
274
- // case '_4':
275
- // return 'CULO';
276
- // case '_5':
277
- // return 'GOOGLE_PAY';
278
- // case '_3':
279
- // return 'PAYBOX';
280
- // case '_2':
281
- // return 'PAY_BY_PEPPER';
282
- // default:
283
- // throw new Error(`Unsupported payment app type: ${appType}`);
284
- // }
285
- // }
203
+ export function getGreenInvoiceDocumentPaymentSubType(subType) {
204
+ switch (subType) {
205
+ case 'BITCOIN':
206
+ return '_1';
207
+ case 'BUYME_VOUCHER':
208
+ return '_7';
209
+ case 'ETHEREUM':
210
+ return '_6';
211
+ case 'GIFT_CARD':
212
+ return '_4';
213
+ case 'MONEY_EQUAL':
214
+ return '_2';
215
+ case 'NII_EMPLOYEE_DEDUCTION':
216
+ return '_5';
217
+ case 'PAYONEER':
218
+ return '_8';
219
+ case 'V_CHECK':
220
+ return '_3';
221
+ default:
222
+ throw new Error(`Unsupported payment sub-type: ${subType}`);
223
+ }
224
+ }
225
+ export function getSubTypeFromGreenInvoiceDocumentPayment(subType) {
226
+ switch (subType) {
227
+ case '_1':
228
+ return 'BITCOIN';
229
+ case '_7':
230
+ return 'BUYME_VOUCHER';
231
+ case '_6':
232
+ return 'ETHEREUM';
233
+ case '_4':
234
+ return 'GIFT_CARD';
235
+ case '_2':
236
+ return 'MONEY_EQUAL';
237
+ case '_5':
238
+ return 'NII_EMPLOYEE_DEDUCTION';
239
+ case '_8':
240
+ return 'PAYONEER';
241
+ case '_3':
242
+ return 'V_CHECK';
243
+ default:
244
+ throw new Error(`Unsupported payment sub-type: ${subType}`);
245
+ }
246
+ }
247
+ export function getGreenInvoiceDocumentPaymentAppType(appType) {
248
+ switch (appType) {
249
+ case 'APPLE_PAY':
250
+ return '_6';
251
+ case 'BIT':
252
+ return '_1';
253
+ case 'CULO':
254
+ return '_4';
255
+ case 'GOOGLE_PAY':
256
+ return '_5';
257
+ case 'PAYBOX':
258
+ return '_3';
259
+ case 'PAY_BY_PEPPER':
260
+ return '_2';
261
+ default:
262
+ throw new Error(`Unsupported payment app type: ${appType}`);
263
+ }
264
+ }
265
+ export function getPaymentAppTypeFromGreenInvoiceDocument(appType) {
266
+ switch (appType) {
267
+ case '_6':
268
+ return 'APPLE_PAY';
269
+ case '_1':
270
+ return 'BIT';
271
+ case '_4':
272
+ return 'CULO';
273
+ case '_5':
274
+ return 'GOOGLE_PAY';
275
+ case '_3':
276
+ return 'PAYBOX';
277
+ case '_2':
278
+ return 'PAY_BY_PEPPER';
279
+ default:
280
+ throw new Error(`Unsupported payment app type: ${appType}`);
281
+ }
282
+ }
286
283
  export function getGreenInvoiceDocumentPaymentCardType(cardType) {
287
284
  switch (cardType) {
288
285
  case 'AMERICAN_EXPRESS':
@@ -319,46 +316,42 @@ export function getCardTypeFromGreenInvoiceDocumentPayment(cardType) {
319
316
  throw new Error(`Unsupported payment card type: ${cardType}`);
320
317
  }
321
318
  }
322
- // export function getGreenInvoiceDocumentPaymentDealType(
323
- // dealType: GreenInvoicePaymentDealType,
324
- // ): query_getDocument_payment_items_dealType {
325
- // switch (dealType) {
326
- // case 'CREDIT':
327
- // return '_3';
328
- // case 'DEFERRED':
329
- // return '_4';
330
- // case 'OTHER':
331
- // return '_5';
332
- // case 'PAYMENTS':
333
- // return '_2';
334
- // case 'RECURRING':
335
- // return '_6';
336
- // case 'STANDARD':
337
- // return '_1';
338
- // default:
339
- // throw new Error(`Unsupported payment deal type: ${dealType}`);
340
- // }
341
- // }
342
- // export function getDealTypeFromGreenInvoiceDocumentPayment(
343
- // dealType: query_getDocument_payment_items_dealType,
344
- // ): GreenInvoicePaymentDealType {
345
- // switch (dealType) {
346
- // case '_3':
347
- // return 'CREDIT';
348
- // case '_4':
349
- // return 'DEFERRED';
350
- // case '_5':
351
- // return 'OTHER';
352
- // case '_2':
353
- // return 'PAYMENTS';
354
- // case '_6':
355
- // return 'RECURRING';
356
- // case '_1':
357
- // return 'STANDARD';
358
- // default:
359
- // throw new Error(`Unsupported payment deal type: ${dealType}`);
360
- // }
361
- // }
319
+ export function getGreenInvoiceDocumentPaymentDealType(dealType) {
320
+ switch (dealType) {
321
+ case 'CREDIT':
322
+ return '_3';
323
+ case 'DEFERRED':
324
+ return '_4';
325
+ case 'OTHER':
326
+ return '_5';
327
+ case 'PAYMENTS':
328
+ return '_2';
329
+ case 'RECURRING':
330
+ return '_6';
331
+ case 'STANDARD':
332
+ return '_1';
333
+ default:
334
+ throw new Error(`Unsupported payment deal type: ${dealType}`);
335
+ }
336
+ }
337
+ export function getDealTypeFromGreenInvoiceDocumentPayment(dealType) {
338
+ switch (dealType) {
339
+ case '_3':
340
+ return 'CREDIT';
341
+ case '_4':
342
+ return 'DEFERRED';
343
+ case '_5':
344
+ return 'OTHER';
345
+ case '_2':
346
+ return 'PAYMENTS';
347
+ case '_6':
348
+ return 'RECURRING';
349
+ case '_1':
350
+ return 'STANDARD';
351
+ default:
352
+ throw new Error(`Unsupported payment deal type: ${dealType}`);
353
+ }
354
+ }
362
355
  export function getGreenInvoiceDocumentLinkType(linkType) {
363
356
  switch (linkType) {
364
357
  case 'CANCEL':
@@ -955,7 +948,7 @@ export async function getLinkedDocuments(injector, externalDocumentId) {
955
948
  return linkedDocumentsIds;
956
949
  }
957
950
  export async function insertNewDocumentFromGreenInvoice(injector, greenInvoiceDoc, ownerId, preDictatedChargeId) {
958
- const documentType = normalizeGreenInvoiceDocumentType(greenInvoiceDoc.type);
951
+ const documentType = normalizeDocumentType(greenInvoiceDoc.type);
959
952
  const isOwnerCreditor = greenInvoiceDoc.amount > 0 && documentType !== DocumentType.CreditInvoice;
960
953
  const links = await injector.get(GreenInvoiceClientProvider).getDocumentLinks(greenInvoiceDoc.id);
961
954
  if (!links) {
@@ -1106,9 +1099,9 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1106
1099
  if (initialInput.client) {
1107
1100
  const clientInfo = await injector
1108
1101
  .get(ClientsProvider)
1109
- .getClientByIdLoader.load(initialInput.client.id);
1102
+ .getClientByIdLoader.load(initialInput.client.businessId);
1110
1103
  if (!clientInfo) {
1111
- throw new GraphQLError(`Client with business ID ${initialInput.client.id} not found`);
1104
+ throw new GraphQLError(`Client with ID ${initialInput.client.greenInvoiceId} not found`);
1112
1105
  }
1113
1106
  let greenInvoiceId = null;
1114
1107
  try {
@@ -1117,10 +1110,10 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1117
1110
  }
1118
1111
  catch (error) {
1119
1112
  console.error('Failed to validate client integrations', error);
1120
- throw new GraphQLError(`Client with business ID ${initialInput.client.id} has invalid integrations`);
1113
+ throw new GraphQLError(`Client with ID ${initialInput.client.greenInvoiceId} has invalid integrations`);
1121
1114
  }
1122
1115
  if (!greenInvoiceId) {
1123
- throw new GraphQLError(`Client with business ID ${initialInput.client.id} not found in Green Invoice`);
1116
+ throw new GraphQLError(`Client with ID ${initialInput.client.greenInvoiceId} not found in Green Invoice`);
1124
1117
  }
1125
1118
  const greenInvoiceClient = await injector
1126
1119
  .get(GreenInvoiceClientProvider)
@@ -1136,7 +1129,6 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1136
1129
  else {
1137
1130
  emails.push(...(greenInvoiceClient.emails ?? []));
1138
1131
  }
1139
- // TODO: use local values
1140
1132
  client = {
1141
1133
  id: greenInvoiceClient.id,
1142
1134
  country: greenInvoiceClient.country,
@@ -1156,7 +1148,7 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1156
1148
  ...initialInput,
1157
1149
  currency: convertCurrencyToGreenInvoice(initialInput.currency),
1158
1150
  type: getGreenInvoiceDocumentType(initialInput.type),
1159
- lang: getGreenInvoiceDocumentLanguage(initialInput.language),
1151
+ lang: getGreenInvoiceDocumentLanguage(initialInput.lang),
1160
1152
  vatType: getGreenInvoiceDocumentVatType(initialInput.vatType ?? 'DEFAULT'),
1161
1153
  discount: initialInput.discount
1162
1154
  ? {
@@ -1173,12 +1165,14 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1173
1165
  payment: initialInput.payment?.map(payment => ({
1174
1166
  ...payment,
1175
1167
  type: getGreenInvoiceDocumentPaymentType(payment.type),
1176
- subType: undefined,
1177
- appType: undefined,
1168
+ subType: payment.subType ? getGreenInvoiceDocumentPaymentSubType(payment.subType) : undefined,
1169
+ appType: payment.appType ? getGreenInvoiceDocumentPaymentAppType(payment.appType) : undefined,
1178
1170
  cardType: payment.cardType
1179
1171
  ? getGreenInvoiceDocumentPaymentCardType(payment.cardType)
1180
1172
  : undefined,
1181
- dealType: undefined,
1173
+ dealType: payment.dealType
1174
+ ? getGreenInvoiceDocumentPaymentDealType(payment.dealType)
1175
+ : undefined,
1182
1176
  currency: convertCurrencyToGreenInvoice(payment.currency),
1183
1177
  })),
1184
1178
  linkedDocumentIds: initialInput.linkedDocumentIds?.length
@@ -1189,31 +1183,32 @@ export async function convertDocumentInputIntoGreenInvoiceInput(initialInput, in
1189
1183
  : undefined,
1190
1184
  };
1191
1185
  }
1192
- export async function convertGreenInvoiceDocumentToDocumentDraft(greenInvoiceDocument, injector) {
1193
- const client = await (greenInvoiceDocument.client?.id
1194
- ? injector
1195
- .get(ClientsProvider)
1196
- .getClientByGreenInvoiceIdLoader.load(greenInvoiceDocument.client?.id)
1197
- : Promise.resolve(undefined));
1186
+ export function convertGreenInvoiceDocumentToLocalDocumentInfo(greenInvoiceDocument) {
1198
1187
  return {
1199
1188
  ...greenInvoiceDocument,
1200
- client,
1189
+ client: greenInvoiceDocument.client?.id,
1201
1190
  currency: greenInvoiceDocument.currency,
1202
1191
  income: greenInvoiceDocument.income?.filter(Boolean).map(income => ({
1203
1192
  ...income,
1204
1193
  currency: income.currency,
1205
1194
  vatType: getVatTypeFromGreenInvoiceDocument(income.vatType),
1206
1195
  })),
1207
- language: getLanguageFromGreenInvoiceDocument(greenInvoiceDocument.lang),
1196
+ lang: getLanguageFromGreenInvoiceDocument(greenInvoiceDocument.lang),
1208
1197
  payment: greenInvoiceDocument.payment?.filter(Boolean).map(payment => ({
1209
1198
  ...payment,
1210
- appType: undefined,
1199
+ appType: payment?.appType
1200
+ ? getPaymentAppTypeFromGreenInvoiceDocument(payment.appType)
1201
+ : undefined,
1211
1202
  cardType: payment?.cardType
1212
1203
  ? getCardTypeFromGreenInvoiceDocumentPayment(payment.cardType)
1213
1204
  : undefined,
1214
1205
  currency: payment.currency,
1215
- dealType: undefined,
1216
- subType: undefined,
1206
+ dealType: payment?.dealType
1207
+ ? getDealTypeFromGreenInvoiceDocumentPayment(payment.dealType)
1208
+ : undefined,
1209
+ subType: payment?.subType
1210
+ ? getSubTypeFromGreenInvoiceDocumentPayment(payment.subType)
1211
+ : undefined,
1217
1212
  type: getTypeFromGreenInvoiceDocumentPayment(payment.type),
1218
1213
  })),
1219
1214
  type: getTypeFromGreenInvoiceDocument(greenInvoiceDocument.type),