@accounter/server 0.0.8-alpha-20251030162201-d2f279aafe537912ec3546af855cbd3a38ac0f5c → 0.0.8-alpha-20251030164843-d2f490daba879840366288d1f62974ab25081876

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 (56) hide show
  1. package/CHANGELOG.md +33 -20
  2. package/dist/server/src/__generated__/types.d.ts +37 -70
  3. package/dist/server/src/__generated__/types.js.map +1 -1
  4. package/dist/server/src/modules/contracts/__generated__/contracts.types.d.ts +29 -0
  5. package/dist/server/src/modules/contracts/__generated__/types.d.ts +3 -1
  6. package/dist/server/src/modules/contracts/__generated__/types.js.map +1 -1
  7. package/dist/server/src/modules/contracts/providers/contracts.provider.d.ts +5 -1
  8. package/dist/server/src/modules/contracts/providers/contracts.provider.js +37 -7
  9. package/dist/server/src/modules/contracts/providers/contracts.provider.js.map +1 -1
  10. package/dist/server/src/modules/contracts/resolvers/contracts.resolver.js +27 -0
  11. package/dist/server/src/modules/contracts/resolvers/contracts.resolver.js.map +1 -1
  12. package/dist/server/src/modules/contracts/typeDefs/contracts.graphql.js +2 -0
  13. package/dist/server/src/modules/contracts/typeDefs/contracts.graphql.js.map +1 -1
  14. package/dist/server/src/modules/financial-entities/__generated__/admin-businesses.types.d.ts +0 -57
  15. package/dist/server/src/modules/financial-entities/__generated__/admin-businesses.types.js +1 -0
  16. package/dist/server/src/modules/financial-entities/__generated__/admin-businesses.types.js.map +1 -1
  17. package/dist/server/src/modules/financial-entities/__generated__/types.d.ts +10 -33
  18. package/dist/server/src/modules/financial-entities/__generated__/types.js.map +1 -1
  19. package/dist/server/src/modules/financial-entities/providers/admin-businesses.provider.d.ts +1 -2
  20. package/dist/server/src/modules/financial-entities/providers/admin-businesses.provider.js +0 -37
  21. package/dist/server/src/modules/financial-entities/providers/admin-businesses.provider.js.map +1 -1
  22. package/dist/server/src/modules/financial-entities/resolvers/admin-businesses.resolver.js +11 -46
  23. package/dist/server/src/modules/financial-entities/resolvers/admin-businesses.resolver.js.map +1 -1
  24. package/dist/server/src/modules/financial-entities/typeDefs/admin-businesses.graphql.js +16 -49
  25. package/dist/server/src/modules/financial-entities/typeDefs/admin-businesses.graphql.js.map +1 -1
  26. package/dist/server/src/modules/financial-entities/types.d.ts +1 -1
  27. package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +2 -1
  28. package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
  29. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.d.ts +5 -0
  30. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +60 -0
  31. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -0
  32. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +10 -54
  33. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
  34. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +4 -0
  35. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/__generated__/types.ts +43 -76
  38. package/src/modules/contracts/__generated__/contracts.types.ts +32 -0
  39. package/src/modules/contracts/__generated__/types.ts +3 -1
  40. package/src/modules/contracts/providers/contracts.provider.ts +51 -6
  41. package/src/modules/contracts/resolvers/contracts.resolver.ts +24 -0
  42. package/src/modules/contracts/typeDefs/contracts.graphql.ts +2 -0
  43. package/src/modules/financial-entities/__generated__/admin-businesses.types.ts +0 -60
  44. package/src/modules/financial-entities/__generated__/types.ts +10 -33
  45. package/src/modules/financial-entities/providers/admin-businesses.provider.ts +0 -44
  46. package/src/modules/financial-entities/resolvers/admin-businesses.resolver.ts +11 -53
  47. package/src/modules/financial-entities/typeDefs/admin-businesses.graphql.ts +16 -49
  48. package/src/modules/financial-entities/types.ts +1 -1
  49. package/src/modules/green-invoice/__generated__/types.ts +2 -1
  50. package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +75 -0
  51. package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +15 -63
  52. package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +4 -0
  53. package/dist/server/src/modules/financial-entities/helpers/admin-businesses.helper.d.ts +0 -31
  54. package/dist/server/src/modules/financial-entities/helpers/admin-businesses.helper.js +0 -27
  55. package/dist/server/src/modules/financial-entities/helpers/admin-businesses.helper.js.map +0 -1
  56. package/src/modules/financial-entities/helpers/admin-businesses.helper.ts +0 -33
@@ -4,6 +4,7 @@ import type { Document } from '@accounter/green-invoice-graphql';
4
4
  import { GreenInvoiceClientProvider } from '@modules/app-providers/green-invoice-client.js';
5
5
  import { ChargesProvider } from '@modules/charges/providers/charges.provider.js';
