public function onGenerate()
    {
        try {
            TTransaction::open('atividade');
            $object = $this->form->getData();
            $desenvolvimento = new RequisitoDesenvolvimento(1);
            $cliente_id = $desenvolvimento->ticket->solicitante_id;
            $responsavel_id = $desenvolvimento->ticket->responsavel_id;
            $pessoa = new Pessoa($cliente_id);
            $cliente = $pessoa->pessoa_nome;
            $pessoa = new Pessoa($responsavel_id);
            $responsavel = $pessoa->pessoa_nome;
            if (!class_exists('PHPRtfLite_Autoloader')) {
                PHPRtfLite::registerAutoloader();
            }
            $tr = new TTableWriterRTF(array(500));
            $tr->addStyle('title', 'Arial', '10', 'BI', '#000000', '#ffffff');
            $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#ffffff');
            $string = new StringsUtil();
            $data = $desenvolvimento->data_cadastro;
            $data = explode('-', $data);
            $desenvolvimento->ticket->data_prevista ? $data_prevista = $string->formatDateBR($desenvolvimento->ticket->data_prevista) : '___/___/___';
            $cabecalho = 'DTR010 - Solicitação de Desenvolvimento
Número: ' . $desenvolvimento->id . '/' . $data[0] . ' Data: ' . $string->formatDateBR($desenvolvimento->data_cadastro) . ' Prazo de entrega: ' . $data_prevista . ' Qtde de Horas: ' . strstr($desenvolvimento->ticket->orcamento_horas, ':', true) . ' Ticket: ' . $desenvolvimento->ticket_id . '
Benefício: ( )+Receita ( )-Despesa ( )+Eficiência ( )-NDA
Título: ' . $desenvolvimento->titulo . '
Sistema: ' . $desenvolvimento->ticket->sistema->nome . '      Módulo:                                   Rotina: ' . $desenvolvimento->rotina . '
Cliente: ' . $cliente . ' Solicitante/Dpto: ' . $responsavel;
            $tr->addRow();
            $tr->addCell($cabecalho, 'left', 'title');
            $tr->addRow();
            $tr->addCell('<br /><b>Objetivo:</b> <br />' . $desenvolvimento->objetivo, 'left', 'datap');
            $tr->addRow();
            $tr->addCell('<br /><b>Entrada: </b><br />' . $desenvolvimento->entrada, 'left', 'datap');
            $tr->addRow();
            $tr->addCell('<br /><b>Processamento: </b><br />' . $desenvolvimento->processamento, 'left', 'datap');
            $tr->addRow();
            $tr->addCell('<br /><b>Saida: </b><br />' . $desenvolvimento->saida, 'left', 'datap');
            $nome = 'DTR010 ' . $desenvolvimento->id . ' - ' . $data[0] . ' - ' . $desenvolvimento->titulo;
            $tr->save("app/output/{$nome}.rtf");
            parent::openFile("app/output/{$nome}.rtf");
            new TMessage('info', 'DTR gerado com sucesso!');
            TTransaction::close();
        } catch (Exception $e) {
            new TMessage('error', $e->getMessage);
        }
    }
