function onReload($param = NULL) { $offset = $param['offset']; //$order = $param['order']; $limit = 10; // inicia transação com o banco 'pg_livro' TTransaction::open('pg_livro'); // instancia um repositório para Alunos $repository = new TRepository('Pessoa'); // retorna todos objetos que satisfazem o critério $criteria = new TCriteria(); $count = $repository->count($criteria); $criteria->setProperty('limit', $limit); $criteria->setProperty('offset', $offset); $pessoas = $repository->load($criteria); $this->navbar->setPageSize($limit); $this->navbar->setCurrentPage($param['page']); $this->navbar->setTotalRecords($count); $this->datagrid->clear(); if ($pessoas) { foreach ($pessoas as $pessoa) { // adiciona o objeto na DataGrid $this->datagrid->addItem($pessoa); } } // finaliza a transação TTransaction::close(); $this->loaded = true; }
public function __construct() { parent::__construct(); try { TTransaction::open('samples'); $criteria = new TCriteria(); $criteria->add(new TFilter('name', 'like', 'Rafael%'), TExpression::OR_OPERATOR); $criteria->add(new TFilter('name', 'like', 'Ana%'), TExpression::OR_OPERATOR); $repository = new TRepository('Customer'); $count = $repository->count($criteria); new TMessage('info', "Total of found customers: {$count} <br>\n"); TTransaction::close(); } catch (Exception $e) { new TMessage('error', $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'); // get the form data into an active record $formdata = $this->form->getData(); $validador = new TDuasDatasValidator(); $validador->validate('Datas', '', array($formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-01')); $meses = $this->colecaoMeses($formdata); $tickets = null; $arrayTickets = null; if ($formdata->cliente_id > 0) { $cliente = Pessoa::getPessoasEntidade($formdata->cliente_id); $retorno = Ticket::getTicketsCliente($cliente); $arrayTickets = $retorno; $tickets = implode(",", $retorno); } $criteria = new TCriteria(); $criteria->add(new TFilter("origem", "=", 1)); $criteria->add(new TFilter("codigo_cadastro_origem", "=", 100)); $criteria->add(new TFilter("ativo", "=", 1)); $criteria->add(new TFilter("usuario", "is not ")); $repo = new TRepository('Pessoa'); $pessoas = $repo->load($criteria); $criteria = new TCriteria(); $criteria->add(new TFilter('data_atividade', '<', $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01'), TExpression::OR_OPERATOR); $criteria->add(new TFilter('data_atividade', '>', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final)), TExpression::OR_OPERATOR); $repository = new TRepository('Atividade'); $count = $repository->count($criteria); $format = $formdata->output_type; if ($count > 0) { $widths = array(); switch ($format) { case 'html': $tr = new TTableWriterHTML($widths); $break = '<br />'; break; case 'pdf': $tr = new TTableWriterPDF($widths); $break = '<br />'; break; case 'rtf': if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $tr = new TTableWriterRTF($widths); $break = '<br />'; 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'); $colunas = count($meses) * 4 + 2; $arrayMeses = $this->string->array_meses(); // add a header row $tr->addRow(); $tr->addCell('RELATORIO XPTO', 'center', 'header', $colunas); // add a header row $tr->addRow(); $tr->addCell('Indicadores', 'center', 'header', $colunas); // add a header row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // add a carga horaria row $i = 0; $totalHorario = null; $arrayHorario = array(); $tr->addRow(); $tr->addCell(utf8_decode('Carga horária mensal:'), 'left', 'datap'); foreach ($meses as $mes) { $criteria = new TCriteria(); $criteria->add(new TFilter("mes", "=", substr($mes, 3, 2))); $criteria->add(new TFilter("ano", "=", substr($mes, 6, 4))); if ($formdata->colaborador_id > 0) { $criteria->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } $repo = new TRepository('CargaHoraria'); $cargaHoraria = $repo->load($criteria); $horario = null; foreach ($cargaHoraria as $carga) { $horario += $this->string->time_to_sec($carga->horario); } $totalHorario += $horario; $arrayHorario[$i] = $horario; $horario = $this->string->sec_to_time($horario); $tr->addCell($this->string->retira_segundos($horario), 'center', 'datap'); $tr->addCell('100%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalHorario = $this->string->sec_to_time($totalHorario); $tr->addCell($this->string->retira_segundos($totalHorario), 'center', 'datap'); $tr->addCell('100%', 'center', 'datap'); //add horas ponto total row $i = 0; $totalPontoTotal = null; $arrayPontoTotal = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas ponto total:'), 'left', 'datap'); foreach ($meses as $mes) { if ($formdata->colaborador_id > 0) { $totalPonto = $this->retornaPonto($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $totalPontoTotal += $this->string->time_to_sec($totalPonto); $arrayPontoTotal[$i] = $this->string->time_to_sec($totalPonto); } else { foreach ($pessoas as $pessoa) { $totalPonto += $this->string->time_to_sec($this->retornaPonto($pessoa->pessoa_codigo, substr($mes, 3, 2), substr($mes, 6, 4))); } $totalPontoTotal += $totalPonto; $arrayPontoTotal[$i] = $totalPonto; $totalPonto = $this->string->sec_to_time($totalPonto); } $tr->addCell($this->string->retira_segundos($totalPonto), 'center', 'datap'); $tr->addCell(round($arrayPontoTotal[$i] * 100 / $arrayHorario[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalPontoTotal = $this->string->sec_to_time($totalPontoTotal); $tr->addCell($this->string->retira_segundos($totalPontoTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalPontoTotal) * 100 / $this->string->time_to_sec($totalHorario)) . '%', 'center', 'datap'); //add horas ponto util row $i = 0; $totalPontoUtil = null; $arrayPontoUtil = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas ponto util:'), 'left', 'datap'); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } $cri->add(new TFilter("ticket_id", "IN", array(328, 514))); $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $repo = new TRepository('Atividade'); $ausencias = $repo->count($cri); $tempo = 0; if ($ausencias) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $pontoUtil = $arrayPontoTotal[$i] - $tempo; $arrayPontoUtil[$i] = $pontoUtil; $totalPontoUtil += $pontoUtil; $pontoUtil = $this->string->sec_to_time($pontoUtil); $tr->addCell($this->string->retira_segundos($pontoUtil), 'center', 'datap'); $tr->addCell(round($arrayPontoUtil[$i] * 100 / $arrayHorario[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalPontoUtil = $this->string->sec_to_time($totalPontoUtil); $tr->addCell($this->string->retira_segundos($totalPontoUtil), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalPontoUtil) * 100 / $this->string->time_to_sec($totalHorario)) . '%', 'center', 'datap'); //add atividades indicador total $i = 0; $totalAtividadeTotal = null; $arrayAtividadeTotal = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas atividade (indicador total):'), 'left', 'datap'); foreach ($meses as $mes) { $total = Atividade::retornaTotalAtividadesColaborador($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4), $tickets); $arrayAtividadeTotal[$i] = $this->string->time_to_sec($total); $totalAtividadeTotal += $this->string->time_to_sec($total); $tr->addCell($this->string->retira_segundos($total), 'center', 'datap'); $tr->addCell(round($arrayAtividadeTotal[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAtividadeTotal = $this->string->sec_to_time($totalAtividadeTotal); $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtividadeTotal) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); //add atividades indicador util $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('Horas atividade (indicador util):'), 'left', 'datap'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'datap'); $tr->addCell(round($arrayAtividadeTotal[$i] * 100 / $arrayPontoUtil[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } //$totalAtividadeTotal = $this->string->sec_to_time($totalAtividadeTotal); $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtividadeTotal) * 100 / $this->string->time_to_sec($totalPontoUtil)) . '%', 'center', 'datap'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add a header row $tr->addRow(); $tr->addCell(utf8_decode('Ausências'), 'center', 'header', $colunas); // add a header row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // add atestado medico row $i = 0; $totalAtestados = null; $arrayAtestados = array(); $tr->addRow(); $tr->addCell(utf8_decode('Atestado médico:'), 'left', 'datap'); foreach ($meses as $mes) { $atestados = Atividade::retornaAtestados($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $arrayAtestados[$i] = $this->string->time_to_sec($atestados); $totalAtestados += $this->string->time_to_sec($atestados); $tr->addCell($this->string->retira_segundos($atestados), 'center', 'datap'); $tr->addCell(round($arrayAtestados[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAtestados = $this->string->sec_to_time($totalAtestados); $tr->addCell($this->string->retira_segundos($totalAtestados), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtestados) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); // add ausencias row $i = 0; $totalAusencias = null; $arrayAusencias = array(); $tr->addRow(); $tr->addCell(utf8_decode('Ausências:'), 'left', 'datap'); foreach ($meses as $mes) { $ausencias = Atividade::retornaAusencias($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $arrayAusencias[$i] = $this->string->time_to_sec($ausencias); $totalAusencias += $this->string->time_to_sec($ausencias); $tr->addCell($this->string->retira_segundos($ausencias), 'center', 'datap'); $tr->addCell(round($arrayAusencias[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAusencias = $this->string->sec_to_time($totalAusencias); $tr->addCell($this->string->retira_segundos($totalAusencias), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAusencias) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add a header row $tr->addRow(); $tr->addCell(utf8_decode('Tipo Atividades'), 'center', 'header', $colunas); // add Tipo Atividades row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // verifica tipos de atividades do periodo $colour = FALSE; $tipoAtividades = array(); $objects = Atividade::retornaTiposAtividadesPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); $i = 1; foreach ($objects as $row) { $tipoAtividades[$i] = $row['tipo_atividade_id']; $i++; } foreach ($tipoAtividades as $ati) { // adiciona as linhas por tipo de atividade $style = $colour ? 'datap' : 'datai'; $i = 0; $totalAtividade = null; $arrayAtividade = array(); $tipoAtv = new TipoAtividade($ati); $tr->addRow(); $tr->addCell(utf8_decode($tipoAtv->nome . ':'), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if ($tickets) { $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); } $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("tipo_atividade_id", "=", $ati)); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arrayAtividade[$i] = $tempo; $totalAtividade += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arrayAtividade[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalAtividade = $this->string->sec_to_time($totalAtividade); $tr->addCell($this->string->retira_segundos($totalAtividade), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalAtividade) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add Por Sistema row $tr->addRow(); $tr->addCell(utf8_decode('Por sistema'), 'center', 'header', $colunas); $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // verifica tipos de atividades do periodo $colour = FALSE; $tipoSistemas = array(); $objects = Atividade::retornaSistemasPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); $i = 1; foreach ($objects as $row) { $tipoSistemas[$i] = $row['sistema_id']; $i++; } foreach ($tipoSistemas as $sis) { // adiciona as linhas por tipo de atividade $style = $colour ? 'datap' : 'datai'; $i = 0; $totalSistema = null; $arraySistema = array(); $sistema = new Sistema($sis); $tr->addRow(); $tr->addCell(utf8_decode($sistema->nome . ':'), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if ($tickets) { $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); } $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("sistema_id", "=", $sis)); $cri->add(new TFilter("ticket_id", "not in", array(328, 514))); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arraySistema[$i] = $tempo; $totalSistema += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arraySistema[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalSistema = $this->string->sec_to_time($totalSistema); $tr->addCell($this->string->retira_segundos($totalSistema), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalSistema) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add Por Cliente row $tr->addRow(); $tr->addCell(utf8_decode('Por Cliente'), 'center', 'header', $colunas); $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // monta array de clientes $tipoClientes = array(); $objects = Atividade::retornaClientesPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); foreach ($objects as $row) { $cliente = new Pessoa($row['solicitante_id']); if ($cliente->origem == 1) { $ind = $cliente->codigo_cadastro_origem; } else { $ind = 999; } $tipoClientes[$ind] += $this->string->time_to_sec($row['sum']); } arsort($tipoClientes); $colour = FALSE; foreach ($tipoClientes as $key => $value) { $style = $colour ? 'datap' : 'datai'; $i = 0; $totalClientes = null; $arrayClientes = array(); $labelCliente = ''; if ($key == '999') { $labelCliente = '999 - ECS'; } else { $entidade = new Entidade($key); $labelCliente = str_pad($key, 3, '0', STR_PAD_LEFT) . ' - ' . $entidade->entnomfan; } $tr->addRow(); $tr->addCell(utf8_decode($labelCliente), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if (!$tickets) { $cliente = Pessoa::getPessoasEntidade($key); $retorno = Ticket::getTicketsCliente($cliente); $arrayTickets = $retorno; } $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("ticket_id", "not in", array(328, 514))); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arrayClientes[$i] = $tempo; $totalClientes += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arrayClientes[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalClientes = $this->string->sec_to_time($totalClientes); $tr->addCell($this->string->retira_segundos($totalClientes), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalClientes) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // stores the file if (!file_exists("app/output/Atividade.{$format}") or is_writable("app/output/Atividade.{$format}")) { $tr->save("app/output/Atividade.{$format}"); } else { throw new Exception(_t('Permission denied') . ': ' . "app/output/Atividade.{$format}"); } // open the report file parent::openFile("app/output/Atividade.{$format}"); // shows the success message new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the 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 onReload() * Load the DETAIL datagrid (backlog) */ function onReload($param = NULL) { try { TTransaction::open('samples'); // open a transaction $repository = new TRepository('Backlog'); // creates a repository $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); // filter the master record $criteria->add(new TFilter('project_id', '=', TSession::getValue('project_id'))); // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { foreach ($objects as $object) { $this->datagrid->addItem($object); // add the detail inside the datagrid } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'samples' TTransaction::open('samples'); // creates a repository for Customer $repository = new TRepository('Customer'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } 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 { // open a transaction with database 'atividade' TTransaction::open('atividade'); // get the form data into an active record $formdata = $this->form->getData(); $format = $formdata->output_type; $tickets = null; if ($formdata->cliente_id > 0) { $cliente = Pessoa::getPessoasEntidade($formdata->cliente_id); $retorno = Ticket::getTicketsCliente($cliente); $tickets = implode(",", $retorno); } $total = Atividade::retornaTotalAtividadesColaborador($formdata->colaborador_id, $formdata->mes_atividade, $formdata->ano_atividade, $tickets); if ($total) { $widths = array(25, 350, 70, 50); switch ($format) { case 'html': $tr = new TTableWriterHTML($widths); $break = '<br />'; break; case 'pdf': $tr = new TTableWriterPDF($widths); $break = ''; break; case 'rtf': if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $tr = new TTableWriterRTF($widths); $break = '<br />'; 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'); $titulo = 'TODOS COLABORADORES'; if ($formdata->colaborador_id > 0) { $colaborador = new Pessoa($formdata->colaborador_id); $titulo = utf8_decode($colaborador->pessoa_nome); $totalPonto = $this->retornaPonto($formdata->colaborador_id, $formdata->mes_atividade); $criteria = new TCriteria(); $criteria->add(new TFilter("mes", "=", $formdata->mes_atividade)); $criteria->add(new TFilter("ano", "=", $formdata->ano_atividade)); $criteria->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); $repo = new TRepository('CargaHoraria'); $cargaHoraria = $repo->load($criteria); foreach ($cargaHoraria as $carga) { $horario = $carga->horario; } } else { //calcular todos $criteria = new TCriteria(); $criteria->add(new TFilter("mes", "=", $formdata->mes_atividade)); $criteria->add(new TFilter("ano", "=", $formdata->ano_atividade)); $repo = new TRepository('CargaHoraria'); $cargaHoraria = $repo->load($criteria); foreach ($cargaHoraria as $carga) { $horario += $this->string->time_to_sec($carga->horario); } $criteria = new TCriteria(); $criteria->add(new TFilter("origem", "=", 1)); $criteria->add(new TFilter("codigo_cadastro_origem", "=", 100)); $criteria->add(new TFilter("ativo", "=", 1)); $criteria->add(new TFilter("usuario", "is not ")); $repo = new TRepository('Pessoa'); $pessoas = $repo->load($criteria); foreach ($pessoas as $pessoa) { $totalPonto += $this->string->time_to_sec($this->retornaPonto($pessoa->pessoa_codigo, $formdata->mes_atividade)); } $horario = $this->string->sec_to_time($horario); $totalPonto = $this->string->sec_to_time($totalPonto); } // report description $tr->addRow(); $tr->addCell('', 'center', 'title'); $tr->addCell($titulo, 'center', 'title'); $tr->addCell("{$this->string->array_meses()[$formdata->mes_atividade]}-{$formdata->ano_atividade}", 'center', 'title', 2); // add a header row $tr->addRow(); $tr->addCell('', 'center', 'header'); $tr->addCell('Indicadores', 'center', 'header'); $tr->addCell('Horas', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // data rows $style = 'datai'; $tr->addRow(); $tr->addCell('', 'center', $style); $tr->addCell(utf8_decode('Carga horária mensal:'), 'left', $style); $tr->addCell($this->string->retira_segundos($horario), 'right', $style); $tr->addCell('100%', 'right', $style); $tr->addRow(); $tr->addCell('', 'center', $style); $tr->addCell(utf8_decode('Horas ponto total:'), 'left', $style); $tr->addCell($this->string->retira_segundos($totalPonto), 'right', $style); $tr->addCell(round($this->string->time_to_sec($totalPonto) * 100 / $this->string->time_to_sec($horario)) . '%', 'right', $style); $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } $cri->add(new TFilter("ticket_id", "IN", array(328, 514))); $cri->add(new TFilter("extract('month' from data_atividade)", "=", $formdata->mes_atividade)); $cri->add(new TFilter("extract('year' from data_atividade)", "=", $formdata->ano_atividade)); $repo = new TRepository('Atividade'); $ausencias = $repo->count($cri); if ($ausencias) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } $pontoUtil = $this->string->time_to_sec($totalPonto) - $tempo; $tr->addRow(); $tr->addCell('', 'center', $style); $tr->addCell(utf8_decode('Horas ponto útil:'), 'left', $style); $tr->addCell($this->string->retira_segundos($this->string->sec_to_time($pontoUtil)), 'right', $style); $tr->addCell(round($pontoUtil * 100 / $this->string->time_to_sec($horario)) . '%', 'right', $style); $tr->addRow(); $tr->addCell('', 'center', 'datap'); $tr->addCell(utf8_decode('Horas atividade (indicador total):'), 'left', 'datap'); $tr->addCell($this->string->retira_segundos($total), 'right', 'datap'); $tr->addCell(round($this->string->time_to_sec($total) * 100 / $this->string->time_to_sec($totalPonto)) . '%', 'right', 'datap'); $tr->addRow(); $tr->addCell('', 'center', 'datap'); $tr->addCell(utf8_decode('Horas atividade (indicador útil):'), 'left', 'datap'); $tr->addCell($this->string->retira_segundos($total), 'right', 'datap'); $tr->addCell(round($this->string->time_to_sec($total) * 100 / $pontoUtil) . '%', 'right', 'datap'); } else { $tr->addRow(); $tr->addCell('', 'center', $style); $tr->addCell(utf8_decode('Horas atividade:'), 'left', $style); $tr->addCell($this->string->retira_segundos($total), 'right', $style); $tr->addCell(round($this->string->time_to_sec($total) * 100 / $this->string->time_to_sec($totalPonto)) . '%', 'right', $style); } // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', 4); //ATESTADOS MEDICOS $objects = Atividade::retornaAtestadosMedicos($formdata->colaborador_id, $formdata->mes_atividade, $formdata->ano_atividade); // add a header row $tr->addRow(); $tr->addCell('', 'center', 'header'); $tr->addCell(utf8_decode('Ausências'), 'center', 'header'); $tr->addCell('Horas', 'center', 'header'); $tr->addCell('', 'center', 'header'); // controls the background filling $colour = FALSE; $seq = 1; // data rows foreach ($objects as $row) { $style = $colour ? 'datap' : 'datai'; $ticket = new Ticket($row['ticket_id']); $tr->addRow(); $tr->addCell($seq, 'center', $style); $tr->addCell(utf8_decode($ticket->titulo), 'left', $style); $tr->addCell($this->string->retira_segundos($row['total']), 'right', $style); $tr->addCell(round($this->string->time_to_sec($row['total']) * 100 / $this->string->time_to_sec($totalPonto)) . '%', 'right', $style); $seq++; $colour = !$colour; } // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', 4); $objects = Atividade::retornaAtividadesColaborador($formdata->colaborador_id, $formdata->mes_atividade, $formdata->ano_atividade, $tickets); // add a header row $tr->addRow(); $tr->addCell('', 'center', 'header'); $tr->addCell('Tipo Atividades', 'center', 'header'); $tr->addCell('Horas', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // controls the background filling $colour = FALSE; $seq = 1; // data rows foreach ($objects as $row) { $style = $colour ? 'datap' : 'datai'; $tr->addRow(); $tr->addCell($seq, 'center', $style); $tr->addCell(utf8_decode($row['nome']), 'left', $style); $tr->addCell($this->string->retira_segundos($row['total']), 'right', $style); $tr->addCell(round($this->string->time_to_sec($row['total']) / $this->string->time_to_sec($total) * 100) . '%', 'right', $style); $seq++; $colour = !$colour; } // footer row $tr->addRow(); $tr->addCell('', 'right', 'footer'); $tr->addCell('Total:', 'left', 'footer'); $tr->addCell($this->string->retira_segundos($total), 'right', 'footer'); $tr->addCell('100%', 'right', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', 4); $objects = Atividade::retornaAtividadesSistemaColaborador($formdata->colaborador_id, $formdata->mes_atividade, $formdata->ano_atividade, $tickets); // add a header row $tr->addRow(); $tr->addCell('', 'center', 'header'); $tr->addCell('Por Sistema', 'center', 'header'); $tr->addCell('Horas', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // controls the background filling $colour = FALSE; $seq = 1; // data rows foreach ($objects as $row) { $style = $colour ? 'datap' : 'datai'; $tr->addRow(); $tr->addCell($seq, 'center', $style); $tr->addCell(utf8_decode($row['nome']), 'left', $style); $tr->addCell($this->string->retira_segundos($row['total']), 'right', $style); $tr->addCell(round($this->string->time_to_sec($row['total']) / $this->string->time_to_sec($total) * 100) . '%', 'right', $style); $seq++; $colour = !$colour; } // footer row $tr->addRow(); $tr->addCell('', 'right', 'footer'); $tr->addCell('Total:', 'left', 'footer'); $tr->addCell($this->string->retira_segundos($total), 'right', 'footer'); $tr->addCell('100%', 'right', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', 4); $objects = Atividade::retornaAtividadesClienteColaborador($formdata->colaborador_id, $formdata->mes_atividade, $formdata->ano_atividade, $tickets); foreach ($objects as $row) { $cliente = new Pessoa($row['solicitante_id']); if ($cliente->origem == 1) { $ind = $cliente->codigo_cadastro_origem; } else { $ind = 999; } $array[$ind] += $this->string->time_to_sec($row['total']); } ksort($array); // add a header row $tr->addRow(); $tr->addCell('', 'center', 'header'); $tr->addCell('Por Cliente', 'center', 'header'); $tr->addCell('Horas', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // controls the background filling $colour = FALSE; $seq = 1; // data rows foreach ($array as $key => $value) { if ($key < 999) { $etd = new Entidade($key); $nome = $key . ' - ' . $etd->entnomfan; } else { $nome = $key . ' - ECS'; } $style = $colour ? 'datap' : 'datai'; $tr->addRow(); $tr->addCell($seq, 'center', $style); $tr->addCell(utf8_decode($nome), 'left', $style); $tr->addCell($this->string->retira_segundos($this->string->sec_to_time($value)), 'right', $style); $tr->addCell(round($value / $this->string->time_to_sec($total) * 100) . '%', 'right', $style); $seq++; $colour = !$colour; } // footer row $tr->addRow(); $tr->addCell('', 'right', 'footer'); $tr->addCell('Total:', 'left', 'footer'); $tr->addCell($this->string->retira_segundos($total), 'right', 'footer'); $tr->addCell('100%', 'right', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', 4); // footer row $tr->addRow(); $tr->addCell(date('d/m/Y H:i:s'), 'center', 'footer', 4); // stores the file $var = rand(0, 1000); if (!file_exists("app/output/Atividade{$var}_{$formdata->mes_atividade}_{$formdata->colaborador_id}.{$format}") or is_writable("app/output/Atividade.{$format}")) { $tr->save("app/output/Atividade{$var}_{$formdata->mes_atividade}_{$formdata->colaborador_id}.{$format}"); } else { throw new Exception(_t('Permission denied') . ': ' . "app/output/Atividade_{$formdata->mes_atividade}_{$formdata->colaborador_id}.{$format}"); } // open the report file parent::openFile("app/output/Atividade{$var}_{$formdata->mes_atividade}_{$formdata->colaborador_id}.{$format}"); // shows the success message new TMessage('info', 'Relatorio gerado. Por favor, habilite popups no navegador (somente para web).'); } else { new TMessage('error', 'Sem atividade no periodo cadastrado!'); } // 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 onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'atividade' TTransaction::open('atividade'); $logado = Pessoa::retornaUsuario(); // creates a repository for Ponto $repository = new TRepository('Ponto'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->add(new TFilter('colaborador_id', '=', $logado->pessoa_codigo)); // default order if (empty($param['order'])) { $param['order'] = 'data_ponto'; $param['direction'] = 'desc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('Ponto_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('Ponto_filter')); } // load the objects according to criteria $objects = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $object->data_ponto ? $object->data_ponto = $this->string->formatDateBR($object->data_ponto) : null; $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message TTransaction::rollback(); // undo all pending operations } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'changeman' TTransaction::open('changeman'); // creates a repository for Issue $repository = new TRepository('Issue'); if (!isset($param['order']) or $param['order'] == 'id') { $param['order'] = 'id'; $param['direction'] = 'desc'; } $limit = 100; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('Issue_filter')) { foreach (TSession::getValue('Issue_filter') as $filter) { // add the filter stored in the session to the criteria $criteria->add($filter); } } $member = Member::newFromLogin(TSession::getValue('login')); if ($member->role_mnemonic == 'CUSTOMER') { $criteria->add(new TFilter('id_user', '=', $member->id)); } // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'samples' TTransaction::open('db_crmbf'); // creates a repository for Customer $repository = new TRepository('CRM'); $limit = 10; // creates a criteria $criteria = new TCriteria(); // if (isset($param['order']) AND $param['order'] == 'city_name') // { // $param['order'] = '(select name from city where city_id = id)'; // } //$criteria->setProperties($param); // order, offset // add the filter stored in the session to the criteria $criteria->add(new TFilter('cliente_id', '=', $_GET['key'])); $criteria->setProperty('order', 'id desc'); // order, offset // $criteria->setProperty('limit', $limit); /* if (TSession::getValue('customer_filter1')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('customer_filter1')); } if (TSession::getValue('customer_filter2')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('customer_filter2')); } * */ // load the objects according to criteria $customers = $repository->load($criteria); $this->datagrid->clear(); if ($customers) { foreach ($customers as $customer) { // add the object inside the datagrid $this->datagrid->addItem($customer); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // in case of exception // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'sample' TTransaction::open('sample'); // creates a repository for Produtos $repository = new TRepository('Produtos'); $limit = 10; // creates a criteria $criteria = new TCriteria(); // default order if (empty($param['order'])) { $param['order'] = 'id'; $param['direction'] = 'asc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('Produtos_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('Produtos_filter')); } // load the objects according to criteria $objects = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { $img = new TImage('uploads/' . $object->imagem); $img->width = '100px'; $img->heigth = '120px'; $object->imagem = $img; // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * Load the datagrid with data */ public function onReload($param = NULL) { try { // open a transaction with database 'sample' TTransaction::open('sample'); // creates a repository for telefone $repository = new TRepository('telefone'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $filter = new TFilter('clientes_id', '=', $param['key']); $criteria->add($filter); // default order if (empty($param['order'])) { $param['order'] = 'id'; $param['direction'] = 'asc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); // load the objects according to criteria $objects = $repository->load($criteria, FALSE); if (is_callable($this->transformCallback)) { call_user_func($this->transformCallback, $objects, $param); } $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'samples' TTransaction::open('samples'); // creates a repository for Product $repository = new TRepository('Product'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); // update the save action parameters to pass // offset, limit, page and other info to the save action $this->saveAction->setParameters($param); // important! // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { $object->sale_price_edit = new TEntry('sale_price_' . $object->id); $object->sale_price_edit->setNumericMask(1, '.', ','); $object->sale_price_edit->setSize(120); $object->sale_price_edit->setValue($object->sale_price); $this->form->addField($object->sale_price_edit); // important! // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'samples' TTransaction::open('samples'); // creates a repository for Product $repository = new TRepository('Product'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); $criteria->setProperty('order', 'description'); if (TSession::getValue('product_filter1')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('product_filter1')); } // load the objects according to criteria $products = $repository->load($criteria); $this->datagrid->clear(); if ($products) { foreach ($products as $product) { // add the object inside the datagrid $this->datagrid->addItem($product); } } $this->cartgrid->clear(); $cart_objects = TSession::getValue('cart_objects'); $total = 0; if ($cart_objects) { foreach ($cart_objects as $object) { $this->cartgrid->addItem($object); $total += $object->sale_price; } } $this->total->setValue(number_format($total)); // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
// segundo exemplo, Contar todas as turmas com aula na sala // "100" no turno da Tarde OU na "200" pelo turno da manha. TTransaction::log("** Conta Turmas"); // instancia um critério de seleção // sala "100" e turno "T" (tarde) $criteria1 = new TCriteria(); $criteria1->add(new TFilter('sala', '=', '100')); $criteria1->add(new TFilter('turno', '=', 'T')); // instancia um critério de seleção // sala "200" e turno "M" (manha) $criteria2 = new TCriteria(); $criteria2->add(new TFilter('sala', '=', '200')); $criteria2->add(new TFilter('turno', '=', 'M')); // instancia um critério de seleção // com OU para juntar os critérios anteriores $criteria = new TCriteria(); $criteria->add($criteria1, TExpression::OR_OPERATOR); $criteria->add($criteria2, TExpression::OR_OPERATOR); // instancia um repositório de Turmas $repository = new TRepository('Turma'); // retorna quantos objetos satisfazem o critério $count = $repository->count($criteria); echo "Total de turmas: {$count} <br>\n"; // finaliza a transação TTransaction::close(); } catch (Exception $e) { // exibe a mensagem gerada pela exceção echo '<b>Erro</b>' . $e->getMessage(); // desfaz todas alterações no banco de dados TTransaction::rollback(); }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'atividade' TTransaction::open('atividade'); // creates a repository for Atividade $repository = new TRepository('Atividade'); $limit = 15; // creates a criteria $criteria = new TCriteria(); $criHoras = new TCriteria(); $criteria2 = new TCriteria(); $criHoras2 = new TCriteria(); $calculaHoras = null; $pesquisaNormal = null; $newparam = $param; // define new parameters if (isset($newparam['order']) and $newparam['order'] == 'ticket->titulo') { $newparam['order'] = '(select titulo from ticket where ticket_id = id)'; } if (isset($newparam['order']) and $newparam['order'] == 'pessoa->pessoa_nome') { $newparam['order'] = '(select pessoa_nome from tbz_pessoas where pessoa_codigo = colaborador_id)'; } if (isset($newparam['order']) and $newparam['order'] == 'tipo_atividade->nome') { $newparam['order'] = '(select nome from tipo_atividade where tipo_atividade_id = id)'; } if (isset($newparam['order']) and $newparam['order'] == 'sistema->nome') { $newparam['order'] = '(select nome from sistema where sistema_id = id)'; } // default order if (empty($newparam['order'])) { $newparam['order'] = 'data_atividade desc, id '; $newparam['direction'] = 'desc'; } $criteria->setProperties($newparam); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('AtividadeList_filter_id')) { $criteria->add(TSession::getValue('AtividadeList_filter_id')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_id')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_data_atividade_inicial')) { $criteria->add(TSession::getValue('AtividadeList_filter_data_atividade_inicial')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_data_atividade_inicial')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_data_atividade_final')) { $criteria->add(TSession::getValue('AtividadeList_filter_data_atividade_final')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_data_atividade_final')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_solicitante_id')) { $criteria->add(TSession::getValue('AtividadeList_filter_solicitante_id')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_solicitante_id')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_colaborador_id')) { $criteria->add(TSession::getValue('AtividadeList_filter_colaborador_id')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_colaborador_id')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_tipo_atividade_id')) { $criteria->add(TSession::getValue('AtividadeList_filter_tipo_atividade_id')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_tipo_atividade_id')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_ticket_id')) { $criteria->add(TSession::getValue('AtividadeList_filter_ticket_id')); // add the session filter $criHoras->add(TSession::getValue('AtividadeList_filter_ticket_id')); // add the session filter $calculaHoras = true; $pesquisaNormal = true; } if (TSession::getValue('AtividadeList_filter_pesquisa_master')) { try { TTransaction::open('atividade'); $pesquisa_master = TSession::getValue('AtividadeList_filter_pesquisa_master'); $repo = new TRepository('Ticket'); $tickets = $repo->where('titulo', 'ilike', "%{$pesquisa_master}%")->load(); $clausula[] = '0'; foreach ($tickets as $ticket) { $clausula[] = $ticket->id; } TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); } $criteria2->add(new TFilter('ticket_id', 'IN', $clausula), TExpression::OR_OPERATOR); $criteria2->add(new TFilter('descricao', 'ilike', "%{$pesquisa_master}%"), TExpression::OR_OPERATOR); $criHoras2->add(new TFilter('ticket_id', 'IN', $clausula), TExpression::OR_OPERATOR); $criHoras2->add(new TFilter('descricao', 'ilike', "%{$pesquisa_master}%"), TExpression::OR_OPERATOR); $calculaHoras = true; } if (TSession::getValue('AtividadeList_filter_pesquisa_master')) { if (!$pesquisaNormal) { $criteriaFinal = $criteria2; $criteriaHorasFinal = $criHoras2; $criteriaFinal->setProperties($newparam); // order, offset $criteriaFinal->setProperty('limit', $limit); } else { $criteriaFinal = new TCriteria(); $criteriaFinal->add($criteria); $criteriaFinal->add($criteria2); $criteriaFinal->setProperties($newparam); // order, offset $criteriaFinal->setProperty('limit', $limit); $criteriaHorasFinal = new TCriteria(); $criteriaHorasFinal->add($criHoras); $criteriaHorasFinal->add($criHoras2); } } else { $criteriaFinal = $criteria; $criteriaHorasFinal = $criHoras; } if ($calculaHoras) { $repo = new TRepository('Atividade'); $horas = $repo->load($criteriaHorasFinal, FALSE); $totalHoras = null; if ($horas) { foreach ($horas as $hora) { $HoraEntrada = new DateTime($hora->hora_inicio); $HoraSaida = new DateTime($hora->hora_fim); $diferenca = $HoraSaida->diff($HoraEntrada)->format('%H:%I:%S'); $totalHoras += $this->string->time_to_sec($diferenca); } } $this->onTotalAtividades(substr($this->string->sec_to_time($totalHoras), 0, -3)); } // load the objects according to criteria $objects = $repository->load($criteriaFinal, FALSE); $this->datagrid->clear(); try { if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); } // reset the criteria for record count $criteriaFinal->resetProperties(); $count = $repository->count($criteriaFinal); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
function onReload($param = NULL) { try { TTransaction::open('liger'); $repository = new TRepository('PlantaValores'); $limit = 10; $criteria = new TCriteria(); if (TSession::getValue('Plantavalores_id')) { $criteria->add(TSession::getValue('Plantavalores_id_filter')); } $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { foreach ($objects as $object) { $this->datagrid->addItem($object); } } $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database TTransaction::open($this->database); // instancia um repositório $repository = new TRepository($this->activeRecord); $limit = isset($this->limit) ? $this->limit : 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue($this->activeRecord . '_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue($this->activeRecord . '_filter')); } // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); if (isset($this->pageNavigation)) { $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit } // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'liger' TTransaction::open('liger'); // creates a repository for SystemProgram $repository = new TRepository('SystemProgram'); $limit = 10; // creates a criteria $criteria = new TCriteria(); if (!isset($param['order'])) { $param['order'] = 'id'; $param['direction'] = 'asc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('SystemProgram_name_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('SystemProgram_name_filter')); } if (TSession::getValue('SystemProgram_control_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('SystemProgram_control_filter')); } // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'saciq' TTransaction::open('saciq'); // creates a repository for Fornecedor $repository = new TRepository('Fornecedor'); $limit = 10; // creates a criteria $criteria = new TCriteria(); // default order if (empty($param['order'])) { $param['order'] = 'id'; $param['direction'] = 'asc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('FornecedorList_filter_nome')) { $criteria->add(TSession::getValue('FornecedorList_filter_nome')); // add the session filter } if (TSession::getValue('FornecedorList_filter_cnpj')) { $criteria->add(TSession::getValue('FornecedorList_filter_cnpj')); // add the session filter } // load the objects according to criteria $objects = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } 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 onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'changeman' TTransaction::open('changeman'); $member = Member::newFromLogin(TSession::getValue('login')); // creates a repository for Release $repository = new TRepository('Release'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('Release_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('Release_filter')); } // customer may only view its projects if ($member->role_mnemonic == 'CUSTOMER') { $member_projects_ids = array_keys($member->getProjectsList()); $criteria->add(new TFilter('id_project', 'IN', $member_projects_ids)); } // load the objects according to criteria $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'atividade' TTransaction::open('atividade'); $criteria = new TCriteria(); $criteria->add(new TFilter("origem", "=", 1)); $criteria->add(new TFilter("codigo_cadastro_origem", "=", 100)); $criteria->add(new TFilter("ativo", "=", 1)); $criteria->add(new TFilter("usuario", "is not ")); $repo = new TRepository('Pessoa'); $count = $repo->count($criteria); // creates a repository for CargaHoraria $repository = new TRepository('CargaHoraria'); $limit = $count; // creates a criteria $criteria = new TCriteria(); !$param['ano'] ? $param['ano'] = date('Y') : ($param['ano'] = $param['ano']); !$param['mes'] ? $param['mes'] = date('m') : ($param['mes'] = $param['mes']); $criteria->add(new TFilter("mes", "=", $param['mes'])); $criteria->add(new TFilter("ano", "=", $param['ano'])); // default order if (empty($param['order'])) { $param['order'] = 'id'; $param['direction'] = 'asc'; } $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('CargaHoraria_filter')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('CargaHoraria_filter')); } // load the objects according to criteria $objects = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit $obj = new StdClass(); $obj->mes = $param['mes']; $obj->ano = $param['ano']; $this->form->setData($obj); // fill the form with the active record data // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message TTransaction::rollback(); // undo all pending operations } }
/** * Load the datagrid with the active record objects */ public function onReload($param = NULL) { try { $model = TSession::getValue('standard_seek_model'); $database = TSession::getValue('standard_seek_database'); // begins the transaction with database TTransaction::open($database); // creates a repository for the model $repository = new TRepository($model); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('tstandardseek_filter')) { // add the filter to the criteria $criteria->add(TSession::getValue('tstandardseek_filter')); } // load all objects according with the criteria $clientes = $repository->load($criteria); $this->datagrid->clear(); if ($clientes) { $display_field = TSession::getValue('standard_seek_display_field'); foreach ($clientes as $cliente) { $item = $cliente; $item->display_field = $cliente->{$display_field}; // add the object into the datagrid $this->datagrid->addItem($item); } } // clear the crieteria to count the records $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // closes the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception genearated message new TMessage('error', '<b>Erro</b> ' . $e->getMessage()); // rollback all the database operations TTransaction::rollback(); } }
/** * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // start database transaction TTransaction::open('tecbiz'); // create a repository for City table $repository = new TRepository('Pessoa'); $limit = 10; // creates a criteria // default order if (empty($param['order'])) { $param['order'] = 'pessoa_nome'; $param['direction'] = 'asc'; } $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('test_pessoa_filter')) { // filter by city name $criteria->add(TSession::getValue('test_pessoa_filter')); } // load the objects according to the criteria $pessoas = $repository->load($criteria); $this->datagrid->clear(); if ($pessoas) { foreach ($pessoas as $pessoa) { // add the objects inside the datagrid $this->datagrid->addItem($pessoa); } } // clear the criteria $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // commit and closes the database transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // show the error message new TMessage('error', '<b>Erro</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * Load the datagrid with the database objects */ function onReload($param = NULL) { try { TTransaction::open($this->getBanco()); // create a repository for City table $repository = new TRepository($this->getModel()); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('filter')) { // filter by city name $criteria->add(TSession::getValue('filter')); } // load the objects according to the criteria $data = $repository->load($criteria); $this->datagrid->clear(); if ($data) { foreach ($data as $dados) { // add the objects inside the datagrid $this->datagrid->addItem($dados); } } // clear the criteria $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit $this->loaded = TRUE; } catch (Exception $e) { // show the error message new TMessage('error', '<b>Erro</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'atividade' TTransaction::open('atividade'); // creates a repository for RequisitoDesenvolvimento $repository = new TRepository('RequisitoDesenvolvimento'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $newparam = $param; // define new parameters if (isset($newparam['order']) and $newparam['order'] == 'ticket->titulo') { $newparam['order'] = '(select titulo from ticket where ticket_id = id)'; } // default order if (empty($newparam['order'])) { $newparam['order'] = 'id'; $newparam['direction'] = 'desc'; } $criteria->setProperties($newparam); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('RequisitoDesenvolvimentoList_filter_id')) { $criteria->add(TSession::getValue('RequisitoDesenvolvimentoList_filter_id')); // add the session filter } if (TSession::getValue('RequisitoDesenvolvimentoList_filter_titulo')) { $criteria->add(TSession::getValue('RequisitoDesenvolvimentoList_filter_titulo')); // add the session filter } if (TSession::getValue('RequisitoDesenvolvimentoList_filter_data_cadastro')) { $criteria->add(TSession::getValue('RequisitoDesenvolvimentoList_filter_data_cadastro')); // add the session filter } // load the objects according to criteria $objects = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onReload() * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // open a transaction with database 'samples' TTransaction::open('samples'); // creates a repository for Customer $repository = new TRepository('Customer'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $newparam = $param; // define new parameters if (isset($newparam['order']) and $newparam['order'] == 'city->name') { $newparam['order'] = '(select name from city where city_id = id)'; } // default order if (empty($newparam['order'])) { $newparam['order'] = 'id'; $newparam['direction'] = 'asc'; } $criteria->setProperties($newparam); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('customer_filter1')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('customer_filter1')); } if (TSession::getValue('customer_filter2')) { // add the filter stored in the session to the criteria $criteria->add(TSession::getValue('customer_filter2')); } // load the objects according to criteria $customers = $repository->load($criteria, FALSE); $this->datagrid->clear(); if ($customers) { foreach ($customers as $customer) { // add the object inside the datagrid $this->datagrid->addItem($customer); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // close the transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
function onReload($param = NULL) { try { TTransaction::open('liger'); $repository = new TRepository('Contribuinte'); $limit = 10; $criteria = new TCriteria(); if (TSession::getValue('contribuinte_id_filter')) { $criteria->add(TSession::getValue('contribuinte_id_filter')); } if (TSession::getValue('contribuinte_nome_filter')) { $criteria->add(TSession::getValue('contribuinte_nome_filter')); } $objects = $repository->load($criteria); $this->datagrid->clear(); if ($objects) { // iterate the collection of active records foreach ($objects as $object) { // add the object inside the datagrid $this->datagrid->addItem($object); } } // reset the criteria for record count $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * Load the datagrid with the database objects */ function onReload($param = NULL) { try { // start database transaction TTransaction::open('library'); // create a repository for Item table $repository = new TRepository('Item'); $limit = 10; // creates a criteria $criteria = new TCriteria(); $criteria->setProperties($param); // order, offset $criteria->setProperty('limit', $limit); if (TSession::getValue('test_item_filter')) { // filter by item barcode $criteria->add(TSession::getValue('test_item_filter')); } // load the objects according to the criteria $items = $repository->load($criteria); $this->datagrid->clear(); if ($items) { foreach ($items as $item) { // add the objects inside the datagrid $this->datagrid->addItem($item); } } // clear the criteria $criteria->resetProperties(); $count = $repository->count($criteria); $this->pageNavigation->setCount($count); // count of records $this->pageNavigation->setProperties($param); // order, page $this->pageNavigation->setLimit($limit); // limit // commit and closes the database transaction TTransaction::close(); $this->loaded = true; } catch (Exception $e) { // show the error message new TMessage('error', '<b>Erro</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onSave() * Executed whenever the user clicks at the save button */ function onSave() { try { TTransaction::open('atividade'); // open a transaction // get the form data into an active record Atividade $object = $this->form->getData(); $this->form->validate(); // form validation $tipo = new TipoAtividade($object->tipo_atividade_id); // Start date $date = $this->string->formatDate($object->data_inicial); // End date $end_date = $this->string->formatDate($object->data_final); while (strtotime($date) <= strtotime($end_date)) { $criteria = new TCriteria(); $criteria->add(new TFilter("data_ponto", "=", $date)); $criteria->add(new TFilter("colaborador_id", "=", $object->colaborador_id)); $repo = new TRepository('Ponto'); $count = $repo->count($criteria); if (!$count) { $criteria = new TCriteria(); $criteria->add(new TFilter("data_atividade", "=", $date)); $criteria->add(new TFilter("colaborador_id", "=", $object->colaborador_id)); $repo = new TRepository('Atividade'); $count = $repo->count($criteria); if (!$count) { $ponto = new Ponto(); $ponto->data_ponto = $date; $ponto->hora_entrada = '08:15:00'; $ponto->hora_saida = '18:03:00'; $ponto->colaborador_id = $object->colaborador_id; $ponto->store(); $atividade = new Atividade(); $atividade->data_atividade = $date; $atividade->hora_inicio = '09:15:00'; $atividade->hora_fim = '18:03:00'; $atividade->descricao = 'AUSENCIA CADASTRADA EM LOTE'; $atividade->colaborador_id = $object->colaborador_id; $atividade->tipo_atividade_id = $object->tipo_atividade_id; $atividade->sistema_id = $tipo->sistema_id; $atividade->ticket_id = $tipo->ticket_id; $atividade->store(); } } else { new TMessage('error', '<b>Erro:</b> Ponto já cadastrado dia: ' . $this->string->formatDateBR($date)); break; } $date = date("Y-m-d", strtotime("+1 day", strtotime($date))); } $this->form->setData($object); // keep form data TTransaction::close(); // close the transaction // shows the success message if (!$count) { 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 } }