Ver Mensaje Individual
  #6  
Antiguo 10-04-2023
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Reputación: 23
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Estimado delphi50jmb, espero que este código le ayude en su tarea...

Código SQL [-]
CREATE OR ALTER trigger Facturas_AU0 for doctype
active after update position 0
AS
begin
     if ((old.Estado<>new.Estado) and (new.Estado='*')) then
        --Reversar factura
       execute procedure ReversarInventario(old.Numero);
     endif

end

CREATE PROCEDURE ReversarInventario
 ( NumeroFactura integer ) 
AS 
DECLARE VARIABLE CodigoArticulo integer; 
DECLARE VARIABLE CantidadARticulos integer;
BEGIN
   --Detalle Facturas
         --For Select que recorre el detalle de la factura,
   --recupera código y cantidad.
   for select 
       Codigo, Cantidad
     from Detalle_Facturas
     where Numero=:NumeroFactura
     into :CodigoArticulo, 
          :CantidadArticulos
     do begin
      --Reversa inventario actualizando existencia
      update Inventario
    set Existencia=Existencia + :CantidadArticulos
    where Codigo=:CodigoArticulo;
   end
END^
Saludos cordiales
Responder Con Cita