CREATE PROCEDURE SP_AGENDA(
PDATA DATE,
PAGENDA INTEGER,
PDIASEMANA INTEGER)
RETURNS(
IDGH INTEGER,
CODHORA INTEGER,
DATA DATE,
HORA TIME,
QTATD INTEGER,
OCORR CHAR(1) CHARACTER SET NONE,
AGENDA INTEGER)
AS
declare variable wcont Integer;
declare variable wdom Char;
declare variable wseg Char;
declare variable wter Char;
declare variable wqua Char;
declare variable wqui Char;
declare variable wsex Char;
declare variable wsab Char;
declare variable wocorr Char;
begin
wocorr = 'F';
AGENDA = :PAGENDA;
for
SELECT "itemocorrencia"."iditemocorrencia", "itemocorrencia"."hora", "itemocorrencia"."qtatendimento"
FROM "itemocorrencia"
INNER JOIN "ocorrencia" ON ("itemocorrencia"."ocorrencia" = "ocorrencia"."idocorrencia")
WHERE "ocorrencia"."tipoocorrencia" = '1'
AND "ocorrencia"."agenda" = :PAGENDA
AND "ocorrencia"."data" = :PDATA
INTO :idgh, :hora, :qtatd
do
begin
wcont = 1;
wocorr = 'T';
while (wcont <= :qtatd) do
begin
codhora = wcont;
data = :PDATA;
ocorr = 'S';
Suspend;
wcont = wcont + 1;
end
end
if (wocorr = 'F') then
begin
if (PDIASEMANA = 1) then begin wdom = 'S'; end else begin wdom = '@'; end
if (PDIASEMANA = 2) then begin wseg = 'S'; end else begin wseg = '@'; end
if (PDIASEMANA = 3) then begin wter = 'S'; end else begin wter = '@'; end
if (PDIASEMANA = 4) then begin wqua = 'S'; end else begin wqua = '@'; end
if (PDIASEMANA = 5) then begin wqui = 'S'; end else begin wqui = '@'; end
if (PDIASEMANA = 6) then begin wsex = 'S'; end else begin wsex = '@'; end
if (PDIASEMANA = 7) then begin wsab = 'S'; end else begin wsab = '@'; end
for
SELECT "gradehoraria"."idgradehoraria", "gradehoraria"."hora", "gradehoraria"."qtatendimento"
FROM "agenda"
INNER JOIN "gradehoraria" ON ("agenda"."idagenda" = "gradehoraria"."agenda")
WHERE "agenda"."idagenda" = :PAGENDA
AND ("gradehoraria"."fldomingo" = :wdom OR
"gradehoraria"."flsegunda" = :wseg OR
"gradehoraria"."flterca" = :wter OR
"gradehoraria"."flquarta" = :wqua OR
"gradehoraria"."flquinta" = :wqui OR
"gradehoraria"."flsexta" = :wsex OR
"gradehoraria"."flsabado" = :wsab)
INTO :idgh, :hora, :qtatd
do
begin
wcont = 1;
while (wcont <= :qtatd) do
begin
codhora = wcont;
data = :PDATA;
ocorr = 'N';
Suspend;
wcont = wcont + 1;
end
end
end
end;