add contract storage fix various bugs and translations

This commit is contained in:
2026-02-16 01:23:31 +01:00
parent 627ddfc464
commit be8e32ebed
28 changed files with 1225 additions and 401 deletions

View File

@@ -1,4 +1,72 @@
import type { Cheque } from "@/components/PaymentMethods/Cheque";
import type { Form } from "./forms";
import type { Product } from "./products";
import type { Shipment } from "./shipments";
export type Contract = {
id: number;
form_id: number;
products: ContractProduct;
form: Form;
firstname: string;
lastname: string;
email: string;
phone: string;
payment_method: string;
cheque_quantity: number;
};
export type ContractCreate = {
form_id: number;
contract: Record<string, string | number | null>;
firstname: string;
lastname: string;
email: string;
phone: string;
payment_method: string;
cheque_quantity: number;
products: ContractProductCreate[];
cheques: Cheque[];
};
export type ContractInputs = {
firstname: string;
lastname: string;
email: string;
phone: string;
products: Record<string, string | number>;
payment_method: string;
cheques: Cheque[];
cheque_quantity: number;
};
export type ContractProduct = {
id: number;
product_id: number;
shipment_id: number;
quantity: number;
contract: Contract;
product: Product;
shipment?: Shipment | null;
};
export type ContractProductCreate = {
product_id: number;
shipment_id: number | null;
quantity: number;
};
export function tranformProducts(
products: Record<string, string | number>,
): ContractProductCreate[] {
return Object.entries(products).map(([key, value]) => {
const quantity = value;
const parts = key.split("-");
const shipment_id = parts[0] === "planned" ? Number(parts[1]) : null;
const product_id = parts[0] === "planned" ? Number(parts[2]) : Number(parts[1]);
return {
quantity: Number(quantity),
shipment_id: shipment_id,
product_id: product_id,
};
});
}