diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarCustomController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarCustomController.java index ba4592c58..0b30436a1 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarCustomController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarCustomController.java @@ -71,7 +71,9 @@ public class EditarCustomController extends MyGenericForwardComposer { cmbTipo.setDisabled(Boolean.TRUE); cmbSistema.setValue(SistemaEnum.getSistema(custom.getSistema()).toString()); - cmbTipo.setValue(CustomTipo.getCustomTipo(custom.getTipo()).toString()); + if (custom.getTipo() != null) { + cmbTipo.setValue(CustomTipo.getCustomTipo(custom.getTipo()).toString()); + } } diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java index b0f6a208e..eaac6cf05 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java @@ -4,8 +4,25 @@ */ package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.InvalidKeyException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.SignatureException; +import java.security.UnrecoverableEntryException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,8 +42,10 @@ import org.zkforge.ckez.CKeditor; import org.zkoss.util.resource.Labels; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.UiException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.UploadEvent; import org.zkoss.zkplus.databind.BindingListModel; import org.zkoss.zkplus.databind.BindingListModelList; import org.zkoss.zul.Button; @@ -36,9 +55,11 @@ import org.zkoss.zul.Comboitem; import org.zkoss.zul.Decimalbox; import org.zkoss.zul.Image; import org.zkoss.zul.Intbox; +import org.zkoss.zul.Label; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Radio; import org.zkoss.zul.Row; +import org.zkoss.zul.Tab; import org.zkoss.zul.Textbox; import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema; @@ -54,6 +75,7 @@ import com.rjconsultores.ventaboletos.entidad.EmpresaEmail; import com.rjconsultores.ventaboletos.entidad.EmpresaEmailConfig; import com.rjconsultores.ventaboletos.entidad.EmpresaEmailFlexBus; import com.rjconsultores.ventaboletos.entidad.EmpresaImposto; +import com.rjconsultores.ventaboletos.entidad.EmpresaSaferConfig; import com.rjconsultores.ventaboletos.entidad.Estado; import com.rjconsultores.ventaboletos.entidad.FormaPago; import com.rjconsultores.ventaboletos.entidad.InscricaoEstadual; @@ -68,6 +90,7 @@ import com.rjconsultores.ventaboletos.service.EmpresaEmailConfigService; import com.rjconsultores.ventaboletos.service.EmpresaEmailFlexBusService; import com.rjconsultores.ventaboletos.service.EmpresaEmailService; import com.rjconsultores.ventaboletos.service.EmpresaImpostoService; +import com.rjconsultores.ventaboletos.service.EmpresaSaferConfigService; import com.rjconsultores.ventaboletos.service.EmpresaService; import com.rjconsultores.ventaboletos.service.EstadoService; import com.rjconsultores.ventaboletos.service.FormaPagoService; @@ -120,14 +143,16 @@ public class EditarEmpresaController extends MyGenericForwardComposer { private EmpresaEmailService empresaEmailService; @Autowired private EmpresaEmailConfigService empresaEmailConfigService; - @Autowired private EmpresaEmailFlexBusService empresaEmailFlexBusService; + @Autowired + private EmpresaSaferConfigService empresaSaferConfigService; private Empresa empresa; private EmpresaEmail empresaEmail; private EmpresaEmailConfig empresaEmailConfig; private EmpresaEmailFlexBus empresaEmailFlexBus; + private EmpresaSaferConfig empresaSaferConfig; private MyListbox empresaList; private MyTextbox txtNome; private MyTextbox txtCNPJ; @@ -331,6 +356,12 @@ public class EditarEmpresaController extends MyGenericForwardComposer { private Decimalbox txtIrkPadrao; + private Label lblCertificado; + private Textbox txtSenhaCertificado; + private Textbox txtPartnerId; + private Textbox txtContractId; + private byte[] certificado; + private Tab tabSafer; private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; @@ -354,6 +385,7 @@ public class EditarEmpresaController extends MyGenericForwardComposer { if (empresa != null && empresa.getEmpresaId() != null) { empresaEmail = empresaEmailService.buscarPorEmpresa(empresa); empresaEmailConfig = empresaEmailConfigService.buscarPorEmpresa(empresa); + empresaSaferConfig = empresaSaferConfigService.buscarPorEmpresa(empresa); } if (empresa != null && empresa.getEmpresaId() != null) { @@ -385,7 +417,6 @@ public class EditarEmpresaController extends MyGenericForwardComposer { } else { chkAutenticacao.setChecked(true); } - if (empresaEmailFlexBus != null) { if(empresaEmailFlexBus.getIndAutenticacao()){ chkAutenticacaoFlexBus.setChecked(true); @@ -398,6 +429,21 @@ public class EditarEmpresaController extends MyGenericForwardComposer { chkAutenticacaoFlexBus.setChecked(true); } + if (empresaSaferConfig != null) { + txtPartnerId.setText(empresaSaferConfig.getPartnerId()); + txtContractId.setText(empresaSaferConfig.getContractId()); + txtSenhaCertificado.setText(empresaSaferConfig.getSenha()); + certificado = empresaSaferConfig.getCertificado(); + if(certificado != null){ + InputStream certStream = new ByteArrayInputStream(certificado); + if (certStream != null) { + lblCertificado.setValue(getCerticateInfo(certStream)); + } + } + } + + mostrarAbaSafer(); + if (empresa.getIndfechatarifa() == null) { rdgFechaSalida.setChecked(Boolean.TRUE); } else if (empresa.getIndfechatarifa()) { @@ -904,6 +950,16 @@ public class EditarEmpresaController extends MyGenericForwardComposer { preencheInformacoesEmpresaConfig(); empresaEmailConfigService.actualizacion(empresaEmailConfig); } + + if (empresaSaferConfig == null) { + empresaSaferConfig = new EmpresaSaferConfig(); + empresaSaferConfig.setEmpresa(empresa); + preencheInformacoesSaferConfig(); + empresaSaferConfig = empresaSaferConfigService.suscribir(empresaSaferConfig); + } else { + preencheInformacoesSaferConfig(); + empresaSaferConfigService.actualizacion(empresaSaferConfig); + } Messagebox.show(Labels.getLabel("editarEmpresaController.MSG.suscribirOK"), Labels.getLabel("editarEmpresaController.window.title"), @@ -948,6 +1004,12 @@ public class EditarEmpresaController extends MyGenericForwardComposer { empresaEmailFlexBus.setIndAutenticacao(chkAutenticacaoFlexBus.isChecked()); } + private void preencheInformacoesSaferConfig() { + empresaSaferConfig.setPartnerId(txtPartnerId.getValue()); + empresaSaferConfig.setContractId(txtContractId.getValue()); + empresaSaferConfig.setSenha(txtSenhaCertificado.getValue()); + empresaSaferConfig.setCertificado(certificado); + } private boolean validarEmail() { if (txtEmail.getText() == null || txtEmail.getText().isEmpty()) { @@ -1958,6 +2020,76 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException { validarCPFCNPJ(numDoc); } + public void uploadFile(UploadEvent event) { + org.zkoss.util.media.Media media = event.getMedia(); + + try { + String info = getCerticateInfo(media.getStreamData()); + + if (info != null) { + certificado = media.getByteData(); + lblCertificado.setValue(info); + } else { + Messagebox.show( + Labels.getLabel("editarMarcaController.MSG.errorIMG") + " " + media, + Labels.getLabel("editarEmpresaController.window.title"), + Messagebox.OK, Messagebox.ERROR); + } + + } catch (Exception ex) { + log.error(ex); + throw UiException.Aide.wrap(ex); + } + } + + private String getCerticateInfo(InputStream cerFileStream) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, UnrecoverableEntryException, InvalidKeyException, SignatureException { + + Certificate certificate = null; + PrivateKey pvtkey = null; + Enumeration aliasList; + String alias; + + String certPassword = txtSenhaCertificado.getValue(); + + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(cerFileStream, certPassword.toCharArray()); + aliasList = keyStore.aliases(); + while (aliasList.hasMoreElements()) { + alias = aliasList.nextElement(); + KeyStore.ProtectionParameter entryPassword = new KeyStore.PasswordProtection(certPassword.toCharArray()); + KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, entryPassword); + pvtkey = privateKeyEntry.getPrivateKey(); + X509Certificate c = (X509Certificate) keyStore.getCertificate(alias); + PrivateKey privKey = pvtkey; + Signature sign = Signature.getInstance("SHA256withRSA"); + sign.initSign(privKey); + byte[] bytes = "TestSign".getBytes(); + sign.update(bytes); + byte[] signature = sign.sign(); + PublicKey pubKey = c.getPublicKey(); + Signature verify = Signature.getInstance("SHA256withRSA"); + verify.initVerify(pubKey); + verify.update(bytes); + + boolean signatureVerified = verify.verify(signature); + if (signatureVerified) { + SimpleDateFormat fmt = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + String dadosCertificado = "Certificado: OK" + "\n" + + "Validade: " + fmt.format(c.getNotBefore()) + " até " + fmt.format(c.getNotAfter()) + + "\n" + "Tipo: " + c.getVersion() + "\n" + + c.getSubjectDN().getName(); + return dadosCertificado; + } + } + return null; + } + + private void mostrarAbaSafer() { + if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.INTEGRACION_SAFER.getDescricao())) { + tabSafer.setVisible(true); + } + } + private boolean validarCPFCNPJ(String numDoc) { try { if(numDoc == null) { diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java index 59c64c70c..2a0792147 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/pricing/EditarPricingController.java @@ -253,7 +253,8 @@ public class EditarPricingController extends PricingController { private Radio rdOcupacaoTrechoSim; private Radio rdOcupacaoTrechoNao; - + + private Checkbox chkIndSafer; private void clearCombobox(Combobox combobox) { int size = combobox.getItemCount(); @@ -581,6 +582,10 @@ public class EditarPricingController extends PricingController { chkIndSomenteAssentoSugerido.setChecked(pricing.getIndSomenteAssentoSugerido()); chkIndPricingDividirIdaEVolta.setChecked(pricing.getIndPricingDividirIdaEVolta()); + if (pricing.getIndSafer() != null) { + chkIndSafer.setChecked(pricing.getIndSafer()); + } + if (lsPricingImporte.size() > 0) { radioImp.setChecked(true); onClick$radioImp(null); @@ -1018,6 +1023,7 @@ public class EditarPricingController extends PricingController { pricing.setIndOcupacaoPorTrecho(rdOcupacaoTrechoSim.isChecked()); pricing.setIndSomenteAssentoSugerido(chkIndSomenteAssentoSugerido.isChecked()); + pricing.setIndSafer(chkIndSafer.isChecked()); pricing.setIndPricingDividirIdaEVolta(chkIndPricingDividirIdaEVolta.isChecked()); diff --git a/src/java/spring-config.xml b/src/java/spring-config.xml index 70b3533e3..d1c402469 100644 --- a/src/java/spring-config.xml +++ b/src/java/spring-config.xml @@ -479,6 +479,7 @@ com.rjconsultores.ventaboletos.entidad.PricingEspecificoCategoria com.rjconsultores.ventaboletos.entidad.EmpresaEmail com.rjconsultores.ventaboletos.entidad.EmpresaEmailConfig + com.rjconsultores.ventaboletos.entidad.EmpresaSaferConfig com.rjconsultores.ventaboletos.entidad.CtrlFechamentoCaixa com.rjconsultores.ventaboletos.entidad.PtovtaAntifraude com.rjconsultores.ventaboletos.entidad.OperadorEmbarcada diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 73d0eb2a5..9c8aecd7d 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -1648,6 +1648,12 @@ editarEmpresaImpostoController.bpe.value = Habilitar BPe editarEmpresaImpostoController.tributoEmissao.value = Tributa Emissão editarEmpresaImpostoController.tributoViagem.value = Tributa Viagem +editarEmpresaController.lblSafer.value = Safer +editarEmpresaController.lblCodigoSafer.value = Código do parceiro +editarEmpresaController.lblCodigoContratoSafer.value = Código do contrato +editarEmpresaController.lblInfoSafer.value = Informações Certificado +editarEmpresaController.lblCarregarCertificadoSafer.value = Carregar Certificado + # Muestra o ponto de Búsqueda de venta busquedaPuntoVentaController.window.title = Punto de venta ( Agencia ) busquedaPuntoVentaController.btnRefresh.tooltiptext = Actualizar diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index ff310eec8..027d57f5a 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -1863,6 +1863,12 @@ editarEmpresaImpostoController.bpe.value = Habilitar BPe editarEmpresaImpostoController.tributoEmissao.value = Tributa Emissão editarEmpresaImpostoController.tributoViagem.value = Tributa Viagem +editarEmpresaController.lblSafer.value = Safer +editarEmpresaController.lblCodigoSafer.value = Código do parceiro +editarEmpresaController.lblCodigoContratoSafer.value = Código do contrato +editarEmpresaController.lblInfoSafer.value = Informações Certificado +editarEmpresaController.lblCarregarCertificadoSafer.value = Carregar Certificado + # Muestra o ponto de Pesquisa de Venda busquedaPuntoVentaController.window.title = Ponto de Venda ( Agência ) busquedaPuntoVentaController.btnRefresh.tooltiptext = Atualizar diff --git a/web/gui/catalogos/editarEmpresa.zul b/web/gui/catalogos/editarEmpresa.zul index 9276bccfd..f6b67d107 100644 --- a/web/gui/catalogos/editarEmpresa.zul +++ b/web/gui/catalogos/editarEmpresa.zul @@ -29,6 +29,7 @@ + + + + + + + + + @@ -1957,11 +1967,67 @@ width="100%"> - + + + + + + + + + + + + + + + + + + + + +                          + +               + + + + + + + + + + + + + diff --git a/web/gui/pricing/editarPricing.zul b/web/gui/pricing/editarPricing.zul index 5dabf3cab..09c6196bb 100644 --- a/web/gui/pricing/editarPricing.zul +++ b/web/gui/pricing/editarPricing.zul @@ -225,6 +225,14 @@ + + + + + +