/******************************************************************************/
/***           Generated by IBExpert 2.5.0.22 26/08/2005 15.44.52           ***/
/******************************************************************************/



SET TERM ^ ; 



/******************************************************************************/
/***                           Stored Procedures                            ***/
/******************************************************************************/

CREATE PROCEDURE STATISTICA_CAMERE (
    DATA1 TIMESTAMP,
    DATA2 TIMESTAMP)
RETURNS (
    CAMERA VARCHAR(6),
    SOTTO INTEGER,
    UGUALE INTEGER,
    SOPRA INTEGER,
    VAL_SOTTO NUMERIC(15,2),
    VAL_UGUALE NUMERIC(15,2),
    VAL_SOPRA NUMERIC(15,2),
    NRLETTI INTEGER)
AS
BEGIN
  EXIT;
END^



SET TERM ; ^


/******************************************************************************/
/***                           Stored Procedures                            ***/
/******************************************************************************/


SET TERM ^ ;

ALTER PROCEDURE STATISTICA_CAMERE (
    DATA1 TIMESTAMP,
    DATA2 TIMESTAMP)
RETURNS (
    CAMERA VARCHAR(6),
    SOTTO INTEGER,
    UGUALE INTEGER,
    SOPRA INTEGER,
    VAL_SOTTO NUMERIC(15,2),
    VAL_UGUALE NUMERIC(15,2),
    VAL_SOPRA NUMERIC(15,2),
    NRLETTI INTEGER)
AS
DECLARE VARIABLE DATA_GIORNO TIMESTAMP;
DECLARE VARIABLE VAL_GIORNO NUMERIC(15,2);
DECLARE VARIABLE VENDUTA INTEGER;
DECLARE VARIABLE PAX INTEGER;
begin
  for select wghapp.codice,wghapp.nrletti from wghapp order by indice,codice into :CAMERA,:NRLETTI
  do
    begin
    sotto=0;
    sopra=0;
    uguale=0;
    val_sotto=0;
    val_sopra=0;
    val_uguale=0;
    for select data_giorno from conteggia_giorni(:data1,:data2) into :data_giorno
    do
    begin
        for select 1,(importo/(wghclist.partenza-wghclist.arrivo)),(coalesce(adulti,0)+coalesce(bambini,0))
            from wghclist
            where wghclist.arrivo<=:data_giorno and wghclist.partenza>:data_giorno
            and (coalesce(adulti,0)+coalesce(bambini,0))>0
            and wghclist.camera=:camera
            into :venduta,:val_giorno,:pax
        do
        begin
        if (pax<nrletti) then
            begin
            sotto=sotto+venduta;
            val_sotto=val_sotto+val_giorno;
            venduta=0;
            val_giorno=0;
            end
        else if (pax=nrletti) then
            begin
            uguale=uguale+venduta;
            val_uguale=val_uguale+val_giorno;
            venduta=0;
            val_giorno=0;
            end
        else
            begin
            sopra=sopra+venduta;
            val_sopra=val_sopra+val_giorno;
            venduta=0;
            val_giorno=0;
            end
        end
        end
    suspend;
    end

end
^


SET TERM ; ^
