import { DomainEntity, MoneyValue, Percentage, UniqueID } from "@common/domain"; import { Quantity } from "@common/domain/value-objects/quantity"; import { Maybe, Result } from "@common/helpers"; export interface ICustomerInvoiceItemProps { description: Maybe; // Descripción del artículo o servicio quantity: Quantity; // Cantidad de unidades unitPrice: MoneyValue; // Precio unitario en la moneda de la factura // subtotalPrice: MoneyValue; // Precio unitario * Cantidad discount: Percentage; // % descuento // totalPrice: MoneyValue; } export interface ICustomerInvoiceItem { description: Maybe; quantity: Quantity; unitPrice: MoneyValue; subtotalPrice: MoneyValue; discount: Percentage; totalPrice: MoneyValue; } export class CustomerInvoiceItem extends DomainEntity implements ICustomerInvoiceItem { public static create( props: ICustomerInvoiceItemProps, id?: UniqueID ): Result { return Result.ok(new CustomerInvoiceItem(props, id)); } get description(): Maybe { return this.props.description; } get quantity(): Quantity { return this.props.quantity; } get unitPrice(): MoneyValue { return this.props.unitPrice; } get subtotalPrice(): MoneyValue { return this.quantity.isNull() || this.unitPrice.isNull() ? MoneyValue.create({ amount: null, scale: 2 }).object : this.unitPrice.multiply(this.quantity.toNumber()); } get discount(): Percentage { return this.props.discount; } get totalPrice(): MoneyValue { return this.subtotalPrice.isNull() ? MoneyValue.create({ amount: null, scale: 2 }).object : this.subtotalPrice.subtract(this.subtotalPrice.percentage(this.discount.toNumber())); } }