

create  or replace PROCEDURE pr_create_export_ic  (
      idu_p        VARCHAR2,
      prg_p        VARCHAR2,
      dat_p        NUMBER,
      hre_p        NUMBER,
      pas_p        NUMBER
      ) is 
      
      begin
      declare
      
      cursor c_lstp(cod_p varchar2) is
      select *  from  slstp
      where  lstp_dat= dat_p
      and lstp_hre=hre_p
      and lstp_prg= prg_p
      and lstp_idu= idu_p
      and lstp_typ=cod_p
      ;
      r_lstp  c_lstp%rowtype;
      
      cursor c_zjc2 is
     SELECT ssta_lib,srul_lib,"ZJCP"."ZJCP_TST", "ZJCP"."ZJCP_STA", "ZJCP"."ZJCP_LET", "ZJCP"."ZJCP_NUM", "ZJCP"."ZJCP_CRE", "ZJCP"."ZJCP_DEB", sum("ZJCP"."ZJCP_RES") as MNT,
  "ZJCP"."ZJCP_MON", "ZJCP"."ZJCP_MONLIB"
 FROM   "NOVA"."ZJCP" "ZJCP",srul,ssta
 where  srul_let(+)="ZJCP"."ZJCP_LET" and srul_num(+)="ZJCP"."ZJCP_NUM" and srul_pas(+)=pas_p and srul_lan(+)='F' and ssta_pas(+)= pas_p and ssta_tst(+)= "ZJCP"."ZJCP_TST" and ssta_num(+)= "ZJCP"."ZJCP_STA"
group by ssta_lib,srul_lib, zjcp_tst,zjcp_sta,zjcp_let,zjcp_num,zjcp_cre,zjcp_deb,  "ZJCP"."ZJCP_MON", "ZJCP"."ZJCP_MONLIB"
 ORDER BY "ZJCP"."ZJCP_MON", "ZJCP"."ZJCP_STA", "ZJCP"."ZJCP_LET", "ZJCP"."ZJCP_NUM", "ZJCP"."ZJCP_DEB", "ZJCP"."ZJCP_CRE"
;



r_zjc2  c_zjc2%rowtype;
p_sficher varchar2(255);
v_DATA1  varchar2(4000);
ligne number;

v_periode  varchar2(2); 
v_annee  varchar2(4);  
v_date date;   
      begin
      
-------
open c_lstp('PER_DE');
fetch c_lstp into r_lstp;
close c_lstp;

v_periode:=r_lstp.lstp_par;


open c_lstp('ANN_DE');
fetch c_lstp into r_lstp;
close c_lstp;

v_annee:=r_lstp.lstp_par;

v_date:= ADD_MONTHS(to_date(v_annee||lpad(v_periode,'2','0')||'01','yyyyMMdd'),1)-1;
 -------entete
 ligne:=1;
 p_sficher:= 'Export_interface_comptable'||'_'|| dat_p ||'_'||hre_p ||'.xls'; -- Nom rapport
 v_DATA1:='Rubrique'||';'|| 'Description'||';'|| 'Centre de charge'||';'||'Descritpion Centre de charge'||';'||'Compte Debit'||';'||'Compte Credit'||';'||'Montant'||';'||'Periode';



  INSERT INTO sw_exp_lst (IDU,PRG,DAT,HRE,FICHIER,PAS,MAT,LIG,DATA)
  VALUES(idu_p,prg_p,dat_p,hre_p,p_sficher,pas_p,0,ligne,v_DATA1);
  ligne:=ligne+1;
    
 ------lignes
 
open c_zjc2;
loop
fetch c_zjc2  into r_zjc2;
exit when c_zjc2%notfound;

v_DATA1:=r_zjc2.zjcp_let||r_zjc2.zjcp_num||';'|| r_zjc2.srul_lib||';'|| r_zjc2.zjcp_sta||';'||r_zjc2.ssta_lib||';'||r_zjc2.zjcp_deb||';'||r_zjc2.zjcp_cre||';'||r_zjc2.MNT||';'||to_char(v_date,'dd.MM.yyyy');

 INSERT INTO sw_exp_lst (IDU,PRG,DAT,HRE,FICHIER,PAS,MAT,LIG,DATA)
  VALUES(idu_p,prg_p,dat_p,hre_p,p_sficher,pas_p,0,ligne,v_DATA1);
  ligne:=ligne+1;



  end loop;
  close c_zjc2;
  commit;  
      
  exception when others then
  null;
  
