diff --git a/Controller/PrinterController.php b/Controller/PrinterController.php
new file mode 100755
index 0000000..d51018e
--- /dev/null
+++ b/Controller/PrinterController.php
@@ -0,0 +1,437 @@
+getDoctrine()->getManager();
+
+ $entities = $em->getRepository('CocarBundle:Printer')->findAll();
+
+ return array(
+ 'entities' => $entities,
+ );
+ }
+ /**
+ * Creates a new Printer entity.
+ *
+ * @Route("/", name="printer_create")
+ * @Method("POST")
+ * @Template("CocarBundle:Printer:new.html.twig")
+ */
+ public function createAction(Request $request)
+ {
+ $entity = new Printer();
+ $form = $this->createCreateForm($entity);
+ $form->handleRequest($request);
+
+ if ($form->isValid())
+ {
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entity);
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('printer_show', array('id' => $entity->getId())));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView(),
+ );
+ }
+
+ /**
+ * Creates a form to create a Printer entity.
+ *
+ * @param Printer $entity The entity
+ *
+ * @return \Symfony\Component\Form\Form The form
+ */
+ private function createCreateForm(Printer $entity)
+ {
+ $form = $this->createForm(new PrinterType(), $entity, array(
+ 'action' => $this->generateUrl('printer_create'),
+ 'method' => 'POST',
+ ));
+
+ $form->add('submit', 'submit', array('label' => 'Create'));
+
+ return $form;
+ }
+
+ /**
+ * Displays a form to create a new Printer entity.
+ *
+ * @Route("/new", name="printer_new")
+ * @Method("GET")
+ * @Template()
+ */
+ public function newAction()
+ {
+ $entity = new Printer();
+ $form = $this->createCreateForm($entity);
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView(),
+ );
+ }
+
+ /**
+ * Finds and displays a Printer entity.
+ *
+ * @Route("/{id}", name="printer_show")
+ * @Method("GET")
+ * @Template()
+ */
+ public function showAction($id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('CocarBundle:Printer')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find Printer entity.');
+ }
+
+ $deleteForm = $this->createDeleteForm($id);
+
+ return array(
+ 'entity' => $entity,
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Displays a form to edit an existing Printer entity.
+ *
+ * @Route("/{id}/edit", name="printer_edit")
+ * @Method("GET")
+ * @Template()
+ */
+ public function editAction($id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('CocarBundle:Printer')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find Printer entity.');
+ }
+
+ $editForm = $this->createEditForm($entity);
+ $deleteForm = $this->createDeleteForm($id);
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Creates a form to edit a Printer entity.
+ *
+ * @param Printer $entity The entity
+ *
+ * @return \Symfony\Component\Form\Form The form
+ */
+ private function createEditForm(Printer $entity)
+ {
+ $form = $this->createForm(new PrinterType(), $entity, array(
+ 'action' => $this->generateUrl('printer_update', array('id' => $entity->getId())),
+ 'method' => 'PUT',
+ ));
+
+ $form->add('submit', 'submit', array('label' => 'Update'));
+
+ return $form;
+ }
+ /**
+ * Edits an existing Printer entity.
+ *
+ * @Route("/{id}", name="printer_update")
+ * @Method("PUT")
+ * @Template("CocarBundle:Printer:edit.html.twig")
+ */
+ public function updateAction(Request $request, $id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('CocarBundle:Printer')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find Printer entity.');
+ }
+
+ $deleteForm = $this->createDeleteForm($id);
+ $editForm = $this->createEditForm($entity);
+ $editForm->handleRequest($request);
+
+ if ($editForm->isValid()) {
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('printer_edit', array('id' => $id)));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+ /**
+ * Deletes a Printer entity.
+ *
+ * @Route("/{id}", name="printer_delete")
+ * @Method("DELETE")
+ */
+ public function deleteAction(Request $request, $id)
+ {
+ $form = $this->createDeleteForm($id);
+ $form->handleRequest($request);
+
+ if ($form->isValid()) {
+ $em = $this->getDoctrine()->getManager();
+ $entity = $em->getRepository('CocarBundle:Printer')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find Printer entity.');
+ }
+
+ $em->remove($entity);
+ $em->flush();
+ }
+
+ return $this->redirect($this->generateUrl('printer'));
+ }
+
+ /**
+ * Creates a form to delete a Printer entity by id.
+ *
+ * @param mixed $id The entity id
+ *
+ * @return \Symfony\Component\Form\Form The form
+ */
+ private function createDeleteForm($id)
+ {
+ return $this->createFormBuilder()
+ ->setAction($this->generateUrl('printer_delete', array('id' => $id)))
+ ->setMethod('DELETE')
+ ->getForm()
+ ;
+ }
+
+ /**
+ * @Route("/reports/{id}", name="cocar_printer_reports")
+ * @Template()
+ */
+ public function reportsAction($id, Request $request)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ if($request->request->get('form'))
+ {
+ $start = new \DateTime($request->request->get('form')['startDate']);
+ $start = $start->format('U');
+
+ $end = new \DateTime($request->request->get('form')['endDate']);
+ $end = $end->format('U');
+ }
+
+ $start = isset($start) ? $start : (time() - ((60*60*24)*30));
+ $end = isset($end) ? $end : time();
+
+ $printerCounter = $em->createQuery(
+ "SELECT pc.id, pc.prints, pc.blackInk, pc.coloredInk FROM CocarBundle:PrinterCounter pc
+ WHERE (pc.date >= :start AND pc.date <= :end) AND (pc.printer = :id)
+ ORDER BY pc.id ASC"
+ )
+ ->setParameter('start', $start)
+ ->setParameter('end', $end)
+ ->setParameter('id', $id)
+ ->getResult();
+
+ $pCounter = array();
+
+ foreach ($printerCounter as $counter)
+ {
+ if($counter === reset($printerCounter))
+ {
+ $pCounter['prints'] = $counter['prints'];
+ }
+
+ if ($counter === end($printerCounter))
+ {
+ $pCounter['prints'] = $counter['prints'] - $pCounter['prints'];
+ $pCounter['blackInk'] = $counter['blackInk'];
+ $pCounter['coloredInk'] = $counter['coloredInk'];
+ }
+ }
+
+ $printer = $em->getRepository('CocarBundle:Printer')->find($id);
+
+
+ return array(
+ "printer" => $printer,
+ "printerCounter" => $pCounter,
+ "form" => $this->createCalendarForm($id, new \DateTime(date("Y-m-d", $start)), new \DateTime(date("Y-m-d", $end)))->createView(),
+ "start" => $start,
+ "end" => $end
+ );
+ }
+
+ /**
+ * Creates a form to reports
+ *
+ * @param mixed $id The entity id
+ *
+ * @return \Symfony\Component\Form\Form The form
+ */
+ private function createCalendarForm($id, $start, $end)
+ {
+ return $this->createFormBuilder()
+ ->add('startDate', 'date', array('widget' => 'single_text', 'data' => $start))
+ ->add('endDate', 'date', array('widget' => 'single_text', 'data' => $end))
+ ->add('printer', 'hidden', array(
+ 'data' => $id
+ ))
+ ->getForm();
+ }
+
+ /**
+ * @Route("/totalizer/info", name="cocar_totalizer_info")
+ * @Template()
+ */
+ public function totalizerAction()
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $printers = $em->getRepository('CocarBundle:Printer')->findAll();
+
+ foreach($printers as $printer)
+ {
+ try
+ {
+ $community = $printer->getCommunitySnmpPrinter();
+ $host = $printer->getHost();
+
+ $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1";
+
+ if($outPut = shell_exec($com))
+ {
+ $this->updateCounter($printer, $outPut);
+ $this->createOrUpdateGraph($printer, $outPut);
+ }
+ }
+ catch(Exception $e)
+ {
+ return new Response($e->getMessage());
+ }
+ }
+ return new Response();
+ }
+
+ /**
+ * Update table by id
+ */
+ private function updateCounter($printer, $prints)
+ {
+ try
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $counter = new PrinterCounter;
+
+ $counter->setPrinter($printer);
+ $counter->setPrints($prints);
+ $counter->setDate(time());
+
+ $em->persist($counter);
+ $em->flush();
+ }
+ catch(\Exception $e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Update graphic counter by id
+ */
+ private function createOrUpdateGraph($printer, $prints)
+ {
+ try
+ {
+ $this->dir = $this->get('kernel')->getRootDir() . "/../web/rrd/graficos/";
+
+ $arqRrd = $this->dir . "printer_" . $printer->getId() . '.rrd';
+
+ if (!file_exists($arqRrd))
+ $this->createRrd($arqRrd);
+ $this->updateRrd($arqRrd, $prints);
+
+ }
+ catch(\Exception $e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public function createRrd($arqRrd)
+ {
+ $create = "rrdtool create $arqRrd --step 60 " .
+ "DS:ds0:COUNTER:120:0:125000000 " .
+ "DS:ds1:COUNTER:120:0:125000000 " .
+ "RRA:AVERAGE:0.5:1:4320 " .
+ "RRA:AVERAGE:0.5:5:2016 " .
+ "RRA:AVERAGE:0.5:20:2232 " .
+ "RRA:AVERAGE:0.5:90:2976 " .
+ "RRA:AVERAGE:0.5:360:1460 " .
+ "RRA:AVERAGE:0.5:1440:730 " .
+ "RRA:MAX:0.5:1:4320 " .
+ "RRA:MAX:0.5:5:2016 " .
+ "RRA:MAX:0.5:20:2232 " .
+ "RRA:MAX:0.5:90:2976 " .
+ "RRA:MAX:0.5:360:1460 " .
+ "RRA:MAX:0.5:1440:730";
+ echo $create;die;
+ shell_exec($create);
+ }
+
+ public function updateRrd($arqRrd, $prints, $date = null)
+ {
+ $date = empty($date) ? date('U') : $date;
+ shell_exec("rrdtool update $arqRrd $date:$prints:0");
+ }
+}
diff --git a/Entity/Printer.php b/Entity/Printer.php
new file mode 100755
index 0000000..40a68c6
--- /dev/null
+++ b/Entity/Printer.php
@@ -0,0 +1,200 @@
+printerCounter = new ArrayCollection();
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ * @return Printer
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set description
+ *
+ * @param string $description
+ * @return Printer
+ */
+ public function setDescription($description)
+ {
+ $this->description = $description;
+
+ return $this;
+ }
+
+ /**
+ * Get description
+ *
+ * @return string
+ */
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ /**
+ * Set communitySnmpPrinter
+ *
+ * @param string $communitySnmpPrinter
+ * @return Printer
+ */
+ public function setCommunitySnmpPrinter($communitySnmpPrinter)
+ {
+ $this->communitySnmpPrinter = $communitySnmpPrinter;
+
+ return $this;
+ }
+
+ /**
+ * Get communitySnmpPrinter
+ *
+ * @return string
+ */
+ public function getCommunitySnmpPrinter()
+ {
+ return $this->communitySnmpPrinter;
+ }
+
+ /**
+ * Set host
+ *
+ * @param string $host
+ * @return Printer
+ */
+ public function setHost($host)
+ {
+ $this->host = $host;
+
+ return $this;
+ }
+
+ /**
+ * Get host
+ *
+ * @return string
+ */
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ /**
+ * Add printerCounter
+ *
+ * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter
+ * @return Entity
+ */
+ public function addPrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter)
+ {
+ $this->printerCounter[] = $printerCounter;
+
+ return $this;
+ }
+
+ /**
+ * Remove printerCounter
+ *
+ * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter
+ */
+ public function removePrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter)
+ {
+ $this->printerCounter->removeElement($printerCounter);
+ }
+
+ /**
+ * Get printerCounter
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getPrinterCounter()
+ {
+ return $this->printerCounter;
+ }
+}
diff --git a/Entity/PrinterCounter.php b/Entity/PrinterCounter.php
new file mode 100755
index 0000000..724dda4
--- /dev/null
+++ b/Entity/PrinterCounter.php
@@ -0,0 +1,189 @@
+printer = 0;
+ $this->coloredInk = 0;
+ $this->blackInk = 0;
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set blackInk
+ *
+ * @param integer $blackInk
+ * @return PrinterCounter
+ */
+ public function setBlackInk($blackInk)
+ {
+ $this->blackInk = $blackInk;
+
+ return $this;
+ }
+
+ /**
+ * Get blackInk
+ *
+ * @return integer
+ */
+ public function getBlackInk()
+ {
+ return $this->blackInk;
+ }
+
+ /**
+ * Set coloredInk
+ *
+ * @param integer $coloredInk
+ * @return PrinterCounter
+ */
+ public function setColoredInk($coloredInk)
+ {
+ $this->coloredInk = $coloredInk;
+
+ return $this;
+ }
+
+ /**
+ * Get coloredInk
+ *
+ * @return integer
+ */
+ public function getColoredInk()
+ {
+ return $this->coloredInk;
+ }
+
+ /**
+ * Set prints
+ *
+ * @param integer $prints
+ * @return PrinterCounter
+ */
+ public function setPrints($prints)
+ {
+ $this->prints = $prints;
+
+ return $this;
+ }
+
+ /**
+ * Get prints
+ *
+ * @return integer
+ */
+ public function getPrints()
+ {
+ return $this->prints;
+ }
+
+ /**
+ * Set date
+ *
+ * @param integer $date
+ * @return PrinterCounter
+ */
+ public function setDate($date)
+ {
+ $this->date = $date;
+
+ return $this;
+ }
+
+ /**
+ * Get date
+ *
+ * @return integer
+ */
+ public function getDate()
+ {
+ return $this->date;
+ }
+
+ /**
+ * Set printer
+ *
+ * @param \Cocar\CocarBundle\Entity\Printer $printer
+ * @return Circuits
+ */
+ public function setPrinter(\Swpb\Bundle\CocarBundle\Entity\Printer $printer = null)
+ {
+ $this->printer = $printer;
+
+ return $this;
+ }
+
+ /**
+ * Get printer
+ *
+ * @return \Cocar\CocarBundle\Entity\Printer
+ */
+ public function getPrinter()
+ {
+ return $this->printer;
+ }
+}
diff --git a/Entity/PrinterCounterRepository.php b/Entity/PrinterCounterRepository.php
new file mode 100755
index 0000000..e702e88
--- /dev/null
+++ b/Entity/PrinterCounterRepository.php
@@ -0,0 +1,15 @@
+add('name')
+ ->add('description')
+ ->add('communitySnmpPrinter')
+ ->add('host')
+ ;
+ }
+
+ /**
+ * @param OptionsResolverInterface $resolver
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ $resolver->setDefaults(array(
+ 'data_class' => 'Swpb\Bundle\CocarBundle\Entity\Printer'
+ ));
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return 'swpb_bundle_cocarbundle_printer';
+ }
+}
diff --git a/Resources/public/images/circuitos.png b/Resources/public/images/circuitos.png
new file mode 100644
index 0000000..f6f52da
Binary files /dev/null and b/Resources/public/images/circuitos.png differ
diff --git a/Resources/public/images/entidades.png b/Resources/public/images/entidades.png
new file mode 100644
index 0000000..cf6a282
Binary files /dev/null and b/Resources/public/images/entidades.png differ
diff --git a/Resources/public/images/help.png b/Resources/public/images/help.png
new file mode 100644
index 0000000..e1a4d92
Binary files /dev/null and b/Resources/public/images/help.png differ
diff --git a/Resources/public/images/home.png b/Resources/public/images/home.png
new file mode 100644
index 0000000..e494996
Binary files /dev/null and b/Resources/public/images/home.png differ
diff --git a/Resources/public/images/ico1.png b/Resources/public/images/ico1.png
new file mode 100644
index 0000000..9721ea8
Binary files /dev/null and b/Resources/public/images/ico1.png differ
diff --git a/Resources/public/images/ico2.png b/Resources/public/images/ico2.png
new file mode 100644
index 0000000..6413d7d
Binary files /dev/null and b/Resources/public/images/ico2.png differ
diff --git a/Resources/public/images/relatorios.png b/Resources/public/images/relatorios.png
new file mode 100644
index 0000000..58759b8
Binary files /dev/null and b/Resources/public/images/relatorios.png differ
diff --git a/Resources/public/images/table.png b/Resources/public/images/table.png
new file mode 100644
index 0000000..1c19cb4
Binary files /dev/null and b/Resources/public/images/table.png differ
diff --git a/Resources/views/Printer/edit.html.twig b/Resources/views/Printer/edit.html.twig
new file mode 100755
index 0000000..6e3bcb5
--- /dev/null
+++ b/Resources/views/Printer/edit.html.twig
@@ -0,0 +1,47 @@
+{% extends 'CocarBundle::layout.html.twig' %}
+
+{% block main -%}
+
{{ entity.description }}
+
+
+
+
+{% endblock %}
diff --git a/Resources/views/Printer/index.html.twig b/Resources/views/Printer/index.html.twig
new file mode 100755
index 0000000..51177b1
--- /dev/null
+++ b/Resources/views/Printer/index.html.twig
@@ -0,0 +1,50 @@
+{% extends 'CocarBundle::layout.html.twig' %}
+
+{% block main -%}
+ Impressoras cadastradas
+
+
+
+
+ Id |
+ Name |
+ Description |
+ Community |
+ Host |
+ Actions |
+
+
+
+ {% for entity in entities %}
+
+ {{ entity.id }} |
+ {{ entity.name }} |
+ {{ entity.description }} |
+ {{ entity.communitySnmpPrinter }} |
+ {{ entity.host }} |
+
+
+ |
+
+ {% endfor %}
+
+
+
+
+ {% endblock %}
diff --git a/Resources/views/Printer/new.html.twig b/Resources/views/Printer/new.html.twig
new file mode 100755
index 0000000..a425a50
--- /dev/null
+++ b/Resources/views/Printer/new.html.twig
@@ -0,0 +1,32 @@
+{% extends 'CocarBundle::layout.html.twig' %}
+
+{% block main -%}
+ Cadastro de Impressoras
+
+
+
+{% endblock %}
diff --git a/Resources/views/Printer/reports.html.twig b/Resources/views/Printer/reports.html.twig
new file mode 100644
index 0000000..d5a1261
--- /dev/null
+++ b/Resources/views/Printer/reports.html.twig
@@ -0,0 +1,35 @@
+{% extends 'CocarBundle::layout.html.twig' %}
+
+{% block main -%}
+ {{ printer.name }}
+ {{ start|date("d/m/Y") }} a {{ end|date("d/m/Y") }}
+
+
+
+
+
+
+ Total de impressões |
+ Nível de tinta Preta |
+ Nível de tinta Colorida |
+
+
+
+
+ {% for p in printerCounter %}
+ {{ p }} |
+ {% endfor %}
+
+
+
+
+{% endblock %}
diff --git a/Resources/views/Printer/show.html.twig b/Resources/views/Printer/show.html.twig
new file mode 100755
index 0000000..4e49a6a
--- /dev/null
+++ b/Resources/views/Printer/show.html.twig
@@ -0,0 +1,46 @@
+{% extends 'CocarBundle::layout.html.twig' %}
+
+{% block main -%}
+ Impressora
+
+
+
+
+ Id |
+ Name |
+ Description |
+ Community |
+ Host |
+
+
+
+
+ {{ entity.id }} |
+ {{ entity.name }} |
+ {{ entity.description }} |
+ {{ entity.communitySnmpPrinter }} |
+ {{ entity.host }} |
+
+
+
+
+
+{% endblock %}
diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig
index fb8ec35..337bc6e 100755
--- a/Resources/views/layout.html.twig
+++ b/Resources/views/layout.html.twig
@@ -19,6 +19,12 @@
+
+
+ Impressoras
+
+
+
Circuitos
@@ -82,7 +88,7 @@