/** * Busca os dados necessários para preencher o relatório */ public function consultarAction() { parent::noLayout(); $oForm = new Fiscal_Form_RelatorioNfsePeriodo(); $this->view->form = $oForm; try { $aParametros = $this->getRequest()->getParams(); if (!$oForm->isValid($aParametros)) { throw new Exception('Informe um período válido!'); } $oNotaModel = new Contribuinte_Model_Nota(); $aNotas = $oNotaModel->getNotaPorPeriodo($aParametros); if (count($aNotas) == 0) { throw new Exception('Nenhum registro encontrado!'); } $oArquivoPDF = $this->gerarPdf($aNotas); $aRetornoJson['status'] = TRUE; $aRetornoJson['url'] = $this->view->baseUrl("/fiscal/relatorio-nfse-periodo/download/arquivo/{$oArquivoPDF->filename}"); $aRetornoJson['success'] = $this->translate->_('Relatório gerado com sucesso.'); } catch (Exception $oErro) { $aRetornoJson['status'] = FALSE; $aRetornoJson['error'][] = $this->translate->_($oErro->getMessage()); } echo $this->getHelper('json')->sendJson($aRetornoJson); }
/** * Método construtor, renderiza os campos do formulário * * @return $this|void */ public function init() { parent::init(); // Tradução self::$oTranslate = Zend_Registry::get('Zend_Translate'); // Url base do sistema self::$oBaseUrlHelper = new Zend_View_Helper_BaseUrl(); // Configurações pado do formulário $this->setName('formRelatorio'); $this->setMethod(Zend_form::METHOD_POST); $this->setAction('/fiscal/relatorio-nfse-periodo/consultar'); $oElm = $this->createElement('text', 'data_nota_inicial', array('divspan' => '4')); $oElm->setLabel('Competência Inicial:'); $oElm->setAttrib('class', 'span2'); $oElm->setAttrib('placeholder', 'Dia/Mês/Ano'); $oElm->addValidator(new Zend_Validate_StringLength(array('min' => 10, 'max' => 10))); $oElm->addValidator(new Zend_Validate_Date(array('format' => 'dd/MM/yyyy'))); $oElm->setRequired(TRUE); $oElm->removeDecorator('errors'); $this->addElement($oElm); $oElm = $this->createElement('text', 'data_nota_final', array('divspan' => '4')); $oElm->setLabel('Competência Final:'); $oElm->setAttrib('class', 'span2'); $oElm->setAttrib('placeholder', 'Dia/Mês/Ano'); $oElm->addValidator(new Zend_Validate_StringLength(array('min' => 10, 'max' => 10))); $oElm->addValidator(new Zend_Validate_Date(array('format' => 'dd/MM/yyyy'))); $oElm->setRequired(TRUE); $oElm->removeDecorator('errors'); $this->addElement($oElm); $oElm = $this->createElement('select', 'natureza_operacao', array('divspan' => '4', 'multioptions' => array('' => 'Todos', 1 => 'Tributação no Município', 2 => 'Tributação Fora do Município'))); $oElm->setLabel('Natureza da Operação:'); $oElm->setAttrib('class', 'span2'); $oElm->setRequired(FALSE); $oElm->removeDecorator('errors'); $this->addElement($oElm); $oElm = $this->createElement('select', 's_dados_iss_retido', array('divspan' => '4', 'multioptions' => array('' => 'Todos', 1 => 'Sim', 2 => 'Não'))); $oElm->setLabel('Subst. Tributário (Retido):'); $oElm->setAttrib('class', 'span2'); $oElm->setRequired(FALSE); $oElm->removeDecorator('errors'); $this->addElement($oElm); $oElm = $this->createElement('submit', 'btn_gerar', array('divspan' => 10, 'label' => 'Gerar Relatório', 'class' => 'span2', 'msg-loading' => 'Aguarde...', 'buttonType' => Twitter_Bootstrap_Form_Element_Button::BUTTON_PRIMARY)); $this->addElement($oElm); // Lista de elementos do formulário $aElementos = array('data_nota_inicial', 'data_nota_final', 'natureza_operacao', 's_dados_iss_retido', 'btn_gerar'); // Seta o grupo de elementos $this->addDisplayGroup($aElementos, "relatorio-nfse-periodo"); return $this; }