Commit 57e462b64210f9eaa7dd0391de7033012d121930
Committed by
Eduardo Santos
1 parent
5e645f47
Exists in
master
and in
1 other branch
Adiciona exportar em CSV todas as coletas WMI e muda o layout dos relatórios para usar o datatable
Showing
5 changed files
with
190 additions
and
10 deletions
Show diff stats
src/Cacic/CommonBundle/Entity/ComputadorColetaRepository.php
@@ -46,7 +46,7 @@ class ComputadorColetaRepository extends EntityRepository | @@ -46,7 +46,7 @@ class ComputadorColetaRepository extends EntityRepository | ||
46 | public function gerarRelatorioConfiguracoes( $filtros ) | 46 | public function gerarRelatorioConfiguracoes( $filtros ) |
47 | { | 47 | { |
48 | $qb = $this->createQueryBuilder('coleta') | 48 | $qb = $this->createQueryBuilder('coleta') |
49 | - ->select('IDENTITY(coleta.computador), coleta.teClassPropertyValue, comp.nmComputador, comp.teNodeAddress, comp.teIpComputador, so.idSo, so.inMswindows, so.sgSo, rede.idRede, local.nmLocal, local.idLocal') | 49 | + ->select('IDENTITY(coleta.computador), coleta.teClassPropertyValue, comp.nmComputador, comp.teNodeAddress, comp.teIpComputador, so.idSo, so.inMswindows, so.sgSo, so.teDescSo, rede.idRede, local.nmLocal, local.idLocal') |
50 | ->innerJoin('coleta.classProperty', 'property') | 50 | ->innerJoin('coleta.classProperty', 'property') |
51 | ->innerJoin('property.idClass', 'classe') | 51 | ->innerJoin('property.idClass', 'classe') |
52 | ->innerJoin('coleta.computador', 'comp') | 52 | ->innerJoin('coleta.computador', 'comp') |
@@ -244,7 +244,7 @@ class ComputadorColetaRepository extends EntityRepository | @@ -244,7 +244,7 @@ class ComputadorColetaRepository extends EntityRepository | ||
244 | public function gerarRelatorioWMI( $filtros, $classe ) | 244 | public function gerarRelatorioWMI( $filtros, $classe ) |
245 | { | 245 | { |
246 | $qb = $this->createQueryBuilder('coleta') | 246 | $qb = $this->createQueryBuilder('coleta') |
247 | - ->select('property.nmPropertyName', 'coleta.teClassPropertyValue', 'so.idSo', 'so.inMswindows', 'so.sgSo', 'rede.idRede', 'rede.nmRede', 'rede.teIpRede', 'local.nmLocal', 'local.idLocal', 'count(DISTINCT coleta.computador) as numComp') | 247 | + ->select('property.nmPropertyName', 'coleta.teClassPropertyValue', 'so.idSo', 'so.inMswindows', 'so.sgSo', 'so.teDescSo', 'rede.idRede', 'rede.nmRede', 'rede.teIpRede', 'local.nmLocal', 'local.idLocal', 'count(DISTINCT coleta.computador) as numComp') |
248 | ->innerJoin('coleta.classProperty', 'property') | 248 | ->innerJoin('coleta.classProperty', 'property') |
249 | ->innerJoin('property.idClass', 'classe') | 249 | ->innerJoin('property.idClass', 'classe') |
250 | ->innerJoin('coleta.computador', 'comp') | 250 | ->innerJoin('coleta.computador', 'comp') |
src/Cacic/RelatorioBundle/Controller/HardwareController.php
@@ -6,6 +6,12 @@ use Doctrine\Common\Util\Debug; | @@ -6,6 +6,12 @@ use Doctrine\Common\Util\Debug; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | 8 | ||
9 | +use Ddeboer\DataImport\Workflow; | ||
10 | +use Ddeboer\DataImport\Reader\ArrayReader; | ||
11 | +use Ddeboer\DataImport\Writer\CsvWriter; | ||
12 | +use Ddeboer\DataImport\ValueConverter\CallbackValueConverter; | ||
13 | +use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
14 | + | ||
9 | class HardwareController extends Controller | 15 | class HardwareController extends Controller |
10 | { | 16 | { |
11 | 17 | ||
@@ -75,9 +81,12 @@ class HardwareController extends Controller | @@ -75,9 +81,12 @@ class HardwareController extends Controller | ||
75 | */ | 81 | */ |
76 | public function wmiRelatorioAction( Request $request, $classe ) | 82 | public function wmiRelatorioAction( Request $request, $classe ) |
77 | { | 83 | { |
84 | + $filtros = $request->get('rel_filtro_hardware'); | ||
85 | + | ||
78 | $dados = $this->getDoctrine() | 86 | $dados = $this->getDoctrine() |
79 | ->getRepository('CacicCommonBundle:ComputadorColeta') | 87 | ->getRepository('CacicCommonBundle:ComputadorColeta') |
80 | - ->gerarRelatorioWMI( $filtros = $request->get('rel_filtro_hardware'), $classe = $classe ); | 88 | + ->gerarRelatorioWMI($filtros , $classe = $classe ); |
89 | + | ||
81 | 90 | ||
82 | $locale = $request->getLocale(); | 91 | $locale = $request->getLocale(); |
83 | return $this->render( | 92 | return $this->render( |
@@ -85,6 +94,7 @@ class HardwareController extends Controller | @@ -85,6 +94,7 @@ class HardwareController extends Controller | ||
85 | array( | 94 | array( |
86 | 'idioma'=> $locale, | 95 | 'idioma'=> $locale, |
87 | 'dados' => $dados, | 96 | 'dados' => $dados, |
97 | + 'filtros' => $filtros, | ||
88 | 'classe' => $classe | 98 | 'classe' => $classe |
89 | ) | 99 | ) |
90 | ); | 100 | ); |
@@ -117,18 +127,159 @@ class HardwareController extends Controller | @@ -117,18 +127,159 @@ class HardwareController extends Controller | ||
117 | 127 | ||
118 | $dados = $this->getDoctrine() | 128 | $dados = $this->getDoctrine() |
119 | ->getRepository('CacicCommonBundle:ComputadorColeta') | 129 | ->getRepository('CacicCommonBundle:ComputadorColeta') |
120 | - ->gerarRelatorioWMIDetalhe( $filtros = $filtros, $classe = $classe ); | 130 | + ->gerarRelatorioWMIDetalhe( $filtros, $classe ); |
121 | 131 | ||
122 | $locale = $request->getLocale(); | 132 | $locale = $request->getLocale(); |
133 | + | ||
134 | + // Pega o idClassProperty | ||
135 | + $idClassProperty = $this | ||
136 | + ->getDoctrine() | ||
137 | + ->getManager() | ||
138 | + ->createQuery("SELECT p.idClassProperty FROM CacicCommonBundle:ClassProperty p WHERE p.nmPropertyName = :propriedade") | ||
139 | + ->setParameter('propriedade', $propriedade) | ||
140 | + ->getArrayResult(); | ||
141 | + | ||
142 | + // Corrige para fazer o parsing da variável | ||
143 | + $item = array(); | ||
144 | + foreach ($idClassProperty as $elm) { | ||
145 | + array_push($item, $elm['idClassProperty']); | ||
146 | + } | ||
147 | + $filtros['conf'] = join($item, ","); | ||
148 | + | ||
123 | return $this->render( | 149 | return $this->render( |
124 | 'CacicRelatorioBundle:Hardware:rel_wmi_detalhe.html.twig', | 150 | 'CacicRelatorioBundle:Hardware:rel_wmi_detalhe.html.twig', |
125 | array( | 151 | array( |
126 | 'idioma'=> $locale, | 152 | 'idioma'=> $locale, |
127 | 'dados' => $dados, | 153 | 'dados' => $dados, |
128 | 'propriedade' => $propriedade, | 154 | 'propriedade' => $propriedade, |
155 | + 'filtros' => $filtros, | ||
129 | 'classe' => $classe | 156 | 'classe' => $classe |
130 | ) | 157 | ) |
131 | ); | 158 | ); |
132 | } | 159 | } |
160 | + | ||
161 | + /** | ||
162 | + * [RELATÓRIO] Relatório CSV de atributos da classe WMI gerado à partir dos filtros informados | ||
163 | + */ | ||
164 | + public function csvWMIRelatorioAction( Request $request, $classe ) | ||
165 | + { | ||
166 | + $conf = $request->get('conf'); | ||
167 | + $rede = $request->get('rede'); | ||
168 | + $local = $request->get('local'); | ||
169 | + $so = $request->get('so'); | ||
170 | + | ||
171 | + // Adiciona rede à lista de filtros se for fornecido | ||
172 | + if (!empty($rede)) { | ||
173 | + $filtros['redes'] = $rede; | ||
174 | + } | ||
175 | + | ||
176 | + // Adiciona local à lista de filtros se for fornecido | ||
177 | + if (!empty($local)) { | ||
178 | + $filtros['locais'] = $local; | ||
179 | + } | ||
180 | + | ||
181 | + // Adiciona SO à lista de filtros se for fornecido | ||
182 | + if (!empty($so)) { | ||
183 | + $filtros['so'] = $so; | ||
184 | + } | ||
185 | + | ||
186 | + // Adiciona Propriedades à lista de filtros se for fornecido | ||
187 | + if (!empty($conf)) { | ||
188 | + $filtros['conf'] = $conf; | ||
189 | + } | ||
190 | + | ||
191 | + $dados = $this->getDoctrine() | ||
192 | + ->getRepository('CacicCommonBundle:ComputadorColeta') | ||
193 | + ->gerarRelatorioWMI( $filtros, $classe ); | ||
194 | + | ||
195 | + $locale = $request->getLocale(); | ||
196 | + | ||
197 | + // Gera cabeçalho | ||
198 | + $cabecalho = array(); | ||
199 | + foreach($dados as $elm) { | ||
200 | + array_push($cabecalho, array_keys($elm)); | ||
201 | + break; | ||
202 | + } | ||
203 | + // Gera CSV | ||
204 | + $reader = new ArrayReader(array_merge($cabecalho, $dados)); | ||
205 | + | ||
206 | + // Create the workflow from the reader | ||
207 | + $workflow = new Workflow($reader); | ||
208 | + | ||
209 | + // Add the writer to the workflow | ||
210 | + $tmpfile = tempnam(sys_get_temp_dir(), $classe.".csv"); | ||
211 | + $file = new \SplFileObject($tmpfile, 'w'); | ||
212 | + $writer = new CsvWriter($file); | ||
213 | + $workflow->addWriter($writer); | ||
214 | + | ||
215 | + // Process the workflow | ||
216 | + $workflow->process(); | ||
217 | + | ||
218 | + // Retorna o arquivo | ||
219 | + $response = new BinaryFileResponse($tmpfile); | ||
220 | + $response->headers->set('Content-Type', 'text/csv'); | ||
221 | + $response->headers->set('Content-Disposition', "attachment; filename=$classe.csv"); | ||
222 | + $response->headers->set('Content-Transfer-Encoding', 'binary'); | ||
223 | + | ||
224 | + return $response; | ||
225 | + } | ||
226 | + | ||
227 | + public function csvWMIRelatorioDetalheAction( Request $request, $classe, $propriedade ) | ||
228 | + { | ||
229 | + $filtros['conf'] = $propriedade; | ||
230 | + $rede = $request->get('rede'); | ||
231 | + $local = $request->get('local'); | ||
232 | + $so = $request->get('so'); | ||
233 | + | ||
234 | + // Adiciona rede à lista de filtros se for fornecido | ||
235 | + if (!empty($rede)) { | ||
236 | + $filtros['redes'] = $rede; | ||
237 | + } | ||
238 | + | ||
239 | + // Adiciona local à lista de filtros se for fornecido | ||
240 | + if (!empty($local)) { | ||
241 | + $filtros['locais'] = $local; | ||
242 | + } | ||
243 | + | ||
244 | + // Adiciona SO à lista de filtros se for fornecido | ||
245 | + if (!empty($so)) { | ||
246 | + $filtros['so'] = $so; | ||
247 | + } | ||
248 | + | ||
249 | + $dados = $this->getDoctrine() | ||
250 | + ->getRepository('CacicCommonBundle:ComputadorColeta') | ||
251 | + ->gerarRelatorioWMIDetalhe( $filtros, $classe ); | ||
252 | + | ||
253 | + $locale = $request->getLocale(); | ||
254 | + | ||
255 | + // Gera cabeçalho | ||
256 | + $cabecalho = array(); | ||
257 | + foreach($dados as $elm) { | ||
258 | + array_push($cabecalho, array_keys($elm)); | ||
259 | + break; | ||
260 | + } | ||
261 | + // Gera CSV | ||
262 | + $reader = new ArrayReader(array_merge($cabecalho, $dados)); | ||
263 | + | ||
264 | + // Create the workflow from the reader | ||
265 | + $workflow = new Workflow($reader); | ||
266 | + | ||
267 | + // Add the writer to the workflow | ||
268 | + $tmpfile = tempnam(sys_get_temp_dir(), $propriedade.".csv"); | ||
269 | + $file = new \SplFileObject($tmpfile, 'w'); | ||
270 | + $writer = new CsvWriter($file); | ||
271 | + $workflow->addWriter($writer); | ||
272 | + | ||
273 | + // Process the workflow | ||
274 | + $workflow->process(); | ||
275 | + | ||
276 | + // Retorna o arquivo | ||
277 | + $response = new BinaryFileResponse($tmpfile); | ||
278 | + $response->headers->set('Content-Type', 'text/csv'); | ||
279 | + $response->headers->set('Content-Disposition', "attachment; filename=$propriedade.csv"); | ||
280 | + $response->headers->set('Content-Transfer-Encoding', 'binary'); | ||
281 | + | ||
282 | + return $response; | ||
283 | + } | ||
133 | 284 | ||
134 | } | 285 | } |
src/Cacic/RelatorioBundle/Resources/config/routing.yml
@@ -166,4 +166,12 @@ cacic_inativos_listar_csv: | @@ -166,4 +166,12 @@ cacic_inativos_listar_csv: | ||
166 | pattern: /inativos/listar/csv/{idRede}/{dtAcaoInicio}/{dtAcaoFim} | 166 | pattern: /inativos/listar/csv/{idRede}/{dtAcaoInicio}/{dtAcaoFim} |
167 | defaults: { _controller: CacicRelatorioBundle:Faturamento:listarInativosCsv, idRede: null, dtAcaoInicio: null, dtAcaoFim: null } | 167 | defaults: { _controller: CacicRelatorioBundle:Faturamento:listarInativosCsv, idRede: null, dtAcaoInicio: null, dtAcaoFim: null } |
168 | requirements: | 168 | requirements: |
169 | - idRede: \d+ | ||
170 | \ No newline at end of file | 169 | \ No newline at end of file |
170 | + idRede: \d+ | ||
171 | + | ||
172 | +cacic_relatorio_csv_hardware_wmi: | ||
173 | + pattern: /csv/hardware/{classe} | ||
174 | + defaults: { _controller: CacicRelatorioBundle:Hardware:csvWMIRelatorio } | ||
175 | + | ||
176 | +cacic_relatorio_csv_hardware_wmi_detalhe: | ||
177 | + pattern: /csv/hardware/{classe}/{propriedade} | ||
178 | + defaults: { _controller: CacicRelatorioBundle:Hardware:csvWMIRelatorioDetalhe } | ||
171 | \ No newline at end of file | 179 | \ No newline at end of file |
src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi.html.twig
@@ -5,14 +5,25 @@ | @@ -5,14 +5,25 @@ | ||
5 | <h2>{{ 'Relatório de Configurações da Classe '|trans }} {{ classe }}</h2> | 5 | <h2>{{ 'Relatório de Configurações da Classe '|trans }} {{ classe }}</h2> |
6 | <h5>{{ 'Relatório gerado em'|trans }} {% if idioma == 'pt_BR' %}{{ "now"|date("d/m/Y H\\hi") }}{% else %}{{ "now"|date("m/d/Y H\\hi") }}{% endif %}</h5> | 6 | <h5>{{ 'Relatório gerado em'|trans }} {% if idioma == 'pt_BR' %}{{ "now"|date("d/m/Y H\\hi") }}{% else %}{{ "now"|date("m/d/Y H\\hi") }}{% endif %}</h5> |
7 | 7 | ||
8 | + <form id="csv" action="{{ path('cacic_relatorio_csv_hardware_wmi', {'classe': classe}) }}" method="post"> | ||
9 | + {% for elm, value in filtros %} | ||
10 | + <input type="hidden" name="{{ elm }}" value="{{ value }}"> | ||
11 | + {% endfor %} | ||
12 | + <button class="btn btn-primary" type="submit"> | ||
13 | + <i class="icon-bar-chart"></i> | ||
14 | + Gerar CSV | ||
15 | + </button> | ||
16 | + </form> | ||
17 | + | ||
8 | <hr /> | 18 | <hr /> |
9 | 19 | ||
10 | -<table class="table table-striped table-bordered"> | 20 | + |
21 | +<table class="display datatable" id="datatable"> | ||
11 | <thead> | 22 | <thead> |
12 | <tr> | 23 | <tr> |
13 | - <th width="10%">{{ "Sistema Operacional"|trans }}</th> | 24 | + <th width="20%">{{ "Sistema Operacional"|trans }}</th> |
14 | <th width="10%">{{ "Local"|trans }}</th> | 25 | <th width="10%">{{ "Local"|trans }}</th> |
15 | - <th width="10%">{{ "Subrede"|trans }}</th> | 26 | + <th width="20%">{{ "Subrede"|trans }}</th> |
16 | <th width="10%">{{ "Propriedade"|trans }}</th> | 27 | <th width="10%">{{ "Propriedade"|trans }}</th> |
17 | <th width="10%">{{ "Computadores"|trans }}</th> | 28 | <th width="10%">{{ "Computadores"|trans }}</th> |
18 | <th>{{ "Valor"|trans }}</th> | 29 | <th>{{ "Valor"|trans }}</th> |
@@ -22,7 +33,7 @@ | @@ -22,7 +33,7 @@ | ||
22 | <tbody> | 33 | <tbody> |
23 | {% for reg in dados %} | 34 | {% for reg in dados %} |
24 | <tr> | 35 | <tr> |
25 | - <td><span class="{% if reg.inMswindows == 'S' %}red{% else %}blue{% endif %}"><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'so': reg.idSo}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.sgSo }}</a></span></td> | 36 | + <td><span class="{% if reg.inMswindows == 'S' %}red{% else %}blue{% endif %}"><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'so': reg.idSo}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.teDescSo }}</a></span></td> |
26 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'local': reg.idLocal}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmLocal }}</a></td> | 37 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'local': reg.idLocal}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmLocal }}</a></td> |
27 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'rede': reg.idRede}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmRede }} / {{ reg.teIpRede }}</a></td> | 38 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName, 'rede': reg.idRede}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmRede }} / {{ reg.teIpRede }}</a></td> |
28 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmPropertyName }}</a></td> | 39 | <td><a href="{{ path('cacic_relatorio_hardware_wmi_detalhe', {'classe': classe, 'propriedade': reg.nmPropertyName}) }}" title="{{ "Lista de computadores"|trans }}" target="_blank">{{ reg.nmPropertyName }}</a></td> |
src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi_detalhe.html.twig
@@ -6,9 +6,19 @@ | @@ -6,9 +6,19 @@ | ||
6 | <h3>{{ 'Dados relativos à Propriedade '|trans }}{{ propriedade }}</h3> | 6 | <h3>{{ 'Dados relativos à Propriedade '|trans }}{{ propriedade }}</h3> |
7 | <h5>{{ 'Relatório gerado em'|trans }} {% if idioma == 'pt_BR' %}{{ "now"|date("d/m/Y H\\hi") }}{% else %}{{ "now"|date("m/d/Y H\\hi") }}{% endif %}</h5> | 7 | <h5>{{ 'Relatório gerado em'|trans }} {% if idioma == 'pt_BR' %}{{ "now"|date("d/m/Y H\\hi") }}{% else %}{{ "now"|date("m/d/Y H\\hi") }}{% endif %}</h5> |
8 | 8 | ||
9 | + <form id="csv" action="{{ path('cacic_relatorio_csv_hardware_wmi_detalhe', { 'classe': classe, 'propriedade': propriedade }) }}" method="post"> | ||
10 | + {% for elm, value in filtros %} | ||
11 | + <input type="hidden" name="{{ elm }}" value="{{ value }}"> | ||
12 | + {% endfor %} | ||
13 | + <button class="btn btn-primary" type="submit"> | ||
14 | + <i class="icon-bar-chart"></i> | ||
15 | + Gerar CSV | ||
16 | + </button> | ||
17 | + </form> | ||
18 | + | ||
9 | <hr /> | 19 | <hr /> |
10 | 20 | ||
11 | -<table class="table table-striped table-bordered"> | 21 | +<table class="display datatable" id="datatable"> |
12 | <thead> | 22 | <thead> |
13 | <tr> | 23 | <tr> |
14 | <th width="10%">{{ "Computador"|trans }}</th> | 24 | <th width="10%">{{ "Computador"|trans }}</th> |