Me falto un par de cosas cuando se recibe un libro
This commit is contained in:
@@ -8,7 +8,7 @@ import javax.swing.JMenuItem;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import xyz.danielcortes.controllers.arrendar.ArrendarArrendarController;
|
import xyz.danielcortes.controllers.arrendar.ArrendarArrendarController;
|
||||||
import xyz.danielcortes.controllers.arrendar.ArrendarSearchController;
|
import xyz.danielcortes.controllers.arrendar.ArrendarSearchController;
|
||||||
import xyz.danielcortes.controllers.arrendar.ArrendarViewRecibidoController;
|
import xyz.danielcortes.controllers.arrendar.ArrendarViewController;
|
||||||
import xyz.danielcortes.controllers.autor.AutorCreateController;
|
import xyz.danielcortes.controllers.autor.AutorCreateController;
|
||||||
import xyz.danielcortes.controllers.autor.AutorSearchController;
|
import xyz.danielcortes.controllers.autor.AutorSearchController;
|
||||||
import xyz.danielcortes.controllers.autor.AutorUpdateController;
|
import xyz.danielcortes.controllers.autor.AutorUpdateController;
|
||||||
@@ -324,7 +324,7 @@ public class LaunchController {
|
|||||||
|
|
||||||
this.controllers.put(PanelName.ARRENDAR_SEARCH, new ArrendarSearchController(new ArrendarSearchPanel(), this));
|
this.controllers.put(PanelName.ARRENDAR_SEARCH, new ArrendarSearchController(new ArrendarSearchPanel(), this));
|
||||||
this.controllers.put(PanelName.ARRENDAR_ARRENDAR, new ArrendarArrendarController(new ArrendarArrendarPanel(), this));
|
this.controllers.put(PanelName.ARRENDAR_ARRENDAR, new ArrendarArrendarController(new ArrendarArrendarPanel(), this));
|
||||||
this.controllers.put(PanelName.ARRENDAR_VIEW, new ArrendarViewRecibidoController(new ArrendarViewPanel(), this));
|
this.controllers.put(PanelName.ARRENDAR_VIEW, new ArrendarViewController(new ArrendarViewPanel(), this));
|
||||||
|
|
||||||
for (Entry<PanelName, BaseController> entry : this.controllers.entrySet()) {
|
for (Entry<PanelName, BaseController> entry : this.controllers.entrySet()) {
|
||||||
this.frame.addCard(entry.getValue().getView().getContentPane(), entry.getKey());
|
this.frame.addCard(entry.getValue().getView().getContentPane(), entry.getKey());
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import xyz.danielcortes.framework.BasePanel;
|
|||||||
import xyz.danielcortes.framework.BaseTableModel;
|
import xyz.danielcortes.framework.BaseTableModel;
|
||||||
import xyz.danielcortes.framework.PanelName;
|
import xyz.danielcortes.framework.PanelName;
|
||||||
import xyz.danielcortes.models.Arriendo;
|
import xyz.danielcortes.models.Arriendo;
|
||||||
|
import xyz.danielcortes.models.Estado;
|
||||||
import xyz.danielcortes.repository.ArrendarRepository;
|
import xyz.danielcortes.repository.ArrendarRepository;
|
||||||
|
import xyz.danielcortes.repository.EjemplarRepository;
|
||||||
|
import xyz.danielcortes.repository.EstadoRepository;
|
||||||
import xyz.danielcortes.views.arrendar.ArrendarSearchPanel;
|
import xyz.danielcortes.views.arrendar.ArrendarSearchPanel;
|
||||||
import xyz.danielcortes.views.arrendar.ArriendoRecibidoDialog;
|
import xyz.danielcortes.views.arrendar.ArriendoRecibidoDialog;
|
||||||
|
|
||||||
@@ -18,11 +21,15 @@ public class ArrendarSearchController extends BaseController {
|
|||||||
|
|
||||||
private ArrendarSearchPanel view;
|
private ArrendarSearchPanel view;
|
||||||
private ArrendarRepository arrendarRepository;
|
private ArrendarRepository arrendarRepository;
|
||||||
|
private EstadoRepository estadoRepository;
|
||||||
|
private EjemplarRepository ejemplarRepository;
|
||||||
|
|
||||||
public ArrendarSearchController(ArrendarSearchPanel view, LaunchController parent) {
|
public ArrendarSearchController(ArrendarSearchPanel view, LaunchController parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.arrendarRepository = new ArrendarRepository();
|
this.arrendarRepository = new ArrendarRepository();
|
||||||
|
this.estadoRepository = new EstadoRepository();
|
||||||
|
this.ejemplarRepository = new EjemplarRepository();
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +52,7 @@ public class ArrendarSearchController extends BaseController {
|
|||||||
if (arriendo == null)
|
if (arriendo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ArrendarViewRecibidoController controller = (ArrendarViewRecibidoController) this.getParentController().getCard(PanelName.ARRENDAR_VIEW);
|
ArrendarViewController controller = (ArrendarViewController) this.getParentController().getCard(PanelName.ARRENDAR_VIEW);
|
||||||
controller.setArriendo(arriendo);
|
controller.setArriendo(arriendo);
|
||||||
this.getParentController().showCard(PanelName.ARRENDAR_VIEW);
|
this.getParentController().showCard(PanelName.ARRENDAR_VIEW);
|
||||||
}
|
}
|
||||||
@@ -55,6 +62,16 @@ public class ArrendarSearchController extends BaseController {
|
|||||||
if (arriendo == null)
|
if (arriendo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (arriendo.getFechaDevolucionReal() != null) {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
null,
|
||||||
|
"El arriendo ya fue recibido",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int multaDiaria = arriendo.getMultaDiaria();
|
int multaDiaria = arriendo.getMultaDiaria();
|
||||||
int diasAtrasado = Period.between(arriendo.getFechaDevolucionEstimada(), LocalDate.now()).getDays();
|
int diasAtrasado = Period.between(arriendo.getFechaDevolucionEstimada(), LocalDate.now()).getDays();
|
||||||
|
|
||||||
@@ -62,8 +79,15 @@ public class ArrendarSearchController extends BaseController {
|
|||||||
dialog.execute();
|
dialog.execute();
|
||||||
|
|
||||||
if (dialog.isAcepted()) {
|
if (dialog.isAcepted()) {
|
||||||
|
Estado disponible = this.estadoRepository.getByNombre("Disponible");
|
||||||
|
|
||||||
arriendo.setFechaDevolucionReal(LocalDate.now());
|
arriendo.setFechaDevolucionReal(LocalDate.now());
|
||||||
|
arriendo.getEjemplares().forEach(ejemplar -> ejemplar.setEstado(disponible));
|
||||||
|
|
||||||
|
this.ejemplarRepository.save(arriendo.getEjemplares());
|
||||||
|
|
||||||
this.arrendarRepository.update(arriendo);
|
this.arrendarRepository.update(arriendo);
|
||||||
|
|
||||||
this.view.getArriendosTableModel().fireTableDataChanged();
|
this.view.getArriendosTableModel().fireTableDataChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package xyz.danielcortes.controllers.arrendar;
|
package xyz.danielcortes.controllers.arrendar;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
import xyz.danielcortes.framework.BaseController;
|
import xyz.danielcortes.framework.BaseController;
|
||||||
@@ -8,20 +9,20 @@ import xyz.danielcortes.framework.PanelName;
|
|||||||
import xyz.danielcortes.models.Arriendo;
|
import xyz.danielcortes.models.Arriendo;
|
||||||
import xyz.danielcortes.views.arrendar.ArrendarViewPanel;
|
import xyz.danielcortes.views.arrendar.ArrendarViewPanel;
|
||||||
|
|
||||||
public class ArrendarViewRecibidoController extends BaseController {
|
public class ArrendarViewController extends BaseController {
|
||||||
|
|
||||||
public ArrendarViewPanel view;
|
public ArrendarViewPanel view;
|
||||||
public Arriendo arriendo;
|
public Arriendo arriendo;
|
||||||
|
|
||||||
|
|
||||||
public ArrendarViewRecibidoController(ArrendarViewPanel view, LaunchController parentController) {
|
public ArrendarViewController(ArrendarViewPanel view, LaunchController parentController) {
|
||||||
super(parentController);
|
super(parentController);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupListeners() {
|
private void setupListeners() {
|
||||||
this.view.getVolverButton().addActionListener(e -> this.parentController.showCard(PanelName.ARRENDAR_VIEW));
|
this.view.getVolverButton().addActionListener(e -> this.parentController.showCard(PanelName.ARRENDAR_SEARCH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArriendo(Arriendo arriendo) {
|
public void setArriendo(Arriendo arriendo) {
|
||||||
@@ -30,17 +31,26 @@ public class ArrendarViewRecibidoController extends BaseController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
if (this.arriendo != null && this.arriendo.getFechaDevolucionReal() != null) {
|
if (this.arriendo != null) {
|
||||||
int costoBase = this.arriendo.getCostoArriendo();
|
int costoBase = this.arriendo.getCostoArriendo();
|
||||||
int diasAtrasado = Math.max(0, Period.between(this.arriendo.getFechaDevolucionEstimada(), this.arriendo.getFechaDevolucionReal()).getDays());
|
|
||||||
int multaDiaria = this.arriendo.getMultaDiaria();
|
int multaDiaria = this.arriendo.getMultaDiaria();
|
||||||
int costoTotal = costoBase + multaDiaria * diasAtrasado;
|
int diasAtrasado = 0;
|
||||||
|
|
||||||
this.view.getClientesField().setText(this.arriendo.getCliente().getRut());
|
this.view.getClientesField().setText(this.arriendo.getCliente().getRut());
|
||||||
this.view.getVendedorField().setText(this.arriendo.getTrabajador().getRut());
|
this.view.getVendedorField().setText(this.arriendo.getTrabajador().getRut());
|
||||||
this.view.getEjemplaresTableModel().setRows(this.arriendo.getEjemplares());
|
this.view.getEjemplaresTableModel().setRows(this.arriendo.getEjemplares());
|
||||||
this.view.getFechaEntregaEstipuladaField().setText(this.arriendo.getFechaDevolucionEstimada().toString());
|
this.view.getFechaEntregaEstipuladaField().setText(this.arriendo.getFechaDevolucionEstimada().toString());
|
||||||
this.view.getFechaEntregaRealField().setText(this.arriendo.getFechaDevolucionReal().toString());
|
|
||||||
|
if (this.arriendo.getFechaDevolucionReal() == null) {
|
||||||
|
diasAtrasado = Math.max(0, Period.between(this.arriendo.getFechaDevolucionEstimada(), LocalDate.now()).getDays());
|
||||||
|
this.view.getFechaEntregaRealField().setText("No entregado");
|
||||||
|
} else {
|
||||||
|
diasAtrasado = Math.max(0, Period.between(this.arriendo.getFechaDevolucionEstimada(), this.arriendo.getFechaDevolucionReal()).getDays());
|
||||||
|
this.view.getFechaEntregaRealField().setText(this.arriendo.getFechaDevolucionReal().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
int costoTotal = costoBase + multaDiaria * diasAtrasado;
|
||||||
|
|
||||||
this.view.getCostoBaseField().setText(String.valueOf(costoBase));
|
this.view.getCostoBaseField().setText(String.valueOf(costoBase));
|
||||||
this.view.getMultaDiariaField().setText(String.valueOf(multaDiaria));
|
this.view.getMultaDiariaField().setText(String.valueOf(multaDiaria));
|
||||||
this.view.getDiasAtrasadosField().setText(String.valueOf(diasAtrasado));
|
this.view.getDiasAtrasadosField().setText(String.valueOf(diasAtrasado));
|
||||||
@@ -40,7 +40,7 @@ public class ArriendoValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ValidationResult validateFechaDevolucion(LocalDate date) {
|
public ValidationResult validateFechaDevolucion(LocalDate date) {
|
||||||
if (date.isBefore(LocalDate.now().plusDays(1)) || date.isEqual(LocalDate.now().plusDays(1))) {
|
if (date.isBefore(LocalDate.now()) || date.isEqual(LocalDate.now())) {
|
||||||
return new ValidationResult("La fecha de devolucion debe ser al menos 1 dias despues de hoy");
|
return new ValidationResult("La fecha de devolucion debe ser al menos 1 dias despues de hoy");
|
||||||
}
|
}
|
||||||
return ValidationResult.NON_ERROR;
|
return ValidationResult.NON_ERROR;
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public class ArriendoRecibidoDialog extends JDialog {
|
|||||||
this.acepted = true;
|
this.acepted = true;
|
||||||
this.dispose();
|
this.dispose();
|
||||||
});
|
});
|
||||||
|
this.cancelButton.addActionListener(e -> {
|
||||||
|
this.acepted = false;
|
||||||
|
this.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
this.addWindowListener(new WindowAdapter() {
|
this.addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user