diff --git a/.idea/misc.xml b/.idea/misc.xml index a90d910..56865e7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/COSAS_POR_ARREGLAR.md b/COSAS_POR_ARREGLAR.md new file mode 100644 index 0000000..b679730 --- /dev/null +++ b/COSAS_POR_ARREGLAR.md @@ -0,0 +1,99 @@ +#Cosas que quiero arreglar, pero no podre + +## Validaciones + +Las validaciones encuentro que me quedaron bien, sin embargo creo que pueden ser mucho mejor, +el problema es que no encontre ninguna libreria que no trabaje con web o con objetos ya creados. + +Mi idea de una buena libreria de validaciones es algo similar a la que utiliza laravel, +se pasa un objeto y una serie de reglas a aplicar a ese objeto, si alguna de las reglas falla, la +validacion completa fallara. + +Estuve jugando un poco con la idea de hacer algo similar, pero no logre hacer que las reglas fueran +universales, para poder arreglar esto puede que me hubiese tomado mucho tiempo asi que decidi volver a +como estan en este momento. + +Basicamente mi idea de una validacion tendria que tener un codigo como este: + +``` +Validation validacion = new Validation( + object.getA() => List.of(Rule.notNull(), Rule.string(), Rule.minLength(5)), + object.getB() => List.of(Rule.date) +).validate(); + +if(validation.hasError()) { + validation.showErrorDialog(); + return; +} +``` + +Sin embargo no sabria como hacer un map al momento de inicializar un objeto (porque el => no existe en java), +podria crearlo y poblarlo antes, pero no quiero escribir tanto codigo y siento que quedaria sucio +dentro de un controlador. + +# BaseTableModel + +Me gusta esa parte de mi codigo, me deja bastante facil el crear un tabla bonita a la que solo le paso +un objeto y con las reglas que le asigno al inicializar los muestra correctamente, me ahorro el estar +transformando a strings en el controlador y cosas asi. + +Sin embargo creo que podria ser mas limpio + +``` +this.model = new BaseTableModel<>( + new String[]{"Distribuidor", "Nº Libros", "Estado", "Fecha Emision"}, + (row, rowIndex, colIndex) -> { + switch (colIndex) { + case 0: + return row.get(rowIndex).getDistribuidor().getRut(); + case 1: + return row.get(rowIndex).getLibros().size(); + case 2: + return row.get(rowIndex).getEstado(); + case 3: + return row.get(rowIndex).getInsertedAt(); + default: + return null; + } + } +); +``` + +Como se ve, cada vez tengo que obtener el objeto y luego obtener la parte que quiero mostrar. +Seguramente es facil dejarlo mas bonito, pero tendria que cambiar todas las vistas que usan una tabla, +me tomaria un rato quizas un poco largo y no quiero perderlo. + +## LaunchController + +Me gusta como queda, pero siento que igual se podria hacer algo mejor. + +Seria perfecto que cada vista se pudiera autoinsertar de alguna forma en ese controlador, en vez de estar +llamando a cada una y creandola manualmente + +Quizas puede hacerse de alguna forma con funciones estaticas? o alguna especie de singleton? como todos +los controladores existen solo una vez dentro de la aplicacion quizas es viable +Cosa que se pueda hacer lo siguiente + +``` + class Controller { + private View view; + + // Constructor estatico + { + LaunchController.add(new Controller(new View())); + } + + public Controller(View view) { + this.view = view; + } + + public void goToView2() { + LaunchController.show(PanelName.View2); + } + } +``` + +No estoy seguro si seria viable, pero pareciera ser una buena solucion, ahora no la puedo implementar porque +significaria crear toda la arquitectura de la app desde cero. + +No hay tiempo :c \ No newline at end of file diff --git a/biblioteca.vpp b/biblioteca.vpp index 08a04e8..a78525f 100644 Binary files a/biblioteca.vpp and b/biblioteca.vpp differ diff --git a/create.sql b/create.sql index ddf6047..130bc56 100644 --- a/create.sql +++ b/create.sql @@ -32,6 +32,7 @@ drop table if exists cliente_correo; drop table if exists trabajador_direccion; drop table if exists trabajador_telefono; drop table if exists trabajador_correo; +drop table if exists orden_compra; drop table if exists factura; drop table if exists boleta; drop table if exists compra; @@ -292,6 +293,17 @@ create table boleta inserted_at timestamp default CURRENT_TIMESTAMP ); +create table orden_compra +( + id int unsigned primary key auto_increment, + estado enum ('En Curso', 'Aceptada', 'Cancelada'), + compra_id int unsigned, + distribuidor_id int unsigned not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade, + foreign key (compra_id) references compra (id) on delete restrict on update cascade +); + create table compra ( id int unsigned primary key auto_increment, @@ -329,6 +341,14 @@ create table arriendo foreign key (cliente_id) references cliente (id) on delete restrict on update cascade ); +create table libro_orden_compra +( + libro_id int unsigned, + orden_compra_id int unsigned, + foreign key (libro_id) references libro (id) on delete restrict on update cascade, + foreign key (orden_compra_id) references orden_compra (id) on delete restrict on update cascade +); + create table ejemplar_compra ( ejemplar_id int unsigned, diff --git a/mysql b/mysql new file mode 100644 index 0000000..8a2fe9b --- /dev/null +++ b/mysql @@ -0,0 +1,504 @@ +#--------------------------------------------------------------------------------# +#-----------------------------Eliminar todas las tablas--------------------------# +#--------------------------------------------------------------------------------# +start transaction; + +set foreign_key_checks = 0; +set autocommit = 0; + +drop table if exists editorial; +drop table if exists estado; +drop table if exists autor; +drop table if exists categoria; +drop table if exists idioma; +drop table if exists libro; +drop table if exists ejemplar; +drop table if exists libro_autor; +drop table if exists libro_categoria; +drop table if exists libro_idioma; +drop table if exists correo; +drop table if exists direccion; +drop table if exists telefono; +drop table if exists empresa; +drop table if exists distribuidor; +drop table if exists cliente; +drop table if exists trabajador; +drop table if exists distribuidor_direccion; +drop table if exists distribuidor_telefono; +drop table if exists distribuidor_correo; +drop table if exists cliente_direccion; +drop table if exists cliente_telefono; +drop table if exists cliente_correo; +drop table if exists trabajador_direccion; +drop table if exists trabajador_telefono; +drop table if exists trabajador_correo; +drop table if exists orden_compra; +drop table if exists factura; +drop table if exists boleta; +drop table if exists compra; +drop table if exists venta; +drop table if exists arriendo; +drop table if exists ejemplar_compra; +drop table if exists ejemplar_venta; +drop table if exists ejemplar_arriendo; +drop table if exists usuario; + + +#--------------------------------------------------------------------------------# +#--------------Definicion de las tablas relacionadas a los libros----------------# +#--------------------------------------------------------------------------------# +create table editorial +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table estado +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table autor +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + apellido_paterno varchar(255) null, + apellido_materno varchar(255) null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table categoria +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table idioma +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table libro +( + id int unsigned primary key auto_increment, + editorial_id int unsigned not null, + isbn varchar(255) not null, + ano_publicacion int default null, + numero_paginas int not null, + titulo varchar(255) default null, + precio_referencia int not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (editorial_id) references editorial (id) on delete restrict on update cascade +); + +create table ejemplar +( + id int unsigned primary key auto_increment, + libro_id int unsigned not null, + estado_id int unsigned default 1, + serie varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + unique key serie_libro (serie, libro_id), + foreign key (libro_id) references libro (id) on delete cascade on update cascade, + foreign key (estado_id) references estado (id) on delete restrict on update cascade +); + +create table libro_autor +( + libro_id int unsigned not null, + autor_id int unsigned not null, + foreign key (libro_id) references libro (id) on delete restrict on update cascade, + foreign key (autor_id) references autor (id) on delete restrict on update cascade +); + +create table libro_categoria +( + libro_id int unsigned not null, + categoria_id int unsigned not null, + foreign key (libro_id) references libro (id) on delete restrict on update cascade, + foreign key (categoria_id) references categoria (id) on delete restrict on update cascade +); + +create table libro_idioma +( + libro_id int unsigned not null, + idioma_id int unsigned not null, + foreign key (libro_id) references libro (id) on delete restrict on update cascade, + foreign key (idioma_id) references idioma (id) on delete restrict on update cascade +); + + +#--------------------------------------------------------------------------------# +#------------Definicion de las tablas relacionadas a las personas----------------# +#--------------------------------------------------------------------------------# +create table direccion +( + id int unsigned primary key auto_increment, + calle varchar(255) not null, + numero varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table telefono +( + id int unsigned primary key auto_increment, + numero varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table correo +( + id int unsigned primary key auto_increment, + correo varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table empresa +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table distribuidor +( + id int unsigned primary key auto_increment, + empresa_id int unsigned not null, + rut varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (empresa_id) references empresa (id) on delete restrict on update cascade +); + +create table cliente +( + id int unsigned primary key auto_increment, + rut varchar(255) not null, + nombre varchar(255) not null, + apellido_paterno varchar(255) not null, + apellido_materno varchar(255) not null, + fecha_nacimiento date not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table trabajador +( + id int unsigned primary key auto_increment, + rut varchar(255) not null, + nombre varchar(255) not null, + apellido_paterno varchar(255) not null, + apellido_materno varchar(255) not null, + fecha_contrato date not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table distribuidor_direccion +( + distribuidor_id int unsigned, + direccion_id int unsigned, + foreign key (distribuidor_id) references cliente (id) on delete restrict on update cascade, + foreign key (direccion_id) references direccion (id) on delete cascade on update cascade +); + +create table distribuidor_telefono +( + distribuidor_id int unsigned, + telefono_id int unsigned, + foreign key (distribuidor_id) references cliente (id) on delete restrict on update cascade, + foreign key (telefono_id) references telefono (id) on delete cascade on update cascade +); + +create table distribuidor_correo +( + distribuidor_id int unsigned, + correo_id int unsigned, + foreign key (distribuidor_id) references cliente (id) on delete restrict on update cascade, + foreign key (correo_id) references correo (id) on delete cascade on update cascade +); + +create table cliente_direccion +( + cliente_id int unsigned, + direccion_id int unsigned, + foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, + foreign key (direccion_id) references direccion (id) on delete cascade on update cascade +); + +create table cliente_telefono +( + cliente_id int unsigned, + telefono_id int unsigned, + foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, + foreign key (telefono_id) references telefono (id) on delete cascade on update cascade +); + +create table cliente_correo +( + cliente_id int unsigned, + correo_id int unsigned, + foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, + foreign key (correo_id) references correo (id) on delete cascade on update cascade +); + +create table trabajador_direccion +( + trabajador_id int unsigned, + direccion_id int unsigned, + foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, + foreign key (direccion_id) references direccion (id) on delete cascade on update cascade +); + +create table trabajador_telefono +( + trabajador_id int unsigned, + telefono_id int unsigned, + foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, + foreign key (telefono_id) references telefono (id) on delete cascade on update cascade +); + +create table trabajador_correo +( + trabajador_id int unsigned, + correo_id int unsigned, + foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, + foreign key (correo_id) references correo (id) on delete cascade on update cascade +); + +#--------------------------------------------------------------------------------# +#-------Definicion de las tablas relacionadas a la venta/compra/arriendo---------# +#--------------------------------------------------------------------------------# + +create table factura +( + id int unsigned primary key auto_increment, + folio varchar(255) not null, + precio_neto int not null, + precio_iva int not null, + fecha_compra datetime not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table boleta +( + id int unsigned primary key auto_increment, + folio varchar(255) not null, + precio_neto int not null, + precio_iva int not null, + fecha_venta datetime not null, + inserted_at timestamp default CURRENT_TIMESTAMP +); + +create table orden_compra +( + id int unsigned primary key auto_increment, + estado enum ('En Curso', 'Aceptada', 'Cancelada'), + compra_id int unsigned, + distribuidor_id int unsigned not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade, + foreign key (compra_id) references compra (id) on delete restrict on update cascade +); + +create table compra +( + id int unsigned primary key auto_increment, + factura_id int unsigned not null, + distribuidor_id int unsigned not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (factura_id) references factura (id) on delete restrict on update cascade, + foreign key (distribuidor_id) references cliente (id) on delete restrict on update cascade +); + +create table venta +( + id int unsigned primary key auto_increment, + cliente_id int unsigned not null, + trabajador_id int unsigned not null, + boleta_id int unsigned not null, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, + foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, + foreign key (boleta_id) references boleta (id) on delete restrict on update cascade +); + +create table arriendo +( + id int unsigned primary key auto_increment, + trabajador_id int unsigned not null, + cliente_id int unsigned not null, + costo_arriendo int not null, + fecha_arriendo date not null, + fecha_devolucion_estimada date not null, + fecha_devolucion_real date, + multa int, + inserted_at timestamp default CURRENT_TIMESTAMP, + foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, + foreign key (cliente_id) references cliente (id) on delete restrict on update cascade +); + +create table ejemplar_compra +( + ejemplar_id int unsigned, + compra_id int unsigned, + foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade, + foreign key (compra_id) references compra (id) on delete restrict on update cascade +); + +create table ejemplar_venta +( + ejemplar_id int unsigned, + venta_id int unsigned, + foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade, + foreign key (venta_id) references venta (id) on delete restrict on update cascade +); + +create table ejemplar_arriendo +( + ejemplar_id int unsigned, + arriendo_id int unsigned, + foreign key (ejemplar_id) references ejemplar (id) on delete restrict on update cascade, + foreign key (arriendo_id) references arriendo (id) on delete restrict on update cascade +); + +#--------------------------------------------------------------------------------# +#---------------------Definicion de las tablas de usuario------------------------# +#--------------------------------------------------------------------------------# + +create table usuario +( + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + password binary(32) not null, + salt binary(16) not null, + trabajador_id int unsigned not null, + inserted_at timestamp default current_timestamp, + foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade +); + +set autocommit = 1; +set foreign_key_checks = 1; + +commit;start transaction; + +set foreign_key_checks = 0; +set autocommit = 0; + +INSERT INTO `autor` +VALUES (1, 'Howard Philips', 'Lovecraft', NULL, '2019-06-12 16:18:57'), + (2, 'Stephen', 'King', NULL, '2019-06-12 16:18:57'), + (3, 'Brandon', 'Sanderson', NULL, '2019-06-12 16:18:57'); + +INSERT INTO `categoria` +VALUES (1, 'Terror', '2019-06-12 16:18:57'), + (2, 'Aventura', '2019-06-12 16:18:57'), + (3, 'Fantasia', '2019-06-12 16:18:57'); +-- + +INSERT INTO `cliente` +VALUES (1, '21786653-7', 'Cliente', '1', '1', '2019-06-17', '2019-06-13 16:01:33'), + (2, '17181388-3', 'Cliente', '2', '2', '2019-06-13', '2019-06-13 16:04:02'); + +INSERT INTO `correo` +VALUES (1, 'HOOLA', '2019-06-13 17:25:41'), + (2, 'skrd159@gmail.com', '2019-06-13 17:32:13'); + +INSERT INTO `distribuidor` +VALUES (2, 1, '14166920-6', '2019-06-13 03:08:17'), + (3, 2, '8425080-5', '2019-06-13 03:08:23'), + (4, 1, '21629388-6', '2019-06-13 03:08:25'), + (5, 1, '13510176-1', '2019-06-13 03:08:27'); + +INSERT INTO `editorial` +VALUES (1, 'Editorial N1', '2019-06-12 16:18:57'), + (2, 'Editorial N2', '2019-06-12 16:18:57'), + (3, 'Editorial N3', '2019-06-12 16:18:57'); + +INSERT INTO `empresa` +VALUES (1, 'Empresa 1', '2019-06-13 00:39:50'), + (2, 'Empresa 2', '2019-06-13 00:39:52'); + +INSERT INTO `estado` +VALUES (1, 'Vendido', '2019-06-12 16:18:57'), + (2, 'Arrendado', '2019-06-12 16:18:57'), + (3, 'Disponible', '2019-06-12 16:18:57'); + +INSERT INTO `idioma` +VALUES (1, 'Español', '2019-06-12 16:18:57'), + (2, 'Ingles', '2019-06-12 16:18:57'), + (3, 'Portuges', '2019-06-12 16:18:57'), + (4, 'Aleman', '2019-06-12 16:18:57'), + (5, 'Ruso', '2019-06-12 16:18:57'), + (6, 'Japones', '2019-06-12 16:18:57'); + +INSERT INTO `libro` +VALUES (1, 1, '0-765-31178-X', 2006, 541, 'Mistborn: The Final Empire', 10000, + '2019-06-12 16:18:57'), + (2, 1, '0-765-31688-9', 2007, 590, 'Mistborn: The Well of Ascension', 10000, + '2019-06-12 16:18:57'), + (3, 1, '978-0-7653-1689-9', 2008, 572, 'Mistborn: The Hero of Ages', 10000, + '2019-06-12 16:18:57'), + (4, 2, '1231231231232', 1931, 100, 'The Shadow over Innsmouth', 10000, + '2019-06-12 16:18:57'), + (5, 2, '1231231231232', 1933, 100, 'The Dreams in the Witch House', 10000, + '2019-06-12 16:18:57'), + (6, 2, '1231231231232', 1936, 100, 'At the Mountains of Madness', 10000, + '2019-06-12 16:18:57'), + (7, 3, '0385086954', 1974, 199, 'Carrie', 10000, '2019-06-12 16:18:57'), + (8, 3, '978-0-670-26077-5', 1979, 428, 'The Dead Zone', 10000, '2019-06-12 16:18:57'), + (9, 3, '0-670-81302-8', 1986, 1138, 'It', 10000, '2019-06-12 16:18:57'); + +INSERT INTO `libro_autor` +VALUES (1, 3), + (2, 3), + (3, 3), + (4, 1), + (5, 1), + (6, 1), + (7, 2), + (8, 2), + (9, 2); + +INSERT INTO `libro_categoria` +VALUES (1, 3), + (2, 3), + (3, 3), + (4, 1), + (5, 1), + (6, 1), + (7, 1), + (8, 1), + (9, 1); + +INSERT INTO `libro_idioma` +VALUES (1, 2), + (2, 2), + (3, 2), + (4, 2), + (5, 2), + (6, 2), + (7, 2), + (8, 2), + (9, 2); + +INSERT INTO `trabajador` +VALUES (2, '19763899-0', 'Daniel', 'Cortes', 'Pincheira', '2019-06-13', '2019-06-13 16:04:42'), + (3, '10768789-0', 'Trabajador', 'N', '2', '2019-06-13', '2019-06-13 16:05:17'), + (4, '9717478-4', 'Trabajador', 'N', '3', '2019-06-13', '2019-06-13 16:05:27'); + +INSERT INTO `trabajador_correo` +VALUES (4, 1), + (2, 2); + +INSERT INTO `usuario` +VALUES (2, 'admin', 0x243168097E0BA82B896F348BABCEB600A8DCA30488C6F238F97FD8737BD00B27, + 0x3564ECCCD85CF0583F9C090602E998B7, 2, '2019-06-13 16:04:53'); + +set autocommit = 1; +set foreign_key_checks = 1; + +commit; \ No newline at end of file diff --git a/src/main/java/xyz/danielcortes/controllers/LaunchController.java b/src/main/java/xyz/danielcortes/controllers/LaunchController.java index e897773..c903096 100644 --- a/src/main/java/xyz/danielcortes/controllers/LaunchController.java +++ b/src/main/java/xyz/danielcortes/controllers/LaunchController.java @@ -30,9 +30,6 @@ import xyz.danielcortes.controllers.cliente.telefono.ClienteTelefonoCreateContro import xyz.danielcortes.controllers.cliente.telefono.ClienteTelefonoSearchController; import xyz.danielcortes.controllers.cliente.telefono.ClienteTelefonoUpdateController; import xyz.danielcortes.controllers.cliente.telefono.ClienteTelefonoViewController; -import xyz.danielcortes.controllers.comprar.ComprarComprarController; -import xyz.danielcortes.controllers.comprar.ComprarSearchController; -import xyz.danielcortes.controllers.comprar.ComprarSeleccionarController; import xyz.danielcortes.controllers.distribuidor.DistribuidorCreateController; import xyz.danielcortes.controllers.distribuidor.DistribuidorSearchController; import xyz.danielcortes.controllers.distribuidor.DistribuidorUpdateController; @@ -65,6 +62,10 @@ import xyz.danielcortes.controllers.libro.LibroCreateController; import xyz.danielcortes.controllers.libro.LibroSearchController; import xyz.danielcortes.controllers.libro.LibroUpdateController; import xyz.danielcortes.controllers.libro.LibroViewController; +import xyz.danielcortes.controllers.orden_compra.OrdenCompraAceptarController; +import xyz.danielcortes.controllers.orden_compra.OrdenCompraCrearController; +import xyz.danielcortes.controllers.orden_compra.OrdenCompraSearchController; +import xyz.danielcortes.controllers.orden_compra.OrdenCompraViewController; import xyz.danielcortes.controllers.trabajador.TrabajadorCreateController; import xyz.danielcortes.controllers.trabajador.TrabajadorSearchController; import xyz.danielcortes.controllers.trabajador.TrabajadorUpdateController; @@ -100,9 +101,6 @@ import xyz.danielcortes.views.cliente.ClienteCreatePanel; import xyz.danielcortes.views.cliente.ClienteSearchPanel; import xyz.danielcortes.views.cliente.ClienteUpdatePanel; import xyz.danielcortes.views.cliente.ClienteViewPanel; -import xyz.danielcortes.views.comprar.ComprarComprarPanel; -import xyz.danielcortes.views.comprar.ComprarSearchPanel; -import xyz.danielcortes.views.comprar.ComprarSeleccionarPanel; import xyz.danielcortes.views.correo.CorreoCreatePanel; import xyz.danielcortes.views.correo.CorreoSearchPanel; import xyz.danielcortes.views.correo.CorreoUpdatePanel; @@ -131,6 +129,10 @@ import xyz.danielcortes.views.libro.LibroCreatePanel; import xyz.danielcortes.views.libro.LibroSearchPanel; import xyz.danielcortes.views.libro.LibroUpdatePanel; import xyz.danielcortes.views.libro.LibroViewPanel; +import xyz.danielcortes.views.orden_compra.OrdenCompraAceptarPanel; +import xyz.danielcortes.views.orden_compra.OrdenCompraCrearPanel; +import xyz.danielcortes.views.orden_compra.OrdenCompraSearchPanel; +import xyz.danielcortes.views.orden_compra.OrdenCompraViewPanel; import xyz.danielcortes.views.telefono.TelefonoCreatePanel; import xyz.danielcortes.views.telefono.TelefonoSearchPanel; import xyz.danielcortes.views.telefono.TelefonoUpdatePanel; @@ -292,9 +294,10 @@ public class LaunchController { this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_CREATE, new DistribuidorDireccionCreateController(new DireccionCreatePanel(), this)); this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_UPDATE, new DistribuidorDireccionUpdateController(new DireccionUpdatePanel(), this)); - this.controllers.put(PanelName.COMPRAR_SEARCH, new ComprarSearchController(new ComprarSearchPanel(), this)); - this.controllers.put(PanelName.COMPRAR_COMPRAR, new ComprarComprarController(new ComprarComprarPanel(), this)); - this.controllers.put(PanelName.COMPRAR_SELECCIONAR, new ComprarSeleccionarController(new ComprarSeleccionarPanel(), this)); + this.controllers.put(PanelName.ORDEN_COMPRA_SEARCH, new OrdenCompraSearchController(new OrdenCompraSearchPanel(), this)); + this.controllers.put(PanelName.ORDEN_COMPRA_CREAR, new OrdenCompraCrearController(new OrdenCompraCrearPanel(), this)); + this.controllers.put(PanelName.ORDEN_COMPRA_VIEW, new OrdenCompraViewController(new OrdenCompraViewPanel(), this)); + this.controllers.put(PanelName.ORDEN_COMPRA_ACEPTAR, new OrdenCompraAceptarController(new OrdenCompraAceptarPanel(), this)); for (Entry entry : this.controllers.entrySet()) { this.frame.addCard(entry.getValue().getView().getContentPane(), entry.getKey()); @@ -362,17 +365,17 @@ public class LaunchController { private JMenu createComprarMenu() { JMenu comprarMenu = new JMenu("Compra, Venta y Arriendo"); - JMenuItem comprarLibroItem = new JMenuItem("Comprar Libro"); - JMenuItem venderLibroItem = new JMenuItem("Vender Libro"); - JMenuItem arrendarLibroItem = new JMenuItem("Arrendar Libro"); + JMenuItem ordenDeCompraItem = new JMenuItem("Orden de compra"); + JMenuItem venderEjemplarItem = new JMenuItem("Vender Ejemplar"); + JMenuItem arrendarEjemplarItem = new JMenuItem("Arrendar Ejemplar"); - comprarLibroItem.addActionListener(e -> this.showCard(PanelName.COMPRAR_SEARCH)); - venderLibroItem.addActionListener(e -> this.showCard(PanelName.VENDER_SEARCH)); - arrendarLibroItem.addActionListener(e -> this.showCard(PanelName.ARRENDAR_SEARCH)); + ordenDeCompraItem.addActionListener(e -> this.showCard(PanelName.ORDEN_COMPRA_SEARCH)); + venderEjemplarItem.addActionListener(e -> this.showCard(PanelName.VENDER_SEARCH)); + arrendarEjemplarItem.addActionListener(e -> this.showCard(PanelName.ARRENDAR_SEARCH)); - comprarMenu.add(comprarLibroItem); - comprarMenu.add(venderLibroItem); - comprarMenu.add(arrendarLibroItem); + comprarMenu.add(ordenDeCompraItem); + comprarMenu.add(venderEjemplarItem); + comprarMenu.add(arrendarEjemplarItem); return comprarMenu; } diff --git a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarComprarController.java b/src/main/java/xyz/danielcortes/controllers/comprar/ComprarComprarController.java deleted file mode 100644 index 1e0106c..0000000 --- a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarComprarController.java +++ /dev/null @@ -1,48 +0,0 @@ -package xyz.danielcortes.controllers.comprar; - -import xyz.danielcortes.controllers.LaunchController; -import xyz.danielcortes.framework.BaseController; -import xyz.danielcortes.framework.BasePanel; -import xyz.danielcortes.framework.PanelName; -import xyz.danielcortes.repository.CompraRepository; -import xyz.danielcortes.repository.DistribuidorRepository; -import xyz.danielcortes.validator.CompraValidator; -import xyz.danielcortes.views.comprar.ComprarComprarPanel; - -public class ComprarComprarController extends BaseController { - - private ComprarComprarPanel view; - private CompraRepository compraRepository; - private DistribuidorRepository distribuidorRepository; - private CompraValidator validator; - - public ComprarComprarController(ComprarComprarPanel view, LaunchController parent) { - super(parent); - this.view = view; - this.compraRepository = new CompraRepository(); - this.distribuidorRepository = new DistribuidorRepository(); - this.validator = new CompraValidator(this.compraRepository); - this.setupListeners(); - - } - - public void setupListeners() { - this.view.getVolverButton().addActionListener(e -> this.parentController.showCard(PanelName.COMPRAR_SEARCH)); - this.view.getSeleccionarButton().addActionListener(e -> this.parentController.showCard(PanelName.COMPRAR_SELECCIONAR)); - } - - @Override - public void show() { - this.fillDistribuidores(); - } - - private void fillDistribuidores() { - this.view.getDistribuidorModel().removeAllElements(); - this.view.getDistribuidorModel().addAll(this.distribuidorRepository.getAll()); - } - - @Override - public BasePanel getView() { - return this.view; - } -} diff --git a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSearchController.java b/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSearchController.java deleted file mode 100644 index 89aed35..0000000 --- a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSearchController.java +++ /dev/null @@ -1,92 +0,0 @@ -package xyz.danielcortes.controllers.comprar; - -import java.util.List; -import javax.swing.JOptionPane; -import xyz.danielcortes.controllers.LaunchController; -import xyz.danielcortes.framework.BaseController; -import xyz.danielcortes.framework.BasePanel; -import xyz.danielcortes.framework.BaseTableModel; -import xyz.danielcortes.framework.PanelName; -import xyz.danielcortes.models.Compra; -import xyz.danielcortes.repository.CompraRepository; -import xyz.danielcortes.validator.CompraValidator; -import xyz.danielcortes.views.comprar.ComprarSearchPanel; - -public class ComprarSearchController extends BaseController { - - private ComprarSearchPanel view; - private CompraRepository repository; - private CompraValidator validator; - - public ComprarSearchController(ComprarSearchPanel view, LaunchController parent) { - super(parent); - this.view = view; - this.repository = new CompraRepository(); - this.validator = new CompraValidator(this.repository); - this.setupListeners(); - } - - private void setupListeners() { - this.view.getComprarButton().addActionListener(e -> this.getParentController().showCard(PanelName.COMPRAR_COMPRAR)); - this.view.getBuscarButton().addActionListener(e -> this.search()); - this.view.getSearchField().addActionListener(e -> this.search()); - this.view.getVerButton().addActionListener(e -> this.view()); - } - - private void search() { - String term = this.view.getSearchField().getText(); - List compras = this.repository.search(term); - this.loadComprarTable(compras); - } - - private void view() { - Compra compra = this.getSelectedCompra(); - if (compra != null) { -// CompraViewController controller = (CompraViewController) this.getParentController().getCard(PanelName.COMPRAR_VIEW); -// controller.setCompra(compra); -// this.getParentController().showCard(PanelName.COMPRAR_VIEW); - } - } - - private void loadComprarTable(List compras) { - BaseTableModel model = this.view.getModel(); - model.setRows(compras); - } - - private Compra getSelectedCompra() { - int selectedRow = this.view.getTable().getSelectedRow(); - if (selectedRow == -1) { - JOptionPane.showMessageDialog( - null, - "No hay copra seleccionada", - "Error", - JOptionPane.ERROR_MESSAGE - ); - return null; - } - - return this.view.getModel().getRow(selectedRow); - } - - @Override - public void show() { - this.reload(); - } - - public void reload() { - this.loadComprarTable(); - this.view.getSearchField().requestFocus(); - this.view.getTable().setRowSelectionInterval(0, 0); - } - - private void loadComprarTable() { - List compra = this.repository.getAll(); - this.loadComprarTable(compra); - } - - @Override - public BasePanel getView() { - return this.view; - } - -} diff --git a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSeleccionarController.java b/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSeleccionarController.java deleted file mode 100644 index 8e291de..0000000 --- a/src/main/java/xyz/danielcortes/controllers/comprar/ComprarSeleccionarController.java +++ /dev/null @@ -1,133 +0,0 @@ -package xyz.danielcortes.controllers.comprar; - -import java.util.ArrayList; -import java.util.List; -import javax.swing.JOptionPane; -import xyz.danielcortes.controllers.LaunchController; -import xyz.danielcortes.framework.BaseController; -import xyz.danielcortes.framework.BasePanel; -import xyz.danielcortes.framework.PanelName; -import xyz.danielcortes.framework.ValidationResult; -import xyz.danielcortes.models.Ejemplar; -import xyz.danielcortes.models.Estado; -import xyz.danielcortes.models.Libro; -import xyz.danielcortes.repository.EjemplarRepository; -import xyz.danielcortes.repository.LibroRepository; -import xyz.danielcortes.validator.EjemplarValidator; -import xyz.danielcortes.views.comprar.ComprarSeleccionarPanel; - -public class ComprarSeleccionarController extends BaseController { - - private ComprarSeleccionarPanel view; - private LibroRepository libroRepository; - private EjemplarValidator ejemplarValidator; - - private List ejemplares; - private List editing; - - public ComprarSeleccionarController(ComprarSeleccionarPanel view, LaunchController parent) { - super(parent); - this.view = view; - this.libroRepository = new LibroRepository(); - this.ejemplarValidator = new EjemplarValidator(new EjemplarRepository()); - this.ejemplares = new ArrayList<>(); - this.editing = new ArrayList<>(); - this.setupListeners(); - } - - public void setupListeners() { - this.view.getGuardarButton().addActionListener(e -> this.save()); - this.view.getVolverButton().addActionListener(e -> this.volver()); - this.view.getRemoverButton().addActionListener(e -> this.remove()); - this.view.getAgregarButton().addActionListener(e -> this.agregar()); - } - - private void save() { - this.ejemplares.clear(); - this.ejemplares.addAll(this.editing); - - this.getParentController().showCard(PanelName.COMPRAR_COMPRAR); - } - - private void volver() { - this.editing.clear(); - this.editing.addAll(this.ejemplares); - - this.parentController.showCard(PanelName.COMPRAR_COMPRAR); - } - - private void remove() { - Ejemplar ejemplar = this.getSelectedEjemplar(); - if (ejemplar == null) - return; - int index = this.view.getEjemplaresTable().getSelectedRow(); - - this.view.getEjemplaresTableModel().removeRow(index); - this.editing.remove(ejemplar); - } - - private void agregar() { - Libro libro = (Libro) this.view.getLibrosCombo().getSelectedItem(); - if (libro == null) - return; - - String serie = this.view.getSerieField().getText(); - - ValidationResult serieValidation = this.ejemplarValidator.validateSerie(serie, libro.getId(), this.editing); - if (serieValidation.hasError()) { - serieValidation.showErrorDialog(); - return; - } - - Ejemplar ejemplar = new Ejemplar(); - ejemplar.setLibro(libro); - ejemplar.setSerie(serie); - ejemplar.setEstado(new Estado()); - - this.editing.add(ejemplar); - this.view.getEjemplaresTableModel().addRow(ejemplar); - - this.view.getLibrosCombo().setSelectedIndex(0); - this.view.getSerieField().setText(""); - } - - private Ejemplar getSelectedEjemplar() { - int selectedRow = this.view.getEjemplaresTable().getSelectedRow(); - if (selectedRow == -1) { - JOptionPane.showMessageDialog( - null, - "No hay ningun ejemplar seleccionado", - "Error", - JOptionPane.ERROR_MESSAGE - ); - return null; - } - return this.view.getEjemplaresTableModel().getRow(selectedRow); - } - - @Override - public void show() { - this.editing.clear(); - this.editing.addAll(this.ejemplares); - - this.fillLibros(); - this.view.getLibrosCombo().setSelectedIndex(0); - } - - private void fillLibros() { - this.view.getLibrosComboModel().removeAllElements(); - this.view.getLibrosComboModel().addAll(this.libroRepository.getAll()); - - this.view.getEjemplaresTableModel().setRows(this.ejemplares); - } - - @Override - public BasePanel getView() { - return this.view; - } - - public List getEjemplares() { - return this.ejemplares; - } - -} diff --git a/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraAceptarController.java b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraAceptarController.java new file mode 100644 index 0000000..25f6281 --- /dev/null +++ b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraAceptarController.java @@ -0,0 +1,59 @@ +package xyz.danielcortes.controllers.orden_compra; + +import java.time.LocalDate; +import xyz.danielcortes.controllers.LaunchController; +import xyz.danielcortes.framework.BaseController; +import xyz.danielcortes.framework.BasePanel; +import xyz.danielcortes.framework.ChangeListener; +import xyz.danielcortes.framework.PanelName; +import xyz.danielcortes.models.OrdenCompra; +import xyz.danielcortes.views.orden_compra.OrdenCompraAceptarPanel; + +public class OrdenCompraAceptarController extends BaseController { + + private OrdenCompraAceptarPanel view; + private OrdenCompra ordenCompra; + + public OrdenCompraAceptarController(OrdenCompraAceptarPanel view, LaunchController parent) { + super(parent); + this.view = view; + this.setupListeners(); + } + + private void setupListeners() { + this.view.getVolverButton().addActionListener(e -> this.parentController.showCard(PanelName.ORDEN_COMPRA_SEARCH)); + this.view.getPrecioNetoField().getDocument().addDocumentListener((ChangeListener) e -> this.calculatePrice()); + } + + private void calculatePrice() { + try { + int neto = Integer.parseInt(this.view.getPrecioNetoField().getText()); + + float iva = (float) neto * .19f; + this.view.getIvaField().setText(String.valueOf(iva)); + this.view.getTotalField().setText(String.valueOf(iva + neto)); + } catch (NumberFormatException e) { + this.view.getIvaField().setText("0"); + this.view.getTotalField().setText("0"); + } + } + + public void setOrdenCompra(OrdenCompra ordenCompra) { + this.ordenCompra = ordenCompra; + } + + @Override + public void show() { + this.view.getAsignarButton().requestFocus(); + this.view.getFechaEmisionPicker().setDate(LocalDate.now()); + this.view.getIvaField().setText("0"); + this.view.getPrecioNetoField().setText("0"); + this.view.getTotalField().setText("0"); + } + + @Override + public BasePanel getView() { + return this.view; + } + +} diff --git a/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraCrearController.java b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraCrearController.java new file mode 100644 index 0000000..2224eac --- /dev/null +++ b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraCrearController.java @@ -0,0 +1,129 @@ +package xyz.danielcortes.controllers.orden_compra; + +import java.util.List; +import javax.swing.JOptionPane; +import xyz.danielcortes.controllers.LaunchController; +import xyz.danielcortes.framework.BaseController; +import xyz.danielcortes.framework.BasePanel; +import xyz.danielcortes.framework.PanelName; +import xyz.danielcortes.framework.ValidationResult; +import xyz.danielcortes.models.Distribuidor; +import xyz.danielcortes.models.Libro; +import xyz.danielcortes.models.OrdenCompra; +import xyz.danielcortes.repository.DistribuidorRepository; +import xyz.danielcortes.repository.LibroRepository; +import xyz.danielcortes.repository.OrdenCompraRepository; +import xyz.danielcortes.validator.OrdenCompraValidator; +import xyz.danielcortes.views.orden_compra.OrdenCompraCrearPanel; + +public class OrdenCompraCrearController extends BaseController { + + private OrdenCompraCrearPanel view; + private LibroRepository libroRepository; + private DistribuidorRepository distribuidorRepository; + private OrdenCompraRepository ordenCompraRepository; + private OrdenCompraValidator validator; + + public OrdenCompraCrearController(OrdenCompraCrearPanel view, LaunchController parent) { + super(parent); + this.view = view; + this.libroRepository = new LibroRepository(); + this.distribuidorRepository = new DistribuidorRepository(); + this.ordenCompraRepository = new OrdenCompraRepository(); + this.validator = new OrdenCompraValidator(); + this.setupListeners(); + } + + public void setupListeners() { + this.view.getGuardarButton().addActionListener(e -> this.save()); + this.view.getVolverButton().addActionListener(e -> this.volver()); + this.view.getRemoverButton().addActionListener(e -> this.remove()); + this.view.getAgregarButton().addActionListener(e -> this.agregar()); + } + + private void save() { + List libros = this.view.getLibroTableModel().getRows(); + ValidationResult librosValidation = this.validator.validateLibros(libros); + if (librosValidation.hasError()) { + librosValidation.showErrorDialog(); + return; + } + + Distribuidor distribuidor = (Distribuidor) this.view.getDistribuidorCombo().getSelectedItem(); + ValidationResult distribuidorValidation = this.validator.validateDistribuidor(distribuidor); + if (distribuidorValidation.hasError()) { + distribuidorValidation.showErrorDialog(); + return; + } + + OrdenCompra ordenCompra = new OrdenCompra(); + ordenCompra.setDistribuidor(distribuidor); + ordenCompra.setEstado("En Curso"); + ordenCompra.setLibros(libros); + + this.ordenCompraRepository.save(ordenCompra); + this.parentController.showCard(PanelName.ORDEN_COMPRA_SEARCH); + } + + private void volver() { + this.parentController.showCard(PanelName.ORDEN_COMPRA_SEARCH); + } + + private void remove() { + Libro libro = this.getSelectedLibro(); + if (libro == null) + return; + + this.view.getLibroTableModel().removeRow(libro); + } + + private void agregar() { + Libro libro = (Libro) this.view.getLibrosCombo().getSelectedItem(); + if (libro == null) + return; + + int cantidad = (int) this.view.getCantidadSpinner().getValue(); + for (int i = 0; i < cantidad; i++) { + this.view.getLibroTableModel().addRow(libro); + } + } + + private Libro getSelectedLibro() { + int selectedRow = this.view.getLibrosTable().getSelectedRow(); + if (selectedRow == -1) { + JOptionPane.showMessageDialog( + null, + "No hay ningun libro seleccionado", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return null; + } + return this.view.getLibroTableModel().getRow(selectedRow); + } + + @Override + public void show() { + this.fillLibros(); + this.fillDistribuidor(); + this.view.getLibrosCombo().setSelectedIndex(0); + this.view.getDistribuidorCombo().setSelectedIndex(0); + this.view.getLibroTableModel().removeRows(); + this.view.getLibrosTable().clearSelection(); + } + + private void fillLibros() { + this.view.getLibrosComboModel().removeAllElements(); + this.view.getLibrosComboModel().addAll(this.libroRepository.getAll()); + } + + private void fillDistribuidor() { + this.view.getDistribuidorComboModel().removeAllElements(); + this.view.getDistribuidorComboModel().addAll(this.distribuidorRepository.getAll()); + } + + @Override + public BasePanel getView() { + return this.view; + } +} diff --git a/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraSearchController.java b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraSearchController.java new file mode 100644 index 0000000..0fe9eea --- /dev/null +++ b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraSearchController.java @@ -0,0 +1,172 @@ +package xyz.danielcortes.controllers.orden_compra; + +import java.util.List; +import javax.swing.JOptionPane; +import xyz.danielcortes.controllers.LaunchController; +import xyz.danielcortes.framework.BaseController; +import xyz.danielcortes.framework.BasePanel; +import xyz.danielcortes.framework.BaseTableModel; +import xyz.danielcortes.framework.PanelName; +import xyz.danielcortes.models.OrdenCompra; +import xyz.danielcortes.repository.OrdenCompraRepository; +import xyz.danielcortes.views.orden_compra.OrdenCompraSearchPanel; + +public class OrdenCompraSearchController extends BaseController { + + private OrdenCompraSearchPanel view; + private OrdenCompraRepository repository; + + public OrdenCompraSearchController(OrdenCompraSearchPanel view, LaunchController parent) { + super(parent); + this.view = view; + this.repository = new OrdenCompraRepository(); + this.setupListeners(); + } + + private void setupListeners() { + this.view.getBuscarButton().addActionListener(e -> this.search()); + this.view.getSearchField().addActionListener(e -> this.search()); + + this.view.getCrearButton().addActionListener(e -> this.getParentController().showCard(PanelName.ORDEN_COMPRA_CREAR)); + this.view.getVerButton().addActionListener(e -> this.view()); + this.view.getCancelarButton().addActionListener(e -> this.cancelar()); + this.view.getAceptarButton().addActionListener(e -> this.aceptar()); + } + + private void search() { + String term = this.view.getSearchField().getText(); + List ordenCompras = this.repository.search(term); + this.loadComprarTable(ordenCompras); + } + + private void view() { + OrdenCompra ordenCompra = this.getSelectedOrdenCompra(); + if (ordenCompra != null) { + OrdenCompraViewController controller = (OrdenCompraViewController) this.getParentController().getCard(PanelName.ORDEN_COMPRA_VIEW); + controller.setOrdenCompra(ordenCompra); + this.getParentController().showCard(PanelName.ORDEN_COMPRA_VIEW); + } + } + + private void cancelar() { + OrdenCompra ordenCompra = this.getSelectedOrdenCompra(); + if (ordenCompra == null) + return; + + if (ordenCompra.getEstado().equals("Cancelada")) { + JOptionPane.showMessageDialog( + null, + "La orden ya esta cancelada", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } else if (ordenCompra.getEstado().equals("Aceptada")) { + JOptionPane.showMessageDialog( + null, + "La orden ya fue aceptada", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } else if (!ordenCompra.getEstado().equals("En Curso")) { + JOptionPane.showMessageDialog( + null, + "La orden esta en un estado imposible, corre!", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } + + int result = JOptionPane.showConfirmDialog( + null, + "Esta seguro de cancelar esta orden de compra?", + "Confirmar", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE + ); + + if (result == JOptionPane.YES_OPTION) { + ordenCompra.setEstado("Cancelada"); + this.repository.update(ordenCompra); + } + } + + private void aceptar() { + OrdenCompra ordenCompra = this.getSelectedOrdenCompra(); + if (ordenCompra == null) + return; + + if (ordenCompra.getEstado().equals("Cancelada")) { + JOptionPane.showMessageDialog( + null, + "La orden fue cancelada, no se pude aceptar", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } else if (ordenCompra.getEstado().equals("Aceptada")) { + JOptionPane.showMessageDialog( + null, + "La orden ya fue aceptada", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } else if (!ordenCompra.getEstado().equals("En Curso")) { + JOptionPane.showMessageDialog( + null, + "La orden está en un estado imposible, corre!", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return; + } + OrdenCompraAceptarController controller = (OrdenCompraAceptarController) this.getParentController().getCard(PanelName.ORDEN_COMPRA_ACEPTAR); + controller.setOrdenCompra(ordenCompra); + this.getParentController().showCard(PanelName.ORDEN_COMPRA_ACEPTAR); + } + + private void loadComprarTable(List ordenCompra) { + BaseTableModel model = this.view.getModel(); + model.setRows(ordenCompra); + } + + private OrdenCompra getSelectedOrdenCompra() { + int selectedRow = this.view.getTable().getSelectedRow(); + if (selectedRow == -1) { + JOptionPane.showMessageDialog( + null, + "No hay orden de compra seleccionada", + "Error", + JOptionPane.ERROR_MESSAGE + ); + return null; + } + + return this.view.getModel().getRow(selectedRow); + } + + @Override + public void show() { + this.reload(); + } + + public void reload() { + this.loadComprarTable(); + this.view.getSearchField().requestFocus(); + this.view.getTable().setRowSelectionInterval(0, 0); + } + + private void loadComprarTable() { + List ordenCompra = this.repository.getAll(); + this.loadComprarTable(ordenCompra); + } + + @Override + public BasePanel getView() { + return this.view; + } + +} diff --git a/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraViewController.java b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraViewController.java new file mode 100644 index 0000000..bde5f5c --- /dev/null +++ b/src/main/java/xyz/danielcortes/controllers/orden_compra/OrdenCompraViewController.java @@ -0,0 +1,45 @@ +package xyz.danielcortes.controllers.orden_compra; + +import xyz.danielcortes.controllers.LaunchController; +import xyz.danielcortes.framework.BaseController; +import xyz.danielcortes.framework.BasePanel; +import xyz.danielcortes.framework.PanelName; +import xyz.danielcortes.models.OrdenCompra; +import xyz.danielcortes.views.orden_compra.OrdenCompraViewPanel; + +public class OrdenCompraViewController extends BaseController { + + private OrdenCompraViewPanel view; + private OrdenCompra ordenCompra; + + public OrdenCompraViewController(OrdenCompraViewPanel view, LaunchController parent) { + super(parent); + this.view = view; + this.setupListeners(); + } + + private void setupListeners() { + this.view.getVolverButton().addActionListener(e -> this.parentController.showCard(PanelName.ORDEN_COMPRA_SEARCH)); + } + + public void setOrdenCompra(OrdenCompra ordenCompra) { + this.ordenCompra = ordenCompra; + } + + @Override + public void show() { + this.view.getDistribuidorField().setText(this.ordenCompra.getDistribuidor().getRut()); + this.fillTable(); + } + + @Override + public BasePanel getView() { + return this.view; + } + + private void fillTable() { + if (this.ordenCompra != null) { + this.view.getLibroTableModel().setRows(this.ordenCompra.getLibros()); + } + } +} diff --git a/src/main/java/xyz/danielcortes/framework/BaseTableModel.java b/src/main/java/xyz/danielcortes/framework/BaseTableModel.java index 0ebe935..96fd276 100644 --- a/src/main/java/xyz/danielcortes/framework/BaseTableModel.java +++ b/src/main/java/xyz/danielcortes/framework/BaseTableModel.java @@ -24,7 +24,7 @@ public class BaseTableModel extends AbstractTableModel { * @param valueAt TriFunction la cual recibe por parametros: - La lista de filas de la tabla - Un Integer indicando la fila del que se necesita el * valor - Un Integer indicando la columna de la que se necesita el valor Y esta debe retornar un objeto con toString para poder ser mostrado en la * tabla - * + *

