package com.fp.frontend.controller.pcustomer;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
import javax.servlet.ServletContext;

import org.primefaces.event.FileUploadEvent;
import org.primefaces.event.FlowEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.UploadedFile;

import com.fp.dto.Request;
import com.fp.dto.Response;
import com.fp.dto.helper.FileHelper;
import com.fp.dto.query.DtoQuery;
import com.fp.dto.query.SubQuery;
import com.fp.dto.save.DtoSave;
import com.fp.frontend.controller.AbstractController;
import com.fp.frontend.controller.pcustomer.lov.JuridicalPersonLovController;
import com.fp.frontend.controller.pcustomer.lov.PersonLovController;
import com.fp.frontend.controller.pgeneral.date.TgeneAccountingDateBranchController;
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
import com.fp.frontend.controller.pgeneral.gene.LanguageController;
import com.fp.frontend.controller.pgeneral.lov.ActivityLovController;
import com.fp.frontend.helper.MessageHelper;
import com.fp.frontend.utility.MsgGeneral;
import com.fp.persistence.pcustomer.company.TcustCompany;
import com.fp.persistence.pcustomer.gene.TcustPersonAddress;
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
import com.fp.persistence.pcustomer.gene.TcustPersonPhone;
import com.fp.persistence.pcustomer.gene.TgeneActivity;
import com.fp.persistence.pcustomer.people.TcustPeople;
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
import com.fp.persistence.pgeneral.gene.TgeneLanguage;
import com.fp.persistence.pgeneral.image.TgeneFilesDetail;
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;

/**
 * Clase controladora de JuridicalPerson.
 *
 * @author MAV.
 * @version 1.0
 */
@ManagedBean
@ViewScoped
public class JuridicalPersonController extends AbstractController<TcustPersonDetail> {

    private static final long serialVersionUID = 1L;

    @ManagedProperty(value = "#{companyController}")
    private CompanyController companyController;

    @ManagedProperty(value = "#{peopleFastController}")
    private PeopleFastController peopleFastController;

    @ManagedProperty(value = "#{personAddressController}")
    private PersonAddressController addressController;

    @ManagedProperty(value = "#{personPhoneController}")
    private PersonPhoneController phonesController;

    @ManagedProperty(value = "#{fileDetailController}")
    private FileDetailController fileDetail;

    /**
     * Atributo para la lista de objetos TgeneCatalogDetail de identificacion
     */
    private List<TgeneCatalogDetail> lidentification;

    /**
     * Atributo para la lista de objetos TgeneCatalogDetail de tipo de cliente
     */
    private List<TgeneCatalogDetail> ltypeclient;

    /**
     * Atributo para la lista de objetos TgeneCatalogDetail de sector
     * econ&oacute;mico
     */
    private List<TgeneCatalogDetail> leconomicsector;

    /**
     * Atributo para la lista de objetos TgeneCatalogDetail de actividad no
     * econ&oacute;mica
     */
    private List<TgeneCatalogDetail> lnotactivity;

    /**
     * Atributo para el listado de g&eacute;neros
     */
    private List<String[]> lgender;

    /**
     * Atributo para el listado de idiomas
     */
    private List<TgeneLanguage> llenguage;

    /**
     * Atributo para activar el keyFilter
     */
    private boolean activeRegEx;

    /**
     * Atributo para la longitud de la identificaci&oacute;n
     */
    private String lengthId;

    /**
     * atributo para el c&oacute;digo de persona
     */
    private String personcode;

    private Boolean existingperson;

    /**
     * Atributo para deshabilitar el boton save
     */
    private Boolean isDisableSave = Boolean.FALSE;

    /**
     * Atributo para el control de checkBox exencto de impuesto a la renta
     */
    private boolean exentoImpuesto;

    /**
     * Atributos relacionados con el logo
     */
    UploadedFile selectedPicture;
    Boolean fotoCargada = false;
    StreamedContent foto;
    String rutaFoto;

    private String extensionFoto = "jpg";

    private String imageUrl;

    TsafeUserDetail usuario;

    List<FileHelper> fileH = new ArrayList<FileHelper>();

    public JuridicalPersonController() throws Exception {
        super(TcustPersonDetail.class);
    }

