Facturas de cliente
This commit is contained in:
parent
5879220fe9
commit
fa56473a00
@ -1,4 +1,3 @@
|
|||||||
import { JsonTaxCatalogProvider } from "@erp/core";
|
|
||||||
import { ITransactionManager } from "@erp/core/api";
|
import { ITransactionManager } from "@erp/core/api";
|
||||||
import { Criteria } from "@repo/rdx-criteria/server";
|
import { Criteria } from "@repo/rdx-criteria/server";
|
||||||
import { UniqueID } from "@repo/rdx-ddd";
|
import { UniqueID } from "@repo/rdx-ddd";
|
||||||
@ -17,8 +16,7 @@ export class ListCustomerInvoicesUseCase {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly service: CustomerInvoiceService,
|
private readonly service: CustomerInvoiceService,
|
||||||
private readonly transactionManager: ITransactionManager,
|
private readonly transactionManager: ITransactionManager,
|
||||||
private readonly assembler: ListCustomerInvoicesAssembler,
|
private readonly assembler: ListCustomerInvoicesAssembler
|
||||||
private readonly taxCatalog: JsonTaxCatalogProvider
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public execute(
|
public execute(
|
||||||
|
|||||||
@ -30,22 +30,10 @@ export interface CustomerInvoiceProps {
|
|||||||
operationDate: Maybe<UtcDate>;
|
operationDate: Maybe<UtcDate>;
|
||||||
|
|
||||||
customerId: UniqueID;
|
customerId: UniqueID;
|
||||||
|
|
||||||
recipient: Maybe<InvoiceRecipient>;
|
recipient: Maybe<InvoiceRecipient>;
|
||||||
|
|
||||||
notes: Maybe<TextValue>;
|
notes: Maybe<TextValue>;
|
||||||
|
|
||||||
//dueDate: UtcDate; // ? --> depende de la forma de pago
|
|
||||||
|
|
||||||
//tax: Tax; // ? --> detalles?
|
|
||||||
|
|
||||||
//purchareOrderNumber: string;
|
|
||||||
|
|
||||||
//senderId: UniqueID;
|
|
||||||
|
|
||||||
//paymentInstructions: Note;
|
|
||||||
//paymentTerms: string;
|
|
||||||
|
|
||||||
languageCode: LanguageCode;
|
languageCode: LanguageCode;
|
||||||
currencyCode: CurrencyCode;
|
currencyCode: CurrencyCode;
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
City,
|
City,
|
||||||
Country,
|
Country,
|
||||||
Name,
|
Name,
|
||||||
PostalCode,
|
PostalCode,
|
||||||
Province,
|
Province,
|
||||||
Street,
|
Street,
|
||||||
TINNumber,
|
TINNumber,
|
||||||
ValueObject
|
ValueObject,
|
||||||
} from "@repo/rdx-ddd";
|
} from "@repo/rdx-ddd";
|
||||||
import { Maybe, Result } from "@repo/rdx-utils";
|
import { Maybe, Result } from "@repo/rdx-utils";
|
||||||
import * as z from "zod/v4";
|
|
||||||
|
|
||||||
export interface InvoiceRecipientProps {
|
export interface InvoiceRecipientProps {
|
||||||
name: Name;
|
name: Name;
|
||||||
@ -23,26 +22,15 @@ export interface InvoiceRecipientProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
||||||
protected static validate(values: InvoiceRecipientProps) {
|
protected static validate(values: InvoiceRecipientProps) {
|
||||||
const schema = z.object({
|
return Result.ok(values);
|
||||||
name: z.string(),
|
}
|
||||||
tin: z.string(),
|
|
||||||
street: z.string().optional(),
|
|
||||||
street2: z.string().optional(),
|
|
||||||
city: z.string().optional(),
|
|
||||||
postalCode: z.string().optional(),
|
|
||||||
province: z.string().optional(),
|
|
||||||
country: z.string().optional(),
|
|
||||||
})
|
|
||||||
|
|
||||||
return schema.safeParse(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
static create(values: InvoiceRecipientProps): Result<InvoiceRecipient, Error> {
|
static create(values: InvoiceRecipientProps): Result<InvoiceRecipient, Error> {
|
||||||
const valueIsValid = InvoiceRecipient.validate(values)
|
const valueIsValid = InvoiceRecipient.validate(values);
|
||||||
|
|
||||||
if (!valueIsValid.success) {
|
if (valueIsValid.isFailure) {
|
||||||
return Result.fail(new Error(valueIsValid.error.issues[0].message));
|
return Result.fail(valueIsValid.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.ok(new InvoiceRecipient(values));
|
return Result.ok(new InvoiceRecipient(values));
|
||||||
@ -57,7 +45,6 @@ export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
|||||||
return InvoiceRecipient.create(updatedProps);
|
return InvoiceRecipient.create(updatedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public get name(): Name {
|
public get name(): Name {
|
||||||
return this.props.name;
|
return this.props.name;
|
||||||
}
|
}
|
||||||
@ -97,7 +84,4 @@ export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
|||||||
toPrimitive() {
|
toPrimitive() {
|
||||||
return this.getProps();
|
return this.getProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
"/:id",
|
"/:invoice_id",
|
||||||
//checkTabContext,
|
//checkTabContext,
|
||||||
validateRequest(GetCustomerInvoiceByIdRequestSchema, "params"),
|
validateRequest(GetCustomerInvoiceByIdRequestSchema, "params"),
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
@ -81,7 +81,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/*router.put(
|
/*router.put(
|
||||||
"/:customer_id",
|
"/:invoice_id",
|
||||||
//checkTabContext,
|
//checkTabContext,
|
||||||
validateRequest(UpdateCustomerInvoiceByIdParamsRequestSchema, "params"),
|
validateRequest(UpdateCustomerInvoiceByIdParamsRequestSchema, "params"),
|
||||||
validateRequest(UpdateCustomerInvoiceByIdRequestSchema, "body"),
|
validateRequest(UpdateCustomerInvoiceByIdRequestSchema, "body"),
|
||||||
@ -93,7 +93,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
|||||||
);*/
|
);*/
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/:id",
|
"/:invoice_id",
|
||||||
//checkTabContext,
|
//checkTabContext,
|
||||||
|
|
||||||
validateRequest(DeleteCustomerInvoiceByIdRequestSchema, "params"),
|
validateRequest(DeleteCustomerInvoiceByIdRequestSchema, "params"),
|
||||||
|
|||||||
@ -121,10 +121,12 @@ export class CustomerInvoiceMapper
|
|||||||
);
|
);
|
||||||
|
|
||||||
const discountPercentage = extractOrPushError(
|
const discountPercentage = extractOrPushError(
|
||||||
Percentage.create({
|
maybeFromNullableVO(source.discount_percentage_value, (value) =>
|
||||||
value: source.discount_percentage_value,
|
Percentage.create({
|
||||||
scale: source.discount_percentage_scale,
|
value: value,
|
||||||
}),
|
scale: source.discount_percentage_scale,
|
||||||
|
})
|
||||||
|
),
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|||||||
@ -114,8 +114,17 @@ export class CustomerInvoiceRepository
|
|||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
): Promise<Result<CustomerInvoice, Error>> {
|
): Promise<Result<CustomerInvoice, Error>> {
|
||||||
try {
|
try {
|
||||||
|
const { CustomerModel } = this._database.models;
|
||||||
|
|
||||||
const row = await CustomerInvoiceModel.findOne({
|
const row = await CustomerInvoiceModel.findOne({
|
||||||
where: { id: id.toString(), company_id: companyId.toString() },
|
where: { id: id.toString(), company_id: companyId.toString() },
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: CustomerModel,
|
||||||
|
as: "current_customer",
|
||||||
|
required: false, // false => LEFT JOIN
|
||||||
|
},
|
||||||
|
],
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -169,8 +178,6 @@ export class CustomerInvoiceRepository
|
|||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(instances);
|
|
||||||
|
|
||||||
return this._mapper.mapArrayToDomain(instances);
|
return this._mapper.mapArrayToDomain(instances);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
return Result.fail(translateSequelizeError(err));
|
return Result.fail(translateSequelizeError(err));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user