161 lines
3.3 KiB
TypeScript
161 lines
3.3 KiB
TypeScript
import { MoneySchema, PercentageSchema, QuantitySchema } from "@erp/core";
|
|
import { ArrayElement } from "@repo/rdx-utils";
|
|
import { z } from "zod/v4";
|
|
|
|
export const CustomerInvoiceItemFormSchema = z.object({
|
|
isNonValued: z.boolean().optional(),
|
|
|
|
description: z.string().optional(),
|
|
quantity: QuantitySchema.optional(),
|
|
unit_amount: MoneySchema.optional(),
|
|
|
|
subtotal_amount: MoneySchema.optional(),
|
|
discount_percentage: PercentageSchema.optional(),
|
|
discount_amount: MoneySchema.optional(),
|
|
taxable_amount: MoneySchema.optional(),
|
|
|
|
tax_codes: z.array(z.string()).default([]),
|
|
taxes: z
|
|
.array(
|
|
z.object({
|
|
label: z.string(),
|
|
percentage: z.number(),
|
|
amount: MoneySchema.optional(),
|
|
})
|
|
)
|
|
.optional(),
|
|
|
|
taxes_amount: MoneySchema.optional(),
|
|
total_amount: MoneySchema.optional(),
|
|
});
|
|
|
|
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(CustomerInvoiceItemFormSchema).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 type CustomerInvoiceItemFormData = ArrayElement<CustomerInvoiceFormData["items"]>;
|
|
|
|
export const defaultCustomerInvoiceItemFormData: CustomerInvoiceItemFormData = {
|
|
description: "",
|
|
|
|
quantity: {
|
|
value: "",
|
|
scale: "2",
|
|
},
|
|
|
|
unit_amount: {
|
|
currency_code: "EUR",
|
|
value: "",
|
|
scale: "4",
|
|
},
|
|
|
|
discount_percentage: {
|
|
value: "",
|
|
scale: "2",
|
|
},
|
|
|
|
tax_codes: ["iva_21"],
|
|
|
|
total_amount: {
|
|
currency_code: "EUR",
|
|
value: "",
|
|
scale: "4",
|
|
},
|
|
};
|
|
|
|
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",
|
|
},
|
|
};
|