CREATE TABLE IF NOT EXISTS despachos (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
numero_guia text UNIQUE NOT NULL,
fecha date NOT NULL,
cliente text NOT NULL,
producto text NOT NULL,
calidad text,
kg_total numeric(8,2),
n_bidones integer,
precio_usd numeric(8,4),
tipo_cambio numeric(10,2),
valor_usd numeric(12,4),
valor_clp numeric(14,0),
estado text CHECK (estado IN ('pendiente','despachado','anulado')) DEFAULT 'pendiente',
chofer text,
patente text,
observaciones text,
temporada integer,
created_at timestamptz DEFAULT now()
);
ALTER TABLE despachos ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS "allow all" ON despachos;
CREATE POLICY "allow all" ON despachos FOR ALL USING (true) WITH CHECK (true);