* Se sugiere el siguiente tipo de implementacion para la funcion (row, rowIndex, colIndex) -> { switch (colIndex) { case 0: return * row.get(rowIndex).getColumn1(); case 1: return row.get(rowIndex).getColumn2(); case 2: return row.get(rowIndex).getColumn3(); case 3: return * row.get(rowIndex).getColumn4(); } return null; } @@ -61,6 +61,30 @@ public class BaseTableModel extends AbstractTableModel { return this.valueAt.apply(this.rows, rowIndex, columnIndex); } + public void removeRow(int row) { + this.rows.remove(row); + this.fireTableRowsDeleted(row, row); + } + + public void removeRow(T t) { + int removed = this.rows.indexOf(t); + this.rows.remove(removed); + this.fireTableRowsDeleted(removed, removed); + + } + + public T getRow(int row) { + if (row > -1 || row < this.getRowCount()) { + return this.rows.get(row); + } else { + return null; + } + } + + public List getRows() { + return this.rows; + } + public void setRows(List items) { this.removeRows(); this.rows.addAll(items); @@ -74,17 +98,4 @@ public class BaseTableModel extends AbstractTableModel { this.fireTableRowsDeleted(0, rowCount - 1); } } - - public void removeRow(int row) { - this.rows.remove(row); - this.fireTableRowsDeleted(row, row); - } - - public T getRow(int row) { - if (row > -1 || row < this.getRowCount()) { - return this.rows.get(row); - } else { - return null; - } - } } diff --git a/src/main/java/xyz/danielcortes/framework/ChangeListener.java b/src/main/java/xyz/danielcortes/framework/ChangeListener.java new file mode 100644 index 0000000..3c538ec --- /dev/null +++ b/src/main/java/xyz/danielcortes/framework/ChangeListener.java @@ -0,0 +1,24 @@ +package xyz.danielcortes.framework; + +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +public interface ChangeListener extends DocumentListener { + + @Override + default void insertUpdate(DocumentEvent e) { + this.changed(e); + } + + @Override + default void removeUpdate(DocumentEvent e) { + this.changed(e); + } + + @Override + default void changedUpdate(DocumentEvent e) { + this.changed(e); + } + + void changed(DocumentEvent e); +} diff --git a/src/main/java/xyz/danielcortes/framework/PanelName.java b/src/main/java/xyz/danielcortes/framework/PanelName.java index 53b0017..dd17e16 100644 --- a/src/main/java/xyz/danielcortes/framework/PanelName.java +++ b/src/main/java/xyz/danielcortes/framework/PanelName.java @@ -97,10 +97,10 @@ public enum PanelName { CLIENTE_DIRECCION_CREATE, CLIENTE_DIRECCION_UPDATE, - COMPRAR_SEARCH, - COMPRAR_SELECCIONAR, - COMPRAR_VIEW, - COMPRAR_COMPRAR, + ORDEN_COMPRA_SEARCH, + ORDEN_COMPRA_ACEPTAR, + ORDEN_COMPRA_VIEW, + ORDEN_COMPRA_CREAR, VENDER_SEARCH, VENDER_VENDER, diff --git a/src/main/java/xyz/danielcortes/models/Libro.java b/src/main/java/xyz/danielcortes/models/Libro.java index 974b429..77f5ef4 100644 --- a/src/main/java/xyz/danielcortes/models/Libro.java +++ b/src/main/java/xyz/danielcortes/models/Libro.java @@ -66,6 +66,14 @@ public class Libro { ) private List categorias; + @ManyToMany + @JoinTable( + name = "libro_orden_compra", + joinColumns = @JoinColumn(name = "libro_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "orden_compra_id", referencedColumnName = "id") + ) + private List ordenCompras; + @ManyToOne @JoinColumn(name = "editorial_id") private Editorial editorial; @@ -170,6 +178,15 @@ public class Libro { this.ejemplares = ejemplar; } + public List getOrdenCompras() { + if (this.ordenCompras == null) + this.ordenCompras = new ArrayList<>(); + return this.ordenCompras; + } + + public void setOrdenCompras(List ordenCompras) { + this.ordenCompras = ordenCompras; + } @Override public String toString() { diff --git a/src/main/java/xyz/danielcortes/models/OrdenCompra.java b/src/main/java/xyz/danielcortes/models/OrdenCompra.java new file mode 100644 index 0000000..f1a8cbc --- /dev/null +++ b/src/main/java/xyz/danielcortes/models/OrdenCompra.java @@ -0,0 +1,96 @@ +package xyz.danielcortes.models; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "orden_compra") +public class OrdenCompra { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Integer id; + + @Column(name = "estado") + private String estado; + + @ManyToMany + @JoinTable( + name = "libro_orden_compra", + joinColumns = @JoinColumn(name = "orden_compra_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "libro_id", referencedColumnName = "id")) + private List libros; + + @ManyToOne + @JoinColumn(name = "distribuidor_id") + private Distribuidor distribuidor; + + @ManyToOne + @JoinColumn(name = "compra_id") + private Compra compra; + + @Column(name = "inserted_at") + private LocalDateTime insertedAt; + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getEstado() { + return this.estado; + } + + public void setEstado(String estado) { + this.estado = estado; + } + + public List getLibros() { + if (this.libros == null) + this.libros = new ArrayList<>(); + return this.libros; + } + + public void setLibros(List libros) { + this.libros = libros; + } + + public Distribuidor getDistribuidor() { + return this.distribuidor; + } + + public void setDistribuidor(Distribuidor distribuidor) { + this.distribuidor = distribuidor; + } + + public Compra getCompra() { + return this.compra; + } + + public void setCompra(Compra compra) { + this.compra = compra; + } + + public LocalDateTime getInsertedAt() { + return this.insertedAt; + } + + public void setInsertedAt(LocalDateTime insertedAt) { + this.insertedAt = insertedAt; + } +} diff --git a/src/main/java/xyz/danielcortes/repository/OrdenCompraRepository.java b/src/main/java/xyz/danielcortes/repository/OrdenCompraRepository.java new file mode 100644 index 0000000..7197f7c --- /dev/null +++ b/src/main/java/xyz/danielcortes/repository/OrdenCompraRepository.java @@ -0,0 +1,19 @@ +package xyz.danielcortes.repository; + +import java.util.List; +import javax.persistence.Query; +import xyz.danielcortes.framework.BaseRepository; +import xyz.danielcortes.models.OrdenCompra; + +public class OrdenCompraRepository extends BaseRepository { + + public OrdenCompraRepository() { + super(OrdenCompra.class); + } + + public List search(String term) { + Query query = this.em.createQuery("SELECT o FROM OrdenCompra o WHERE LOWER(o.estado) LIKE :term"); + query.setParameter("term", "%" + term.toLowerCase() + "%"); + return query.getResultList(); + } +} diff --git a/src/main/java/xyz/danielcortes/validator/OrdenCompraValidator.java b/src/main/java/xyz/danielcortes/validator/OrdenCompraValidator.java new file mode 100644 index 0000000..db23bbf --- /dev/null +++ b/src/main/java/xyz/danielcortes/validator/OrdenCompraValidator.java @@ -0,0 +1,50 @@ +package xyz.danielcortes.validator; + +import java.util.List; +import xyz.danielcortes.framework.ValidationResult; +import xyz.danielcortes.models.Compra; +import xyz.danielcortes.models.Distribuidor; +import xyz.danielcortes.models.Libro; + +public class OrdenCompraValidator { + + public ValidationResult validateEstado(String estado) { + if (estado == null) { + return new ValidationResult("No hay estado"); + } + if (estado.isBlank()) { + return new ValidationResult("El estado esta vacio"); + } + //Lo siento, me vi en la necesidad de hacer la validacion asi + // se ve mas cul + switch (estado) { + case "En Curso": + case "Aceptada": + case "Cancelada": + return ValidationResult.NON_ERROR; + default: + return new ValidationResult("El estado no es valido"); + } + } + + public ValidationResult validateLibros(List libros) { + if (libros == null || libros.isEmpty()) { + return new ValidationResult("No hay libros"); + } + return ValidationResult.NON_ERROR; + } + + public ValidationResult validateDistribuidor(Distribuidor distribuidor) { + if (distribuidor == null) { + return new ValidationResult("No hay distribuidor"); + } + return ValidationResult.NON_ERROR; + } + + public ValidationResult validateCompra(Compra compra) { + if (compra == null) { + return new ValidationResult("No hay compra"); + } + return ValidationResult.NON_ERROR; + } +} diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.form b/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.form deleted file mode 100644 index 968f76a..0000000 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.form +++ /dev/null @@ -1,186 +0,0 @@ - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.java b/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.java deleted file mode 100644 index 892bd02..0000000 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarComprarPanel.java +++ /dev/null @@ -1,200 +0,0 @@ -package xyz.danielcortes.views.comprar; - -import com.github.lgooddatepicker.components.DatePicker; -import com.intellij.uiDesigner.core.GridConstraints; -import com.intellij.uiDesigner.core.GridLayoutManager; -import com.intellij.uiDesigner.core.Spacer; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Insets; -import javax.swing.BorderFactory; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import xyz.danielcortes.framework.BasePanel; -import xyz.danielcortes.models.Distribuidor; - -public class ComprarComprarPanel extends BasePanel { - - private JPanel contentPane; - private JComboBox distribuidorCombo; - private DefaultComboBoxModel distribuidorModel; - private JButton seleccionarButton; - private JTextField folioField; - private JTextField precioNetoField; - private JTextField precioIVAField; - private JTextField precioBrutoField; - private DatePicker fechaCompraField; - private JButton guardarButton; - private JButton volverButton; - - { -// GUI initializer generated by IntelliJ IDEA GUI Designer -// >>> IMPORTANT!! <<< -// DO NOT EDIT OR ADD ANY CODE HERE! - this.$$$setupUI$$$(); - } - - @Override - public JPanel getContentPane() { - return this.contentPane; - } - - public JComboBox getDistribuidorCombo() { - return this.distribuidorCombo; - } - - public JButton getSeleccionarButton() { - return this.seleccionarButton; - } - - public JTextField getFolioField() { - return this.folioField; - } - - public JTextField getPrecioNetoField() { - return this.precioNetoField; - } - - public JTextField getPrecioIVAField() { - return this.precioIVAField; - } - - public JTextField getPrecioBrutoField() { - return this.precioBrutoField; - } - - public DatePicker getFechaCompraField() { - return this.fechaCompraField; - } - - public JButton getGuardarButton() { - return this.guardarButton; - } - - public JButton getVolverButton() { - return this.volverButton; - } - - public DefaultComboBoxModel getDistribuidorModel() { - return this.distribuidorModel; - } - - /** - * Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code! - * - * @noinspection ALL - */ - private void $$$setupUI$$$() { - createUIComponents(); - contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(7, 3, new Insets(20, 20, 20, 20), -1, -1)); - final JLabel label1 = new JLabel(); - label1.setText("Libros:"); - contentPane.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - contentPane.add(spacer1, - new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, - null, null, 0, false)); - final Spacer spacer2 = new Spacer(); - contentPane.add(spacer2, - new GridConstraints(6, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, - null, null, 0, false)); - final Spacer spacer3 = new Spacer(); - contentPane.add(spacer3, - new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, - null, null, 0, false)); - final JLabel label2 = new JLabel(); - label2.setText("Distribuidor:"); - contentPane.add(label2, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - contentPane.add(distribuidorCombo, - new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - seleccionarButton = new JButton(); - seleccionarButton.setText("Seleccionar"); - contentPane.add(seleccionarButton, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(10, 1, new Insets(10, 10, 10, 10), -1, -1)); - contentPane.add(panel1, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Factura")); - final JLabel label3 = new JLabel(); - label3.setText("Folio:"); - panel1.add(label3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - folioField = new JTextField(); - folioField.setText(""); - panel1.add(folioField, - new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - final JLabel label4 = new JLabel(); - label4.setText("Precio Neto:"); - panel1.add(label4, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - precioNetoField = new JTextField(); - panel1.add(precioNetoField, - new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - final JLabel label5 = new JLabel(); - label5.setText("Precio IVA:"); - panel1.add(label5, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - precioIVAField = new JTextField(); - precioIVAField.setEditable(false); - panel1.add(precioIVAField, - new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - final JLabel label6 = new JLabel(); - label6.setText("Precio Bruto:"); - panel1.add(label6, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - precioBrutoField = new JTextField(); - precioBrutoField.setEditable(false); - panel1.add(precioBrutoField, - new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - final JLabel label7 = new JLabel(); - label7.setText("Fecha compra:"); - panel1.add(label7, new GridConstraints(8, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - fechaCompraField = new DatePicker(); - panel1.add(fechaCompraField, - new GridConstraints(9, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); - final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel2, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - guardarButton = new JButton(); - guardarButton.setText("Guardar"); - panel2.add(guardarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), - null, 0, false)); - volverButton = new JButton(); - volverButton.setText("Volver"); - panel2.add(volverButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), - null, 0, false)); - } - - private void createUIComponents() { - this.distribuidorModel = new DefaultComboBoxModel<>(); - this.distribuidorCombo = new JComboBox<>(this.distribuidorModel); - } - - /** - * @noinspection ALL - */ - public JComponent $$$getRootComponent$$$() { - return contentPane; - } -} diff --git a/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.form b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.form new file mode 100644 index 0000000..4e3e479 --- /dev/null +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.form @@ -0,0 +1,158 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.java b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.java new file mode 100644 index 0000000..872738a --- /dev/null +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraAceptarPanel.java @@ -0,0 +1,167 @@ +package xyz.danielcortes.views.orden_compra; + +import com.github.lgooddatepicker.components.DatePicker; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; +import java.awt.Dimension; +import java.awt.Insets; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import xyz.danielcortes.framework.BasePanel; + +public class OrdenCompraAceptarPanel extends BasePanel { + + private JPanel contentPane; + private JTextField folioField; + private JTextField precioNetoField; + private JTextField ivaField; + private JTextField totalField; + private DatePicker fechaEmisionPicker; + private JButton asignarButton; + private JButton guardarButton; + private JButton volverButton; + + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + this.$$$setupUI$$$(); + } + + @Override + public JPanel getContentPane() { + return this.contentPane; + } + + public JTextField getFolioField() { + return this.folioField; + } + + public JTextField getPrecioNetoField() { + return this.precioNetoField; + } + + public JTextField getIvaField() { + return this.ivaField; + } + + public JTextField getTotalField() { + return this.totalField; + } + + public DatePicker getFechaEmisionPicker() { + return this.fechaEmisionPicker; + } + + public JButton getAsignarButton() { + return this.asignarButton; + } + + public JButton getGuardarButton() { + return this.guardarButton; + } + + public JButton getVolverButton() { + return this.volverButton; + } + + /** + * Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(14, 3, new Insets(20, 20, 20, 20), -1, -1)); + final JLabel label1 = new JLabel(); + label1.setText("Folio:"); + contentPane.add(label1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + contentPane.add(spacer1, + new GridConstraints(13, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, + null, null, 0, false)); + folioField = new JTextField(); + contentPane.add(folioField, + new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false)); + final Spacer spacer2 = new Spacer(); + contentPane.add(spacer2, + new GridConstraints(13, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, + null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + contentPane.add(spacer3, + new GridConstraints(13, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, + null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Precio Neto:"); + contentPane.add(label2, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + precioNetoField = new JTextField(); + contentPane.add(precioNetoField, + new GridConstraints(7, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + ivaField = new JTextField(); + ivaField.setEditable(false); + contentPane.add(ivaField, + new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + totalField = new JTextField(); + totalField.setEditable(false); + contentPane.add(totalField, + new GridConstraints(11, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label3 = new JLabel(); + label3.setText("IVA:"); + contentPane.add(label3, new GridConstraints(8, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label4 = new JLabel(); + label4.setText("Total:"); + contentPane.add(label4, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label5 = new JLabel(); + label5.setText("Fecha Emision:"); + contentPane.add(label5, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + fechaEmisionPicker = new DatePicker(); + contentPane.add(fechaEmisionPicker, + new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(12, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + guardarButton = new JButton(); + guardarButton.setText("Guardar"); + panel1.add(guardarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + volverButton = new JButton(); + volverButton.setText("Volver"); + panel1.add(volverButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + asignarButton = new JButton(); + asignarButton.setText("Asignar"); + contentPane.add(asignarButton, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + final JLabel label6 = new JLabel(); + label6.setText("Ejemplares:"); + contentPane.add(label6, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } + +} diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.form b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.form similarity index 60% rename from src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.form rename to src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.form index 6acd316..806dc8a 100644 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.form +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.form @@ -1,28 +1,28 @@ -
- + + - + - + - + - + @@ -30,59 +30,25 @@ - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -90,19 +56,9 @@ - - - - - - - - - - - + @@ -110,6 +66,16 @@ + + + + + + + + + + @@ -132,6 +98,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.java b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.java similarity index 62% rename from src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.java rename to src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.java index eafe37b..7571dab 100644 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarSeleccionarPanel.java +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraCrearPanel.java @@ -1,4 +1,4 @@ -package xyz.danielcortes.views.comprar; +package xyz.danielcortes.views.orden_compra; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; @@ -12,25 +12,27 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JSpinner; import javax.swing.JTable; -import javax.swing.JTextField; import xyz.danielcortes.framework.BasePanel; import xyz.danielcortes.framework.BaseTableModel; -import xyz.danielcortes.models.Ejemplar; +import xyz.danielcortes.models.Distribuidor; import xyz.danielcortes.models.Libro; -public class ComprarSeleccionarPanel extends BasePanel { +public class OrdenCompraCrearPanel extends BasePanel { private JPanel contentPane; - private JTable ejemplaresTable; - private BaseTableModel ejemplaresTableModel; + private JTable librosTable; + private BaseTableModel libroTableModel; private JComboBox librosCombo; private DefaultComboBoxModel librosComboModel; + private JComboBox distribuidorCombo; + private DefaultComboBoxModel distribuidorComboModel; private JButton agregarButton; private JButton removerButton; private JButton guardarButton; private JButton volverButton; - private JTextField serieField; + private JSpinner cantidadSpinner; { // GUI initializer generated by IntelliJ IDEA GUI Designer @@ -44,14 +46,22 @@ public class ComprarSeleccionarPanel extends BasePanel { return this.contentPane; } - public JTable getEjemplaresTable() { - return this.ejemplaresTable; + public JTable getLibrosTable() { + return this.librosTable; } - public JComboBox getLibrosCombo() { + public BaseTableModel getLibroTableModel() { + return this.libroTableModel; + } + + public JComboBox getLibrosCombo() { return this.librosCombo; } + public DefaultComboBoxModel getLibrosComboModel() { + return this.librosComboModel; + } + public JButton getAgregarButton() { return this.agregarButton; } @@ -68,16 +78,16 @@ public class ComprarSeleccionarPanel extends BasePanel { return this.volverButton; } - public BaseTableModel getEjemplaresTableModel() { - return this.ejemplaresTableModel; + public JComboBox getDistribuidorCombo() { + return this.distribuidorCombo; } - public JTextField getSerieField() { - return this.serieField; + public DefaultComboBoxModel getDistribuidorComboModel() { + return this.distribuidorComboModel; } - public DefaultComboBoxModel getLibrosComboModel() { - return this.librosComboModel; + public JSpinner getCantidadSpinner() { + return this.cantidadSpinner; } /** @@ -88,60 +98,44 @@ public class ComprarSeleccionarPanel extends BasePanel { private void $$$setupUI$$$() { createUIComponents(); contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(5, 3, new Insets(20, 20, 20, 20), -1, -1)); + contentPane.setLayout(new GridLayoutManager(8, 4, new Insets(20, 20, 20, 20), -1, -1)); final Spacer spacer1 = new Spacer(); contentPane.add(spacer1, - new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, + new GridConstraints(7, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final JScrollPane scrollPane1 = new JScrollPane(); - contentPane.add(scrollPane1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + contentPane.add(scrollPane1, new GridConstraints(5, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(400, -1), null, 0, false)); - scrollPane1.setViewportView(ejemplaresTable); + scrollPane1.setViewportView(librosTable); final Spacer spacer2 = new Spacer(); contentPane.add(spacer2, - new GridConstraints(4, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, + new GridConstraints(7, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final Spacer spacer3 = new Spacer(); contentPane.add(spacer3, - new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, + new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(4, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - panel1.add(librosCombo, - new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(350, -1), null, 0, false)); - final JLabel label1 = new JLabel(); - label1.setText("Libro:"); - panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label2 = new JLabel(); - label2.setText("Serie:"); - panel1.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, - GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - serieField = new JTextField(); - serieField.setText(""); - panel1.add(serieField, - new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); agregarButton = new JButton(); agregarButton.setText("Agregar"); - panel1.add(agregarButton, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + panel1.add(agregarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + removerButton = new JButton(); + removerButton.setText("Remover"); + panel1.add(removerButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel2, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel2, new GridConstraints(6, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - removerButton = new JButton(); - removerButton.setText("Remover"); - panel2.add(removerButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, - GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), - null, 0, false)); guardarButton = new JButton(); guardarButton.setText("Guardar"); panel2.add(guardarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, @@ -152,30 +146,53 @@ public class ComprarSeleccionarPanel extends BasePanel { panel2.add(volverButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Distribuidor:"); + contentPane.add(label1, new GridConstraints(0, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + contentPane.add(distribuidorCombo, + new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Cantidad:"); + contentPane.add(label2, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label3 = new JLabel(); + label3.setText("Libro:"); + contentPane.add(label3, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + contentPane.add(librosCombo, + new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + cantidadSpinner = new JSpinner(); + contentPane.add(cantidadSpinner, + new GridConstraints(3, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(50, -1), null, 0, false)); } private void createUIComponents() { this.librosComboModel = new DefaultComboBoxModel<>(); this.librosCombo = new JComboBox<>(this.librosComboModel); - this.ejemplaresTableModel = new BaseTableModel<>( - new String[]{"ISBN", "Titulo", "Precio Referencial", "Serie"}, + this.distribuidorComboModel = new DefaultComboBoxModel<>(); + this.distribuidorCombo = new JComboBox<>(this.distribuidorComboModel); + + this.libroTableModel = new BaseTableModel<>( + new String[]{"ISBN", "Titulo", "Precio Referencial"}, (rows, rowIndex, colIndex) -> { switch (colIndex) { case 0: - return rows.get(rowIndex).getLibro().getIsbn(); + return rows.get(rowIndex).getIsbn(); case 1: - return rows.get(rowIndex).getLibro().getTitulo(); + return rows.get(rowIndex).getTitulo(); case 2: - return rows.get(rowIndex).getLibro().getPrecioReferencia(); - case 3: - return rows.get(rowIndex).getSerie(); + return rows.get(rowIndex).getPrecioReferencia(); default: return null; } } ); - this.ejemplaresTable = new JTable(this.ejemplaresTableModel); + this.librosTable = new JTable(this.libroTableModel); } /** @@ -184,4 +201,5 @@ public class ComprarSeleccionarPanel extends BasePanel { public JComponent $$$getRootComponent$$$() { return contentPane; } + } diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.form b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.form similarity index 67% rename from src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.form rename to src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.form index 268a712..409cc76 100644 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.form +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.form @@ -1,9 +1,9 @@ -
- + + - + @@ -57,14 +57,14 @@ - + - + @@ -74,7 +74,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.java b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.java similarity index 67% rename from src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.java rename to src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.java index de3dcad..9eb11d1 100644 --- a/src/main/java/xyz/danielcortes/views/comprar/ComprarSearchPanel.java +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraSearchPanel.java @@ -1,4 +1,4 @@ -package xyz.danielcortes.views.comprar; +package xyz.danielcortes.views.orden_compra; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; @@ -13,17 +13,19 @@ import javax.swing.JTextField; import javax.swing.ListSelectionModel; import xyz.danielcortes.framework.BasePanel; import xyz.danielcortes.framework.BaseTableModel; -import xyz.danielcortes.models.Compra; +import xyz.danielcortes.models.OrdenCompra; -public class ComprarSearchPanel extends BasePanel { +public class OrdenCompraSearchPanel extends BasePanel { private JPanel contentPane; private JTextField searchField; private JButton buscarButton; private JTable table; - private BaseTableModel model; - private JButton comprarButton; + private BaseTableModel model; + private JButton crearButton; private JButton verButton; + private JButton cancelarButton; + private JButton aceptarButton; { // GUI initializer generated by IntelliJ IDEA GUI Designer @@ -32,6 +34,11 @@ public class ComprarSearchPanel extends BasePanel { this.$$$setupUI$$$(); } + @Override + public JPanel getContentPane() { + return this.contentPane; + } + public JTextField getSearchField() { return this.searchField; } @@ -44,21 +51,24 @@ public class ComprarSearchPanel extends BasePanel { return this.table; } - public BaseTableModel getModel() { + public BaseTableModel getModel() { return this.model; } - public JButton getComprarButton() { - return this.comprarButton; + public JButton getCrearButton() { + return this.crearButton; } public JButton getVerButton() { return this.verButton; } - @Override - public JPanel getContentPane() { - return this.contentPane; + public JButton getCancelarButton() { + return this.cancelarButton; + } + + public JButton getAceptarButton() { + return this.aceptarButton; } /** @@ -69,7 +79,7 @@ public class ComprarSearchPanel extends BasePanel { private void $$$setupUI$$$() { createUIComponents(); contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(3, 1, new Insets(20, 20, 20, 20), -1, -1)); + contentPane.setLayout(new GridLayoutManager(4, 1, new Insets(20, 20, 20, 20), -1, -1)); final JScrollPane scrollPane1 = new JScrollPane(); contentPane.add(scrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, @@ -94,35 +104,46 @@ public class ComprarSearchPanel extends BasePanel { contentPane.add(panel2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - comprarButton = new JButton(); - comprarButton.setText("Comprar"); - panel2.add(comprarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + crearButton = new JButton(); + crearButton.setText("Crear"); + panel2.add(crearButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); verButton = new JButton(); - verButton.setText("Ver Orden de Compra"); + verButton.setText("Ver"); panel2.add(verButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + cancelarButton = new JButton(); + cancelarButton.setText("Cancelar Orden"); + panel3.add(cancelarButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + aceptarButton = new JButton(); + aceptarButton.setText("Recibir Orden"); + panel3.add(aceptarButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); } private void createUIComponents() { this.model = new BaseTableModel<>( - new String[]{"Folio Factura", "Precio Neto", "Precio Bruto", "Distribuidor", "Fecha Compra", "Nº Libros Comprados"}, + new String[]{"Distribuidor", "Nº Libros", "Estado", "Fecha Emision"}, (row, rowIndex, colIndex) -> { switch (colIndex) { case 0: - return row.get(rowIndex).getFactura().getFolio(); - case 1: - return row.get(rowIndex).getFactura().getPrecioNeto(); - case 2: - return row.get(rowIndex).getFactura().getPrecioBruto(); - case 3: return row.get(rowIndex).getDistribuidor().getRut(); - case 4: - return row.get(rowIndex).getFactura().getFechaVenta(); - case 6: - return row.get(rowIndex).getEjemplares().size(); + case 1: + return row.get(rowIndex).getLibros().size(); + case 2: + return row.get(rowIndex).getEstado(); + case 3: + return row.get(rowIndex).getInsertedAt(); default: return null; } diff --git a/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.form b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.form new file mode 100644 index 0000000..fe6cf2a --- /dev/null +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.form @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.java b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.java new file mode 100644 index 0000000..fc3f194 --- /dev/null +++ b/src/main/java/xyz/danielcortes/views/orden_compra/OrdenCompraViewPanel.java @@ -0,0 +1,128 @@ +package xyz.danielcortes.views.orden_compra; + +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; +import java.awt.Dimension; +import java.awt.Insets; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import xyz.danielcortes.framework.BasePanel; +import xyz.danielcortes.framework.BaseTableModel; +import xyz.danielcortes.models.Libro; + +public class OrdenCompraViewPanel extends BasePanel { + + private JPanel contentPane; + private JTable librosTable; + private BaseTableModel libroTableModel; + private JButton volverButton; + private JTextField distribuidorField; + + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + this.$$$setupUI$$$(); + } + + @Override + public JPanel getContentPane() { + return this.contentPane; + } + + public JTable getLibrosTable() { + return this.librosTable; + } + + public BaseTableModel getLibroTableModel() { + return this.libroTableModel; + } + + public JButton getVolverButton() { + return this.volverButton; + } + + public JTextField getDistribuidorField() { + return this.distribuidorField; + } + + /** + * Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + createUIComponents(); + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(5, 3, new Insets(20, 20, 20, 20), -1, -1)); + final Spacer spacer1 = new Spacer(); + contentPane.add(spacer1, + new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, + null, null, 0, false)); + final JScrollPane scrollPane1 = new JScrollPane(); + contentPane.add(scrollPane1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(400, -1), null, 0, false)); + scrollPane1.setViewportView(librosTable); + final Spacer spacer2 = new Spacer(); + contentPane.add(spacer2, + new GridConstraints(4, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, + null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + contentPane.add(spacer3, + new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, + null, null, 0, false)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + volverButton = new JButton(); + volverButton.setText("Volver"); + panel1.add(volverButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), + null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Distribuidor:"); + contentPane.add(label1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + distribuidorField = new JTextField(); + distribuidorField.setEditable(false); + contentPane.add(distribuidorField, + new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + } + + private void createUIComponents() { + + this.libroTableModel = new BaseTableModel<>( + new String[]{"ISBN", "Titulo", "Precio Referencial"}, + (rows, rowIndex, colIndex) -> { + switch (colIndex) { + case 0: + return rows.get(rowIndex).getIsbn(); + case 1: + return rows.get(rowIndex).getTitulo(); + case 2: + return rows.get(rowIndex).getPrecioReferencia(); + default: + return null; + } + } + ); + this.librosTable = new JTable(this.libroTableModel); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } +}