factuges.sql: añadidos procesimientos almacenados de tratamiento de capítulos y conceptos en presupuestos.

git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@211 0c75b7a4-871f-7646-8a2f-f78d34cc349f
This commit is contained in:
David Arranz 2008-01-13 21:33:19 +00:00
parent 91d3f6cc0b
commit 284291b41f

View File

@ -213,48 +213,154 @@ SET TERM ^ ;
/**** Stored Procedures ****/ /**** Stored Procedures ****/
/******************************************************************************/ /******************************************************************************/
CREATE PROCEDURE PRO_PRES_CAPITULOS ( SET TERM ^ ;
AID INTEGER)
RETURNS (
ID INTEGER,
ID_PRESUPUESTO INTEGER,
POSICION INTEGER,
TIPO_DETALLE VARCHAR(10),
CONCEPTO VARCHAR(2000),
IMPORTE_TOTAL NUMERIC(11,2),
VISIBLE SMALLINT)
AS
BEGIN
SUSPEND;
END^
CREATE PROCEDURE PRO_PRES_CAPITULOS (
aid integer)
returns (
id integer,
id_presupuesto integer,
posicion integer,
tipo_detalle varchar(10),
concepto varchar(2000),
importe_total numeric(11,2),
visible smallint)
as
declare variable num_filas integer;
declare variable contador integer;
declare variable existe numeric(11,2);
declare variable total_acumulado numeric(11,2);
begin
existe = 0;
total_acumulado = 0.0;
contador = 0;
num_filas = 0;
/* ¿Existe el presupuesto? */
for select count(*)
from presupuestos_cliente_detalles
where id_presupuesto = :AID
into :num_filas
do
begin
if (num_filas = 0) then
suspend;
end
/* Ver si hay conceptos al principio sin capitulos */
for select id, id_presupuesto, posicion, tipo_detalle
from presupuestos_cliente_detalles
where id_presupuesto = :AID
order by id_presupuesto, posicion
rows 1
into :ID, :ID_PRESUPUESTO, :POSICION, :TIPO_DETALLE
do
begin
if (TIPO_DETALLE = 'Concepto') then
EXISTE = 1;
end
if (existe = 1) then
begin
contador = 0;
/* Existen conceptos sin capitulo */
for select tipo_detalle, importe_total, coalesce(visible, 1)
from presupuestos_cliente_detalles
where id_presupuesto = :AID
order by id_presupuesto, posicion
into :TIPO_DETALLE, :IMPORTE_TOTAL, :VISIBLE
do
begin
contador = contador + 1;
if ((tipo_detalle <> 'Concepto') or (contador = num_filas)) then
begin
importe_total = total_acumulado;
tipo_detalle = 'Titulo';
concepto = 'General';
visible = 1;
ID = -1;
posicion = -1;
suspend;
break;
end
else begin
if (visible <> 0) then
total_acumulado = total_acumulado + importe_total;
end
end
end
for select id, id_presupuesto, posicion, tipo_detalle, F_RTFTOTEXT(concepto) as concepto,
importe_total, coalesce(visible, 1)
from presupuestos_cliente_detalles
where tipo_detalle <> 'Concepto' and id_presupuesto = :AID
order by id_presupuesto, posicion
into :ID, :ID_PRESUPUESTO, :POSICION, :TIPO_DETALLE, :CONCEPTO,
:IMPORTE_TOTAL, :VISIBLE
do
suspend;
end^
SET TERM ; ^
GRANT SELECT ON PRESUPUESTOS_CLIENTE_DETALLES TO PROCEDURE PRO_PRES_CAPITULOS;
GRANT EXECUTE ON PROCEDURE PRO_PRES_CAPITULOS TO SYSDBA;
SET TERM ^ ;
CREATE PROCEDURE PRO_PRES_CAPITULOS_CONCEPTOS ( CREATE PROCEDURE PRO_PRES_CAPITULOS_CONCEPTOS (
AID INTEGER) aid integer)
RETURNS ( returns (
ID INTEGER, id integer,
ID_PRESUPUESTO INTEGER, id_presupuesto integer,
POSICION INTEGER, posicion integer,
TIPO_DETALLE VARCHAR(10), tipo_detalle varchar(10),
ID_CAPITULO INTEGER, id_capitulo integer,
ID_ARTICULO INTEGER, id_articulo integer,
REFERENCIA VARCHAR(255), referencia varchar(255),
CONCEPTO VARCHAR(2000), concepto varchar(2000),
CANTIDAD INTEGER, cantidad integer,
IMPORTE_UNIDAD NUMERIC(11,2), importe_unidad numeric(11,2),
DESCUENTO FLOAT, descuento float,
IMPORTE_PORTE NUMERIC(11,2), importe_porte numeric(11,2),
IMPORTE_TOTAL NUMERIC(11,2), importe_total numeric(11,2),
VISIBLE SMALLINT) visible smallint)
AS as
BEGIN declare variable capitulo_actual integer;
SUSPEND; begin
END^ capitulo_actual = -1;
ID_CAPITULO = -1;
for select pre.id, pre.id_presupuesto, pre.posicion, pre.tipo_detalle,
pre.id_articulo, articulos.referencia, pre.concepto, pre.cantidad,
pre.importe_unidad, pre.descuento, pre.importe_porte,
pre.importe_total, coalesce(pre.visible, 1)
from presupuestos_cliente_detalles pre
left join articulos on (pre.id_articulo = articulos.id)
where pre.id_presupuesto = :AID
order by pre.id_presupuesto, pre.posicion
into :ID, :ID_PRESUPUESTO, :POSICION, :TIPO_DETALLE, :ID_ARTICULO,
:REFERENCIA, :CONCEPTO, :CANTIDAD, :IMPORTE_UNIDAD, :DESCUENTO,
:IMPORTE_PORTE, :IMPORTE_TOTAL, :VISIBLE
do
begin
if (:tipo_detalle <> 'Concepto') then
begin
capitulo_actual = :ID;
ID_CAPITULO = capitulo_actual;
end
else
suspend;
end
end^
SET TERM ; ^ SET TERM ; ^
GRANT SELECT ON PRESUPUESTOS_CLIENTE_DETALLES TO PROCEDURE PRO_PRES_CAPITULOS_CONCEPTOS;
GRANT SELECT ON ARTICULOS TO PROCEDURE PRO_PRES_CAPITULOS_CONCEPTOS;
GRANT EXECUTE ON PROCEDURE PRO_PRES_CAPITULOS_CONCEPTOS TO SYSDBA;
/******************************************************************************/ /******************************************************************************/
/**** Tables ****/ /**** Tables ****/