import java.math.BigDecimal;

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

/**
 * <p>Titre : Jwlwclm1Web</p>
 * <p>Description : Classe de ajout, modification, suppression </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>04/04/2012</i>
 * @version 1.0
 */
public class Jwlwclm1Web {	
	/**
	 * <p>Titre : setCasLogistique</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>04/04/2012</i>
	 * @version 1.0
	 */
	public static Jwlwclm1 setCasLogistique(
		String fonction,
		String type_cloture,
		String cd_cible_cli,
		String num_cli,
		String type_adresse, 
		String etat_adresse, 
		String dt_debval_cpl,
		String niveau,
		String cd_reponse,
		String cd_zpo,
		String type_portage,
		String isn_kl_mere,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwclm1 jwlwclm1 = new Jwlwclm1(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwclm1.Nwlwclm1Axwebent vWebent = jwlwclm1.new Nwlwclm1Axwebent();
		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;
		jwlwclm1.setNwlwclm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwclm1.Nwlwclm1Awlwclm1 vLwclm1 = jwlwclm1.new Nwlwclm1Awlwclm1();
		vLwclm1.cd_cible      = cd_cible_cli;
		vLwclm1.num_cli       = Utils.transformNumClient(num_cli) ;
		vLwclm1.type_adresse  = type_adresse;
		vLwclm1.etat_adresse  = etat_adresse;
		if(!"".equals(dt_debval_cpl) && dt_debval_cpl!=null){
			vLwclm1.dt_debval_cpl = new BigDecimal(dt_debval_cpl);
		}		
		vLwclm1.niveau        = niveau;
		vLwclm1.cd_reponse    = cd_reponse;
		vLwclm1.cd_zpo		  = cd_zpo;
		vLwclm1.type_portage  = type_portage;
		if(!"".equals(isn_kl_mere) && isn_kl_mere!=null){
			vLwclm1.isn_kl_mere = new BigDecimal(isn_kl_mere);
		}
		if("".equals(type_cloture) || type_cloture==null){
			vWebent.fonction          = "CREATION";
		}
		else if("CLOTURE".equals(fonction)){
			vLwclm1.type_cloture  = type_cloture;
		}
		jwlwclm1.setNwlwclm1Awlwclm1(vLwclm1);
		
		// CALL SERVER
		jwlwclm1.nwlwclm1();
		
		// Verification du code retour
		vWebent = jwlwclm1.getNwlwclm1Axwebent();
		System.out.println("Code retour nwlwclm1() = " + 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{
			System.out.println ("Suite normale");
		}
		return jwlwclm1;
	   } // End setCasLogistique
	   
	   /**
		 * <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>25/03/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);
			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;
			
			//Constructeur TEST
			System.out.println("DEBUT TEST CREATION : cas logistique .................") ;
			//---------------Debut données test--------------------------
			String fonction  	 = "CLOTURE";
			String type_cloture	 = "T";
			String cd_cible_cli  = "85";
			String num_cli       = "00016496846";
			String type_adresse  = "PPAL";
			String etat_adresse  = "D";
			String dt_debval_cpl = "79889588";
			String niveau        = "2";
			String cd_reponse    = "CNFP";
			String cd_zpo		 = "0002";
			String type_portage  = "N";
			String isn_kl_mere	 = null;
			//String cd_cible_cli[] = {"01","02","22","33","33"};//	*2[40]
			//String cd_cible_cli[] = {"50"};
			//String num_cli[] = {"00001288985"};//		11[40]
			//String num_cli[] = {"00000281139"};
			//String num_cli[] = {"00001275821"};9/28113
			//String num_cli[] = {"00000278952"};
			
			//---------------Fin données test--------------------------
			setCasLogistique(
				fonction,
				type_cloture,
				cd_cible_cli,
				num_cli,
				type_adresse,
				etat_adresse,
				dt_debval_cpl,
				niveau,
				cd_reponse,
				cd_zpo,
				type_portage,
				isn_kl_mere,
				groupe_exploitant, numero_session, utilisateur, 
				cd_cible, cd_stegrp,broker);
			
			System.out.println("...Fin de test ...");
		}
			
}