import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwcll1Web</p>
* <p>Description : Consultation , Liste des Cas Logistiques </p>
* <p>Copyright : Copyright (c) 2012</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>28/03/2012</i>
* @version 1.0
 */
public class Jwlwcll1Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeLogistique</p>
		 * <p>Description : Consultation , Liste des Cas Logistiques </p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>28/03/2012</i>
		 * @version 1.0
		 */
		public static Jwlwcll1 getListeLogistique(
			String nbrep,
			String page,
			String fonction,
			String cd_prt,
			String cd_zpo,
			String type_portage,
			String num_cli,
			String cd_cible_1, 
			String num_reclamation, 
			String type_cas_logistic, 
			String etat_cas_logistic, 
			String mot_directeur_voie,
			String code_postal,
			String cd_insee,
			String localite,
			String numero_voie,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwcll1 jwlwcll1 = new Jwlwcll1(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwcll1.Nwlwcll1Axwebent vWebent = jwlwcll1.new Nwlwcll1Axwebent();
			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;
			jwlwcll1.setNwlwcll1Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwlwcll1.Nwlwcll1Axweblst vWeblst = jwlwcll1.new Nwlwcll1Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwcll1.setNwlwcll1Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwlwcll1.Nwlwcll1Awlwcll1 vLwcll1 = jwlwcll1.new Nwlwcll1Awlwcll1();
			Jwlwcll1.Nwlwcll1Awlwcll1Demande vLwcll1Demande = jwlwcll1.new Nwlwcll1Awlwcll1Demande();
			Jwlwcll1.Nwlwcll1Awlwcll1DemandeCritere_select vLwcll1DemandeCritere = jwlwcll1.new Nwlwcll1Awlwcll1DemandeCritere_select();
			vLwcll1DemandeCritere.cd_prt			 = cd_prt;
            vLwcll1DemandeCritere.cd_zpo             = cd_zpo;
            vLwcll1DemandeCritere.type_portage       = type_portage;
            
            System.out.println("num_cli avant ====== "+num_cli);
            if(!"".equals(num_cli) && num_cli!=null){
    			num_cli = Utils.transformNumClient(num_cli) ;
    		}
            System.out.println("num_cli apres ====== "+num_cli);
            
			vLwcll1DemandeCritere.num_cli		     = num_cli;
			vLwcll1DemandeCritere.cd_cible           = cd_cible_1;
			if(!"".equals(num_reclamation) && num_reclamation!=null){
				vLwcll1DemandeCritere.num_reclamation    = new BigDecimal(num_reclamation);
			}
            vLwcll1DemandeCritere.type_cas_logistic  = type_cas_logistic;			
            vLwcll1DemandeCritere.etat_cas_logistic  = etat_cas_logistic;			
            vLwcll1DemandeCritere.mot_directeur_voie = mot_directeur_voie;
			vLwcll1DemandeCritere.code_postal 		 = code_postal;
            vLwcll1DemandeCritere.cd_insee           = cd_insee;			
            vLwcll1DemandeCritere.localite       	 = localite;
            vLwcll1DemandeCritere.numero_voie		 = numero_voie;

			vLwcll1Demande.critere_select = vLwcll1DemandeCritere;
			vLwcll1.demande = vLwcll1Demande;

			jwlwcll1.setNwlwcll1Awlwcll1 (vLwcll1);
			
		    // CALL SERVER
		    jwlwcll1.nwlwcll1();
				                                
	        // Verification du code retour
			vWebent = jwlwcll1.getNwlwcll1Axwebent();
			System.out.println("Code retour nwlwcll1() = " + 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
				Jwlwcll1.Nwlwcll1Awlwcll1_tab vWeblsttab = jwlwcll1.getNwlwcll1Awlwcll1_tab();
				
				//Affichage de la liste des résultats
				if(PRINT == "YES") {
					System.out.println (
							"num_cli;cd_cible;numero_voie;lib_voie;localite;" +
							"cd_poste;type_adr;etat_adr;lig_nom;lig_adr;" +
							"cd_insee;cd_motif;lib_logistic;dt_deb_periode;" +
							"dt_fin_periode;num_reclamation;");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "num_cli="		+ vWeblsttab.ligne_ref[i].num_cli 
									+ "; cd_cible=" 	+ vWeblsttab.ligne_ref[i].cd_cible
									+ "; numero_voie="  + vWeblsttab.ligne_ref[i].numero_voie
									+ "; localite=" + vWeblsttab.ligne_ref[i].localite 
									+ "; cd_poste=" + vWeblsttab.ligne_ref[i].cd_poste 
									+ "; type_adr=" + vWeblsttab.ligne_ref[i].type_adr
									+ "; etat_adr=" + vWeblsttab.ligne_ref[i].etat_adr 
									+ "; dt_debval_cpl=" + vWeblsttab.ligne_ref[i].dt_debval_cpl.intValue() 
									+ "; lig_nom=" 	+ vWeblsttab.ligne_ref[i].lig_nom 
									+ "; lig_adr=" 	+ vWeblsttab.ligne_ref[i].lig_adr
									+ "; cd_insee=" + vWeblsttab.ligne_ref[i].cd_insee 
									+ "; cd_motif=" + vWeblsttab.ligne_ref[i].cd_motif 
									+ "; lib_motif=" 		+ vWeblsttab.ligne_ref[i].lib_motif 
									+ "; dt_deb_periode=" 	+ vWeblsttab.ligne_ref[i].dt_deb_periode 
									+ "; cd_reponse=" 	+ vWeblsttab.ligne_ref[i].cd_reponse
									+ "; lib_reponse=" 	+ vWeblsttab.ligne_ref[i].lib_reponse); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwcll1.getNwlwcll1Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwcll1.getNwlwcll1Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwcll1.getNwlwcll1Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwcll1.getNwlwcll1Axweblst().nb_pages_totales);
				}
			}
			return jwlwcll1;
			
	   } // End getListeLogistique

		/**
		 * <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/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;
		
			getListeLogistique ( "20", "2", "I",
									"0001",
									"0001",
									"N",
									null,
									null,
									null,
									null,
									null,
									null,
									null,
									null,
									null,
									null,
									groupe_exploitant,
									numero_session,
									utilisateur,
									cd_cible,
									cd_stegrp,
									broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwcll1Web