CREATE OR REPLACE
PACKAGE UTIL_APURAC AS 
    
   TYPE MINEFETMES_RECTYPE IS RECORD( 
      CDFILIAL     FILIAL.CDFILIAL%TYPE,
      NMTURNO      TURNOSERV.NMTURNO%TYPE,
      CDSERVFILI   SERVICO.CDSERVFILI%TYPE, 
      QTEFETIVOS   MINEFETMES.QTMINEFET%TYPE, 
      DSMINEFET    MINEFETMES.DSMINEFET%TYPE, 
      CDPRODUTO    PRODUTO.CDPRODUTO%TYPE, 
      DTBASE       DATE, 
      VRSERVICO    NUMBER); 
       
   TYPE MINEFETMES_CURTYPE IS REF CURSOR RETURN MINEFETMES_RECTYPE;    
    
   PROCEDURE OPENEFETMINCUR (C_MINEFETMES  IN OUT MINEFETMES_CURTYPE, 
                             P_CDFILIAL    IN FILIAL.CDFILIAL%TYPE, 
                             P_DATAINI     IN DATE, 
                             P_DATAFIM     IN DATE, 
                             P_IDFATUPLAN  IN VARCHAR, 
                             P_SERVMINEFETMES IN VARCHAR); 
    
   FUNCTION CalcValrServ (P_CDFILIAL   IN FILIAL.CDFILIAL%TYPE, 
                          P_CDCLIENTE  IN CLIENTE.CDCLIENTE%TYPE, 
                          P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                          P_DTFATURAM  IN EFECLIFAT.DTFATURAM%TYPE, 
                          P_CDTURNO    IN EFECLIFATTUR.CDTURNO%TYPE,
                          P_DTREF      IN DATE DEFAULT NULL) 
 
            RETURN NUMBER; 
   PRAGMA RESTRICT_REFERENCES (CalcValrServ, WNDS, WNPS); 
 
   FUNCTION CalcValrServTur (P_CDFILIAL   IN FILIAL.CDFILIAL%TYPE, 
                             P_CDCLIENTE  IN CLIENTE.CDCLIENTE%TYPE, 
                             P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                             P_DTFATURAM  IN EFECLIFAT.DTFATURAM%TYPE, 
                             P_CDTURNO    IN EFECLIFATTUR.CDTURNO%TYPE,
                             P_DTREF      IN DATE DEFAULT NULL) 
 
            RETURN NUMBER; 
   PRAGMA RESTRICT_REFERENCES (CalcValrServTur, WNDS, WNPS); 
 
 
   FUNCTION CalcEfetMini (P_CDFILIAL IN FILIAL.CDFILIAL%TYPE, 
                          P_CDCLIENTE IN CLIENTE.CDCLIENTE%TYPE, 
                          P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                          P_CDGRSERVFAT IN SERVCLIE.CDGRSERVFAT%TYPE, 
                          P_DTFATURAM IN EFECLIFAT.DTFATURAM%TYPE) 
            RETURN NUMBER; 
   PRAGMA RESTRICT_REFERENCES (CalcEfetMini, WNDS, WNPS); 
 
   PROCEDURE PrecoCorr (P_CDFILIAL IN FILIAL.CDFILIAL%TYPE, 
                        P_CDCLIENTE IN CLIENTE.CDCLIENTE%TYPE, 
                        P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                        P_CDGRSERVFAT IN SERVCLIE.CDGRSERVFAT%TYPE, 
                        P_QTEFETIVOS IN NUMBER, 
                        P_QTEFETMINI IN NUMBER, 
                        P_IDSERVGRUP IN VARCHAR2, 
                        P_VRSERVICO IN OUT NUMBER, 
                        P_VRPERCCORR IN OUT NUMBER, 
                        P_IDCONSTABCORR IN VARCHAR2 DEFAULT 'N',
                        P_DATAINI IN DATE DEFAULT NULL,
                        P_DATAFIM IN DATE DEFAULT NULL,
                        P_UTEFEPLA IN VARCHAR DEFAULT 'N'); 
   PRAGMA RESTRICT_REFERENCES (PrecoCorr, WNDS, WNPS); 
 
 
   FUNCTION DsNmServico (P_CDFILIAL   IN FILIAL.CDFILIAL%TYPE, 
                         P_CDCLIENTE  IN CLIENTE.CDCLIENTE%TYPE, 
                         P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                         P_DTFATURAM  IN EFECLIFAT.DTFATURAM%TYPE) 
 
            RETURN VARCHAR; 
   PRAGMA RESTRICT_REFERENCES (DsNmServico, WNDS, WNPS); 
 
   FUNCTION DsNmServicoTur (P_CDFILIAL   IN FILIAL.CDFILIAL%TYPE, 
                            P_CDCLIENTE  IN CLIENTE.CDCLIENTE%TYPE, 
                            P_CDSERVFILI IN EFECLIFAT.CDSERVFILI%TYPE, 
                            P_DTFATURAM  IN EFECLIFAT.DTFATURAM%TYPE, 
                            P_CDTURNO    IN EFECLIFATTUR.CDTURNO%TYPE) 
 
            RETURN VARCHAR; 
   PRAGMA RESTRICT_REFERENCES (DsNmServicoTur, WNDS, WNPS); 
    
   FUNCTION CalculaDtBase (P_NRDIABASE   IN NUMBER, 
                           P_DATAINI     IN DATE, 
                           P_DATAFIM     IN DATE)  
            RETURN DATE; 
   PRAGMA RESTRICT_REFERENCES (CalculaDtBase, WNDS, WNPS);        
   
   PROCEDURE INSERE_COMPENSACAO (P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
                                 P_CDFILIAPUR  IN FILIAL.CDFILIAL%TYPE,
                                 P_CDCLIENTE    IN CLIENTE.CDCLIENTE%TYPE,
                                 P_DATAINI      IN DATE,
                                 P_DATAFIM      IN DATE,
                                 P_NRAPURACFAT  IN NOTAFISCAL.NRAPURACFAT%TYPE,
                                 P_NRAPURACENTRAL  IN NOTAFISCAL.NRAPURACFAT%TYPE,
                                 P_CDFILIALCENTRAL IN FILIAL.CDFILIAL%TYPE);

   PROCEDURE INSERE_MINIMO_EFET_MES (P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
                                     P_CDFILIAPUR  IN FILIAL.CDFILIAL%TYPE,
                                     P_CDCLIENTE    IN CLIENTE.CDCLIENTE%TYPE,
                                     P_DATAINI      IN DATE,
                                     P_DATAFIM      IN DATE,
                                     P_NRAPURACFAT  IN NOTAFISCAL.NRAPURACFAT%TYPE,
                                     P_IDFATUPLAN   IN VARCHAR2,
                                     P_NRAPURACENTRAL  IN NOTAFISCAL.NRAPURACFAT%TYPE,
                                     P_CDFILIALCENTRAL IN FILIAL.CDFILIAL%TYPE);                                  
END UTIL_APURAC;
/