import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwbwfpm1Web</p>
 * <p>Description : Classe de ajout, modification, suppression </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>02/05/2012</i>
 * @version 1.0
 */
public class Jwbwfpm1Web {

	private static String PRINT = "NO";
	/**
	 * <p>Titre : getFichePortage</p>
	 * <p>Description : Interrogation d'une Fiche Portage</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>02/05/2012</i>
	 * @version 1.0
	 */
	public static Jwbwfpm1 getFichePortage(
				String cd_cible1,       
				String num_cli,        
				String type_adr,      
				String etat_adr,        
				String dt_debval_cpl,
				String cd_zpo,
				String cd_prt,
				String type_portage,
			
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_stegrp,
				String cd_cible,
				String dbid,
				String rpc_name,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwbwfpm1 Jwbwfpm1 = new Jwbwfpm1(broker, Utils.formatSrvAddr (rpc_name));
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwbwfpm1.Nwlwfpm1Axwebent vWebent = Jwbwfpm1.new Nwlwfpm1Axwebent();
		vWebent.dbid = new BigDecimal (dbid);
		vWebent.cible_exploitant = cd_cible;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session = new BigDecimal (numero_session);
		vWebent.utilisateur =  utilisateur;
		vWebent.transaction 	  = "WBWEFLSA";
		vWebent.fonction 		  = "VISU";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		Jwbwfpm1.setNwlwfpm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwbwfpm1.Nwlwfpm1Awlwfpm1 vLwfpm1 					= Jwbwfpm1.new Nwlwfpm1Awlwfpm1();
		Jwbwfpm1.Nwlwfpm1Awlwfpm1Cle_adresse vLwfpm1Adresse = Jwbwfpm1.new Nwlwfpm1Awlwfpm1Cle_adresse();
		vLwfpm1Adresse.cd_cible = cd_cible1;
		if(!"".equals(num_cli) && num_cli!=null){
			System.out.println("num_cli avant = " + num_cli);
			vLwfpm1Adresse.num_cli = Utils.transformNumClient(num_cli) ;
			System.out.println("num_cli après = " + vLwfpm1Adresse.num_cli);
		}
		vLwfpm1Adresse.type_adr 	= type_adr;
		vLwfpm1Adresse.etat_adr 	= etat_adr;
		vLwfpm1Adresse.cd_zpo 		= cd_zpo;
		vLwfpm1Adresse.cd_prt 		= cd_prt;
		vLwfpm1Adresse.type_portage = type_portage;
		
		if(!"".equals(dt_debval_cpl) && dt_debval_cpl!=null){
			vLwfpm1Adresse.dt_debval_cpl = new BigDecimal(dt_debval_cpl);
		}
		
		vLwfpm1.cle_adresse = vLwfpm1Adresse;
		
		Jwbwfpm1.setNwlwfpm1Awlwfpm1(vLwfpm1);
		
		// CALL SERVER
		Jwbwfpm1.nwlwfpm1();
		
		// Verification du code retour
		vWebent = Jwbwfpm1.getNwlwfpm1Axwebent();
		System.out.println("Code retour nwlwfpm1() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return Jwbwfpm1;
	   }
	   
	/**
	 * <p>Titre : setFichePortage</p>
	 * <p>Description : Mise à jour d'une Fiche Portage </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>02/05/2012</i>
	 * @version 1.0
	 */
	public static Jwbwfpm1 setFichePortage(
		String fonction,
		String cd_cible1,       
		String num_cli,        
		String type_adr,      
		String etat_adr,        
		String dt_debval_cpl,      
		String top_adr_port,
		String numero_voie,
		String commune,
		String cd_postal,
		String localite,
		String voie,
		String cpl_voie,
		String mot_directeur_voie,
		String num_ordre_voie,
		String cd_insee,
		String lib_resid,
		String cd_acc_resid_1,
		String lib_acc_resid_1,
		String cd_acc_resid_2,
		String lib_acc_resid_2,
		String lib_bati,
		String cd_acc_bati_1,
		String lib_acc_bati_1,
		String cd_acc_bati_2,
		String lib_acc_bati_2,
		String lib_esca,
		String cd_acc_esca_1,
		String lib_acc_esca_1,
		String cd_acc_esca_2,
		String lib_acc_esca_2,
		String mode_depot,
		String num_boite,
		String cpl_depot,
		String top_etiq,
		String tpr_groupe,
		String cd_zpo,
		String cd_prt,
		String type_portage,
		String usr_maj,
		String dt_maj,
		String hhmmss_maj,
		String isn_maj,
		String top_liste_gardien,
			
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_stegrp,
		String cd_cible,
		String dbid,
		String rpc_name,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwbwfpm1 Jwbwfpm1 = new Jwbwfpm1(broker, Utils.formatSrvAddr (rpc_name));
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwbwfpm1.Nwlwfpm1Axwebent vWebent = Jwbwfpm1.new Nwlwfpm1Axwebent();
		vWebent.dbid = new BigDecimal (dbid);
		vWebent.cible_exploitant = cd_cible;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session = new BigDecimal (numero_session);
		vWebent.utilisateur =  utilisateur;
		vWebent.transaction 	  = "WBWEFLSA";
		vWebent.fonction 		  = fonction;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		Jwbwfpm1.setNwlwfpm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwbwfpm1.Nwlwfpm1Awlwfpm1 vLwfpm1 = Jwbwfpm1.new Nwlwfpm1Awlwfpm1();
		
		if(!"".equals(top_adr_port) && top_adr_port!=null){
			vLwfpm1.top_adr_port = top_adr_port ;
		}
		Jwbwfpm1.Nwlwfpm1Awlwfpm1Cle_adresse vLwfpm1Adresse = Jwbwfpm1.new Nwlwfpm1Awlwfpm1Cle_adresse();
		vLwfpm1Adresse.cd_cible = cd_cible1;
		
		if(!"".equals(num_cli) && num_cli!=null){
			System.out.println("num_cli avant = " + num_cli);
			num_cli = Utils.transformNumClient(num_cli) ;
			System.out.println("num_cli après = " + num_cli);
		}
		vLwfpm1Adresse.num_cli 		= num_cli;
		vLwfpm1Adresse.type_adr 	= type_adr;
		vLwfpm1Adresse.etat_adr 	= etat_adr;
		vLwfpm1Adresse.cd_zpo 		= cd_zpo;
		vLwfpm1Adresse.cd_prt 		= cd_prt;
		vLwfpm1Adresse.type_portage = type_portage;
		
		if(!"".equals(dt_debval_cpl) && dt_debval_cpl!=null){
			vLwfpm1Adresse.dt_debval_cpl = new BigDecimal(dt_debval_cpl);
		}
		vLwfpm1.cle_adresse = vLwfpm1Adresse;
		
		Jwbwfpm1.Nwlwfpm1Awlwfpm1ReponseInfo_portage vLwfpm1info = Jwbwfpm1.new Nwlwfpm1Awlwfpm1ReponseInfo_portage();
		vLwfpm1info.lib_resid       = lib_resid;
		vLwfpm1info.cd_acc_resid_1 	= cd_acc_resid_1;
		vLwfpm1info.lib_acc_resid_1 = lib_acc_resid_1;
		vLwfpm1info.cd_acc_resid_2 	= cd_acc_resid_2;
		vLwfpm1info.lib_acc_resid_2 = lib_acc_resid_2;
		vLwfpm1info.lib_bati 		= lib_bati;
		vLwfpm1info.cd_acc_bati_1 	= cd_acc_bati_1;
		vLwfpm1info.lib_acc_bati_1 	= lib_acc_bati_1;
		vLwfpm1info.cd_acc_bati_2 	= cd_acc_bati_2;
		vLwfpm1info.lib_acc_bati_2 	= lib_acc_bati_2;
		vLwfpm1info.lib_esca 		= lib_esca;
		vLwfpm1info.cd_acc_esca_1 	= cd_acc_esca_1;
		vLwfpm1info.lib_acc_esca_1 	= lib_acc_esca_1;
		vLwfpm1info.cd_acc_esca_2 	= cd_acc_esca_2;
		vLwfpm1info.lib_acc_esca_2 	= lib_acc_esca_2;
		vLwfpm1info.mode_depot 		= mode_depot;
		vLwfpm1info.num_boite 		= num_boite;
		vLwfpm1info.cpl_depot 		= cpl_depot;
		vLwfpm1info.top_etiq 		= top_etiq;
		vLwfpm1info.tpr_groupe 		= tpr_groupe;
		
		Jwbwfpm1.Nwlwfpm1Awlwfpm1ReponseInfo_adresse infoAdresse = Jwbwfpm1.new Nwlwfpm1Awlwfpm1ReponseInfo_adresse();
		infoAdresse.numero_voie 		= numero_voie;
		infoAdresse.commune				= commune;
		infoAdresse.cd_postal 			= cd_postal;
		infoAdresse.localite 			= localite;
		infoAdresse.voie 				= voie;
		infoAdresse.cpl_voie 			= cpl_voie;
		infoAdresse.mot_directeur_voie 	= mot_directeur_voie;
		infoAdresse.num_ordre_voie 		= num_ordre_voie;
		infoAdresse.cd_insee 			= cd_insee;
		
		Jwbwfpm1.Nwlwfpm1Awlwfpm1Reponse reponse = Jwbwfpm1.new Nwlwfpm1Awlwfpm1Reponse();
		reponse.info_portage         = vLwfpm1info;
		vLwfpm1.reponse              = reponse;
		vLwfpm1.top_adr_port		 = top_adr_port;
		vLwfpm1.reponse.info_adresse = infoAdresse;
		
		vLwfpm1.usr_maj	= usr_maj;
		if(!"".equals(dt_maj) && dt_maj!=null){
			vLwfpm1.dt_maj=new BigDecimal(dt_maj);
		}
		if(!"".equals(hhmmss_maj) && hhmmss_maj!=null){
			vLwfpm1.hhmmss_maj = new BigDecimal(hhmmss_maj);
		}
		if(!"".equals(isn_maj) && isn_maj!=null){
			vLwfpm1.isn_maj = new BigDecimal(isn_maj);
		}
		if(!"".equals(top_liste_gardien) && top_liste_gardien!=null){
			vLwfpm1.top_liste_gardien = top_liste_gardien ;
		}
		Jwbwfpm1.setNwlwfpm1Awlwfpm1(vLwfpm1);
		
		// CALL SERVER
		Jwbwfpm1.nwlwfpm1();
		
		// Verification du code retour
		vWebent = Jwbwfpm1.getNwlwfpm1Axwebent();
		System.out.println("Code retour nwlwfpm1() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return Jwbwfpm1;
	   } // End setFichePortage

	/**
	 * <p>Titre : annulerFichePortage</p>
	 * <p>Description : Annulation d'une Fiche Portage </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>02/05/2012</i>
	 * @version 1.0
	 */
	public static Jwbwfpm1 annulerFichePortage(
		String cd_cible1,       
		String num_cli,        
		String type_adr,      
		String etat_adr,        
		String dt_debval_cpl,
		String cd_zpo,
		String cd_prt,
		String type_portage,
		String usr_maj,
		String dt_maj,
		String hhmmss_maj,
		String isn_maj, 
		
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_stegrp,
		String cd_cible,
		String dbid,
		String rpc_name,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwbwfpm1 Jwbwfpm1 = new Jwbwfpm1(broker, Utils.formatSrvAddr (rpc_name));
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwbwfpm1.Nwlwfpm1Axwebent vWebent = Jwbwfpm1.new Nwlwfpm1Axwebent();
		vWebent.dbid = new BigDecimal (dbid);
		vWebent.cible_exploitant = cd_cible;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session = new BigDecimal (numero_session);
		vWebent.utilisateur =  utilisateur;
		vWebent.transaction 	  = "WBWEFLSA";
		vWebent.fonction 		  = "ANNULER";	
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		Jwbwfpm1.setNwlwfpm1Axwebent (vWebent);
	
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwbwfpm1.Nwlwfpm1Awlwfpm1 vLwfpm1 = Jwbwfpm1.new Nwlwfpm1Awlwfpm1();
		Jwbwfpm1.Nwlwfpm1Awlwfpm1Cle_adresse vLwfpm1Adresse = Jwbwfpm1.new Nwlwfpm1Awlwfpm1Cle_adresse();
		vLwfpm1Adresse.cd_cible = cd_cible1;
		
		if(!"".equals(num_cli) && num_cli!=null){
			System.out.println("num_cli avant = " + num_cli);
			num_cli = Utils.transformNumClient(num_cli) ;
			System.out.println("num_cli après = " + num_cli);
		}
		vLwfpm1Adresse.num_cli 		= num_cli;
		vLwfpm1Adresse.type_adr 	= type_adr;
		vLwfpm1Adresse.etat_adr 	= etat_adr;
		vLwfpm1Adresse.cd_zpo		= cd_zpo;
		vLwfpm1Adresse.cd_prt		= cd_prt;
		vLwfpm1Adresse.type_portage = type_portage;
		if(!"".equals(dt_debval_cpl) && dt_debval_cpl!=null){
			vLwfpm1Adresse.dt_debval_cpl = new BigDecimal(dt_debval_cpl);
		}
		vLwfpm1.cle_adresse = vLwfpm1Adresse;
		
		vLwfpm1.usr_maj	= usr_maj;
		if(!"".equals(dt_maj) && dt_maj!=null){
			vLwfpm1.dt_maj=new BigDecimal(dt_maj);
		}
		if(!"".equals(hhmmss_maj) && hhmmss_maj!=null){
			vLwfpm1.hhmmss_maj = new BigDecimal(hhmmss_maj);
		}
		
		if(!"".equals(isn_maj) && isn_maj!=null){
			vLwfpm1.isn_maj = new BigDecimal(isn_maj);
		}

		Jwbwfpm1.setNwlwfpm1Awlwfpm1(vLwfpm1);
		
		// CALL SERVER
		Jwbwfpm1.nwlwfpm1();
		
		// Verification du code retour
		vWebent = Jwbwfpm1.getNwlwfpm1Axwebent();
		System.out.println("Code retour nwlwfpm1() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return Jwbwfpm1;
	   } // End annulerFichePortage
	   
	   /**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2012</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("BW") ;
			JxweblogBw.setUtilisateur ("MADAA01");
			JxweblogBw.setPassword ("MADAAF1");
			PRINT = "YES";
			Broker broker 	  = JxweblogBw.logonBroker();
			Jxweblog jxweblog = JxweblogBw.getConnexion("00", "14", "SRV1", broker);
			PRINT = "YES";
			
			Jxweblog.NxweblogAxwebent connexion = jxweblog.getNxweblogAxwebent();
			String groupe_exploitant = connexion.groupe_exploitant;
			String numero_session = Integer.toString(connexion.numero_session.intValue());
			String utilisateur = connexion.utilisateur;
			String cd_stegrp = connexion.cd_stegrp;
			String cd_cible = connexion.cd_cible;
			String dbid = "14";
			String rpc_name = "SRV1";
			//Constructeur TEST
			//------------------ données test-------------
			String cd_cible1 	 = "50";       
			String num_cli 		 = "1/330";        
			String type_adr 	 = "PPAL";      
			String etat_adr 	 = "D";
			String dt_debval_cpl = "79939579";
			String cd_zpo 		 = null;
			String cd_prt 		 = null;
			String type_portage  = null;
			
			//-------------------donnée de test-----------
			Jwbwfpm1 Jwbwfpm1 = getFichePortage (
					cd_cible1,num_cli,type_adr,etat_adr,dt_debval_cpl,cd_zpo,cd_prt,type_portage,
					groupe_exploitant, numero_session, utilisateur, cd_stegrp, cd_cible, dbid,rpc_name,broker);
			//retour
			System.out.println("DEBUT TEST CONTROLE .......................") ;
			Jwbwfpm1.Nwlwfpm1Awlwfpm1 Jwbwfpm1Reponse = Jwbwfpm1.getNwlwfpm1Awlwfpm1() ; 
			Jwbwfpm1.Nwlwfpm1Awlwfpm1Reponse liste_reponse = Jwbwfpm1Reponse.reponse;

			System.out.println("top_trouve  ="+ liste_reponse.top_trouve) ;
			System.out.println("etat_ticket ="+ liste_reponse.info_portage.etat_ticket) ;
			System.out.println("top_etiq    ="+ liste_reponse.info_portage.top_etiq) ;

			System.out.println("lig_nom 	="+ liste_reponse.info_adresse.lig_nom) ;
			System.out.println("numero_voie ="+ liste_reponse.info_adresse.numero_voie) ;
			System.out.println("lig_adr 	="+ liste_reponse.info_adresse.lig_adr) ;
			System.out.println("cd_postal 	="+ liste_reponse.info_adresse.cd_postal) ;
			System.out.println("localite 	="+ liste_reponse.info_adresse.localite) ;

			/* setFichePortage( "08", "3/127605", "PPAL", "D", "79929371", "RV COUCOU", "INE", "C1 NEW", "COD", "C2", "BT", "INE", "I1", "INI", "I2", "ES1", "INI", "I3", "LIB", "I4", "ARE", "EBBBB", "CCCMPL", "N", "X", groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp) ; */
			//Test de MODIFICATION
			//-------------------donnée de test-----------
			/*String cd_cible1 		= "";       
			String num_cli 			= "";        
			String type_adr 		= "";      
			String etat_adr 		= "";        
			String dt_debval_cpl 	= "";      
			String action 			= "";
			String cd_zpo 		 	= null;
			String cd_prt 		 	= null;
			String type_portage  	= null;
			
			String usr_maj			 = "MADAA01" ;
			String dt_maj			 = "20120513" ;
			String hhmmss_maj		 = "152435" ;
			String top_liste_gardien = null;
			
			//-------------------donnée de test-----------
			System.out.println("DEBUT TEST CREATION : cas logistique .................") ;
			Jwbwfpm1 Jwbwfpm1Modif = setFichePortage(
			cd_cible1,num_cli,type_adr,etat_adr,dt_debval_cpl,action,
			lib_resid,cd_acc_resid_1,lib_acc_resid_1,
			cd_acc_resid_2,lib_acc_resid_2,lib_bati,cd_acc_bati_1,
			lib_acc_bati_1,cd_acc_bati_2,lib_acc_bati_2,lib_esca,cd_acc_esca_1,
			lib_acc_esca_1, cd_acc_esca_2,lib_acc_esca_2,mode_depot,num_boite,
			cpl_depot,top_etiq,tpr_groupe,cd_zpo,cd_prt,type_portage,
			usr_creat,dt_creat,hhmmss_creat,usr_maj,dt_maj,hhmmss_maj,usr_ann,dt_ann,hhmmss_ann,top_liste_gardien,
			groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp);
			
			Jwbwfpm1.Nwlwfpm1Awlwfpm1 Jwbwfpm1Reponse = Jwbwfpm1Modif.getNwlwfpm1Awlwfpm1() ; 
			Jwbwfpm1.Nwlwfpm1Awlwfpm1Reponse liste_Reponse = Jwbwfpm1Reponse.reponse;
			System.out.println("lig_nom 	="+ liste_Reponse.info_adresse.lig_nom) ;
			System.out.println("numero_voie	="+ liste_Reponse.info_adresse.numero_voie) ;
			System.out.println("lig_adr		="+ liste_Reponse.info_adresse.lig_adr) ;
			System.out.println("cd_poste	="+ liste_Reponse.info_adresse.cd_poste) ;
			System.out.println("localite	="+ liste_Reponse.info_adresse.localite) ;*/
			JxweblogBw.closeConnexion (rpc_name, jxweblog, broker);			
			JxweblogBw.closeBroker (broker);			
			System.out.println("...Fin de test ...");
		}
			
}