@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.
- package/CHANGELOG.md +5 -28
- package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1 -1
- package/dist/server/src/__generated__/types.d.ts +301 -282
- package/dist/server/src/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/app-providers/green-invoice-client.d.ts +3 -3
- package/dist/server/src/modules/documents/__generated__/types.d.ts +7 -121
- package/dist/server/src/modules/documents/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/documents/helpers/common.helper.d.ts +0 -2
- package/dist/server/src/modules/documents/helpers/common.helper.js +0 -20
- package/dist/server/src/modules/documents/helpers/common.helper.js.map +1 -1
- package/dist/server/src/modules/documents/index.js +2 -9
- package/dist/server/src/modules/documents/index.js.map +1 -1
- package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +135 -6
- package/dist/server/src/modules/green-invoice/__generated__/types.js +2 -0
- package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.d.ts +7 -0
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +53 -0
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -0
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.d.ts +27 -21
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js +146 -151
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js.map +1 -1
- package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.d.ts +19 -0
- package/dist/server/src/modules/{documents → green-invoice}/helpers/issue-document.helper.js +11 -59
- package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.js.map +1 -0
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +347 -4
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +512 -4
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
- package/dist/shaam-uniform-format-generator/src/generator/records/b110.d.ts +35 -35
- package/dist/shaam-uniform-format-generator/src/types/enums.d.ts +71 -71
- package/package.json +1 -1
- package/src/__generated__/types.ts +620 -327
- package/src/modules/documents/__generated__/types.ts +7 -121
- package/src/modules/documents/helpers/common.helper.ts +0 -21
- package/src/modules/documents/index.ts +2 -9
- package/src/modules/green-invoice/__generated__/types.ts +137 -6
- package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +69 -0
- package/src/modules/green-invoice/helpers/green-invoice.helper.ts +199 -183
- package/src/modules/{documents → green-invoice}/helpers/issue-document.helper.ts +44 -96
- package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +520 -5
- package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +512 -4
- package/dist/server/src/modules/documents/helpers/issue-document.helper.d.ts +0 -21
- package/dist/server/src/modules/documents/helpers/issue-document.helper.js.map +0 -1
- package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.d.ts +0 -2
- package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js +0 -346
- package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js.map +0 -1
- package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.d.ts +0 -2
- package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js +0 -228
- package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js.map +0 -1
- package/src/modules/documents/resolvers/documents-issuing.resolver.ts +0 -529
- package/src/modules/documents/typeDefs/documents-issuing.graphql.ts +0 -228
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import { addMonths, endOfMonth, format, startOfMonth, subMonths } from 'date-fns';
|
|
2
1
|
import { GraphQLError } from 'graphql';
|
|
3
|
-
import
|
|
2
|
+
import { Injector } from 'graphql-modules';
|
|
4
3
|
import type { _DOLLAR_defs_Document } from '@accounter/green-invoice-graphql';
|
|
5
4
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
ResolversTypes,
|
|
5
|
+
GreenInvoiceIncome,
|
|
6
|
+
GreenInvoiceLinkType,
|
|
7
|
+
GreenInvoicePayment,
|
|
8
|
+
GreenInvoicePaymentType,
|
|
9
|
+
GreenInvoiceVatType,
|
|
10
|
+
NewDocumentInfo,
|
|
11
|
+
NewDocumentInput,
|
|
14
12
|
} from '../../../__generated__/types.js';
|
|
15
13
|
import { Currency, DocumentType } from '../../../shared/enums.js';
|
|
16
14
|
import { dateToTimelessDateString } from '../../../shared/helpers/index.js';
|
|
17
|
-
import
|
|
15
|
+
import { TimelessDateString } from '../../../shared/types/index.js';
|
|
18
16
|
import { GreenInvoiceClientProvider } from '../../app-providers/green-invoice-client.js';
|
|
19
17
|
import { ChargesProvider } from '../../charges/providers/charges.provider.js';
|
|
20
|
-
import
|
|
18
|
+
import { IssuedDocumentsProvider } from '../../documents/providers/issued-documents.provider.js';
|
|
19
|
+
import type {
|
|
20
|
+
IGetDocumentsByChargeIdResult,
|
|
21
|
+
IGetIssuedDocumentsByIdsResult,
|
|
22
|
+
} from '../../documents/types.js';
|
|
21
23
|
import { FinancialAccountsProvider } from '../../financial-accounts/providers/financial-accounts.provider.js';
|
|
22
24
|
import { FinancialBankAccountsProvider } from '../../financial-accounts/providers/financial-bank-accounts.provider.js';
|
|
23
25
|
import type { IGetFinancialBankAccountsByIdsResult } from '../../financial-accounts/types.js';
|
|
24
|
-
import { validateClientIntegrations } from '../../financial-entities/helpers/clients.helper.js';
|
|
25
26
|
import { BusinessesProvider } from '../../financial-entities/providers/businesses.provider.js';
|
|
26
|
-
import {
|
|
27
|
+
import type { IGetTransactionsByChargeIdsResult } from '../../transactions/types.js';
|
|
27
28
|
import {
|
|
28
29
|
convertDocumentInputIntoGreenInvoiceInput,
|
|
29
|
-
|
|
30
|
+
getGreenInvoiceDocumentType,
|
|
30
31
|
getVatTypeFromGreenInvoiceDocument,
|
|
31
32
|
insertNewDocumentFromGreenInvoice,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import { IssuedDocumentsProvider } from '../providers/issued-documents.provider.js';
|
|
35
|
-
import { normalizeDocumentType } from '../resolvers/common.js';
|
|
36
|
-
import type { IGetIssuedDocumentsByIdsResult } from '../types.js';
|
|
33
|
+
normalizeDocumentType,
|
|
34
|
+
} from './green-invoice.helper.js';
|
|
37
35
|
|
|
38
36
|
export async function getPaymentsFromTransactions(
|
|
39
37
|
injector: Injector,
|
|
40
38
|
transactions: IGetTransactionsByChargeIdsResult[],
|
|
41
|
-
): Promise<
|
|
39
|
+
): Promise<GreenInvoicePayment[]> {
|
|
42
40
|
const payments = await Promise.all(
|
|
43
41
|
transactions.map(async transaction => {
|
|
44
42
|
// get account
|
|
@@ -50,7 +48,7 @@ export async function getPaymentsFromTransactions(
|
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
// get account type
|
|
53
|
-
let type:
|
|
51
|
+
let type: GreenInvoicePaymentType = 'OTHER';
|
|
54
52
|
switch (account.type) {
|
|
55
53
|
case 'BANK_ACCOUNT':
|
|
56
54
|
type = 'WIRE_TRANSFER';
|
|
@@ -73,7 +71,7 @@ export async function getPaymentsFromTransactions(
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
// get further fields
|
|
76
|
-
let paymentTypeSpecificAttributes: Partial<
|
|
74
|
+
let paymentTypeSpecificAttributes: Partial<GreenInvoicePayment> = {};
|
|
77
75
|
switch (type as string) {
|
|
78
76
|
case 'CHEQUE':
|
|
79
77
|
paymentTypeSpecificAttributes = {
|
|
@@ -84,6 +82,7 @@ export async function getPaymentsFromTransactions(
|
|
|
84
82
|
paymentTypeSpecificAttributes = {
|
|
85
83
|
cardType: 'MASTERCARD', // TODO: add logic to support other card types
|
|
86
84
|
cardNum: account.account_number,
|
|
85
|
+
dealType: 'STANDARD', // TODO: add logic to support other deal types
|
|
87
86
|
numPayments: 1,
|
|
88
87
|
firstPayment: transaction.event_date.getTime() / 1000, // assuming first payment is the transaction date
|
|
89
88
|
};
|
|
@@ -121,7 +120,7 @@ export async function getPaymentsFromTransactions(
|
|
|
121
120
|
break;
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
const payment:
|
|
123
|
+
const payment: GreenInvoicePayment = {
|
|
125
124
|
currency: transaction.currency as Currency,
|
|
126
125
|
currencyRate: undefined,
|
|
127
126
|
date: dateToTimelessDateString(transaction.debit_date ?? transaction.event_date),
|
|
@@ -137,16 +136,20 @@ export async function getPaymentsFromTransactions(
|
|
|
137
136
|
return payments;
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
export function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
export function getIncomeFromDocuments(
|
|
140
|
+
documents: {
|
|
141
|
+
document: IGetDocumentsByChargeIdResult;
|
|
142
|
+
issuedDocument: IGetIssuedDocumentsByIdsResult;
|
|
143
|
+
greenInvoiceDocument: _DOLLAR_defs_Document;
|
|
144
|
+
}[],
|
|
145
|
+
): GreenInvoiceIncome[] {
|
|
146
|
+
const incomes = documents
|
|
147
|
+
.map(({ greenInvoiceDocument }) => {
|
|
145
148
|
return greenInvoiceDocument.income.filter(Boolean).map(originIncome => {
|
|
146
149
|
if (!originIncome?.currency) {
|
|
147
150
|
throw new Error('Income currency is missing');
|
|
148
151
|
}
|
|
149
|
-
const income:
|
|
152
|
+
const income: GreenInvoiceIncome = {
|
|
150
153
|
description: originIncome.description,
|
|
151
154
|
quantity: originIncome.quantity,
|
|
152
155
|
price: originIncome.price,
|
|
@@ -164,17 +167,19 @@ export function getIncomeRecordsFromDocuments(
|
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
export function getTypeFromDocumentsAndTransactions(
|
|
167
|
-
|
|
170
|
+
greenInvoiceDocuments: _DOLLAR_defs_Document[],
|
|
168
171
|
transactions: IGetTransactionsByChargeIdsResult[],
|
|
169
172
|
): DocumentType {
|
|
170
|
-
if (!
|
|
173
|
+
if (!greenInvoiceDocuments.length) {
|
|
171
174
|
if (transactions.length) {
|
|
172
175
|
return DocumentType.InvoiceReceipt;
|
|
173
176
|
}
|
|
174
177
|
return DocumentType.Proforma;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
const documentsTypes = new Set<DocumentType>(
|
|
180
|
+
const documentsTypes = new Set<DocumentType>(
|
|
181
|
+
greenInvoiceDocuments.map(doc => normalizeDocumentType(doc.type)),
|
|
182
|
+
);
|
|
178
183
|
|
|
179
184
|
if (documentsTypes.size === 1) {
|
|
180
185
|
switch (Array.from(documentsTypes)[0]) {
|
|
@@ -225,9 +230,9 @@ export function filterAndHandleSwiftTransactions(
|
|
|
225
230
|
export function getLinkedDocumentsAttributes(
|
|
226
231
|
issuedDocuments: IGetIssuedDocumentsByIdsResult[],
|
|
227
232
|
shouldCancel: boolean = false,
|
|
228
|
-
): Pick<
|
|
233
|
+
): Pick<NewDocumentInfo, 'linkedDocumentIds' | 'linkType'> {
|
|
229
234
|
const linkedDocumentIds = issuedDocuments.map(doc => doc.external_id);
|
|
230
|
-
let linkType:
|
|
235
|
+
let linkType: GreenInvoiceLinkType | undefined = undefined;
|
|
231
236
|
if (linkedDocumentIds.length) {
|
|
232
237
|
if (shouldCancel) {
|
|
233
238
|
linkType = 'CANCEL';
|
|
@@ -261,81 +266,24 @@ export async function deduceVatTypeFromBusiness(
|
|
|
261
266
|
injector: Injector,
|
|
262
267
|
locality: string,
|
|
263
268
|
businessId?: string | null,
|
|
264
|
-
): Promise<
|
|
269
|
+
): Promise<GreenInvoiceVatType> {
|
|
265
270
|
if (!businessId) return 'DEFAULT';
|
|
266
271
|
|
|
267
272
|
const business = await injector.get(BusinessesProvider).getBusinessByIdLoader.load(businessId);
|
|
268
273
|
if (!business) return 'DEFAULT';
|
|
269
274
|
|
|
270
275
|
// Deduce VAT type based on business information
|
|
271
|
-
if (business.country === locality
|
|
276
|
+
if (business.country === locality) {
|
|
272
277
|
return 'MIXED';
|
|
273
278
|
}
|
|
274
279
|
|
|
275
280
|
return 'EXEMPT';
|
|
276
281
|
}
|
|
277
282
|
|
|
278
|
-
export const convertContractToDraft = async (
|
|
279
|
-
contract: IGetContractsByIdsResult,
|
|
280
|
-
injector: Injector,
|
|
281
|
-
issueMonth: TimelessDateString,
|
|
282
|
-
) => {
|
|
283
|
-
const businessPromise = injector
|
|
284
|
-
.get(BusinessesProvider)
|
|
285
|
-
.getBusinessByIdLoader.load(contract.client_id);
|
|
286
|
-
const clientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(contract.client_id);
|
|
287
|
-
const [business, client] = await Promise.all([businessPromise, clientPromise]);
|
|
288
|
-
|
|
289
|
-
if (!business) {
|
|
290
|
-
throw new GraphQLError(`Business ID="${contract.client_id}" not found`);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (!client) {
|
|
294
|
-
throw new GraphQLError(`Client not found for business ID="${contract.client_id}"`);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const greenInvoiceId = validateClientIntegrations(client.integrations)?.greenInvoiceId;
|
|
298
|
-
|
|
299
|
-
if (!greenInvoiceId) {
|
|
300
|
-
throw new GraphQLError(`Green invoice match not found for business ID="${contract.client_id}"`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const today = issueMonth ? addMonths(new Date(issueMonth), 1) : new Date();
|
|
304
|
-
const monthStart = dateToTimelessDateString(startOfMonth(today));
|
|
305
|
-
const monthEnd = dateToTimelessDateString(endOfMonth(today));
|
|
306
|
-
const year = today.getFullYear() + (today.getMonth() === 0 ? -1 : 0);
|
|
307
|
-
const month = format(subMonths(today, 1), 'MMMM');
|
|
308
|
-
|
|
309
|
-
const documentInput: ResolversTypes['DocumentDraft'] = {
|
|
310
|
-
remarks: `${contract.purchase_orders[0] ? `PO: ${contract.purchase_orders[0]}${contract.remarks ? ', ' : ''}` : ''}${contract.remarks ?? ''}`,
|
|
311
|
-
description: `GraphQL Hive Enterprise License - ${month} ${year}`,
|
|
312
|
-
type: normalizeDocumentType(contract.document_type),
|
|
313
|
-
date: monthStart,
|
|
314
|
-
dueDate: monthEnd,
|
|
315
|
-
language: 'ENGLISH',
|
|
316
|
-
currency: contract.currency as Currency,
|
|
317
|
-
vatType: 'EXEMPT',
|
|
318
|
-
rounding: false,
|
|
319
|
-
signed: true,
|
|
320
|
-
client,
|
|
321
|
-
income: [
|
|
322
|
-
{
|
|
323
|
-
description: `GraphQL Hive Enterprise License - ${month} ${year}`,
|
|
324
|
-
quantity: 1,
|
|
325
|
-
price: contract.amount,
|
|
326
|
-
currency: contract.currency as Currency,
|
|
327
|
-
vatType: 'EXEMPT',
|
|
328
|
-
},
|
|
329
|
-
],
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
return documentInput;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
283
|
export async function executeDocumentIssue(
|
|
336
284
|
injector: Injector,
|
|
337
285
|
adminBusinessId: string,
|
|
338
|
-
initialInput:
|
|
286
|
+
initialInput: NewDocumentInput,
|
|
339
287
|
emailContent?: string,
|
|
340
288
|
attachment = true,
|
|
341
289
|
chargeId?: string,
|
|
@@ -417,7 +365,7 @@ export async function executeDocumentIssue(
|
|
|
417
365
|
}),
|
|
418
366
|
);
|
|
419
367
|
}
|
|
420
|
-
if (
|
|
368
|
+
if (coreInput.type === getGreenInvoiceDocumentType(DocumentType.CreditInvoice)) {
|
|
421
369
|
// Close origin
|
|
422
370
|
}
|
|
423
371
|
|