import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwcll3Web</p>
* <p>Description : Liste des CLients </p>
* <p>Copyright : Copyright (c) 2012</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>28/06/2012</i>
* @version 1.0
 */
public class Jwlwcll3Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeClients</p>
		 * <p>Description : Liste des CLients </p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>28/06/2012</i>
		 * @version 1.0
		 */
		public static Jwlwcll3 getListeClients(
			String nbrep,
			String page,
			String fonction,
			String f_cd_cible,
			String f_num_cli,
			String f_nom,
			String f_raison_sociale,
			String f_cd_prt,
			String f_cd_zpo,
			String f_type_portage,
			String f_numero_voie,
			String f_mot_directeur_voie,
			String f_cd_postal,
			String f_cd_insee,
			String f_localite,
			String f_titre,
			String f_tpr_groupe,
			String f_tpr_num,
			String f_top_cas_logistic,
			String f_abo_actif,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwcll3 jwlwcll3 = new Jwlwcll3(broker, Constantes.SERVER_ADRESSE);
			
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwcll3.Nwlwcll3Axwebent vWebent = jwlwcll3.new Nwlwcll3Axwebent();
			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 	  = "WLWAALST";
			vWebent.fonction 		  = fonction;
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			jwlwcll3.setNwlwcll3Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwlwcll3.Nwlwcll3Axweblst vWeblst = jwlwcll3.new Nwlwcll3Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwcll3.setNwlwcll3Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwlwcll3.Nwlwcll3Awlwcll3 vLwcll3 = jwlwcll3.new Nwlwcll3Awlwcll3();
			Jwlwcll3.Nwlwcll3Awlwcll3Demande vLwcll3Demande = jwlwcll3.new Nwlwcll3Awlwcll3Demande();
			Jwlwcll3.Nwlwcll3Awlwcll3DemandeCritere_select vLwcll3DemandeCritere = jwlwcll3.new Nwlwcll3Awlwcll3DemandeCritere_select();
			vLwcll3DemandeCritere.f_cd_cible            = f_cd_cible;
			if(!"".equals(f_num_cli) && f_num_cli!=null){
				f_num_cli = Utils.transformNumClient(f_num_cli) ;
			}
			vLwcll3DemandeCritere.f_num_cli 			= f_num_cli;
			vLwcll3DemandeCritere.f_nom 				= f_nom;
			vLwcll3DemandeCritere.f_raison_sociale 		= f_raison_sociale;
			vLwcll3DemandeCritere.f_cd_prt 				= f_cd_prt;
			vLwcll3DemandeCritere.f_cd_zpo              = f_cd_zpo;
			vLwcll3DemandeCritere.f_type_portage 		= f_type_portage;
			vLwcll3DemandeCritere.f_numero_voie 		= f_numero_voie;
			vLwcll3DemandeCritere.f_mot_directeur_voie  = f_mot_directeur_voie;
			vLwcll3DemandeCritere.f_cd_postal       	= f_cd_postal;
			vLwcll3DemandeCritere.f_cd_insee 			= f_cd_insee;
			vLwcll3DemandeCritere.f_localite            = f_localite;
            vLwcll3DemandeCritere.f_titre 				= f_titre;
            vLwcll3DemandeCritere.f_tpr_groupe 			= f_tpr_groupe;
            vLwcll3DemandeCritere.f_tpr_num 			= f_tpr_num;
            vLwcll3DemandeCritere.f_top_cas_logistic 	= f_top_cas_logistic;
            vLwcll3DemandeCritere.f_abo_actif           = f_abo_actif;
			
			vLwcll3Demande.critere_select = vLwcll3DemandeCritere;
			vLwcll3.demande = vLwcll3Demande;
			jwlwcll3.setNwlwcll3Awlwcll3 (vLwcll3);
			
		    // CALL SERVER
		    jwlwcll3.nwlwcll3();
				                                
	        // Verification du code retour
			vWebent = jwlwcll3.getNwlwcll3Axwebent();
			System.out.println("Code retour nwlwcll3() = " + 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
				Jwlwcll3.Nwlwcll3Awlwcll3_tab vWeblsttab = jwlwcll3.getNwlwcll3Awlwcll3_tab();
				//Affichage de la liste des résultats
				if(PRINT == "YES") {
					System.out.println ("NUMERO_VOIE       = "	  +jwlwcll3.getNwlwcll3Awlwcll3().demande.critere_select.f_numero_voie);
					System.out.println ("F-MOT-DIRECTEUR-VOIE = " +jwlwcll3.getNwlwcll3Awlwcll3().demande.critere_select.f_mot_directeur_voie);
					System.out.println ("============================================================================================");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "  cd_cible="    		+ vWeblsttab.liste_ref[i].cd_cible 
									+ "; num_cli=" 			+ vWeblsttab.liste_ref[i].num_cli
									+ "; type_adresse=" 	+ vWeblsttab.liste_ref[i].type_adresse
									+ "; etat_adresse=" 	+ vWeblsttab.liste_ref[i].etat_adresse
									+ "; dt_debval_cpl=" 	+ vWeblsttab.liste_ref[i].dt_debval_cpl
									+ "; dt_debval=" 		+ vWeblsttab.liste_ref[i].dt_debval
									+ "; cd_prt=" 			+ vWeblsttab.liste_ref[i].cd_prt
									+ "; cd_zpo=" 			+ vWeblsttab.liste_ref[i].cd_zpo
									+ "; lib_fi_por_zone=" 	+ vWeblsttab.liste_ref[i].lib_fi_por_zone
									+ "; type_portage=" 	+ vWeblsttab.liste_ref[i].type_portage
									+ "; lig_nom="    		+ vWeblsttab.liste_ref[i].lig_nom
									+ "; lig_adr="    		+ vWeblsttab.liste_ref[i].lig_adr
									+ "; commune="    		+ vWeblsttab.liste_ref[i].commune
									+ "; cd_postal="    	+ vWeblsttab.liste_ref[i].cd_postal
									+ "; localite="    		+ vWeblsttab.liste_ref[i].localite
									+ "; cd_insee="    		+ vWeblsttab.liste_ref[i].cd_insee
									+ "; cd_insee="    		+ vWeblsttab.liste_ref[i].cd_insee
									+ "; code_titre=" 		+ vWeblsttab.liste_ref[i].code_titre
									+ "; nom_titre=" 		+ vWeblsttab.liste_ref[i].nom_titre
									+ "; tpr_groupe=" 		+ vWeblsttab.liste_ref[i].tpr_groupe
									+ "; tpr_num=" 			+ vWeblsttab.liste_ref[i].tpr_num
									+ "; top_cas_logistic=" + vWeblsttab.liste_ref[i].top_cas_logistic
									+ "; abo_actif=" 		+ vWeblsttab.liste_ref[i].abo_actif
									);
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwcll3.getNwlwcll3Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwcll3.getNwlwcll3Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwcll3.getNwlwcll3Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwcll3.getNwlwcll3Axweblst().nb_pages_totales);
				}
			}
			return jwlwcll3;
			
	   } // End getListeClients

		/**
		 * <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>28/06/2012</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA11");
			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;
											
			//--------------Donnée test-------------------------
			String nbrep 	  		= "20";
			String page 			= "1"; 
			String fonction 		= "I";
			String f_cd_cible 		= null;
			String f_num_cli 		= null;
			String f_nom 			= null;
			String f_raison_sociale = "PRISMA";
			String f_cd_prt 		= null;
			String f_cd_zpo 		= null;
			String f_type_portage 	= null;
			String f_numero_voie 	= null;
			String f_mot_directeur_voie = null;
			String f_cd_postal 			= null;
			String f_cd_insee 			= null;
			String f_localite 			= null;
			String f_titre 				= null;
			String f_tpr_groupe 		= null;
			String f_tpr_num 			= null;
			String f_top_cas_logistic 	= null;
			String f_abo_actif 			= null;
			//--------------Donnée test-------------------------	
			getListeClients(nbrep, page, fonction,
					f_cd_cible, f_num_cli, f_nom, f_raison_sociale, f_cd_prt, f_cd_zpo, 
					f_type_portage, f_numero_voie, f_mot_directeur_voie, f_cd_postal,
					f_cd_insee, f_localite, f_titre, f_tpr_groupe, f_tpr_num, f_top_cas_logistic, f_abo_actif,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker) ;
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwcll3Web