6
6
  import { ContractsProvider } from '@modules/contracts/providers/contracts.provider.js';
7
+ import { IGetContractsByIdsResult } from '@modules/contracts/types.js';
7
8
  import { DocumentsProvider } from '@modules/documents/providers/documents.provider.js';
8
9
  import { IssuedDocumentsProvider } from '@modules/documents/providers/issued-documents.provider.js';
9
10
  import { normalizeDocumentType } from '@modules/documents/resolvers/common.js';
@@ -28,6 +29,7 @@ import { TransactionsProvider } from '@modules/transactions/providers/transactio
28
29
  import { Currency, DocumentType } from '@shared/enums';
29
30
  import { NewDocumentInfo } from '@shared/gql-types';
30
31
  import { dateToTimelessDateString } from '@shared/helpers';
32
+ import { convertContractToDraft } from '../helpers/contract-to-draft.helper.js';
31
33
  import {
32
34
  deduceVatTypeFromBusiness,
33
35
  executeDocumentIssue,
@@ -354,71 +356,21 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
354
356
  contract => contract.billing_cycle === 'monthly',
355
357
  );
356
358
  const drafts = await Promise.all(
357
- monthlyContracts.map(async contract => {
358
- const businessPromise = injector
359
- .get(BusinessesProvider)
360
- .getBusinessByIdLoader.load(contract.client_id);
361
- const clientPromise = injector
362
- .get(ClientsProvider)
363
- .getClientByIdLoader.load(contract.client_id);
364
- const greenInvoiceClientPromise = getClientFromGreenInvoiceClient(
365
- injector,
366
- contract.client_id,
367
- );
368
- const [business, client, greenInvoiceClient] = await Promise.all([
369
- businessPromise,
370
- clientPromise,
371
- greenInvoiceClientPromise,
372
- ]);
373
-
374
- if (!business) {
375
- throw new GraphQLError(`Business ID="${contract.client_id}" not found`);
376
- }
377
-
378
- if (!client) {
379
- throw new GraphQLError(`Client not found for business ID="${contract.client_id}"`);
380
- }
381
-
382
- if (!greenInvoiceClient) {
383
- throw new GraphQLError(
384
- `Green invoice match not found for business ID="${contract.client_id}"`,
385
- );
386
- }
359
+ monthlyContracts.map(async contract =>
360
+ convertContractToDraft(contract, injector, issueMonth),
361
+ ),
362
+ );
387
363
 
388
- const today = issueMonth ? addMonths(new Date(issueMonth), 1) : new Date();
389
- const monthStart = dateToTimelessDateString(startOfMonth(today));
390
- const monthEnd = dateToTimelessDateString(endOfMonth(today));
391
- const year = today.getFullYear() + (today.getMonth() === 0 ? -1 : 0);
392
- const month = format(subMonths(today, 1), 'MMMM');
364
+ return drafts;
365
+ },
366
+ clientChargesDraftsByContracts: async (_, { issueMonth, contractIds }, { injector }) => {
367
+ const contracts = await injector
368
+ .get(ContractsProvider)
369
+ .getContractsByIdLoader.loadMany(contractIds)
370
+ .then(res => res.filter(c => !!c && !(c instanceof Error)) as IGetContractsByIdsResult[]);
393
371
 
394
- const documentInput: NewDocumentInfo = {
395
- remarks: `${contract.purchase_orders[0] ? `PO: ${contract.purchase_orders[0]}${contract.remarks ? ', ' : ''}` : ''}${contract.remarks ?? ''}`,
396
- description: `GraphQL Hive Enterprise License - ${month} ${year}`,
397
- type: normalizeDocumentType(contract.document_type),
398
- date: monthStart,
399
- dueDate: monthEnd,
400
- lang: 'ENGLISH',
401
- currency: contract.currency as Currency,
402
- vatType: 'EXEMPT',
403
- rounding: false,
404
- signed: true,
405
- client: {
406
- ...greenInvoiceClient,
407
- emails: [...((client.emails?.filter(Boolean) as string[]) ?? [])],
408
- },
409
- income: [
410
- {
411
- description: `GraphQL Hive Enterprise License - ${month} ${year}`,
412
- quantity: 1,
413
- price: contract.amount,
414
- currency: contract.currency as Currency,
415
- vatType: 'EXEMPT',
416
- },
417
- ],
418
- };
419
-
420
- return documentInput;
421
- }),
372
+ const drafts = await Promise.all(
373
+ contracts.map(async contract => convertContractToDraft(contract, injector, issueMonth)),
422
374
  );
423
375
 
424
376
  return drafts;
