Facturas de cliente
This commit is contained in:
parent
8c867eb7f3
commit
df1aa258d9
@ -7,39 +7,41 @@ type GetCustomerInvoiceItemsByInvoiceIdResponseDTO = GetCustomerInvoiceByIdRespo
|
||||
export class GetCustomerInvoiceItemsAssembler {
|
||||
toDTO(invoice: CustomerInvoice): GetCustomerInvoiceItemsByInvoiceIdResponseDTO {
|
||||
const { items } = invoice;
|
||||
return items.map((item, index) => ({
|
||||
id: item.id.toString(),
|
||||
position: String(index),
|
||||
description: toEmptyString(item.description, (value) => value.toPrimitive()),
|
||||
|
||||
quantity: item.quantity.match(
|
||||
(quantity) => {
|
||||
const { value, scale } = quantity.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
return items.map((item, index) => {
|
||||
const amounts = item.getAllAmounts();
|
||||
|
||||
unit_amount: item.unitAmount.match(
|
||||
(unitAmount) => {
|
||||
const { value, scale } = unitAmount.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
return {
|
||||
id: item.id.toString(),
|
||||
position: String(index),
|
||||
description: toEmptyString(item.description, (value) => value.toPrimitive()),
|
||||
|
||||
discount_percentage: item.discountPercentage.match(
|
||||
(discountPercentage) => {
|
||||
const { value, scale } = discountPercentage.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
quantity: item.quantity.match(
|
||||
(quantity) => {
|
||||
const { value, scale } = quantity.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
total_amount: {
|
||||
value: item.totalAmount.toPrimitive().value.toString(),
|
||||
scale: item.totalAmount.toPrimitive().scale.toString(),
|
||||
},
|
||||
}));
|
||||
unit_amount: item.unitAmount.match(
|
||||
(unitAmount) => {
|
||||
const { value, scale } = unitAmount.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
discount_percentage: item.discountPercentage.match(
|
||||
(discountPercentage) => {
|
||||
const { value, scale } = discountPercentage.toPrimitive();
|
||||
return { value: value.toString(), scale: scale.toString() };
|
||||
},
|
||||
() => ({ value: "", scale: "" })
|
||||
),
|
||||
|
||||
total_amount: amounts.totalAmount.toPrimitive(),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,22 +14,22 @@ export class GetCustomerInvoiceAssembler {
|
||||
const items = this._itemsAssembler.toDTO(invoice);
|
||||
|
||||
return {
|
||||
id: invoice.id.toPrimitive(),
|
||||
company_id: invoice.companyId.toPrimitive(),
|
||||
id: invoice.id.toString(),
|
||||
company_id: invoice.companyId.toString(),
|
||||
|
||||
invoice_number: invoice.invoiceNumber.toString(),
|
||||
status: invoice.status.toPrimitive(),
|
||||
series: invoice.series.toString(),
|
||||
series: toEmptyString(invoice.series, (value) => value.toString()),
|
||||
|
||||
invoice_date: invoice.invoiceDate.toDateString(),
|
||||
operation_date: toEmptyString(invoice.operationDate, (value) => value.toDateString()),
|
||||
|
||||
notes: toEmptyString(invoice.notes, (value) => value.toPrimitive()),
|
||||
notes: toEmptyString(invoice.notes, (value) => value.toString()),
|
||||
|
||||
language_code: invoice.languageCode.toPrimitive(),
|
||||
currency_code: invoice.currencyCode.toPrimitive(),
|
||||
language_code: invoice.languageCode.toString(),
|
||||
currency_code: invoice.currencyCode.toString(),
|
||||
|
||||
subtotal_amount: {
|
||||
/*subtotal_amount: {
|
||||
value: invoice.subtotalAmount.value.toString(),
|
||||
scale: invoice.subtotalAmount.scale.toString(),
|
||||
},
|
||||
@ -57,14 +57,13 @@ export class GetCustomerInvoiceAssembler {
|
||||
total_amount: {
|
||||
value: invoice.totalAmount.value.toString(),
|
||||
scale: invoice.totalAmount.scale.toString(),
|
||||
},
|
||||
},*/
|
||||
|
||||
items,
|
||||
|
||||
metadata: {
|
||||
entity: "customer-invoices",
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,12 +10,13 @@ import {
|
||||
UtcDate,
|
||||
} from "@repo/rdx-ddd";
|
||||
import { Maybe, Result } from "@repo/rdx-utils";
|
||||
import { CustomerInvoiceItems, InvoiceRecipient } from "../entities";
|
||||
import { CustomerInvoiceItems } from "../entities";
|
||||
import { InvoiceTaxes } from "../entities/invoice-taxes";
|
||||
import {
|
||||
CustomerInvoiceNumber,
|
||||
CustomerInvoiceSerie,
|
||||
CustomerInvoiceStatus,
|
||||
InvoiceRecipient,
|
||||
} from "../value-objects";
|
||||
|
||||
export interface CustomerInvoiceProps {
|
||||
|
||||
@ -5,8 +5,6 @@ import { InvoiceAmount } from "../../value-objects/invoice-amount";
|
||||
|
||||
export interface InvoiceTaxProps {
|
||||
tax: Tax;
|
||||
taxableAmount: InvoiceAmount;
|
||||
taxesAmount: InvoiceAmount;
|
||||
}
|
||||
|
||||
export class InvoiceTax extends DomainEntity<InvoiceTaxProps> {
|
||||
@ -24,14 +22,6 @@ export class InvoiceTax extends DomainEntity<InvoiceTaxProps> {
|
||||
return this.props.tax;
|
||||
}
|
||||
|
||||
public get taxableAmount(): InvoiceAmount {
|
||||
return this.props.taxableAmount;
|
||||
}
|
||||
|
||||
public get taxesAmount(): InvoiceAmount {
|
||||
return this.props.taxesAmount;
|
||||
}
|
||||
|
||||
getProps(): InvoiceTaxProps {
|
||||
return this.props;
|
||||
}
|
||||
@ -39,4 +29,8 @@ export class InvoiceTax extends DomainEntity<InvoiceTaxProps> {
|
||||
toPrimitive() {
|
||||
return this.getProps();
|
||||
}
|
||||
|
||||
public getTaxAmount(taxableAmount: InvoiceAmount): InvoiceAmount {
|
||||
return taxableAmount.percentage(this.tax.percentage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,13 +9,13 @@ export interface ItemTaxProps {
|
||||
|
||||
export class ItemTax extends DomainEntity<ItemTaxProps> {
|
||||
static create(props: ItemTaxProps, id?: UniqueID): Result<ItemTax, Error> {
|
||||
const invoiceTax = new ItemTax(props, id);
|
||||
const itemTax = new ItemTax(props, id);
|
||||
|
||||
// Reglas de negocio / validaciones
|
||||
// ...
|
||||
// ...
|
||||
|
||||
return Result.ok(invoiceTax);
|
||||
return Result.ok(itemTax);
|
||||
}
|
||||
|
||||
public get tax(): Tax {
|
||||
|
||||
@ -4,6 +4,7 @@ export * from "./customer-invoice-number";
|
||||
export * from "./customer-invoice-serie";
|
||||
export * from "./customer-invoice-status";
|
||||
export * from "./invoice-amount";
|
||||
export * from "./invoice-recipient";
|
||||
export * from "./item-amount";
|
||||
export * from "./item-discount";
|
||||
export * from "./item-quantity";
|
||||
|
||||
@ -6,19 +6,20 @@ import {
|
||||
ValidationErrorDetail,
|
||||
extractOrPushError,
|
||||
} from "@erp/core/api";
|
||||
import { UniqueID, maybeFromNullableVO, toNullable } from "@repo/rdx-ddd";
|
||||
import { UniqueID, maybeFromNullableVO } from "@repo/rdx-ddd";
|
||||
import { Result } from "@repo/rdx-utils";
|
||||
import { InferCreationAttributes } from "sequelize";
|
||||
import {
|
||||
CustomerInvoice,
|
||||
CustomerInvoiceItem,
|
||||
CustomerInvoiceItemDescription,
|
||||
CustomerInvoiceProps,
|
||||
ItemAmount,
|
||||
ItemDiscount,
|
||||
ItemQuantity,
|
||||
ItemTaxes,
|
||||
} from "../../domain";
|
||||
import { CustomerInvoiceItemCreationAttributes, CustomerInvoiceItemModel } from "../sequelize";
|
||||
import { ItemTaxesMapper } from "./item-taxes.mapper";
|
||||
|
||||
export interface ICustomerInvoiceItemMapper
|
||||
extends ISequelizeMapper<
|
||||
@ -35,6 +36,13 @@ export class CustomerInvoiceItemMapper
|
||||
>
|
||||
implements ICustomerInvoiceItemMapper
|
||||
{
|
||||
private _taxesMapper: ItemTaxesMapper;
|
||||
|
||||
constructor(params: MapperParamsType) {
|
||||
super();
|
||||
this._taxesMapper = new ItemTaxesMapper(params);
|
||||
}
|
||||
|
||||
private mapAttributesToDomain(source: CustomerInvoiceItemModel, params?: MapperParamsType) {
|
||||
const { errors, index, attributes } = params as {
|
||||
index: number;
|
||||
@ -92,6 +100,10 @@ export class CustomerInvoiceItemMapper
|
||||
attributes: Partial<CustomerInvoiceProps>;
|
||||
};
|
||||
|
||||
// 1) Valores escalares (atributos generales)
|
||||
const attributes = this.mapAttributesToDomain(source, params);
|
||||
|
||||
// 2) Comprobar relaciones
|
||||
if (requireIncludes) {
|
||||
if (!source.taxes) {
|
||||
errors.push({
|
||||
@ -101,8 +113,7 @@ export class CustomerInvoiceItemMapper
|
||||
}
|
||||
}
|
||||
|
||||
const attributes = this.mapAttributesToDomain(source, params);
|
||||
|
||||
// 3) Importes
|
||||
const discountPercentage = extractOrPushError(
|
||||
maybeFromNullableVO(source.discount_percentage_value, (value) =>
|
||||
ItemDiscount.create({ value })
|
||||
@ -111,7 +122,25 @@ export class CustomerInvoiceItemMapper
|
||||
errors
|
||||
);
|
||||
|
||||
// Creación del objeto de dominio
|
||||
// 4) Taxes (colección a nivel de item/línea)
|
||||
const taxesResults = this._taxesMapper.mapArrayToDomain(source.taxes, {
|
||||
attributes,
|
||||
...params,
|
||||
});
|
||||
|
||||
if (taxesResults.isFailure) {
|
||||
errors.push({
|
||||
path: `taxes[${index}].discount_percentage`,
|
||||
message: taxesResults.error.message,
|
||||
});
|
||||
}
|
||||
|
||||
// 5) Construcción del elemento de dominio
|
||||
|
||||
const taxes = ItemTaxes.create({
|
||||
items: taxesResults.data.getAll(),
|
||||
});
|
||||
|
||||
const createResult = CustomerInvoiceItem.create(
|
||||
{
|
||||
languageCode: attributes.languageCode!,
|
||||
@ -120,6 +149,7 @@ export class CustomerInvoiceItemMapper
|
||||
quantity: attributes.quantity!,
|
||||
unitAmount: attributes.unitAmount!,
|
||||
discountPercentage: discountPercentage!,
|
||||
taxes,
|
||||
},
|
||||
attributes.itemId
|
||||
);
|
||||
@ -139,12 +169,15 @@ export class CustomerInvoiceItemMapper
|
||||
source: CustomerInvoiceItem,
|
||||
params?: MapperParamsType
|
||||
): InferCreationAttributes<CustomerInvoiceItemModel, {}> {
|
||||
1;
|
||||
const { index, sourceParent } = params as {
|
||||
throw new Error("not implemented");
|
||||
/*
|
||||
|
||||
const { index, sourceParent } = params as {
|
||||
index: number;
|
||||
sourceParent: CustomerInvoice;
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
item_id: source.id.toPrimitive(),
|
||||
invoice_id: sourceParent.id.toPrimitive(),
|
||||
@ -193,6 +226,6 @@ export class CustomerInvoiceItemMapper
|
||||
|
||||
total_amount_value: source.totalAmount.toPrimitive().value,
|
||||
total_amount_scale: source.totalAmount.toPrimitive().scale,
|
||||
};
|
||||
};*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { JsonTaxCatalogProvider } from "@erp/core";
|
||||
import {
|
||||
ISequelizeMapper,
|
||||
MapperParamsType,
|
||||
@ -15,7 +14,6 @@ import {
|
||||
UniqueID,
|
||||
UtcDate,
|
||||
maybeFromNullableVO,
|
||||
toNullable,
|
||||
} from "@repo/rdx-ddd";
|
||||
import { Result } from "@repo/rdx-utils";
|
||||
import {
|
||||
@ -47,11 +45,10 @@ export class CustomerInvoiceMapper
|
||||
private _recipientMapper: InvoiceRecipientMapper;
|
||||
private _taxesMapper: TaxesMapper;
|
||||
|
||||
constructor(params: {
|
||||
taxCatalog: JsonTaxCatalogProvider;
|
||||
}) {
|
||||
constructor(params: MapperParamsType) {
|
||||
super();
|
||||
this._itemsMapper = new CustomerInvoiceItemMapper(); // Instanciar el mapper de items
|
||||
|
||||
this._itemsMapper = new CustomerInvoiceItemMapper(params); // Instanciar el mapper de items
|
||||
this._recipientMapper = new InvoiceRecipientMapper();
|
||||
this._taxesMapper = new TaxesMapper(params);
|
||||
}
|
||||
@ -155,8 +152,10 @@ export class CustomerInvoiceMapper
|
||||
try {
|
||||
const errors: ValidationErrorDetail[] = [];
|
||||
|
||||
// 1) Valores escalares (atributos generales)
|
||||
const attributes = this.mapAttributesToDomain(source, { errors, ...params });
|
||||
|
||||
// 2) Comprobar relaciones
|
||||
const requireIncludes = Boolean(params?.requireIncludes);
|
||||
if (requireIncludes) {
|
||||
if (!source.items) {
|
||||
@ -190,13 +189,13 @@ export class CustomerInvoiceMapper
|
||||
if (recipientResult.isFailure) {
|
||||
errors.push({
|
||||
path: "recipient",
|
||||
|
||||
message: recipientResult.error.message,
|
||||
});
|
||||
}
|
||||
|
||||
// 4) Items (colección)
|
||||
const itemsResults = this._itemsMapper.mapArrayToDomain(source.items, {
|
||||
requireIncludes,
|
||||
errors,
|
||||
attributes,
|
||||
...params,
|
||||
@ -219,7 +218,7 @@ export class CustomerInvoiceMapper
|
||||
if (taxesResults.isFailure) {
|
||||
errors.push({
|
||||
path: "taxes",
|
||||
message: recipientResult.error.message,
|
||||
message: taxesResults.error.message,
|
||||
});
|
||||
}
|
||||
|
||||
@ -262,7 +261,7 @@ export class CustomerInvoiceMapper
|
||||
languageCode: attributes.languageCode!,
|
||||
currencyCode: attributes.currencyCode!,
|
||||
|
||||
discountPercentage: attributes.discountPercentage!,
|
||||
//discountPercentage: attributes.discountPercentage!,
|
||||
|
||||
taxes,
|
||||
items,
|
||||
@ -288,7 +287,9 @@ export class CustomerInvoiceMapper
|
||||
source: CustomerInvoice,
|
||||
params?: MapperParamsType
|
||||
): CustomerInvoiceCreationAttributes {
|
||||
const items = this._itemsMapper.mapCollectionToPersistence(source.items, params);
|
||||
throw new Error("not implemented");
|
||||
|
||||
/*const items = this._itemsMapper.mapCollectionToPersistence(source.items, params);
|
||||
|
||||
const customer = source.recipient.match(
|
||||
(recipient) =>
|
||||
@ -363,6 +364,6 @@ export class CustomerInvoiceMapper
|
||||
|
||||
items,
|
||||
...customer,
|
||||
};
|
||||
};*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,7 @@ import {
|
||||
extractOrPushError,
|
||||
} from "@erp/core/api";
|
||||
import { Maybe, Result } from "@repo/rdx-utils";
|
||||
import { InferCreationAttributes } from "sequelize";
|
||||
import { CustomerInvoice, CustomerInvoiceProps, InvoiceRecipient } from "../../domain";
|
||||
import { CustomerInvoiceProps, InvoiceRecipient } from "../../domain";
|
||||
import { CustomerInvoiceModel } from "../sequelize";
|
||||
|
||||
export class InvoiceRecipientMapper {
|
||||
@ -105,14 +104,4 @@ export class InvoiceRecipientMapper {
|
||||
|
||||
return Result.ok(Maybe.some(createResult.data));
|
||||
}
|
||||
|
||||
public mapToPersistence(
|
||||
source: InvoiceRecipient,
|
||||
params?: MapperParamsType
|
||||
): Partial<InferCreationAttributes<CustomerInvoiceModel, {}>> {
|
||||
const { index, sourceParent } = params as {
|
||||
index: number;
|
||||
sourceParent: CustomerInvoice;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,32 +1,68 @@
|
||||
import { MapperParamsType, Taxes } from "@erp/core/api";
|
||||
import { InferCreationAttributes } from "sequelize";
|
||||
import { CustomerInvoiceItemModel, CustomerInvoiceItemTaxModel } from "../sequelize";
|
||||
import { JsonTaxCatalogProvider } from "@erp/core";
|
||||
import {
|
||||
MapperParamsType,
|
||||
SequelizeMapper,
|
||||
Tax,
|
||||
ValidationErrorCollection,
|
||||
ValidationErrorDetail,
|
||||
extractOrPushError,
|
||||
} from "@erp/core/api";
|
||||
import { Result } from "@repo/rdx-utils";
|
||||
import { ItemTax } from "../../domain";
|
||||
import { CustomerInvoiceItemCreationAttributes, CustomerInvoiceItemTaxModel } from "../sequelize";
|
||||
|
||||
export class ItemTaxesMapper {
|
||||
public mapArrayToDomain(item: CustomerInvoiceItemModel, params?: MapperParamsType) {
|
||||
const taxes = Taxes.create({ items: [] });
|
||||
export class ItemTaxesMapper extends SequelizeMapper<
|
||||
CustomerInvoiceItemTaxModel,
|
||||
CustomerInvoiceItemCreationAttributes,
|
||||
ItemTax
|
||||
> {
|
||||
private _taxCatalog!: JsonTaxCatalogProvider;
|
||||
|
||||
item.taxes.split(",").every((tax_code, taxIndex) => {
|
||||
const taxResult = Tax.createFromCode(tax_code, this.taxCatalog);
|
||||
if (taxResult.isSuccess) {
|
||||
taxes.add(taxResult.data);
|
||||
} else {
|
||||
this.errors.push({
|
||||
path: `items[${itemIndex}].taxes[${taxIndex}]`,
|
||||
message: taxResult.error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
return taxes;
|
||||
constructor(params: MapperParamsType) {
|
||||
super();
|
||||
const { taxCatalog } = params as {
|
||||
taxCatalog: JsonTaxCatalogProvider;
|
||||
};
|
||||
|
||||
if (!taxCatalog) {
|
||||
throw new Error('taxCatalog not defined ("ItemTaxesMapper")');
|
||||
}
|
||||
|
||||
this._taxCatalog = taxCatalog;
|
||||
}
|
||||
|
||||
public mapToDomain(
|
||||
source: CustomerInvoiceItemTaxModel,
|
||||
params?: MapperParamsType
|
||||
): Result<ItemTax, Error> {
|
||||
const { errors, index } = params as {
|
||||
index: number;
|
||||
errors: ValidationErrorDetail[];
|
||||
};
|
||||
|
||||
const tax = extractOrPushError(
|
||||
Tax.createFromCode(source.tax_code, this._taxCatalog),
|
||||
`taxes[${index}].tax_code`,
|
||||
errors
|
||||
);
|
||||
|
||||
// Creación del objeto de dominio
|
||||
const createResult = ItemTax.create({ tax: tax! });
|
||||
if (createResult.isFailure) {
|
||||
return Result.fail(
|
||||
new ValidationErrorCollection("Invoice item tax creation failed", [
|
||||
{ path: `taxes[${index}]`, message: createResult.error.message },
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
return createResult;
|
||||
}
|
||||
|
||||
public mapToPersistence(
|
||||
source: Taxes,
|
||||
source: ItemTax,
|
||||
params?: MapperParamsType
|
||||
): InferCreationAttributes<CustomerInvoiceItemTaxModel, {}> {
|
||||
/*const { index, sourceParent } = params as {
|
||||
index: number;
|
||||
sourceParent: CustomerInvoice;
|
||||
};*/
|
||||
): CustomerInvoiceItemCreationAttributes {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,20 +3,14 @@ import {
|
||||
MapperParamsType,
|
||||
SequelizeMapper,
|
||||
Tax,
|
||||
Taxes,
|
||||
ValidationErrorCollection,
|
||||
ValidationErrorDetail,
|
||||
extractOrPushError,
|
||||
} from "@erp/core/api";
|
||||
import { Result } from "@repo/rdx-utils";
|
||||
import { InferCreationAttributes } from "sequelize";
|
||||
import { CustomerInvoiceProps, InvoiceAmount } from "../../domain";
|
||||
import { CustomerInvoiceProps } from "../../domain";
|
||||
import { InvoiceTax } from "../../domain/entities/invoice-taxes";
|
||||
import {
|
||||
CustomerInvoiceItemTaxModel,
|
||||
CustomerInvoiceTaxCreationAttributes,
|
||||
CustomerInvoiceTaxModel,
|
||||
} from "../sequelize";
|
||||
import { CustomerInvoiceTaxCreationAttributes, CustomerInvoiceTaxModel } from "../sequelize";
|
||||
|
||||
export class TaxesMapper extends SequelizeMapper<
|
||||
CustomerInvoiceTaxModel,
|
||||
@ -25,11 +19,16 @@ export class TaxesMapper extends SequelizeMapper<
|
||||
> {
|
||||
private _taxCatalog: JsonTaxCatalogProvider;
|
||||
|
||||
constructor(params: {
|
||||
taxCatalog: JsonTaxCatalogProvider;
|
||||
}) {
|
||||
constructor(params: MapperParamsType) {
|
||||
super();
|
||||
const { taxCatalog } = params;
|
||||
const { taxCatalog } = params as {
|
||||
taxCatalog: JsonTaxCatalogProvider;
|
||||
};
|
||||
|
||||
if (!taxCatalog) {
|
||||
throw new Error('taxCatalog not defined ("TaxesMapper")');
|
||||
}
|
||||
|
||||
this._taxCatalog = taxCatalog;
|
||||
}
|
||||
|
||||
@ -39,7 +38,6 @@ export class TaxesMapper extends SequelizeMapper<
|
||||
): Result<InvoiceTax, Error> {
|
||||
const { errors, index, attributes } = params as {
|
||||
index: number;
|
||||
requireIncludes: boolean;
|
||||
errors: ValidationErrorDetail[];
|
||||
attributes: Partial<CustomerInvoiceProps>;
|
||||
};
|
||||
@ -50,48 +48,14 @@ export class TaxesMapper extends SequelizeMapper<
|
||||
errors
|
||||
);
|
||||
|
||||
const taxableAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: source.taxable_amount_value,
|
||||
currency_code: attributes.currencyCode?.code,
|
||||
}),
|
||||
`taxes[${index}].taxable_amount_value`,
|
||||
errors
|
||||
);
|
||||
|
||||
if (source.taxable_amount_scale !== InvoiceAmount.DEFAULT_SCALE) {
|
||||
errors.push({
|
||||
path: `taxes[${index}].taxable_amount_scale`,
|
||||
message: "Invalid taxable amount scale",
|
||||
});
|
||||
}
|
||||
|
||||
const taxesAmount = extractOrPushError(
|
||||
InvoiceAmount.create({
|
||||
value: source.taxes_amount_value,
|
||||
currency_code: attributes.currencyCode?.code,
|
||||
}),
|
||||
`taxes[${index}].taxes_amount_value`,
|
||||
errors
|
||||
);
|
||||
|
||||
if (source.taxes_amount_scale !== InvoiceAmount.DEFAULT_SCALE) {
|
||||
errors.push({
|
||||
path: `taxes[${index}].taxes_amount_scale`,
|
||||
message: "Invalid taxes amount scale",
|
||||
});
|
||||
}
|
||||
|
||||
// Creación del objeto de dominio
|
||||
const createResult = InvoiceTax.create({
|
||||
tax: tax!,
|
||||
taxableAmount: taxableAmount!,
|
||||
taxesAmount: taxesAmount!,
|
||||
});
|
||||
|
||||
if (createResult.isFailure) {
|
||||
return Result.fail(
|
||||
new ValidationErrorCollection("Invoice taxes creation failed", [
|
||||
new ValidationErrorCollection("Invoice tax creation failed", [
|
||||
{ path: `taxes[${index}]`, message: createResult.error.message },
|
||||
])
|
||||
);
|
||||
@ -101,12 +65,9 @@ export class TaxesMapper extends SequelizeMapper<
|
||||
}
|
||||
|
||||
public mapToPersistence(
|
||||
source: Taxes,
|
||||
source: InvoiceTax,
|
||||
params?: MapperParamsType
|
||||
): InferCreationAttributes<CustomerInvoiceItemTaxModel, {}> {
|
||||
/*const { index, sourceParent } = params as {
|
||||
index: number;
|
||||
sourceParent: CustomerInvoice;
|
||||
};*/
|
||||
): CustomerInvoiceTaxCreationAttributes {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,9 @@ import { Collection, Result } from "@repo/rdx-utils";
|
||||
import { Sequelize, Transaction } from "sequelize";
|
||||
import { CustomerInvoice, ICustomerInvoiceRepository } from "../../domain";
|
||||
import { ICustomerInvoiceMapper } from "../mappers/customer-invoice.mapper";
|
||||
import { CustomerInvoiceItemTaxModel } from "./customer-invoice-item-tax.model";
|
||||
import { CustomerInvoiceItemModel } from "./customer-invoice-item.model";
|
||||
import { CustomerInvoiceTaxModel } from "./customer-invoice-tax.model";
|
||||
import { CustomerInvoiceModel } from "./customer-invoice.model";
|
||||
|
||||
export class CustomerInvoiceRepository
|
||||
@ -124,6 +127,23 @@ export class CustomerInvoiceRepository
|
||||
as: "current_customer",
|
||||
required: false, // false => LEFT JOIN
|
||||
},
|
||||
{
|
||||
model: CustomerInvoiceItemModel,
|
||||
as: "items",
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: CustomerInvoiceItemTaxModel,
|
||||
as: "taxes",
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: CustomerInvoiceTaxModel,
|
||||
as: "taxes",
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
transaction,
|
||||
});
|
||||
|
||||
@ -49,4 +49,8 @@ export class CurrencyCode extends ValueObject<CurrencyCodeProps> {
|
||||
toPrimitive(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return String(this.props.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,4 +49,8 @@ export class LanguageCode extends ValueObject<LanguageCodeProps> {
|
||||
toPrimitive(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return String(this.props.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,10 @@ export class TextValue extends ValueObject<TextValueProps> {
|
||||
}
|
||||
|
||||
toPrimitive(): string {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return String(this.getProps());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user