@accounter/server
Version:
Accounter GraphQL server
57 lines (56 loc) • 2.65 kB
TypeScript
import type { Injector } from 'graphql-modules';
import type { AccountantStatus, Pcn874RecordType } from '../../../__generated__/types.js';
import { type Currency } from '../../../shared/enums.js';
import type { IGetChargesByIdsResult } from '../../charges/types.js';
import type { IGetDocumentsByFiltersResult } from '../../documents/types.js';
import type { IGetBusinessesByIdsResult } from '../../financial-entities/types.js';
export type VatReportRecordSources = {
charge: IGetChargesByIdsResult;
doc: IGetDocumentsByFiltersResult;
business: IGetBusinessesByIdsResult;
};
export type RawVatReportRecord = {
localAmountBeforeVAT?: number;
foreignAmountBeforeVAT?: number;
businessId: string | null;
chargeAccountantStatus: AccountantStatus;
chargeDate: Date;
chargeId: string;
currencyCode: Currency;
documentAmount: string;
documentId: string;
documentDate: Date | null;
documentSerial: string | null;
documentUrl: string | null;
eventLocalAmount?: number;
isExpense: boolean;
isProperty: boolean;
roundedVATToAdd?: number;
foreignVat: number | null;
localVat: number | null;
foreignVatAfterDeduction?: number;
localVatAfterDeduction?: number;
vatNumber?: string | null;
allocationNumber?: string | null;
pcn874RecordType?: Pcn874RecordType;
};
/**
* Determines whether a document should be considered by the VAT report.
*
* Only financial (invoice) documents linked to a charge and carrying both counterparties are
* relevant. Non-financial documents — most notably `OTHER`, but also `RECEIPT`, `PROFORMA` and
* `UNPROCESSED` — may still carry a date, counterparty or amount, yet they must never be included
* in the report nor pull their charge into it via that date (issue #3375).
*
* Acts as a type guard so callers can safely treat `charge_id`, `creditor_id` and `debtor_id`
* as non-null strings — all three are asserted present here.
*/
export declare function isVatReportRelevantDocument(doc: IGetDocumentsByFiltersResult): doc is IGetDocumentsByFiltersResult & {
charge_id: string;
creditor_id: string;
debtor_id: string;
};
export declare const MONTHLY_VAT_AMOUNT_TOLERANCE = 0.01;
export declare function calculateMonthlyVatTotalAmount(incomeRecords: Array<RawVatReportRecord>, expenseRecords: Array<RawVatReportRecord>): number;
export declare function isWithinMonthlyVatAmountTolerance(expectedVatAmount: number, transactionsAmount: number, tolerance?: number): boolean;
export declare function adjustTaxRecord(rawRecord: VatReportRecordSources, injector: Injector): Promise<RawVatReportRecord>;