
import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwstl1Web</p>
 * <p>Description : Classe de récupération de la liste des Suivis Terrain</p>
 * <p>Copyright : Copyright (c) 2009</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR <i>15/03/2012</i>
 * @version 1.0
 */
public class Jwlwstl1Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getSuivisTerrain</p>
		 * <p>Description : Récupération de l'objet Liste des Suivis Terrain</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR <i>15/03/2012</i>
		 * @version 1.0
		 */
		public static Jwlwstl1 getSuivisTerrain(
			String nbrep,
			String page,
			String fonction,
			String cd_prt,
            String cd_zpo,
            String type_portage,
			String num_cli,
			String cd_cible_1,
			String trp_num,
            String cd_titre,
			String numero_voie, 
			String mot_directeur,
			String cd_postal,
			String cd_insee,
            String localite,
            String top_sans_reponse,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwstl1 jwlwstl1 = new Jwlwstl1(broker, Constantes.SERVER_ADRESSE);
			
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwstl1.Nwlwstl1Axwebent vWebent = jwlwstl1.new Nwlwstl1Axwebent();
			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;
			jwlwstl1.setNwlwstl1Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwlwstl1.Nwlwstl1Axweblst vWeblst = jwlwstl1.new Nwlwstl1Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 	      = new BigDecimal(page);
			jwlwstl1.setNwlwstl1Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwlwstl1.Nwlwstl1Awlwstl1 vLwstl1 				= jwlwstl1.new Nwlwstl1Awlwstl1();
			Jwlwstl1.Nwlwstl1Awlwstl1Demande vLwstl1Demande = jwlwstl1.new Nwlwstl1Awlwstl1Demande();
			Jwlwstl1.Nwlwstl1Awlwstl1DemandeCritere_select vLwstl1DemandeCritere = jwlwstl1.new Nwlwstl1Awlwstl1DemandeCritere_select();
			vLwstl1DemandeCritere.cd_prt			 = cd_prt;
            vLwstl1DemandeCritere.cd_zpo             = cd_zpo;
            vLwstl1DemandeCritere.type_portage       = type_portage;
            if(!"".equals(num_cli) && num_cli!=null){
    			num_cli = Utils.transformNumClient(num_cli) ;
    		}
			vLwstl1DemandeCritere.num_cli		     = num_cli;
			vLwstl1DemandeCritere.cd_cible           = cd_cible_1;
            vLwstl1DemandeCritere.trp_num            = trp_num;
            vLwstl1DemandeCritere.cd_titre           = cd_titre;			
            vLwstl1DemandeCritere.numero_voie        = numero_voie;			
			vLwstl1DemandeCritere.mot_directeur      = mot_directeur;
            vLwstl1DemandeCritere.cd_postal          = cd_postal;			
            vLwstl1DemandeCritere.cd_insee           = cd_insee;			
            vLwstl1DemandeCritere.localite           = localite;
            vLwstl1DemandeCritere.top_sans_reponse   = top_sans_reponse;

			vLwstl1Demande.critere_select = vLwstl1DemandeCritere;
			vLwstl1.demande = vLwstl1Demande;

			jwlwstl1.setNwlwstl1Awlwstl1 (vLwstl1);
			
		    // CALL SERVER
		    jwlwstl1.nwlwstl1();
				                                
	        // Verification du code retour
			vWebent = jwlwstl1.getNwlwstl1Axwebent();
			System.out.println("Code retour nwlwstl1() = " + 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 {
				//Récupération du résultat si code retour OK
				Jwlwstl1.Nwlwstl1Awlwstl1_tab vWeblsttab = jwlwstl1.getNwlwstl1Awlwstl1_tab();
				
				//Affichage de la liste des résultats
				if(PRINT == "YES") {
					System.out.println ("num_cli;lig_nom;lig_adr;cd_postal;localite;cd_titre;id_suivi;cd_cible");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println ("num_cli="+vWeblsttab.ligne_ref[i].num_cli + "; lig_nom=" + vWeblsttab.ligne_ref[i].lig_nom + "; lig_adr=" + vWeblsttab.ligne_ref[i].lig_adr + "; cd_postal=" + vWeblsttab.ligne_ref[i].cd_postal + "; localite=" + vWeblsttab.ligne_ref[i].localite + "; cd_titre=" + vWeblsttab.ligne_ref[i].cd_titre+ "; id_suivi=" + vWeblsttab.ligne_ref[i].id_suivi + "; cd_cible=" + vWeblsttab.ligne_ref[i].cd_cible); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : " 	+ jwlwstl1.getNwlwstl1Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : " 	+ jwlwstl1.getNwlwstl1Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " 	+ jwlwstl1.getNwlwstl1Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : " 	+ jwlwstl1.getNwlwstl1Axweblst().nb_pages_totales);
				}
			}
			return jwlwstl1;
			
	   } // End getSuivisTerrain

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR <i>15/03/2012</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA01");
			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;
			
			/* cd_prt, cd_zpo, type_portage, num_cli, cd_cible_1, trp_num, cd_titre, mot_directeur, num_voie, cd_postal, cd_insee, localite, groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, */
			//-------------Donnée test-----------------
			String nbrep 			= "15";
			String page 			= "1";
			String fonction 		= "0001";
			String cd_prt 			= "0001";
			String cd_zpo 			= null;
			String type_portage 	= null;
			String num_cli 			= null;
			String cd_cible_1 		= null;
			String trp_num 			= null;
			String cd_titre 		= null;
			String numero_voie 	 	= null; 
			String mot_directeur 	= null;
			String cd_postal 	 	= null;
			String cd_insee 	 	= null;
			String localite 	 	= null;
			String top_sans_reponse = null;
			//-------------Donnée test-----------------
			getSuivisTerrain(nbrep, page, fonction, cd_prt, cd_zpo, type_portage, num_cli, 
					cd_cible_1, trp_num, cd_titre, numero_voie, mot_directeur, cd_postal, 
					cd_insee, localite, top_sans_reponse, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);								
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwstl1Web