/// <summary> /// crea una PagoPendiente nuevo /// </summary> /// <param name="dato"></param> /// Se crea un dato de tipo PagoPendiente public void modificar(PlanillaEncabezado dato) { using (Database db = DatabaseFactory.openDatabase("rh_db")) { //Agregamos la instruccion con el stored procedure MySqlCommand comando = new MySqlCommand("sp_planilla_encabezado_UPDATE"); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("p_idPlanilla", dato.idPlanilla); comando.Parameters.AddWithValue("p_colaborador", dato.colaborador.idColaborador); comando.Parameters.AddWithValue("p_montoPago", dato.montoPago); comando.Parameters.AddWithValue("p_montoSalarioActual", dato.montoSalarioActual); comando.Parameters.AddWithValue("p_periodo", dato.periodo); comando.Parameters.AddWithValue("p_usuarioCreacion", dato.usuarioCreacion); //comando.Parameters.AddWithValue("p_usuarioModificacion", pUsuario); comando.Parameters.AddWithValue("p_estado", dato.estado); db.executeNonQuery(comando); } }
/// <summary> /// crea una PagoPendiente nuevo /// </summary> /// <param name="dato"></param> /// Se crea un dato de tipo PagoPendiente public int nuevo(PlanillaEncabezado dato) { int id = 0; using (Database db = DatabaseFactory.openDatabase("rh_db")) { //Agregamos la instruccion con el stored procedure MySqlCommand comando = new MySqlCommand("sp_planilla_encabezado_INSERT"); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("p_colaborador", dato.colaborador.idColaborador); comando.Parameters.AddWithValue("p_montoPago", dato.montoPago); comando.Parameters.AddWithValue("p_montoSalarioActual", dato.montoSalarioActual); comando.Parameters.AddWithValue("p_periodo", dato.periodo); comando.Parameters.AddWithValue("p_manual", dato.manual); comando.Parameters.AddWithValue("p_sucursal", dato.sucursal.idSucursal); comando.Parameters.AddWithValue("p_tipoCalculoPago", dato.tipoCalculoPago); comando.Parameters.AddWithValue("p_usuarioCreacion", dato.usuarioCreacion); //comando.Parameters.AddWithValue("p_usuarioModificacion", pUsuario); comando.Parameters.AddWithValue("p_estado", dato.estado); db.executeNonQuery(comando); comando = new MySqlCommand("sp_util_last_insert"); DataSet ds = db.executeReader(comando, "planilla_encabezado"); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (!row["id"].ToString().Equals("")) id = Int32.Parse(row["id"].ToString()); } return id; } }
/// <summary> /// consulta todas las aulas /// </summary> /// <returns>List</returns> public List<PlanillaEncabezado> consultarTodos() { using (Database db = DatabaseFactory.openDatabase("rh_db")) { List<PlanillaEncabezado> lista = new List<PlanillaEncabezado>(); MySqlCommand comando = new MySqlCommand("sp_planilla_encabezado_SELECT_all"); comando.CommandType = CommandType.Text; //indicamos el nombre de la tabla DataSet ds = db.executeReader(comando, "planilla_encabezado"); foreach (DataRow row in ds.Tables[0].Rows) { PlanillaEncabezado dato = new PlanillaEncabezado(); if (!row["idPlanilla"].ToString().Equals("")) dato.idPlanilla = Int32.Parse(row["idPlanilla"].ToString()); if (!row["colaborador"].ToString().Equals("")) dato.colaborador.idColaborador = Int32.Parse(row["colaborador"].ToString()); if (!row["sucursal"].ToString().Equals("")) dato.sucursal.idSucursal = Int32.Parse(row["sucursal"].ToString()); if (!row["periodo"].ToString().Equals("")) dato.periodo = row["periodo"].ToString(); if (!row["horasLaboradas"].ToString().Equals("")) dato.horasLaboradas = row["horasLaboradas"].ToString(); if (!row["horasExtras"].ToString().Equals("")) dato.horasExtras = row["horasExtras"].ToString(); if (!row["montoSalarioActual"].ToString().Equals("")) dato.montoSalarioActual = Double.Parse(row["montoSalarioActual"].ToString()); if (!row["montoPago"].ToString().Equals("")) dato.montoPago = Double.Parse(row["montoPago"].ToString()); //Para indicar los datos del usuario if (!row["usuarioCreacion"].ToString().Equals("")) dato.usuarioCreacion = row["usuarioCreacion"].ToString(); if (!row["usuarioModificacion"].ToString().Equals("")) dato.usuarioModificacion = row["usuarioModificacion"].ToString(); //Indicamos los valores de las fechas if (!row["fechaCreacion"].ToString().Equals("")) dato.fechaCreacion = DateTime.Parse(row["fechaCreacion"].ToString()); if (!row["fechaModificacion"].ToString().Equals("")) dato.fechaModificacion = DateTime.Parse(row["fechaModificacion"].ToString()); lista.Add(dato); } return lista; } }
/// <summary> /// verifica si existe una PlanillaEncabezado /// </summary> /// <param name="dato"></param> /// <returns>TRUE si existe FALSE en caso contrario</returns> public bool existe(PlanillaEncabezado dato) { using (Database db = DatabaseFactory.openDatabase("rh_db")) { MySqlCommand comando = new MySqlCommand("sp_planilla_encabezado_SELECT_ById"); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("p_idPlanilla", dato.idPlanilla); DataSet ds = db.executeReader(comando, "planilla_encabezado"); if (ds.Tables[0].Rows.Count > 0) { return true; } else { return false; } } }
protected void btnCalcular_Click(object sender, EventArgs e) { try { if (Session["listaDetalles"] != null) { double total_neto = 0; double total_bruto = 0; this.listaDetalles = (List<PlanillaDetalle>)Session["listaDetalles"]; foreach (PlanillaDetalle detalle in this.listaDetalles) { total_neto = total_neto + detalle.monto; if (detalle.tipo.Equals("PERCEPCIÓN")) { total_bruto = total_bruto + detalle.monto; } } if (total_bruto < 0) { this.lblMensaje.Text = "No puede ingresar un cálculo de planilla con un total NEGATIVO."; this.lblMensaje.CssClass = "errorMessage"; return; } PlanillaEncabezado encabezado = new PlanillaEncabezado(); encabezado.colaborador.idColaborador = Int32.Parse(this.cmbColaborador.Value.ToString()); encabezado.estado = this.cmbModo.Text; encabezado.montoPago = total_neto; encabezado.montoSalarioActual = total_bruto; encabezado.periodo = this.cmbPeriodo.Text; encabezado.sucursal.idSucursal = Int32.Parse(this.cmbSucursal.Value.ToString()); encabezado.manual = PlanillaEncabezado.MANUAL_SI; encabezado.tipoCalculoPago = this.cmbTipo.Text; encabezado.usuarioCreacion = Session["usuario"].ToString(); encabezado.idPlanilla = this.planillaEncabezadoBL.nuevo(encabezado); foreach (PlanillaDetalle detalle in this.listaDetalles) { detalle.idEncabezado = encabezado.idPlanilla; this.planillaDetalleBL.nuevo(detalle); } this.limpiar(); this.cargarDatos(); } } catch (Exception ex) { this.lblMensaje.Text = Utilidades.validarExepcionSQL(ex.Message); this.lblMensaje.CssClass = "errorMessage"; Session["errorMessage"] = ex.Message; } }
/// <summary> /// consulta una PlanillaEncabezado /// </summary> /// <param name="dato"></param> /// <returns></returns> public PlanillaEncabezado consultarId(PlanillaEncabezado dato) { using (Database db = DatabaseFactory.openDatabase("rh_db")) { MySqlCommand comando = new MySqlCommand("sp_planilla_encabezado_SELECT_ById"); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("p_idPlanilla", dato.idPlanilla); //Despues del comando indicar el nombre de la tabla DataSet ds = db.executeReader(comando, "planilla_encabezado"); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (!row["idPlanilla"].ToString().Equals("")) dato.idPlanilla = Int32.Parse(row["idPlanilla"].ToString()); if (!row["colaborador"].ToString().Equals("")) dato.colaborador.idColaborador = Int32.Parse(row["colaborador"].ToString()); if (!row["sucursal"].ToString().Equals("")) dato.sucursal.idSucursal = Int32.Parse(row["sucursal"].ToString()); if (!row["periodo"].ToString().Equals("")) dato.periodo = row["periodo"].ToString(); if (!row["horasLaboradas"].ToString().Equals("")) dato.horasLaboradas = row["horasLaboradas"].ToString(); if (!row["horasExtras"].ToString().Equals("")) dato.horasExtras = row["horasExtras"].ToString(); if (!row["horasLactancia"].ToString().Equals("")) dato.horasLactancia = row["horasLactancia"].ToString(); if (!row["horasLibres"].ToString().Equals("")) dato.horasLibres = row["horasLibres"].ToString(); if (!row["montoSalarioActual"].ToString().Equals("")) dato.montoSalarioActual = Double.Parse(row["montoSalarioActual"].ToString()); if (!row["montoPago"].ToString().Equals("")) dato.montoPago = Double.Parse(row["montoPago"].ToString()); //Para indicar los datos del usuario if (!row["usuarioCreacion"].ToString().Equals("")) dato.usuarioCreacion = row["usuarioCreacion"].ToString(); if (!row["usuarioModificacion"].ToString().Equals("")) dato.usuarioModificacion = row["usuarioModificacion"].ToString(); //Indicamos los valores de las fechas if (!row["fechaCreacion"].ToString().Equals("")) dato.fechaCreacion = DateTime.Parse(row["fechaCreacion"].ToString()); if (!row["fechaModificacion"].ToString().Equals("")) dato.fechaModificacion = DateTime.Parse(row["fechaModificacion"].ToString()); } else { dato = null; } return dato; } }
/// <summary> /// agrega un nuevo registro /// </summary> public int nuevo(PlanillaEncabezado dato) { if (!this.existe(dato)) { return this.planillaEncabezadoDA.nuevo(dato); } else { throw new Exception("Ya existe el registro."); } }
/// <summary> /// modificar un registro /// </summary> public void modificar(PlanillaEncabezado dato) { if (this.existe(dato)) { this.planillaEncabezadoDA.modificar(dato); } else { throw new Exception("Ya existe el registro."); } }
/// <summary> /// verifica si existe una PagoPendiente /// </summary> /// <param name="dato"></param> /// <returns>TRUE si existe FALSE en caso contrario</returns> public bool existe(PlanillaEncabezado dato) { return this.planillaEncabezadoDA.existe(dato); }
/// <summary> /// consulta una PlanillaEncabezados /// </summary> /// <param name="dato"></param> /// <returns></returns> public PlanillaEncabezado consultarId(PlanillaEncabezado dato) { PlanillaEncabezado planillaEncabezado = this.planillaEncabezadoDA.consultarId(dato); if (planillaEncabezado != null) { if (planillaEncabezado.colaborador.idColaborador != 0) { planillaEncabezado.colaborador = this.colaboradorBL.consultarId(new Colaborador(planillaEncabezado.colaborador.idColaborador)); } if (planillaEncabezado.sucursal.idSucursal != 0) { planillaEncabezado.sucursal = this.sucursalBL.consultarId(new Sucursal(planillaEncabezado.sucursal.idSucursal)); } } return planillaEncabezado; }
/// <summary> /// crea el encabezado de la liquitacion con sus detalles /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCrear_Click(object sender, EventArgs e) { Int32 colaborador = Int32.Parse(this.cmbColaborador.Value.ToString()); Double vacaciones = 0; Double preaviso = 0; Double totalMeses = 0; Double mensual = 0; Double diario = 0; Double cesantia = 0; Double aguinaldo = 0; Double total = 0; Int32 divisor2630 = 0; foreach (PagoMensual pago in this.planillaEncabezadoBL.consultarSalariosLiquidacion(colaborador)) { totalMeses = totalMeses + pago.monto; } mensual = totalMeses / this.ASPxGridViewProducto.VisibleRowCount + 1; if (Int32.Parse(this.cmbPago.Value.ToString().Substring(1, 1)) >= 30) { divisor2630 = 30; } else { divisor2630 = 26; } diario = (mensual / divisor2630); vacaciones = diario * Int32.Parse(this.txtVacaciones.Text); preaviso = diario * Int32.Parse(this.txtPreaviso.Text); cesantia = diario * this.planillaEncabezadoBL.consultarCantidadDiasCesantia(colaborador); aguinaldo = this.planillaEncabezadoBL.consultarMontoAguinaldo(colaborador); total = vacaciones + preaviso + cesantia + aguinaldo; PlanillaEncabezado encabezado = new PlanillaEncabezado(); encabezado.colaborador.idColaborador = colaborador; encabezado.estado = this.cmbModo.Text; encabezado.montoPago = total; encabezado.montoSalarioActual = total; encabezado.periodo = this.cmbPeriodo.Text; encabezado.sucursal.idSucursal = Int32.Parse(this.cmbSucursal.Value.ToString()); encabezado.manual = PlanillaEncabezado.MANUAL_SI; encabezado.tipoCalculoPago = this.cmbTipo.Text; encabezado.usuarioCreacion = Session["usuario"].ToString(); encabezado.idPlanilla = this.planillaEncabezadoBL.nuevo(encabezado); PlanillaDetalle detalle; if (aguinaldo > 0) { detalle = new PlanillaDetalle(); detalle.idEncabezado = encabezado.idPlanilla; detalle.producto.idProducto = 7; //AGUINALDO detalle.tipo = Producto.PERCEPCION; detalle.monto = aguinaldo; this.planillaDetalleBL.nuevo(detalle); } if (vacaciones > 0) { detalle = new PlanillaDetalle(); detalle.idEncabezado = encabezado.idPlanilla; detalle.producto.idProducto = 8; //VACACIONES detalle.tipo = Producto.PERCEPCION; detalle.monto = vacaciones; this.planillaDetalleBL.nuevo(detalle); } if (preaviso > 0) { detalle = new PlanillaDetalle(); detalle.idEncabezado = encabezado.idPlanilla; detalle.producto.idProducto = 14; //PREAVISO detalle.tipo = Producto.PERCEPCION; detalle.monto = preaviso; this.planillaDetalleBL.nuevo(detalle); } if (cesantia > 0) { detalle = new PlanillaDetalle(); detalle.idEncabezado = encabezado.idPlanilla; detalle.producto.idProducto = 15; //CESANTIA detalle.tipo = Producto.PERCEPCION; detalle.monto = cesantia; this.planillaDetalleBL.nuevo(detalle); } }