Uecko_ERP/modules/customer-invoices/src/api/domain/entities/customer-invoice-items/customer-invoice-item.ts

143 lines
3.4 KiB
TypeScript
Raw Normal View History

2025-09-04 17:57:04 +00:00
import {
CurrencyCode,
DomainEntity,
LanguageCode,
MoneyValue,
Percentage,
2025-09-07 19:55:12 +00:00
Taxes,
2025-09-04 17:57:04 +00:00
UniqueID,
} from "@repo/rdx-ddd";
2025-09-03 10:41:12 +00:00
import { Maybe, Result } from "@repo/rdx-utils";
import {
CustomerInvoiceItemDescription,
2025-09-05 11:23:45 +00:00
ItemAmount,
ItemDiscount,
ItemQuantity,
2025-09-03 10:41:12 +00:00
} from "../../value-objects";
export interface CustomerInvoiceItemProps {
description: Maybe<CustomerInvoiceItemDescription>;
2025-09-05 11:23:45 +00:00
quantity: Maybe<ItemQuantity>; // Cantidad de unidades
unitAmount: Maybe<ItemAmount>; // Precio unitario en la moneda de la factura
discountPercentage: Maybe<ItemDiscount>; // % descuento
2025-09-03 10:41:12 +00:00
2025-09-07 19:55:12 +00:00
taxes: Taxes;
2025-09-03 10:41:12 +00:00
languageCode: LanguageCode;
currencyCode: CurrencyCode;
}
2025-09-05 11:23:45 +00:00
export interface ICustomerInvoiceItem {
description: Maybe<CustomerInvoiceItemDescription>;
quantity: Maybe<ItemQuantity>; // Cantidad de unidades
unitAmount: Maybe<ItemAmount>; // Precio unitario en la moneda de la factura
subtotalAmount: ItemAmount;
discountPercentage: Maybe<ItemDiscount>; // % descuento
discountAmount: Maybe<ItemAmount>;
taxableAmount: ItemAmount;
taxesAmount: ItemAmount;
totalAmount: ItemAmount;
languageCode: LanguageCode;
currencyCode: CurrencyCode;
calculateSubtotal(): ItemAmount;
calculateTotal(): ItemAmount;
}
export class CustomerInvoiceItem
extends DomainEntity<CustomerInvoiceItemProps>
implements ICustomerInvoiceItem
{
private _subtotalAmount!: ItemAmount;
private _totalAmount!: ItemAmount;
2025-09-03 10:41:12 +00:00
public static create(
props: CustomerInvoiceItemProps,
id?: UniqueID
): Result<CustomerInvoiceItem, Error> {
const item = new CustomerInvoiceItem(props, id);
// Reglas de negocio / validaciones
// ...
// ...
// 🔹 Disparar evento de dominio "CustomerInvoiceItemCreatedEvent"
//const { customerInvoice } = props;
//user.addDomainEvent(new CustomerInvoiceAuthenticatedEvent(id, customerInvoice.toString()));
return Result.ok(item);
}
get description(): Maybe<CustomerInvoiceItemDescription> {
return this.props.description;
}
2025-09-05 11:23:45 +00:00
get quantity(): Maybe<ItemQuantity> {
2025-09-03 10:41:12 +00:00
return this.props.quantity;
}
2025-09-05 11:23:45 +00:00
get unitAmount(): Maybe<ItemAmount> {
2025-09-04 17:57:04 +00:00
return this.props.unitAmount;
2025-09-03 10:41:12 +00:00
}
2025-09-05 11:23:45 +00:00
get subtotalAmount(): ItemAmount {
throw new Error("Not implemented");
2025-09-03 10:41:12 +00:00
}
2025-09-04 17:57:04 +00:00
get discountPercentage(): Maybe<Percentage> {
return this.props.discountPercentage;
}
get discountAmount(): Maybe<MoneyValue> {
throw new Error("Not implemented");
2025-09-03 10:41:12 +00:00
}
2025-09-05 11:23:45 +00:00
get taxableAmount(): ItemAmount {
throw new Error("Not implemented");
}
get taxesAmount(): ItemAmount {
throw new Error("Not implemented");
}
get totalAmount(): ItemAmount {
throw new Error("Not implemented");
2025-09-03 10:41:12 +00:00
}
public get languageCode(): LanguageCode {
return this.props.languageCode;
}
public get currencyCode(): CurrencyCode {
return this.props.currencyCode;
}
2025-09-05 11:23:45 +00:00
getProps(): CustomerInvoiceItemProps {
2025-09-03 10:41:12 +00:00
return this.props;
}
toPrimitive() {
2025-09-05 11:23:45 +00:00
return this.getProps();
2025-09-03 10:41:12 +00:00
}
2025-09-05 11:23:45 +00:00
calculateSubtotal(): ItemAmount {
2025-09-03 10:41:12 +00:00
throw new Error("Not implemented");
/*const unitPrice = this.unitPrice.isSome()
? this.unitPrice.unwrap()
: CustomerInvoiceItemUnitPrice.zero();
return this.unitPrice.multiply(this.quantity.toNumber()); // Precio unitario * Cantidad*/
}
2025-09-05 11:23:45 +00:00
calculateTotal(): ItemAmount {
2025-09-03 10:41:12 +00:00
throw new Error("Not implemented");
//return this.subtotalPrice.subtract(this.subtotalPrice.percentage(this.discount.toNumber()));
}
}