Esempio n. 2
0
 public function saldoHorasMes($user)
 {
     $string = new StringsUtil();
     $mes = date('m');
     $ano = date('Y');
     $conn = TTransaction::get();
     $result = $conn->query("select (hora_saida - hora_entrada) as horario from ponto \n                                where colaborador_id = {$user} and extract('month' from data_ponto) = {$mes} and extract('year' from data_ponto) = {$ano} and hora_saida is not null and hora_entrada is not null");
     $almoco = new DateTime('01:00:00');
     $limite = new DateTime('06:00:00');
     $cargaHoraria = $string->time_to_sec('08:48:00');
     $saldo = null;
     foreach ($result as $row) {
         $total = new DateTime($row['horario']);
         if ($total > $limite) {
             $total = $total->diff($almoco)->format('%H:%I:%S');
         } else {
             $total = $row['horario'];
         }
         $saldo += $string->time_to_sec($total) - $cargaHoraria;
     }
     return $string->sec_to_time($saldo);
 }
 public static function onChangeDataAction($param)
 {
     $string = new StringsUtil();
     $data1 = date('Y-m-d');
     $data2 = $string->formatDate($param['data_ponto']);
     if (strtotime($data2) > strtotime($data1)) {
         new TMessage('error', 'Data do ponto maior que a data atual!');
         TButton::disableField('form_Ponto', 'salvar');
     } else {
         $dataLimite = date('Y-m-d', strtotime("-5 days"));
         if (strtotime($dataLimite) > strtotime($data2)) {
             new TMessage('error', 'Data do ponto menor que data limite permitida [' . $string->formatDateBR($dataLimite) . ']');
             TButton::disableField('form_Ponto', 'salvar');
         } else {
             try {
                 TTransaction::open('atividade');
                 $ultimoPonto = Ponto::retornaUltimoPonto($param['colaborador_id']);
                 $ponto = new Ponto($ultimoPonto);
                 if (strtotime($ponto->data_ponto) >= strtotime($data2)) {
                     new TMessage('error', 'Existe data posterior ou igual cadastrada!');
                     TButton::disableField('form_Ponto', 'salvar');
                 } else {
                     //verificar se a data ta fechada
                     if ($ponto->hora_saida) {
                         TButton::enableField('form_Ponto', 'salvar');
                     } else {
                         new TMessage('error', 'Ponto anterior não encerrado!');
                         TButton::disableField('form_Ponto', 'salvar');
                     }
                 }
                 TTransaction::close();
             } catch (Exception $e) {
                 new TMessage('error', '<b>Error</b> ' . $e->getMessage());
             }
         }
     }
 }
 /**
  * method onGenerate()
  * Executed whenever the user clicks at the generate button
  */
 function onGenerate()
 {
     try {
         // open a transaction with database 'atividade'
         TTransaction::open('atividade');
         $string = new StringsUtil();
         // get the form data into an active record
         $formdata = $this->form->getData();
         $repository = new TRepository('RegistroLogin');
         $criteria = new TCriteria();
         if ($formdata->login) {
             $criteria->add(new TFilter('login', '=', "{$formdata->login}"));
         }
         if ($formdata->data_ponto) {
             $criteria->add(new TFilter('data_ponto', '>=', "{$string->formatDate($formdata->data_ponto)}"));
         }
         $newparam['order'] = 'data_ponto';
         $newparam['direction'] = 'desc';
         $criteria->setProperties($newparam);
         // order, offset
         $objects = $repository->load($criteria);
         $format = $formdata->output_type;
         if ($objects) {
             $widths = array(20, 200, 50, 80, 80);
             switch ($format) {
                 case 'html':
                     $tr = new TTableWriterHTML($widths);
                     break;
                 case 'pdf':
                     $tr = new TTableWriterPDF($widths);
                     break;
                 case 'rtf':
                     if (!class_exists('PHPRtfLite_Autoloader')) {
                         PHPRtfLite::registerAutoloader();
                     }
                     $tr = new TTableWriterRTF($widths);
                     break;
             }
             // create the document styles
             $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#6B6B6B');
             $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#E5E5E5');
             $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
             $tr->addStyle('header', 'Times', '16', 'B', '#4A5590', '#C0D3E9');
             $tr->addStyle('footer', 'Times', '12', 'BI', '#4A5590', '#C0D3E9');
             // add a header row
             $tr->addRow();
             $tr->addCell('Registro de acessos ao sistema', 'center', 'header', 5);
             // add titles row
             $tr->addRow();
             $tr->addCell('Seq.', 'center', 'title');
             $tr->addCell('Nome', 'center', 'title');
             $tr->addCell('Data', 'center', 'title');
             $tr->addCell('Hora inicial', 'center', 'title');
             $tr->addCell('Hora final', 'center', 'title');
             // controls the background filling
             $colour = FALSE;
             $seq = 1;
             // data rows
             foreach ($objects as $object) {
                 $style = $colour ? 'datap' : 'datai';
                 $tr->addRow();
                 $tr->addCell($seq++, 'right', $style);
                 $tr->addCell($object->name, 'left', $style);
                 $tr->addCell($string->formatDateBR($object->data_ponto), 'center', $style);
                 $tr->addCell($object->hora_inicial, 'center', $style);
                 $tr->addCell($object->hora_final, 'center', $style);
                 $colour = !$colour;
             }
             // footer row
             $tr->addRow();
             $tr->addCell(date('d/m/Y h:i:s'), 'center', 'footer', 5);
             // stores the file
             if (!file_exists("app/output/RegistroLogin.{$format}") or is_writable("app/output/RegistroLogin.{$format}")) {
                 $tr->save("app/output/RegistroLogin.{$format}");
             } else {
                 throw new Exception(_t('Permission denied') . ': ' . "app/output/RegistroLogin.{$format}");
             }
             // open the report file
             parent::openFile("app/output/RegistroLogin.{$format}");
             // shows the success message
             new TMessage('info', 'Relatorio gerado. Por favor, habilite popups no navegador (somente para web).');
         } else {
             new TMessage('error', 'No records found');
         }
         // fill the form with the active record data
         $this->form->setData($formdata);
         // close the transaction
         TTransaction::close();
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * method onGenerate()
  * Executed whenever the user clicks at the generate button
  */
 function onGenerate()
 {
     try {
         $string = new StringsUtil();
         TTransaction::open('atividade');
         // open a transaction with database 'atividade'
         // get the form data into an active record
         $formdata = $this->form->getData();
         if ($formdata->ticket_id) {
             $where .= " and t.id >= {$formdata->ticket_id} ";
         }
         if ($formdata->solicitante_id) {
             $where .= " and t.solicitante_id = {$formdata->solicitante_id} ";
         }
         if ($formdata->responsavel_id) {
             $where .= " and t.responsavel_id = {$formdata->responsavel_id} ";
         }
         if ($formdata->entcodent) {
             $solicitantes = Pessoa::getPessoasEntidade($formdata->entcodent);
             $comma_separated = implode(",", $solicitantes);
             $where .= " and t.solicitante_id in ( {$comma_separated} )";
         }
         if ($formdata->status_ticket_id) {
             $where .= " and t.status_ticket_id = {$formdata->status_ticket_id} ";
         }
         if ($formdata->prioridade_id) {
             $where .= " and t.prioridade_id = {$formdata->prioridade_id} ";
         }
         if ($formdata->data_prevista) {
             $where .= " and t.data_prevista <= '{$string->formatDate($formdata->data_prevista)}' ";
         }
         if ($formdata->data_atividade_inicio) {
             $where .= " and a.data_atividade >= '{$string->formatDate($formdata->data_atividade_inicio)}' ";
         }
         if ($formdata->data_atividade_final) {
             $where .= " and a.data_atividade <= '{$string->formatDate($formdata->data_atividade_final)}' ";
         }
         if ($formdata->colaborador_id) {
             $where .= " and a.colaborador_id = {$formdata->colaborador_id} ";
         }
         if ($formdata->tipo_atividade_id) {
             $where .= " and a.tipo_atividade_id = {$formdata->tipo_atividade_id} ";
         }
         if ($formdata->saldo) {
             $where .= " and (coalesce(t.valor_total,0) - coalesce(t.valor_total_pago,0)) > 0 ";
         }
         if ($formdata->ticket_sistema_id) {
             $where .= " and t.sistema_id = {$formdata->ticket_sistema_id} ";
         }
         if ($formdata->atividade_sistema_id) {
             $where .= " and a.sistema_id = {$formdata->atividade_sistema_id} ";
         }
         if ($formdata->tipo_ticket_id) {
             $where .= " and t.tipo_ticket_id = {$formdata->tipo_ticket_id} ";
         }
         if ($formdata->pesquisa_master) {
             $where .= " and (t.titulo ilike '%{$formdata->pesquisa_master}%' or a.descricao ilike '%{$formdata->pesquisa_master}%') ";
         }
         //  and (t.titulo ilike %{$formdata->pesquisa_master}% or a.descricao ilike %{$formdata->pesquisa_master}%)
         $format = $formdata->output_type;
         $objects = Ticket::relatorioSintetico($where);
         if ($objects) {
             $widths = null;
             switch ($format) {
                 case 'html':
                     $tr = new TTableWriterHTML($widths);
                     break;
                 case 'pdf':
                     $tr = new TTableWriterPDF($widths, 'L');
                     break;
                 case 'rtf':
                     if (!class_exists('PHPRtfLite_Autoloader')) {
                         PHPRtfLite::registerAutoloader();
                     }
                     $tr = new TTableWriterRTF($widths);
                     break;
             }
             // create the document styles
             $tr->addStyle('title', 'Arial', '12', 'B', '#ffffff', '#6B6B6B');
             $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#E5E5E5');
             $tr->addStyle('datapa', 'Arial', '9', '', '#000000', '#E5E5E5');
             $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
             $tr->addStyle('dataia', 'Arial', '9', '', '#000000', '#ffffff');
             $tr->addStyle('header', 'Times', '16', 'B', '#4A5590', '#C0D3E9');
             $tr->addStyle('footer', 'Times', '12', 'BI', '#4A5590', '#C0D3E9');
             $tr->addStyle('valpos', 'Arial', '12', '', '#000000', '#0DC13A');
             $tr->addStyle('valneg', 'Arial', '12', '', '#000000', '#FF0000');
             // add a header row
             $tr->addRow();
             $tr->addCell('Ticket - Resumo atividades', 'center', 'header', 16);
             // add titles row
             $tr->addRow();
             $tr->addCell('Seq', 'center', 'title');
             $tr->addCell('ID', 'center', 'title');
             $tr->addCell('ST', 'center', 'title');
             $tr->addCell('PR', 'center', 'title');
             $tr->addCell('H.O.', 'center', 'title');
             $tr->addCell('H.A.', 'center', 'title');
             $tr->addCell('H.S.', 'center', 'title');
             $tr->addCell('Prevista', 'center', 'title');
             $tr->addCell('Dias', 'center', 'title');
             $tr->addCell(utf8_decode('Título'), 'left', 'title');
             $tr->addCell(utf8_decode('Responsável'), 'left', 'title');
             $tr->addCell('T', 'center', 'title');
             $tr->addCell('Cliente', 'left', 'title');
             $tr->addCell(utf8_decode('Orçado'), 'right', 'title');
             $tr->addCell('Pago', 'right', 'title');
             $tr->addCell('Saldo', 'right', 'title');
             // controls the background filling
             $colour = FALSE;
             $repository = new TRepository('Pessoa');
             $repo = $repository->load();
             foreach ($repo as $row) {
                 $pessoa[$row->pessoa_codigo] = $row->pessoa_nome;
             }
             $seq = 1;
             $totalOrcado = 0;
             $totalPago = 0;
             $totalSaldo = 0;
             $totalHorasOrcadas = 0;
             $totalHorasAtividades = 0;
             $totalHorasSaldo = 0;
             // data rows
             foreach ($objects as $object) {
                 //$responsavel = new Pessoa($object['responsavel_id']);
                 $cliente = new Pessoa($object['solicitante_id']);
                 $style = $colour ? 'datap' : 'datai';
                 $horasStyle = $style;
                 $dias = '';
                 $dataStyle = $style;
                 if ($object['orcamento_horas']) {
                     if (substr($object['horas_saldo'], 0, 1) == '-') {
                         $horasStyle = 'valneg';
                     } else {
                         $horasStyle = 'valpos';
                     }
                 }
                 if ($object['data_prevista']) {
                     $dias = $string->subtrair_datas(date('Y-m-d'), $object['data_prevista']);
                     if (substr($dias, 0, 1) == '-') {
                         $dataStyle = 'valneg';
                     } else {
                         $dataStyle = 'valpos';
                     }
                 }
                 $tr->addRow();
                 $tr->addCell($seq++, 'center', $style);
                 $tr->addCell($object['id'], 'center', $style);
                 $tr->addCell(substr($object['status'], 0, 1), 'center', $style);
                 $tr->addCell(substr($object['prioridade'], 0, 1), 'center', $style);
                 $tr->addCell(substr($object['orcamento_horas'], 0, -3), 'center', $style);
                 $tr->addCell(substr($object['horas_atividade'], 0, -3), 'center', $style);
                 $tr->addCell(substr($object['horas_saldo'], 0, -3), 'center', $horasStyle);
                 $tr->addCell($object['data_prevista'] ? $data_prevista = $string->formatDateBR($object['data_prevista']) : null, 'center', $style);
                 $tr->addCell($dias, 'center', $dataStyle);
                 $tr->addCell(utf8_decode($object['titulo']), 'left', $style);
                 $tr->addCell(utf8_decode($pessoa[$object['responsavel_id']]), 'left', $style);
                 $tr->addCell($object['origem'], 'center', $style);
                 $tr->addCell(utf8_decode($cliente->origem_nome), 'left', $style);
                 $tr->addCell($object['valor_total'], 'right', $style);
                 $tr->addCell($object['valor_total_pago'], 'right', $style);
                 $tr->addCell($object['saldo'], 'right', $style);
                 $totalDias += $dias;
                 $totalOrcado += $object['valor_total'];
                 $totalPago += $object['valor_total_pago'];
                 $totalSaldo += $object['saldo'];
                 $totalHorasOrcadas += $string->time_to_sec($object['orcamento_horas']);
                 $totalHorasAtividades += $string->time_to_sec($object['horas_atividade']);
                 $totalHorasSaldo += $string->time_to_sec($object['horas_saldo']);
                 if ($formdata->tipo == 'a') {
                     $atividades = Ticket::relatorioAnalitico($object['id'], $where);
                     if ($atividades) {
                         $seqA = 1;
                         foreach ($atividades as $atividade) {
                             $stylea = $colour ? 'datapa' : 'dataia';
                             $tr->addRow();
                             $tr->addCell('', 'center', $stylea);
                             $tr->addCell($seqA++, 'center', $stylea);
                             $tr->addCell($string->formatDateBR($atividade['data_atividade']), 'center', $stylea, 3);
                             //$tr->addCell(substr($object['prioridade'], 0, 1), 'center', $style);
                             //$tr->addCell($object['orcamento_horas'], 'center', $style);
                             $tr->addCell(substr($atividade['tempo'], 0, -3), 'center', $stylea);
                             $tr->addCell('', 'center', $stylea);
                             $tr->addCell($object['data_prevista'] ? $data_prevista = $string->formatDateBR($object['data_prevista']) : null, 'center', $stylea);
                             $tr->addCell('', 'center', $stylea);
                             $tr->addCell('das ' . substr($atividade['hora_inicio'], 0, -3) . ' as ' . substr($atividade['hora_fim'], 0, -3), 'left', $stylea);
                             $tr->addCell(utf8_decode($pessoa[$atividade['colaborador_id']]), 'left', $stylea);
                             $tr->addCell('', 'center', $stylea);
                             $tr->addCell(utf8_decode($atividade['tipo_atividade']), 'left', $stylea);
                             $tr->addCell('', 'right', $stylea);
                             $tr->addCell('', 'right', $stylea);
                             $tr->addCell('', 'right', $stylea);
                         }
                     }
                 }
                 $tr->addRow();
                 $tr->addCell('&nbsp; ', 'center', $style, 16);
                 $colour = !$colour;
             }
             // footer row
             $tr->addRow();
             $tr->addCell('Totais:', 'center', 'footer', 4);
             //$tr->addCell('', 'center', 'footer');
             //$tr->addCell('', 'center', 'footer');
             //$tr->addCell('', 'center', 'footer');
             $tr->addCell(substr($string->sec_to_time($totalHorasOrcadas), 0, -3), 'center', 'footer');
             $tr->addCell(substr($string->sec_to_time($totalHorasAtividades), 0, -3), 'center', 'footer');
             $tr->addCell(substr($string->sec_to_time($totalHorasSaldo), 0, -3), 'center', 'footer');
             $tr->addCell('', 'center', 'footer');
             $tr->addCell('', 'center', 'footer');
             $tr->addCell('', 'left', 'footer');
             $tr->addCell('', 'left', 'footer');
             $tr->addCell('', 'center', 'footer');
             $tr->addCell('', 'left', 'footer');
             $tr->addCell($totalOrcado, 'right', 'footer');
             $tr->addCell($totalPago, 'right', 'footer');
             $tr->addCell($totalSaldo, 'right', 'footer');
             $tr->addRow();
             $tr->addCell(date('d/m/Y H:i:s'), 'center', 'footer', 16);
             // stores the file
             if (!file_exists("app/output/Ticket.{$format}") or is_writable("app/output/Ticket.{$format}")) {
                 $tr->save("app/output/Ticket.{$format}");
             } else {
                 throw new Exception(_t('Permission denied') . ': ' . "app/output/Ticket.{$format}");
             }
             // open the report file
             parent::openFile("app/output/Ticket.{$format}");
             // shows the success message
             new TMessage('info', 'Relatorio gerado. Por favor, habilite popups no navegador (somente para web).');
         } else {
             new TMessage('error', 'Não foram encontrados registros!');
         }
         // fill the form with the active record data
         $this->form->setData($formdata);
         // close the transaction
         TTransaction::close();
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 function onEdit($param)
 {
     $string = new StringsUtil();
     try {
         TTransaction::open('atividade');
         // open a transaction
         $logado = Pessoa::retornaUsuario();
         if (isset($param['key'])) {
             $key = $param['key'];
             // get the parameter $key
             $atividade = new Atividade($key);
             $criteria = new TCriteria();
             $newparam['order'] = 'id';
             $newparam['direction'] = 'asc';
             $criteria->setProperties($newparam);
             // order, offset
             $this->onComboTicket($criteria);
             $this->onSetarValoresCombo($atividade->ticket_id);
             // criar metodo de preenchimento de horas
             $HoraEntrada = new DateTime($atividade->hora_inicio);
             $HoraSaida = new DateTime($atividade->hora_fim);
             $diffHoras = $HoraSaida->diff($HoraEntrada)->format('%H:%I:%S');
             $horas = explode(':', $atividade->hora_fim);
             $atividade->qtde_horas = $horas[0];
             $atividade->qtde_minutos = $horas[1];
             TCombo::disableField('form_Atividade', 'qtde_horas');
             TCombo::disableField('form_Atividade', 'qtde_minutos');
             $atividade->tempo_atividade = $diffHoras;
             $ultimaAtividade = Atividade::retornaUltimaAtividade($atividade->colaborador_id);
             if (!$ultimaAtividade) {
                 $action = new TAction(array('AtividadeList', 'onReload'));
                 new TMessage('info', 'Nenhuma atividade cadastrada!', $action);
                 // success message
             }
             if ($key != $ultimaAtividade) {
                 TButton::disableField('form_Atividade', 'delete');
             }
             $atividade->data_atividade ? $atividade->data_atividade = $string->formatDateBR($atividade->data_atividade) : null;
             $colaborador = new Pessoa($atividade->colaborador_id);
             $atividade->colaborador_nome = $colaborador->pessoa_nome;
             if ($logado->pessoa_codigo != $atividade->colaborador_id) {
                 TButton::disableField('form_Atividade', 'save');
                 TButton::disableField('form_Atividade', 'delete');
             }
             TButton::disableField('form_Atividade', 'atividade');
             $this->form->setData($atividade);
             // fill the form
         } else {
             $object = new Atividade();
             $object->colaborador_id = $logado->pessoa_codigo;
             $object->colaborador_nome = $logado->pessoa_nome;
             $this->form->setData($object);
         }
         TTransaction::close();
         // close the transaction
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         TTransaction::rollback();
         // undo all pending operations
     }
 }
 public static function onChangeData($param)
 {
     $obj = new StdClass();
     $string = new StringsUtil();
     if (strlen($param['data_atividade_inicial']) == 10 && strlen($param['data_atividade_final']) == 10) {
         if (strtotime($string->formatDate($param['data_atividade_final'])) < strtotime($string->formatDate($param['data_atividade_inicial']))) {
             $obj->data_atividade_final = '';
             new TMessage('error', 'Data de atividade final menor que data de atividade inicial');
         }
     }
     TForm::sendData('form_search_Atividade', $obj, FALSE, FALSE);
 }
 public static function onChangeData($param)
 {
     $obj = new StdClass();
     $string = new StringsUtil();
     if (strlen($param['data_inicial']) == 10 && strlen($param['data_final']) == 10) {
         if (strtotime($string->formatDate($param['data_final'])) < strtotime($string->formatDate($param['data_inicial']))) {
             $obj->data_final = '';
             new TMessage('error', 'Data de cadastro final menor que data inicial');
         } else {
             // Start date
             $date = $string->formatDate($param['data_inicial']);
             // End date
             $end_date = $string->formatDate($param['data_final']);
             while (strtotime($date) <= strtotime($end_date)) {
                 if (date("w", strtotime($date)) == 0 or date("w", strtotime($date)) == 6) {
                     $obj->data_final = '';
                     new TMessage('error', 'Existe final de semana no periodo informado');
                     break;
                 }
                 $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
             }
         }
     }
     TForm::sendData('form_Atividade', $obj, FALSE, FALSE);
 }
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 function onEdit($param)
 {
     $string = new StringsUtil();
     try {
         TTransaction::open('atividade');
         // open a transaction
         if (isset($param['key'])) {
             $key = $param['key'];
             // get the parameter $key
             $object = new Ticket($key);
             // instantiates the Active Record
             $dtrs = $object->getRequisitoDesenvolvimentos();
             foreach ($dtrs as $dtr) {
                 $object->nome_dtr = $dtr->titulo;
             }
             if ($object->nome_dtr) {
                 TButton::disableField('form_Ticket', 'gerar_dr');
                 TButton::enableField('form_Ticket', 'link_dtr');
             }
             if ($object->tipo_ticket_id == 4 or $object->tipo_ticket_id == 5 or $object->tipo_ticket_id == 6) {
                 if (!$object->nome_dtr) {
                     TButton::enableField('form_Ticket', 'gerar_dr');
                 }
             }
             TButton::disableField('form_Ticket', 'delete');
             if ($object->status_ticket_id == 2 and !$object->data_aprovacao and !$object->getAtividades()) {
                 TButton::enableField('form_Ticket', 'delete');
             }
             if ($object->status_ticket_id == 5) {
                 TDate::disableField('form_Ticket', 'data_inicio');
                 TDate::disableField('form_Ticket', 'data_encerramento');
                 TDate::disableField('form_Ticket', 'data_cancelamento');
             }
             $object->data_cadastro ? $object->data_cadastro = $string->formatDateBR($object->data_cadastro) : null;
             $object->data_prevista ? $object->data_prevista = $string->formatDateBR($object->data_prevista) : null;
             $object->data_inicio ? $object->data_inicio = $string->formatDateBR($object->data_inicio) : null;
             $object->data_inicio ? $object->data_inicio_oculta = $object->data_inicio : null;
             $object->data_encerramento ? $object->data_encerramento = $string->formatDateBR($object->data_encerramento) : null;
             $object->data_cancelamento ? $object->data_cancelamento = $string->formatDateBR($object->data_cancelamento) : null;
             $object->data_aprovacao ? $object->data_aprovacao = $string->formatDateBR($object->data_aprovacao) : null;
             $object->data_ultimo_pgto ? $object->data_ultimo_pgto = $string->formatDateBR($object->data_ultimo_pgto) : null;
             $saldo = $object->valor_total - $object->valor_total_pago;
             $saldo ? $object->valor_saldo = number_format($saldo, 2, ',', '.') : null;
             $object->orcamento_valor_hora ? $object->orcamento_valor_hora = number_format($object->orcamento_valor_hora, 2, ',', '.') : null;
             $object->valor_desconto ? $object->valor_desconto = number_format($object->valor_desconto, 2, ',', '.') : null;
             $object->valor_total ? $object->valor_total = number_format($object->valor_total, 2, ',', '.') : null;
             $object->valor_ultimo_pgto ? $object->valor_ultimo_pgto = number_format($object->valor_ultimo_pgto, 2, ',', '.') : null;
             $object->valor_total_pago ? $object->valor_total_pago = number_format($object->valor_total_pago, 2, ',', '.') : null;
             $object->orcamento_horas ? $object->orcamento_horas = strstr($object->orcamento_horas, ':', true) : null;
             if ($object->solicitante_id) {
                 $pessoa = new Pessoa($object->solicitante_id);
                 $vars['tipo_origens'] = $pessoa->origem;
                 $vars['codigo_cadastro_origem'] = $pessoa->codigo_cadastro_origem;
                 $vars['solicitante_id'] = $pessoa->pessoa_codigo;
                 $this->onChangeOrigem($vars);
                 $this->onChangeTipoOrigem($vars);
             }
             $this->form->setData($object);
             // fill the form
             $this->onSetarValoresCombo($vars);
         } else {
             $object = new Ticket();
             $object->data_cadastro = date('d/m/Y');
             $this->form->setData($object);
         }
         TTransaction::close();
         // close the transaction
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         TTransaction::rollback();
         // undo all pending operations
     }
 }