示例#1
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();
     }
 }
 /**
  * method Delete()
  * Delete a record
  */
 function Delete($param)
 {
     try {
         $key = $param['key'];
         // get the parameter $key
         TTransaction::open('saciq');
         // open a transaction with database
         $object = new Cessao($key, FALSE);
         // instantiates the Active Record
         $object->delete();
         // deletes the object from the database
         TTransaction::close();
         // close the transaction
         $this->onReload($param);
         // reload the listing
         new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));
         // success message
     } 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();
     }
 }
示例#3
0
 public function onSave($param)
 {
     try {
         $this->form_cessao->validate();
         // validate form data
         $form_cessao_data = $this->form_cessao->getData();
         $form_cessao = TSession::getValue('form_cessao');
         $form_cessao->numeroCessao = $form_cessao_data->numeroCessao;
         $form_cessao->campusID = $form_cessao_data->campusID;
         $form_cessao->campusNome = $form_cessao_data->campusNome;
         $form_cessao->emissao = $form_cessao_data->emissao;
         $cessao_itens = TSession::getValue('cessao_itens');
         if (!isset($cessao_itens) || count($cessao_itens) == 0) {
             new TMessage('error', 'Insira ao menos 1 item');
             return;
         }
         TTransaction::open('saciq');
         if ($cessao_itens) {
             $id = isset($form_cessao->id) ? $form_cessao->id : NULL;
             $cessao = new Cessao($id);
             // create a new Sale
             $cessao->clearParts();
             $cessao->numeroCessao = $form_cessao->numeroCessao;
             $cessao->campus = new Campus($form_cessao->campusID);
             $cessao->emissao = TDate::date2us($form_cessao->emissao);
             //if (!$cessao->emissao){
             //    $cessao->emissao = date("Y-m-d");
             //}
             $cessao->aprovado = 0;
             $cessao->srp = new Srp(TSession::getValue('SRP_id'));
             foreach ($cessao_itens as $item) {
                 $item_cessao = new Item($item->item_id);
                 $item_cessao->quantidade = $item->quantidade;
                 $item_cessao->quantidade = str_replace('.', '', $item->quantidade);
                 $item_cessao->quantidade = str_replace(',', '.', $item->quantidade);
                 $cessao->addItem($item_cessao);
                 // add the item to the Sale
             }
             $cessao->store();
             // store the Sale
             TSession::delValue('cessao_itens');
             TSession::delValue('form_cessao');
             TSession::delValue('SRP_id');
             new TMessage('info', 'Cessão salva');
         }
         TTransaction::close();
         $this->onReload();
     } 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());
             }
         }
     }
 }