/** * Retorna o objeto relativo a compentência do contribuinte * * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte * @return Contribuinte_Model_Competencia[] */ public static function getByContribuinte(Contribuinte_Model_ContribuinteAbstract $oContribuinte) { $oEntityManager = self::getEm(); $sSql = 'SELECT DISTINCT nota.ano_comp, nota.mes_comp, SUM(nota.s_vl_iss) as s_vl_iss , SUM(nota.s_vl_servicos) as s_vl_servicos FROM Contribuinte\\Nota nota WHERE nota.id_contribuinte in(:id_contribuinte) AND nota.cancelada = false AND nota.s_vl_iss > 0 AND nota.s_dados_iss_retido = 1 AND nota.emite_guia = true AND nota.importada = false GROUP BY nota.ano_comp, nota.mes_comp ORDER BY nota.ano_comp DESC, nota.mes_comp DESC'; $oQuery = $oEntityManager->createQuery($sSql); $oQuery->setParameter('id_contribuinte', $oContribuinte->getContribuintes()); $aResultados = $oQuery->getResult(); $aRetorno = array(); foreach ($aResultados as $aCompetencia) { $oCompetencia = new self($aCompetencia['ano_comp'], $aCompetencia['mes_comp'], $oContribuinte); $oCompetencia->setTotalIss($aCompetencia['s_vl_iss']); $oCompetencia->setTotalServico($aCompetencia['s_vl_servicos']); $lExisteGuia = Contribuinte_Model_Guia::existeGuia($oContribuinte, $aCompetencia['mes_comp'], $aCompetencia['ano_comp'], 10); $oCompetencia->setExisteGuia($lExisteGuia); $aRetorno[] = $oCompetencia; } return $aRetorno; }
/** * Busca a aliquota por servico [Json] */ public function emissaoManualBuscarDadosServicoAction() { try { // Perfil do usuario $iIdPerfil = $this->oUsuario->getPerfil()->getId(); $iIdServico = $this->getParam('id_servico'); $aRetornoJson = array(); // Ignora se for prestador eventual if ($iIdPerfil != 6) { $aServicos = Contribuinte_Model_Servico::getByIm($this->oContribuinte->getInscricaoMunicipal(), FALSE); if (is_array($aServicos)) { foreach ($aServicos as $oServico) { if ($oServico->attr('cod_atividade') == $iIdServico) { $aRetornoJson = array('item_servico' => $oServico->attr('desc_item_servico'), 'cod_item_servico' => $oServico->attr('cod_item_servico'), 'estrut_cnae' => $oServico->attr('estrut_cnae'), 'deducao' => $oServico->attr('deducao'), 'aliq' => DBSeller_Helper_Number_Format::toMoney($oServico->attr('aliq'))); break; } } } } echo $this->getHelper('json')->sendJson($aRetornoJson); } catch (Exception $e) { $aRetorno['erro'] = TRUE; if ($e->getCode() == Global_Lib_Model_WebService::CODIGO_ERRO_CONSULTA_WEBSERVICE) { $aRetorno['mensagem'] = "E-cidade temporariamente insdisponível. Emissão bloqueada!"; } else { $aRetorno['mensagem'] = $e->getMessage(); } echo $this->getHelper('json')->sendJson($aRetorno); } }
/** * Retorna todas guias pagas pelo contribuinte optante pelo simples nacional * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte contribuinte optante pelo simples * @return array */ public static function getGuiasPagasOptanteSimples(Contribuinte_Model_ContribuinteAbstract $oContribuinte) { $aCampos = array('competencia', 'data_vencimento', 'valor_historico', 'valor_corrigido', 'valor_pago'); $aParametros = array(array('inscricao_municipal' => $oContribuinte->getInscricaoMunicipal(), 'tipo_debito' => 3), $aCampos); $aGuiasPagas = WebService_Model_Ecidade::consultar('getPagamentosEfetuadosOptanteSimples', $aParametros); $sRetorno = ''; if (empty($aGuiasPagas)) { $aGuiasPagas = array(); } else { $sRetorno = print_r($aGuiasPagas, true); if (count($aGuiasPagas) == 1 && trim($aGuiasPagas[0]) == 'N') { $aGuiasPagas = array(); } else { if (trim($sRetorno) === "Não houve retorno do WebService") { $aGuiasPagas = array(); } else { //Reverte a ordenação para DESC $aGuiasPagas = array_reverse($aGuiasPagas); } } } return $aGuiasPagas; }
/** * Verifica se o RPS já foi registrado pelo contribuinte * * @tutorial Retorna TRUE caso já exista o RPS * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte * @param integer $iNumeroRps * @param integer $iTipoDocumento * @return boolean */ public static function existeRps(Contribuinte_Model_ContribuinteAbstract $oContribuinte, $iNumeroRps, $iTipoDocumento) { $oEm = parent::getEm(); $sSql = 'SELECT 1 FROM Contribuinte\\Nota nota WHERE nota.id_contribuinte = :id_contribuinte AND nota.grupo_nota = :grupo_documento AND nota.tipo_nota = :tipo_documento AND nota.n_rps = :numero_rps'; $oQuery = $oEm->createQuery($sSql); $oQuery->setParameter('id_contribuinte', $oContribuinte->getIdUsuarioContribuinte()); $oQuery->setParameter('grupo_documento', Contribuinte_Model_Nota::GRUPO_NOTA_RPS); $oQuery->setParameter('tipo_documento', $iTipoDocumento); $oQuery->setParameter('numero_rps', $iNumeroRps); $aResultado = $oQuery->getResult(); return count($aResultado) > 0; }
/** * Verifica se exista nota emitida com o numero e serie informados * * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte * @param string $sTipoDocumentoDescricao * @param string $sNumeroDocumento * @param string $sSerieDocumento * @param integer $iIdDocumento * @return boolean * [TRUE : Existe Nota Emitida] */ public static function checarNotaEmitidaPrestadorEventual(Contribuinte_Model_ContribuinteAbstract $oContribuinte, $sTipoDocumentoDescricao, $sNumeroDocumento, $sSerieDocumento = NULL, $iIdDocumento = NULL) { if (empty($oContribuinte)) { throw new Exception('Informe um contribuinte válido para checar a emissão'); } if (!$sTipoDocumentoDescricao) { throw new Exception('Informe o Tipo de Nota para checar a emissão'); } if (!$sNumeroDocumento) { throw new Exception('Informe o Número da Nota para checar a emissão'); } $oEntityManager = parent::getEm(); $oQuery = $oEntityManager->createQueryBuilder(); $oQuery->select('1'); $oQuery->from('Contribuinte\\DmsNota', 'n'); $oQuery->leftJoin('Contribuinte\\Dms', 'd', \Doctrine\ORM\Query\Expr\Join::WITH, 'n.id_dms = d.id'); $oQuery->where('n.id_contribuinte in (:id_contribuinte)'); $oQuery->andWhere('n.nota = :nota'); $oQuery->andWhere('n.tipo_documento_descricao = :tipo_documento_descricao'); $oQuery->andWhere('d.operacao = :operacao'); $oQuery->setParameter('id_contribuinte', $oContribuinte->getContribuintes()); $oQuery->setParameter('nota', $sNumeroDocumento); $oQuery->setParameter('tipo_documento_descricao', $sTipoDocumentoDescricao); $oQuery->setParameter('operacao', 's'); $oQuery->setMaxResults(1); if ($sSerieDocumento) { $oQuery->andWhere('n.serie = TRIM(:serie)'); $oQuery->setParameter('serie', $sSerieDocumento); } // Verifica se existem outros documentos somente na alteração if ($iIdDocumento) { $oQuery->andWhere('n.id <> :id_nota'); $oQuery->setParameter('id_nota', $iIdDocumento); } $aResultado = $oQuery->getQuery()->getResult(); if (is_array($aResultado) && count($aResultado) > 0) { return TRUE; } return FALSE; }
/** * Seta o contribuinte na sessão * * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte * @internal param int $iInscricaoMunicipal */ private function setContribuinte(Contribuinte_Model_ContribuinteAbstract $oContribuinte) { $this->_session->id = $oContribuinte->getIdUsuarioContribuinte(); $this->_session->contribuinte = $oContribuinte; new DBSeller_Acl_Setup(TRUE); }
/** * Retorna Notas do Dms filtrando por id do Dms * * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte Instância do contribuinte * @param integer $iAno Ano da competência * @param integer $iMes Mês da competência * @param string $sOperacao Tipo de operação * @return Contribuinte_Model_Dms[] Coleção de contribuinte */ public static function getDMSSemGuiaNaCompetencia(Contribuinte_Model_ContribuinteAbstract $oContribuinte, $iAno, $iMes, $sOperacao = self::SAIDA) { $sDql = 'SELECT e FROM Contribuinte\\Dms e WHERE e.id_contribuinte in(:id_contribuinte) AND e.operacao = :operacao AND e.ano_comp = :ano AND e.mes_comp = :mes AND e.codigo_planilha IS NULL AND (e.status = \'fechado\' OR e.status = \'emitida\')'; $oEntidade = self::getEm(); $sQuery = $oEntidade->createQuery($sDql); $oResult = $sQuery->setParameters(array('id_contribuinte' => $oContribuinte->getContribuintes(), 'mes' => $iMes, 'ano' => $iAno, 'operacao' => $sOperacao))->getResult(); if (count($oResult) > 0) { foreach ($oResult as $oRetorno) { $aRetorno[] = new self($oRetorno); } } return isset($aRetorno) ? $aRetorno : array(); }