end;
end ; 


-- Start of DDL Script for Procedure NOVA.PR_CREATE_EXPORT_IC_ALL
-- Generated 16-mars-2022 8:15:03 from NOVA@smart02

CREATE OR REPLACE 
PROCEDURE pr_create_export_ic_all  (
      idu_p        VARCHAR2,
      prg_p        VARCHAR2,
      dat_p        NUMBER,
      hre_p        NUMBER,
      pas_p        NUMBER
      ) is 
      begin
      
      declare
v_per number;
v_ann number;
inbr number;
begin
v_per :=to_char(ADD_MONTHS(sysdate,-1),'MM');
v_ann :=to_char(ADD_MONTHS(sysdate,-1),'yyyy');


INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'PAS',pas_p,NULL,'JCPT',0,0,NULL);
                
                
 INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'PER_DE',v_per,NULL,'JCPT',0,0,NULL);
                
 INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'DATE_REF',to_char(sysdate,'yyyyMMdd'),NULL,'JCPT',0,0,NULL);   
                
                
                 
                
 INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'DAT_REF',to_char(sysdate,'yyyyMMdd'),NULL,'JCPT',0,0,NULL); 
                
                INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'ParamDe0',to_char(sysdate,'yyyyMMdd'),NULL,'JCPT',0,0,NULL); 
                
                                             
                
 INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'ANN_DE',v_ann,NULL,'JCPT',0,0,NULL);

       /* INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'COMPTA_OK','0',NULL,'JCPT',0,0,NULL);
                */
        
        INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'SAUT_PAGE','0',NULL,'JCPT',0,0,NULL);
        INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'JUSTIF_RUB','1',NULL,'JCPT',0,0,NULL);
        INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'JUSTIF_CT','1',NULL,'JCPT',0,0,NULL);
        INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'DAT_VAL',NULL,NULL,'JCPT',0,0,to_char(sysdate,'dd.mm.yyyy'));
        INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'MON',NULL,NULL,'JCPT',0,0,NULL);
              
            
            INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'MAT_DE',1,NULL,'JCPT',0,0,NULL);
                
                
                      
            INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'MAT_A',999999999,NULL,'JCPT',0,0,NULL);
            
            INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'TYP_PER','12',NULL,'JCPT',0,0,NULL);
                
                       INSERT INTO slstp
                (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,
                LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,
                LSTP_FLTS,LSTP_TXT)
            VALUES
                (idu_p,dat_p,hre_p,'SELECT','0',NULL,'JCPT',0,0,NULL);
            
                
                
           INSERT INTO slstp (LSTP_IDU,LSTP_DAT,LSTP_HRE,LSTP_TYP,LSTP_PAR,LSTP_CAT_NUM,LSTP_PRG,LSTP_TMP,LSTP_FLTS,LSTP_TXT,LSTP_LOC)
            select idu_p,dat_p,hre_p,'SRED_LET',srub_let,srub_num,'JCPT',0,1,NULL,NULL from  srub  where srub_pas=pas_p and srub_let in ('B','E', 'G', 'I');

       
     
        
     
 
 
 


INSERT INTO scivs (sciv_idu,sciv_dat,sciv_hre,sciv_pas,sciv_mat, sciv_prg)
                select distinct idu_p,dat_p,hre_p,SCIV_PAS,SCIV_MAT,'JCPT'
                    from sciv where
                       sciv_pas=pas_p and sciv_mil=1
                    ;
              



                    
         PR_INSERT_PRINTJOBPARAM(pas_p, idu_p, prg_p,dat_p, hre_p, 'F');
         pa_sb_compta.effacer( idu_p,0,0, prg_p);
  

        pa_sb_compta.initialiseretpiloter(idu_p,'JCPT',dat_p,hre_p,pas_p);
        
        
        
    pr_create_export_ic  (idu_p,'JCPT',dat_p,hre_p,pas_p);
    
    
    commit;
   
 

   
 
 exception  when others then null;

    end ;
    end;
/



-- End of DDL Script for Procedure NOVA.PR_CREATE_EXPORT_IC_ALL


