2026-02-07 22:07:23 +00:00
|
|
|
import type { CustomerInvoiceListDTO } from "@erp/customer-invoices/api/infrastructure";
|
|
|
|
|
import type { Criteria } from "@repo/rdx-criteria/server";
|
|
|
|
|
import type { UniqueID } from "@repo/rdx-ddd";
|
|
|
|
|
import type { Collection, Result } from "@repo/rdx-utils";
|
|
|
|
|
import type { Transaction } from "sequelize";
|
|
|
|
|
|
2026-02-15 22:14:17 +00:00
|
|
|
import type { ICustomerInvoiceRepository, Proforma } from "../../../domain";
|
2026-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
export interface IIssuedInvoiceFinder {
|
|
|
|
|
findIssuedInvoiceById(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
invoiceId: UniqueID,
|
|
|
|
|
transaction?: Transaction
|
2026-02-15 22:14:17 +00:00
|
|
|
): Promise<Result<Proforma, Error>>;
|
2026-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
issuedInvoiceExists(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
invoiceId: UniqueID,
|
|
|
|
|
transaction?: Transaction
|
|
|
|
|
): Promise<Result<boolean, Error>>;
|
|
|
|
|
|
|
|
|
|
findIssuedInvoicesByCriteria(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
criteria: Criteria,
|
|
|
|
|
transaction?: Transaction
|
|
|
|
|
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class IssuedInvoiceFinder implements IIssuedInvoiceFinder {
|
|
|
|
|
constructor(private readonly repository: ICustomerInvoiceRepository) {}
|
|
|
|
|
|
|
|
|
|
async findIssuedInvoiceById(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
invoiceId: UniqueID,
|
|
|
|
|
transaction?: Transaction
|
2026-02-15 22:14:17 +00:00
|
|
|
): Promise<Result<Proforma, Error>> {
|
2026-02-07 22:07:23 +00:00
|
|
|
return this.repository.getIssuedInvoiceByIdInCompany(companyId, invoiceId, transaction, {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async issuedInvoiceExists(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
invoiceId: UniqueID,
|
|
|
|
|
transaction?: Transaction
|
|
|
|
|
): Promise<Result<boolean, Error>> {
|
|
|
|
|
return this.repository.existsByIdInCompany(companyId, invoiceId, transaction, {
|
|
|
|
|
is_proforma: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async findIssuedInvoicesByCriteria(
|
|
|
|
|
companyId: UniqueID,
|
|
|
|
|
criteria: Criteria,
|
|
|
|
|
transaction?: Transaction
|
|
|
|
|
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>> {
|
|
|
|
|
return this.repository.findIssuedInvoicesByCriteriaInCompany(
|
|
|
|
|
companyId,
|
|
|
|
|
criteria,
|
|
|
|
|
transaction,
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|