function onGerar($param)
 {
     if (!isset($param)) {
         return;
     }
     $key = $param['requisicao'];
     if (!isset($key) || !$key) {
         return;
     }
     try {
         TTransaction::open('saciq');
         $gerarArquivo = new Exportar();
         $gerarArquivo->loadRequisicao($key);
         $nome = "planilha_requisicao" . date("d-m-Y_H-i-s");
         $gerarArquivo->createfile($nome);
         //echo ('<a href="'.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'] . '/' . $_SERVER['CONTEXT_PREFIX'] . '/app/output/' . $nome .'.xlsx">DOWNLOAD</a>');
         //download nova pagina
         //TScript::create(' window.open("'. $_SERVER['CONTEXT_PREFIX'] .'/app/output/' . $nome .'.xlsx", "_blank"); ');
         parent::openFile('app/output/' . $nome . '.xlsx');
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
         return;
     }
 }
示例#2
0
 /**
  * method onGenerate()
  * Executed whenever the user clicks at the generate button
  */
 function onGenerate()
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT("c:\\array\\LOG" . date("Ymd-His") . ".txt"));
         // get the form data into an active record
         $formdata = $this->form->getData();
         $validadeI = $formdata->validadeI;
         $validadeF = TDate::date2us($formdata->validadeF);
         if (!$validadeI === 0) {
             $validadeI = '0';
         } else {
             $validadeI = TDate::date2us($validadeI);
         }
         $this->form->validate();
         $repository = new TRepository('Srp');
         $criteria = new TCriteria();
         $param['order'] = 'id';
         $param['direction'] = 'desc';
         $criteria->setProperties($param);
         if ($formdata->numeroProcessoI != '' && $formdata->numeroProcessoF != '') {
             $criteria->add(new TFilter('numeroProcesso', 'BETWEEN', "{$formdata->numeroProcessoI}", "{$formdata->numeroProcessoF}"));
         }
         if ($formdata->validadeI != '' && $formdata->validadeF != '') {
             $criteria->add(new TFilter('validade', 'between', "{$validadeI}", "{$validadeF}"));
         }
         if ($formdata->numeroSRPI != '' && $formdata->numeroSRPF != '') {
             $criteria->add(new TFilter('numeroSRP', 'between', "{$formdata->numeroSRPI}", "{$formdata->numeroSRPF}"));
         }
         if ($formdata->numeroIRPI != '' && $formdata->numeroIRPF != '') {
             $criteria->add(new TFilter('numeroIRP', 'between', "{$formdata->numeroIRPI}", "{$formdata->numeroIRPF}"));
         }
         $imprimeZero = true;
         if (isset($formdata->itensZero)) {
             if ($formdata->itensZero === '0') {
                 $imprimeZero = false;
             }
         }
         $srps = $repository->load($criteria, true);
         if ($srps) {
             $this->pdf = new FPDF();
             $this->pdf->AliasNbPages();
             $this->pdf->SetMargins(10, 10, 10);
             $this->pdf->setHeaderCallback(array($this, 'header'));
             $this->pdf->setFooterCallback(array($this, 'footer'));
             $this->pdf->AddPage();
             foreach ($srps as $srp) {
                 $this->data = $srp;
                 $this->srpHeader($imprimeZero);
                 $this->srpItens($imprimeZero);
             }
             if (!file_exists("app/output/RelatorioSrp.pdf") or is_writable("app/output/RelatorioSrp.pdf")) {
                 $this->pdf->Output("app/output/RelatorioSrp.pdf");
             } else {
                 throw new Exception('Permissão negada' . ': ' . "app/output/RelatorioSrp.pdf");
             }
             parent::openFile("app/output/RelatorioSrp.pdf");
             //new TMessage('info', 'Relatório gerado. Por favor, habilite o pop-up do seu browser.');
         } else {
             new TMessage('error', 'Nenhum registro encontrado');
         }
         // fill the form with the active record data
         $this->form->setData($formdata);
         // close the transaction
         TTransaction::close();
     } catch (Exception $e) {
         // in case of exception
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#3
0
 public function onGenerate($param)
 {
     //var_dump($param);
     $this->B = 0;
     $this->I = 0;
     $this->U = 0;
     $this->HREF = '';
     $data = $this->form->getData();
     $id = $data->cessao_id;
     $this->pdf = new FPDF();
     $this->pdf->AliasNbPages();
     setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
     try {
         TTransaction::open('saciq');
         $this->form->validate();
         $cessao = new Cessao($id);
         $itens_list = $cessao->getItems();
         if (count($itens_list) == 0) {
             new TMessage('error', 'Nenhum item encontrado na cessão');
             $this->form->sendData('doc_cessao_form', $data);
             return;
         }
         $memorando = utf8_decode($data->memorando);
         $emissao = TDate::date2us($data->emissao);
         $repository = new TRepository('Campus');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('sigla', '=', CAMPUS));
         $campus_list = $repository->load($criteria);
         $campus = $campus_list[0];
         $this->cidade = $campus->nome;
         $destino = strtoupper($data->campusNome);
         $this->gerente = $data->gerente;
         $this->diretor = $data->diretor;
         $emissao = strtotime($emissao);
         $mes = ucfirst(strftime('%B', $emissao));
         $emissao = $this->cidade . ', ' . strftime(" %d de {$mes} de %Y.", $emissao);
         $srp = $cessao->srp->numeroSRP;
         $natureza = $cessao->srp->natureza->descricao;
         $nomeSrp = $cessao->srp->nome;
         //$this->pdf->Open();
         $this->pdf->SetMargins(25, 20, 25);
         $this->pdf->setHeaderCallback(array($this, 'Header'));
         //$this->pdf->setFooterCallback(array($this, 'Footer'));
         $this->pdf->AddPage();
         $this->pdf->SetFont('Times', '', 12);
         //$this->pdf->Cell(15);
         $this->pdf->Cell(0, 5, "{$memorando}", 0, 1);
         $this->pdf->Ln(10);
         $this->pdf->Cell(0, 5, $emissao, 0, 0, 'R');
         $this->pdf->Ln(10);
         $this->pdf->Cell(0, 5, utf8_decode('À'), 0, 1);
         $this->pdf->Cell(0, 5, utf8_decode("GERÊNCIA ADMINISTRATIVA DO CAMPUS {$destino}"));
         $this->pdf->Ln(10);
         $this->pdf->SetFont('Times', 'B', 12);
         $this->pdf->MultiCell(0, 5, utf8_decode("ASSUNTO: CESSÃO DE QUANTITATIVO - SRP {$srp} - {$natureza} - {$nomeSrp}"));
         $this->pdf->SetFont('Times', '', 12);
         $this->pdf->Ln(15);
         $this->pdf->SetX(21);
         $this->WriteHTML(utf8_decode("1.Conforme solicitação, autorizamos a utilização do quantitativo abaixo referido," . "referente a estimativa do Câmpus Capivari para a <B>SRP {$srp} - {$natureza} - {$nomeSrp}</B>"));
         $this->pdf->Ln(10);
         //cabecalho da tabela
         $y = $this->pdf->GetY();
         $x = $this->pdf->GetX();
         $this->pdf->SetFont('Times', 'B', 12);
         $width = array(18, 107, 38);
         $this->pdf->MultiCell($width[0], 10, utf8_decode('ITEM'), 1, 'C');
         $this->pdf->SetXY($x += $width[0], $y);
         $this->pdf->MultiCell($width[1], 10, utf8_decode("DESCRIÇÃO"), 1, 'C');
         $this->pdf->SetXY($x += $width[1], $y);
         $this->pdf->MultiCell($width[2], 10, utf8_decode('QUANT.'), 1, 'C');
         $this->pdf->SetFont('Times', '', 12);
         $this->pdf->ln(0);
         $y = $this->pdf->GetY();
         $x = $this->pdf->GetX();
         usort($itens_list, array("DocCessaoForm", "cmp"));
         //preencher a tabela
         foreach ($itens_list as $item) {
             $numeroItem = $item->numeroItem;
             $descricaoSumaria = substr($item->descricaoSumaria, 0, 80);
             $quantidade = $item->quantidade;
             $t1 = $this->pdf->GetStringWidth($descricaoSumaria);
             $tamanhoTexto = $t1;
             $tamanhoDesc = $width[1];
             $qtdLinha = 1;
             $offset = 0;
             $atualSize = 0;
             while (true) {
                 $pos = strpos($descricaoSumaria, ' ', $offset);
                 if ($pos === FALSE) {
                     while ($tamanhoTexto > $tamanhoDesc) {
                         $qtdLinha++;
                         $tamanhoTexto -= $tamanhoDesc;
                     }
                     break;
                 }
                 $textCompare = substr($descricaoSumaria, $offset, $pos - $offset);
                 $textSize = $this->pdf->GetStringWidth($textCompare . ' ');
                 if ($textSize + $atualSize > $tamanhoDesc) {
                     $qtdLinha++;
                     $tamanhoTexto -= $atualSize;
                     $atualSize = 0;
                 } else {
                     $atualSize += $textSize;
                     $offset = $pos + 1;
                 }
             }
             if ($qtdLinha == 1) {
                 $qtdLinha = 2;
             }
             $alturaLinha = 5 * $qtdLinha;
             if ($this->pdf->GetY() + $alturaLinha > 280) {
                 $this->pdf->Cell(array_sum($width), 0, '', 'T');
                 $this->pdf->AddPage();
                 $y = $this->pdf->GetY();
                 $x = $this->pdf->GetX();
             }
             $this->pdf->MultiCell($width[0], $alturaLinha, utf8_decode($numeroItem), 'LRT', 'C');
             $this->pdf->SetXY($x += $width[0], $y);
             $this->pdf->MultiCell($width[1], 5, utf8_decode($descricaoSumaria), 'LRT', 'J');
             $this->pdf->SetXY($x += $width[1], $y);
             $this->pdf->MultiCell($width[2], $alturaLinha, utf8_decode($quantidade), 'LRT', 'C');
             $this->pdf->Ln(0);
             $y = $this->pdf->GetY();
             $x = $this->pdf->GetX();
         }
         $this->pdf->Cell(array_sum($width), 0, '', 'T');
         if ($this->pdf->GetY() + $alturaLinha > 210) {
             $this->pdf->AddPage();
             $this->ImprimiNoRodape = false;
         } else {
             $this->ImprimiNoRodape = true;
         }
         $this->Footer();
         if (!file_exists("app/output/doc.pdf") or is_writable("app/output/doc.pdf")) {
             $this->pdf->Output("app/output/doc.pdf");
         } else {
             throw new Exception('Permissão negada' . ': ' . "app/output/doc.pdf");
         }
         parent::openFile('app/output/doc.pdf');
         $this->form->sendData('doc_cessao_form', $data);
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }