diff --git a/data/database.sqlite b/data/database.sqlite index 6804099..23bf42a 100755 Binary files a/data/database.sqlite and b/data/database.sqlite differ diff --git a/src/Controller/ImovelController.php b/src/Controller/ImovelController.php index 5cbf296..3c775b5 100644 --- a/src/Controller/ImovelController.php +++ b/src/Controller/ImovelController.php @@ -6,6 +6,7 @@ use App\Entity\Imovel; use App\Forms\ImovelType; +use App\Service\ImovelService; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; @@ -19,7 +20,7 @@ class ImovelController extends AbstractController * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function cadastroImovel(Request $request) + public function cadastroImovel(Request $request, ImovelService $imovelservice) { $imovel = new Imovel(); @@ -28,9 +29,7 @@ public function cadastroImovel(Request $request) if ($form->isSubmitted()) { $imovel = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->persist($imovel); - $em->flush(); + $imovelservice->salvar($imovel); return $this->redirectToRoute('index'); } @@ -81,6 +80,43 @@ public function imovelVisualizar(Request $request) ]); } + /** + * @Route("/editar_imovel/{id}", name="editar_imovel") + */ + public function editarImovel(int $id, Request $request, ImovelService $imovelservice) + { + $em = $this->getDoctrine()->getManager(); + $imovel = $em->getRepository(Imovel::class)->find($id); + + if (!$imovel) { + throw new \Exception('Imóvel não encontrado'); + } + + $form = $this->createForm(ImovelType::class, $imovel); + + $form->handleRequest($request); + + if ($form->isSubmitted()) { + $imovel = $form->getData(); + $imovelservice->atualizar($imovel); + + return $this->redirectToRoute('listar_imoveis'); + } + return $this->render('imovel_cadastro.html.twig', [ + 'form' => $form->createView() + ]); + } + + /** + * @Route("/deletar_imovel/{id}", name="deletar_imovel") + */ + public function deletarImovel(int $id, Request $request, ImovelService $imovelservice) + { + $imovelservice->remover($id); + $this->addFlash('success', 'Imóvel de id:' . $id . ' deletado com sucesso!!!'); + + return $this->redirectToRoute('listar_imoveis'); + } } \ No newline at end of file diff --git a/src/Controller/UsuarioController.php b/src/Controller/UsuarioController.php index f1facd9..93ce8e7 100644 --- a/src/Controller/UsuarioController.php +++ b/src/Controller/UsuarioController.php @@ -6,6 +6,7 @@ use App\Entity\Corretor; use App\Forms\UsuarioType; use App\Entity\Usuario; +use App\Service\UsuarioService; use phpDocumentor\Reflection\DocBlock\Tags\Throws; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; @@ -21,10 +22,9 @@ class UsuarioController extends AbstractController { /** - *@IsGranted("ROLE_ADMIN") * @Route("/usuario", name="usuario_novo") */ - public function cadastroUsuario(Request $request) + public function cadastroUsuario(Request $request, UsuarioService $usuarioservice) { $usuario = new Usuario(); $form = $this->createForm(UsuarioType::class, $usuario); @@ -32,9 +32,7 @@ public function cadastroUsuario(Request $request) if ($form->isSubmitted()) { $usuario = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->persist($usuario); - $em->flush(); + $usuarioservice->salvar($usuario); return $this->redirectToRoute('index'); } @@ -71,7 +69,7 @@ public function listarUsuarios(Request $request) /** * @Route("/editar/{id}", name="editar_usuario") */ - public function editarUsuario(int $id, Request $request) + public function editarUsuario(int $id, Request $request, UsuarioService $usuarioservice) { $em = $this->getDoctrine()->getManager(); $usuario = $em->getRepository(Usuario::class)->find($id); @@ -86,9 +84,7 @@ public function editarUsuario(int $id, Request $request) if ($form->isSubmitted()) { $usuario = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->merge($usuario); - $em->flush(); + $usuarioservice->atualizar($usuario); return $this->redirectToRoute('listar_usuarios'); } @@ -101,12 +97,9 @@ public function editarUsuario(int $id, Request $request) /** * @Route("/deletar/{id}", name="deletar_usuario") */ - public function deletarUsuario(int $id, Request $request) + public function deletarUsuario(int $id, Request $request, UsuarioService $usuarioService) { - $em = $this->getDoctrine()->getManager(); - $usuario = $em->getRepository(Usuario::class)->find($id); - $em->remove($usuario); - $em->flush(); + $usuarioService->remover($id); $this->addFlash('success', 'Usuario de id:'.$id.' deletado com sucesso!!!'); return $this->redirectToRoute('listar_usuarios'); diff --git a/src/Entity/ContratoAdm.php b/src/Entity/ContratoAdm.php new file mode 100644 index 0000000..d641947 --- /dev/null +++ b/src/Entity/ContratoAdm.php @@ -0,0 +1,121 @@ +id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getDtCadastro() + { + return $this->dt_cadastro; + } + + /** + * @param mixed $dt_cadastro + */ + public function setDtCadastro($dt_cadastro): void + { + $this->dt_cadastro = $dt_cadastro; + } + + /** + * @return mixed + */ + public function getUsusarioId() + { + return $this->ususario_id; + } + + /** + * @param mixed $ususario_id + */ + public function setUsusarioId($ususario_id): void + { + $this->ususario_id = $ususario_id; + } + + /** + * @return mixed + */ + public function getImovelId() + { + return $this->imovel_id; + } + + /** + * @param mixed $imovel_id + */ + public function setImovelId($imovel_id): void + { + $this->imovel_id = $imovel_id; + } + + /** + * @return mixed + */ + public function getClausulaContratual() + { + return $this->clausula_contratual; + } + + /** + * @param mixed $clausula_contratual + */ + public function setClausulaContratual($clausula_contratual): void + { + $this->clausula_contratual = $clausula_contratual; + } + +} \ No newline at end of file diff --git a/src/Entity/ContratoLocacao.php b/src/Entity/ContratoLocacao.php new file mode 100644 index 0000000..9bc07a7 --- /dev/null +++ b/src/Entity/ContratoLocacao.php @@ -0,0 +1,181 @@ +id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getDtCadastro() + { + return $this->dt_cadastro; + } + + /** + * @param mixed $dt_cadastro + */ + public function setDtCadastro($dt_cadastro): void + { + $this->dt_cadastro = $dt_cadastro; + } + + /** + * @return mixed + */ + public function getDtValidade() + { + return $this->dt_validade; + } + + /** + * @param mixed $dt_validade + */ + public function setDtValidade($dt_validade): void + { + $this->dt_validade = $dt_validade; + } + + /** + * @return mixed + */ + public function getFormaPagamento() + { + return $this->forma_pagamento; + } + + /** + * @param mixed $forma_pagamento + */ + public function setFormaPagamento($forma_pagamento): void + { + $this->forma_pagamento = $forma_pagamento; + } + + /** + * @return mixed + */ + public function getDtVencimento() + { + return $this->dt_vencimento; + } + + /** + * @param mixed $dt_vencimento + */ + public function setDtVencimento($dt_vencimento): void + { + $this->dt_vencimento = $dt_vencimento; + } + + /** + * @return mixed + */ + public function getUsusarioId() + { + return $this->ususario_id; + } + + /** + * @param mixed $ususario_id + */ + public function setUsusarioId($ususario_id): void + { + $this->ususario_id = $ususario_id; + } + + /** + * @return mixed + */ + public function getImovelId() + { + return $this->imovel_id; + } + + /** + * @param mixed $imovel_id + */ + public function setImovelId($imovel_id): void + { + $this->imovel_id = $imovel_id; + } + + /** + * @return mixed + */ + public function getClausulaContratual() + { + return $this->clausula_contratual; + } + + /** + * @param mixed $clausula_contratual + */ + public function setClausulaContratual($clausula_contratual): void + { + $this->clausula_contratual = $clausula_contratual; + } + + +} \ No newline at end of file diff --git a/src/Entity/Usuario.php b/src/Entity/Usuario.php index 692db37..e532e0d 100644 --- a/src/Entity/Usuario.php +++ b/src/Entity/Usuario.php @@ -52,11 +52,6 @@ class Usuario */ private $endereco; - /** -// * @ORM\OneToMany(targetEntity="Entity\contratoLocacao", mappedBy="usuario") -// */ -// private $contratoLocacao; - // /** // * @ORM\OneToMany(targetEntity="Entity\ContratoAdm", mappedBy="usuario") // */ diff --git a/src/Forms/ImovelType.php b/src/Forms/ImovelType.php index 14fb62a..fa2b1d0 100755 --- a/src/Forms/ImovelType.php +++ b/src/Forms/ImovelType.php @@ -26,25 +26,25 @@ class ImovelType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder -// ->setAction('../usuario') +// ->setAction('../imovel') // ->setMethod('POST') ->add('status', ChoiceType::class, [ 'label' => 'Status', 'choices' => [ - 'Disponivel' => 'disponivel', + 'Disponível' => 'disponivel', 'Alugado' => 'alugado', 'Em Manutenção' => 'Em Manutenção', - 'Vistoria' => 'Vistoria', + 'Vistória' => 'Vistoria', 'Sem Cotrato Adm' => 'Sem Cotrato Adm', 'Sem Contrato de Locação' => 'Sem Contrato de Locação' ] ]) ->add('caracteristicas', TextType::class, [ - 'label' => 'Caracterisiticas do Imovel', + 'label' => 'Características do Imóvel' ]) ->add('observacao', TextType::class, [ - 'label' => 'Observações Geral', + 'label' => 'Observações Gerais', ]) ->add('tipoImovel', ChoiceType::class, [ 'empty_data' => 'Casa', diff --git a/src/Forms/UsuarioType.php b/src/Forms/UsuarioType.php index 486f2bf..198f781 100755 --- a/src/Forms/UsuarioType.php +++ b/src/Forms/UsuarioType.php @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ] ]) ->add('sexo', TextType::class, [ - 'label' => 'Sexto', + 'label' => 'Sexo', ]) ->add('email', EmailType::class, [ 'label' => 'Email', diff --git a/src/Repository/ImovelRepository.php b/src/Repository/ImovelRepository.php new file mode 100644 index 0000000..a5f526a --- /dev/null +++ b/src/Repository/ImovelRepository.php @@ -0,0 +1,55 @@ +getEntityManager(); + $em->persist($imovel); + $em->flush(); + } + + /** + * @param Imovel $imovel + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function atualizar(Imovel $imovel) + { + $em = $this->getEntityManager(); + $em->merge($imovel); + $em->flush(); + } + + /** + * @param int $id + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function remover(int $id) + { + $em = $this->getEntityManager(); + $imovel = $em->getRepository(Imovel::class)->find($id); + $em->remove($imovel); + $em->flush(); + } + +} \ No newline at end of file diff --git a/src/Repository/UsuarioRepository.php b/src/Repository/UsuarioRepository.php new file mode 100644 index 0000000..600454b --- /dev/null +++ b/src/Repository/UsuarioRepository.php @@ -0,0 +1,55 @@ +getEntityManager(); + $em->persist($usuario); + $em->flush(); + } + + /** + * @param Usuario $usuario + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function atualizar(Usuario $usuario) + { + $em = $this->getEntityManager(); + $em->merge($usuario); + $em->flush(); + } + + /** + * @param int $id + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function remover(int $id) + { + $em = $this->getEntityManager(); + $usuario = $em->getRepository(Usuario::class)->find($id); + $em->remove($usuario); + $em->flush(); + } + +} \ No newline at end of file diff --git a/src/Service/ImovelService.php b/src/Service/ImovelService.php new file mode 100644 index 0000000..feb075e --- /dev/null +++ b/src/Service/ImovelService.php @@ -0,0 +1,34 @@ +imovelrepository = $imovelrepository; + } + + public function salvar(Imovel $imovel) + { + $this->imovelrepository->salvar($imovel); + } + + public function atualizar(Imovel $imovel) + { + $this->imovelrepository->atualizar($imovel); + } + + public function remover(int $id) + { + $this->imovelrepository->remover($id); + } + +} \ No newline at end of file diff --git a/src/Service/UsuarioService.php b/src/Service/UsuarioService.php new file mode 100644 index 0000000..0254bd3 --- /dev/null +++ b/src/Service/UsuarioService.php @@ -0,0 +1,34 @@ +usuarioRepository = $usuarioRepository; + } + + public function salvar(Usuario $usuario) + { + $this->usuarioRepository->salvar($usuario); + } + + public function atualizar(Usuario $usuario) + { + $this->usuarioRepository->atualizar($usuario); + } + + public function remover(int $id) + { + $this->usuarioRepository->remover($id); + } + +} \ No newline at end of file diff --git a/templates/imovel_cadastro.html.twig b/templates/imovel_cadastro.html.twig index 9e378da..2508484 100644 --- a/templates/imovel_cadastro.html.twig +++ b/templates/imovel_cadastro.html.twig @@ -5,16 +5,81 @@

Cadastro de Imóveis

+ {{ form_start(form) }} +
+
+ {{ form_row(form.status) }} +
+
+ {{ form_row(form.tipoImovel) }} +
-
- {{ form_start(form) }} - {{ form_widget(form) }} +
+
+
+ {{ form_row(form.observacao) }} +
+
+ {{ form_row(form.caracteristicas) }} +
- +
+
+
+ {{ form_row(form.dtCadastro) }} +
+
+

Endereço

+
+
+ {{ form_row(form.endereco.logradouro) }} +
+
+ {{ form_row(form.endereco.numero) }} +
+
+
+
+ {{ form_row(form.endereco.bairro) }} +
+
+ {{ form_row(form.endereco.cep) }} +
+
+
+
+ {{ form_row(form.endereco.cidade) }} +
+
+ {{ form_row(form.endereco.uf) }} +
+
+
+
+ {{ form_row(form.endereco.complemento) }} +
+
+
+
+ {{ form_row(form.endereco.dddTelefone) }} +
+
+ {{ form_row(form.endereco.telefone) }} +
+
+
+
+ {{ form_row(form.endereco.dddCelular) }} +
+
+ {{ form_row(form.endereco.celular) }} +
+
+ + + {{ form_end(form) }} - {{ form_end(form) }} -
diff --git a/templates/listar_imoveis.html.twig b/templates/listar_imoveis.html.twig index 6af1973..f37f68f 100644 --- a/templates/listar_imoveis.html.twig +++ b/templates/listar_imoveis.html.twig @@ -14,23 +14,25 @@ Status - Caracterisitcas - Observacao - Tipo do Imovel + Características + Observação + Tipo do Imóvel Data Cadastro Bairro Rua + Editar/Deletar Status - Caracterisitcas - Observacao - Tipo do Imovel + Características + Observação + Tipo do Imóvel Data Cadastro Bairro Rua + Editar/Deletar @@ -45,9 +47,13 @@ {{ imovel.dtCadastro|date("m/d/Y") }} {{ imovel.endereco.bairro }} {{ imovel.endereco.logradouro }} - + - + + + + + {% endfor %} @@ -62,21 +68,21 @@ - - + + - + - + - - + + - + diff --git a/templates/usuario_cadastro.html.twig b/templates/usuario_cadastro.html.twig index b994c77..c635c6d 100644 --- a/templates/usuario_cadastro.html.twig +++ b/templates/usuario_cadastro.html.twig @@ -83,7 +83,7 @@ -{% include "footer.html.twig" %}s +{% include "footer.html.twig" %}