Skip to content

Commit

Permalink
Merge pull request #13 from isamed92/liquidacion
Browse files Browse the repository at this point in the history
mejoras en edit conceptoSueldo
  • Loading branch information
isamed92 authored Feb 6, 2018
2 parents 1e93286 + 115f1d3 commit 70c7601
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/application/repository/info/ConceptoSueldoRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,19 @@ public ObservableList<ConceptoSueldo> getConceptosByEmpleadoId(int idEmpleado){
}
return list;
}
public int getLastId(){
int id=0;
try {
connection = JDBCConnection.getInstanceConnection();
preparedStatement= connection.prepareStatement("select max(idCodigoConcepto) from concepto_sueldo;");
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
id = resultSet.getInt(1);

} catch (SQLException e) {
e.printStackTrace();
}
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public class TipoLiquidacionRepository {
PreparedStatement preparedStatement;
ResultSet resultSet;

public void save(int idCategoria){
public void save(int idCategoria, int idConceptoSueldo){
try {
connection= JDBCConnection.getInstanceConnection();
preparedStatement = connection.prepareStatement("INSERT INTO tipo_liquidacion values(?,LAST_INSERT_ID())");
preparedStatement = connection.prepareStatement("INSERT INTO tipo_liquidacion values(?,?)");
preparedStatement.setInt(1,idCategoria);
preparedStatement.setInt(2,idConceptoSueldo);
preparedStatement.execute();
} catch (SQLException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private boolean showEdit(ConceptoSueldo conceptoSueldo, boolean b) {
ConceptoEditController controller = loader.getController();
controller.setDialogStage(dialogStage);
controller.setIsNew(b);
// controller.setDatos(conceptoSueldo);
controller.setDatos(conceptoSueldo);

// Show the dialog and wait until the user closes it
dialogStage.showAndWait();
Expand Down
47 changes: 37 additions & 10 deletions src/application/view/sueldo/cruds/ConceptoEditController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import application.model.enums.TipoCantidad;
import application.model.info.CategoriaEmpleado;
import application.model.sueldo.ConceptoSueldo;
import application.repository.info.CamionRepository;
import application.repository.info.CategoriaEmpleadoRepository;
import application.repository.info.ConceptoSueldoRepository;
import application.repository.info.TipoLiquidacionRepository;
Expand Down Expand Up @@ -83,7 +82,10 @@ public void handleOk(){
conceptoSueldo.setTipoConcepto("RETENCION");
if (isNew){
repository.save(conceptoSueldo);
tipoLiquidacionRepository.save(categoriaEmpleadoTableView.getSelectionModel().getSelectedItem().getIdCategoriaEmpleado());
int last = repository.getLastId();
for (int idCategoria : obtenerIDs()){
tipoLiquidacionRepository.save(idCategoria,last);
}
}
else {
repository.update(conceptoSueldo);
Expand All @@ -93,6 +95,17 @@ public void handleOk(){
}

}

private ObservableList<Integer> obtenerIDs() {
ObservableList<Integer> ids = FXCollections.observableArrayList();
for (CategoriaEmpleado categoria :
categoriaEmpleadoTableView.getItems()) {
if (categoria.getSelect().isSelected())
ids.add(categoria.getIdCategoriaEmpleado());
}
return ids;
}

@FXML
public void handleCancel(){
dialogStage.close();
Expand All @@ -102,10 +115,23 @@ public void setDialogStage(Stage dialogStage) {
}

public void setDatos(ConceptoSueldo conceptoSueldo){
/* this.conceptoSueldo = conceptoSueldo;
marcaField.setText(conceptoSueldo.getMarca());
modeloField.setText(conceptoSueldo.getModelo());
patenteField.setText(conceptoSueldo.getPatente());*/
this.conceptoSueldo = conceptoSueldo;
if (!isNew){
descripcionColField.setText(conceptoSueldo.getDescripcion());
switch (conceptoSueldo.getTipoConcepto()){
case "NO REMUNERATIVO":
haberNoRemunerativoRadioButton.setSelected(true);
break;
case "REMUNERATIVO":
haberRemunerativoRadioButton.setSelected(true);
break;
case "RETENCION":
retencionRadioButton.setSelected(true);
break;
}
cantidadTextField.setText(String.valueOf(conceptoSueldo.getCantidad()));
tipoCantidadComboBox.getSelectionModel().select(conceptoSueldo.getTipoCantidad());
}
}
public boolean isOkClicked(){
return okClicked;
Expand All @@ -114,13 +140,13 @@ private boolean isInputValid() {
String errorMessage = "";
if (descripcionColField.getText() == null || descripcionColField.getText().length() == 0)
errorMessage += "Descripcion del concepto no ingresado\n";
if (haberRemunerativoRadioButton.isSelected() || haberNoRemunerativoRadioButton.isSelected() || retencionRadioButton.isSelected())
errorMessage += "Tipo de concepto no seleccionado\n";
/*if (!haberRemunerativoRadioButton.isSelected() || !haberNoRemunerativoRadioButton.isSelected() || !retencionRadioButton.isSelected())
errorMessage += "Tipo de concepto no seleccionado\n";*/ //todo: corregir
if (cantidadTextField.getText() == null || cantidadTextField.getText().length() == 0 || !NumberUtils.isParsable(cantidadTextField.getText()))
errorMessage += "Cantidad no ingresada correctamente\n";
if (tipoCantidadComboBox.getSelectionModel().isEmpty())
errorMessage += "Por favor seleecione un tipo de cantidad (porcentaje, fijo o unidad).\n";
if (tablas()==0)
if (cantidadCategoriasChekeadas()==0)
errorMessage += "Seleccione la/las categorias asignadas al concepto.";
if (errorMessage.length() == 0) {
return true;
Expand All @@ -141,6 +167,7 @@ public void initialize(URL location, ResourceBundle resources) {
}

private void cargarCategorias(){
//todo: hacer que cuando se seleccione esta fila se guarden todas las categorias.
categorias = categoriaEmpleadoRepository.view();
categorias.add(new CategoriaEmpleado(0, "Todos"));
categoriaEmpleadoTableView.setItems(categorias);
Expand All @@ -150,7 +177,7 @@ private void setComboBox(){
tipos.setAll(TipoCantidad.FIJO.toString(), TipoCantidad.UNIDAD.toString(),TipoCantidad.PORCENTAJE.toString());
tipoCantidadComboBox.setItems(tipos);
}
private int tablas(){
private int cantidadCategoriasChekeadas(){
int cantidad=0;
for (CategoriaEmpleado categoria :
categoriaEmpleadoTableView.getItems()) {
Expand Down

0 comments on commit 70c7601

Please sign in to comment.