public function andamento($projeto_id) { $porcentagem = 0; $trabalhados = 0; $horas_projeto = 0; $horas_trabalhadas = 0; // dados do projeto $modelProjeto = new Model_DbTable_Projeto(); $projeto = $modelProjeto->getById($projeto_id); $horas_projeto = $projeto->projeto_horas; $modelControleHoras = new Model_DbTable_ControleHoras(); $horas = $modelControleHoras->fetchAll("projeto_id = {$projeto_id}"); foreach ($horas as $hora) { $zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio); $zendDateFim = new Zend_Date($hora->controle_horas_data_fim); $trabalhados += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP); } // converte horas trabalhadas para horas $horas_trabalhadas = $trabalhados / 3600; if ($horas_trabalhadas < 1) { return 0; } if ($horas_projeto == 0) { return 100; } $porcentagem = number_format($horas_trabalhadas * 100 / $horas_projeto, 2, '.', ''); return $porcentagem; }
public function indexAction() { /** * Total de clientes */ $modelClientes = new Model_DbTable_Cliente(); $this->view->clientes = $modelClientes->fetchAll(); /** * Total de propostas */ $modelProposta = new Model_DbTable_Proposta(); $propostas = $modelProposta->fetchAll(); $this->view->propostas = $propostas; $total_horas_propostas = 0; $total_valor_propostas = 0; foreach ($propostas as $proposta) { $total_horas_propostas += $proposta->proposta_horas; $total_valor_propostas += $proposta->proposta_valor; } $this->view->total_horas_proposta = $total_horas_propostas; $this->view->total_valor_proposta = $total_valor_propostas; /** * Total de Projetos */ $modelProjeto = new Model_DbTable_Projeto(); $projetos = $modelProjeto->fetchAll(); $this->view->projetos = $projetos; /** * Total Faturamento */ $modelFaturamento = new Model_DbTable_Faturamento(); $faturamentos = $modelFaturamento->fetchAll(); $faturamento_total = 0; $receber = 0; $recebido = 0; foreach ($faturamentos as $faturamento) { if ($faturamento->faturamento_status === self::STATUS_AGUARDANDO_PAGAMENTO) { $receber += $faturamento->faturamento_valor; } if ($faturamento->faturamento_status === self::STATUS_PAGO) { $recebido += $faturamento->faturamento_valor; } $faturamento_total += $faturamento->faturamento_valor; } $this->view->faturamento_total = $faturamento_total; $this->view->receber = $receber; $this->view->recebido = $recebido; /** * Total de Horas Trbalhadas */ $modelControleHoras = new Model_DbTable_ControleHoras(); $horas = $modelControleHoras->fetchAll(); $horas_trabalhadas = 0; foreach ($horas as $hora) { $zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio); $zendDateFim = new Zend_Date($hora->controle_horas_data_fim); $horas_trabalhadas += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP); } $this->view->horas = ceil($horas_trabalhadas / 3600); }
private function setPlayPause($projeto_id, $status, $projeto_controle_horas = null) { $modelProjeto = new Model_DbTable_Projeto(); //Zend_Debug::dump($projeto_controle_horas); die(); try { Zend_Db_Table_Abstract::getDefaultAdapter()->beginTransaction(); // controle de horas $modelControleHoras = new Model_DbTable_ControleHoras(); if ($status === self::STATUS_TRABALHANDO) { $controle_data = array("projeto_id" => $projeto_id, "controle_horas_data_inicio" => date("Y-m-d H:i:s")); $controle_horas_id = $modelControleHoras->insert($controle_data); } elseif (self::STATUS_PAUSADO) { if (!$projeto_controle_horas) { throw new Exception("Controle Horas ID não encontrado!"); } $controle_data = array("controle_horas_data_fim" => date("Y-m-d H:i:s")); $controle_horas_id = $modelControleHoras->updateById($controle_data, $projeto_controle_horas); } $update = array("projeto_status" => $status, "projeto_controle_horas" => $controle_horas_id); $modelProjeto->updateById($update, $projeto_id); Zend_Db_Table_Abstract::getDefaultAdapter()->commit(); return true; } catch (Exception $ex) { Zend_Db_Table_Abstract::getDefaultAdapter()->rollBack(); throw new Exception($ex->getMessage()); } }