@@ -6,6 +6,10 @@ export default gql`
6
6
  newDocumentInfoDraftByDocument(documentId: UUID!): NewDocumentInfo! @auth(role: ACCOUNTANT)
7
7
  clientMonthlyChargesDrafts(issueMonth: TimelessDate!): [NewDocumentInfo!]!
8
8
  @auth(role: ACCOUNTANT)
9
+ clientChargesDraftsByContracts(
10
+ issueMonth: TimelessDate!
11
+ contractIds: [UUID!]!
12
+ ): [NewDocumentInfo!]! @auth(role: ACCOUNTANT)
9
13
  clientMonthlyChargeDraft(clientId: UUID!, issueMonth: TimelessDate!): NewDocumentInfo!
10
14
  @auth(role: ACCOUNTANT)
11
15
  greenInvoiceClient(clientId: UUID!): GreenInvoiceClient! @auth(role: ACCOUNTANT)
@@ -1,31 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const adminBusinessUpdateSchema: z.ZodObject<{
3
- id: z.ZodUUID;
4
- businessRegistrationStartDate: z.ZodOptional<z.ZodISODate>;
5
- companyTaxId: z.ZodOptional<z.ZodString>;
6
- advanceTaxRates: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
- date: z.ZodISODate;
8
- rate: z.ZodNumber;
9
- }, z.core.$strict>>>;
10
- taxAdvancesIds: z.ZodOptional<z.ZodArray<z.ZodObject<{
11
- year: z.ZodNumber;
12
- id: z.ZodString;
13
- }, z.core.$strict>>>;
14
- socialSecurityEmployerIds: z.ZodOptional<z.ZodArray<z.ZodObject<{
15
- year: z.ZodNumber;
16
- id: z.ZodString;
17
- }, z.core.$strict>>>;
18
- withholdingTaxAnnualIds: z.ZodOptional<z.ZodArray<z.ZodObject<{
19
- year: z.ZodNumber;
20
- id: z.ZodString;
21
- }, z.core.$strict>>>;
22
- }, z.core.$strict>;
23
- export type AdminBusinessUpdateSchema = z.infer<typeof adminBusinessUpdateSchema>;
24
- export declare const yearlyIdsSchema: z.ZodArray<z.ZodObject<{
25
- year: z.ZodNumber;
26
- id: z.ZodString;
27
- }, z.core.$strict>>;
28
- export declare const taxAdvancesRatesSchema: z.ZodArray<z.ZodObject<{
29
- date: z.ZodISODate;
30
- rate: z.ZodNumber;
31
- }, z.core.$strict>>;
@@ -1,27 +0,0 @@
1
- import { z } from 'zod';
2
- const yearlyIdSchema = z
3
- .object({
4
- year: z.number().min(2000).max(2100),
5
- id: z.string().min(1, { message: 'ID is required' }),
6
- })
7
- .strict();
8
- const taxAdvanceRateSchema = z
9
- .object({
10
- date: z.iso.date(),
11
- rate: z.number().min(0).max(1),
12
- })
13
- .strict();
14
- export const adminBusinessUpdateSchema = z
15
- .object({
16
- id: z.uuid(),
17
- businessRegistrationStartDate: z.iso.date().optional(),
18
- companyTaxId: z.string().optional(),
19
- advanceTaxRates: z.array(taxAdvanceRateSchema).optional(),
20
- taxAdvancesIds: z.array(yearlyIdSchema).optional(),
21
- socialSecurityEmployerIds: z.array(yearlyIdSchema).optional(),
22
- withholdingTaxAnnualIds: z.array(yearlyIdSchema).optional(),
23
- })
24
- .strict();
25
- export const yearlyIdsSchema = z.array(yearlyIdSchema);
26
- export const taxAdvancesRatesSchema = z.array(taxAdvanceRateSchema);
27
- //# sourceMappingURL=admin-businesses.helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"admin-businesses.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/financial-entities/helpers/admin-businesses.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;IACpC,E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min(1, { message: 'ID is required' }),
7
- })
8
- .strict();
9
-
10
- const taxAdvanceRateSchema = z
11
- .object({
12
- date: z.iso.date(),
13
- rate: z.number().min(0).max(1),
14
- })
15
- .strict();
16
-
17
- export const adminBusinessUpdateSchema = z
18
- .object({
19
- id: z.uuid(),
20
- businessRegistrationStartDate: z.iso.date().optional(),
21
- companyTaxId: z.string().optional(),
22
- advanceTaxRates: z.array(taxAdvanceRateSchema).optional(),
23
- taxAdvancesIds: z.array(yearlyIdSchema).optional(),
24
- socialSecurityEmployerIds: z.array(yearlyIdSchema).optional(),
25
- withholdingTaxAnnualIds: z.array(yearlyIdSchema).optional(),
26
- })
27
- .strict();
28
-
29
- export type AdminBusinessUpdateSchema = z.infer<typeof adminBusinessUpdateSchema>;
30
-
31
- export const yearlyIdsSchema = z.array(yearlyIdSchema);
32
-
33
- export const taxAdvancesRatesSchema = z.array(taxAdvanceRateSchema);