/** * 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 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 onSearch() * Register the filter in the session when the user performs a search */ function onSearch() { // get the search form data $data = $this->form->getData(); // clear session filters TSession::setValue('TicketList_filter_id', NULL); TSession::setValue('TicketList_filter_titulo', NULL); TSession::setValue('TicketList_filter_solicitante_id', NULL); TSession::setValue('TicketList_filter_entidade_id', NULL); TSession::setValue('TicketList_filter_status_ticket_id', NULL); TSession::setValue('TicketList_filter_tipo_ticket_id', NULL); TSession::setValue('TicketList_filter_responsavel_id', NULL); TSession::setValue('TicketList_filter_prioridade_id', NULL); TSession::setValue('TicketList_filter_sistema_id', NULL); if (isset($data->id) and $data->id) { $filter = new TFilter('id', '=', "{$data->id}"); // create the filter TSession::setValue('TicketList_filter_id', $filter); // stores the filter in the session } if (isset($data->titulo) and $data->titulo) { $filter = new TFilter('titulo', 'ilike', "%{$data->titulo}%"); // create the filter TSession::setValue('TicketList_filter_titulo', $filter); // stores the filter in the session } if (isset($data->solicitante_id) and $data->solicitante_id) { $filter = new TFilter('solicitante_id', '=', "{$data->solicitante_id}"); // create the filter TSession::setValue('TicketList_filter_solicitante_id', $filter); // stores the filter in the session } if (isset($data->entcodent) and $data->entcodent) { try { TTransaction::open('atividade'); $solicitantes = Pessoa::getPessoasEntidade($data->entcodent); TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); } $filter = new TFilter('solicitante_id', 'IN', $solicitantes); // create the filter TSession::setValue('TicketList_filter_entidade_id', $filter); // stores the filter in the session } if (isset($data->status_ticket_id) and $data->status_ticket_id) { $filter = new TFilter('status_ticket_id', '=', "{$data->status_ticket_id}"); // create the filter TSession::setValue('TicketList_filter_status_ticket_id', $filter); // stores the filter in the session } if (isset($data->tipo_ticket_id) and $data->tipo_ticket_id) { $filter = new TFilter('tipo_ticket_id', '=', "{$data->tipo_ticket_id}"); // create the filter TSession::setValue('TicketList_filter_tipo_ticket_id', $filter); // stores the filter in the session } if (isset($data->responsavel_id) and $data->responsavel_id) { $filter = new TFilter('responsavel_id', '=', "{$data->responsavel_id}"); // create the filter TSession::setValue('TicketList_filter_responsavel_id', $filter); // stores the filter in the session } if (isset($data->prioridade_id) and $data->prioridade_id) { $filter = new TFilter('prioridade_id', '=', "{$data->prioridade_id}"); // create the filter TSession::setValue('TicketList_filter_prioridade_id', $filter); // stores the filter in the session } if (isset($data->sistema_id) and $data->sistema_id) { $filter = new TFilter('sistema_id', '=', "{$data->sistema_id}"); // create the filter TSession::setValue('TicketList_filter_sistema_id', $filter); // stores the filter in the session } // fill the form with data again $this->form->setData($data); // keep the search data in the session TSession::setValue('Ticket_filter_data', $data); $param = array(); $param['offset'] = 0; $param['first_page'] = 1; $this->onReload($param); }
/** * 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(); } }