121 lines
2.5 KiB
TypeScript
121 lines
2.5 KiB
TypeScript
import { MoneySchema, PercentageSchema, QuantitySchema } from "@erp/core";
|
|
import { z } from "zod/v4";
|
|
|
|
export const CustomerInvoiceFormSchema = z.object({
|
|
invoice_number: z.string().optional(),
|
|
status: z.string(),
|
|
series: z.string().optional(),
|
|
|
|
invoice_date: z.string().optional(),
|
|
operation_date: z.string().optional(),
|
|
|
|
customer_id: z.string().optional(),
|
|
|
|
description: z.string().optional(),
|
|
notes: z.string().optional(),
|
|
|
|
language_code: z
|
|
.string({
|
|
error: "El idioma es obligatorio",
|
|
})
|
|
.min(1, "Debe indicar un idioma")
|
|
.toUpperCase() // asegura mayúsculas
|
|
.default("es"),
|
|
|
|
currency_code: z
|
|
.string({
|
|
error: "La moneda es obligatoria",
|
|
})
|
|
.min(1, "La moneda no puede estar vacía")
|
|
.toUpperCase() // asegura mayúsculas
|
|
.default("EUR"),
|
|
|
|
taxes: z
|
|
.array(
|
|
z.object({
|
|
tax_code: z.string(),
|
|
taxable_amount: MoneySchema,
|
|
taxes_amount: MoneySchema,
|
|
})
|
|
)
|
|
.optional(),
|
|
|
|
items: z
|
|
.array(
|
|
z.object({
|
|
position: z.string(),
|
|
description: z.string(),
|
|
quantity: QuantitySchema,
|
|
unit_amount: MoneySchema,
|
|
|
|
tax_codes: z.array(z.string()).default([]),
|
|
|
|
subtotal_amount: MoneySchema,
|
|
discount_percentage: PercentageSchema,
|
|
discount_amount: MoneySchema,
|
|
taxable_amount: MoneySchema,
|
|
taxes_amount: MoneySchema,
|
|
total_amount: MoneySchema,
|
|
})
|
|
)
|
|
.optional(),
|
|
|
|
subtotal_amount: MoneySchema,
|
|
discount_percentage: PercentageSchema,
|
|
discount_amount: MoneySchema,
|
|
taxable_amount: MoneySchema,
|
|
taxes_amount: MoneySchema,
|
|
total_amount: MoneySchema,
|
|
});
|
|
|
|
export type CustomerInvoiceFormData = z.infer<typeof CustomerInvoiceFormSchema>;
|
|
|
|
export const defaultCustomerInvoiceFormData: CustomerInvoiceFormData = {
|
|
invoice_number: "",
|
|
status: "draft",
|
|
series: "",
|
|
|
|
invoice_date: "",
|
|
operation_date: "",
|
|
|
|
description: "",
|
|
notes: "",
|
|
|
|
language_code: "es",
|
|
currency_code: "EUR",
|
|
|
|
taxes: [],
|
|
|
|
items: [],
|
|
|
|
subtotal_amount: {
|
|
currency_code: "EUR",
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
discount_amount: {
|
|
currency_code: "EUR",
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
discount_percentage: {
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
taxable_amount: {
|
|
currency_code: "EUR",
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
taxes_amount: {
|
|
currency_code: "EUR",
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
total_amount: {
|
|
currency_code: "EUR",
|
|
value: "0",
|
|
scale: "2",
|
|
},
|
|
};
|