.
This commit is contained in:
parent
16118da1ee
commit
647528b128
@ -70,18 +70,18 @@ export class UpdateProformaInputMapper implements IUpdateProformaInputMapper {
|
||||
);
|
||||
});
|
||||
|
||||
toPatchField(dto.invoice_date).ifSet((invoiceDate) => {
|
||||
if (isNullishOrEmpty(invoiceDate)) {
|
||||
toPatchField(dto.proforma_date).ifSet((proformaDate) => {
|
||||
if (isNullishOrEmpty(proformaDate)) {
|
||||
errors.push({
|
||||
path: "invoice_date",
|
||||
message: "Invoice date cannot be empty",
|
||||
path: "proforma_date",
|
||||
message: "Proforma date cannot be empty",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
proformaPatchProps.proformaDate = extractOrPushError(
|
||||
UtcDate.createFromISO(invoiceDate),
|
||||
"invoice_date",
|
||||
UtcDate.createFromISO(proformaDate),
|
||||
"proforma_date",
|
||||
errors
|
||||
);
|
||||
});
|
||||
@ -340,5 +340,4 @@ export class UpdateProformaInputMapper implements IUpdateProformaInputMapper {
|
||||
throw new ValidationErrorCollection("Proforma props mapping failed", errors);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import type { Maybe } from "@repo/rdx-utils";
|
||||
|
||||
import type {
|
||||
InvoiceSerie,
|
||||
ProformaItemPatchProps,
|
||||
ProformaPatchProps,
|
||||
ProformaTaxMode,
|
||||
} from "../../../domain";
|
||||
import type { Maybe } from "@repo/rdx-utils";
|
||||
import type { InvoiceSerie } from "../../../domain";
|
||||
|
||||
import type { ProformaItemTaxCodesInput } from "./proforma-item-tax-codes-input.model";
|
||||
|
||||
|
||||
@ -8,16 +8,15 @@ import {
|
||||
InvoiceNumber,
|
||||
Proforma,
|
||||
ProformaTaxConfig,
|
||||
type ProformaTaxMode,
|
||||
} from "../../../domain";
|
||||
import type { ProformaCreateInputProps, ProformaTaxConfigInputProps } from "../models";
|
||||
import type { IProformaRepository } from "../repositories";
|
||||
|
||||
import type { ProformaPaymentResolver } from "./catalog-resolver/proforma-payment-resolver";
|
||||
import type { ProformaSeriesValidator } from "./proforma-series-validator.interface";
|
||||
import type { ProformaTargetInvoiceSeriesValidator } from "./proforma-target-invoice-series-validator.interface";
|
||||
import type { ProformaTaxResolver } from "./catalog-resolver/proforma-tax-resolver";
|
||||
import type { IProformaNumberGenerator } from "./proforma-number-generator.interface";
|
||||
import type { ProformaSeriesValidator } from "./proforma-series-validator.interface";
|
||||
import type { ProformaTargetInvoiceSeriesValidator } from "./proforma-target-invoice-series-validator.interface";
|
||||
|
||||
export interface IProformaCreatorParams {
|
||||
companyId: UniqueID;
|
||||
@ -46,16 +45,18 @@ export class ProformaCreator implements IProformaCreator {
|
||||
async create(params: IProformaCreatorParams): Promise<Result<Proforma, Error>> {
|
||||
const { companyId, id, props, transaction } = params;
|
||||
|
||||
const resolvedProps = await this.resolveCreateProps(props, transaction);
|
||||
const resolvedPropsResult = await this.resolveCreateProps(props, transaction);
|
||||
|
||||
if (resolvedProps.isFailure) {
|
||||
return Result.fail(resolvedProps.error);
|
||||
if (resolvedPropsResult.isFailure) {
|
||||
return Result.fail(resolvedPropsResult.error);
|
||||
}
|
||||
|
||||
const resolvedProps = resolvedPropsResult.data;
|
||||
|
||||
const proformaSeriesValidationResult =
|
||||
await this.deps.proformaSeriesValidator.ensureValidProformaSeries({
|
||||
companyId,
|
||||
proformaSeriesCode: resolvedProps.data.proformaSeriesCode,
|
||||
proformaSeriesCode: resolvedProps.proformaSeriesCode,
|
||||
transaction,
|
||||
});
|
||||
|
||||
@ -66,7 +67,7 @@ export class ProformaCreator implements IProformaCreator {
|
||||
// 1. Obtener siguiente número
|
||||
const numberResult = await this.deps.numberService.getNextForCompany(
|
||||
companyId,
|
||||
resolvedProps.data.proformaSeriesCode,
|
||||
resolvedProps.proformaSeriesCode,
|
||||
transaction
|
||||
);
|
||||
|
||||
@ -77,7 +78,7 @@ export class ProformaCreator implements IProformaCreator {
|
||||
const targetInvoiceSeriesValidationResult =
|
||||
await this.deps.targetInvoiceSeriesValidator.ensureValidIssuedInvoiceSeries({
|
||||
companyId,
|
||||
targetInvoiceSeriesCode: resolvedProps.data.targetInvoiceSeriesCode,
|
||||
targetInvoiceSeriesCode: resolvedPropsResult.data.targetInvoiceSeriesCode,
|
||||
transaction,
|
||||
});
|
||||
|
||||
@ -102,12 +103,12 @@ export class ProformaCreator implements IProformaCreator {
|
||||
// 2. Crear agregado
|
||||
const proformaResult = Proforma.create(
|
||||
{
|
||||
...resolvedProps.data,
|
||||
...resolvedPropsResult.data,
|
||||
companyId,
|
||||
documentSeriesId: Maybe.some(numberResult.data.documentSeriesId),
|
||||
proformaNumber: Maybe.some(proformaNumberResult.data),
|
||||
proformaReference,
|
||||
series: resolvedProps.data.targetInvoiceSeriesCode,
|
||||
series: resolvedPropsResult.data.targetInvoiceSeriesCode,
|
||||
},
|
||||
id
|
||||
);
|
||||
@ -139,7 +140,10 @@ export class ProformaCreator implements IProformaCreator {
|
||||
props: ProformaCreateInputProps,
|
||||
transaction?: unknown
|
||||
): Promise<
|
||||
Result<Omit<IProformaCreateProps, "proformaReference" | "proformaNumber" | "documentSeriesId">, Error>
|
||||
Result<
|
||||
Omit<IProformaCreateProps, "proformaReference" | "proformaNumber" | "documentSeriesId">,
|
||||
Error
|
||||
>
|
||||
> {
|
||||
const customerResult = await this.deps.customerServices.getCustomerById(props.customerId, {
|
||||
companyId: props.companyId,
|
||||
@ -154,12 +158,11 @@ export class ProformaCreator implements IProformaCreator {
|
||||
|
||||
const _newProps = {
|
||||
...props,
|
||||
taxRegimeCode:
|
||||
props.taxRegimeCode.isNone()
|
||||
? customer.taxRegimeCode.isSome()
|
||||
? customer.taxRegimeCode
|
||||
: Maybe.some("01")
|
||||
: props.taxRegimeCode,
|
||||
taxRegimeCode: props.taxRegimeCode.isNone()
|
||||
? customer.taxRegimeCode.isSome()
|
||||
? customer.taxRegimeCode
|
||||
: Maybe.some("01")
|
||||
: props.taxRegimeCode,
|
||||
};
|
||||
|
||||
// Tax Regime => comprobar que existe
|
||||
|
||||
@ -2,10 +2,10 @@ import { DomainValidationError, type UniqueID, type UtcDate } from "@repo/rdx-dd
|
||||
import { Maybe, Result } from "@repo/rdx-utils";
|
||||
|
||||
import {
|
||||
ProformaTaxConfig,
|
||||
type Proforma,
|
||||
type ProformaItemPatchProps,
|
||||
type ProformaPatchProps,
|
||||
ProformaTaxConfig,
|
||||
} from "../../../domain";
|
||||
import type { ProformaPatchInputProps } from "../models";
|
||||
import type { IProformaRepository } from "../repositories";
|
||||
@ -246,8 +246,7 @@ export class ProformaUpdater implements IProformaUpdater {
|
||||
companyId: params.companyId,
|
||||
atDate: params.currentInvoiceDate,
|
||||
usesRetention,
|
||||
requestedCode:
|
||||
patchTaxConfig.defaultRetentionCode ?? currentTaxConfig.defaultRetentionCode,
|
||||
requestedCode: patchTaxConfig.defaultRetentionCode ?? currentTaxConfig.defaultRetentionCode,
|
||||
});
|
||||
|
||||
if (defaultRetentionCode.isFailure) {
|
||||
|
||||
@ -2,7 +2,7 @@ import type { ISnapshotBuilder } from "@erp/core/api";
|
||||
import { DomainValidationError, maybeToNullable } from "@repo/rdx-ddd";
|
||||
|
||||
import type { ProformaRecipientSummaryDTO } from "../../../../../common";
|
||||
import type { InvoiceRecipient, Proforma } from "../../../../domain";
|
||||
import type { Proforma } from "../../../../domain";
|
||||
|
||||
export interface IProformaRecipientFullSnapshotBuilder
|
||||
extends ISnapshotBuilder<Proforma, ProformaRecipientSummaryDTO> {}
|
||||
@ -16,7 +16,7 @@ export class ProformaRecipientFullSnapshotBuilder implements IProformaRecipientF
|
||||
}
|
||||
|
||||
return proforma.recipient.match(
|
||||
(recipient: InvoiceRecipient) => ({
|
||||
(recipient) => ({
|
||||
id: proforma.customerId.toString(),
|
||||
name: recipient.name.toString(),
|
||||
tin: maybeToNullable(recipient.tin, (v) => v.toString()),
|
||||
|
||||
@ -29,7 +29,11 @@ import {
|
||||
import { InvalidProformaTransitionError, ProformaItemMismatch } from "../errors";
|
||||
import type { IProformaTaxTotals, ProformaCalculationContext } from "../services";
|
||||
import { canManuallyTransitionProformaStatus } from "../services";
|
||||
import { ProformaItemTaxes, ProformaTaxConfig, type ProformaRecipient } from "../value-objects";
|
||||
import {
|
||||
ProformaItemTaxes,
|
||||
type ProformaRecipient,
|
||||
type ProformaTaxConfig,
|
||||
} from "../value-objects";
|
||||
|
||||
export interface IProformaCreateProps {
|
||||
companyId: UniqueID;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user