import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwcdl1Web</p>
* <p>Description : Consultation , Liste des commandes </p>
* <p>Copyright : Copyright (c) 2012</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>05/09/2012</i>
* @version 1.0
 */
public class Jwlwcdl1Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeCommandes</p>
		 * <p>Description : Consultation , Liste des commandes </p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>05/09/2012</i>
		 * @version 1.0
		 */
		public static Jwlwcdl1 getListeCommandes(
			String nbrep,
			String page,
			String fonction,
			String f_dt_trt,
			String f_cd_cmd,
			String f_code_titre,
			String f_dt_parution,
			String f_cd_etat_cmd,
			String f_dt_trt_filtre,
			String f_top_cc,
			String c_cd_cmd,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwcdl1 jwlwcdl1 = new Jwlwcdl1(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwcdl1.Nwlwcdl1Axwebent vWebent = jwlwcdl1.new Nwlwcdl1Axwebent();
			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;
			jwlwcdl1.setNwlwcdl1Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwcdl1.Nwlwcdl1Axweblst vWeblst = jwlwcdl1.new Nwlwcdl1Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwcdl1.setNwlwcdl1Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwcdl1.Nwlwcdl1Awlwcdl1 vLwcdl1 = jwlwcdl1.new Nwlwcdl1Awlwcdl1();
			Jwlwcdl1.Nwlwcdl1Awlwcdl1Demande vLwcdl1Demande = jwlwcdl1.new Nwlwcdl1Awlwcdl1Demande();
			
			Jwlwcdl1.Nwlwcdl1Awlwcdl1DemandeCritere_copie vLwcdl1DemandeCopie	 = jwlwcdl1.new Nwlwcdl1Awlwcdl1DemandeCritere_copie();
			Jwlwcdl1.Nwlwcdl1Awlwcdl1DemandeCritere_select vLwcdl1DemandeCritere = jwlwcdl1.new Nwlwcdl1Awlwcdl1DemandeCritere_select();
			
			//vLwcdl1DemandeCritere.f_top_action =  f_top_action ;
			if(!"".equals(f_dt_trt) && f_dt_trt!=null){
				vLwcdl1DemandeCritere.f_dt_trt =  new BigDecimal(f_dt_trt);
			}
            vLwcdl1DemandeCritere.f_cd_cmd 	      = f_cd_cmd;
            vLwcdl1DemandeCritere.f_code_titre    = f_code_titre;
            vLwcdl1DemandeCopie.f_top_cc    	  = f_top_cc;
            vLwcdl1DemandeCopie.c_cd_cmd    	  = c_cd_cmd;
            if(!"".equals(f_dt_parution) && f_dt_parution!=null){
				vLwcdl1DemandeCritere.f_dt_parution =  new BigDecimal(f_dt_parution);
			}
            vLwcdl1DemandeCritere.f_cd_etat_cmd   = f_cd_etat_cmd;
            if(!"".equals(f_dt_trt_filtre) && f_dt_trt_filtre!=null){
				vLwcdl1DemandeCritere.f_dt_trt_filtre =  new BigDecimal(f_dt_trt_filtre);
			}    

			vLwcdl1Demande.critere_select = vLwcdl1DemandeCritere;
			vLwcdl1Demande.critere_copie  = vLwcdl1DemandeCopie;
			vLwcdl1.demande = vLwcdl1Demande;

			jwlwcdl1.setNwlwcdl1Awlwcdl1 (vLwcdl1);
			
		    // CALL SERVER
		    jwlwcdl1.nwlwcdl1();
				                                
	        // Verification du code retour
			vWebent = jwlwcdl1.getNwlwcdl1Axwebent();
			System.out.println("Code retour nwlwcdl1() = " + 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
				Jwlwcdl1.Nwlwcdl1Awlwcdl1_tab vWeblsttab = jwlwcdl1.getNwlwcdl1Awlwcdl1_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 (
									  "  id_cmd="				+ vWeblsttab.liste_commande[i].id_cmd 
									+ "; cd_cible=" 			+ vWeblsttab.liste_commande[i].cd_cible
									+ "; code_postal="  		+ vWeblsttab.liste_commande[i].code_titre
									+ "; lib_titre="  			+ vWeblsttab.liste_commande[i].lib_titre 
									+ "; cd_cmd=" 				+ vWeblsttab.liste_commande[i].cd_cmd
									+ "; lib_cmd=" 				+ vWeblsttab.liste_commande[i].lib_cmd
									+ "; cd_etat_cmd=" 			+ vWeblsttab.liste_commande[i].cd_etat_cmd 
									+ "; dt_parution=" 			+ vWeblsttab.liste_commande[i].dt_parution
									+ "; jour=" 				+ vWeblsttab.liste_commande[i].jour
									+ "; k_parution=" 			+ vWeblsttab.liste_commande[i].k_parution
									+ "; dt_trt=" 				+ vWeblsttab.liste_commande[i].dt_trt
									+ "; type_parution_presse=" + vWeblsttab.liste_commande[i].type_parution_presse
									+ "; top_coiffe=" 			+ vWeblsttab.liste_commande[i].top_coiffe
									+ "; top_supp_autorise=" 	+ vWeblsttab.liste_commande[i].top_supp_autorise
									+ "; type_cmd=" 			+ vWeblsttab.liste_commande[i].type_cmd
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwcdl1.getNwlwcdl1Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwcdl1.getNwlwcdl1Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwcdl1.getNwlwcdl1Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwcdl1.getNwlwcdl1Axweblst().nb_pages_totales);
				}
			}
			return jwlwcdl1;
			
	   } // End getListeCommandes

		/**
		 * <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>05/09/2012</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA62");
			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_dt_trt 	   = null;
			String f_cd_cmd 	   = null;
			String f_code_titre    = null;
			String f_dt_parution   = null;
			String f_cd_etat_cmd   = null;
			String f_dt_trt_filtre = null;
			String f_top_cc 	   = null;
			String c_cd_cmd 	   = null;

			//--------------------Donnee test------------------
			getListeCommandes(nbrep, page, fonction, 
					f_dt_trt, f_cd_cmd,f_code_titre, f_dt_parution, f_cd_etat_cmd, f_dt_trt_filtre,f_top_cc,c_cd_cmd, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwcdl1Web