private void calculo(double valor, int tipo) { int DiasDePago = 0; double FactorDePago = 0; cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); Factores.Core.FactoresHelper fh = new Factores.Core.FactoresHelper(); Factores.Core.Factores f = new Factores.Core.Factores(); ph.Command = cmd; fh.Command = cmd; p.idperiodo = idperiodo; f.anio = antiguedad; try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); FactorDePago = double.Parse(fh.FactorDePago(f).ToString()); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); this.Dispose(); } switch (tipo) { case 0: txtSD.Text = (double.Parse(txtSDI.Text) / FactorDePago).ToString("F6"); txtSueldo.Text = (double.Parse(txtSD.Text) * DiasDePago).ToString("F6"); break; case 1: txtSD.Text = (double.Parse(txtSueldo.Text) / DiasDePago).ToString("F6"); txtSDI.Text = (double.Parse(txtSD.Text) * FactorDePago).ToString("F6"); break; } }
private void btnCalcular_Click(object sender, EventArgs e) { if (txtSueldo.Text.Length != 0) { int DiasDePago = 0; double FactorDePago = 0; cnx = new MySqlConnection(); cnx.ConnectionString = cdn; cmd = new MySqlCommand(); cmd.Connection = cnx; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); Factores.Core.FactoresHelper fh = new Factores.Core.FactoresHelper(); Factores.Core.Factores f = new Factores.Core.Factores(); ph.Command = cmd; fh.Command = cmd; p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); f.anio = 0; try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); FactorDePago = double.Parse(fh.FactorDePago(f).ToString()); cnx.Close(); cnx.Dispose(); txtSD.Text = (double.Parse(txtSueldo.Text) / DiasDePago).ToString("F4"); txtSDI.Text = (double.Parse(txtSD.Text) * FactorDePago).ToString("F4"); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); this.Dispose(); } } }
private decimal ObtieneSD(decimal sdi) { int DiasDePago = 0; decimal FactorDePago = 0; decimal sd = 0; cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); fh = new Factores.Core.FactoresHelper(); Factores.Core.Factores f = new Factores.Core.Factores(); ph.Command = cmd; fh.Command = cmd; p.idperiodo = idPeriodo; f.anio = 0; try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); FactorDePago = decimal.Parse(fh.FactorDePago(f).ToString()); cnx.Close(); sd = (sdi / FactorDePago); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n Al obtener los dias de pago y/o factor de pago. \r\n" + error.Message, "Error"); this.Dispose(); } return sd; }
private void toolAplicar_Click(object sender, EventArgs e) { if (dgvCargaFaltas.Rows.Count == 0) { MessageBox.Show("No se puede aplicar verifique.", "Error"); return; } int idEmpleado = 0; bool EsAlta = false, EsReingreso = false, EsBaja = false; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; Altas.Core.AltasHelper ah = new Altas.Core.AltasHelper(); ah.Command = cmd; Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper(); rh.Command = cmd; Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper(); bh.Command = cmd; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; List<Altas.Core.Altas> lstAlta; List<Reingreso.Core.Reingresos> lstReingreso; List<Bajas.Core.Bajas> lstBaja; foreach (DataGridViewRow fila in dgvCargaFaltas.Rows) { try { cnx.Open(); idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), idEmpresa); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Obtener ID del empleado. \r\n \r\n" + error.Message, "Error"); return; } int idperiodo = 0; try { cnx.Open(); idperiodo = (int)emph.obtenerIdPeriodo(idEmpleado); cnx.Close(); } catch { MessageBox.Show("Error: al obtener el Id del Periodo.", "Error"); cnx.Dispose(); return; } Altas.Core.Altas alta = new Altas.Core.Altas(); alta.idempresa = GLOBALES.IDEMPRESA; alta.idtrabajador = idEmpleado; alta.periodoInicio = _inicioPeriodo.Date; alta.periodoFin = _finPeriodo.Date; Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos(); reingreso.idempresa = GLOBALES.IDEMPRESA; reingreso.idtrabajador = idEmpleado; reingreso.periodoinicio = _inicioPeriodo.Date; reingreso.periodofin = _finPeriodo.Date; Bajas.Core.Bajas baja = new Bajas.Core.Bajas(); baja.idempresa = GLOBALES.IDEMPRESA; baja.idtrabajador = idEmpleado; baja.periodoinicio = _inicioPeriodo.Date; baja.periodofin = _finPeriodo.Date; lstAlta = new List<Altas.Core.Altas>(); lstReingreso = new List<Reingreso.Core.Reingresos>(); lstBaja = new List<Bajas.Core.Bajas>(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; int periodo = 0; try { cnx.Open(); periodo = (int)ph.DiasDePago(p); lstAlta = ah.obtenerAlta(alta); lstReingreso = rh.obtenerReingreso(reingreso); lstBaja = bh.obtenerBaja(baja); cnx.Close(); } catch { MessageBox.Show("Error: al obtener los dias de pago.", "Error"); cnx.Dispose(); return; } if (lstAlta.Count != 0) EsAlta = true; if (lstBaja.Count != 0) EsBaja = true; if (lstReingreso.Count != 0) EsReingreso = true; int falta = int.Parse(fila.Cells["faltas"].Value.ToString()); DateTime fecha = DateTime.Parse(fila.Cells["fechainicio"].Value.ToString()); if (falta > 15) falta = 15; for (int i = 0; i < falta; i++) { int existe = 0; int existeFalta = 0; int existeVacacion = 0; try { cnx.Open(); existeFalta = (int)fh.existeFalta(idEmpleado, fecha.AddDays(i).Date); cnx.Close(); } catch { MessageBox.Show("Error: Al verificar existencia de falta.", "Error"); cnx.Dispose(); return; } if (existeFalta == 0) { Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper(); ih.Command = cmd; Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; bool FLAG_FALTAS = false; if (EsAlta) { if (fecha.AddDays(i).Date < lstAlta[0].fechaingreso.Date) { MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (EsReingreso) { if (fecha.AddDays(i).Date < lstReingreso[0].fechaingreso.Date) { MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (EsBaja) { if (fecha.AddDays(i).Date > lstBaja[0].fecha.Date) { MessageBox.Show("Error: Alta del empleado " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() + "\r\n Fecha de la falta es mayor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (!FLAG_FALTAS) { try { cnx.Open(); existe = (int)ih.existeIncidenciaEnFalta(idEmpleado, fecha.AddDays(i).Date); existeVacacion = (int)vh.existeVacacionEnFalta(idEmpleado, fecha.AddDays(i).Date); cnx.Close(); } catch { MessageBox.Show("Error: Al guardar la falta.", "Error"); cnx.Dispose(); return; } if (existe == 0 && existeVacacion == 0) try { Faltas.Core.Faltas f = new Faltas.Core.Faltas(); f.idempresa = GLOBALES.IDEMPRESA; f.idtrabajador = idEmpleado; f.periodo = periodo; f.faltas = 1; f.fechainicio = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechainicio"].Value.ToString()); f.fechafin = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechafin"].Value.ToString()); f.fecha = fecha.AddDays(i).Date; cnx.Open(); fh.insertaFalta(f); cnx.Close(); } catch { MessageBox.Show("Error: Al guardar la falta.", "Error"); cnx.Dispose(); } else MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.", "Error"); } } } EsAlta = false; EsReingreso = false; EsBaja = false; } MessageBox.Show("Faltas importadas", "Confirmación"); cnx.Dispose(); dgvCargaFaltas.Rows.Clear(); }
private void btnGuardar_Click(object sender, EventArgs e) { DateTime periodoInicio, periodoFin; bool EsAlta = false, EsReingreso = false, EsBaja = false; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Empleados.Core.EmpleadosHelper emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; Altas.Core.AltasHelper ah = new Altas.Core.AltasHelper(); ah.Command = cmd; Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper(); rh.Command = cmd; Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper(); bh.Command = cmd; List<Altas.Core.Altas> lstAlta = new List<Altas.Core.Altas>(); List<Reingreso.Core.Reingresos> lstReingreso = new List<Reingreso.Core.Reingresos>(); List<Bajas.Core.Bajas> lstBaja = new List<Bajas.Core.Bajas>(); Altas.Core.Altas alta = new Altas.Core.Altas(); alta.idempresa = GLOBALES.IDEMPRESA; alta.idtrabajador = idTrabajador; alta.periodoInicio = _inicioPeriodo.Date; alta.periodoFin = _finPeriodo.Date; Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos(); reingreso.idempresa = GLOBALES.IDEMPRESA; reingreso.idtrabajador = idTrabajador; reingreso.periodoinicio = _inicioPeriodo.Date; reingreso.periodofin = _finPeriodo.Date; Bajas.Core.Bajas baja = new Bajas.Core.Bajas(); baja.idempresa = GLOBALES.IDEMPRESA; baja.idtrabajador = idTrabajador; baja.periodoinicio = _inicioPeriodo.Date; baja.periodofin = _finPeriodo.Date; int idperiodo = 0; try { cnx.Open(); idperiodo = (int)emph.obtenerIdPeriodo(idTrabajador); lstAlta = ah.obtenerAlta(alta); lstReingreso = rh.obtenerReingreso(reingreso); lstBaja = bh.obtenerBaja(baja); cnx.Close(); } catch { MessageBox.Show("Error: al obtener el Id del Periodo.","Error"); cnx.Dispose(); return; } Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; int periodo = 0; try { cnx.Open(); periodo = (int)ph.DiasDePago(p); cnx.Close(); } catch { MessageBox.Show("Error: al obtener los dias de pago.", "Error"); cnx.Dispose(); return; } if (periodo == 7) { DateTime dt = dtpFecha.Value.Date; while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); periodoInicio = dt; periodoFin = dt.AddDays(6); } else { if (dtpFecha.Value.Day <= 15) { periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 1); periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 15); } else { periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 16); periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, DateTime.DaysInMonth(dtpFecha.Value.Year, dtpFecha.Value.Month)); } } if (lstAlta.Count != 0) EsAlta = true; if (lstBaja.Count != 0) EsBaja = true; if (lstReingreso.Count != 0) EsReingreso = true; Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; List<Faltas.Core.Faltas> lstFaltas = new List<Faltas.Core.Faltas>(); int faltas = int.Parse(txtFalta.Text); if (int.Parse(txtFalta.Text) > 15) faltas = 15; for (int i = 0; i < faltas; i++) { int existe = 0; int existeVacacion = 0; try { cnx.Open(); existe = (int)fh.existeFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date); cnx.Close(); } catch { MessageBox.Show("Error: Al verificar existencia de falta.", "Error"); cnx.Dispose(); return; } if (existe != 0) { MessageBox.Show("Ya existe una falta con esa fecha.", "Error"); //return; } else { Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper(); ih.Command = cmd; Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; bool FLAG_FALTAS = false; if (EsAlta) { if (dtpFecha.Value.AddDays(i).Date < lstAlta[0].fechaingreso.Date) { MessageBox.Show("Error: Alta del empleado, Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (EsReingreso) { if (dtpFecha.Value.AddDays(i).Date < lstReingreso[0].fechaingreso.Date) { MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (EsBaja) { if (dtpFecha.Value.AddDays(i).Date > lstBaja[0].fecha.Date) { MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() + "\r\n Fecha de la falta es mayor.", "Error"); FLAG_FALTAS = true; } else FLAG_FALTAS = false; } if (!FLAG_FALTAS) { try { cnx.Open(); existe = (int)ih.existeIncidenciaEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date); existeVacacion = (int)vh.existeVacacionEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date); cnx.Close(); } catch { MessageBox.Show("Error: Al guardar la falta.", "Error"); cnx.Dispose(); return; } if (existe == 0 && existeVacacion == 0) { Faltas.Core.Faltas falta = new Faltas.Core.Faltas(); falta.idtrabajador = idTrabajador; falta.idempresa = GLOBALES.IDEMPRESA; falta.faltas = 1; falta.fechainicio = periodoInicio.Date; falta.fechafin = periodoFin.Date; falta.fecha = dtpFecha.Value.AddDays(i).Date; falta.periodo = periodo; lstFaltas.Add(falta); } else MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.", "Error"); } } } if (lstFaltas.Count != 0) { SqlBulkCopy bulk = new SqlBulkCopy(cnx); fh.bulkCommand = bulk; DataTable dtFalta = new DataTable(); DataRow dtFilaFalta; dtFalta.Columns.Add("id", typeof(Int32)); dtFalta.Columns.Add("idtrabajador", typeof(Int32)); dtFalta.Columns.Add("idempresa", typeof(Int32)); dtFalta.Columns.Add("periodo", typeof(Int32)); dtFalta.Columns.Add("faltas", typeof(Int32)); dtFalta.Columns.Add("fechainicio", typeof(DateTime)); dtFalta.Columns.Add("fechafin", typeof(DateTime)); dtFalta.Columns.Add("fecha", typeof(DateTime)); for (int i = 0; i < lstFaltas.Count; i++) { dtFilaFalta = dtFalta.NewRow(); dtFilaFalta["id"] = i + 1; dtFilaFalta["idtrabajador"] = lstFaltas[i].idtrabajador; dtFilaFalta["idempresa"] = lstFaltas[i].idempresa; dtFilaFalta["periodo"] = lstFaltas[i].periodo; dtFilaFalta["faltas"] = lstFaltas[i].faltas; dtFilaFalta["fechainicio"] = lstFaltas[i].fechainicio; dtFilaFalta["fechafin"] = lstFaltas[i].fechafin; dtFilaFalta["fecha"] = lstFaltas[i].fecha; dtFalta.Rows.Add(dtFilaFalta); } try { cnx.Open(); fh.bulkFaltas(dtFalta, "tmpFaltas"); fh.stpFaltas(); cnx.Close(); cnx.Dispose(); muestraFaltas(); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n" + error.Message + "\r\n \r\n Error Bulk Faltas.", "Error"); } } }
private void toolEliminar_Click(object sender, EventArgs e) { int fila = dgvBajasSua.CurrentCell.RowIndex; int idPeriodo = 0, diasPeriodo = 0; string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper(); bh.Command = cmd; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos periodo = new Periodos.Core.Periodos(); Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; List<Bajas.Core.Bajas> lstBaja = new List<Bajas.Core.Bajas>(); List<CalculoNomina.Core.tmpPagoNomina> lstNomina = new List<CalculoNomina.Core.tmpPagoNomina>(); try { cnx.Open(); idPeriodo = int.Parse(eh.obtenerIdPeriodo(int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString())).ToString()); periodo.idperiodo = idPeriodo; diasPeriodo = int.Parse(ph.DiasDePago(periodo).ToString()); lstBaja = bh.obtenerBaja(int.Parse(dgvBajasSua.Rows[fila].Cells[0].Value.ToString())); lstNomina = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString()), diasPeriodo); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener los datos de la baja.", "Error"); cnx.Dispose(); return; } if (lstNomina.Count != 0) if (lstBaja[0].periodoinicio == lstNomina[0].fechainicio && lstBaja[0].periodofin == lstNomina[0].fechafin) { MessageBox.Show("La baja pertenece a un periodo cerrado. No se puede eliminar.", "Información"); return; } DialogResult respuesta = MessageBox.Show("¿Quiere eliminar la baja?. \r\n \r\n CUIDADO. Esta acción eliminará permanentemente el registro.", "Confirmación", MessageBoxButtons.YesNo); if (respuesta == DialogResult.Yes) { Historial.Core.HistorialHelper hh = new Historial.Core.HistorialHelper(); hh.Command = cmd; Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus(); ee.idtrabajador = int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString()); ee.idempresa = GLOBALES.IDEMPRESA; ee.estatus = GLOBALES.ACTIVO; Bajas.Core.Bajas baja = new Bajas.Core.Bajas(); baja.idtrabajador = int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString()); baja.idempresa = GLOBALES.IDEMPRESA; baja.fecha = DateTime.Parse(dgvBajasSua.Rows[fila].Cells[8].Value.ToString()).Date; Historial.Core.Historial historial = new Historial.Core.Historial(); historial.idtrabajador = int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString()); historial.idempresa = GLOBALES.IDEMPRESA; historial.fecha_imss = DateTime.Parse(dgvBajasSua.Rows[fila].Cells[8].Value.ToString()).Date; try { cnx.Open(); bh.eliminaBaja(baja); eh.bajaEmpleado(ee); eh.actualizaEstatus(int.Parse(dgvBajasSua.Rows[fila].Cells[1].Value.ToString())); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al eliminar la baja. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } try { cnx.Open(); hh.eliminaHistorial(historial); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error: Al eliminar el movimiento del historial.\r\n" + error.Message, "Error"); cnx.Dispose(); return; } MessageBox.Show("Registro eliminado.", "Confirmación"); ListaEmpleados(); } }
private void guardar(int tipoGuardar) { int existe = 0; //SE VALIDA SI TODOS LOS CAMPOS HAN SIDO LLENADOS. string control = GLOBALES.VALIDAR(this, typeof(TextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } control = GLOBALES.VALIDAR(this, typeof(MaskedTextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } if (txtNSS.Text.Length != 11) { MessageBox.Show("El campo NSS es mayor o meno a 11 dígitos.", "Error"); return; } int idtrabajador; cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; Empleados.Core.Empleados existeEmpleado = new Empleados.Core.Empleados(); existeEmpleado.nss = txtNSS.Text.Trim().Substring(0, 10); existeEmpleado.digitoverificador = int.Parse(txtNSS.Text.Trim().Substring(10, 1)); existeEmpleado.idempresa = GLOBALES.IDEMPRESA; int existeNss; try { cnx.Open(); existeNss = (int)eh.existeEmpleado(existeEmpleado); cnx.Close(); } catch { MessageBox.Show("Error al validar existencia de empleado.", "Error"); return; } Empleados.Core.Empleados em = new Empleados.Core.Empleados(); em.nombres = txtNombre.Text; em.paterno = txtApPaterno.Text; em.materno = txtApMaterno.Text; em.noempleado = mtxtNoEmpleado.Text; em.nombrecompleto = txtApPaterno.Text + (string.IsNullOrEmpty(txtApMaterno.Text) ? "" : " " + txtApMaterno.Text) + " " + txtNombre.Text; em.fechaingreso = dtpFechaIngreso.Value; em.antiguedad = int.Parse(txtAntiguedad.Text); em.fechaantiguedad = dtpFechaAntiguedad.Value; em.fechanacimiento = dtpFechaNacimiento.Value; em.antiguedadmod = int.Parse(txtAntiguedadMod.Text); em.edad = int.Parse(txtEdad.Text); em.idempresa = GLOBALES.IDEMPRESA; em.rfc = txtRFC.Text; em.curp = txtCURP.Text; em.nss = txtNSS.Text.Trim().Substring(0, 10); em.digitoverificador = int.Parse(txtNSS.Text.Trim().Substring(10, 1)); em.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); em.idsalario = int.Parse(cmbZona.SelectedValue.ToString()); em.tiposalario = int.Parse(cmbTipoSalario.SelectedValue.ToString()); em.tiporegimen = int.Parse(cmbTipoRegimen.SelectedValue.ToString()); em.sdi = decimal.Parse(txtSDI.Text); em.sd = decimal.Parse(txtSD.Text); em.sueldo = decimal.Parse(txtSueldo.Text); em.cuenta = mtxtCuentaBancaria.Text; em.clabe = mtxtCuentaClabe.Text; em.idbancario = mtxtIdBancario.Text; em.metodopago = cmbMetodoPago.Text; //em.metodopago = int.Parse(cmbMetodoPago.SelectedValue.ToString()); if (chkObraCivil.Checked) em.obracivil = true; else em.obracivil = false; //hh = new Historial.Core.HistorialHelper(); //hh.Command = cmd; //Historial.Core.Historial h = new Historial.Core.Historial(); //h.idempresa = GLOBALES.IDEMPRESA; //h.tipomovimiento = GLOBALES.mALTA; //h.valor = decimal.Parse(txtSDI.Text); //h.fecha_imss = dtpFechaIngreso.Value; //h.fecha_sistema = DateTime.Now; //h.motivobaja = 0; //h.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); //h.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); ih = new Imagen.Core.ImagenesHelper(); ih.Command = cmd; Imagen.Core.Imagenes img = null; //Empresas.Core.EmpresasHelper empresash = new Empresas.Core.EmpresasHelper(); //empresash.Command = cmd; //Empresas.Core.Empresas empresa = new Empresas.Core.Empresas(); //empresa.idempresa = GLOBALES.IDEMPRESA; try { if (ImagenAsignada == true) { img = new Imagen.Core.Imagenes(); img.imagen = GLOBALES.IMAGEN_BYTES(bmp); img.tipopersona = GLOBALES.pEMPLEADO; } } catch (Exception error) { MessageBox.Show("Error: " + error.Message, "Error"); } switch (_tipoOperacion) { case 0: try { //Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus(); //ee.estatus = GLOBALES.ACTIVO; //ee.idempresa = GLOBALES.IDEMPRESA; em.estatus = GLOBALES.ACTIVO; em.idusuario = GLOBALES.IDUSUARIO; em.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); em.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); if (existeNss != 0) { MessageBox.Show("El empleado que desea ingresar ya existe actualmente. \r\n \r\n Es necesario realizar un reingreso.", "Error"); return; } cnx.Open(); eh.insertaEmpleado(em); idtrabajador = (int)eh.obtenerIdTrabajador(em); //h.idtrabajador = idtrabajador; //hh.insertarHistorial(h); //ee.idtrabajador = idtrabajador; //eh.insertaEmpleadoEstatus(ee); //a.idtrabajador = idtrabajador; //a.registropatronal = empresash.obtenerRegistroPatronal(empresa).ToString(); //ah.insertaAlta(a); if (ImagenAsignada == true) { img.idpersona = idtrabajador; ih.insertaImagen(img); } cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al ingresar el empleado. \r\n \r\n Error: " + error.Message); } break; case 2: try { em.idtrabajador = _idempleado; em.iddepartamento = idDepto; em.idpuesto = idPuesto; pdh = new Periodos.Core.PeriodosHelper(); pdh.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); int diasPago = 0; try { cnx.Open(); diasPago = (int)pdh.DiasDePago(p); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias de pago.", "Error"); } DateTime dt = dtpFechaIngreso.Value.Date; DateTime periodoInicio, periodoFin; int diasProporcionales = 0; if (diasPago == 7) { while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); periodoInicio = dt; periodoFin = dt.AddDays(6); diasProporcionales = (int)(periodoFin.Date - dtpFechaIngreso.Value.Date).TotalDays + 1; } else { if (dt.Day <= 15) { periodoInicio = new DateTime(dt.Year, dt.Month, 1); periodoFin = new DateTime(dt.Year, dt.Month, 15); diasProporcionales = (int)(periodoFin.Date - dtpFechaIngreso.Value.Date).TotalDays + 1; } else { int diasMes = DateTime.DaysInMonth(dt.Year, dt.Month); int diasNoLaborados = 0; periodoInicio = new DateTime(dt.Year, dt.Month, 16); periodoFin = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month)); diasNoLaborados = (int)(dtpFechaIngreso.Value.Date - periodoInicio).TotalDays; switch (diasMes) { case 28: diasProporcionales = 15 - diasNoLaborados; break; case 29: diasProporcionales = 15 - diasNoLaborados; break; case 30: diasProporcionales = (diasMes - 15) - diasNoLaborados; break; case 31: diasProporcionales = (diasMes - 16) - diasNoLaborados; break; } } } Altas.Core.AltasHelper ah = new Altas.Core.AltasHelper(); ah.Command = cmd; Altas.Core.Altas a = new Altas.Core.Altas(); a.idempresa = GLOBALES.IDEMPRESA; a.contrato = 4; a.jornada = 12; a.nss = txtNSS.Text; a.rfc = txtRFC.Text; a.curp = txtCURP.Text; a.paterno = txtApPaterno.Text; a.materno = txtApMaterno.Text; a.nombre = txtNombre.Text; a.fechaingreso = dtpFechaIngreso.Value; a.diasproporcionales = diasProporcionales; a.sdi = decimal.Parse(txtSDI.Text); a.fechanacimiento = dtpFechaNacimiento.Value; a.estado = cmbEstado.Text; a.noestado = int.Parse(cmbEstado.SelectedValue.ToString()); a.sexo = ObtieneSexo(); a.periodoInicio = periodoInicio; a.periodoFin = periodoFin; cnx.Open(); eh.actualizaEmpleado(em); a.idtrabajador = _idempleado; ah.actualizaAlta(a); if (ImagenAsignada == true) { img.idpersona = _idempleado; img.tipopersona = GLOBALES.pEMPLEADO; existe = (int)ih.ExisteImagen(img); if (existe != 0) ih.actualizaImagen(img); else ih.insertaImagen(img); } cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al actualizar el empleado. \r\n \r\n Error: " + error.Message); } break; } switch (tipoGuardar) { case 0: GLOBALES.LIMPIAR(this, typeof(TextBox)); GLOBALES.LIMPIAR(this, typeof(MaskedTextBox)); GLOBALES.REFRESCAR(this, typeof(ComboBox)); break; case 1: if (OnNuevoEmpleado != null) OnNuevoEmpleado(_tipoOperacion); this.Dispose(); break; } }
private void cmbPeriodo_SelectedIndexChanged(object sender, EventArgs e) { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); empleado.idempresa = GLOBALES.IDEMPRESA; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); if (!FLAG_COMBOBOX) { Periodos.Core.Periodos a = (Periodos.Core.Periodos)cmbPeriodo.SelectedValue; p.idperiodo = a.idperiodo; } else p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); List<Empleados.Core.Empleados> lstEmpleadoDe = new List<Empleados.Core.Empleados>(); List<Empleados.Core.Empleados> lstEmpleadoHasta = new List<Empleados.Core.Empleados>(); try { cnx.Open(); periodo = int.Parse(ph.DiasDePago(p).ToString()); lstEmpleadoDe = eh.obtenerEmpleadosBaja(empleado, periodo); lstEmpleadoHasta = eh.obtenerEmpleadosBaja(empleado, periodo); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error"); } cmbEmpleadoInicial.DataSource = lstEmpleadoDe; cmbEmpleadoInicial.DisplayMember = "noempleado"; cmbEmpleadoInicial.ValueMember = "idtrabajador"; cmbEmpleadoFinal.DataSource = lstEmpleadoHasta; cmbEmpleadoFinal.DisplayMember = "noempleado"; cmbEmpleadoFinal.ValueMember = "idtrabajador"; }
private void btnCalcular_Click(object sender, EventArgs e) { if (txtAntiguedadMod.Text.Length == 0) return; if (txtSDI.Text.Length != 0) { int DiasDePago = 0; double FactorDePago = 0; cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); Factores.Core.FactoresHelper fh = new Factores.Core.FactoresHelper(); Factores.Core.Factores f = new Factores.Core.Factores(); ph.Command = cmd; fh.Command = cmd; p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); f.anio = int.Parse(txtAntiguedadMod.Text); try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); FactorDePago = double.Parse(fh.FactorDePago(f).ToString()); cnx.Close(); cnx.Dispose(); //txtSalarioDiario.Text = (double.Parse(txtSueldo.Text) / DiasDePago).ToString("F6"); //txtSDI.Text = (double.Parse(txtSalarioDiario.Text) * FactorDePago).ToString("F6"); txtSalarioDiario.Text = (double.Parse(txtSDI.Text) / FactorDePago).ToString("F6"); txtSueldo.Text = (double.Parse(txtSalarioDiario.Text) * DiasDePago).ToString("F6"); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); this.Dispose(); } } }
private void dtpFecha_ValueChanged(object sender, EventArgs e) { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; List<CalculoNomina.Core.tmpPagoNomina> lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>(); eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos periodo = new Periodos.Core.Periodos(); int dias = 0; try { cnx.Open(); periodo.idperiodo = (int)eh.obtenerIdPeriodo(_idempleado); dias = int.Parse(ph.DiasDePago(periodo).ToString()); lstUltimaNomina = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, _idempleado, dias); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la ultima nómina del trabajador.", "Error"); cnx.Dispose(); } if (lstUltimaNomina.Count != 0) if (dtpFecha.Value.Date <= lstUltimaNomina[0].fechafin) { MessageBox.Show("La fecha de aplicación seleccionada no es valida.\r\n\r\n" + "Se empalma con la ultima nomina del trabajador, por favor verifique.", "Información"); } if (dias == 7) { DateTime dt = dtpFecha.Value; while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); inicioPeriodo = dt; finPeriodo = dt.AddDays(6); } else { if (dtpFecha.Value.Day <= 15) { inicioPeriodo = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 1); finPeriodo = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 15); } else { inicioPeriodo = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 16); finPeriodo = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, DateTime.DaysInMonth(dtpFecha.Value.Year, dtpFecha.Value.Month)); } } }
private void workVacaciones_DoWork(object sender, DoWorkEventArgs e) { int idEmpleado = 0; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; List<Vacaciones.Core.VacacionesPrima> lstMovimientos = new List<Vacaciones.Core.VacacionesPrima>(); vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; foreach (DataGridViewRow fila in dgvCargaVacaciones.Rows) { try { cnx.Open(); idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), idEmpresa); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Obtener ID del concepto. \r\n \r\n" + error.Message, "Error"); cnx.Dispose(); this.Dispose(); } Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); empleado.idtrabajador = idEmpleado; List<Empleados.Core.Empleados> lstEmpleado = new List<Empleados.Core.Empleados>(); try { cnx.Open(); lstEmpleado = emph.obtenerEmpleado(empleado); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la antigüedad del empleado.", "Error"); cnx.Dispose(); this.Dispose(); } Vacaciones.Core.DiasDerecho dd = new Vacaciones.Core.DiasDerecho(); dd.anio = lstEmpleado[0].antiguedadmod; int dias = 0; try { cnx.Open(); dias = (int)vh.diasDerecho(dd); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias por derecho del empleado.", "Error"); cnx.Dispose(); return; } Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; Faltas.Core.Faltas falta = new Faltas.Core.Faltas(); falta.idempresa = GLOBALES.IDEMPRESA; falta.idtrabajador = idEmpleado; falta.fechainicio = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["inicio"].Value.ToString()); falta.fechafin = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["fin"].Value.ToString()); int existeFaltas = 0; try { cnx.Open(); existeFaltas = (int)fh.existeFalta(falta); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener las faltas del trabajador. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int idperiodo = 0; try { cnx.Open(); idperiodo = (int)emph.obtenerIdPeriodo(idEmpleado); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener el id del periodo. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; int diasPeriodo = 0; try { cnx.Open(); diasPeriodo = (int)ph.DiasDePago(p); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener los dias del periodo. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int diasPagoReales = int.Parse(fila.Cells["diaspago"].Value.ToString()) + existeFaltas; if (diasPagoReales >= diasPeriodo) { diasPagoReales = diasPeriodo - existeFaltas; MessageBox.Show("Existen faltas del trabajador, se ajustarán las vacaciones.", "Información"); } else { diasPagoReales = int.Parse(fila.Cells["diaspago"].Value.ToString()); } Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idEmpleado; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodoinicio = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["inicio"].Value.ToString()); vp.periodofin = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["fin"].Value.ToString()); vp.diasderecho = dias; vp.fechapago = DateTime.Now.Date; vp.vacacionesprima = fila.Cells["concepto"].Value.ToString() == "Prima Vacacional" ? "P" : "V"; if (fila.Cells["concepto"].Value.ToString() == "Prima Vacacional") { vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechainicio = DateTime.Now.Date; vp.fechafin = DateTime.Now.Date; } else { vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechainicio = DateTime.Parse(fila.Cells["fechaaplicacion"].Value.ToString()); vp.fechafin = DateTime.Parse(fila.Cells["fechaaplicacion"].Value.ToString()).AddDays(diasPagoReales - 1); } lstMovimientos.Add(vp); } bulk = new SqlBulkCopy(cnx); vh.bulkCommand = bulk; DataTable dt = new DataTable(); DataRow dtFila; dt.Columns.Add("id", typeof(Int32)); dt.Columns.Add("idtrabajador", typeof(Int32)); dt.Columns.Add("idempresa", typeof(Int32)); dt.Columns.Add("periodoinicio", typeof(DateTime)); dt.Columns.Add("periodofin", typeof(DateTime)); dt.Columns.Add("diasderecho", typeof(Int32)); dt.Columns.Add("diaspago", typeof(Int32)); dt.Columns.Add("diaspendientes", typeof(Int32)); dt.Columns.Add("fechapago", typeof(DateTime)); dt.Columns.Add("vacacionesprima", typeof(String)); dt.Columns.Add("fechainicio", typeof(DateTime)); dt.Columns.Add("fechafin", typeof(DateTime)); int index = 1; for (int i = 0; i < lstMovimientos.Count; i++) { dtFila = dt.NewRow(); dtFila["id"] = i + 1; dtFila["idtrabajador"] = lstMovimientos[i].idtrabajador; dtFila["idempresa"] = lstMovimientos[i].idempresa; dtFila["periodoinicio"] = lstMovimientos[i].periodoinicio; dtFila["periodofin"] = lstMovimientos[i].periodofin; dtFila["diasderecho"] = lstMovimientos[i].diasderecho; dtFila["diaspago"] = lstMovimientos[i].diaspago; dtFila["diaspendientes"] = lstMovimientos[i].diaspendientes; dtFila["fechapago"] = lstMovimientos[i].fechapago; dtFila["vacacionesprima"] = lstMovimientos[i].vacacionesprima; dtFila["fechainicio"] = lstMovimientos[i].fechainicio; dtFila["fechafin"] = lstMovimientos[i].fechafin; dt.Rows.Add(dtFila); index++; } try { cnx.Open(); vh.bulkVacaciones(dt, "tmpVacacionesPrima"); vh.stpVacaciones(); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error (DataTable): \r\n \r\n" + error.Message, "Error"); } }
public static List<CalculoNomina.Core.tmpPagoNomina> PERCEPCIONES(List<CalculoNomina.Core.Nomina> lstConceptosPercepciones, DateTime inicio, DateTime fin, int tipoNomina) { #region VARIABLES GLOBALES string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString; SqlConnection cnx = new SqlConnection(cdn); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnx; #endregion #region LISTA PARA DATOS DEL TRABAJADOR List<CalculoNomina.Core.tmpPagoNomina> lstValoresNomina; List<CalculoNomina.Core.tmpPagoNomina> lstValoresDefinitivos; #endregion #region CALCULO lstValoresNomina = new List<CalculoNomina.Core.tmpPagoNomina>(); for (int i = 0; i < lstConceptosPercepciones.Count; i++) { CalculoNomina.Core.tmpPagoNomina vn = new CalculoNomina.Core.tmpPagoNomina(); vn.idtrabajador = lstConceptosPercepciones[i].idtrabajador; vn.idempresa = GLOBALES.IDEMPRESA; vn.idconcepto = lstConceptosPercepciones[i].id; vn.noconcepto = lstConceptosPercepciones[i].noconcepto; vn.tipoconcepto = lstConceptosPercepciones[i].tipoconcepto; vn.fechainicio = inicio.Date; vn.fechafin = fin.Date; vn.guardada = false; vn.tiponomina = tipoNomina; vn.modificado = false; CalculoFormula formula = new CalculoFormula(lstConceptosPercepciones[i].idtrabajador, inicio.Date, fin.Date, lstConceptosPercepciones[i].formula); vn.cantidad = decimal.Parse(formula.calcularFormula().ToString()); CalculoFormula formulaExcento = new CalculoFormula(lstConceptosPercepciones[i].idtrabajador, inicio.Date, fin.Date, lstConceptosPercepciones[i].formulaexento); vn.exento = decimal.Parse(formulaExcento.calcularFormula().ToString()); Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; cnx.Open(); int idperiodo = (int)eh.obtenerIdPeriodo(lstConceptosPercepciones[i].idtrabajador); cnx.Close(); Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; cnx.Open(); int dias = (int)ph.DiasDePago(p); cnx.Close(); Conceptos.Core.ConceptosHelper ch = new Conceptos.Core.ConceptosHelper(); ch.Command = cmd; Conceptos.Core.Conceptos c = new Conceptos.Core.Conceptos(); c.idempresa = GLOBALES.IDEMPRESA; c.noconcepto = lstConceptosPercepciones[i].noconcepto; c.tipoconcepto = lstConceptosPercepciones[i].tipoconcepto; c.periodo = dias; cnx.Open(); bool grava = (bool)ch.gravaConcepto(c); bool exenta = (bool)ch.exentaConcepto(c); cnx.Close(); if (grava && !exenta) vn.gravado = vn.cantidad; if (grava && exenta) { if (vn.cantidad <= vn.exento) { vn.exento = vn.cantidad; vn.gravado = 0; } else { vn.gravado = vn.cantidad - vn.exento; } } if (!grava && exenta) { vn.gravado = 0; vn.exento = vn.cantidad; } #region SWITCH SUELDO CERO switch (lstConceptosPercepciones[i].noconcepto) { case 1: if (vn.cantidad == 0) { vn.gravado = 0; lstValoresNomina.Add(vn); Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = lstConceptosPercepciones[i].idtrabajador; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodofin = fin.Date; vp.periodoinicio = inicio.Date; vp.vacacionesprima = "V"; cnx.Open(); int diasVacaciones = (int)vh.pagoVacacionesPrima(vp); cnx.Close(); if (diasVacaciones == 0) { i++; int contadorDatosNomina = i; for (int j = i; j < lstConceptosPercepciones.Count; j++) { contadorDatosNomina = j; if (lstConceptosPercepciones[j].idtrabajador == vn.idtrabajador) { CalculoNomina.Core.tmpPagoNomina vnCero = new CalculoNomina.Core.tmpPagoNomina(); vnCero.idtrabajador = lstConceptosPercepciones[j].idtrabajador; vnCero.idempresa = GLOBALES.IDEMPRESA; vnCero.idconcepto = lstConceptosPercepciones[j].id; vnCero.noconcepto = lstConceptosPercepciones[j].noconcepto; vnCero.tipoconcepto = lstConceptosPercepciones[j].tipoconcepto; vnCero.fechainicio = inicio.Date; vnCero.fechafin = fin.Date; vnCero.guardada = false; vnCero.tiponomina = tipoNomina; vnCero.modificado = false; vnCero.cantidad = 0; vnCero.exento = 0; vnCero.gravado = 0; lstValoresNomina.Add(vnCero); } else { --contadorDatosNomina; break; } } i = contadorDatosNomina; } } else lstValoresNomina.Add(vn); break; default: lstValoresNomina.Add(vn); break; } #endregion } #endregion #region EXISTENCIA DEL CONCEPTO EN TABLA int existe = 0; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; lstValoresDefinitivos = new List<CalculoNomina.Core.tmpPagoNomina>(); for (int i = 0; i < lstValoresNomina.Count; i++) { CalculoNomina.Core.tmpPagoNomina vn = new CalculoNomina.Core.tmpPagoNomina(); vn.idtrabajador = lstValoresNomina[i].idtrabajador; vn.idempresa = GLOBALES.IDEMPRESA; vn.idconcepto = lstValoresNomina[i].idconcepto; vn.noconcepto = lstValoresNomina[i].noconcepto; vn.tipoconcepto = lstValoresNomina[i].tipoconcepto; vn.fechainicio = lstValoresNomina[i].fechainicio; vn.fechafin = lstValoresNomina[i].fechafin; vn.guardada = lstValoresNomina[i].guardada; vn.tiponomina = lstValoresNomina[i].tiponomina; vn.modificado = lstValoresNomina[i].modificado; vn.exento = lstValoresNomina[i].exento; vn.gravado = lstValoresNomina[i].gravado; vn.cantidad = lstValoresNomina[i].cantidad; cnx.Open(); existe = (int)nh.existeConcepto(vn); cnx.Close(); if (existe == 0) { lstValoresDefinitivos.Add(vn); } else { cnx.Open(); nh.actualizaConcepto(vn); cnx.Close(); } } #endregion return lstValoresDefinitivos; }
public static List<CalculoNomina.Core.tmpPagoNomina> DEDUCCIONES(List<CalculoNomina.Core.Nomina> lstConceptosDeducciones, List<CalculoNomina.Core.tmpPagoNomina> lstPercepciones, DateTime inicio, DateTime fin, int tipoNomina) { #region VARIABLES GLOBALES string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString; SqlConnection cnx = new SqlConnection(cdn); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnx; #endregion #region VARIABLES bool activoInfonavit = false; #endregion #region LISTA PARA DATOS DEL TRABAJADOR List<CalculoNomina.Core.tmpPagoNomina> lstValoresNomina; List<CalculoNomina.Core.tmpPagoNomina> lstValoresDefinitivos; #endregion #region CALCULO lstValoresNomina = new List<CalculoNomina.Core.tmpPagoNomina>(); decimal isrAntes = 0, subsidioAntes = 0; for (int i = 0; i < lstConceptosDeducciones.Count; i++) { decimal percepciones = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.tipoconcepto == "P").Sum(e => e.cantidad); switch (lstConceptosDeducciones[i].noconcepto) { #region CONCEPTO IMSS case 99: int vsmdf, idsalario; decimal porcentajeImss, excedenteVsmdf, sm, sdiTrabajador; Configuracion.Core.ConfiguracionHelper ch = new Configuracion.Core.ConfiguracionHelper(); ch.Command = cmd; Imss.Core.ImssHelper ih = new Imss.Core.ImssHelper(); ih.Command = cmd; Imss.Core.Imss imss = new Imss.Core.Imss(); imss.secalcula = true; Empleados.Core.EmpleadosHelper empleadosHelper = new Empleados.Core.EmpleadosHelper(); empleadosHelper.Command = cmd; Empleados.Core.Empleados empleadoImss = new Empleados.Core.Empleados(); empleadoImss.idtrabajador = lstConceptosDeducciones[i].idtrabajador; Salario.Core.SalariosHelper sh = new Salario.Core.SalariosHelper(); sh.Command = cmd; Salario.Core.Salarios salario = new Salario.Core.Salarios(); cnx.Open(); vsmdf = int.Parse(ch.obtenerValorConfiguracion("VSMDF").ToString()); porcentajeImss = ih.CuotaObreroPatronal(imss); excedenteVsmdf = ih.ExcedenteVSM(5); idsalario = int.Parse(empleadosHelper.obtenerIdSalarioMinimo(lstConceptosDeducciones[i].idtrabajador).ToString()); salario.idsalario = idsalario; sm = decimal.Parse(sh.obtenerSalarioValor(salario).ToString()); sdiTrabajador = decimal.Parse(empleadosHelper.obtenerSalarioDiarioIntegrado(empleadoImss).ToString()); cnx.Close(); string formulaDiasAPagar = "[DiasLaborados]-[Faltas]-[DiasIncapacidad]"; CalculoFormula cfImss = new CalculoFormula(lstConceptosDeducciones[i].idtrabajador, inicio, fin, formulaDiasAPagar); int diasAPagar = int.Parse(cfImss.calcularFormula().ToString()); decimal tresVSMG = vsmdf * sm; decimal excedenteImss = 0; decimal valorImss = (sdiTrabajador * (porcentajeImss / 100)) * diasAPagar; decimal totalImss = 0; if (sdiTrabajador > tresVSMG) { excedenteImss = (sdiTrabajador - tresVSMG) * (excedenteVsmdf / 100) * diasAPagar; totalImss = valorImss + excedenteImss; } else totalImss = valorImss; CalculoNomina.Core.tmpPagoNomina imssNomina = new CalculoNomina.Core.tmpPagoNomina(); imssNomina.idtrabajador = lstConceptosDeducciones[i].idtrabajador; imssNomina.idempresa = GLOBALES.IDEMPRESA; imssNomina.idconcepto = lstConceptosDeducciones[i].id; imssNomina.noconcepto = lstConceptosDeducciones[i].noconcepto; imssNomina.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; imssNomina.fechainicio = inicio.Date; imssNomina.fechafin = fin.Date; imssNomina.exento = 0; imssNomina.gravado = 0; imssNomina.cantidad = totalImss; imssNomina.diaslaborados = 0; imssNomina.guardada = false; imssNomina.tiponomina = tipoNomina; imssNomina.modificado = false; lstValoresNomina.Add(imssNomina); break; #endregion #region CONCEPTO ISR ANTES DE SUBSIDIO case 8: decimal excedente = 0, ImpMarginal = 0, isr = 0; List<TablaIsr.Core.TablaIsr> lstIsr = new List<TablaIsr.Core.TablaIsr>(); TablaIsr.Core.IsrHelper isrh = new TablaIsr.Core.IsrHelper(); isrh.Command = cmd; CalculoNomina.Core.tmpPagoNomina isrAntesSubsidio = new CalculoNomina.Core.tmpPagoNomina(); isrAntesSubsidio.idtrabajador = lstConceptosDeducciones[i].idtrabajador; isrAntesSubsidio.idempresa = GLOBALES.IDEMPRESA; isrAntesSubsidio.idconcepto = lstConceptosDeducciones[i].id; isrAntesSubsidio.noconcepto = lstConceptosDeducciones[i].noconcepto; isrAntesSubsidio.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; isrAntesSubsidio.fechainicio = inicio.Date; isrAntesSubsidio.fechafin = fin.Date; isrAntesSubsidio.exento = 0; isrAntesSubsidio.gravado = 0; if (percepciones != 0) { decimal baseGravableIsr = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador).Sum(e => e.gravado); Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; cnx.Open(); int idperiodo = (int)eh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); cnx.Close(); Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; cnx.Open(); int dias = (int)ph.DiasDePago(p); cnx.Close(); TablaIsr.Core.TablaIsr _isr = new TablaIsr.Core.TablaIsr(); _isr.inferior = (baseGravableIsr / dias) * decimal.Parse((30.4).ToString()); cnx.Open(); lstIsr = isrh.isrCorrespondiente(_isr); cnx.Close(); excedente = ((baseGravableIsr / dias) * decimal.Parse((30.4).ToString())) - lstIsr[0].inferior; ImpMarginal = excedente * (lstIsr[0].porcentaje / 100); isr = ImpMarginal + lstIsr[0].cuota; isrAntesSubsidio.cantidad = (isr / decimal.Parse((30.4).ToString())) * dias; isrAntes = (isr / decimal.Parse((30.4).ToString())) * dias; } else { isrAntes = 0; isrAntesSubsidio.cantidad = 0; //double vacaciones = lstPercepciones.Where(e => e.idtrabajador == lstPercepciones[i].idtrabajador && e.noconcepto == 7).Sum(e => e.cantidad); //if (vacaciones != 0) //{ // double baseGravableIsr = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador).Sum(e => e.gravado); // Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); // eh.Command = cmd; // cnx.Open(); // int idperiodo = (int)eh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); // cnx.Close(); // Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); // ph.Command = cmd; // Periodos.Core.Periodos p = new Periodos.Core.Periodos(); // p.idperiodo = idperiodo; // cnx.Open(); // int dias = (int)ph.DiasDePago(p); // cnx.Close(); // TablaIsr.Core.TablaIsr _isr = new TablaIsr.Core.TablaIsr(); // _isr.inferior = (baseGravableIsr / dias) * 30.4; // cnx.Open(); // lstIsr = isrh.isrCorrespondiente(_isr); // cnx.Close(); // excedente = ((baseGravableIsr / dias) * 30.4) - lstIsr[0].inferior; // ImpMarginal = excedente * (lstIsr[0].porcentaje / 100); // isr = ImpMarginal + lstIsr[0].cuota; // isrAntesSubsidio.cantidad = isr; // isrAntes = isr; //} //else //{ // isrAntes = 0; // isrAntesSubsidio.cantidad = 0; //} } isrAntesSubsidio.guardada = false; isrAntesSubsidio.tiponomina = tipoNomina; isrAntesSubsidio.modificado = false; lstValoresNomina.Add(isrAntesSubsidio); break; #endregion #region SUBSIDIO case 15: //double sueldoSubsidio = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 1).Sum(e => e.cantidad); CalculoNomina.Core.tmpPagoNomina subsidioNomina = new CalculoNomina.Core.tmpPagoNomina(); subsidioNomina.idtrabajador = lstConceptosDeducciones[i].idtrabajador; subsidioNomina.idempresa = GLOBALES.IDEMPRESA; subsidioNomina.idconcepto = lstConceptosDeducciones[i].id; subsidioNomina.noconcepto = lstConceptosDeducciones[i].noconcepto; subsidioNomina.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; subsidioNomina.fechainicio = inicio.Date; subsidioNomina.fechafin = fin.Date; subsidioNomina.exento = 0; subsidioNomina.gravado = 0; if (percepciones != 0) { decimal baseGravableSubsidio = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador).Sum(e => e.gravado); Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); eh.Command = cmd; cnx.Open(); int idperiodo = (int)eh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); cnx.Close(); Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; cnx.Open(); int dias = (int)ph.DiasDePago(p); cnx.Close(); TablaSubsidio.Core.SubsidioHelper ts = new TablaSubsidio.Core.SubsidioHelper(); ts.Command = cmd; TablaSubsidio.Core.TablaSubsidio subsidio = new TablaSubsidio.Core.TablaSubsidio(); subsidio.desde = (baseGravableSubsidio / dias) * decimal.Parse((30.4).ToString()); decimal cantidad = 0; cnx.Open(); cantidad = decimal.Parse(ts.obtenerCantidadSubsidio(subsidio).ToString()); cnx.Close(); subsidioNomina.cantidad = (cantidad / decimal.Parse((30.4).ToString())) * dias; subsidioAntes = (cantidad / decimal.Parse((30.4).ToString())) * dias; } else { subsidioNomina.cantidad = 0; subsidioAntes = 0; //double vacacionesSubsidio = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 7).Sum(e => e.cantidad); //if (vacacionesSubsidio != 0) //{ // double baseGravableSubsidio = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador).Sum(e => e.gravado); // Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); // eh.Command = cmd; // cnx.Open(); // int idperiodo = (int)eh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); // cnx.Close(); // Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); // ph.Command = cmd; // Periodos.Core.Periodos p = new Periodos.Core.Periodos(); // p.idperiodo = idperiodo; // cnx.Open(); // int dias = (int)ph.DiasDePago(p); // cnx.Close(); // TablaSubsidio.Core.SubsidioHelper ts = new TablaSubsidio.Core.SubsidioHelper(); // ts.Command = cmd; // TablaSubsidio.Core.TablaSubsidio subsidio = new TablaSubsidio.Core.TablaSubsidio(); // subsidio.desde = (baseGravableSubsidio / dias) * 30.4; // double cantidad = 0; // cnx.Open(); // cantidad = double.Parse(ts.obtenerCantidadSubsidio(subsidio).ToString()); // cnx.Close(); // subsidioNomina.cantidad = cantidad; // subsidioAntes = cantidad; //} //else //{ // subsidioNomina.cantidad = 0; // subsidioAntes = 0; //} } subsidioNomina.guardada = false; subsidioNomina.tiponomina = tipoNomina; subsidioNomina.modificado = false; lstValoresNomina.Add(subsidioNomina); break; #endregion #region SUBSIDIO DEFINITIVO case 16: CalculoNomina.Core.tmpPagoNomina subsidioDefinitivo = new CalculoNomina.Core.tmpPagoNomina(); subsidioDefinitivo.idtrabajador = lstConceptosDeducciones[i].idtrabajador; subsidioDefinitivo.idempresa = GLOBALES.IDEMPRESA; subsidioDefinitivo.idconcepto = lstConceptosDeducciones[i].id; subsidioDefinitivo.noconcepto = lstConceptosDeducciones[i].noconcepto; subsidioDefinitivo.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; subsidioDefinitivo.fechainicio = inicio.Date; subsidioDefinitivo.fechafin = fin.Date; subsidioDefinitivo.exento = 0; subsidioDefinitivo.gravado = 0; //double sueldoSubsidioDefinitivo = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 1).Sum(e => e.cantidad); if (percepciones != 0) { Empleados.Core.EmpleadosHelper esh = new Empleados.Core.EmpleadosHelper(); esh.Command = cmd; cnx.Open(); int idperiodoSubsidio = (int)esh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); cnx.Close(); Periodos.Core.PeriodosHelper psh = new Periodos.Core.PeriodosHelper(); psh.Command = cmd; Periodos.Core.Periodos ps = new Periodos.Core.Periodos(); ps.idperiodo = idperiodoSubsidio; cnx.Open(); int diasSubsidio = (int)psh.DiasDePago(ps); cnx.Close(); if (subsidioAntes > isrAntes) subsidioDefinitivo.cantidad = subsidioAntes - isrAntes; else subsidioDefinitivo.cantidad = 0; } else { subsidioDefinitivo.cantidad = 0; //double vacacionSubsidioDefinitivo = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 7).Sum(e => e.cantidad); //if (vacacionSubsidioDefinitivo != 0) //{ // Empleados.Core.EmpleadosHelper esh = new Empleados.Core.EmpleadosHelper(); // esh.Command = cmd; // cnx.Open(); // int idperiodoSubsidio = (int)esh.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); // cnx.Close(); // Periodos.Core.PeriodosHelper psh = new Periodos.Core.PeriodosHelper(); // psh.Command = cmd; // Periodos.Core.Periodos ps = new Periodos.Core.Periodos(); // ps.idperiodo = idperiodoSubsidio; // cnx.Open(); // int diasSubsidio = (int)psh.DiasDePago(ps); // cnx.Close(); // if (subsidioAntes > isrAntes) // subsidioDefinitivo.cantidad = subsidioAntes - isrAntes; // else // subsidioDefinitivo.cantidad = 0; //} //else // subsidioDefinitivo.cantidad = 0; } subsidioDefinitivo.guardada = false; subsidioDefinitivo.tiponomina = tipoNomina; subsidioDefinitivo.modificado = false; lstValoresNomina.Add(subsidioDefinitivo); break; #endregion #region ISR DEFINITIVO case 17: CalculoNomina.Core.tmpPagoNomina isrDefinitivo = new CalculoNomina.Core.tmpPagoNomina(); isrDefinitivo.idtrabajador = lstConceptosDeducciones[i].idtrabajador; isrDefinitivo.idempresa = GLOBALES.IDEMPRESA; isrDefinitivo.idconcepto = lstConceptosDeducciones[i].id; isrDefinitivo.noconcepto = lstConceptosDeducciones[i].noconcepto; isrDefinitivo.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; isrDefinitivo.fechainicio = inicio.Date; isrDefinitivo.fechafin = fin.Date; isrDefinitivo.exento = 0; isrDefinitivo.gravado = 0; //double sueldoIsrDefinitivo = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 1).Sum(e => e.cantidad); if (percepciones != 0) { Empleados.Core.EmpleadosHelper eih = new Empleados.Core.EmpleadosHelper(); eih.Command = cmd; cnx.Open(); int idperiodoIsr = (int)eih.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); cnx.Close(); Periodos.Core.PeriodosHelper pih = new Periodos.Core.PeriodosHelper(); pih.Command = cmd; Periodos.Core.Periodos pi = new Periodos.Core.Periodos(); pi.idperiodo = idperiodoIsr; cnx.Open(); int diasIsr = (int)pih.DiasDePago(pi); cnx.Close(); if (subsidioAntes > isrAntes) { isrDefinitivo.cantidad = 0; } else { isrDefinitivo.cantidad = isrAntes - subsidioAntes; } } else { isrDefinitivo.cantidad = 0; //double vacacionIsrDefinitivo = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 7).Sum(e => e.cantidad); //if (vacacionIsrDefinitivo != 0) //{ // Empleados.Core.EmpleadosHelper eih = new Empleados.Core.EmpleadosHelper(); // eih.Command = cmd; // cnx.Open(); // int idperiodoIsr = (int)eih.obtenerIdPeriodo(lstConceptosDeducciones[i].idtrabajador); // cnx.Close(); // Periodos.Core.PeriodosHelper pih = new Periodos.Core.PeriodosHelper(); // pih.Command = cmd; // Periodos.Core.Periodos pi = new Periodos.Core.Periodos(); // pi.idperiodo = idperiodoIsr; // cnx.Open(); // int diasIsr = (int)pih.DiasDePago(pi); // cnx.Close(); // double isptIsr = 0; // if (subsidioAntes > isrAntes) // { // isrDefinitivo.cantidad = 0; // } // else // { // isptIsr = ((isrAntes - subsidioAntes) / 30.4) * diasIsr; // if (isptIsr <= 0) // { // isrDefinitivo.cantidad = 0; // } // else // { // isrDefinitivo.cantidad = isptIsr; // } // } //} //else // isrDefinitivo.cantidad = 0; } isrDefinitivo.guardada = false; isrDefinitivo.tiponomina = tipoNomina; isrDefinitivo.modificado = false; lstValoresNomina.Add(isrDefinitivo); break; #endregion #region OTRAS DEDUCCIONES default: //double sueldoDeducciones = lstPercepciones.Where(e => e.idtrabajador == lstConceptosDeducciones[i].idtrabajador && e.noconcepto == 1).Sum(e => e.cantidad); CalculoNomina.Core.tmpPagoNomina vn = new CalculoNomina.Core.tmpPagoNomina(); vn.idtrabajador = lstConceptosDeducciones[i].idtrabajador; vn.idempresa = GLOBALES.IDEMPRESA; vn.idconcepto = lstConceptosDeducciones[i].id; vn.noconcepto = lstConceptosDeducciones[i].noconcepto; vn.tipoconcepto = lstConceptosDeducciones[i].tipoconcepto; vn.fechainicio = inicio.Date; vn.fechafin = fin.Date; vn.guardada = false; vn.tiponomina = tipoNomina; vn.modificado = false; #region SUELDO DIFERENTE DE CERO if (percepciones != 0) { Infonavit.Core.InfonavitHelper infh = new Infonavit.Core.InfonavitHelper(); infh.Command = cmd; Infonavit.Core.Infonavit inf = new Infonavit.Core.Infonavit(); inf.idtrabajador = lstConceptosDeducciones[i].idtrabajador; inf.idempresa = GLOBALES.IDEMPRESA; if (lstConceptosDeducciones[i].noconcepto == 9 || lstConceptosDeducciones[i].noconcepto == 21) { cnx.Open(); activoInfonavit = (bool)infh.activoInfonavit(inf); cnx.Close(); if (activoInfonavit) { CalculoFormula cf = new CalculoFormula(lstConceptosDeducciones[i].idtrabajador, inicio.Date, fin.Date, lstConceptosDeducciones[i].formula); vn.cantidad = decimal.Parse(cf.calcularFormula().ToString()); vn.exento = 0; vn.gravado = 0; } else { vn.cantidad = 0; vn.exento = 0; vn.gravado = 0; } } else { CalculoFormula cf = new CalculoFormula(lstConceptosDeducciones[i].idtrabajador, inicio.Date, fin.Date, lstConceptosDeducciones[i].formula); vn.cantidad = decimal.Parse(cf.calcularFormula().ToString()); vn.exento = 0; vn.gravado = 0; } lstValoresNomina.Add(vn); } else { vn.cantidad = 0; vn.exento = 0; vn.gravado = 0; lstValoresNomina.Add(vn); } break; #endregion #endregion } } #endregion #region EXISTENCIA DEL CONCEPTO EN TABLA int existe = 0; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; lstValoresDefinitivos = new List<CalculoNomina.Core.tmpPagoNomina>(); for (int i = 0; i < lstValoresNomina.Count; i++) { CalculoNomina.Core.tmpPagoNomina vn = new CalculoNomina.Core.tmpPagoNomina(); vn.idtrabajador = lstValoresNomina[i].idtrabajador; vn.idempresa = GLOBALES.IDEMPRESA; vn.idconcepto = lstValoresNomina[i].idconcepto; vn.noconcepto = lstValoresNomina[i].noconcepto; vn.tipoconcepto = lstValoresNomina[i].tipoconcepto; vn.fechainicio = lstValoresNomina[i].fechainicio; vn.fechafin = lstValoresNomina[i].fechafin; vn.guardada = lstValoresNomina[i].guardada; vn.tiponomina = lstValoresNomina[i].tiponomina; vn.modificado = lstValoresNomina[i].modificado; vn.exento = lstValoresNomina[i].exento; vn.gravado = lstValoresNomina[i].gravado; vn.cantidad = lstValoresNomina[i].cantidad; cnx.Open(); existe = (int)nh.existeConcepto(vn); cnx.Close(); if (existe == 0) { lstValoresDefinitivos.Add(vn); } else { cnx.Open(); nh.actualizaConcepto(vn); cnx.Close(); } } #endregion return lstValoresDefinitivos; }
private void btnCalcular_Click(object sender, EventArgs e) { if (idempleado == 0) { MessageBox.Show("Debe especificar el empleado.", "Información"); return; } if (txtSueldo.Text.Length != 0) { int DiasDePago = 0; double FactorDePago = 0; int Periodo = 0; cnx = new MySqlConnection(); cnx.ConnectionString = cdn; cmd = new MySqlCommand(); cmd.Connection = cnx; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); Factores.Core.FactoresHelper fh = new Factores.Core.FactoresHelper(); Factores.Core.Factores f = new Factores.Core.Factores(); Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper(); Empleados.Core.Empleados em = new Empleados.Core.Empleados(); ph.Command = cmd; fh.Command = cmd; eh.Command = cmd; try { em.idtrabajador = idempleado; List <Empleados.Core.Empleados> lstEmpleado = eh.obtenerEmpleado(em); for (int i = 0; i < lstEmpleado.Count; i++) { Periodo = lstEmpleado[i].idperiodo; } } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); this.Dispose(); } p.idperiodo = Periodo; f.anio = 0; try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); FactorDePago = double.Parse(fh.FactorDePago(f).ToString()); cnx.Close(); cnx.Dispose(); txtSD.Text = (double.Parse(txtSueldo.Text) / DiasDePago).ToString("F4"); txtSDI.Text = (double.Parse(txtSD.Text) * FactorDePago).ToString("F4"); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); this.Dispose(); } } }
private decimal ObtieneSueldo(decimal sd) { int DiasDePago = 0; decimal sueldo = 0; cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ph = new Periodos.Core.PeriodosHelper(); Periodos.Core.Periodos p = new Periodos.Core.Periodos(); ph.Command = cmd; p.idperiodo = idPeriodo; try { cnx.Open(); DiasDePago = (int)ph.DiasDePago(p); cnx.Close(); sueldo = sd * DiasDePago; } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n Al obtener los dias de pago y/o factor de pago. \r\n" + error.Message, "Error"); this.Dispose(); } return sueldo; }
private int ObtenerDiasProporcionales(DateTime fechaingreso) { cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idPeriodo; int diasPago = 0; try { cnx.Open(); diasPago = (int)ph.DiasDePago(p); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias de pago.", "Error"); } DateTime dt = fechaingreso.Date; int diasProporcionales = 0; if (diasPago == 7) { while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); periodoInicio = dt; periodoFin = dt.AddDays(6); diasProporcionales = (int)(periodoFin.Date - fechaingreso.Date).TotalDays + 1; } else { if (dt.Day <= 15) { periodoInicio = new DateTime(dt.Year, dt.Month, 1); periodoFin = new DateTime(dt.Year, dt.Month, 15); diasProporcionales = (int)(periodoFin.Date - fechaingreso.Date).TotalDays + 1; } else { int diasMes = DateTime.DaysInMonth(dt.Year, dt.Month); int diasNoLaborados = 0; periodoInicio = new DateTime(dt.Year, dt.Month, 16); periodoFin = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month)); diasNoLaborados = (int)(fechaingreso.Date - periodoInicio).TotalDays; diasProporcionales = 15 - diasNoLaborados; } } return diasProporcionales; }
private void cmbPeriodo_SelectedIndexChanged(object sender, EventArgs e) { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); if (!FLAG_COMBOBOX) { Periodos.Core.Periodos a = (Periodos.Core.Periodos)cmbPeriodo.SelectedValue; p.idperiodo = a.idperiodo; } else p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); List<CalculoNomina.Core.tmpPagoNomina> lstPeriodos = new List<CalculoNomina.Core.tmpPagoNomina>(); lstvPeriodos.Items.Clear(); try { cnx.Open(); periodo = int.Parse(ph.DiasDePago(p).ToString()); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error"); } switch (cmbTipoNomina.Text) { case "Normal": try { cnx.Open(); lstPeriodos = nh.obtenerPeriodosNomina(GLOBALES.IDEMPRESA, GLOBALES.NORMAL, periodo); cnx.Close(); cnx.Dispose(); } catch (Exception) { MessageBox.Show("Error: Al obtener los periodos de la empresa.", "Error"); cnx.Dispose(); return; } break; case "Extraordinaria normal": try { cnx.Open(); lstPeriodos = nh.obtenerPeriodosNomina(GLOBALES.IDEMPRESA, GLOBALES.EXTRAORDINARIO_NORMAL, periodo); cnx.Close(); cnx.Dispose(); } catch (Exception) { MessageBox.Show("Error: Al obtener los periodos de la empresa.", "Error"); cnx.Dispose(); return; } break; } for (int i = 0; i < lstPeriodos.Count; i++) { ListViewItem Lista; Lista = lstvPeriodos.Items.Add(lstPeriodos[i].fechainicio.ToShortDateString()); Lista.SubItems.Add(lstPeriodos[i].fechafin.ToShortDateString()); } }
private void btnAceptar_Click(object sender, EventArgs e) { string rp; //SE VALIDA SI TODOS LOS CAMPOS HAN SIDO LLENADOS. string control = GLOBALES.VALIDAR(this, typeof(TextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } control = GLOBALES.VALIDAR(this, typeof(MaskedTextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Empleados.Core.EmpleadosHelper empleadoh = new Empleados.Core.EmpleadosHelper(); Historial.Core.HistorialHelper hh = new Historial.Core.HistorialHelper(); Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper(); Empresas.Core.EmpresasHelper eh = new Empresas.Core.EmpresasHelper(); Infonavit.Core.InfonavitHelper ih = new Infonavit.Core.InfonavitHelper(); empleadoh.Command = cmd; hh.Command = cmd; rh.Command = cmd; eh.Command = cmd; ih.Command = cmd; Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus(); Historial.Core.Historial historia = new Historial.Core.Historial(); Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos(); Empresas.Core.Empresas empresa = new Empresas.Core.Empresas(); empleado.idtrabajador = _idempleado; empleado.idempresa = lstEmpleado[0].idempresa; empleado.fechaingreso = dtpFechaReingreso.Value; empleado.fechaantiguedad = dtpFechaAntiguedad.Value; empleado.antiguedad = int.Parse(txtAntiguedad.Text); empleado.antiguedadmod = int.Parse(txtAntiguedadMod.Text); empleado.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); empleado.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); empleado.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); empleado.sueldo = decimal.Parse(txtSueldo.Text); empleado.sd = decimal.Parse(txtSalarioDiario.Text); empleado.sdi = decimal.Parse(txtSDI.Text); empleado.idusuario = GLOBALES.IDUSUARIO; empleado.estatus = GLOBALES.ACTIVO; empleado.cuenta = mtxtCuentaBancaria.Text; empleado.clabe = mtxtCuentaClabe.Text; empleado.idbancario = mtxtIdBancario.Text; empleado.metodopago = cmbMetodoPago.Text; if (chkObraCivil.Checked) empleado.obracivil = true; else empleado.obracivil = false; ee.idtrabajador = _idempleado; ee.idempresa = GLOBALES.IDEMPRESA; ee.estatus = GLOBALES.REINGRESO; historia.idtrabajador = _idempleado; historia.idempresa = lstEmpleado[0].idempresa; historia.valor = decimal.Parse(txtSDI.Text); historia.fecha_imss = dtpFechaReingreso.Value; historia.fecha_sistema = DateTime.Now; historia.motivobaja = 0; historia.tipomovimiento = GLOBALES.mREINGRESO; historia.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); historia.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); empresa.idempresa = lstEmpleado[0].idempresa; reingreso.idtrabajador = _idempleado; reingreso.idempresa = lstEmpleado[0].idempresa; reingreso.fechaingreso = dtpFechaReingreso.Value; reingreso.sdi = decimal.Parse(txtSDI.Text); reingreso.registro = DateTime.Now; Periodos.Core.PeriodosHelper pdh = new Periodos.Core.PeriodosHelper(); pdh.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); int diasPago = 0; try { cnx.Open(); diasPago = (int)pdh.DiasDePago(p); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias de pago.", "Error"); } DateTime dt = dtpFechaReingreso.Value.Date; DateTime periodoInicio, periodoFin; int diasProporcionales = 0; if (diasPago == 7) { while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); periodoInicio = dt; periodoFin = dt.AddDays(6); diasProporcionales = (int)(periodoFin.Date - dtpFechaReingreso.Value.Date).TotalDays + 1; } else { if (dt.Day <= 15) { periodoInicio = new DateTime(dt.Year, dt.Month, 1); periodoFin = new DateTime(dt.Year, dt.Month, 15); diasProporcionales = (int)(periodoFin.Date - dtpFechaReingreso.Value.Date).TotalDays + 1; } else { int diasMes = DateTime.DaysInMonth(dt.Year, dt.Month); int diasNoLaborados = 0; periodoInicio = new DateTime(dt.Year, dt.Month, 16); periodoFin = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month)); diasNoLaborados = (int)(dtpFechaReingreso.Value.Date - periodoInicio).TotalDays; switch (diasMes) { case 28: diasProporcionales = 15 - diasNoLaborados; break; case 29: diasProporcionales = 15 - diasNoLaborados; break; case 30: diasProporcionales = (diasMes - 15) - diasNoLaborados; break; case 31: diasProporcionales = (diasMes - 16) - diasNoLaborados; break; } } } CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; List<CalculoNomina.Core.tmpPagoNomina> lstFechas = new List<CalculoNomina.Core.tmpPagoNomina>(); bool verificaFechas = false; try { cnx.Open(); lstFechas = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, GLOBALES.NORMAL, diasPago, _idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la fecha de la ultima nómina calculada", "Error"); } if (lstFechas.Count != 0) { if (dtpFechaReingreso.Value.Date <= lstFechas[0].fechainicio.Date || dtpFechaReingreso.Value.Date <= lstFechas[0].fechafin.Date) verificaFechas = false; else verificaFechas = true; if (!verificaFechas) { MessageBox.Show("La fecha de ingreso es invalida. Fecha menor al ultimo periodo calculado, verifique.", "Error"); return; } } try { cnx.Open(); empleadoh.reingreso(empleado); empleadoh.bajaEmpleado(ee); rp = (string)eh.obtenerRegistroPatronal(empresa); reingreso.registropatronal = rp; reingreso.nss = lstEmpleado[0].nss + lstEmpleado[0].digitoverificador; reingreso.diasproporcionales = diasProporcionales; reingreso.periodoinicio = periodoInicio; reingreso.periodofin = periodoFin; rh.insertaReingreso(reingreso); hh.insertarHistorial(historia); cnx.Close(); MessageBox.Show("Empleado reingresado con éxito.", "Información"); if (OnReingreso != null) OnReingreso(GLOBALES.NUEVO); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); } int existeInfonavit = 0; try { cnx.Open(); existeInfonavit = (int)ih.existeInfonavit(_idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la existencia del Infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } List<Infonavit.Core.Infonavit> lstInfonavit = new List<Infonavit.Core.Infonavit>(); if (existeInfonavit != 0) { try { cnx.Open(); lstInfonavit = ih.obtenerInfonavitTrabajador(_idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la información de infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } try { cnx.Open(); ih.actualizaEstatusInfonavit(lstInfonavit[0].idinfonavit, _idempleado); cnx.Close(); MessageBox.Show("Trabajador cuenta con Infonavit. Crédito: " + lstInfonavit[0].credito, "Información"); } catch (Exception) { MessageBox.Show("Error: Al obtener al activar el crédito de infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } } this.Dispose(); }
private void workMovimientos_DoWork(object sender, DoWorkEventArgs e) { string formulaexento = ""; int idConcepto = 0, idEmpleado = 0; int existeConcepto = 0; int idPeriodo = 0, diasPeriodo = 0; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; List<CalculoNomina.Core.tmpPagoNomina> lstMovimientos = new List<CalculoNomina.Core.tmpPagoNomina>(); List<Movimientos.Core.Movimientos> lstOtrasDeducciones = new List<Movimientos.Core.Movimientos>(); CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; Movimientos.Core.MovimientosHelper mh = new Movimientos.Core.MovimientosHelper(); mh.Command = cmd; ch = new Conceptos.Core.ConceptosHelper(); ch.Command = cmd; emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; foreach (DataGridViewRow fila in dgvMovimientos.Rows) { Empleados.Core.EmpleadosHelper empleadosHelper = new Empleados.Core.EmpleadosHelper(); empleadosHelper.Command = cmd; cnx.Open(); idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), idEmpresa); idPeriodo = int.Parse(empleadosHelper.obtenerIdPeriodo(idEmpleado).ToString()); cnx.Close(); Periodos.Core.PeriodosHelper periodoHelper = new Periodos.Core.PeriodosHelper(); periodoHelper.Command = cmd; Periodos.Core.Periodos periodos = new Periodos.Core.Periodos(); periodos.idperiodo = idPeriodo; cnx.Open(); diasPeriodo = int.Parse(periodoHelper.DiasDePago(periodos).ToString()); cnx.Close(); try { cnx.Open(); idConcepto = (int)ch.obtenerIdConcepto(fila.Cells["concepto"].Value.ToString().TrimStart().TrimEnd(), idEmpresa, diasPeriodo); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Obtener ID del concepto. \r\n " + fila.Cells["concepto"].Value.ToString() + "\r\n" + "No. Empleado: " + fila.Cells["noempleado"].Value.ToString() + "\r\n" + error.Message, "Error"); return; } Conceptos.Core.Conceptos concepto = new Conceptos.Core.Conceptos(); concepto.id = idConcepto; List<Conceptos.Core.Conceptos> lstConcepto = new List<Conceptos.Core.Conceptos>(); try { cnx.Open(); lstConcepto = ch.obtenerConcepto(concepto); cnx.Close(); } catch { MessageBox.Show("Error al obtener el concepto. \r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); this.Dispose(); } CalculoNomina.Core.tmpPagoNomina pn = new CalculoNomina.Core.tmpPagoNomina(); pn.idempresa = GLOBALES.IDEMPRESA; pn.idtrabajador = idEmpleado; pn.idconcepto = idConcepto; pn.noconcepto = lstConcepto[0].noconcepto; pn.tipoconcepto = lstConcepto[0].tipoconcepto; pn.fechainicio = DateTime.Parse(dgvMovimientos.Rows[0].Cells["inicio"].Value.ToString()); pn.fechafin = DateTime.Parse(dgvMovimientos.Rows[0].Cells["fin"].Value.ToString()); pn.modificado = true; pn.guardada = false; pn.tiponomina = _tipoNomina; CalculoNomina.Core.tmpPagoNomina pne; switch (lstConcepto[0].tipoconcepto) { #region PERCEPCIONES case "P": Conceptos.Core.Conceptos _concepto = new Conceptos.Core.Conceptos(); concepto.noconcepto = lstConcepto[0].noconcepto; concepto.idempresa = GLOBALES.IDEMPRESA; try { cnx.Open(); formulaexento = ch.obtenerFormulaExento(concepto).ToString(); cnx.Close(); } catch { MessageBox.Show("Error al obtener la formula de exento.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } if (formulaexento == "0") { pn.cantidad = decimal.Parse(fila.Cells["cantidad"].Value.ToString()); pn.exento = 0; pn.gravado = decimal.Parse(fila.Cells["cantidad"].Value.ToString()); } else { CalculoFormula cf = new CalculoFormula(idEmpleado, DateTime.Parse(dgvMovimientos.Rows[0].Cells["inicio"].Value.ToString()), DateTime.Parse(dgvMovimientos.Rows[0].Cells["fin"].Value.ToString()), formulaexento); decimal exento = decimal.Parse(cf.calcularFormula().ToString()); decimal cantidad = decimal.Parse(fila.Cells["cantidad"].Value.ToString()); decimal gravado = 0; if (cantidad <= exento) { exento = cantidad; gravado = 0; } else { gravado = cantidad - exento; } pn.cantidad = cantidad; pn.exento = exento; pn.gravado = gravado; } pne = new CalculoNomina.Core.tmpPagoNomina(); pne.idempresa = GLOBALES.IDEMPRESA; pne.idtrabajador = idEmpleado; pne.fechainicio = DateTime.Parse(dgvMovimientos.Rows[0].Cells["inicio"].Value.ToString()); pne.fechafin = DateTime.Parse(dgvMovimientos.Rows[0].Cells["fin"].Value.ToString()); pne.noconcepto = lstConcepto[0].noconcepto; try { cnx.Open(); existeConcepto = (int)nh.existeConcepto(pne); cnx.Close(); } catch { MessageBox.Show("Error al obtener la existencia del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } if (existeConcepto == 0) { lstMovimientos.Add(pn); } else { try { cnx.Open(); nh.actualizaConceptoModificado(pn); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error al obtener la actualizar el concepto.\r\n \r\n Esta ventana se cerrará.\r\n" + error.Message, "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } } break; #endregion #region DEDUCCIONES case "D": //*****SE OBTIENE LA FORMULA DEL CONCEPTO DE DEDUCCION string formula = ""; Conceptos.Core.ConceptosHelper conceptoh = new Conceptos.Core.ConceptosHelper(); conceptoh.Command = cmd; Conceptos.Core.Conceptos conceptoDeduccion = new Conceptos.Core.Conceptos(); conceptoDeduccion.idempresa = GLOBALES.IDEMPRESA; conceptoDeduccion.noconcepto = lstConcepto[0].noconcepto; conceptoDeduccion.periodo = diasPeriodo; try { cnx.Open(); formula = conceptoh.obtenerFormula(conceptoDeduccion).ToString(); cnx.Close(); } catch { MessageBox.Show("Error al obtener la formula del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); return; } //*****FIN if (formula != "[Deduccion]") { pn.cantidad = decimal.Parse(fila.Cells["cantidad"].Value.ToString()); pn.exento = 0; pn.gravado = 0; pne = new CalculoNomina.Core.tmpPagoNomina(); pne.idempresa = GLOBALES.IDEMPRESA; pne.idtrabajador = idEmpleado; pne.fechainicio = DateTime.Parse(dgvMovimientos.Rows[0].Cells["inicio"].Value.ToString()); pne.fechafin = DateTime.Parse(dgvMovimientos.Rows[0].Cells["fin"].Value.ToString()); pne.noconcepto = lstConcepto[0].noconcepto; try { cnx.Open(); existeConcepto = (int)nh.existeConcepto(pne); cnx.Close(); } catch { MessageBox.Show("Error al obtener la existencia del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } if (existeConcepto == 0) { lstMovimientos.Add(pn); } else { try { cnx.Open(); nh.actualizaConceptoModificado(pn); cnx.Close(); } catch { MessageBox.Show("Error al obtener la existencia del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } } } else { Movimientos.Core.Movimientos mov = new Movimientos.Core.Movimientos(); mov.idtrabajador = idEmpleado; mov.idempresa = GLOBALES.IDEMPRESA; mov.idconcepto = lstConcepto[0].id; mov.cantidad = decimal.Parse(fila.Cells["cantidad"].Value.ToString()); mov.fechainicio = DateTime.Parse(fila.Cells["inicio"].Value.ToString()); mov.fechafin = DateTime.Parse(fila.Cells["fin"].Value.ToString()); try { cnx.Open(); existeConcepto = (int)mh.existeMovimientoConcepto(mov); cnx.Close(); } catch { MessageBox.Show("Error al obtener la existencia del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } if (existeConcepto == 0) { lstOtrasDeducciones.Add(mov); } else { try { cnx.Open(); mh.actualizaMovimiento(mov); cnx.Close(); } catch { MessageBox.Show("Error al obtener la existencia del concepto.\r\n \r\n Esta ventana se cerrará.", "Error"); cnx.Dispose(); workMovimientos.CancelAsync(); this.Dispose(); } } } break; #endregion } } if (lstMovimientos.Count != 0) { bulk = new SqlBulkCopy(cnx); nh.bulkCommand = bulk; DataTable dt = new DataTable(); DataRow dtFila; dt.Columns.Add("id", typeof(Int32)); dt.Columns.Add("idtrabajador", typeof(Int32)); dt.Columns.Add("idempresa", typeof(Int32)); dt.Columns.Add("idconcepto", typeof(Int32)); dt.Columns.Add("noconcepto", typeof(Int32)); dt.Columns.Add("tipoconcepto", typeof(String)); dt.Columns.Add("exento", typeof(Decimal)); dt.Columns.Add("gravado", typeof(Decimal)); dt.Columns.Add("cantidad", typeof(Decimal)); dt.Columns.Add("fechainicio", typeof(DateTime)); dt.Columns.Add("fechafin", typeof(DateTime)); dt.Columns.Add("noperiodo", typeof(Int32)); dt.Columns.Add("diaslaborados", typeof(Int32)); dt.Columns.Add("guardada", typeof(Boolean)); dt.Columns.Add("tiponomina", typeof(Int32)); dt.Columns.Add("modificado", typeof(Boolean)); dt.Columns.Add("fechapago", typeof(DateTime)); dt.Columns.Add("obracivil", typeof(Boolean)); dt.Columns.Add("periodo", typeof(Int32)); int index = 1; for (int i = 0; i < lstMovimientos.Count; i++) { dtFila = dt.NewRow(); dtFila["id"] = i + 1; dtFila["idtrabajador"] = lstMovimientos[i].idtrabajador; dtFila["idempresa"] = lstMovimientos[i].idempresa; dtFila["idconcepto"] = lstMovimientos[i].idconcepto; dtFila["noconcepto"] = lstMovimientos[i].noconcepto; dtFila["tipoconcepto"] = lstMovimientos[i].tipoconcepto; dtFila["exento"] = lstMovimientos[i].exento; dtFila["gravado"] = lstMovimientos[i].gravado; dtFila["cantidad"] = lstMovimientos[i].cantidad; dtFila["fechainicio"] = lstMovimientos[i].fechainicio; dtFila["fechafin"] = lstMovimientos[i].fechafin; dtFila["noperiodo"] = 0; dtFila["diaslaborados"] = 0; dtFila["guardada"] = lstMovimientos[i].guardada; dtFila["tiponomina"] = lstMovimientos[i].tiponomina; dtFila["modificado"] = lstMovimientos[i].modificado; dtFila["fechapago"] = new DateTime(1900,1,1); dtFila["obracivil"] = false; dtFila["periodo"] = _periodo; dt.Rows.Add(dtFila); index++; } try { cnx.Open(); nh.bulkNomina(dt, "tmpPagoNomina"); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error (DataTable): \r\n \r\n" + error.Message, "Error"); } } if (lstOtrasDeducciones.Count != 0) { bulk = new SqlBulkCopy(cnx); mh.bulkCommand = bulk; DataTable dt = new DataTable(); DataRow dtFila; dt.Columns.Add("id", typeof(Int32)); dt.Columns.Add("idtrabajador", typeof(Int32)); dt.Columns.Add("idempresa", typeof(Int32)); dt.Columns.Add("idconcepto", typeof(Int32)); dt.Columns.Add("cantidad", typeof(Decimal)); dt.Columns.Add("fechainicio", typeof(DateTime)); dt.Columns.Add("fechafin", typeof(DateTime)); int index = 1; for (int i = 0; i < lstOtrasDeducciones.Count; i++) { dtFila = dt.NewRow(); dtFila["id"] = i + 1; dtFila["idtrabajador"] = lstOtrasDeducciones[i].idtrabajador; dtFila["idempresa"] = lstOtrasDeducciones[i].idempresa; dtFila["idconcepto"] = lstOtrasDeducciones[i].idconcepto; dtFila["cantidad"] = lstOtrasDeducciones[i].cantidad; dtFila["fechainicio"] = lstOtrasDeducciones[i].fechainicio; dtFila["fechafin"] = lstOtrasDeducciones[i].fechafin; dt.Rows.Add(dtFila); index++; } try { cnx.Open(); mh.bulkMovimientos(dt, "tmpMovimientos"); mh.stpMovimientos(); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error (DataTable): \r\n \r\n" + error.Message, "Error"); } } }