Gracias duilioisola por tu respuesta pero como cometí el error de escribir 2 veces el mismo código en mi mensaje anterior y no el código de los procedimientos que supuestamente tienen el error para que se viera que si esta escrita la sentencia
SUSPEND y según yo están escritas de forma correcta.
Código SQL
[-]
CREATE PROCEDURE V_VENTAS
returns (
id integer,
fecha date,
id_cliente integer,
apenom varchar(123),
id_documento integer,
desc_documento varchar(20),
numdocumento integer,
id_formapagos integer,
contado char(1),
numpagos integer,
diasplazo integer,
id_impuesto integer,
desc_impuesto varchar(10),
porceimpu decimal(18,2),
porpedido char(1),
id_ordencompra integer,
id_usuario varchar(10),
nombre varchar(90),
calendariopago char(1),
cancelada char(1),
devuelta char(1),
subtotal decimal(15,2),
impuesto decimal(15,2),
total decimal(15,2),
abonos decimal(15,2),
saldo decimal(15,2),
fecha_envio date,
fletera varchar(60),
chofer varchar(130),
vehiculo varchar(50),
placas varchar(10),
id_subcategorias integer,
desc_subcategoria varchar(30),
id_categoria integer,
desc_categoria varchar(30))
as
BEGIN
FOR
SELECT T_VENTAS.ID, T_VENTAS.FECHA, T_VENTAS.ID_CLIENTE, T_CLIENTES.APENOM, T_VENTAS.ID_DOCUMENTO,
T_DOCUMENTOS.DESCRIPCION, T_VENTAS.NUMDOCUMENTO, T_VENTAS.ID_FORMAPAGOS, T_VENTAS.CONTADO,
T_VENTAS.NUMPAGOS, T_VENTAS.DIASPLAZO, T_VENTAS.ID_IMPUESTO, T_IMPUESTOS.DESCRIPCION, T_VENTAS.PORCEIMPU,
T_VENTAS.PORPEDIDO, T_VENTAS.ID_ORDENCOMPRA, T_VENTAS.ID_USUARIO, T_USUARIOS.NOMBRE,
T_VENTAS.CALENDARIOPAGO, T_VENTAS.CANCELADA, t_ventas.fecha_envio, t_ventas.fletera, t_ventas.chofer,
t_ventas.vehiculo, t_ventas.placas
FROM T_VENTAS
INNER JOIN T_CLIENTES ON (T_VENTAS.ID_CLIENTE = T_CLIENTES.ID)
INNER JOIN T_DOCUMENTOS ON (T_VENTAS.ID_DOCUMENTO = T_DOCUMENTOS.ID)
INNER JOIN T_IMPUESTOS ON (T_VENTAS.ID_IMPUESTO = T_IMPUESTOS.ID)
INNER JOIN T_USUARIOS ON (T_VENTAS.ID_USUARIO = T_USUARIOS.ID)
INTO :ID,
:FECHA,
:ID_CLIENTE,
:APENOM,
:ID_DOCUMENTO,
:_DESC_DOCUMENTO,
:NUMDOCUMENTO,
:ID_FORMAPAGOS,
:CONTADO,
:NUMPAGOS,
:_DIASPLAZO,
:ID_IMPUESTO,
:_DESC_IMPUESTO,
:_PORCEIMPU,
:_PORPEDIDO,
:ID_ORDENCOMPRA,
:ID_USUARIO,
:NOMBRE,
:CALENDARIOPAGO,
:CANCELADA,
:fecha_envio,
:fletera,
:chofer,
:vehiculo,
:_Placas
DO
BEGIN
Select sum(v_detalleventas.totalventa) from v_detalleventas where v_detalleventas.id_venta = :id into :SUBTOTAL;
if (subtotal is null) then subtotal = 0;
Impuesto = Subtotal * PORCEIMPU / 100;
Total = subtotal + impuesto;
Select sum(v_cobros.abonos) from v_cobros where v_cobros.id_venta = :ID into :ABONOS;
if (abonos is null) then abonos = 0;
Saldo = Total - Abonos;
SELECT Max(T_SUBCATEGORIAS.ID)
FROM T_DETALLEVENTAS
INNER JOIN T_DETALLEPRODUCTO ON (T_DETALLEVENTAS.ID_PRODUCTO = T_DETALLEPRODUCTO.ID)
INNER JOIN T_PRODUCTOSALMACEN ON (T_DETALLEPRODUCTO.ID_PRODUCTO = T_PRODUCTOSALMACEN.ID)
INNER JOIN T_PRODUCTOS ON (T_PRODUCTOSALMACEN.ID_PRODUCTO = T_PRODUCTOS.ID)
INNER JOIN T_SUBCATEGORIAS ON (T_PRODUCTOS.ID_SUBCATEGORIA = T_SUBCATEGORIAS.ID)
WHERE ((T_DETALLEVENTAS.ID_VENTA = :ID)) into :ID_SUBCATEGORIAS;
Select t_subcategorias.descripcion, t_subcategorias.id_categoria from t_subcategorias where
t_subcategorias.id = :ID_SUBCATEGORIAS into :_DESC_SUBCATEGORIA, :ID_CATEGORIA;
Select t_categorias.descripcion from t_categorias where t_categorias.id = :ID_CATEGORIA
into :_DESC_CATEGORIA;
Select Min(t_detalleventas.devuelta) from t_detalleventas where t_detalleventas.id_venta = :id
into :_Devuelta;
SUSPEND;
END
END
CREATE PROCEDURE V_DETALLEPRODUCTO
returns (
id integer,
id_productoalmacen integer,
id_productogeneral integer,
clave varchar(20),
desc_producto varchar(60),
desc_factura blob sub_type 1 segment size 80,
codigobarras varchar(13),
detallar varchar(1),
cantidad decimal(15,2),
vendido char(1),
adicional1 varchar(30),
adicional2 varchar(30),
adicional3 varchar(30),
adicional4 varchar(30),
adicional5 varchar(30),
adicional6 varchar(30),
adicional7 varchar(30),
adicional8 varchar(30),
adicional9 varchar(15),
adicional10 varchar(30),
adicional11 varchar(30),
id_impuesto integer,
desc_impuesto varchar(10),
id_unimed integer,
desc_unimed varchar(5),
costouni decimal(18,2),
descuento decimal(18,2),
costodescuento decimal(15,2),
costo1 decimal(18,2),
costo2 decimal(18,2),
costo3 decimal(18,2),
costosubtotal decimal(15,2),
costoimpuesto decimal(15,2),
costototal decimal(15,2),
id_compra integer,
fechaentrada date,
id_venta integer,
fechaventa date,
etiqueta char(1),
minimomenudeo integer,
id_unimedmenudeo integer,
desc_unimedmenudeo varchar(5),
id_tpmenudeo integer,
utilidadmenudeo decimal(18,2),
preciomenudeo decimal(15,2),
ventamedmayoreo char(1),
id_unimedmedmayoreo integer,
desc_unimedmedmayoreo varchar(5),
minimomedmayoreo integer,
id_tpmedmayoreo integer,
utilidadmedmayoreo decimal(18,2),
preciomedmayoreo decimal(15,2),
ventamayoreo char(1),
id_unimedmayoreo integer,
desc_unimedmayoreo varchar(5),
minimomayoreo integer,
id_tpmayoreo integer,
utilidadmayoreo decimal(18,2),
preciomayoreo decimal(15,2),
id_impuestov integer,
desc_impuventa varchar(10),
impuestomenudeo decimal(15,2),
impuestomedmayoreo decimal(15,2),
impuestomayoreo decimal(15,2),
totalmenudeo decimal(15,2),
totalmedmayoreo decimal(15,2),
totalmayoreo decimal(15,2),
enconsigna char(1),
id_cliente_consigna integer,
cliente varchar(123),
fechaconsigna date,
id_almacen integer,
desc_almacen varchar(20),
envalesalida char(1),
id_vale integer,
pventa char(1),
ubicacion varchar(10),
id_subcategoria integer,
desc_subcategoria varchar(30),
id_categoria integer,
desc_categoria varchar(30),
id_familia integer,
desc_familia varchar(30),
descuentomaximo decimal(15,2))
as
declare variable impucompra decimal(15,2);
declare variable impuventa decimal(15,2);
declare variable campo_ad varchar(30);
BEGIN
FOR
SELECT T_DETALLEPRODUCTO.ID, T_DETALLEPRODUCTO.ID_PRODUCTO, T_DETALLEPRODUCTO.VENDIDO,
T_DETALLEPRODUCTO.ADICIONAL1, T_DETALLEPRODUCTO.ADICIONAL2, T_DETALLEPRODUCTO.ADICIONAL3,
T_DETALLEPRODUCTO.ADICIONAL4, T_DETALLEPRODUCTO.ADICIONAL5, T_DETALLEPRODUCTO.ADICIONAL6,
T_DETALLEPRODUCTO.ADICIONAL7, T_DETALLEPRODUCTO.ADICIONAL8, T_DETALLEPRODUCTO.ADICIONAL9,
T_DETALLEPRODUCTO.ADICIONAL10, T_DETALLEPRODUCTO.ADICIONAL11, T_DETALLEPRODUCTO.ID_IMPUESTO,
T_DETALLEPRODUCTO.ID_UNIMED, T_DETALLEPRODUCTO.COSTOUNI, T_DETALLEPRODUCTO.DESCUENTO,
T_DETALLEPRODUCTO.COSTO1, T_DETALLEPRODUCTO.COSTO2, T_DETALLEPRODUCTO.COSTO3,
T_DETALLEPRODUCTO.ID_COMPRA, T_DETALLEPRODUCTO.FECHAENTRADA, T_DETALLEPRODUCTO.ID_VENTA,
T_DETALLEPRODUCTO.FECHAVENTA, T_DETALLEPRODUCTO.ETIQUETA, T_DETALLEPRODUCTO.MINIMOMENUDEO,
T_DETALLEPRODUCTO.ID_UNIMEDMENUDEO, T_DETALLEPRODUCTO.ID_TPMENUDEO,
T_DETALLEPRODUCTO.UTILIDADMENUDEO,
T_DETALLEPRODUCTO.VENTAMEDMAYOREO, T_DETALLEPRODUCTO.ID_UNIMEDMEDMAYOREO,
T_DETALLEPRODUCTO.MINIMOMEDMAYOREO,
T_DETALLEPRODUCTO.ID_TPMEDMAYOREO, T_DETALLEPRODUCTO.UTILIDADMEDMAYOREO,
T_DETALLEPRODUCTO.VENTAMAYOREO,
T_DETALLEPRODUCTO.ID_UNIMEDMAYOREO, T_DETALLEPRODUCTO.MINIMOMAYOREO,
T_DETALLEPRODUCTO.ID_TPMAYOREO,
T_DETALLEPRODUCTO.UTILIDADMAYOREO, T_DETALLEPRODUCTO.ID_IMPUESTOV, T_DETALLEPRODUCTO.ENCONSIGNA,
T_DETALLEPRODUCTO.ID_CLIENTE_CONSIGNA, T_DETALLEPRODUCTO.FECHACONSIGNA,
t_detalleproducto.envalesalida, t_detalleproducto.id_vale
FROM T_DETALLEPRODUCTO
INTO :ID, :ID_PRODUCTOALMACEN, :VENDIDO, :ADICIONAL1, :ADICIONAL2, :ADICIONAL3, :ADICIONAL4,
:ADICIONAL5, :ADICIONAL6, :ADICIONAL7, :ADICIONAL8, :ADICIONAL9, :ADICIONAL10, :ADICIONAL11,
:ID_IMPUESTO, :ID_UNIMED, :COSTOUNI, :_DESCUENTO, :COSTO1, :COSTO2, :COSTO3, :ID_COMPRA, :FECHAENTRADA,
:ID_VENTA, :FECHAVENTA, :ETIQUETA, :MINIMOMENUDEO, :ID_UNIMEDMENUDEO, :ID_TPMENUDEO, :UTILIDADMENUDEO,
:VENTAMEDMAYOREO, :ID_UNIMEDMEDMAYOREO, :MINIMOMEDMAYOREO, :ID_TPMEDMAYOREO, :UTILIDADMEDMAYOREO,
:VENTAMAYOREO, :ID_UNIMEDMAYOREO, :MINIMOMAYOREO, :ID_TPMAYOREO, :UTILIDADMAYOREO, :ID_IMPUESTOV, :ENCONSIGNA,
:ID_CLIENTE_CONSIGNA, :FECHACONSIGNA, :envalesalida, :id_vale
DO
BEGIN
Select t_productosalmacen.id_producto, t_productosalmacen.cantidad, t_productosalmacen.id_almacen from
t_productosalmacen where t_productosalmacen.id = :ID_PRODUCTOALMACEN
into :ID_PRODUCTOGENERAL, :CANTIDAD, :id_almacen;
Select t_productos.clave, t_productos.descripcion, t_productos.descripcion_fact, t_productos.detallar,
t_productos.pventa, t_productos.codigobarras, t_productos.ubicacion, t_productos.id_subcategoria
from t_productos where t_productos.id = :ID_PRODUCTOGENERAL
into :CLAVE, :_DESC_PRODUCTO, :_DESC_FACTURA, :_DETALLAR, :_Pventa, :codigobarras, :ubicacion, :id_subcategoria;
if (Detallar = 'S') then Cantidad = 1;
select t_impuestos.descripcion, t_impuestos.monto from t_impuestos where t_impuestos.id = :ID_IMPUESTO
into :_DESC_IMPUESTO, :IMPUCOMPRA;
select t_unidadmedida.abreviatura from t_unidadmedida where t_unidadmedida.id = :ID_UNIMED
into :_DESC_UNIMED;
Costodescuento= costouni - descuento;
CostoSubtotal= costodescuento+costo1+costo2+costo3;
CostoImpuesto= costosubtotal * impucompra / 100;
CostoTotal = CostoSubtotal + CostoImpuesto;
Select t_unidadmedida.abreviatura from t_unidadmedida where t_unidadmedida.id = :ID_UNIMEDMENUDEO into :_DESC_UNIMEDMENUDEO;
if (id_tpmenudeo = 0)
then preciomenudeo = utilidadmenudeo;
Else PrecioMenudeo = (COSTOTOTAL / (100 - UTILIDADMENUDEO)) * 100;
Select t_unidadmedida.abreviatura from t_unidadmedida where t_unidadmedida.id = :ID_UNIMEDMEDMAYOREO into :_DESC_UNIMEDMEDMAYOREO;
if (VENTAMEDMAYOREO = 'S')
then if (id_tpmedmayoreo = 0)
then preciomedmayoreo = utilidadmedmayoreo;
Else PrecioMedmayoreo = (COSTOTOTAL / (100 - UTILIDADmedmayoreo)) * 100;
else PrecioMedMayoreo = 0;
Select t_unidadmedida.abreviatura from t_unidadmedida where t_unidadmedida.id = :ID_UNIMEDMAYOREO into :_DESC_UNIMEDMAYOREO;
if (VENTAMAYOREO = 'S')
then if (id_tpmayoreo = 0)
then preciomayoreo = utilidadmayoreo;
Else Preciomayoreo = (COSTOTOTAL / (100 - UTILIDADmayoreo)) * 100;
Else PrecioMayoreo = 0;
select t_impuestos.descripcion, t_impuestos.monto from t_impuestos where t_impuestos.id = :ID_IMPUESTOV into :_DESC_IMPUVENTA, :IMPUVENTA;
ImpuestoMenudeo = PrecioMenudeo * impuventa / 100;
totalmenudeo = preciomenudeo + ImpuestoMenudeo;
ImpuestoMedmayoreo = Preciomedmayoreo * impuventa / 100;
totalmedmayoreo = preciomedmayoreo + ImpuestoMedMayoreo;
ImpuestoMayoreo = PrecioMayoreo * impuventa / 100;
totalMayoreo = precioMayoreo + ImpuestoMayoreo;
if (enconsigna = 'S')
then Select t_clientes.apenom from t_clientes where t_clientes.id = :ID_CLIENTE_CONSIGNA into :CLIENTE;
Else Begin
id_cliente_consigna = null;
Cliente = null;
FechaConsigna = null;
End
select t_almacen.descripcion from t_almacen where t_almacen.id = :id_almacen into :_Desc_almacen;
Select t_subcategorias.descripcion, t_subcategorias.id_categoria, t_subcategorias.descuentomaximo from
t_subcategorias where t_subcategorias.id = :id_subcategoria
into :_Desc_subcategoria, :id_categoria, :_Descuentomaximo;
Select t_categorias.descripcion, t_categorias.id_familia from t_categorias where t_categorias.id
= :id_subcategoria into :_Desc_categoria, :id_familia;
Select t_familias.descripcion from t_familias where t_familias.id = :id_familia into :_Desc_familia;
if (detallar = 'S')
then Begin
Select t_adicionales.adicional1 from t_Adicionales where t_adicionales.id_producto
= :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional1;
Select t_adicionales.adicional2 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional2;
Select t_adicionales.adicional3 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional3;
Select t_adicionales.adicional4 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional4;
Select t_adicionales.adicional5 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional5;
Select t_adicionales.adicional6 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional6;
Select t_adicionales.adicional7 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional7;
Select t_adicionales.adicional8 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional8;
Select t_adicionales.adicional9 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional9;
Select t_adicionales.adicional10 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional10;
Select t_adicionales.adicional11 from t_Adicionales where t_adicionales.id_producto = :id_productogeneral into :campo_ad;
if (not(campo_ad is null)) then desc_factura = desc_factura||' '||campo_ad||' '||adicional11;
End
SUSPEND;
END
END
CREATE PROCEDURE V_COBROS
returns (
id integer,
id_venta integer,
id_notacargo integer,
num_cobro varchar(10),
cobro integer,
cobros integer,
enganche char(1),
capital decimal(18,2),
pagofijo decimal(18,2),
interes decimal(18,2),
impuesto decimal(18,2),
totalinteres decimal(18,2),
total decimal(18,2),
mensualidad decimal(18,2),
abonos decimal(15,2),
saldo decimal(15,2),
fecha date,
motivo varchar(20),
numero_mov integer,
id_cliente integer,
cliente varchar(123))
as
BEGIN
FOR
SELECT T_COBROS.ID, T_COBROS.ID_VENTA, T_COBROS.ID_NOTACARGO, T_COBROS.COBRO, T_COBROS.COBROS,
T_COBROS.ENGANCHE, T_COBROS.CAPITAL, T_COBROS.PAGOFIJO, T_COBROS.INTERES, T_COBROS.IMPUESTO,
T_COBROS.TOTALINTERES, T_COBROS.TOTAL, T_COBROS.MENSUALIDAD, T_COBROS.FECHA
FROM T_COBROS
INTO :ID, :ID_VENTA, :ID_NOTACARGO, :COBRO, :COBROS, :ENGANCHE, :CAPITAL, :_PAGOFIJO, :INTERES, :IMPUESTO,
:TOTALINTERES, :TOTAL, :MENSUALIDAD, :FECHA DO
BEGIN
num_cobro = :COBRO||'/'||:COBROS;
if (not(id_venta is null))
then Begin
motivo = 'Venta';
numero_mov = id_venta;
Select t_ventas.id_cliente from t_ventas where t_ventas.id = :ID_VENTA into :ID_CLIENTE;
End
if (not(ID_NOTACARGO is null))
then Begin
motivo = 'Nota de cargo';
Numero_mov = ID_NotaCargo;
Select t_notascargoclientes.id_cliente from t_notascargoclientes where t_notascargoclientes.id = :ID_NOTACARGO into :ID_CLIENTE;
End
Select t_clientes.apenom from t_clientes where t_clientes.id = :ID_CLIENTE into :CLIENTE;
select sum(t_abonoscobros.monto) from t_abonoscobros where t_abonoscobros.id_cobro = :ID into :ABONOS;
if (abonos is null) then abonos = 0;
Saldo = mensualidad - abonos;
SUSPEND;
END
END