import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : JwlwoztmWeb</p>
 * <p>Description : Soumission d’ordo, de zonage et d’affectation de tournée.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>07/03/2013</i>
 * @version 1.0
 */
 
public class JwlwoztmWeb {
	private static final int TAILLE = 50;
	
	/**
	 * <p>Titre : setSoumission</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwoztm setSoumission(
		String i_action,
		String i_cd_cible,
		String i_cd_insee[],
		String i_cd_postal[],
		String i_cd_zpo,
		String i_type_portage,
		String i_tpr_groupe,
		String i_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
	    Jwlwoztm jwlwoztm 		  = new Jwlwoztm(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwoztm.NwlwoztmAxwebent vWebent = jwlwoztm.new NwlwoztmAxwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "MODIF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwoztm.setNwlwoztmAxwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwoztm.NwlwoztmAwlwoztm vLwoztm 				= jwlwoztm.new NwlwoztmAwlwoztm();
		Jwlwoztm.NwlwoztmAwlwoztmDemande vLwoztmDemande = jwlwoztm.new NwlwoztmAwlwoztmDemande();
		
		String[] tab_cd_insee  = new String[TAILLE];
		String[] tab_cd_postal = new String[TAILLE];
		
		for(int i=0;i<i_cd_insee.length ;i++){
			tab_cd_insee[i]  = i_cd_insee[i];
		}
		
		for(int i=0;i< i_cd_postal.length ;i++){
			tab_cd_postal[i] = i_cd_postal[i];
		}
		
		
		
		vLwoztmDemande.i_action    	  = i_action;
		vLwoztmDemande.i_cd_cible     = i_cd_cible;
		vLwoztmDemande.i_cd_zpo       = i_cd_zpo;
		vLwoztmDemande.i_type_portage = i_type_portage;
		vLwoztmDemande.i_tpr_groupe   = i_tpr_groupe;
		vLwoztmDemande.i_tpr_num   	  = i_tpr_num;
		
		vLwoztmDemande.i_cd_insee     = tab_cd_insee;
		vLwoztmDemande.i_cd_postal    = tab_cd_postal;
		
		vLwoztm.demande = vLwoztmDemande;
		
		jwlwoztm.setNwlwoztmAwlwoztm(vLwoztm);
		
		// CALL SERVER
		jwlwoztm.nwlwoztm();
		
		// Verification du code retour
		vWebent = jwlwoztm.getNwlwoztmAxwebent();
		System.out.println("Code retour nwlwoztm() = " + 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{
			/*Jwlwoztm.NwlwoztmAwlwoztmAnomalie anomali = jwlwoztm.new NwlwoztmAwlwoztmAnomalie();
			int nb = jwlwoztm.getNwlwoztmAwlwoztm().anomalie.nb_ano.intValue();
			System.out.println("nb_ret:"+ nb);
			for (int i = 0; i < nb ; i++) {
				anomali = jwlwoztm.getNwlwoztmAwlwoztm().anomalie.[i];
				System.out.println("message : " + tret.lib_ret.trim());
			}*/
			
			Jwlwoztm.NwlwoztmAwlwoztmInfo_retour info_ret = jwlwoztm.new NwlwoztmAwlwoztmInfo_retour();
			info_ret = jwlwoztm.getNwlwoztmAwlwoztm().info_retour;
			System.out.println("message : " + info_ret.lib_info);
		}
	
		return jwlwoztm;
	   } // End setSoumission
	
	
	/**
		 * <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>25/03/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA81");
			Broker broker 				    	= JxweblogWeb.logonBroker();
			Jxweblog jxweblog 				    = JxweblogWeb.getConnexion(broker);
			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;
			
			//Test de MODIFICATION
			//---------Donnee Test---------------
			String i_action 	  = "1";
			String i_cd_cible 	  = null;
			String i_cd_zpo 	  = "0001";
			String i_type_portage = "N";
			String i_tpr_groupe   = null;
			String i_tpr_num 	  = null;
			
			String i_cd_postal[]  = new String[TAILLE];
			
			String i_cd_insee[]   = new String[TAILLE];
			i_cd_insee[0] = "75112";
			i_cd_insee[1] = "75113";
			i_cd_insee[2] = "75114";
			i_cd_insee[3] = "75115";
			//---------Donnee Test---------------
			setSoumission(i_action, i_cd_cible, i_cd_insee, i_cd_postal, 
					i_cd_zpo, i_type_portage, i_tpr_groupe, i_tpr_num, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
		}

}