Last active
August 19, 2019 17:14
-
-
Save maxmillernunes/579bf11345a5488410d9251fb948da7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function portabilidadesGrafico($dados) { | |
try { | |
$mes = date('m'); | |
$portabilidade = $this->connection->prepare("SELECT | |
--tipo_portabilidade, | |
COUNT(tipo_portabilidade) as total, | |
p_qual_operadora | |
FROM | |
public.vendas | |
WHERE | |
EXTRACT( | |
MONTH | |
FROM | |
data_venda | |
) = :mes | |
AND id_vendedor = :id_vendedor | |
AND tipo_portabilidade IN('Portado', 'Migrado') | |
GROUP BY | |
p_qual_operadora, | |
tipo_portabilidade | |
"); | |
$portabilidade->bindValue(":mes", $mes); | |
$portabilidade->bindValue(":id_vendedor", $dados['id_vendedor']); | |
$portabilidade->execute(); | |
if ($portabilidade->rowCount() > 0) { | |
$dados = $portabilidade->fetchAll(PDO::FETCH_ASSOC); | |
$array = array(); | |
$index = 0; | |
foreach ($dados as $item) { | |
$array[$index]['name'] = $item['p_qual_operadora']; | |
$array[$index]['y'] = $item['total']; | |
$index++; | |
} | |
return $this->funcoes->retorno(200, "Busca realizada com sucesso!", $array); | |
} else { | |
return $this->funcoes->retorno(400, "Sem registro!", $array); | |
} | |
} catch (PDOException $e) { | |
return $e; | |
return $this->funcoes->retorno(500, "Ops, ocorreu algum erro!", null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment