.
This commit is contained in:
parent
97544b012d
commit
2157ddeaa3
@ -1,4 +1,4 @@
|
||||
import type { CurrencyCode, LanguageCode, Percentage, UniqueID, UtcDate } from "@repo/rdx-ddd";
|
||||
import type { CurrencyCode, LanguageCode, UniqueID, UtcDate } from "@repo/rdx-ddd";
|
||||
import type { Maybe } from "@repo/rdx-utils";
|
||||
|
||||
import type {
|
||||
@ -31,10 +31,8 @@ export type IssuedInvoiceListDTO = {
|
||||
languageCode: LanguageCode;
|
||||
currencyCode: CurrencyCode;
|
||||
|
||||
discountPercentage: Percentage;
|
||||
|
||||
subtotalAmount: InvoiceAmount;
|
||||
discountAmount: InvoiceAmount;
|
||||
totalDiscountAmount: InvoiceAmount;
|
||||
taxableAmount: InvoiceAmount;
|
||||
taxesAmount: InvoiceAmount;
|
||||
totalAmount: InvoiceAmount;
|
||||
|
||||
@ -14,6 +14,13 @@ export interface IIssuedInvoiceRepository {
|
||||
transaction: unknown
|
||||
): Promise<Result<IssuedInvoice, Error>>;
|
||||
|
||||
existsByIdInCompany(
|
||||
companyId: UniqueID,
|
||||
id: UniqueID,
|
||||
transaction: unknown,
|
||||
options: unknown
|
||||
): Promise<Result<boolean, Error>>;
|
||||
|
||||
findByCriteriaInCompany(
|
||||
companyId: UniqueID,
|
||||
criteria: Criteria,
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
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";
|
||||
|
||||
import type { ICustomerInvoiceRepository, Proforma } from "../../../domain";
|
||||
import type { IssuedInvoice } from "../../../domain";
|
||||
import type { IssuedInvoiceListDTO } from "../dtos";
|
||||
import type { IIssuedInvoiceRepository } from "../repositories";
|
||||
|
||||
export interface IIssuedInvoiceFinder {
|
||||
findIssuedInvoiceById(
|
||||
companyId: UniqueID,
|
||||
invoiceId: UniqueID,
|
||||
transaction?: Transaction
|
||||
): Promise<Result<Proforma, Error>>;
|
||||
): Promise<Result<IssuedInvoice, Error>>;
|
||||
|
||||
issuedInvoiceExists(
|
||||
companyId: UniqueID,
|
||||
@ -23,18 +24,18 @@ export interface IIssuedInvoiceFinder {
|
||||
companyId: UniqueID,
|
||||
criteria: Criteria,
|
||||
transaction?: Transaction
|
||||
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>>;
|
||||
): Promise<Result<Collection<IssuedInvoiceListDTO>, Error>>;
|
||||
}
|
||||
|
||||
export class IssuedInvoiceFinder implements IIssuedInvoiceFinder {
|
||||
constructor(private readonly repository: ICustomerInvoiceRepository) {}
|
||||
constructor(private readonly repository: IIssuedInvoiceRepository) {}
|
||||
|
||||
async findIssuedInvoiceById(
|
||||
companyId: UniqueID,
|
||||
invoiceId: UniqueID,
|
||||
transaction?: Transaction
|
||||
): Promise<Result<Proforma, Error>> {
|
||||
return this.repository.getIssuedInvoiceByIdInCompany(companyId, invoiceId, transaction, {});
|
||||
): Promise<Result<IssuedInvoice, Error>> {
|
||||
return this.repository.getByIdInCompany(companyId, invoiceId, transaction);
|
||||
}
|
||||
|
||||
async issuedInvoiceExists(
|
||||
@ -51,12 +52,7 @@ export class IssuedInvoiceFinder implements IIssuedInvoiceFinder {
|
||||
companyId: UniqueID,
|
||||
criteria: Criteria,
|
||||
transaction?: Transaction
|
||||
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>> {
|
||||
return this.repository.findIssuedInvoicesByCriteriaInCompany(
|
||||
companyId,
|
||||
criteria,
|
||||
transaction,
|
||||
{}
|
||||
);
|
||||
): Promise<Result<Collection<IssuedInvoiceListDTO>, Error>> {
|
||||
return this.repository.findByCriteriaInCompany(companyId, criteria, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ export class ProformaToIssuedInvoiceMaterializer implements IProformaToIssuedInv
|
||||
languageCode: proforma.languageCode,
|
||||
currencyCode: proforma.currencyCode,
|
||||
paymentMethod: proforma.paymentMethod,
|
||||
discountPercentage: proforma.discountPercentage,
|
||||
discountPercentage: proforma.globalDiscountPercentage,
|
||||
|
||||
items: new Collection(issuedItems),
|
||||
taxes: new Collection(issuedTaxes),
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { toEmptyString } from "@repo/rdx-ddd";
|
||||
|
||||
import { InvoiceAmount, type Proforma } from "../../../../domain";
|
||||
import { InvoiceAmount, type IssuedInvoice } from "../../../../domain";
|
||||
|
||||
import type { IssuedInvoiceFullSnapshot } from "./issued-invoice-full-snapshot.interface";
|
||||
import type { IIssuedInvoiceFullSnapshot } from "./issued-invoice-full-snapshot.interface";
|
||||
import type { IIssuedInvoiceItemsFullSnapshotBuilder } from "./issued-invoice-items-full-snapshot-builder";
|
||||
import type { IIssuedInvoiceRecipientFullSnapshotBuilder } from "./issued-invoice-recipient-full-snapshot-builder";
|
||||
import type { IIssuedInvoiceVerifactuFullSnapshotBuilder } from "./issued-invoice-verifactu-full-snapshot-builder";
|
||||
|
||||
export interface IIssuedInvoiceFullSnapshotBuilder
|
||||
extends ISnapshotBuilder<Proforma, IssuedInvoiceFullSnapshot> {}
|
||||
extends ISnapshotBuilder<IssuedInvoice, IIssuedInvoiceFullSnapshot> {}
|
||||
|
||||
export class IssuedInvoiceFullSnapshotBuilder implements IIssuedInvoiceFullSnapshotBuilder {
|
||||
constructor(
|
||||
@ -18,13 +18,11 @@ export class IssuedInvoiceFullSnapshotBuilder implements IIssuedInvoiceFullSnaps
|
||||
private readonly verifactuBuilder: IIssuedInvoiceVerifactuFullSnapshotBuilder
|
||||
) {}
|
||||
|
||||
toOutput(invoice: Proforma): IssuedInvoiceFullSnapshot {
|
||||
toOutput(invoice: IssuedInvoice): IIssuedInvoiceFullSnapshot {
|
||||
const items = this.itemsBuilder.toOutput(invoice.items);
|
||||
const recipient = this.recipientBuilder.toOutput(invoice);
|
||||
const verifactu = this.verifactuBuilder.toOutput(invoice);
|
||||
|
||||
const allAmounts = invoice.calculateAllAmounts();
|
||||
|
||||
const payment = invoice.paymentMethod.match(
|
||||
(payment) => {
|
||||
const { id, payment_description } = payment.toObjectString();
|
||||
@ -40,7 +38,7 @@ export class IssuedInvoiceFullSnapshotBuilder implements IIssuedInvoiceFullSnaps
|
||||
let totalRecAmount = InvoiceAmount.zero(invoice.currencyCode.code);
|
||||
let totalRetentionAmount = InvoiceAmount.zero(invoice.currencyCode.code);
|
||||
|
||||
const invoiceTaxes = invoice.getTaxes().map((taxGroup) => {
|
||||
const invoiceTaxes = invoice.taxes().map((taxGroup) => {
|
||||
const { ivaAmount, recAmount, retentionAmount, totalAmount } = taxGroup.calculateAmounts();
|
||||
|
||||
totalIvaAmount = totalIvaAmount.add(ivaAmount);
|
||||
@ -109,7 +107,7 @@ export class IssuedInvoiceFullSnapshotBuilder implements IIssuedInvoiceFullSnaps
|
||||
subtotal_amount: allAmounts.subtotalAmount.toObjectString(),
|
||||
items_discount_amount: allAmounts.itemDiscountAmount.toObjectString(),
|
||||
|
||||
discount_percentage: invoice.discountPercentage.toObjectString(),
|
||||
discount_percentage: invoice.globalDiscountPercentage.toObjectString(),
|
||||
discount_amount: allAmounts.globalDiscountAmount.toObjectString(),
|
||||
|
||||
taxable_amount: allAmounts.taxableAmount.toObjectString(),
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import type { IssuedInvoiceItemFullSnapshot } from "./issued-invoice-item-full-snapshot.interface";
|
||||
import type { IssuedInvoiceRecipientFullSnapshot } from "./issued-invoice-recipient-full-snapshot.interfce";
|
||||
import type { IssuedInvoiceVerifactuFullSnapshot } from "./issued-invoice-verifactu-full-snapshot.interface";
|
||||
import type { IIssuedInvoiceItemFullSnapshot } from "./issued-invoice-item-full-snapshot.interface";
|
||||
import type { IIssuedInvoiceRecipientFullSnapshot } from "./issued-invoice-recipient-full-snapshot.interfce";
|
||||
import type { IIssuedInvoiceVerifactuFullSnapshot } from "./issued-invoice-verifactu-full-snapshot.interface";
|
||||
|
||||
export interface IssuedInvoiceFullSnapshot {
|
||||
export interface IIssuedInvoiceFullSnapshot {
|
||||
id: string;
|
||||
company_id: string;
|
||||
|
||||
@ -22,7 +22,7 @@ export interface IssuedInvoiceFullSnapshot {
|
||||
currency_code: string;
|
||||
|
||||
customer_id: string;
|
||||
recipient: IssuedInvoiceRecipientFullSnapshot;
|
||||
recipient: IIssuedInvoiceRecipientFullSnapshot;
|
||||
|
||||
payment_method?: {
|
||||
payment_id: string;
|
||||
@ -62,8 +62,8 @@ export interface IssuedInvoiceFullSnapshot {
|
||||
taxes_amount: { value: string; scale: string; currency_code: string };
|
||||
}>;
|
||||
|
||||
verifactu: IssuedInvoiceVerifactuFullSnapshot;
|
||||
items: IssuedInvoiceItemFullSnapshot[];
|
||||
verifactu: IIssuedInvoiceVerifactuFullSnapshot;
|
||||
items: IIssuedInvoiceItemFullSnapshot[];
|
||||
|
||||
metadata?: Record<string, string>;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface IssuedInvoiceItemFullSnapshot {
|
||||
export interface IIssuedInvoiceItemFullSnapshot {
|
||||
id: string;
|
||||
is_valued: string;
|
||||
position: string;
|
||||
|
||||
@ -1,18 +1,17 @@
|
||||
import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { toEmptyString } from "@repo/rdx-ddd";
|
||||
|
||||
import type { CustomerInvoiceItems, IssuedInvoiceItem } from "../../../../domain";
|
||||
import type { IssuedInvoiceItemFullSnapshot } from "../../application-models";
|
||||
import type { IssuedInvoiceItem, IssuedInvoiceItems } from "../../../../domain";
|
||||
|
||||
import type { IIssuedInvoiceItemFullSnapshot } from "./issued-invoice-item-full-snapshot.interface";
|
||||
|
||||
export interface IIssuedInvoiceItemsFullSnapshotBuilder
|
||||
extends ISnapshotBuilder<CustomerInvoiceItems, IssuedInvoiceItemFullSnapshot[]> {}
|
||||
extends ISnapshotBuilder<IssuedInvoiceItems, IIssuedInvoiceItemFullSnapshot[]> {}
|
||||
|
||||
export class IssuedInvoiceItemsFullSnapshotBuilder
|
||||
implements IIssuedInvoiceItemsFullSnapshotBuilder
|
||||
{
|
||||
private mapItem(invoiceItem: IssuedInvoiceItem, index: number): IssuedInvoiceItemFullSnapshot {
|
||||
const allAmounts = invoiceItem.calculateAllAmounts();
|
||||
|
||||
private mapItem(invoiceItem: IssuedInvoiceItem, index: number): IIssuedInvoiceItemFullSnapshot {
|
||||
return {
|
||||
id: invoiceItem.id.toPrimitive(),
|
||||
is_valued: String(invoiceItem.isValued),
|
||||
@ -29,23 +28,23 @@ export class IssuedInvoiceItemsFullSnapshotBuilder
|
||||
() => ({ value: "", scale: "", currency_code: "" })
|
||||
),
|
||||
|
||||
subtotal_amount: allAmounts.subtotalAmount.toObjectString(),
|
||||
subtotal_amount: invoiceItem.subtotalAmount.toObjectString(),
|
||||
|
||||
discount_percentage: invoiceItem.itemDiscountPercentage.match(
|
||||
(discountPercentage) => discountPercentage.toObjectString(),
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
discount_amount: allAmounts.itemDiscountAmount.toObjectString(),
|
||||
discount_amount: invoiceItem.itemDiscountAmount.toObjectString(),
|
||||
|
||||
global_discount_percentage: invoiceItem.globalDiscountPercentage.match(
|
||||
(discountPercentage) => discountPercentage.toObjectString(),
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
global_discount_amount: allAmounts.globalDiscountAmount.toObjectString(),
|
||||
global_discount_amount: invoiceItem.globalDiscountAmount.toObjectString(),
|
||||
|
||||
taxable_amount: allAmounts.taxableAmount.toObjectString(),
|
||||
taxable_amount: invoiceItem.taxableAmount.toObjectString(),
|
||||
|
||||
iva_code: invoiceItem.taxes.iva.match(
|
||||
(iva) => iva.code,
|
||||
@ -57,7 +56,7 @@ export class IssuedInvoiceItemsFullSnapshotBuilder
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
iva_amount: allAmounts.ivaAmount.toObjectString(),
|
||||
iva_amount: invoiceItem.ivaAmount.toObjectString(),
|
||||
|
||||
rec_code: invoiceItem.taxes.rec.match(
|
||||
(rec) => rec.code,
|
||||
@ -69,7 +68,7 @@ export class IssuedInvoiceItemsFullSnapshotBuilder
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
rec_amount: allAmounts.recAmount.toObjectString(),
|
||||
rec_amount: invoiceItem.recAmount.toObjectString(),
|
||||
|
||||
retention_code: invoiceItem.taxes.retention.match(
|
||||
(retention) => retention.code,
|
||||
@ -81,15 +80,15 @@ export class IssuedInvoiceItemsFullSnapshotBuilder
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
retention_amount: allAmounts.retentionAmount.toObjectString(),
|
||||
retention_amount: invoiceItem.retentionAmount.toObjectString(),
|
||||
|
||||
taxes_amount: allAmounts.taxesAmount.toObjectString(),
|
||||
taxes_amount: invoiceItem.taxesAmount.toObjectString(),
|
||||
|
||||
total_amount: allAmounts.totalAmount.toObjectString(),
|
||||
total_amount: invoiceItem.totalAmount.toObjectString(),
|
||||
};
|
||||
}
|
||||
|
||||
toOutput(invoiceItems: CustomerInvoiceItems): IssuedInvoiceItemFullSnapshot[] {
|
||||
toOutput(invoiceItems: IssuedInvoiceItems): IIssuedInvoiceItemFullSnapshot[] {
|
||||
return invoiceItems.map((item, index) => this.mapItem(item, index));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { DomainValidationError, toEmptyString } from "@repo/rdx-ddd";
|
||||
|
||||
import type { InvoiceRecipient, Proforma } from "../../../../domain";
|
||||
import type { IssuedInvoiceRecipientFullSnapshot } from "../../application-models";
|
||||
import type { InvoiceRecipient, IssuedInvoice } from "../../../../domain";
|
||||
|
||||
import type { IIssuedInvoiceRecipientFullSnapshot } from "./issued-invoice-recipient-full-snapshot.interfce";
|
||||
|
||||
export interface IIssuedInvoiceRecipientFullSnapshotBuilder
|
||||
extends ISnapshotBuilder<Proforma, IssuedInvoiceRecipientFullSnapshot> {}
|
||||
extends ISnapshotBuilder<IssuedInvoice, IIssuedInvoiceRecipientFullSnapshot> {}
|
||||
|
||||
export class IssuedInvoiceRecipientFullSnapshotBuilder
|
||||
implements IIssuedInvoiceRecipientFullSnapshotBuilder
|
||||
{
|
||||
toOutput(invoice: Proforma): IssuedInvoiceRecipientFullSnapshot {
|
||||
toOutput(invoice: IssuedInvoice): IIssuedInvoiceRecipientFullSnapshot {
|
||||
if (!invoice.recipient) {
|
||||
throw DomainValidationError.requiredValue("recipient", {
|
||||
cause: invoice,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface IssuedInvoiceRecipientFullSnapshot {
|
||||
export interface IIssuedInvoiceRecipientFullSnapshot {
|
||||
id: string;
|
||||
name: string;
|
||||
tin: string;
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { DomainValidationError } from "@repo/rdx-ddd";
|
||||
|
||||
import type { Proforma } from "../../../../domain";
|
||||
import type { IssuedInvoiceVerifactuFullSnapshot } from "../../application-models";
|
||||
import type { IssuedInvoice } from "../../../../domain";
|
||||
|
||||
import type { IIssuedInvoiceVerifactuFullSnapshot } from "./issued-invoice-verifactu-full-snapshot.interface";
|
||||
|
||||
export interface IIssuedInvoiceVerifactuFullSnapshotBuilder
|
||||
extends ISnapshotBuilder<Proforma, IssuedInvoiceVerifactuFullSnapshot> {}
|
||||
extends ISnapshotBuilder<IssuedInvoice, IIssuedInvoiceVerifactuFullSnapshot> {}
|
||||
|
||||
export class IssuedInvoiceVerifactuFullSnapshotBuilder
|
||||
implements IIssuedInvoiceVerifactuFullSnapshotBuilder
|
||||
{
|
||||
toOutput(invoice: Proforma): IssuedInvoiceVerifactuFullSnapshot {
|
||||
toOutput(invoice: IssuedInvoice): IIssuedInvoiceVerifactuFullSnapshot {
|
||||
if (!invoice.verifactu) {
|
||||
throw DomainValidationError.requiredValue("verifactu", {
|
||||
cause: invoice,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface IssuedInvoiceVerifactuFullSnapshot {
|
||||
export interface IIssuedInvoiceVerifactuFullSnapshot {
|
||||
id: string;
|
||||
status: string;
|
||||
url: string;
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { toEmptyString } from "@repo/rdx-ddd";
|
||||
|
||||
import type { CustomerInvoiceListDTO } from "../../../../infrastructure";
|
||||
import type { IssuedInvoiceListItemSnapshot } from "../../application-models";
|
||||
import type { IssuedInvoiceListDTO } from "../../dtos";
|
||||
|
||||
import type { IIssuedInvoiceListItemSnapshot } from "./issued-invoice-list-item-snapshot.interface";
|
||||
|
||||
export interface IIssuedInvoiceListItemSnapshotBuilder
|
||||
extends ISnapshotBuilder<CustomerInvoiceListDTO, IssuedInvoiceListItemSnapshot> {}
|
||||
extends ISnapshotBuilder<IssuedInvoiceListDTO, IIssuedInvoiceListItemSnapshot> {}
|
||||
|
||||
export class IssuedInvoiceListItemSnapshotBuilder implements IIssuedInvoiceListItemSnapshotBuilder {
|
||||
toOutput(invoice: CustomerInvoiceListDTO): IssuedInvoiceListItemSnapshot {
|
||||
toOutput(invoice: IssuedInvoiceListDTO): IIssuedInvoiceListItemSnapshot {
|
||||
const recipient = invoice.recipient.toObjectString();
|
||||
|
||||
const verifactu = invoice.verifactu.match(
|
||||
@ -42,8 +43,7 @@ export class IssuedInvoiceListItemSnapshotBuilder implements IIssuedInvoiceListI
|
||||
currency_code: invoice.currencyCode.code,
|
||||
|
||||
subtotal_amount: invoice.subtotalAmount.toObjectString(),
|
||||
discount_percentage: invoice.discountPercentage.toObjectString(),
|
||||
discount_amount: invoice.discountAmount.toObjectString(),
|
||||
total_discount_amount: invoice.totalDiscountAmount.toObjectString(),
|
||||
taxable_amount: invoice.taxableAmount.toObjectString(),
|
||||
taxes_amount: invoice.taxesAmount.toObjectString(),
|
||||
total_amount: invoice.totalAmount.toObjectString(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface IssuedInvoiceListItemSnapshot {
|
||||
export interface IIssuedInvoiceListItemSnapshot {
|
||||
id: string;
|
||||
company_id: string;
|
||||
is_proforma: boolean;
|
||||
@ -30,8 +30,7 @@ export interface IssuedInvoiceListItemSnapshot {
|
||||
};
|
||||
|
||||
subtotal_amount: { value: string; scale: string; currency_code: string };
|
||||
discount_percentage: { value: string; scale: string };
|
||||
discount_amount: { value: string; scale: string; currency_code: string };
|
||||
total_discount_amount: { value: string; scale: string; currency_code: string };
|
||||
taxable_amount: { value: string; scale: string; currency_code: string };
|
||||
taxes_amount: { value: string; scale: string; currency_code: string };
|
||||
total_amount: { value: string; scale: string; currency_code: string };
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import type { ICustomerInvoiceRepository } from "../../../domain/repositories";
|
||||
import { ProformaFactory } from "../factories";
|
||||
import type { IProformaRepository } from "../repositories";
|
||||
import { type IProformaCreator, type IProformaNumberGenerator, ProformaCreator } from "../services";
|
||||
|
||||
export function buildProformaCreator(
|
||||
export const buildProformaCreator = (
|
||||
numberService: IProformaNumberGenerator,
|
||||
repository: ICustomerInvoiceRepository
|
||||
): IProformaCreator {
|
||||
repository: IProformaRepository
|
||||
): IProformaCreator => {
|
||||
return new ProformaCreator({
|
||||
numberService,
|
||||
factory: new ProformaFactory(),
|
||||
repository,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { CurrencyCode, LanguageCode, Percentage, UniqueID, UtcDate } from "@repo/rdx-ddd";
|
||||
import type { CurrencyCode, LanguageCode, UniqueID, UtcDate } from "@repo/rdx-ddd";
|
||||
import type { Maybe } from "@repo/rdx-utils";
|
||||
|
||||
import type {
|
||||
@ -30,10 +30,8 @@ export type ProformaListDTO = {
|
||||
languageCode: LanguageCode;
|
||||
currencyCode: CurrencyCode;
|
||||
|
||||
discountPercentage: Percentage;
|
||||
|
||||
subtotalAmount: InvoiceAmount;
|
||||
discountAmount: InvoiceAmount;
|
||||
totalDiscountAmount: InvoiceAmount;
|
||||
taxableAmount: InvoiceAmount;
|
||||
taxesAmount: InvoiceAmount;
|
||||
totalAmount: InvoiceAmount;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export * from "./create-proforma-props.mapper";
|
||||
export * from "./proforma-domain-mapper.interface";
|
||||
export * from "./proforma-list-mapper.interface";
|
||||
export * from "./update-proforma-props.mapper";
|
||||
//export * from "./update-proforma-props.mapper";
|
||||
|
||||
@ -106,7 +106,7 @@ export class ProformaFullSnapshotBuilder implements IProformaFullSnapshotBuilder
|
||||
subtotal_amount: allAmounts.subtotalAmount.toObjectString(),
|
||||
items_discount_amount: allAmounts.itemDiscountAmount.toObjectString(),
|
||||
|
||||
discount_percentage: invoice.discountPercentage.toObjectString(),
|
||||
discount_percentage: invoice.globalDiscountPercentage.toObjectString(),
|
||||
discount_amount: allAmounts.globalDiscountAmount.toObjectString(),
|
||||
|
||||
taxable_amount: allAmounts.taxableAmount.toObjectString(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface ProformaListItemSnapshot {
|
||||
export interface IProformaListItemSnapshot {
|
||||
id: string;
|
||||
company_id: string;
|
||||
is_proforma: boolean;
|
||||
|
||||
@ -2,5 +2,6 @@ export * from "./proforma-items-report-snapshot-builder";
|
||||
export * from "./proforma-report-item-snapshot.interface";
|
||||
export * from "./proforma-report-snapshot.interface";
|
||||
export * from "./proforma-report-snapshot-builder";
|
||||
export * from "./proforma-report-snapshot-builder";
|
||||
export * from "./proforma-report-tax-snapshot.interface";
|
||||
export * from "./proforma-tax-report-snapshot-builder";
|
||||
|
||||
@ -109,7 +109,7 @@ export class ProformaFullPresenter extends Presenter<Proforma, GetProformaByIdRe
|
||||
subtotal_amount: allAmounts.subtotalAmount.toObjectString(),
|
||||
items_discount_amount: allAmounts.itemDiscountAmount.toObjectString(),
|
||||
|
||||
discount_percentage: proforma.discountPercentage.toObjectString(),
|
||||
discount_percentage: proforma.globalDiscountPercentage.toObjectString(),
|
||||
discount_amount: allAmounts.globalDiscountAmount.toObjectString(),
|
||||
|
||||
taxable_amount: allAmounts.taxableAmount.toObjectString(),
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export * from "./issued-invoice.aggregate";
|
||||
@ -51,7 +51,7 @@ export type IssuedInvoiceProps = {
|
||||
subtotalAmount: InvoiceAmount;
|
||||
|
||||
itemDiscountAmount: InvoiceAmount;
|
||||
discountPercentage: Percentage;
|
||||
globalDiscountPercentage: Percentage;
|
||||
globalDiscountAmount: InvoiceAmount;
|
||||
totalDiscountAmount: InvoiceAmount;
|
||||
|
||||
@ -77,7 +77,7 @@ export class IssuedInvoice extends AggregateRoot<IssuedInvoiceProps> {
|
||||
IssuedInvoiceItems.create({
|
||||
languageCode: props.languageCode,
|
||||
currencyCode: props.currencyCode,
|
||||
globalDiscountPercentage: props.discountPercentage,
|
||||
globalDiscountPercentage: props.globalDiscountPercentage,
|
||||
});
|
||||
}
|
||||
|
||||
@ -170,8 +170,36 @@ export class IssuedInvoice extends AggregateRoot<IssuedInvoiceProps> {
|
||||
return this.props.verifactu;
|
||||
}
|
||||
|
||||
public get discountPercentage(): Percentage {
|
||||
return this.props.discountPercentage;
|
||||
public get subtotalAmount(): InvoiceAmount {
|
||||
return this.props.subtotalAmount;
|
||||
}
|
||||
|
||||
public get itemDiscountAmount(): InvoiceAmount {
|
||||
return this.props.itemDiscountAmount;
|
||||
}
|
||||
|
||||
public get globalDiscountPercentage(): Percentage {
|
||||
return this.props.globalDiscountPercentage;
|
||||
}
|
||||
|
||||
public get globalDiscountAmount(): InvoiceAmount {
|
||||
return this.props.globalDiscountAmount;
|
||||
}
|
||||
|
||||
public get totalDiscountAmount(): InvoiceAmount {
|
||||
return this.props.totalDiscountAmount;
|
||||
}
|
||||
|
||||
public get taxableAmount(): InvoiceAmount {
|
||||
return this.props.taxableAmount;
|
||||
}
|
||||
|
||||
public get taxesAmount(): InvoiceAmount {
|
||||
return this.props.taxesAmount;
|
||||
}
|
||||
|
||||
public get totalAmount(): InvoiceAmount {
|
||||
return this.props.totalAmount;
|
||||
}
|
||||
|
||||
public get taxes(): IssuedInvoiceTaxes {
|
||||
@ -1,4 +1,4 @@
|
||||
export * from "./issued-invoice-items";
|
||||
export * from "./issued-invoice-tax-group.entity";
|
||||
export * from "./issued-invoice-taxes.entity";
|
||||
export * from "./issued-invoice-tax.entity";
|
||||
export * from "./issued-invoice-taxes.collection";
|
||||
export * from "./verifactu-record.entity";
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
import { DomainEntity, type Percentage, type UniqueID } from "@repo/rdx-ddd";
|
||||
import { type Maybe, Result } from "@repo/rdx-utils";
|
||||
|
||||
import type { InvoiceAmount } from "../../common";
|
||||
|
||||
export type IssuedInvoiceTaxGroupProps = {
|
||||
taxableAmount: InvoiceAmount;
|
||||
|
||||
ivaCode: string;
|
||||
ivaPercentage: Percentage;
|
||||
ivaAmount: InvoiceAmount;
|
||||
|
||||
recCode: Maybe<string>;
|
||||
recPercentage: Maybe<Percentage>;
|
||||
recAmount: InvoiceAmount;
|
||||
|
||||
retentionCode: Maybe<string>;
|
||||
retentionPercentage: Maybe<Percentage>;
|
||||
retentionAmount: InvoiceAmount;
|
||||
|
||||
totalAmount: InvoiceAmount;
|
||||
};
|
||||
|
||||
export class IssuedInvoiceTaxGroup extends DomainEntity<IssuedInvoiceTaxGroupProps> {
|
||||
public static create(
|
||||
props: IssuedInvoiceTaxGroupProps,
|
||||
id?: UniqueID
|
||||
): Result<IssuedInvoiceTaxGroup, Error> {
|
||||
return Result.ok(new IssuedInvoiceTaxGroup(props, id));
|
||||
}
|
||||
|
||||
public getProps(): IssuedInvoiceTaxGroupProps {
|
||||
return this.props;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
import { DomainEntity, type Percentage, type UniqueID } from "@repo/rdx-ddd";
|
||||
import { type Maybe, Result } from "@repo/rdx-utils";
|
||||
|
||||
import type { InvoiceAmount } from "../../common";
|
||||
|
||||
export type IssuedInvoiceTaxProps = {
|
||||
taxableAmount: InvoiceAmount;
|
||||
|
||||
ivaCode: string;
|
||||
ivaPercentage: Percentage;
|
||||
ivaAmount: InvoiceAmount;
|
||||
|
||||
recCode: Maybe<string>;
|
||||
recPercentage: Maybe<Percentage>;
|
||||
recAmount: InvoiceAmount;
|
||||
|
||||
retentionCode: Maybe<string>;
|
||||
retentionPercentage: Maybe<Percentage>;
|
||||
retentionAmount: InvoiceAmount;
|
||||
|
||||
taxesAmount: InvoiceAmount;
|
||||
};
|
||||
|
||||
export class IssuedInvoiceTax extends DomainEntity<IssuedInvoiceTaxProps> {
|
||||
public static create(
|
||||
props: IssuedInvoiceTaxProps,
|
||||
id?: UniqueID
|
||||
): Result<IssuedInvoiceTax, Error> {
|
||||
return Result.ok(new IssuedInvoiceTax(props, id));
|
||||
}
|
||||
|
||||
public get taxableAmount(): InvoiceAmount {
|
||||
return this.props.taxableAmount;
|
||||
}
|
||||
|
||||
public get ivaCode(): string {
|
||||
return this.props.ivaCode;
|
||||
}
|
||||
public get ivaPercentage(): Percentage {
|
||||
return this.props.ivaPercentage;
|
||||
}
|
||||
public get ivaAmount(): InvoiceAmount {
|
||||
return this.props.ivaAmount;
|
||||
}
|
||||
|
||||
public get recCode(): Maybe<string> {
|
||||
return this.props.recCode;
|
||||
}
|
||||
public get recPercentage(): Maybe<Percentage> {
|
||||
return this.props.recPercentage;
|
||||
}
|
||||
public get recAmount(): InvoiceAmount {
|
||||
return this.props.recAmount;
|
||||
}
|
||||
|
||||
public get retentionCode(): Maybe<string> {
|
||||
return this.props.retentionCode;
|
||||
}
|
||||
public get retentionPercentage(): Maybe<Percentage> {
|
||||
return this.props.retentionPercentage;
|
||||
}
|
||||
public get retentionAmount(): InvoiceAmount {
|
||||
return this.props.retentionAmount;
|
||||
}
|
||||
|
||||
public get taxesAmount(): InvoiceAmount {
|
||||
return this.props.taxesAmount;
|
||||
}
|
||||
|
||||
public getProps(): IssuedInvoiceTaxProps {
|
||||
return this.props;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { Collection } from "@repo/rdx-utils";
|
||||
|
||||
import type { IssuedInvoiceTax } from "./issued-invoice-tax.entity";
|
||||
|
||||
export class IssuedInvoiceTaxes extends Collection<IssuedInvoiceTax> {
|
||||
constructor(items: IssuedInvoiceTax[] = []) {
|
||||
super(items);
|
||||
}
|
||||
|
||||
public static create(items: IssuedInvoiceTax[] = []): IssuedInvoiceTaxes {
|
||||
return new IssuedInvoiceTaxes(items);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { Collection } from "@repo/rdx-utils";
|
||||
|
||||
import type { IssuedInvoiceTaxGroup } from "./issued-invoice-tax-group.entity";
|
||||
|
||||
export class IssuedInvoiceTaxes extends Collection<IssuedInvoiceTaxGroup> {
|
||||
constructor(items: IssuedInvoiceTaxGroup[] = []) {
|
||||
super(items);
|
||||
}
|
||||
|
||||
public static create(items: IssuedInvoiceTaxGroup[] = []): IssuedInvoiceTaxes {
|
||||
return new IssuedInvoiceTaxes(items);
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./aggregates";
|
||||
export * from "./entities";
|
||||
export * from "./issued-invoice.aggregate";
|
||||
export * from "./errors";
|
||||
export * from "./value-objects";
|
||||
|
||||
@ -1,2 +1 @@
|
||||
export * from "./invoice-tax-group.vo";
|
||||
export * from "./verifactu-status.vo";
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export * from "./proforma.aggregate";
|
||||
@ -10,7 +10,7 @@ import {
|
||||
} from "@repo/rdx-ddd";
|
||||
import { Collection, type Maybe, Result } from "@repo/rdx-utils";
|
||||
|
||||
import type { InvoicePaymentMethod } from "../common/entities";
|
||||
import type { InvoicePaymentMethod } from "../../common/entities";
|
||||
import {
|
||||
InvoiceAmount,
|
||||
type InvoiceNumber,
|
||||
@ -19,9 +19,8 @@ import {
|
||||
type InvoiceStatus,
|
||||
InvoiceTaxGroup,
|
||||
type ItemAmount,
|
||||
} from "../common/value-objects";
|
||||
|
||||
import { ProformaItems } from "./proforma-items";
|
||||
} from "../../common/value-objects";
|
||||
import { ProformaItems } from "../entities/proforma-items";
|
||||
|
||||
export type ProformaProps = {
|
||||
companyId: UniqueID;
|
||||
@ -49,7 +48,7 @@ export type ProformaProps = {
|
||||
|
||||
paymentMethod: Maybe<InvoicePaymentMethod>;
|
||||
|
||||
discountPercentage: Percentage;
|
||||
globalDiscountPercentage: Percentage;
|
||||
};
|
||||
|
||||
export type ProformaPatchProps = Partial<Omit<ProformaProps, "companyId" | "items">> & {
|
||||
@ -66,7 +65,7 @@ export class Proforma extends AggregateRoot<ProformaProps> {
|
||||
ProformaItems.create({
|
||||
languageCode: props.languageCode,
|
||||
currencyCode: props.currencyCode,
|
||||
globalDiscountPercentage: props.discountPercentage,
|
||||
globalDiscountPercentage: props.globalDiscountPercentage,
|
||||
});
|
||||
}
|
||||
|
||||
@ -177,8 +176,8 @@ export class Proforma extends AggregateRoot<ProformaProps> {
|
||||
return this.props.currencyCode;
|
||||
}
|
||||
|
||||
public get discountPercentage(): Percentage {
|
||||
return this.props.discountPercentage;
|
||||
public get globalDiscountPercentage(): Percentage {
|
||||
return this.props.globalDiscountPercentage;
|
||||
}
|
||||
|
||||
// Method to get the complete list of line items
|
||||
@ -273,10 +272,6 @@ export class Proforma extends AggregateRoot<ProformaProps> {
|
||||
return this.calculateAllAmounts().totalAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Agrupa impuestos a nivel factura usando el trío (iva|rec|ret),
|
||||
* construyendo InvoiceTaxGroup desde los datos de los ítems.
|
||||
*/
|
||||
/**
|
||||
* @summary Agrupa impuestos a nivel factura usando el trío (iva|rec|ret),
|
||||
* construyendo InvoiceTaxGroup desde los datos de los ítems.
|
||||
@ -0,0 +1 @@
|
||||
export * from "./proforma-items";
|
||||
@ -7,7 +7,7 @@ import {
|
||||
ItemDiscount,
|
||||
ItemQuantity,
|
||||
type ItemTaxGroup,
|
||||
} from "../../common";
|
||||
} from "../../../common";
|
||||
|
||||
/**
|
||||
*
|
||||
@ -1,7 +1,7 @@
|
||||
import type { CurrencyCode, LanguageCode, Percentage } from "@repo/rdx-ddd";
|
||||
import { Collection } from "@repo/rdx-utils";
|
||||
|
||||
import { ItemAmount, ItemDiscount, type ItemTaxGroup } from "../../common";
|
||||
import { ItemAmount, ItemDiscount, type ItemTaxGroup } from "../../../common";
|
||||
|
||||
import type { ProformaItem } from "./proforma-item.entity";
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export * from "./proforma.aggregate";
|
||||
export * from "./proforma-items";
|
||||
export * from "./aggregates";
|
||||
export * from "./entities";
|
||||
export * from "./errors";
|
||||
|
||||
@ -4,9 +4,9 @@ import {
|
||||
type IssuedInvoicesInternalDeps,
|
||||
buildIssuedInvoicesDependencies,
|
||||
buildProformaServices,
|
||||
issuedInvoicesRouter,
|
||||
models,
|
||||
} from "./infrastructure";
|
||||
import { issuedInvoicesRouter } from "./infrastructure/express";
|
||||
|
||||
export const customerInvoicesAPIModule: IModuleServer = {
|
||||
name: "customer-invoices",
|
||||
|
||||
@ -379,8 +379,8 @@ export class CustomerInvoiceDomainMapper
|
||||
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
||||
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
||||
|
||||
discount_percentage_value: source.discountPercentage.toPrimitive().value,
|
||||
discount_percentage_scale: source.discountPercentage.toPrimitive().scale,
|
||||
discount_percentage_value: source.globalDiscountPercentage.toPrimitive().value,
|
||||
discount_percentage_scale: source.globalDiscountPercentage.toPrimitive().scale,
|
||||
|
||||
discount_amount_value: allAmounts.globalDiscountAmount.value,
|
||||
discount_amount_scale: allAmounts.globalDiscountAmount.scale,
|
||||
|
||||
@ -68,13 +68,21 @@ export class CustomerInvoiceModel extends Model<
|
||||
declare subtotal_amount_value: number;
|
||||
declare subtotal_amount_scale: number;
|
||||
|
||||
// Discount percentage
|
||||
declare discount_percentage_value: number;
|
||||
declare discount_percentage_scale: number;
|
||||
// Items discount amount (suma de descuentos individuales por ítem)
|
||||
declare items_discount_amount_value: number;
|
||||
declare items_discount_amount_scale: number;
|
||||
|
||||
// Discount amount
|
||||
declare discount_amount_value: number;
|
||||
declare discount_amount_scale: number;
|
||||
// Global/header discount percentage
|
||||
declare global_discount_percentage_value: number;
|
||||
declare global_discount_percentage_scale: number;
|
||||
|
||||
// Global/header discount amount
|
||||
declare global_discount_amount_value: number;
|
||||
declare global_discount_amount_scale: number;
|
||||
|
||||
// Total discount amount (subtotal - descuentos)
|
||||
declare total_discount_amount_value: number;
|
||||
declare total_discount_amount_scale: number;
|
||||
|
||||
// Taxable amount (base imponible)
|
||||
declare taxable_amount_value: number;
|
||||
@ -283,25 +291,49 @@ export default (database: Sequelize) => {
|
||||
defaultValue: 2,
|
||||
},
|
||||
|
||||
discount_percentage_value: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
discount_percentage_scale: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 2,
|
||||
},
|
||||
|
||||
discount_amount_value: {
|
||||
items_discount_amount_value: {
|
||||
type: new DataTypes.BIGINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
discount_amount_scale: {
|
||||
items_discount_amount_scale: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 2,
|
||||
},
|
||||
|
||||
global_discount_percentage_value: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
global_discount_percentage_scale: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 2,
|
||||
},
|
||||
|
||||
global_discount_amount_value: {
|
||||
type: new DataTypes.BIGINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
global_discount_amount_scale: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 2,
|
||||
},
|
||||
|
||||
total_discount_amount_value: {
|
||||
type: new DataTypes.BIGINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
total_discount_amount_scale: {
|
||||
type: new DataTypes.SMALLINT(),
|
||||
allowNull: false,
|
||||
defaultValue: 2,
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export * from "./get-issued-invoice-by-id.controller";
|
||||
//export * from "./list-issued-invoices.controller";
|
||||
//export * from "./report-issued-invoice.controller";
|
||||
@ -1,2 +1,3 @@
|
||||
export * from "./controllers";
|
||||
export * from "../../issued-invoices/express";
|
||||
|
||||
export * from "./issued-invoices.routes";
|
||||
|
||||
@ -8,11 +8,12 @@ import {
|
||||
ReportIssueInvoiceByIdParamsRequestSchema,
|
||||
ReportIssueInvoiceByIdQueryRequestSchema,
|
||||
} from "../../../../common/dto";
|
||||
import {
|
||||
GetIssuedInvoiceByIdController,
|
||||
ReportIssuedInvoiceController,
|
||||
} from "../../issued-invoices";
|
||||
import type { IssuedInvoicesInternalDeps } from "../../issued-invoices/di";
|
||||
|
||||
import { GetIssuedInvoiceByIdController } from "./controllers";
|
||||
import { ListIssuedInvoicesController } from "./controllers/list-issued-invoices.controller";
|
||||
import { ReportIssuedInvoiceController } from "./controllers/report-issued-invoice.controller";
|
||||
import { ListIssuedInvoicesController } from "../../issued-invoices/express/list-issued-invoices.controller";
|
||||
|
||||
export const issuedInvoicesRouter = (params: ModuleParams, deps: IssuedInvoicesInternalDeps) => {
|
||||
const { app, config } = params;
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
export * from "./change-status-proforma.controller";
|
||||
export * from "./create-proforma.controller";
|
||||
export * from "./delete-proforma.controller";
|
||||
export * from "./get-proforma.controller";
|
||||
export * from "./issue-proforma.controller";
|
||||
export * from "./list-proformas.controller";
|
||||
export * from "./report-proforma.controller";
|
||||
export * from "./update-proforma.controller";
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./controllers";
|
||||
export * from "../../proformas/express";
|
||||
|
||||
export * from "./proformas.routes";
|
||||
export * from "./proformas-api-error-mapper";
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
type ErrorToApiRule,
|
||||
ValidationApiError,
|
||||
} from "@erp/core/api";
|
||||
import { isProformaCannotBeDeletedError } from "@erp/customer-invoices/api/domain/errors";
|
||||
|
||||
import {
|
||||
type CustomerInvoiceIdAlreadyExistsError,
|
||||
@ -17,7 +18,6 @@ import {
|
||||
isEntityIsNotProformaError,
|
||||
isInvalidProformaTransitionError,
|
||||
isProformaCannotBeConvertedToInvoiceError,
|
||||
isProformaCannotBeDeletedError,
|
||||
} from "../../../domain";
|
||||
|
||||
// Crea una regla específica (prioridad alta para sobreescribir mensajes)
|
||||
|
||||
@ -16,7 +16,6 @@ import {
|
||||
UpdateProformaByIdRequestSchema,
|
||||
} from "../../../../common";
|
||||
import type { IssuedInvoicesInternalDeps } from "../../issued-invoices/di";
|
||||
|
||||
import {
|
||||
ChangeStatusProformaController,
|
||||
CreateProformaController,
|
||||
@ -26,7 +25,7 @@ import {
|
||||
ListProformasController,
|
||||
ReportProformaController,
|
||||
UpdateProformaController,
|
||||
} from "./controllers";
|
||||
} from "../../proformas/express";
|
||||
|
||||
export const proformasRouter = (params: ModuleParams, deps: IssuedInvoicesInternalDeps) => {
|
||||
const { app, config } = params;
|
||||
|
||||
@ -1,29 +1,19 @@
|
||||
import { SpainTaxCatalogProvider } from "@erp/core";
|
||||
import { InMemoryMapperRegistry } from "@erp/core/api";
|
||||
import type { Sequelize } from "sequelize";
|
||||
|
||||
import {
|
||||
CustomerInvoiceDomainMapper,
|
||||
CustomerInvoiceListMapper,
|
||||
CustomerInvoiceRepository,
|
||||
} from "../../common/persistence";
|
||||
IssuedInvoiceRepository,
|
||||
SequelizeIssuedInvoiceDomainMapper,
|
||||
SequelizeIssuedInvoiceListMapper,
|
||||
} from "../persistence";
|
||||
|
||||
export const buildIssuedInvoiceRepository = (database: Sequelize) => {
|
||||
const mapperRegistry = new InMemoryMapperRegistry();
|
||||
|
||||
const taxCatalog = SpainTaxCatalogProvider();
|
||||
|
||||
mapperRegistry
|
||||
.registerDomainMapper(
|
||||
{ resource: "customer-invoice" },
|
||||
new CustomerInvoiceDomainMapper({ taxCatalog })
|
||||
)
|
||||
.registerQueryMappers([
|
||||
{
|
||||
key: { resource: "customer-invoice", query: "LIST" },
|
||||
mapper: new CustomerInvoiceListMapper(),
|
||||
},
|
||||
]);
|
||||
const domainMapper = new SequelizeIssuedInvoiceDomainMapper({
|
||||
taxCatalog,
|
||||
});
|
||||
const listMapper = new SequelizeIssuedInvoiceListMapper();
|
||||
|
||||
return new CustomerInvoiceRepository({ mapperRegistry, database });
|
||||
return new IssuedInvoiceRepository(domainMapper, listMapper, database);
|
||||
};
|
||||
|
||||
@ -5,9 +5,9 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import { GetIssuedInvoiceByIdResponseSchema } from "../../../../../common";
|
||||
import type { GetIssuedInvoiceByIdUseCase } from "../../../../application/issued-invoices";
|
||||
import { customerInvoicesApiErrorMapper } from "../../proformas/proformas-api-error-mapper.ts";
|
||||
import { GetIssuedInvoiceByIdResponseSchema } from "../../../../common/index.ts";
|
||||
import type { GetIssuedInvoiceByIdUseCase } from "../../../application/issued-invoices/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class GetIssuedInvoiceByIdController extends ExpressController {
|
||||
public constructor(private readonly useCase: GetIssuedInvoiceByIdUseCase) {
|
||||
@ -0,0 +1,3 @@
|
||||
export * from "./get-issued-invoice-by-id.controller";
|
||||
export * from "./list-issued-invoices.controller";
|
||||
export * from "./report-issued-invoice.controller";
|
||||
@ -6,9 +6,9 @@ import {
|
||||
} from "@erp/core/api";
|
||||
import { Criteria } from "@repo/rdx-criteria/server";
|
||||
|
||||
import { ListIssuedInvoicesResponseSchema } from "../../../../../common";
|
||||
import type { ListIssuedInvoicesUseCase } from "../../../../application/issued-invoices";
|
||||
import { customerInvoicesApiErrorMapper } from "../../proformas/proformas-api-error-mapper.ts";
|
||||
import { ListIssuedInvoicesResponseSchema } from "../../../../common/index.ts";
|
||||
import type { ListIssuedInvoicesUseCase } from "../../../application/issued-invoices/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class ListIssuedInvoicesController extends ExpressController {
|
||||
public constructor(private readonly useCase: ListIssuedInvoicesUseCase) {
|
||||
@ -7,8 +7,8 @@ import {
|
||||
} from "@erp/core/api";
|
||||
import type { ReportIssueInvoiceByIdQueryRequestDTO } from "@erp/customer-invoices/common";
|
||||
|
||||
import type { ReportIssuedInvoiceUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../../proformas/proformas-api-error-mapper.ts";
|
||||
import type { ReportIssuedInvoiceUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class ReportIssuedInvoiceController extends ExpressController {
|
||||
public constructor(private readonly useCase: ReportIssuedInvoiceUseCase) {
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./di";
|
||||
export * from "./documents";
|
||||
export * from "./express";
|
||||
export * from "./persistence";
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
export * from "./mappers";
|
||||
export * from "./repositories";
|
||||
export * from "./services";
|
||||
|
||||
@ -16,13 +16,13 @@ import { Maybe, Result, isNullishOrEmpty } from "@repo/rdx-utils";
|
||||
|
||||
import type { IIssuedInvoiceDomainMapper } from "../../../../../../application";
|
||||
import {
|
||||
CustomerInvoiceItems,
|
||||
type IIssuedInvoiceProps,
|
||||
InvoiceNumber,
|
||||
InvoicePaymentMethod,
|
||||
InvoiceSerie,
|
||||
InvoiceStatus,
|
||||
IssuedInvoice,
|
||||
IssuedInvoiceItems,
|
||||
type IssuedInvoiceProps,
|
||||
} from "../../../../../../domain";
|
||||
import type {
|
||||
CustomerInvoiceCreationAttributes,
|
||||
@ -52,7 +52,7 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
|
||||
this._itemsMapper = new SequelizeIssuedInvoiceItemDomainMapper(params); // Instanciar el mapper de items
|
||||
this._recipientMapper = new SequelizeIssuedInvoiceRecipientDomainMapper();
|
||||
this._taxesMapper = new SequelizeIssuedInvoiceTaxesDomainMapper(params);
|
||||
this._taxesMapper = new SequelizeIssuedInvoiceTaxesDomainMapper();
|
||||
this._verifactuMapper = new SequelizeIssuedInvoiceVerifactuDomainMapper();
|
||||
}
|
||||
|
||||
@ -236,17 +236,16 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
|
||||
// 6) Construcción del agregado (Dominio)
|
||||
|
||||
const items = CustomerInvoiceItems.create({
|
||||
const items = IssuedInvoiceItems.create({
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
globalDiscountPercentage: attributes.discountPercentage!,
|
||||
items: itemsResults.data.getAll(),
|
||||
});
|
||||
|
||||
const invoiceProps: IIssuedInvoiceProps = {
|
||||
const invoiceProps: IssuedInvoiceProps = {
|
||||
companyId: attributes.companyId!,
|
||||
|
||||
isIssuedInvoice: attributes.isIssuedInvoice,
|
||||
proformaId: attributes.proformaId!,
|
||||
status: attributes.status!,
|
||||
series: attributes.series!,
|
||||
@ -264,7 +263,7 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
|
||||
discountPercentage: attributes.discountPercentage!,
|
||||
globalDiscountPercentage: attributes.discountPercentage!,
|
||||
|
||||
paymentMethod: attributes.paymentMethod!,
|
||||
|
||||
@ -309,7 +308,7 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
}
|
||||
|
||||
// 2) Taxes
|
||||
const taxesResult = this._taxesMapper.mapToPersistenceArray(source.getTaxes(), {
|
||||
const taxesResult = this._taxesMapper.mapToPersistenceArray(source.taxes, {
|
||||
errors,
|
||||
parent: source,
|
||||
...params,
|
||||
@ -347,8 +346,6 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
const taxes = taxesResult.data;
|
||||
const verifactu = verifactuResult.data;
|
||||
|
||||
const allAmounts = source.calculateAllAmounts(); // Da los totales ya calculados
|
||||
|
||||
const invoiceValues: Partial<CustomerInvoiceCreationAttributes> = {
|
||||
// Identificación
|
||||
id: source.id.toPrimitive(),
|
||||
@ -356,11 +353,11 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
|
||||
// Flags / estado / serie / número
|
||||
is_proforma: false,
|
||||
proforma_id: toNullable(source.proformaId, (v) => v.toPrimitive()),
|
||||
status: source.status.toPrimitive(),
|
||||
proforma_id: toNullable(source.proformaId, (v) => v.toPrimitive()),
|
||||
|
||||
series: toNullable(source.series, (v) => v.toPrimitive()),
|
||||
invoice_number: source.invoiceNumber.toPrimitive(),
|
||||
|
||||
invoice_date: source.invoiceDate.toPrimitive(),
|
||||
operation_date: toNullable(source.operationDate, (v) => v.toPrimitive()),
|
||||
language_code: source.languageCode.toPrimitive(),
|
||||
@ -368,13 +365,20 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
|
||||
reference: toNullable(source.reference, (reference) => reference),
|
||||
description: toNullable(source.description, (description) => description),
|
||||
|
||||
notes: toNullable(source.notes, (v) => v.toPrimitive()),
|
||||
|
||||
payment_method_id: toNullable(source.paymentMethod, (payment) => payment.toObjectString().id),
|
||||
payment_method_description: toNullable(
|
||||
source.paymentMethod,
|
||||
(payment) => payment.toObjectString().payment_description
|
||||
),
|
||||
|
||||
subtotal_amount_value: source.subtotalAmount.value,
|
||||
subtotal_amount_scale: source.subtotalAmount.scale,
|
||||
|
||||
discount_percentage_value: source.discountPercentage.toPrimitive().value,
|
||||
discount_percentage_scale: source.discountPercentage.toPrimitive().scale,
|
||||
discount_percentage_value: source.globalDiscountPercentage.toPrimitive().value,
|
||||
discount_percentage_scale: source.globalDiscountPercentage.toPrimitive().scale,
|
||||
|
||||
discount_amount_value: source.globalDiscountAmount.value,
|
||||
discount_amount_scale: source.globalDiscountAmount.scale,
|
||||
@ -388,12 +392,6 @@ export class SequelizeIssuedInvoiceDomainMapper
|
||||
total_amount_value: source.totalAmount.value,
|
||||
total_amount_scale: source.totalAmount.scale,
|
||||
|
||||
payment_method_id: toNullable(source.paymentMethod, (payment) => payment.toObjectString().id),
|
||||
payment_method_description: toNullable(
|
||||
source.paymentMethod,
|
||||
(payment) => payment.toObjectString().payment_description
|
||||
),
|
||||
|
||||
customer_id: source.customerId.toPrimitive(),
|
||||
...recipient,
|
||||
|
||||
|
||||
@ -14,11 +14,10 @@ import {
|
||||
} from "@repo/rdx-ddd";
|
||||
import { Result } from "@repo/rdx-utils";
|
||||
|
||||
import type { IssuedInvoiceListDTO } from "../../../../../../application";
|
||||
import { InvoiceRecipient } from "../../../../../../domain";
|
||||
import type { CustomerInvoiceModel } from "../../../../../common";
|
||||
|
||||
import type { CustomerInvoiceListDTO } from "./sequelize-issued-invoice.list.mapper";
|
||||
|
||||
export class SequelizeIssuedInvoiceRecipientListMapper extends SequelizeQueryMapper<
|
||||
CustomerInvoiceModel,
|
||||
InvoiceRecipient
|
||||
@ -33,7 +32,7 @@ export class SequelizeIssuedInvoiceRecipientListMapper extends SequelizeQueryMap
|
||||
|
||||
const { errors, attributes } = params as {
|
||||
errors: ValidationErrorDetail[];
|
||||
attributes: Partial<CustomerInvoiceListDTO>;
|
||||
attributes: Partial<IssuedInvoiceListDTO>;
|
||||
};
|
||||
|
||||
const { isProforma } = attributes;
|
||||
|
||||
@ -2,7 +2,6 @@ import { type MapperParamsType, SequelizeQueryMapper } from "@erp/core/api";
|
||||
import {
|
||||
CurrencyCode,
|
||||
LanguageCode,
|
||||
Percentage,
|
||||
UniqueID,
|
||||
UtcDate,
|
||||
ValidationErrorCollection,
|
||||
@ -94,7 +93,7 @@ export class SequelizeIssuedInvoiceListMapper
|
||||
operationDate: attributes.operationDate!,
|
||||
|
||||
description: attributes.description!,
|
||||
reference: attributes.description!,
|
||||
reference: attributes.reference!,
|
||||
|
||||
customerId: attributes.customerId!,
|
||||
recipient: recipientResult.data,
|
||||
@ -102,9 +101,8 @@ export class SequelizeIssuedInvoiceListMapper
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
|
||||
discountPercentage: attributes.discountPercentage!,
|
||||
subtotalAmount: attributes.subtotalAmount!,
|
||||
discountAmount: attributes.discountAmount!,
|
||||
totalDiscountAmount: attributes.totalDiscountAmount!,
|
||||
taxableAmount: attributes.taxableAmount!,
|
||||
taxesAmount: attributes.taxesAmount!,
|
||||
totalAmount: attributes.totalAmount!,
|
||||
@ -175,15 +173,6 @@ export class SequelizeIssuedInvoiceListMapper
|
||||
errors
|
||||
);
|
||||
|
||||
const discountPercentage = extractOrPushError(
|
||||
Percentage.create({
|
||||
value: raw.discount_percentage_value,
|
||||
scale: raw.discount_percentage_scale,
|
||||
}),
|
||||
"discount_percentage_value",
|
||||
errors
|
||||
);
|
||||
|
||||
const subtotalAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: raw.subtotal_amount_value,
|
||||
@ -193,12 +182,12 @@ export class SequelizeIssuedInvoiceListMapper
|
||||
errors
|
||||
);
|
||||
|
||||
const discountAmount = extractOrPushError(
|
||||
const totalDiscountAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: raw.discount_amount_value,
|
||||
value: raw.total_discount_amount_value,
|
||||
currency_code: currencyCode?.code,
|
||||
}),
|
||||
"discount_amount_value",
|
||||
"total_discount_amount_value",
|
||||
errors
|
||||
);
|
||||
|
||||
@ -243,9 +232,9 @@ export class SequelizeIssuedInvoiceListMapper
|
||||
description,
|
||||
languageCode,
|
||||
currencyCode,
|
||||
discountPercentage,
|
||||
|
||||
subtotalAmount,
|
||||
discountAmount,
|
||||
totalDiscountAmount,
|
||||
taxableAmount,
|
||||
taxesAmount,
|
||||
totalAmount,
|
||||
|
||||
@ -12,6 +12,10 @@ import {
|
||||
CustomerInvoiceTaxModel,
|
||||
VerifactuRecordModel,
|
||||
} from "../../../../common";
|
||||
import type {
|
||||
SequelizeIssuedInvoiceDomainMapper,
|
||||
SequelizeIssuedInvoiceListMapper,
|
||||
} from "../mappers";
|
||||
|
||||
export class IssuedInvoiceRepository
|
||||
extends SequelizeRepository<IssuedInvoice>
|
||||
@ -76,6 +80,38 @@ export class IssuedInvoiceRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprueba si existe una factura con un `id` dentro de una `company`.
|
||||
*
|
||||
* @param companyId - Identificador UUID de la empresa a la que pertenece la factura.
|
||||
* @param id - Identificador UUID de la factura.
|
||||
* @param transaction - Transacción activa para la operación.
|
||||
* @param options - Opciones adicionales para la consulta (Sequelize FindOptions)
|
||||
* @returns Result<boolean, Error>
|
||||
*/
|
||||
async existsByIdInCompany(
|
||||
companyId: UniqueID,
|
||||
id: UniqueID,
|
||||
transaction: Transaction,
|
||||
options: FindOptions<InferAttributes<CustomerInvoiceModel>> = {}
|
||||
): Promise<Result<boolean, Error>> {
|
||||
try {
|
||||
const count = await CustomerInvoiceModel.count({
|
||||
...options,
|
||||
where: {
|
||||
id: id.toString(),
|
||||
company_id: companyId.toString(),
|
||||
is_proforma: false,
|
||||
...(options.where ?? {}),
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
return Result.ok(Boolean(count > 0));
|
||||
} catch (error: unknown) {
|
||||
return Result.fail(translateSequelizeError(error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Busca una factura por su identificador único.
|
||||
@ -86,7 +122,7 @@ export class IssuedInvoiceRepository
|
||||
* @param options - Opciones adicionales para la consulta (Sequelize FindOptions)
|
||||
* @returns Result<CustomerInvoice, Error>
|
||||
*/
|
||||
async getIssuedInvoiceByIdInCompany(
|
||||
async getByIdInCompany(
|
||||
companyId: UniqueID,
|
||||
id: UniqueID,
|
||||
transaction: Transaction,
|
||||
|
||||
@ -1,45 +1,17 @@
|
||||
import {
|
||||
InMemoryMapperRegistry,
|
||||
InMemoryPresenterRegistry,
|
||||
type ModuleParams,
|
||||
buildTransactionManager,
|
||||
} from "@erp/core/api";
|
||||
import { buildProformaCreator } from "@erp/customer-invoices/api/application/proformas/di/proforma-creator.di";
|
||||
import { type ModuleParams, buildTransactionManager } from "@erp/core/api";
|
||||
|
||||
import {
|
||||
type GetProformaByIdUseCase,
|
||||
type ListProformasUseCase,
|
||||
type ReportProformaUseCase,
|
||||
buildGetProformaByIdUseCase,
|
||||
buildListProformasUseCase,
|
||||
buildProformaFinder,
|
||||
buildProformaSnapshotBuilders,
|
||||
buildReportProformaUseCase,
|
||||
} from "../../../application";
|
||||
import { buildProformaSnapshotBuilders } from "../../../application/issued-invoices";
|
||||
import {
|
||||
ChangeStatusProformaUseCase,
|
||||
CreateProformaUseCase,
|
||||
CustomerInvoiceApplicationService,
|
||||
DeleteProformaUseCase,
|
||||
GetProformaUseCase,
|
||||
IssueProformaUseCase,
|
||||
ListProformasUseCase,
|
||||
ProformaFullPresenter,
|
||||
ProformaListPresenter,
|
||||
ReportProformaUseCase,
|
||||
UpdateProformaUseCase,
|
||||
} from "../application";
|
||||
import {
|
||||
ProformaItemsReportPresenter,
|
||||
ProformaReportPresenter,
|
||||
ProformaTaxesReportPresenter,
|
||||
} from "../application/snapshot-builders/reports";
|
||||
|
||||
import { SequelizeInvoiceNumberGenerator } from "./persistence/sequelize";
|
||||
import {
|
||||
CustomerInvoiceDomainMapper,
|
||||
CustomerInvoiceListMapper,
|
||||
} from "./persistence/sequelize/mappers";
|
||||
import { buildProformaDocumentService } from "./proforma-documents.di";
|
||||
import { buildProformaNumberGenerator } from "./proforma-number-generator.di";
|
||||
import { buildproformaDocumentService } from "./proforma-documents.di";
|
||||
import { buildProformaRepository } from "./proforma-repositories.di";
|
||||
|
||||
export type ProformasInternalDeps = {
|
||||
@ -62,15 +34,15 @@ export function buildProformasDependencies(params: ModuleParams): ProformasInter
|
||||
// Infrastructure
|
||||
const transactionManager = buildTransactionManager(database);
|
||||
const repository = buildProformaRepository(database);
|
||||
const numberService = buildProformaNumberGenerator();
|
||||
//const numberService = buildProformaNumberGenerator();
|
||||
|
||||
// Application helpers
|
||||
|
||||
const finder = buildProformaFinder(repository);
|
||||
const creator = buildProformaCreator(numberService, repository);
|
||||
//const creator = buildProformaCreator(numberService, repository);
|
||||
|
||||
const snapshotBuilders = buildProformaSnapshotBuilders();
|
||||
const documentGeneratorPipeline = buildProformaDocumentService(params);
|
||||
const documentGeneratorPipeline = buildproformaDocumentService(params);
|
||||
|
||||
// Internal use cases (factories)
|
||||
return {
|
||||
@ -108,7 +80,7 @@ export function buildProformasDependencies(params: ModuleParams): ProformasInter
|
||||
};
|
||||
}
|
||||
|
||||
const mapperRegistry = new InMemoryMapperRegistry();
|
||||
/*const mapperRegistry = new InMemoryMapperRegistry();
|
||||
mapperRegistry
|
||||
.registerDomainMapper(
|
||||
{ resource: "customer-invoice" },
|
||||
@ -124,7 +96,7 @@ mapperRegistry
|
||||
// Repository & Services
|
||||
const numberGenerator = new SequelizeInvoiceNumberGenerator();
|
||||
|
||||
/** Aplicación */
|
||||
|
||||
const appService = new CustomerInvoiceApplicationService(repository, numberGenerator);
|
||||
|
||||
// Presenter Registry
|
||||
@ -178,4 +150,5 @@ const useCases: ProformasDeps["useCases"] = {
|
||||
new ReportProformaUseCase(appService, transactionManager, presenterRegistry),
|
||||
issue_proforma: () => new IssueProformaUseCase(appService, transactionManager, presenterRegistry),
|
||||
changeStatus_proforma: () => new ChangeStatusProformaUseCase(appService, transactionManager),
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
@ -16,7 +16,6 @@ import {
|
||||
ProformaDocumentPropertiesFactory,
|
||||
type ProformaReportSnapshot,
|
||||
} from "../../../../application";
|
||||
import { DigitalSignaturePostProcessor } from "../post-processors";
|
||||
import { ProformaSignedDocumentCachePreProcessor } from "../pre-processors";
|
||||
import { ProformaDocumentRenderer } from "../renderers";
|
||||
import { PersistProformaDocumentSideEffect } from "../side-effects";
|
||||
@ -51,7 +50,7 @@ export class ProformaDocumentPipelineFactory {
|
||||
|
||||
// 3) Firma real (Core / Infra)
|
||||
const postProcessor: IDocumentPostProcessor = new DocumentPostProcessorChain([
|
||||
new DigitalSignaturePostProcessor(deps.signingContextResolver, deps.documentSigningService),
|
||||
// Aquí podrían ir más post-procesadores, como uno de validación o similar
|
||||
]);
|
||||
|
||||
// 4. Side-effects (persistencia best-effort)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
export * from "./digital-signature-post-processor";
|
||||
@ -5,9 +5,7 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { ChangeStatusProformaByIdRequestDTO } from "../../../../../common/dto";
|
||||
import type { ChangeStatusProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { ChangeStatusProformaByIdRequestDTO } from "../../../../common/dto/index.ts";
|
||||
|
||||
export class ChangeStatusProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: ChangeStatusProformaUseCase) {
|
||||
@ -5,9 +5,9 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { CreateProformaRequestDTO } from "../../../../../common/dto";
|
||||
import type { CreateProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { CreateProformaRequestDTO } from "../../../../common/dto/index.ts";
|
||||
import type { CreateProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class CreateProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: CreateProformaUseCase) {
|
||||
@ -5,8 +5,8 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { DeleteProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { DeleteProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class DeleteProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: DeleteProformaUseCase) {
|
||||
@ -5,8 +5,8 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { GetProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { GetProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class GetProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: GetProformaUseCase) {
|
||||
@ -0,0 +1,8 @@
|
||||
//export * from "./change-status-proforma.controller";
|
||||
//export * from "./create-proforma.controller";
|
||||
//export * from "./delete-proforma.controller";
|
||||
export * from "./get-proforma.controller";
|
||||
//export * from "./issue-proforma.controller";
|
||||
export * from "./list-proformas.controller";
|
||||
export * from "./report-proforma.controller";
|
||||
//export * from "./update-proforma.controller";
|
||||
@ -5,8 +5,8 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { IssueProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { IssueProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class IssueProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: IssueProformaUseCase) {
|
||||
@ -6,8 +6,8 @@ import {
|
||||
} from "@erp/core/api";
|
||||
import { Criteria } from "@repo/rdx-criteria/server";
|
||||
|
||||
import type { ListProformasUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { ListProformasUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class ListProformasController extends ExpressController {
|
||||
public constructor(private readonly useCase: ListProformasUseCase) {
|
||||
@ -5,8 +5,8 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { ReportProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { ReportProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class ReportProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: ReportProformaUseCase) {
|
||||
@ -5,9 +5,9 @@ import {
|
||||
requireCompanyContextGuard,
|
||||
} from "@erp/core/api";
|
||||
|
||||
import type { UpdateProformaByIdRequestDTO } from "../../../../../common/dto";
|
||||
import type { UpdateProformaUseCase } from "../../../../application";
|
||||
import { customerInvoicesApiErrorMapper } from "../proformas-api-error-mapper.ts";
|
||||
import type { UpdateProformaByIdRequestDTO } from "../../../../common/dto/index.ts";
|
||||
import type { UpdateProformaUseCase } from "../../../application/index.ts";
|
||||
import { customerInvoicesApiErrorMapper } from "../../express/proformas/proformas-api-error-mapper.ts";
|
||||
|
||||
export class UpdateProformaController extends ExpressController {
|
||||
public constructor(private readonly useCase: UpdateProformaUseCase) {
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./di";
|
||||
export * from "./documents";
|
||||
export * from "./express";
|
||||
export * from "./persistence";
|
||||
|
||||
@ -249,7 +249,7 @@ export class SequelizeProformaDomainMapper
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
|
||||
discountPercentage: attributes.discountPercentage!,
|
||||
globalDiscountPercentage: attributes.discountPercentage!,
|
||||
|
||||
paymentMethod: attributes.paymentMethod!,
|
||||
|
||||
@ -348,11 +348,17 @@ export class SequelizeProformaDomainMapper
|
||||
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
||||
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
||||
|
||||
discount_percentage_value: source.discountPercentage.toPrimitive().value,
|
||||
discount_percentage_scale: source.discountPercentage.toPrimitive().scale,
|
||||
items_discount_amount_value: allAmounts.itemDiscountAmount.value,
|
||||
items_discount_amount_scale: allAmounts.itemDiscountAmount.scale,
|
||||
|
||||
discount_amount_value: allAmounts.globalDiscountAmount.value,
|
||||
discount_amount_scale: allAmounts.globalDiscountAmount.scale,
|
||||
global_discount_percentage_value: source.globalDiscountPercentage.toPrimitive().value,
|
||||
global_discount_percentage_scale: source.globalDiscountPercentage.toPrimitive().scale,
|
||||
|
||||
global_discount_amount_value: allAmounts.globalDiscountAmount.value,
|
||||
global_discount_amount_scale: allAmounts.globalDiscountAmount.scale,
|
||||
|
||||
total_discount_amount_value: allAmounts.totalDiscountAmount.value,
|
||||
total_discount_amount_scale: allAmounts.totalDiscountAmount.scale,
|
||||
|
||||
taxable_amount_value: allAmounts.taxableAmount.value,
|
||||
taxable_amount_scale: allAmounts.taxableAmount.scale,
|
||||
|
||||
@ -42,9 +42,9 @@ export class SequelizeProformaTaxesDomainMapper extends SequelizeDomainMapper<
|
||||
};
|
||||
|
||||
try {
|
||||
const { ivaAmount, recAmount, retentionAmount } = source.calculateAmounts();
|
||||
const { ivaAmount, recAmount, retentionAmount, totalAmount } = source.calculateAmounts();
|
||||
|
||||
const totalTaxes = ivaAmount.add(recAmount).add(retentionAmount);
|
||||
const totalTaxes = totalAmount;
|
||||
|
||||
const dto: CustomerInvoiceTaxCreationAttributes = {
|
||||
tax_id: UniqueID.generateNewID().toPrimitive(),
|
||||
|
||||
@ -2,7 +2,6 @@ import { type MapperParamsType, SequelizeQueryMapper } from "@erp/core/api";
|
||||
import {
|
||||
CurrencyCode,
|
||||
LanguageCode,
|
||||
Percentage,
|
||||
UniqueID,
|
||||
UtcDate,
|
||||
ValidationErrorCollection,
|
||||
@ -83,9 +82,8 @@ export class SequelizeProformaListMapper
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
|
||||
discountPercentage: attributes.discountPercentage!,
|
||||
subtotalAmount: attributes.subtotalAmount!,
|
||||
discountAmount: attributes.discountAmount!,
|
||||
totalDiscountAmount: attributes.totalDiscountAmount!,
|
||||
taxableAmount: attributes.taxableAmount!,
|
||||
taxesAmount: attributes.taxesAmount!,
|
||||
totalAmount: attributes.totalAmount!,
|
||||
@ -154,15 +152,6 @@ export class SequelizeProformaListMapper
|
||||
errors
|
||||
);
|
||||
|
||||
const discountPercentage = extractOrPushError(
|
||||
Percentage.create({
|
||||
value: raw.discount_percentage_value,
|
||||
scale: raw.discount_percentage_scale,
|
||||
}),
|
||||
"discount_percentage_value",
|
||||
errors
|
||||
);
|
||||
|
||||
const subtotalAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: raw.subtotal_amount_value,
|
||||
@ -172,12 +161,12 @@ export class SequelizeProformaListMapper
|
||||
errors
|
||||
);
|
||||
|
||||
const discountAmount = extractOrPushError(
|
||||
const totalDiscountAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: raw.discount_amount_value,
|
||||
value: raw.total_discount_amount_value,
|
||||
currency_code: currencyCode?.code,
|
||||
}),
|
||||
"discount_amount_value",
|
||||
"total_discount_amount_value",
|
||||
errors
|
||||
);
|
||||
|
||||
@ -222,9 +211,9 @@ export class SequelizeProformaListMapper
|
||||
description,
|
||||
languageCode,
|
||||
currencyCode,
|
||||
discountPercentage,
|
||||
|
||||
subtotalAmount,
|
||||
discountAmount,
|
||||
totalDiscountAmount,
|
||||
taxableAmount,
|
||||
taxesAmount,
|
||||
totalAmount,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user