@accounter/server
Version:
Accounter GraphQL server
199 lines (198 loc) • 8.63 kB
TypeScript
import type { Injector } from 'graphql-modules';
import type { LedgerProto, StrictLedgerProto } from '../../../shared/types/index.js';
import type { DeelWorker, Invoice, PaymentBreakdownRecord, PaymentReceipts } from '../../app-providers/deel/schemas.js';
import type { IGetDocumentsByChargeIdResult } from '../../documents/types.js';
import type { IInsertDeelInvoiceRecordsParams, IUpdateDeelInvoiceRecordsParams } from '../types.js';
export declare function isDeelDocument(document: IGetDocumentsByChargeIdResult): boolean;
export declare function getDeelEmployeeId(injector: Injector, document: IGetDocumentsByChargeIdResult, ledgerEntry: StrictLedgerProto, ledgerEntries: LedgerProto[], updateLedgerBalance: (entry: LedgerProto) => void): Promise<void>;
type Prefixer<Type> = {
[Property in keyof Type as `breakdown_${string & Property}`]: Type[Property];
};
export type PrefixedBreakdown = Prefixer<PaymentBreakdownRecord & {
receipt_id: string;
}>;
export type DeelInvoiceMatch = Invoice & PrefixedBreakdown;
export declare const createDeelInvoiceMatchFromUnmatchedInvoice: (invoice: Invoice) => DeelInvoiceMatch;
export declare function uploadDeelInvoice(chargeId: string, match: DeelInvoiceMatch, injector: Injector, ownerId: string): Promise<string>;
export declare function convertMatchToDeelInvoiceRecord(match: DeelInvoiceMatch, documentId: string): IInsertDeelInvoiceRecordsParams;
export declare function convertMatchToPartialDeelInvoiceRecord(match: DeelInvoiceMatch): IUpdateDeelInvoiceRecordsParams;
export declare function getDeelChargeDescription(injector: Injector, workers?: DeelWorker[]): Promise<string>;
export declare function fetchAndFilterInvoices(injector: Injector): Promise<{
newInvoices: {
id: string;
amount: string;
billing_type: "FEE" | "WORK" | "RESERVE" | "PREPAID_BILLING";
contract_id: string | null;
created_at: string;
currency: string;
deel_fee: "0.00";
document_type: "INVOICE" | "FUNDING_STATEMENT";
due_date: string;
is_overdue: boolean;
issued_at: string;
label: string;
paid_at: string;
status: "pending" | "paid" | "processing" | "canceled" | "skipped" | "failed" | "refunded" | "processed";
total: string;
vat_id: "";
vat_percentage: "";
vat_total: "0.00";
recipient_legal_entity_id: "1dee10b1-105b-4dc7-bcdb-5ed5c52ba868";
}[];
unmatchedExistingInvoices: {
id: string;
amount: string;
billing_type: "FEE" | "WORK" | "RESERVE" | "PREPAID_BILLING";
contract_id: string | null;
created_at: string;
currency: string;
deel_fee: "0.00";
document_type: "INVOICE" | "FUNDING_STATEMENT";
due_date: string;
is_overdue: boolean;
issued_at: string;
label: string;
paid_at: string;
status: "pending" | "paid" | "processing" | "canceled" | "skipped" | "failed" | "refunded" | "processed";
total: string;
vat_id: "";
vat_percentage: "";
vat_total: "0.00";
recipient_legal_entity_id: "1dee10b1-105b-4dc7-bcdb-5ed5c52ba868";
}[];
}>;
export declare function fetchReceipts(injector: Injector): Promise<{
id: string;
created_at: string;
deel_granted_credits_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
eor_early_invoicing_funds_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
general_funds_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
invoices: {
id: string;
}[];
label: string;
paid_at: string | null;
payment_currency: string;
prepaid_billing_credits_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
total: string;
total_due: string;
status: "paid";
timezone: string | null;
deel_reference: string | null;
payment_method?: {
type?: "ach" | "alviere_ach" | "adyen_card" | "bank_transfer" | "bt_card" | "bt_pay_pal" | "brex" | "coinbase" | "client_balance" | "eor_funding_balance" | "fee_credits" | "go_cardless" | "go_cardless_becs" | "mercury_wire" | "pay_pal" | "stablecoin_transfer" | "stripe_ach" | "stripe_bacs_debit" | "stripe_card" | "stripe_sepa_debit" | "transferwise" | undefined;
} | undefined;
workers?: {
id: string;
picUrl: string | null;
contract_id?: string | null | undefined;
name?: string | undefined;
public_id?: string | undefined;
}[] | undefined;
}[]>;
export type DecoratedPaymentBreakdown = PaymentBreakdownRecord & {
receipt_id: string;
};
export declare function fetchPaymentBreakdowns(injector: Injector, receipts: PaymentReceipts[]): Promise<DecoratedPaymentBreakdown[]>;
type ContractInfo = {
contract_country: string;
contract_start_date: string;
contract_type: string;
contractor_email: string;
contractor_employee_name: string;
contractor_unique_identifier: string;
};
export declare function getContractsFromPaymentBreakdowns(matches: DeelInvoiceMatch[]): Map<string, ContractInfo>;
export declare function validateContracts(contractsInfo: Map<string, ContractInfo>, injector: Injector): Promise<void>;
export declare function getChargeMatchesForPayments(injector: Injector, receipts: PaymentReceipts[], paymentBreakdowns: DecoratedPaymentBreakdown[]): Promise<{
receiptChargeMap: Map<string, string>;
invoiceChargeMap: Map<string, string>;
newReceipts: {
id: string;
created_at: string;
deel_granted_credits_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
eor_early_invoicing_funds_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
general_funds_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
invoices: {
id: string;
}[];
label: string;
paid_at: string | null;
payment_currency: string;
prepaid_billing_credits_used: {
amount: string | null;
original_amount: string | null;
original_currency: string | null;
};
total: string;
total_due: string;
status: "paid";
timezone: string | null;
deel_reference: string | null;
payment_method?: {
type?: "ach" | "alviere_ach" | "adyen_card" | "bank_transfer" | "bt_card" | "bt_pay_pal" | "brex" | "coinbase" | "client_balance" | "eor_funding_balance" | "fee_credits" | "go_cardless" | "go_cardless_becs" | "mercury_wire" | "pay_pal" | "stablecoin_transfer" | "stripe_ach" | "stripe_bacs_debit" | "stripe_card" | "stripe_sepa_debit" | "transferwise" | undefined;
} | undefined;
workers?: {
id: string;
picUrl: string | null;
contract_id?: string | null | undefined;
name?: string | undefined;
public_id?: string | undefined;
}[] | undefined;
}[];
}>;
export declare function matchInvoicesWithPayments(invoices: Invoice[], paymentBreakdowns: DecoratedPaymentBreakdown[]): Promise<{
matches: DeelInvoiceMatch[];
unmatched: {
id: string;
amount: string;
billing_type: "FEE" | "WORK" | "RESERVE" | "PREPAID_BILLING";
contract_id: string | null;
created_at: string;
currency: string;
deel_fee: "0.00";
document_type: "INVOICE" | "FUNDING_STATEMENT";
due_date: string;
is_overdue: boolean;
issued_at: string;
label: string;
paid_at: string;
status: "pending" | "paid" | "processing" | "canceled" | "skipped" | "failed" | "refunded" | "processed";
total: string;
vat_id: "";
vat_percentage: "";
vat_total: "0.00";
recipient_legal_entity_id: "1dee10b1-105b-4dc7-bcdb-5ed5c52ba868";
}[];
}>;
export declare function updateDeelInvoiceRecord(injector: Injector, match: DeelInvoiceMatch, chargeId: string): Promise<void>;
export declare function insertDeelInvoiceRecord(injector: Injector, match: DeelInvoiceMatch, chargeId: string): Promise<void>;
export {};