    @PostConstruct
    private void postconstruct() throws Exception {
        this.lengthId = "13";
        this.init();
        //super.buildTransactionPages("juridicalPersonController");
    }

    /**
     * Incializa el controlador, cuando se esta utilizando una pagina que utliza
     * el controlador.
     */
    private void init() {
        try {
            this.create();
            this.lrecord = new ArrayList<>();
            this.record = new TcustPersonDetail();
            this.record.setIsnew(true);
            this.beanalias = "JURIDICALPERSONCONTROLLER";

            this.companyController.create();
            this.companyController.setRecord(new TcustCompany());
            this.companyController.getRecord().setIsnew(true);

            this.addressController.create();
            this.addressController.setRecord(new TcustPersonAddress());
            this.addressController.getRecord().setIsnew(true);

            this.phonesController.create();
            this.phonesController.setRecord(new TcustPersonPhone());
            this.phonesController.getRecord().setIsnew(true);

            //Llenando las listas
            this.lidentification = CatalogDetailController.find("IDENTIFICATION", "2");
            this.leconomicsector = CatalogDetailController.find("ECONOMICSECTOR");
            this.ltypeclient = CatalogDetailController.findClientType("CLIENTTYPE", "2");
            this.lnotactivity = CatalogDetailController.find("NOTACTIVITY");
            this.lgender = CatalogDetailController.getListGender();
            this.llenguage = LanguageController.find();
            this.getRecord().setLanguagecode("ES");

            //Obteniendo los datos del usuario logueado
            usuario = (TsafeUserDetail) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");

        } catch (Exception e) {
            MessageHelper.setMessageError(e);
        }
    }

