/** * 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(); } }
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 { $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(' ', '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 onSave() * Executed whenever the user clicks at the save button */ function onSave() { $string = new StringsUtil(); try { TTransaction::open('atividade'); // open a transaction // get the form data into an active record Atividade $object = $this->form->getData('Atividade'); $object->data_atividade ? $object->data_atividade = $string->formatDate($object->data_atividade) : null; $this->onSetarValoresCombo($object->ticket_id); $this->form->validate(); // form validation $object->store(); // stores the object $object->ticket_id = $arraySwap; $object->data_atividade ? $object->data_atividade = $string->formatDateBR($object->data_atividade) : null; $this->form->setData($object); // keep form data TTransaction::close(); // close the transaction // shows the success message $action = new TAction(array($this, 'onEdit')); new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'), $action); } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message $this->form->setData($this->form->getData()); // keep form data 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 onSave() * Executed whenever the user clicks at the save button */ function onSave() { $string = new StringsUtil(); try { TTransaction::open('atividade'); // open a transaction // get the form data into an active record Ticket $object = $this->form->getData('Ticket'); $validador = new TUltiPgtoValidator(); $validador->validate('Ultimo pagamento', '', array($object->valor_pagamento, $object->data_pagamento)); !$object->data_cadastro ? $object->data_cadastro = date('Y-m-d') : ($object->data_cadastro = $string->formatDate($object->data_cadastro)); $object->data_prevista ? $object->data_prevista = $string->formatDate($object->data_prevista) : null; if ($object->status_ticket_id == 5) { $object->data_inicio = $object->data_inicio_oculta; } $object->data_inicio ? $object->data_inicio = $string->formatDate($object->data_inicio) : null; $object->data_encerramento ? $object->data_encerramento = $string->formatDate($object->data_encerramento) : null; $object->data_cancelamento ? $object->data_cancelamento = $string->formatDate($object->data_cancelamento) : null; $object->data_aprovacao ? $object->data_aprovacao = $string->formatDate($object->data_aprovacao) : null; $object->data_ultimo_pgto ? $object->data_ultimo_pgto = $string->formatDate($object->data_ultimo_pgto) : null; $object->data_pagamento ? $object->data_ultimo_pgto = $string->formatDate($object->data_pagamento) : null; $object->orcamento_horas ? $object->orcamento_horas = $object->orcamento_horas . ':00:00' : null; $object->orcamento_valor_hora ? $object->orcamento_valor_hora = $string->desconverteReais($object->orcamento_valor_hora) : null; $object->valor_desconto ? $object->valor_desconto = $string->desconverteReais($object->valor_desconto) : null; $object->valor_total ? $object->valor_total = $string->desconverteReais($object->valor_total) : null; $object->valor_ultimo_pgto ? $object->valor_ultimo_pgto = $string->desconverteReais($object->valor_ultimo_pgto) : null; $object->valor_total_pago ? $object->valor_total_pago = $string->desconverteReais($object->valor_total_pago) : null; if ($object->valor_pagamento) { $object->valor_ultimo_pgto = $string->desconverteReais($object->valor_pagamento); $object->valor_total_pago += $string->desconverteReais($object->valor_pagamento); } $vars['tipo_origens'] = $object->tipo_origens; $vars['codigo_cadastro_origem'] = $object->codigo_cadastro_origem; $vars['solicitante_id'] = $object->solicitante_id; $this->onChangeOrigem($vars); $this->onChangeTipoOrigem($vars); $this->onSetarValoresCombo($vars); $this->form->validate(); // form validation $object->store(); // stores the object $saldo = $object->valor_total - $object->valor_total_pago; $object->valor_saldo = number_format($saldo, 2, ',', '.'); $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_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; $object->orcamento_horas ? $object->orcamento_horas = strstr($object->orcamento_horas, ':', true) : 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; $ticket = new Ticket($object->id); $dtrs = $ticket->getRequisitoDesenvolvimentos(); foreach ($dtrs as $dtr) { $titulo = $dtr->titulo; } if (!$titulo) { if ($object->tipo_ticket_id == 4 or $object->tipo_ticket_id == 5 or $object->tipo_ticket_id == 6) { TButton::enableField('form_Ticket', 'gerar_dr'); } } else { TButton::enableField('form_Ticket', 'link_dtr'); } TButton::disableField('form_Ticket', 'delete'); if ($object->status_ticket_id == 2 and !$object->data_aprovacao and !$object->getAtividades() and !$object->data_ultimo_pgto) { 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'); } $this->form->setData($object); // keep form data TTransaction::close(); // close the transaction // shows the success message new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message $this->form->setData($this->form->getData()); // keep form data TTransaction::rollback(); // undo all pending operations } }