gleimar 2015-03-29 17:42:55 +00:00
parent b4361d4079
commit 15920c98f4
1 changed files with 73 additions and 16 deletions

View File

@ -7,6 +7,7 @@ package com.rjconsultores.ventaboletos.service.impl;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -26,7 +27,8 @@ import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.service.PuntoVentaService; import com.rjconsultores.ventaboletos.service.PuntoVentaService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ws.totvs.fornecedor.Tipo; import com.rjconsultores.ws.totvs.fornecedor.TipoCliente;
import com.rjconsultores.ws.totvs.fornecedor.TipoPessoa;
import com.rjconsultores.ws.totvs.service.TotvsService; import com.rjconsultores.ws.totvs.service.TotvsService;
/** /**
@ -164,21 +166,26 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
String endpointFornecedor = getEndpointFornecedor(); String endpointFornecedor = getEndpointFornecedor();
String endpointCliente = getEndpointCliente(); String endpointCliente = getEndpointCliente();
Integer xidsvp = puntoVenta.getEmpresa().getEmpresaId(); Integer xidsvp = puntoVenta.getPuntoventaId();
String nomeEmpresa = puntoVenta.getRazonSocial(); String nomeEmpresa = puntoVenta.getRazonSocial();
String nomeFilial = puntoVenta.getNumDoCPuntoVenta(); String nomeFilial = puntoVenta.getNumDoCPuntoVenta();
String cnpjEmpresaProtheus = "25634551000138"; String cnpjEmpresaProtheus = "25634551000138";
String nome = puntoVenta.getNombpuntoventa(); String nome = puntoVenta.getNombpuntoventa();
String cgc ="";// puntoVenta.getNumDoCPuntoVenta(); String cgc =puntoVenta.getNumDoCPuntoVenta();
String endereco = puntoVenta.getDireccioncalle() + "," + puntoVenta.getDireccionnumero() == null ? "" : puntoVenta.getDireccionnumero(); String endereco = puntoVenta.getDireccioncalle() + "," + puntoVenta.getDireccionnumero() == null ? "" : puntoVenta.getDireccionnumero();
String complemen = puntoVenta.getCompl() == null ? "" : puntoVenta.getCompl(); String complemen = puntoVenta.getCompl() == null ? "" : puntoVenta.getCompl();
String bairro = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getDesccolonia(); String bairro = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getDesccolonia();
String codmun = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getCodmunicipio().toString(); String codmun = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getCodmunicipio().toString();
codmun = (codmun ==null)?"":StringUtils.leftPad(codmun, 5, '0');
String est = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getCveestado(); String est = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getCveestado();
String codpais = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getPais().getPaisId().toString(); //O código do país no banco central
//brasil - 01058
String codpais = "01058";
String cep = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCodpostal(); String cep = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCodpostal();
String pais = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getPais().getNombpais(); String pais = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getPais().getNombpais();
String tel = puntoVenta.getNumtelefonouno(); String tel = puntoVenta.getNumtelefonouno();
@ -193,20 +200,32 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
String email = puntoVenta.getDescCorreo(); String email = puntoVenta.getDescCorreo();
String fax = puntoVenta.getNumfax(); String fax = puntoVenta.getNumfax();
String inscr = puntoVenta.getNumIEPuntoVenta(); String inscr = puntoVenta.getNumIEPuntoVenta(); //esse campo é validado na totvs. Tem que ser o mesmo do estado enviado
String nreduz = puntoVenta.getNombpuntoventa(); String nreduz = puntoVenta.getNombpuntoventa();
String tipo = Tipo.F.name(); String tipoCliente = TipoCliente.F.name();
String tpessoa = "";//puntoVenta.getNumDoCPuntoVenta();
String tipoPessoa = TipoPessoa.F.name();
if (isCNPJ(cgc)){
tipoPessoa = TipoPessoa.J.name();
}
String obs = puntoVenta.getComentarios(); String obs = puntoVenta.getComentarios();
obs = StringUtils.isBlank(obs)?"sem obs.":obs;
String conta = "";//puntoVenta.getAgenciaId() == null ? null : puntoVenta.getAgenciaId().getNumconta() + "-" + puntoVenta.getAgenciaId().getDigito(); String conta = "1110101001001";//DEVE SER REVISADO COM A GUANABARA
String cnae = ""; String cnae = "";
String inscrm = "";
String inscrm = "ISENTO";//DEVE SER REVISADO COM A GUANABARA
String naturez = ""; String naturez = "";
String simpnac = ""; //1 = SIM
String contrib = ""; //2 = Não
String entid = ""; String simpnac = "1";//deve ser revisado com a guanabara
String fator = ""; String fator = "";
Exception respEx = null; Exception respEx = null;
@ -214,17 +233,42 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
log.info(" ------------- INICIO INTEGRACION FORNECEDOR TOTVS ------------- "); log.info(" ------------- INICIO INTEGRACION FORNECEDOR TOTVS ------------- ");
TotvsService.cadastrarFornecedor(endpointFornecedor, bairro, cep, cgc, cnae, codmun, codpais, complemen, conta, ddd, email, endereco, TotvsService.cadastrarFornecedor(endpointFornecedor, bairro, cep, cgc, cnae, codmun, codpais, complemen, conta, ddd, email, endereco,
est, inscr, inscrm, naturez, nome, nreduz, simpnac, tel, tipo, tpessoa, cnpjEmpresaProtheus,xidsvp); est, inscr, inscrm, naturez, nome, nreduz, simpnac, tel, tipoPessoa, tipoCliente, cnpjEmpresaProtheus,xidsvp);
} catch (Exception e) { } catch (Exception e) {
log.error("", e); log.error("", e);
respEx = e; respEx = e;
} }
/**
* campo CONTRIB - deve ser passado
- 1 = Sim
- 2 - Não
*/
String contrib = "2";//deve ser revisado com a guanabara
/**
* No campo ENTID - deve ser passado:
00-PJ Dir.Priv.;
01-Órg.,Autq.;
02-Autopec
03-Emp.Pub./Soc.Eco.Mis.;
04-Trans.Passg.
05-Ser.Pres.Fin.;
06-Demais Serv.
07-Dema is Ent.;
08-Assoc.Profis.;
09-Combustív.;
10-Pgto n .Espec.
*/
String entid = "04";
try { try {
log.info(" ------------- INICIO INTEGRACION CLIENTE TOTVS ------------- "); log.info(" ------------- INICIO INTEGRACION CLIENTE TOTVS ------------- ");
pais = "";//segundo mateus, passar em branco, segundo orientação do mateus da totvs
TotvsService.cadastrarCliente(endpointCliente, bairro, cep, cgc, codmun, codpais, complemen, conta, contrib, ddd, email, nomeEmpresa, TotvsService.cadastrarCliente(endpointCliente, bairro, cep, cgc, codmun, codpais, complemen, conta, contrib, ddd, email, cnpjEmpresaProtheus,
endereco, entid, fator, fax, inscr, inscrm, naturez, nome, nreduz, obs, pais, tpessoa, tel, tipo, est, xidsvp); endereco, entid, fator, fax, inscr, inscrm, naturez, nome, nreduz, obs, pais, tipoCliente, tel, tipoPessoa, est, xidsvp);
} catch (Exception e) { } catch (Exception e) {
log.error("", e); log.error("", e);
respEx = e; respEx = e;
@ -252,5 +296,18 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
} }
return constante.getValorconstante(); return constante.getValorconstante();
} }
private String somenteNumeros(String s) {
if (s == null || StringUtils.isBlank(s) ){
return "";
}
s = StringUtils.trim(s);
return s.replaceAll("[^0-9]", "");
}
private boolean isCNPJ(String vlr){
vlr = somenteNumeros(vlr);
return vlr.length() > 11;
}
} }