    @Override
    protected void querydatabase() {
        try {
            if (super.getMfilters().get("pk.personcode") == null || super.getMfilters().get("pk.personcode").equals("null")) {
                return;
            }
            super.addFilterDateto();

            //Obteniendo la compannia
            TcustCompany compannia = CompanyController.findByPersonCode(super.getMfilters().get("pk.personcode"));
            if (compannia != null) {
                this.companyController.setRecord(compannia);
            }

            //Obteniendo las direcciones
            List<TcustPersonAddress> direcciones = PersonAddressController.findAllByPersonCode(this.getMfilters().get("pk.personcode"));
            this.addressController.setLrecord(direcciones);

            //Obteniendo los telefonos
            List<TcustPersonPhone> telefonos = PersonPhoneController.findAllByPersonCode(this.getMfilters().get("pk.personcode"));
            this.phonesController.setLrecord(telefonos);

            Request request = this.callerhelper.getRequest();

            DtoQuery dto = super.getDtoQuery(false);

            // subqueries
            SubQuery subquery = new SubQuery("TgeneActivity", "description",
                    "activitydesc", "i.pk = t.activitycode");
            dto.addSubQuery(subquery);

            SubQuery subquery1 = new SubQuery("TgeneActivity",
                    "segmenttypecatalog", "segmenttypecatalog",
                    "i.pk = t.activitycode");
            dto.addSubQuery(subquery1);

            SubQuery subquery2 = new SubQuery(
                    "TgeneCatalogDetail",
                    "description",
                    "segmentdesc",
                    "i.pk.catalogcode = 'SEGMENTTYPE' and i.pk.catalog = (select a.segmenttypecatalog from TgeneActivity a where a.pk = t.activitycode)");
            dto.addSubQuery(subquery2);

            HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
            mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.

            request.setQueryTables(mtables);

            Response resp = this.callerhelper.executeQuery(request);

            if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
                this.record = new TcustPersonDetail();
                this.companyController.setRecord(new TcustCompany());
                MessageHelper.setMessageError(resp);
            } else {

                if (resp.get(this.beanalias) != null) {
                    this.record = (TcustPersonDetail) resp.get(this.beanalias);
                    this.record.setIsnew(false);
                }

                if (this.companyController.getRecord() == null) {
                    this.companyController.setRecord(new TcustCompany());
                    this.companyController.getRecord().setIsnew(true);
                } else //Cargando la imagen
                if (this.companyController.getRecord() != null && this.companyController.getRecord().getLogo() != null) {

                    TgeneFilesDetail fileDetalle = fileDetail.find((this.companyController == null || this.companyController.getRecord().getLogo() == null) ? null : String.valueOf(this.companyController.getRecord().getLogo()));
                    extensionFoto = fileDetalle != null ? fileDetalle.getExtension() : extensionFoto;
                    if (fileDetalle != null && fileDetalle.getImage() != null) {
                        InputStream input = new ByteArrayInputStream(fileDetalle.getImage());
                        this.foto = new DefaultStreamedContent(input);
                        this.fotoCargada = true;

                        //Almacenando la imagen temporalmente            			
                        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
                        ServletContext servletContext = (ServletContext) externalContext.getContext();
                        String tempUrl = servletContext.getRealPath("/");;
                        String imageName = UUID.randomUUID().toString();
                        String imageUrl = tempUrl + "resources/images/" + imageName + "." + extensionFoto;
                        imageUrl = imageUrl.replace("\\", "/");
                        File outputfile = new File(imageUrl);
                        BufferedImage image = ImageIO.read(input);
                        Boolean saved = ImageIO.write(image, extensionFoto, outputfile);

                        this.rutaFoto = "/resources/images/" + imageName + "." + extensionFoto;
                    }
                } else {
                    this.fotoCargada = false;
                }
            }

            this.personcode = String.valueOf(this.getMfilters().get("pk.personcode"));

//            this.addressController.addPersoncodeFilter(this.personcode);
//            this.addressController.addFilterDateto();
//            this.addressController.query();
            /*
            this.phonesController.addPersoncodeFilter(this.personcode);
            this.phonesController.addFilterDateto();
            this.phonesController.query();*/
        } catch (Throwable e) {
            MessageHelper.setMessageError(e);
        }
    }

    @Override
    public void save() {
        try {
            //Validando las direcciones y telefonos
            if (this.addressController.getLrecord().size() == 0) {
                MessageHelper.setMessageError("msg_requireAddress");
                return;
            } else {
                for (TcustPersonAddress direccion : this.addressController.getLrecord()) {
                    if (direccion.isnew) {
                        direccion.setIngressusercode(this.usuario.getPk().getUsercode());
                    } else {
                        direccion.setModifyusercode(this.usuario.getPk().getUsercode());
                    }
                }
            }
            if (this.phonesController.getLrecord().size() == 0) {
                MessageHelper.setMessageError("msg_requirePhones");
                return;
            } else {
                for (TcustPersonPhone telefono : this.phonesController.getLrecord()) {
                    if (telefono.isnew) {
                        telefono.setIngressusercode(this.usuario.getPk().getUsercode());
                    } else {
                        telefono.setModifyusercode(this.usuario.getPk().getUsercode());
                    }
                }
            }

            //Asignando los campos
            this.record.setDatefrom(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            this.record.setIdentificationcatalogcode("IDENTIFICATION");
            if (this.record.isnew) {
                this.record.setIngressuser(this.usuario.getPk().getUsercode());
            } else {
                this.record.setModifyuser(this.usuario.getPk().getUsercode());
            }

            this.record.setPersontypecatalog("2");
            this.record.setPersontypecatalogcode("PERSONTYPE");
            this.record.setRegisterdate(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
            this.record.setClienttypecatalogcode("CLIENTTYPE");
            this.record.setEconomicsectorcatalogcode("ECONOMICSECTOR");

            if (this.selectedPicture != null) {
                this.companyController.getRecord().setPicture(this.selectedPicture.getContents());
            }

            DtoSave dtosave = super.getDtoSave(true);
            dtosave.setReturnpk(true);
            HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();

            Request request = this.callerhelper.getRequest();
            dtosave.setPosition(3);
            msave.put(this.beanalias, dtosave);

            // DIRECCIONES            
            DtoSave dtosaveAddress = addressController.getDtoSave();
            dtosaveAddress.setPosition(1);
            msave.put(addressController.getBeanalias(), dtosaveAddress);

            // TELEFONOS
            DtoSave dtosavePhone = phonesController.getDtoSave();
            dtosavePhone.setPosition(2);
            msave.put(phonesController.getBeanalias(), dtosavePhone);

            request.setSaveTables(msave);

            request.getModifiedData().put("PERSON", this.record);
            request.getModifiedData().put("COMPANY", this.companyController.getRecord());
            request.getModifiedData().put("ADDRESSES", this.addressController.getLrecord());

            guardarInformacionImagenes();

            request.getModifiedData().put("file", fileH);
            request.getModifiedData().put("logocode", companyController.getRecord() != null ? companyController.getRecord().getLogo() != null ? companyController.getRecord().getLogo() : null : null);
            request.getModifiedData().put("pk_personcode", companyController.getRecord() != null ? companyController.getRecord().getPk() != null ? companyController.getRecord().getPk().getPersoncode() : null : null);
            request.getModifiedData().put("PHONES", this.phonesController.getLrecord());

            Response resp = this.callerhelper.executeSave(request);

            if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
                this.postCommit(resp);
                this.companyController.postCommit(resp);
                this.addressController.postCommit(resp);
                this.phonesController.postCommit(resp);
                this.personcode = String.valueOf(resp.get("personcode"));
                super.addFilter("pk.personcode", this.personcode);
                isDisableSave = Boolean.TRUE;
                MessageHelper.setMessageInfo(resp);
            } else {
                MessageHelper.setMessageError(resp);
            }

        } catch (Throwable e) {
            MessageHelper.setMessageError(e);
        }
    }

    /**
     * Metodo para guardar informacion de las imagenes en la base de datos
     *
     * @throws IOException
     */
    private void guardarInformacionImagenes() throws IOException {
        FileHelper archivoPicture = new FileHelper();
        archivoPicture.setName("");
        fileH = new ArrayList<FileHelper>();

        if (selectedPicture != null) {
            long size = selectedPicture.getSize();
            InputStream stream = selectedPicture.getInputstream();
            byte[] buffer = new byte[(int) size];
            stream.read(buffer, 0, (int) size);
            stream.close();
            archivoPicture.setContentType(selectedPicture.getContentType());
            archivoPicture.setExtension(extensionFoto);
            archivoPicture.setImage(buffer);
            archivoPicture.setName(selectedPicture.getFileName());
            archivoPicture.setSize(selectedPicture.getFileName().length());
        }

        fileH.add(archivoPicture);

    }

    /**
     * M&eacute;todo que abre el lov de activudad econ&oacute;mica
     */
    public void openActivityLov() {
        Map<String, List<String>> params = new HashMap<>();
        ActivityLovController.openLov(params);
    }

    @Override
    public void forcedQuery() throws Exception {
        Field f[] = this.getClass().getDeclaredFields();
        //super.forcedQuery(f, this);
        super.forcedQuery();
    }

    /**
     * M&eacute;todo para cargar datos en el editar
     */
    public void loadEdit() {
        if (this.record.getTaxexempt() != null) {
            this.exentoImpuesto = this.record.getTaxexempt().equals("Y") ? true : false;
        }
    }

    /**
     * M&eacute;todo para manejar el evento change en el CheckBox
     */
    public void onChangeTaxexempt() {
        if (this.exentoImpuesto) {
            this.record.setTaxexempt("Y");
        } else {
            this.record.setTaxexempt("N");
        }
    }

    /**
     * Verifica el ingreso de una actividad econ&oacute;mica
     *
     * @param person Objeto TcustPersonDetail
     * @param people Objeto TcustPeople
     * @return result V/F
     */
    private boolean activity(TcustPersonDetail person, TcustPeople people) {
        boolean result = false;
        if (((person.getActivitycode() == null) || person.getActivitycode()
                .equals(""))
                && ((people.getNotactivitycatalog() == null) || people
                .getNotactivitycatalog().equals(""))) {
            result = true;
        }
        return result;
    }

    /**
     * Ejecuta el evento change del combo actividad no econ&oacute;mica
     */
    public void onChangeNotactivity() {
        this.getRecord().setActivitycode(null);
        this.getRecord().put("activitydesc", null);
        this.getRecord().put("segmenttypecatalog", null);
        this.getRecord().put("segmentdesc", null);
    }

    /**
     * M&eacute;todo para abrir el lov de personas
     */
    public void openPersonLov() {
        Map<String, List<String>> params = new HashMap<>();
        List<String> juridical = new ArrayList<String>();
        juridical.add("RUC");
        params.put("isJuridical", juridical);
        JuridicalPersonLovController.openLov(params);
    }

    /**
     * M&eacute;todo para abrir el lov de personas
     */
    public void openPersonLovComplete() {
        Map<String, List<String>> params = new HashMap<>();

        PersonLovController.openLov(params);
    }

    /**
     * M&eacute;todo para abrir el lov de Instituciones Finacieras
     */
    public void openInstitucionTypeLov() {
        Map<String, List<String>> params = new HashMap<>();
        // InstitutionTypeLovController.openLov(params);
    }

    public void onReturnInstitucionTypeLov(SelectEvent event) throws Exception {
        TgeneCatalogDetail t = (TgeneCatalogDetail) event.getObject();
        this.companyController.getRecord().getModifiedData().put("institutiontypedesc", t.getDescription());
        this.companyController.getRecord().setInstitutiontypecatalog(t.getPk().getCatalog());
        this.companyController.getRecord().setInstitutiontypecatalogcode(t.getPk().getCatalogcode());

    }

    /**
     * Retorna los valores del lov
     *
     * @param event Evento ajax
     * @throws Exception
     */
    public void onReturnPersonLov(SelectEvent event) throws Exception {
        TcustPersonDetail t = (TcustPersonDetail) event.getObject();
        super.addFilter("pk.personcode", t.getPk().getPersoncode().toString());
        super.addField("personname", t.getName());
        super.query();
    }

    /**
     * Controla la respuesta del lov de activudad econ&oacute;mica
     *
     * @param event
     * @throws Exception
     */
    public void onReturnActivityLov(SelectEvent event) throws Exception {

        TgeneActivity t = (TgeneActivity) event.getObject();

        super.addField("activitydesc", t.getDescription());
        this.getRecord().setActivitycode(t.getPk());
        this.getRecord().modifiedData.put("activitydesc",
                t.getDescription());
        this.getRecord().modifiedData.put("segmenttypecatalog",
                t.getSegmenttypecatalog());
        this.getRecord().modifiedData.put("segmentdesc",
                t.get("segmentdesc"));
    }

    public void onChangeId() {
        if (this.getRecord().getIdentificationcatalog()
                .compareTo("CED") == 0) {
            this.lengthId = "10";
            this.activeRegEx = false;
        } else if (this.getRecord().getIdentificationcatalog()
                .compareTo("RUC") == 0) {
            this.lengthId = "13";
            this.activeRegEx = false;
        } else if (this.getRecord().getIdentificationcatalog()
                .compareTo("PAS") == 0) {
            this.lengthId = "13";
            this.activeRegEx = true;
        }
    }

    public String onFlowProcess(FlowEvent event) {

        System.out.println("WIZARD NEW " + event.getNewStep());
        System.out.println("WIZARD OLD " + event.getNewStep());
        if (this.getRecord().getActivitycode() == null) {
            MessageHelper.setMessageError("msg_requireActivity");
            return event.getOldStep();
        }
        return event.getNewStep();
    }

    public String workingdate() {
        String dateString = null;
        try {
            Date date = TgeneAccountingDateBranchController.find(
                    this.getLoginController().getRequest().getCompany())
                    .getWorkingdate();
            dateString = (new SimpleDateFormat(
                    MsgGeneral.getProperty("dateformat")).format(date));
        } catch (Throwable e) {
            MessageHelper.setMessageError(e);
        }
        return dateString;
    }

    /**
     * Metodo que carga la foto
     */
    @SuppressWarnings("unused")
    public void uploadPicture(FileUploadEvent event) {
        try {
            selectedPicture = event.getFile();

            InputStream is = new ByteArrayInputStream(selectedPicture.getContents());
            //this.foto=new DefaultStreamedContent(is, selectedPicture.getContentType(), selectedPicture.getFileName());
            this.foto = new DefaultStreamedContent(event.getFile().getInputstream());
            this.fotoCargada = true;

            //Obteniendo la extension de la imagen
            String extension = "";
            int pos = -1;
            for (int i = selectedPicture.getFileName().length() - 1; i >= 0; i--) {
                if (selectedPicture.getFileName().toCharArray()[i] == '.') {
                    pos = i;
                    break;
                }
            }
            if (pos != -1) {
                extension = selectedPicture.getFileName().substring(pos + 1, selectedPicture.getFileName().length());
            }

            //Almacenando la imagen temporalmente
/*			ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();			
			ServletContext servletContext = (ServletContext) externalContext.getContext();
			String tempUrl = "/resources/images/temp/";
			String imageName=UUID.randomUUID().toString();
			String imageUrl=servletContext.getRealPath(tempUrl)+File.separator+imageName+"."+extension;
			File outputfile = new File(imageUrl);			
			InputStream input=new ByteArrayInputStream(selectedPicture.getContents());
			BufferedImage image=ImageIO.read(input);
			Boolean saved=ImageIO.write(image, extension, outputfile);
			
			this.rutaFoto="/resources/images/temp/"+imageName+"."+extension;*/
            //Almacenando la imagen temporalmente
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
            ServletContext servletContext = (ServletContext) externalContext.getContext();

            String tempUrl = servletContext.getRealPath("/");;
            String imageName = UUID.randomUUID().toString();
            imageUrl = tempUrl + "resources/images/" + imageName + "." + extensionFoto;
            imageUrl = imageUrl.replace("\\", "/");
            File outputfile = new File(imageUrl);
            InputStream input = new ByteArrayInputStream(selectedPicture.getContents());
            BufferedImage image = ImageIO.read(input);
            Boolean saved = ImageIO.write(image, extensionFoto, outputfile);
            this.rutaFoto = "/resources/images/" + imageName + "." + extensionFoto;

        } catch (Exception e) {
            MessageHelper.setMessageError(e);
        }
    }

    /**
     * Entrega lista de objetos TgeneCatalogDetail tipo de identificaci&oacute;n
     *
     * @return lidentification Lista de objetos TgeneCatalogDetail
     */
    public List<TgeneCatalogDetail> getLidentification() {
        return this.lidentification;
    }

    /**
     * Fija lista de objetos TgeneCatalogDetail tipo de identificaci&oacute;n
     *
     * @param lidentification Lista de objetos TgeneCatalogDetail
     */
    public void setLidentification(List<TgeneCatalogDetail> lidentification) {
        this.lidentification = lidentification;
    }

    /**
     * Entrega Verdadero/Falso
     *
     * @return activeNotEconomic V/F
     */
    public boolean isActiveRegEx() {
        return this.activeRegEx;
    }

    /**
     * Fija Verdadero/Falso
     *
     * @param activeNotEconomic V/F
     */
    public void setActiveRegEx(boolean activeRegEx) {
        this.activeRegEx = activeRegEx;
    }

    /**
     * Entrega el n&uacute;mero de digitos para el tipo de identificaci&oacuye;n
     *
     * @return lengthId N&uacute;mero de digitos
     */
    public String getLengthId() {
        return this.lengthId;
    }

    /**
     * Fija el n&uacute;mero de digitos para el tipo de identificaci&oacuye;n
     *
     * @param lengthId N&uacute;mero de digitos
     */
    public void setLengthId(String lengthId) {
        this.lengthId = lengthId;
    }

    /**
     * Entrega lista de objetos TgeneCatalogDetail de sector econ&oacute;mico
     *
     * @return leconomicsector Lista de objetos TgeneCatalogDetail
     */
    public List<TgeneCatalogDetail> getLeconomicsector() {
        return this.leconomicsector;
    }

    /**
     * Fija lista de objetos TgeneCatalogDetail de sector econ&oacute;mico
     *
     * @param leconomicsector Lista de objetos TgeneCatalogDetail
     */
    public void setLeconomicsector(List<TgeneCatalogDetail> leconomicsector) {
        this.leconomicsector = leconomicsector;
    }

    /**
     * Entrega lista de objetos TgeneCatalogDetail de tipo cliente
     *
     * @return ltypeclient Lista de objetos TgeneCatalogDetail
     */
    public List<TgeneCatalogDetail> getLtypeclient() {
        return this.ltypeclient;
    }

    /**
     * Fija lista de objetos TgeneCatalogDetail de tipo cliente
     *
     * @param ltypeclient Lista de objetos TgeneCatalogDetail
     */
    public void setLtypeclient(List<TgeneCatalogDetail> ltypeclient) {
        this.ltypeclient = ltypeclient;
    }

    /**
     * Entrega lista de objetos TgeneCatalogDetail
     *
     * @return lnotactivity Lista de objetos TgeneCatalogDetail
     */
    public List<TgeneCatalogDetail> getLnotactivity() {
        return this.lnotactivity;
    }

    /**
     * Fija lista de objetos TgeneCatalogDetail
     *
     * @param lnotactivity Lista de objetos TgeneCatalogDetail
     */
    public void setLnotactivity(List<TgeneCatalogDetail> lnotactivity) {
        this.lnotactivity = lnotactivity;
    }

    /**
     * Entrega la lista de g&eacute;neros
     *
     * @return lgender Lista de g&eacute;neros
     */
    public List<String[]> getLgender() {
        return this.lgender;
    }

    /**
     * Fija la lista de g&eacute;neros
     *
     * @param lgender Lista de g&eacute;neros
     */
    public void setLgender(List<String[]> lgender) {
        this.lgender = lgender;
    }

    public List<TgeneLanguage> getLlenguage() {
        return llenguage;
    }

    public void setLlenguage(List<TgeneLanguage> llenguage) {
        this.llenguage = llenguage;
    }

    public Boolean getExistingperson() {
        return existingperson;
    }

    public void setExistingperson(Boolean existingperson) {
        this.existingperson = existingperson;
    }

    /**
     * @return the personcode
     */
    public String getPersoncode() {
        return personcode;
    }

    /**
     * @param personcode the personcode to set
     */
    public void setPersoncode(String personcode) {
        this.personcode = personcode;
    }

    /**
     * @return the exentoImpuesto
     */
    public boolean isExentoImpuesto() {
        return exentoImpuesto;
    }

    /**
     * @param exentoImpuesto the exentoImpuesto to set
     */
    public void setExentoImpuesto(boolean exentoImpuesto) {
        this.exentoImpuesto = exentoImpuesto;
    }

    public PeopleFastController getPeopleFastController() {
        return peopleFastController;
    }

    public void setPeopleFastController(PeopleFastController peopleFastController) {
        this.peopleFastController = peopleFastController;
    }

    public UploadedFile getSelectedPicture() {
        return selectedPicture;
    }

    public void setSelectedPicture(UploadedFile selectedPicture) {
        this.selectedPicture = selectedPicture;
    }

    public Boolean getFotoCargada() {
        return fotoCargada;
    }

    public void setFotoCargada(Boolean fotoCargada) {
        this.fotoCargada = fotoCargada;
    }

    public StreamedContent getFoto() {
        return foto;
    }

    public void setFoto(StreamedContent foto) {
        this.foto = foto;
    }

    public String getRutaFoto() {
        return rutaFoto;
    }

    public void setRutaFoto(String rutaFoto) {
        this.rutaFoto = rutaFoto;
    }

    public CompanyController getCompanyController() {
        return companyController;
    }

    public void setCompanyController(CompanyController companyController) {
        this.companyController = companyController;
    }

    public PersonAddressController getAddressController() {
        return addressController;
    }

    public void setAddressController(PersonAddressController addressController) {
        this.addressController = addressController;
    }

    public PersonPhoneController getPhonesController() {
        return phonesController;
    }

    public void setPhonesController(PersonPhoneController phonesController) {
        this.phonesController = phonesController;
    }

    public FileDetailController getFileDetail() {
        return fileDetail;
    }

    public void setFileDetail(FileDetailController fileDetail) {
        this.fileDetail = fileDetail;
    }

    public TsafeUserDetail getUsuario() {
        return usuario;
    }

    public void setUsuario(TsafeUserDetail usuario) {
        this.usuario = usuario;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public Boolean getIsDisableSave() {
        return isDisableSave;
    }

    public void setIsDisableSave(Boolean isDisableSave) {
        this.isDisableSave = isDisableSave;
    }

}
