@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
@@ -3,13 +3,8 @@ import * as gm from "graphql-modules";
3
3
  export namespace DocumentsModule {
4
4
  interface DefinedFields {
5
5
  DocumentSuggestions: 'owner' | 'counterparty' | 'amount' | 'isIncome';
6
- Query: 'newDocumentDraftByCharge' | 'newDocumentDraftByDocument' | 'periodicalDocumentDrafts' | 'periodicalDocumentDraftsByContracts' | 'clientMonthlyChargeDraft' | 'documents' | 'documentsByFilters' | 'documentById' | 'recentDocumentsByBusiness' | 'recentDocumentsByClient' | 'recentIssuedDocumentsByType';
7
- Mutation: 'issueGreenInvoiceDocuments' | 'issueGreenInvoiceDocument' | 'previewDocument' | 'insertDocument' | 'updateDocument' | 'deleteDocument' | 'uploadDocument' | 'batchUploadDocuments' | 'batchUploadDocumentsFromGoogleDrive' | 'closeDocument';
8
- GenerateDocumentsResult: 'success' | 'errors';
9
- DocumentDraft: 'description' | 'remarks' | 'footer' | 'type' | 'date' | 'dueDate' | 'language' | 'currency' | 'vatType' | 'discount' | 'rounding' | 'signed' | 'maxPayments' | 'client' | 'income' | 'payment' | 'linkedDocumentIds' | 'linkedPaymentId' | 'linkType';
10
- DocumentIncomeRecord: 'currency' | 'currencyRate' | 'description' | 'itemId' | 'price' | 'quantity' | 'vatRate' | 'vatType';
11
- DocumentPaymentRecord: 'currency' | 'currencyRate' | 'date' | 'price' | 'type' | 'bankName' | 'bankBranch' | 'bankAccount' | 'chequeNum' | 'accountId' | 'transactionId' | 'cardType' | 'cardNum' | 'numPayments' | 'firstPayment';
12
- DocumentDiscount: 'amount' | 'type';
6
+ Query: 'documents' | 'documentsByFilters' | 'documentById' | 'recentDocumentsByBusiness' | 'recentDocumentsByClient' | 'recentIssuedDocumentsByType';
7
+ Mutation: 'insertDocument' | 'updateDocument' | 'deleteDocument' | 'uploadDocument' | 'batchUploadDocuments' | 'batchUploadDocumentsFromGoogleDrive' | 'closeDocument';
13
8
  Unprocessed: 'id' | 'image' | 'file' | 'documentType' | 'isReviewed';
14
9
  OtherDocument: 'id' | 'image' | 'file' | 'documentType' | 'isReviewed';
15
10
  Invoice: 'missingInfoSuggestions' | 'id' | 'image' | 'file' | 'vat' | 'documentType' | 'isReviewed' | 'serialNumber' | 'date' | 'amount' | 'vatReportDateOverride' | 'noVatAmount' | 'allocationNumber' | 'exchangeRateOverride' | 'issuedDocumentInfo';
@@ -39,22 +34,11 @@ export namespace DocumentsModule {
39
34
  };
40
35
 
41
36
  interface DefinedEnumValues {
42
- DocumentLanguage: 'ENGLISH' | 'HEBREW';
43
- DocumentVatType: 'DEFAULT' | 'EXEMPT' | 'MIXED';
44
- DocumentDiscountType: 'SUM' | 'PERCENTAGE';
45
- PaymentType: 'TAX_DEDUCTION' | 'CASH' | 'CHEQUE' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'PAYPAL' | 'OTHER_DEDUCTION' | 'PAYMENT_APP' | 'OTHER';
46
- DocumentLinkType: 'LINK' | 'CANCEL';
47
- DocumentPaymentRecordCardType: 'UNKNOWN' | 'ISRACARD' | 'VISA' | 'MASTERCARD' | 'AMERICAN_EXPRESS' | 'DINERS';
48
37
  DocumentType: 'INVOICE' | 'RECEIPT' | 'INVOICE_RECEIPT' | 'CREDIT_INVOICE' | 'PROFORMA' | 'UNPROCESSED' | 'OTHER';
49
38
  DocumentStatus: 'OPEN' | 'CLOSED' | 'MANUALLY_CLOSED' | 'CANCELLED_BY_OTHER_DOC' | 'CANCELLED';
50
39
  };
51
40
 
52
41
  interface DefinedInputFields {
53
- DocumentIssueInput: 'description' | 'remarks' | 'footer' | 'type' | 'date' | 'dueDate' | 'language' | 'currency' | 'vatType' | 'discount' | 'rounding' | 'signed' | 'maxPayments' | 'client' | 'income' | 'payment' | 'linkedDocumentIds' | 'linkedPaymentId' | 'linkType';
54
- DocumentDiscountInput: 'amount' | 'type';
55
- DocumentClientInput: 'country' | 'emails' | 'id' | 'name' | 'phone' | 'taxId' | 'self' | 'address' | 'city' | 'zip' | 'fax' | 'mobile' | 'add';
56
- DocumentIncomeRecordInput: 'amount' | 'amountTotal' | 'catalogNum' | 'currency' | 'currencyRate' | 'description' | 'itemId' | 'price' | 'quantity' | 'vat' | 'vatRate' | 'vatType';
57
- DocumentPaymentRecordInput: 'currency' | 'currencyRate' | 'date' | 'price' | 'type' | 'bankName' | 'bankBranch' | 'bankAccount' | 'chequeNum' | 'accountId' | 'transactionId' | 'cardType' | 'cardNum' | 'numPayments' | 'firstPayment';
58
42
  DocumentsFilters: 'businessIDs' | 'ownerIDs' | 'fromDate' | 'toDate' | 'unmatched';
59
43
  UpdateDocumentFieldsInput: 'vat' | 'serialNumber' | 'date' | 'amount' | 'documentType' | 'image' | 'file' | 'chargeId' | 'creditorId' | 'debtorId' | 'vatReportDateOverride' | 'noVatAmount' | 'allocationNumber' | 'exchangeRateOverride';
60
44
  InsertDocumentInput: 'image' | 'file' | 'vat' | 'documentType' | 'serialNumber' | 'date' | 'amount' | 'chargeId' | 'creditorId' | 'debtorId' | 'vatReportDateOverride' | 'noVatAmount' | 'allocationNumber' | 'exchangeRateOverride';
@@ -70,38 +54,18 @@ export namespace DocumentsModule {
70
54
  export type FinancialEntity = Types.FinancialEntity;
71
55
  export type FinancialAmount = Types.FinancialAmount;
72
56
  export type Query = Pick<Types.Query, DefinedFields['Query']>;
73
- export type DocumentDraft = Pick<Types.DocumentDraft, DefinedFields['DocumentDraft']>;
57
+ export type Document = Pick<Types.Document, DefinedFields['Document']>;
58
+ export type DocumentsFilters = Pick<Types.DocumentsFilters, DefinedInputFields['DocumentsFilters']>;
74
59
  export type UUID = Types.Uuid;
60
+ export type DocumentType = DefinedEnumValues['DocumentType'];
75
61
  export type TimelessDate = Types.TimelessDate;
76
62
  export type Mutation = Pick<Types.Mutation, DefinedFields['Mutation']>;
77
- export type GenerateDocumentsResult = Pick<Types.GenerateDocumentsResult, DefinedFields['GenerateDocumentsResult']>;
78
- export type DocumentIssueInput = Pick<Types.DocumentIssueInput, DefinedInputFields['DocumentIssueInput']>;
79
- export type Charge = Types.Charge;
80
- export type FileScalar = Types.FileScalar;
81
- export type DocumentType = DefinedEnumValues['DocumentType'];
82
- export type DocumentLanguage = DefinedEnumValues['DocumentLanguage'];
83
- export type Currency = Types.Currency;
84
- export type DocumentVatType = DefinedEnumValues['DocumentVatType'];
85
- export type DocumentDiscount = Pick<Types.DocumentDiscount, DefinedFields['DocumentDiscount']>;
86
- export type Client = Types.Client;
87
- export type DocumentIncomeRecord = Pick<Types.DocumentIncomeRecord, DefinedFields['DocumentIncomeRecord']>;
88
- export type DocumentPaymentRecord = Pick<Types.DocumentPaymentRecord, DefinedFields['DocumentPaymentRecord']>;
89
- export type DocumentLinkType = DefinedEnumValues['DocumentLinkType'];
90
- export type PaymentType = DefinedEnumValues['PaymentType'];
91
- export type DocumentPaymentRecordCardType = DefinedEnumValues['DocumentPaymentRecordCardType'];
92
- export type DocumentDiscountType = DefinedEnumValues['DocumentDiscountType'];
93
- export type DocumentDiscountInput = Pick<Types.DocumentDiscountInput, DefinedInputFields['DocumentDiscountInput']>;
94
- export type DocumentClientInput = Pick<Types.DocumentClientInput, DefinedInputFields['DocumentClientInput']>;
95
- export type DocumentIncomeRecordInput = Pick<Types.DocumentIncomeRecordInput, DefinedInputFields['DocumentIncomeRecordInput']>;
96
- export type DocumentPaymentRecordInput = Pick<Types.DocumentPaymentRecordInput, DefinedInputFields['DocumentPaymentRecordInput']>;
97
- export type CountryCode = Types.CountryCode;
98
- export type Document = Pick<Types.Document, DefinedFields['Document']>;
99
- export type DocumentsFilters = Pick<Types.DocumentsFilters, DefinedInputFields['DocumentsFilters']>;
100
63
  export type InsertDocumentResult = Types.InsertDocumentResult;
101
64
  export type InsertDocumentInput = Pick<Types.InsertDocumentInput, DefinedInputFields['InsertDocumentInput']>;
102
65
  export type UpdateDocumentResult = Types.UpdateDocumentResult;
103
66
  export type UpdateDocumentFieldsInput = Pick<Types.UpdateDocumentFieldsInput, DefinedInputFields['UpdateDocumentFieldsInput']>;
104
67
  export type UploadDocumentResult = Types.UploadDocumentResult;
68
+ export type FileScalar = Types.FileScalar;
105
69
  export type Linkable = Pick<Types.Linkable, DefinedFields['Linkable']>;
106
70
  export type URL = Types.Url;
107
71
  export type Unprocessed = Pick<Types.Unprocessed, DefinedFields['Unprocessed']>;
@@ -111,6 +75,7 @@ export namespace DocumentsModule {
111
75
  export type CommonError = Types.CommonError;
112
76
  export type InsertDocumentSuccessfulResult = Pick<Types.InsertDocumentSuccessfulResult, DefinedFields['InsertDocumentSuccessfulResult']>;
113
77
  export type UploadDocumentSuccessfulResult = Pick<Types.UploadDocumentSuccessfulResult, DefinedFields['UploadDocumentSuccessfulResult']>;
78
+ export type Charge = Types.Charge;
114
79
  export type CommonCharge = Types.CommonCharge;
115
80
  export type FinancialCharge = Types.FinancialCharge;
116
81
  export type ConversionCharge = Types.ConversionCharge;
@@ -128,11 +93,6 @@ export namespace DocumentsModule {
128
93
  export type DocumentSuggestionsResolvers = Pick<Types.DocumentSuggestionsResolvers, DefinedFields['DocumentSuggestions']>;
129
94
  export type QueryResolvers = Pick<Types.QueryResolvers, DefinedFields['Query']>;
130
95
  export type MutationResolvers = Pick<Types.MutationResolvers, DefinedFields['Mutation']>;
131
- export type GenerateDocumentsResultResolvers = Pick<Types.GenerateDocumentsResultResolvers, DefinedFields['GenerateDocumentsResult']>;
132
- export type DocumentDraftResolvers = Pick<Types.DocumentDraftResolvers, DefinedFields['DocumentDraft']>;
133
- export type DocumentIncomeRecordResolvers = Pick<Types.DocumentIncomeRecordResolvers, DefinedFields['DocumentIncomeRecord']>;
134
- export type DocumentPaymentRecordResolvers = Pick<Types.DocumentPaymentRecordResolvers, DefinedFields['DocumentPaymentRecord']>;
135
- export type DocumentDiscountResolvers = Pick<Types.DocumentDiscountResolvers, DefinedFields['DocumentDiscount']>;
136
96
  export type UnprocessedResolvers = Pick<Types.UnprocessedResolvers, DefinedFields['Unprocessed'] | '__isTypeOf'>;
137
97
  export type OtherDocumentResolvers = Pick<Types.OtherDocumentResolvers, DefinedFields['OtherDocument'] | '__isTypeOf'>;
138
98
  export type InvoiceResolvers = Pick<Types.InvoiceResolvers, DefinedFields['Invoice'] | '__isTypeOf'>;
@@ -164,11 +124,6 @@ export namespace DocumentsModule {
164
124
  DocumentSuggestions?: DocumentSuggestionsResolvers;
165
125
  Query?: QueryResolvers;
166
126
  Mutation?: MutationResolvers;
167
- GenerateDocumentsResult?: GenerateDocumentsResultResolvers;
168
- DocumentDraft?: DocumentDraftResolvers;
169
- DocumentIncomeRecord?: DocumentIncomeRecordResolvers;
170
- DocumentPaymentRecord?: DocumentPaymentRecordResolvers;
171
- DocumentDiscount?: DocumentDiscountResolvers;
172
127
  Unprocessed?: UnprocessedResolvers;
173
128
  OtherDocument?: OtherDocumentResolvers;
174
129
  Invoice?: InvoiceResolvers;
@@ -296,11 +251,6 @@ export namespace DocumentsModule {
296
251
  };
297
252
  Query?: {
298
253
  '*'?: gm.Middleware[];
299
- newDocumentDraftByCharge?: gm.Middleware[];
300
- newDocumentDraftByDocument?: gm.Middleware[];
301
- periodicalDocumentDrafts?: gm.Middleware[];
302
- periodicalDocumentDraftsByContracts?: gm.Middleware[];
303
- clientMonthlyChargeDraft?: gm.Middleware[];
304
254
  documents?: gm.Middleware[];
305
255
  documentsByFilters?: gm.Middleware[];
306
256
  documentById?: gm.Middleware[];
@@ -310,9 +260,6 @@ export namespace DocumentsModule {
310
260
  };
311
261
  Mutation?: {
312
262
  '*'?: gm.Middleware[];
313
- issueGreenInvoiceDocuments?: gm.Middleware[];
314
- issueGreenInvoiceDocument?: gm.Middleware[];
315
- previewDocument?: gm.Middleware[];
316
263
  insertDocument?: gm.Middleware[];
317
264
  updateDocument?: gm.Middleware[];
318
265
  deleteDocument?: gm.Middleware[];
@@ -321,67 +268,6 @@ export namespace DocumentsModule {
321
268
  batchUploadDocumentsFromGoogleDrive?: gm.Middleware[];
322
269
  closeDocument?: gm.Middleware[];
323
270
  };
324
- GenerateDocumentsResult?: {
325
- '*'?: gm.Middleware[];
326
- success?: gm.Middleware[];
327
- errors?: gm.Middleware[];
328
- };
329
- DocumentDraft?: {
330
- '*'?: gm.Middleware[];
331
- description?: gm.Middleware[];
332
- remarks?: gm.Middleware[];
333
- footer?: gm.Middleware[];
334
- type?: gm.Middleware[];
335
- date?: gm.Middleware[];
336
- dueDate?: gm.Middleware[];
337
- language?: gm.Middleware[];
338
- currency?: gm.Middleware[];
339
- vatType?: gm.Middleware[];
340
- discount?: gm.Middleware[];
341
- rounding?: gm.Middleware[];
342
- signed?: gm.Middleware[];
343
- maxPayments?: gm.Middleware[];
344
- client?: gm.Middleware[];
345
- income?: gm.Middleware[];
346
- payment?: gm.Middleware[];
347
- linkedDocumentIds?: gm.Middleware[];
348
- linkedPaymentId?: gm.Middleware[];
349
- linkType?: gm.Middleware[];
350
- };
351
- DocumentIncomeRecord?: {
352
- '*'?: gm.Middleware[];
353
- currency?: gm.Middleware[];
354
- currencyRate?: gm.Middleware[];
355
- description?: gm.Middleware[];
356
- itemId?: gm.Middleware[];
357
- price?: gm.Middleware[];
358
- quantity?: gm.Middleware[];
359
- vatRate?: gm.Middleware[];
360
- vatType?: gm.Middleware[];
361
- };
362
- DocumentPaymentRecord?: {
363
- '*'?: gm.Middleware[];
364
- currency?: gm.Middleware[];
365
- currencyRate?: gm.Middleware[];
366
- date?: gm.Middleware[];
367
- price?: gm.Middleware[];
368
- type?: gm.Middleware[];
369
- bankName?: gm.Middleware[];
370
- bankBranch?: gm.Middleware[];
371
- bankAccount?: gm.Middleware[];
372
- chequeNum?: gm.Middleware[];
373
- accountId?: gm.Middleware[];
374
- transactionId?: gm.Middleware[];
375
- cardType?: gm.Middleware[];
376
- cardNum?: gm.Middleware[];
377
- numPayments?: gm.Middleware[];
378
- firstPayment?: gm.Middleware[];
379
- };
380
- DocumentDiscount?: {
381
- '*'?: gm.Middleware[];
382
- amount?: gm.Middleware[];
383
- type?: gm.Middleware[];
384
- };
385
271
  Unprocessed?: {
386
272
  '*'?: gm.Middleware[];
387
273
  id?: gm.Middleware[];
@@ -12,24 +12,3 @@ export function isInvoice(type: document_type): boolean {
12
12
  export function isReceipt(type: document_type): boolean {
13
13
  return type === DocumentType.Receipt || type === DocumentType.InvoiceReceipt;
14
14
  }
15
-
16
- export function getDocumentNameFromType(documentType: DocumentType): string {
17
- switch (documentType) {
18
- case DocumentType.Invoice:
19
- return 'Tax Invoice';
20
- case DocumentType.Proforma:
21
- return 'Proforma Invoice';
22
- case DocumentType.InvoiceReceipt:
23
- return 'Invoice / Receipt';
24
- case DocumentType.CreditInvoice:
25
- return 'Credit Note';
26
- case DocumentType.Receipt:
27
- return 'Receipt';
28
- case DocumentType.Other:
29
- return 'Misc Document';
30
- case DocumentType.Unprocessed:
31
- return 'Unprocessed Document';
32
- default:
33
- throw new Error(`Unsupported document type: ${documentType}`);
34
- }
35
- }
@@ -2,11 +2,9 @@ import { createModule } from 'graphql-modules';
2
2
  import { DocumentsProvider } from './providers/documents.provider.js';
3
3
  import { IssuedDocumentsProvider } from './providers/issued-documents.provider.js';
4
4
  import { documentSuggestionsResolvers } from './resolvers/document-suggestions.resolver.js';
5
- import { documentsIssuingResolvers } from './resolvers/documents-issuing.resolver.js';
6
5
  import { documentsResolvers } from './resolvers/documents.resolver.js';
7
6
  import { issuedDocumentsResolvers } from './resolvers/issued-documents.resolver.js';
8
7
  import documentSuggestions from './typeDefs/document-suggestions.graphql.js';
9
- import DocumentsIssuing from './typeDefs/documents-issuing.graphql.js';
10
8
  import documents from './typeDefs/documents.graphql.js';
11
9
  import issuedDocuments from './typeDefs/issued-documents.graphql.js';
12
10
 
@@ -15,13 +13,8 @@ const __dirname = new URL('.', import.meta.url).pathname;
15
13
  export const documentsModule = createModule({
16
14
  id: 'documents',
17
15
  dirname: __dirname,
18
- typeDefs: [documents, documentSuggestions, DocumentsIssuing, issuedDocuments],
19
- resolvers: [
20
- documentsResolvers,
21
- documentSuggestionsResolvers,
22
- documentsIssuingResolvers,
23
- issuedDocumentsResolvers,
24
- ],
16
+ typeDefs: [documents, documentSuggestions, issuedDocuments],
17
+ resolvers: [documentsResolvers, documentSuggestionsResolvers, issuedDocumentsResolvers],
25
18
  providers: () => [DocumentsProvider, IssuedDocumentsProvider],
26
19
  });
27
20
 
@@ -2,33 +2,92 @@ import * as Types from "../../../__generated__/types.js";
2
2
  import * as gm from "graphql-modules";
3
3
  export namespace GreenInvoiceModule {
4
4
  interface DefinedFields {
5
- Query: 'greenInvoiceClient';
6
- Mutation: 'syncGreenInvoiceDocuments';
5
+ Query: 'newDocumentInfoDraftByCharge' | 'newDocumentInfoDraftByDocument' | 'clientMonthlyChargesDrafts' | 'clientChargesDraftsByContracts' | 'clientMonthlyChargeDraft' | 'greenInvoiceClient';
6
+ Mutation: 'fetchIncomeDocuments' | 'issueGreenInvoiceDocuments' | 'previewGreenInvoiceDocument' | 'issueGreenInvoiceDocument';
7
+ GenerateMonthlyClientDocumentsResult: 'success' | 'errors';
8
+ NewDocumentInfo: 'description' | 'remarks' | 'footer' | 'type' | 'date' | 'dueDate' | 'lang' | 'currency' | 'vatType' | 'discount' | 'rounding' | 'signed' | 'maxPayments' | 'client' | 'income' | 'payment' | 'linkedDocumentIds' | 'linkedPaymentId' | 'linkType';
9
+ GreenInvoiceDiscount: 'amount' | 'type';
7
10
  GreenInvoiceClient: 'country' | 'emails' | 'greenInvoiceId' | 'businessId' | 'name' | 'phone' | 'taxId' | 'self' | 'address' | 'city' | 'zip' | 'fax' | 'mobile' | 'add';
11
+ GreenInvoiceIncome: 'currency' | 'currencyRate' | 'description' | 'itemId' | 'price' | 'quantity' | 'vatRate' | 'vatType';
12
+ GreenInvoicePayment: 'currency' | 'currencyRate' | 'date' | 'price' | 'type' | 'subType' | 'bankName' | 'bankBranch' | 'bankAccount' | 'chequeNum' | 'accountId' | 'transactionId' | 'appType' | 'cardType' | 'cardNum' | 'dealType' | 'numPayments' | 'firstPayment';
8
13
  IssuedDocumentInfo: 'originalDocument';
9
14
  ClientIntegrations: 'greenInvoiceInfo';
10
15
  };
11
16
 
17
+ interface DefinedEnumValues {
18
+ GreenInvoiceDocumentLang: 'ENGLISH' | 'HEBREW';
19
+ GreenInvoiceVatType: 'DEFAULT' | 'EXEMPT' | 'MIXED';
20
+ GreenInvoiceDiscountType: 'SUM' | 'PERCENTAGE';
21
+ GreenInvoiceCountry: 'UG' | 'UZ' | 'AT' | 'AU' | 'UA' | 'UY' | 'AZ' | 'CX' | 'AE' | 'IT' | 'BS' | 'GS' | 'UM' | 'VI' | 'VG' | 'HM' | 'TC' | 'MP' | 'MH' | 'SB' | 'FO' | 'FK' | 'FJ' | 'KM' | 'CK' | 'CC' | 'KY' | 'ID' | 'IS' | 'IE' | 'IR' | 'SV' | 'AL' | 'DZ' | 'AX' | 'AO' | 'AI' | 'AD' | 'AQ' | 'AG' | 'EE' | 'AF' | 'EC' | 'AR' | 'US' | 'AW' | 'ER' | 'AM' | 'ET' | 'BT' | 'BV' | 'BW' | 'BG' | 'BO' | 'BA' | 'BI' | 'BF' | 'BH' | 'BY' | 'BE' | 'BZ' | 'BD' | 'BJ' | 'BB' | 'BN' | 'BR' | 'GB' | 'BM' | 'DJ' | 'JM' | 'JE' | 'GA' | 'GE' | 'GH' | 'GT' | 'GU' | 'GP' | 'GY' | 'GI' | 'GN' | 'GW' | 'GQ' | 'GF' | 'GM' | 'GL' | 'DE' | 'GD' | 'GG' | 'DM' | 'DK' | 'ZA' | 'SS' | 'KR' | 'IM' | 'NF' | 'HT' | 'MV' | 'BQ' | 'IN' | 'NL' | 'HK' | 'HU' | 'HN' | 'IO' | 'TF' | 'PH' | 'DO' | 'CD' | 'CF' | 'PS' | 'WF' | 'VN' | 'VU' | 'VE' | 'VA' | 'ZW' | 'ZM' | 'CI' | 'TJ' | 'TV' | 'TG' | 'TO' | 'TN' | 'TK' | 'TR' | 'TM' | 'TW' | 'TZ' | 'TT' | 'GR' | 'JP' | 'JO' | 'IL' | 'KW' | 'CV' | 'LA' | 'LB' | 'LY' | 'LU' | 'LV' | 'LR' | 'LT' | 'LI' | 'LS' | 'MR' | 'MU' | 'ML' | 'MG' | 'MZ' | 'MD' | 'MN' | 'ME' | 'MS' | 'MC' | 'TL' | 'MM' | 'YT' | 'FM' | 'MW' | 'MY' | 'MT' | 'EG' | 'MO' | 'MK' | 'MX' | 'MA' | 'MQ' | 'NR' | 'NO' | 'NG' | 'NZ' | 'NU' | 'NE' | 'NI' | 'NA' | 'NP' | 'ST' | 'SJ' | 'EH' | 'SD' | 'SZ' | 'SO' | 'SY' | 'SR' | 'SL' | 'SC' | 'CN' | 'SG' | 'SI' | 'SK' | 'WS' | 'AS' | 'BL' | 'MF' | 'SM' | 'PM' | 'SN' | 'SH' | 'VC' | 'LC' | 'SX' | 'KN' | 'SA' | 'ES' | 'RS' | 'LK' | 'OM' | 'IQ' | 'PW' | 'PL' | 'PF' | 'PR' | 'PT' | 'PN' | 'FI' | 'PA' | 'PG' | 'PK' | 'PY' | 'PE' | 'TD' | 'CL' | 'CZ' | 'KP' | 'FR' | 'CU' | 'CO' | 'CG' | 'XK' | 'CR' | 'CW' | 'KZ' | 'QA' | 'KG' | 'KI' | 'NC' | 'KH' | 'CM' | 'CA' | 'KE' | 'CY' | 'HR' | 'RE' | 'RW' | 'RO' | 'RU' | 'SE' | 'CH' | 'TH' | 'YE';
22
+ GreenInvoicePaymentSubType: 'BITCOIN' | 'MONEY_EQUAL' | 'V_CHECK' | 'GIFT_CARD' | 'NII_EMPLOYEE_DEDUCTION' | 'ETHEREUM' | 'BUYME_VOUCHER' | 'PAYONEER';
23
+ GreenInvoicePaymentAppType: 'BIT' | 'PAY_BY_PEPPER' | 'PAYBOX' | 'CULO' | 'GOOGLE_PAY' | 'APPLE_PAY';
24
+ GreenInvoicePaymentCardType: 'UNKNOWN' | 'ISRACARD' | 'VISA' | 'MASTERCARD' | 'AMERICAN_EXPRESS' | 'DINERS';
25
+ GreenInvoicePaymentDealType: 'STANDARD' | 'PAYMENTS' | 'CREDIT' | 'DEFERRED' | 'OTHER' | 'RECURRING';
26
+ GreenInvoicePaymentType: 'TAX_DEDUCTION' | 'CASH' | 'CHEQUE' | 'CREDIT_CARD' | 'WIRE_TRANSFER' | 'PAYPAL' | 'OTHER_DEDUCTION' | 'PAYMENT_APP' | 'OTHER';
27
+ GreenInvoiceLinkType: 'LINK' | 'CANCEL';
28
+ };
29
+
30
+ interface DefinedInputFields {
31
+ NewDocumentInput: 'description' | 'remarks' | 'footer' | 'type' | 'date' | 'dueDate' | 'lang' | 'currency' | 'vatType' | 'discount' | 'rounding' | 'signed' | 'maxPayments' | 'client' | 'income' | 'payment' | 'linkedDocumentIds' | 'linkedPaymentId' | 'linkType';
32
+ GreenInvoiceDiscountInput: 'amount' | 'type';
33
+ GreenInvoiceClientInput: 'country' | 'emails' | 'greenInvoiceId' | 'businessId' | 'name' | 'phone' | 'taxId' | 'self' | 'address' | 'city' | 'zip' | 'fax' | 'mobile' | 'add';
34
+ GreenInvoicePaymentIncomeInput: 'amount' | 'amountTotal' | 'catalogNum' | 'currency' | 'currencyRate' | 'description' | 'itemId' | 'price' | 'quantity' | 'vat' | 'vatRate' | 'vatType';
35
+ GreenInvoicePaymentInput: 'currency' | 'currencyRate' | 'date' | 'price' | 'type' | 'subType' | 'bankName' | 'bankBranch' | 'bankAccount' | 'chequeNum' | 'accountId' | 'transactionId' | 'appType' | 'cardType' | 'cardNum' | 'dealType' | 'numPayments' | 'firstPayment';
36
+ };
37
+
12
38
  export type Query = Pick<Types.Query, DefinedFields['Query']>;
13
- export type GreenInvoiceClient = Pick<Types.GreenInvoiceClient, DefinedFields['GreenInvoiceClient']>;
39
+ export type NewDocumentInfo = Pick<Types.NewDocumentInfo, DefinedFields['NewDocumentInfo']>;
14
40
  export type UUID = Types.Uuid;
41
+ export type TimelessDate = Types.TimelessDate;
42
+ export type GreenInvoiceClient = Pick<Types.GreenInvoiceClient, DefinedFields['GreenInvoiceClient']>;
15
43
  export type Mutation = Pick<Types.Mutation, DefinedFields['Mutation']>;
16
44
  export type Document = Types.Document;
45
+ export type GenerateMonthlyClientDocumentsResult = Pick<Types.GenerateMonthlyClientDocumentsResult, DefinedFields['GenerateMonthlyClientDocumentsResult']>;
46
+ export type NewDocumentInput = Pick<Types.NewDocumentInput, DefinedInputFields['NewDocumentInput']>;
47
+ export type FileScalar = Types.FileScalar;
48
+ export type Charge = Types.Charge;
17
49
  export type IssuedDocumentInfo = Types.IssuedDocumentInfo;
18
- export type DocumentDraft = Types.DocumentDraft;
19
50
  export type ClientIntegrations = Types.ClientIntegrations;
20
- export type Country = Types.Country;
51
+ export type DocumentType = Types.DocumentType;
52
+ export type GreenInvoiceDocumentLang = DefinedEnumValues['GreenInvoiceDocumentLang'];
53
+ export type Currency = Types.Currency;
54
+ export type GreenInvoiceVatType = DefinedEnumValues['GreenInvoiceVatType'];
55
+ export type GreenInvoiceDiscount = Pick<Types.GreenInvoiceDiscount, DefinedFields['GreenInvoiceDiscount']>;
56
+ export type GreenInvoiceIncome = Pick<Types.GreenInvoiceIncome, DefinedFields['GreenInvoiceIncome']>;
57
+ export type GreenInvoicePayment = Pick<Types.GreenInvoicePayment, DefinedFields['GreenInvoicePayment']>;
58
+ export type GreenInvoiceLinkType = DefinedEnumValues['GreenInvoiceLinkType'];
59
+ export type GreenInvoiceDiscountType = DefinedEnumValues['GreenInvoiceDiscountType'];
60
+ export type GreenInvoiceCountry = DefinedEnumValues['GreenInvoiceCountry'];
61
+ export type GreenInvoicePaymentType = DefinedEnumValues['GreenInvoicePaymentType'];
62
+ export type GreenInvoicePaymentSubType = DefinedEnumValues['GreenInvoicePaymentSubType'];
63
+ export type GreenInvoicePaymentAppType = DefinedEnumValues['GreenInvoicePaymentAppType'];
64
+ export type GreenInvoicePaymentCardType = DefinedEnumValues['GreenInvoicePaymentCardType'];
65
+ export type GreenInvoicePaymentDealType = DefinedEnumValues['GreenInvoicePaymentDealType'];
66
+ export type GreenInvoiceDiscountInput = Pick<Types.GreenInvoiceDiscountInput, DefinedInputFields['GreenInvoiceDiscountInput']>;
67
+ export type GreenInvoiceClientInput = Pick<Types.GreenInvoiceClientInput, DefinedInputFields['GreenInvoiceClientInput']>;
68
+ export type GreenInvoicePaymentIncomeInput = Pick<Types.GreenInvoicePaymentIncomeInput, DefinedInputFields['GreenInvoicePaymentIncomeInput']>;
69
+ export type GreenInvoicePaymentInput = Pick<Types.GreenInvoicePaymentInput, DefinedInputFields['GreenInvoicePaymentInput']>;
21
70
 
22
71
  export type QueryResolvers = Pick<Types.QueryResolvers, DefinedFields['Query']>;
23
72
  export type MutationResolvers = Pick<Types.MutationResolvers, DefinedFields['Mutation']>;
73
+ export type GenerateMonthlyClientDocumentsResultResolvers = Pick<Types.GenerateMonthlyClientDocumentsResultResolvers, DefinedFields['GenerateMonthlyClientDocumentsResult']>;
74
+ export type NewDocumentInfoResolvers = Pick<Types.NewDocumentInfoResolvers, DefinedFields['NewDocumentInfo']>;
75
+ export type GreenInvoiceDiscountResolvers = Pick<Types.GreenInvoiceDiscountResolvers, DefinedFields['GreenInvoiceDiscount']>;
24
76
  export type GreenInvoiceClientResolvers = Pick<Types.GreenInvoiceClientResolvers, DefinedFields['GreenInvoiceClient']>;
77
+ export type GreenInvoiceIncomeResolvers = Pick<Types.GreenInvoiceIncomeResolvers, DefinedFields['GreenInvoiceIncome']>;
78
+ export type GreenInvoicePaymentResolvers = Pick<Types.GreenInvoicePaymentResolvers, DefinedFields['GreenInvoicePayment']>;
25
79
  export type IssuedDocumentInfoResolvers = Pick<Types.IssuedDocumentInfoResolvers, DefinedFields['IssuedDocumentInfo']>;
26
80
  export type ClientIntegrationsResolvers = Pick<Types.ClientIntegrationsResolvers, DefinedFields['ClientIntegrations']>;
27
81
 
28
82
  export interface Resolvers {
29
83
  Query?: QueryResolvers;
30
84
  Mutation?: MutationResolvers;
85
+ GenerateMonthlyClientDocumentsResult?: GenerateMonthlyClientDocumentsResultResolvers;
86
+ NewDocumentInfo?: NewDocumentInfoResolvers;
87
+ GreenInvoiceDiscount?: GreenInvoiceDiscountResolvers;
31
88
  GreenInvoiceClient?: GreenInvoiceClientResolvers;
89
+ GreenInvoiceIncome?: GreenInvoiceIncomeResolvers;
90
+ GreenInvoicePayment?: GreenInvoicePaymentResolvers;
32
91
  IssuedDocumentInfo?: IssuedDocumentInfoResolvers;
33
92
  ClientIntegrations?: ClientIntegrationsResolvers;
34
93
  };
@@ -39,11 +98,19 @@ export namespace GreenInvoiceModule {
39
98
  };
40
99
  Query?: {
41
100
  '*'?: gm.Middleware[];
101
+ newDocumentInfoDraftByCharge?: gm.Middleware[];
102
+ newDocumentInfoDraftByDocument?: gm.Middleware[];
103
+ clientMonthlyChargesDrafts?: gm.Middleware[];
104
+ clientChargesDraftsByContracts?: gm.Middleware[];
105
+ clientMonthlyChargeDraft?: gm.Middleware[];
42
106
  greenInvoiceClient?: gm.Middleware[];
43
107
  };
44
108
  Mutation?: {
45
109
  '*'?: gm.Middleware[];
46
- syncGreenInvoiceDocuments?: gm.Middleware[];
110
+ fetchIncomeDocuments?: gm.Middleware[];
111
+ issueGreenInvoiceDocuments?: gm.Middleware[];
112
+ previewGreenInvoiceDocument?: gm.Middleware[];
113
+ issueGreenInvoiceDocument?: gm.Middleware[];
47
114
  };
48
115
  IssuedDocumentInfo?: {
49
116
  '*'?: gm.Middleware[];
@@ -53,6 +120,38 @@ export namespace GreenInvoiceModule {
53
120
  '*'?: gm.Middleware[];
54
121
  greenInvoiceInfo?: gm.Middleware[];
55
122
  };
123
+ GenerateMonthlyClientDocumentsResult?: {
124
+ '*'?: gm.Middleware[];
125
+ success?: gm.Middleware[];
126
+ errors?: gm.Middleware[];
127
+ };
128
+ NewDocumentInfo?: {
129
+ '*'?: gm.Middleware[];
130
+ description?: gm.Middleware[];
131
+ remarks?: gm.Middleware[];
132
+ footer?: gm.Middleware[];
133
+ type?: gm.Middleware[];
134
+ date?: gm.Middleware[];
135
+ dueDate?: gm.Middleware[];
136
+ lang?: gm.Middleware[];
137
+ currency?: gm.Middleware[];
138
+ vatType?: gm.Middleware[];
139
+ discount?: gm.Middleware[];
140
+ rounding?: gm.Middleware[];
141
+ signed?: gm.Middleware[];
142
+ maxPayments?: gm.Middleware[];
143
+ client?: gm.Middleware[];
144
+ income?: gm.Middleware[];
145
+ payment?: gm.Middleware[];
146
+ linkedDocumentIds?: gm.Middleware[];
147
+ linkedPaymentId?: gm.Middleware[];
148
+ linkType?: gm.Middleware[];
149
+ };
150
+ GreenInvoiceDiscount?: {
151
+ '*'?: gm.Middleware[];
152
+ amount?: gm.Middleware[];
153
+ type?: gm.Middleware[];
154
+ };
56
155
  GreenInvoiceClient?: {
57
156
  '*'?: gm.Middleware[];
58
157
  country?: gm.Middleware[];
@@ -70,5 +169,37 @@ export namespace GreenInvoiceModule {
70
169
  mobile?: gm.Middleware[];
71
170
  add?: gm.Middleware[];
72
171
  };
172
+ GreenInvoiceIncome?: {
173
+ '*'?: gm.Middleware[];
174
+ currency?: gm.Middleware[];
175
+ currencyRate?: gm.Middleware[];
176
+ description?: gm.Middleware[];
177
+ itemId?: gm.Middleware[];
178
+ price?: gm.Middleware[];
179
+ quantity?: gm.Middleware[];
180
+ vatRate?: gm.Middleware[];
181
+ vatType?: gm.Middleware[];
182
+ };
183
+ GreenInvoicePayment?: {
184
+ '*'?: gm.Middleware[];
185
+ currency?: gm.Middleware[];
186
+ currencyRate?: gm.Middleware[];
187
+ date?: gm.Middleware[];
188
+ price?: gm.Middleware[];
189
+ type?: gm.Middleware[];
190
+ subType?: gm.Middleware[];
191
+ bankName?: gm.Middleware[];
192
+ bankBranch?: gm.Middleware[];
193
+ bankAccount?: gm.Middleware[];
194
+ chequeNum?: gm.Middleware[];
195
+ accountId?: gm.Middleware[];
196
+ transactionId?: gm.Middleware[];
197
+ appType?: gm.Middleware[];
198
+ cardType?: gm.Middleware[];
199
+ cardNum?: gm.Middleware[];
200
+ dealType?: gm.Middleware[];
201
+ numPayments?: gm.Middleware[];
202
+ firstPayment?: gm.Middleware[];
203
+ };
73
204
  };
74
205
  }
@@ -0,0 +1,69 @@
1
+ import { addMonths, endOfMonth, format, startOfMonth, subMonths } from 'date-fns';
2
+ import { GraphQLError } from 'graphql';
3
+ import type { Injector } from 'graphql-modules';
4
+ import type { NewDocumentInfo } from '../../../__generated__/types.js';
5
+ import { Currency } from '../../../shared/enums.js';
6
+ import { dateToTimelessDateString } from '../../../shared/helpers/index.js';
7
+ import type { TimelessDateString } from '../../../shared/types/index.js';
8
+ import type { IGetContractsByIdsResult } from '../../contracts/types.js';
9
+ import { normalizeDocumentType } from '../../documents/resolvers/common.js';
10
+ import { validateClientIntegrations } from '../../financial-entities/helpers/clients.helper.js';
11
+ import { BusinessesProvider } from '../../financial-entities/providers/businesses.provider.js';
12
+ import { ClientsProvider } from '../../financial-entities/providers/clients.provider.js';
13
+
14
+ export const convertContractToDraft = async (
15
+ contract: IGetContractsByIdsResult,
16
+ injector: Injector,
17
+ issueMonth: TimelessDateString,
18
+ ) => {
19
+ const businessPromise = injector
20
+ .get(BusinessesProvider)
21
+ .getBusinessByIdLoader.load(contract.client_id);
22
+ const clientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(contract.client_id);
23
+ const [business, client] = await Promise.all([businessPromise, clientPromise]);
24
+
25
+ if (!business) {
26
+ throw new GraphQLError(`Business ID="${contract.client_id}" not found`);
27
+ }
28
+
29
+ if (!client) {
30
+ throw new GraphQLError(`Client not found for business ID="${contract.client_id}"`);
31
+ }
32
+
33
+ const greenInvoiceId = validateClientIntegrations(client.integrations)?.greenInvoiceId;
34
+
35
+ if (!greenInvoiceId) {
36
+ throw new GraphQLError(`Green invoice match not found for business ID="${contract.client_id}"`);
37
+ }
38
+
39
+ const today = issueMonth ? addMonths(new Date(issueMonth), 1) : new Date();
40
+ const monthStart = dateToTimelessDateString(startOfMonth(today));
41
+ const monthEnd = dateToTimelessDateString(endOfMonth(today));
42
+ const year = today.getFullYear() + (today.getMonth() === 0 ? -1 : 0);
43
+ const month = format(subMonths(today, 1), 'MMMM');
44
+
45
+ const documentInput: Omit<NewDocumentInfo, 'client'> & { client: string | undefined } = {
46
+ remarks: `${contract.purchase_orders[0] ? `PO: ${contract.purchase_orders[0]}${contract.remarks ? ', ' : ''}` : ''}${contract.remarks ?? ''}`,
47
+ description: `GraphQL Hive Enterprise License - ${month} ${year}`,
48
+ type: normalizeDocumentType(contract.document_type),
49
+ date: monthStart,
50
+ dueDate: monthEnd,
51
+ lang: 'ENGLISH',
52
+ currency: contract.currency as Currency,
53
+ vatType: 'EXEMPT',
54
+ rounding: false,
55
+ signed: true,
56
+ client: greenInvoiceId,
57
+ income: [
58
+ {
59
+ description: `GraphQL Hive Enterprise License - ${month} ${year}`,
60
+ quantity: 1,
61
+ price: contract.amount,
62
+ currency: contract.currency as Currency,
63
+ vatType: 'EXEMPT',
64
+ },
65
+ ],
66
+ };
67
+
68
+ return documentInput;
69
+ };