160 lines
4.4 KiB
TypeScript
160 lines
4.4 KiB
TypeScript
import { IInvoiceDocument } from "./Invoices.Adapter.Mongoose";
|
|
|
|
export enum INVOICE_TYPE {
|
|
FACTURA_C = "FACTURA_C",
|
|
}
|
|
|
|
export enum INVOICE_STATUS {
|
|
PENDING_ARCA = "PENDING_ARCA",
|
|
APPROVED = "APPROVED",
|
|
PENDING_VERIFICATION = "PENDING_VERIFICATION",
|
|
REJECTED = "REJECTED",
|
|
FAILED = "FAILED",
|
|
}
|
|
|
|
export enum INVOICE_SALE_CONDITION {
|
|
CASH = "cash",
|
|
CONTADO = "contado",
|
|
BANK_TRANSFER = "bank_transfer",
|
|
CREDIT_CARD = "credit_card",
|
|
DEBIT_CARD = "debit_card",
|
|
CURRENT_ACCOUNT = "current_account",
|
|
CHECK = "check",
|
|
OTHER = "other",
|
|
ELECTRONIC_PAYMENT = "electronic_payment",
|
|
}
|
|
|
|
export const FINAL_CONSUMER_IVA_CONDITION_ID = 5;
|
|
|
|
export type CreateInvoiceFromCashMovementParams = {
|
|
cashMovementId: string;
|
|
billingDate: Date | string;
|
|
servicePeriodFrom: Date | string;
|
|
servicePeriodTo: Date | string;
|
|
paymentDueDate: Date | string;
|
|
activityCode: string;
|
|
activityDescription: string;
|
|
receiverIvaCondition?: 5;
|
|
receiverDocumentType?: number | string;
|
|
receiverDocumentNumber?: number | string;
|
|
receiverName?: string;
|
|
receiverAddress?: string;
|
|
receiverEmail?: string;
|
|
saleCondition: INVOICE_SALE_CONDITION | string;
|
|
itemDescription: string;
|
|
itemQuantity?: number;
|
|
itemUnit?: string;
|
|
itemUnitPrice: number;
|
|
itemDiscountPercent?: number;
|
|
itemDiscountAmount?: number;
|
|
itemSubtotal: number;
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type FindInvoicesParams = {
|
|
id?: string;
|
|
cashMovementId?: string;
|
|
cashMovementIds?: string[];
|
|
companyId?: string;
|
|
status?: INVOICE_STATUS;
|
|
sessionUser?: string;
|
|
};
|
|
|
|
export type CreateInvoiceParams = {
|
|
cashMovementId: string;
|
|
companyId: string;
|
|
clientId?: string;
|
|
paymentId?: string;
|
|
clientAccountMovementId?: string;
|
|
appointmentId?: string;
|
|
amount: number;
|
|
type: INVOICE_TYPE;
|
|
status: INVOICE_STATUS;
|
|
billingDate: Date;
|
|
servicePeriodFrom: Date;
|
|
servicePeriodTo: Date;
|
|
paymentDueDate: Date;
|
|
activityCode: string;
|
|
activityDescription: string;
|
|
receiverIvaCondition: 5;
|
|
receiverDocumentType?: number | string;
|
|
receiverDocumentNumber?: number | string;
|
|
receiverName?: string;
|
|
receiverAddress?: string;
|
|
receiverEmail?: string;
|
|
saleCondition: INVOICE_SALE_CONDITION | string;
|
|
itemDescription: string;
|
|
itemQuantity: number;
|
|
itemUnit?: string;
|
|
itemUnitPrice: number;
|
|
itemDiscountPercent: number;
|
|
itemDiscountAmount: number;
|
|
itemSubtotal: number;
|
|
cae?: string;
|
|
caeExpiresAt?: Date;
|
|
pointOfSale?: number;
|
|
voucherNumber?: number;
|
|
voucherType?: string;
|
|
arcaErrorCode?: string;
|
|
arcaErrorMessage?: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
};
|
|
|
|
export type UpdateInvoiceParams = FindInvoicesParams & Partial<CreateInvoiceParams>;
|
|
|
|
export interface IInvoice {
|
|
id?: string;
|
|
cashMovementId: string;
|
|
companyId: string;
|
|
clientId?: string;
|
|
paymentId?: string;
|
|
clientAccountMovementId?: string;
|
|
appointmentId?: string;
|
|
amount: number;
|
|
type: INVOICE_TYPE;
|
|
status: INVOICE_STATUS;
|
|
billingDate: Date;
|
|
servicePeriodFrom: Date;
|
|
servicePeriodTo: Date;
|
|
paymentDueDate: Date;
|
|
activityCode: string;
|
|
activityDescription: string;
|
|
receiverIvaCondition: 5;
|
|
receiverDocumentType?: number | string;
|
|
receiverDocumentNumber?: number | string;
|
|
receiverName?: string;
|
|
receiverAddress?: string;
|
|
receiverEmail?: string;
|
|
saleCondition: INVOICE_SALE_CONDITION | string;
|
|
itemDescription: string;
|
|
itemQuantity: number;
|
|
itemUnit?: string;
|
|
itemUnitPrice: number;
|
|
itemDiscountPercent: number;
|
|
itemDiscountAmount: number;
|
|
itemSubtotal: number;
|
|
cae?: string;
|
|
caeExpiresAt?: Date;
|
|
pointOfSale?: number;
|
|
voucherNumber?: number;
|
|
voucherType?: string;
|
|
arcaErrorCode?: string;
|
|
arcaErrorMessage?: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
export interface IInvoicesAdapter {
|
|
create(data: CreateInvoiceParams): Promise<IInvoice>;
|
|
find(filters: FindInvoicesParams): Promise<IInvoice[]>;
|
|
findOne(filters: FindInvoicesParams): Promise<IInvoiceDocument | null>;
|
|
update(data: UpdateInvoiceParams): Promise<IInvoiceDocument | null>;
|
|
}
|
|
|
|
export interface IInvoicesManager {
|
|
invoices: IInvoicesAdapter;
|
|
createFromCashMovement(data: CreateInvoiceFromCashMovementParams): Promise<IInvoice>;
|
|
find(data: FindInvoicesParams): Promise<IInvoice[]>;
|
|
}
|