import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwtnl2Web</p>
* <p>Description : Consultation , Liste des tournees  pour une voies </p>
* <p>Copyright : Copyright (c) 2013</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>20/02/2013</i>
* @version 1.0
 */
public class Jwlwtnl2Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeTournees </p>
		 * <p>Description : Consultation , Liste des tournees  pour une voies  </p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>20/02/2013</i>
		 * @version 1.0
		 */
		public static Jwlwtnl2 getListeTournees (
			String nbrep,
			String page,
			String fonction,
			String f_matricule_mere,
			String f_code_cible,
			String f_cd_insee,
			String f_cd_postal,
			String f_localite,
			String f_bur_dir,
			String f_mot_directeur,
			String f_voi_id,
			String f_libelle_voie,
			String f_type_voie,
			String f_matricule_voie,
			String f_tpr_groupe,
			String f_tpr_num,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwtnl2 jwlwtnl2 = new Jwlwtnl2(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwtnl2.Nwlwtnl2Axwebent vWebent = jwlwtnl2.new Nwlwtnl2Axwebent();
			vWebent.dbid 		   	  = new BigDecimal (Constantes.DBID);
			vWebent.cible_exploitant  = Constantes.CD_CIBLE;
			vWebent.groupe_exploitant = groupe_exploitant;
			vWebent.numero_session 	  = new BigDecimal (numero_session);
			vWebent.utilisateur       = utilisateur;
			vWebent.transaction 	  = "WLWCLLST";
			vWebent.fonction 		  = fonction;
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			jwlwtnl2.setNwlwtnl2Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwtnl2.Nwlwtnl2Axweblst vWeblst = jwlwtnl2.new Nwlwtnl2Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwtnl2.setNwlwtnl2Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwtnl2.Nwlwtnl2Awlwtnl2 vLwtnl2 = jwlwtnl2.new Nwlwtnl2Awlwtnl2();
			Jwlwtnl2.Nwlwtnl2Awlwtnl2Demande vLwtnl2Demande = jwlwtnl2.new Nwlwtnl2Awlwtnl2Demande();
			
			Jwlwtnl2.Nwlwtnl2Awlwtnl2DemandeCritere_select vLwtnl2DemandeCritere = jwlwtnl2.new Nwlwtnl2Awlwtnl2DemandeCritere_select();
			
			if(!"".equals(f_matricule_mere) && f_matricule_mere!=null){
				vLwtnl2DemandeCritere.f_matricule_mere = new BigDecimal(f_matricule_mere);
			}
			if(!"".equals(f_voi_id) && f_voi_id!=null){
				vLwtnl2DemandeCritere.f_voi_id = new BigDecimal(f_voi_id);
			}
			if(!"".equals(f_matricule_voie) && f_matricule_voie!=null){
				vLwtnl2DemandeCritere.f_matricule_voie = new BigDecimal(f_matricule_voie);
			}
			
            vLwtnl2DemandeCritere.f_code_cible     = f_code_cible;
            vLwtnl2DemandeCritere.f_cd_insee  	   = f_cd_insee;
            vLwtnl2DemandeCritere.f_cd_postal  	   = f_cd_postal;
            vLwtnl2DemandeCritere.f_localite   	   = f_localite;
            vLwtnl2DemandeCritere.f_bur_dir   	   = f_bur_dir;
            vLwtnl2DemandeCritere.f_mot_directeur  = f_mot_directeur;
            vLwtnl2DemandeCritere.f_libelle_voie   = f_libelle_voie;
            vLwtnl2DemandeCritere.f_type_voie  	   = f_type_voie;
            vLwtnl2DemandeCritere.f_tpr_groupe     = f_tpr_groupe;
            vLwtnl2DemandeCritere.f_tpr_num  	   = f_tpr_num;
                

			vLwtnl2Demande.critere_select = vLwtnl2DemandeCritere;
			vLwtnl2.demande = vLwtnl2Demande;

			jwlwtnl2.setNwlwtnl2Awlwtnl2 (vLwtnl2);
			
		    // CALL SERVER
		    jwlwtnl2.nwlwtnl2();
				                                
	        // Verification du code retour
			vWebent = jwlwtnl2.getNwlwtnl2Axwebent();
			System.out.println("Code retour nwlwtnl2() = " + 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 {
				//Recuperation du resultat si code retour OK
				Jwlwtnl2.Nwlwtnl2Awlwtnl2_tab vWeblsttab = jwlwtnl2.getNwlwtnl2Awlwtnl2_tab();
				
				//Affichage de la liste des resultats
				if(PRINT == "YES") {
					
					System.out.println("\n");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "  cd_zpo="		+ vWeblsttab.liste_tournee[i].cd_zpo 
									+ "; type_portage=" + vWeblsttab.liste_tournee[i].type_portage
									+ "; zpo_libelle=" 	+ vWeblsttab.liste_tournee[i].zpo_libelle 
									+ "; tpr_groupe="  	+ vWeblsttab.liste_tournee[i].tpr_groupe
									+ "; tpr_num="  	+ vWeblsttab.liste_tournee[i].tpr_num 
									+ "; tpr_libelle=" 	+ vWeblsttab.liste_tournee[i].tpr_libelle
									+ "; top_actif=" 	+ vWeblsttab.liste_tournee[i].top_actif
									+ "; cd_prt=" 		+ vWeblsttab.liste_tournee[i].cd_prt 
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwtnl2.getNwlwtnl2Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwtnl2.getNwlwtnl2Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwtnl2.getNwlwtnl2Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwtnl2.getNwlwtnl2Axweblst().nb_pages_totales);
				}
			}
			return jwlwtnl2;
			
	   } // End getListeTournees 

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>09/01/2013</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA71");
			Broker broker 	  = JxweblogWeb.logonBroker();
			Jxweblog jxweblog = JxweblogWeb.getConnexion(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_cible						= connexion.cd_cible;
			String cd_stegrp 					= connexion.cd_stegrp;
		
			//--------------------Donnee test------------------
			String nbrep 		   = "20";
			String page 		   = "1";
			String fonction 	   = "I";
			String f_matricule_mere = "1457171";
			String f_code_cible 	= null;
			String f_cd_insee  		= null;
			String f_cd_postal   	= null;
			String f_localite   	= null;
			String f_bur_dir 		= null;
			String f_mot_directeur  = null;
			String f_voi_id   	    = null;
			String f_libelle_voie  	= null;
			String f_type_voie   	= null;
			String f_matricule_voie = null;
			String f_tpr_groupe 	= null;
			String f_tpr_num 		= null;

			//--------------------Donnee test------------------
			getListeTournees(nbrep, page, fonction, 
					f_matricule_mere, f_code_cible, f_cd_insee, f_cd_postal, f_localite, f_bur_dir, 
					f_mot_directeur, f_voi_id, f_libelle_voie, f_type_voie, f_matricule_voie,
					f_tpr_groupe,f_tpr_num,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwtnl2Web