/** * (non-PHPdoc) * @see Zend_Form::init() */ public function init() { $oBaseUrlHelper = new Zend_View_Helper_BaseUrl(); $this->setName('form_parametros_prefeitura_rps'); $this->setAction($oBaseUrlHelper->baseUrl('/administrativo/parametro/prefeitura-salvar-rps')); $oParametrosPrefeituraRps = new Administrativo_Model_ParametroPrefeituraRps(); $aParametrosPrefeituraRps = $oParametrosPrefeituraRps->getListAll(NULL, array('tipo_nfse' => 'ASC')); foreach ($aParametrosPrefeituraRps as $oParametroRps) { $aElementos[$oParametroRps->getId()] = $this->createElement('select', (string) $oParametroRps->getTipoNfse()); $aElementos[$oParametroRps->getId()]->setLabel("{$oParametroRps->getTipoNfseDescricao()}:"); $aElementos[$oParametroRps->getId()]->setBelongsTo('parametros_prefeitura_rps'); $aElementos[$oParametroRps->getId()]->setAttrib('class', 'span3'); $aElementos[$oParametroRps->getId()]->removeDecorator('errors'); self::setTiposEcidade($aElementos[$oParametroRps->getId()]); } $aElementos[] = $this->createElement('submit', 'btn_salvar_rps', array('label' => 'Salvar', 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_SUCCESS)); $this->addElements($aElementos); return $this; }
/** * Define os dados dos documentos válidos * * @param \Doctrine\DBAL\Statement $oStatement * @param array $aParametros * @throws Exception */ public function setDadosDocumentosValidos(Doctrine\DBAL\Statement $oStatement, array $aParametros) { // Notas Válidas $this->SetFont('Arial', 'B', 8); $this->SetFillColor(201, 201, 201); $this->Cell(0, 5, utf8_decode('LANÇAMENTOS VÁLIDOS'), 1, 1, 'C', TRUE); $this->Ln(1); $aLarguraCelulas = array(6, 13, 10, 50, 25, 9, 12, 20, 20, 27, 85); $this->SetFillColor(230, 230, 230); $this->Cell($aLarguraCelulas[0], 5, utf8_decode('Dia'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[1], 5, utf8_decode('Número'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[2], 5, utf8_decode('Série'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[3], 5, utf8_decode('Tipo'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[4], 5, utf8_decode('Situação'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[5], 5, utf8_decode('Cod.'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[6], 5, utf8_decode('Aliq.(%)'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[7], 5, utf8_decode('Base(R$)'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[8], 5, utf8_decode('ISS(R$)'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[9], 5, utf8_decode('CNPJ Tomador'), 1, NULL, NULL, TRUE); $this->Cell($aLarguraCelulas[10], 5, utf8_decode('Razão Tomador'), 1, NULL, NULL, TRUE); $this->SetFont('Arial', NULL, 8); try { $oStatement->execute($aParametros); if ($oStatement->rowCount() > 0) { $fTotalBase = 0; $fTotalIss = 0; while ($aNota = $oStatement->fetch()) { $sDiaEmissaoDocumento = substr($aNota['documento_data'], -2); $this->Ln(); $this->Cell($aLarguraCelulas[0], 5, $sDiaEmissaoDocumento, 1, 0, 'C'); $this->Cell($aLarguraCelulas[1], 5, $aNota['documento_numero'], 1, 0, 'R'); $this->Cell($aLarguraCelulas[2], 5, $aNota['documento_serie'], 1, 0, 'R'); // Tipo de documento if ($aNota['documento_classe'] == 'nfse') { $sTipoNota = 'NFSe'; if ($aNota['documento_tipo']) { $oTipoNota = Administrativo_Model_ParametroPrefeituraRps::getByTipoEcidade($aNota['documento_tipo']); $sTipoNota = $oTipoNota->getTipoNfseDescricao(); } $this->Cell($aLarguraCelulas[3], 5, utf8_decode($sTipoNota), 1); } else { if ($aNota['documento_classe'] == 'dms' && $aNota['documento_tipo']) { if ($aNota['documento_tipo_descricao']) { $sTipoNota = $aNota['documento_tipo_descricao']; } else { $oTipoNota = Administrativo_Model_ParametroPrefeituraRps::getByTipoEcidade($aNota['documento_tipo']); $sTipoNota = $oTipoNota->getTipoNfseDescricao(); } $this->Cell($aLarguraCelulas[3], 5, utf8_decode($sTipoNota), 1); } else { $this->Cell($aLarguraCelulas[3], 5, '-', 1); } } // Formata dados $sServicoValorAliquota = DBSeller_Helper_Number_Format::toMoney($aNota['servico_valor_aliquota']); $sServicoValorBaseCalculo = DBSeller_Helper_Number_Format::toMoney($aNota['servico_valor_base_calculo']); $sServicoValorIss = DBSeller_Helper_Number_Format::toMoney($aNota['servico_valor_iss']); $sTomadorCnpjCpf = DBSeller_Helper_Number_Format::maskCPF_CNPJ($aNota['tomador_cnpjcpf']); $sTomadorRazaoSocial = utf8_decode($aNota['tomador_razao_social']); $sTomadorRazaoSocial = substr($sTomadorRazaoSocial, 0, 50); // Verifica se é tomador não identificado if (!$sTomadorCnpjCpf) { $sTomadorRazaoSocial = utf8_decode('Não identificado'); } // Trata a situação do documento switch (strtoupper($aNota['documento_situacao'])) { case 'T': $sSituacaoDocumento = utf8_decode('Tributado'); break; case 'R': $sSituacaoDocumento = utf8_decode('Retido'); break; case 'IS': $sSituacaoDocumento = utf8_decode('Isento'); break; case 'E': $sSituacaoDocumento = utf8_decode('Extraviado'); break; default: $sSituacaoDocumento = '-'; } // ALtera a situação do documento quando a natureza for fora do município if ($aNota['documento_natureza_operacao'] == 2) { $sSituacaoDocumento = utf8_decode('Fora do Município'); } // Nota cancelada if ($aNota['documento_status_cancelamento'] == 't' || $aNota['documento_situacao'] == 'c') { $sSituacaoDocumento = utf8_decode('Cancelado'); $sServicoValorBaseCalculo = '-'; $sServicoValorIss = '-'; } // Nota substituida if (!empty($aNota['documento_id_nota_substituta'])) { $sSituacaoDocumento = utf8_decode('Substituida'); $sServicoValorBaseCalculo = '-'; $sServicoValorIss = '-'; } // Verifica se a nota foi substituida ou cancelada não soma os valores totais if ($aNota['documento_status_cancelamento'] != 't' && empty($aNota['documento_id_nota_substituta'])) { $fTotalBase += $aNota['servico_valor_base_calculo']; $fTotalIss += $aNota['servico_valor_iss']; } $this->Cell($aLarguraCelulas[4], 5, $sSituacaoDocumento, 1, 0, 'L', NULL); $this->Cell($aLarguraCelulas[5], 5, $aNota['servico_item_lista_servico'], 1, 0, 'L', NULL); $this->Cell($aLarguraCelulas[6], 5, $sServicoValorAliquota, 1, 0, 'R', NULL); $this->Cell($aLarguraCelulas[7], 5, $sServicoValorBaseCalculo, 1, 0, 'R', NULL); $this->Cell($aLarguraCelulas[8], 5, $sServicoValorIss, 1, 0, 'R', NULL); $this->Cell($aLarguraCelulas[9], 5, $sTomadorCnpjCpf, 1, 0, 'L', NULL); $this->Cell($aLarguraCelulas[10], 5, $sTomadorRazaoSocial, 1, 0, 'L', NULL); } $this->SetFont('Arial', 'B', 8); $this->Ln(); $this->Cell(113); $this->Cell($aLarguraCelulas[6], 5, 'Total:', 1); $this->Cell($aLarguraCelulas[7], 5, DBSeller_Helper_Number_Format::toMoney($fTotalBase), 1, 0, 'R'); $this->Cell($aLarguraCelulas[8], 5, DBSeller_Helper_Number_Format::toMoney($fTotalIss), 1, 0, 'R'); } else { $this->Ln(); $this->Cell(0, 5, utf8_decode('Sem Lançamentos no Período'), 1, NULL, 'C'); } $oStatement->closeCursor(); } catch (Exception $oErro) { throw new Exception($oErro->getMessage()); } }
/** * Valida a importação de arquivo do tipo RPS modelo 1 (ABRASF 1.0) */ public function validaArquivoCarregado() { $oSessao = new Zend_Session_Namespace('nfse'); if (empty($this->oDadosPrefeitura)) { $aParametrosPrefeitura = Administrativo_Model_ParametroPrefeitura::getAll(0, 1); if (count($aParametrosPrefeitura) == 0) { throw new Exception('Parâmetros da prefeitura não configurados. Processamento Abortado'); } $this->oDadosPrefeitura = $aParametrosPrefeitura[0]; } if (empty($this->oArquivoXmlRetorno->lote->numero)) { $this->setMensagemErro('E88'); } if (empty($this->oArquivoXmlRetorno->lote->cnpj)) { $this->setMensagemErro('E46'); } $oContribuinte = Contribuinte_Model_Contribuinte::getByCpfCnpj($this->oArquivoXmlRetorno->lote->cnpj); if (empty($oContribuinte)) { $this->setMensagemErro('E45', 'Contribuinte: ' . $this->oArquivoXmlRetorno->lote->cnpj); } else { if ($oContribuinte->getCgcCpf() != $oSessao->contribuinte->getCgcCpf()) { $this->setMensagemErro('E156', '', true); } } if ($this->oArquivoXmlRetorno->lote->quantidade_rps != count($this->oArquivoXmlRetorno->rps)) { $this->setMensagemErro('E69'); } if (strlen($this->oArquivoXmlRetorno->lote->quantidade_rps) > 4) { $this->setMensagemErro('E72'); } $aNumeracaoRPS = array(); foreach ($this->oArquivoXmlRetorno->rps as $oRps) { if ($this->oArquivoXmlRetorno->lote->inscricao_municipal != $oRps->prestador->inscricao_municipal) { $this->setMensagemErro('E70', 'RPS: ' . $oRps->numero); } if (empty($oRps->numero)) { $this->setMensagemErro('E11'); } else { if (is_int($oRps->numero) && strlen($oRps->numero) > 15) { $this->setMensagemErro('E96', 'RPS: ' . $oRps->numero); } if (in_array($oRps->numero, $aNumeracaoRPS)) { $this->setMensagemErro('E71', 'RPS: ' . $oRps->numero); } $aNumeracaoRPS[$oRps->numero] = NULL; } if (strlen($oRps->serie) > 5) { $this->setMensagemErro('E97', 'RPS: ' . $oRps->numero); } if (empty($oRps->tipo)) { $this->setMensagemErro('E12', 'RPS: ' . $oRps->numero); } if (empty($oRps->natureza_operacao)) { $this->setMensagemErro('E3', 'RPS: ' . $oRps->numero); } else { if (!in_array($oRps->natureza_operacao, array(1, 2, 3, 4, 5, 6))) { $this->setMensagemErro('E144', 'RPS: ' . $oRps->numero); } } if (empty($oRps->optante_simples_nacional)) { $this->setMensagemErro('E8', 'RPS: ' . $oRps->numero); } else { if (!in_array($oRps->optante_simples_nacional, array(1, 2))) { $this->setMensagemErro('E146', 'RPS: ' . $oRps->numero); } } if (empty($oRps->incentivador_cultural)) { $this->setMensagemErro('E9', 'RPS: ' . $oRps->numero); } else { if (!in_array($oRps->incentivador_cultural, array(1, 2))) { $this->setMensagemErro('E147', 'RPS: ' . $oRps->numero); } } if (empty($oRps->data_emissao)) { $this->setMensagemErro('E14', 'RPS: ' . $oRps->numero); } if (!in_array($oRps->status, array(1, 2))) { $this->setMensagemErro('E68', 'RPS: ' . $oRps->numero); } if ($oRps->data_emissao->format('Ymd') > date('Ymd')) { $this->setMensagemErro('E16', 'RPS: ' . $oRps->numero); } if ($oRps->prestador->cnpj == $oRps->tomador->cpf_cnpj) { $this->setMensagemErro('E52', 'RPS: ' . $oRps->numero); } // validação dos valores se float $oNumeroFloat = new Zend_Validate_Float(); if ($oRps->servico->valores->valor_servicos <= 0) { $this->setMensagemErro('E18', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_servicos)) { $this->setMensagemErro('E100', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_servicos <= 0) { $this->setMensagemErro('E18', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_deducoes > $oRps->servico->valores->valor_servicos) { $this->setMensagemErro('E19', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_deducoes < 0) { $this->setMensagemErro('E20', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_deducoes)) { $this->setMensagemErro('E101', 'RPS: ' . $oRps->numero); } $fTotalDesconto = $oRps->servico->valores->desconto_incondicionado + $oRps->servico->valores->desconto_condicionado; if ($fTotalDesconto > $oRps->servico->valores->valor_servicos) { $this->setMensagemErro('E21', 'RPS: ' . $oRps->numero); } if ($fTotalDesconto < 0) { $this->setMensagemErro('E22', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($fTotalDesconto)) { $this->setMensagemErro('E102', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_pis < 0) { $this->setMensagemErro('E23', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_pis)) { $this->setMensagemErro('E103', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_cofins < 0) { $this->setMensagemErro('E24', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_cofins)) { $this->setMensagemErro('E103', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_inss < 0) { $this->setMensagemErro('E25', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_inss)) { $this->setMensagemErro('E103', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_ir < 0) { $this->setMensagemErro('E26', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_ir)) { $this->setMensagemErro('E103', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->valor_csll < 0) { $this->setMensagemErro('E27', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_csll)) { $this->setMensagemErro('E103', 'RPS: ' . $oRps->numero); } if (!in_array($oRps->servico->valores->iss_retido, array(1, 2))) { $this->setMensagemErro('E36', 'RPS: ' . $oRps->numero); } if ($oRps->servico->valores->iss_retido == 1) { if ($oRps->servico->valores->valor_iss_retido <= 0) { $this->setMensagemErro('E40', 'RPS: ' . $oRps->numero); } if (!$oNumeroFloat->isValid($oRps->servico->valores->valor_iss_retido)) { $this->setMensagemErro('E153', 'RPS: ' . $oRps->numero); } if (strlen(DBSeller_Helper_Number_Format::unmaskCPF_CNPJ($oRps->tomador->cpf_cnpj)) != 14) { $this->setMensagemErro('E39', 'RPS: ' . $oRps->numero . ". Serviços tomados por pessoa Física não pode reter iss"); } } if ($oRps->servico->valores->iss_retido == 1 && $oRps->servico->valores->valor_iss_retido > $oRps->servico->valores->valor_servicos) { $this->setMensagemErro('E99', 'RPS: ' . $oRps->numero); } if (empty($oRps->servico->discriminacao)) { $this->setMensagemErro('E41', 'RPS: ' . $oRps->numero); } if (!empty($oContribuinte)) { $iInscricaoMunicipal = $oContribuinte->getInscricaoMunicipal(); $aServicos = Contribuinte_Model_Servico::getByIm($iInscricaoMunicipal); // Valida se o prestador de serviço pode atuar no município if (empty($aServicos)) { $this->setMensagemErro('E17', 'RPS: ' . $oRps->numero); } // Valida se o prestador do serviço é emissor de NFSE $iTipoEmissaoNfse = Contribuinte_Model_ContribuinteAbstract::TIPO_EMISSAO_NOTA; if ($oContribuinte->getTipoEmissao($iInscricaoMunicipal) != $iTipoEmissaoNfse) { $this->setMensagemErro('E138', 'RPS: ' . $oRps->numero); } // Valida a competência $oCompetencia = new Contribuinte_Model_Competencia($oRps->data_emissao->format('Y'), $oRps->data_emissao->format('m'), $oContribuinte); if (empty($oCompetencia) || $oCompetencia->existeGuiaEmitida()) { $this->setMensagemErro(null, "A competência da RPS \"{$oRps->numero}\" é inválida, já existe Guia Emitida."); } } // Valida se a data é maior que a atual if ($oRps->data_emissao->format('Y-m') > date('Y-m')) { $this->setMensagemErro('E2', 'RPS: ' . $oRps->numero); } // Valida se já existe na base de dados $oTipoRps = Administrativo_Model_ParametroPrefeituraRps::getByTipoNfse($oRps->tipo); $iTipoRps = 0; // Valida o tipo de RPS if (is_object($oTipoRps)) { $iTipoRps = $oTipoRps->getEntity()->getTipoEcidade($oRps->tipo); } if ($iTipoRps == 0) { $this->setMensagemErro('E13', 'RPS: ' . $oRps->numero); } // Verifica se a numeração do AIDOF é válida $oAidof = new Administrativo_Model_Aidof(); $lVerificaNumeracaoRps = $oAidof->verificarNumeracaoValidaParaEmissaoDocumento($oSessao->contribuinte->getInscricaoMunicipal(), $oRps->numero, $iTipoRps); if ($lVerificaNumeracaoRps === FALSE) { $this->setMensagemErro('E90', 'RPS: ' . $oRps->numero); } $lExisteRps = Contribuinte_Model_Nota::existeRps($oSessao->contribuinte, $oRps->numero, $oRps->tipo); if ($lExisteRps) { $this->setMensagemErro('E10', 'RPS: ' . $oRps->numero); } if (empty($oRps->servico->atividade)) { $this->setMensagemErro('E31', 'RPS: ' . $oRps->numero); } else { if (strlen($oRps->servico->atividade) > 5) { $this->setMensagemErro('E104', 'RPS: ' . $oRps->numero); } // Valida Grupo de Serviço/Atividade if (!empty($iInscricaoMunicipal)) { $oServico = Contribuinte_Model_Servico::getServicoPorAtividade($iInscricaoMunicipal, $oRps->servico->atividade); if (!$oServico) { $this->setMensagemErro('E30', 'RPS: ' . $oRps->numero); } } } if (empty($oRps->servico->codigo_cnae)) { $this->setMensagemErro('E33', 'RPS: ' . $oRps->numero); } else { if (strlen($oRps->servico->codigo_cnae) > 7) { $this->setMensagemErro('E105', 'RPS: ' . $oRps->numero); } } if (!empty($oRps->servico->ibge_municipio)) { if (strlen($oRps->servico->ibge_municipio) > 7) { $this->setMensagemErro('E108', 'RPS: ' . $oRps->numero); } // 2 = fora do municipio if ($oRps->natureza_operacao == 2 && $oRps->servico->ibge_municipio == $this->oDadosPrefeitura->getIbge()) { $this->setMensagemErro('E110', 'RPS: ' . $oRps->numero); } } // Validar IBGE Prefeitura if ($oRps->natureza_operacao == 1 && $this->oDadosPrefeitura->getIbge() !== $oRps->servico->ibge_municipio) { $this->setMensagemErro('E42', 'RPS: ' . $oRps->numero); } if (strlen($oRps->construcao_civil->art) > 15) { $this->setMensagemErro('E130', 'RPS: ' . $oRps->numero); } if (strlen($oRps->construcao_civil->codigo_obra) > 15) { $this->setMensagemErro('E129', 'Rps: ' . $oRps->numero); } if (count($this->aMensagensErroValidacao) >= 50) { $this->setMensagemErro('E49', '', TRUE); } } // Se existirem erros executa uma exceção com a lista de erros if (count($this->aMensagensErroValidacao) > 0) { return FALSE; } return TRUE; }
/** * Atualiza a lista de parâmetros do RPS com os código de tipo de RPS do ecidade, * limpa os códigos do ecidade se o paraêmtro para limpar for informado * * @param array $aParametros * @param boolean (default: FALSE) $lLimpar * @see Administrativo_ParametroController::prefeituraSalvarRpsAction() * @return boolean */ private function atualizarParametrosRps($aParametros, $lLimpar = FALSE) { if (!is_array($aParametros)) { return FALSE; } // Varre a lista de parametros foreach ($aParametros as $iIdParametroPrefeituraRps => $iTipoEcidade) { $oParametrosPrefeituraRps = Administrativo_Model_ParametroPrefeituraRps::getById($iIdParametroPrefeituraRps); // Limpar para poder salvar if ($lLimpar) { $oParametrosPrefeituraRps->setTipoEcidade(NULL); } else { $oParametrosPrefeituraRps->setTipoEcidade(empty($iTipoEcidade) ? NULL : $iTipoEcidade); } $oParametrosPrefeituraRps->persist(); } return TRUE; }