예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        private void frmListaHistorial_Load(object sender, EventArgs e)
        {
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            eh = new Empleados.Core.EmpleadosHelper();
            hh = new Historial.Core.HistorialHelper();
            dh = new Departamento.Core.DeptoHelper();
            ph = new Puestos.Core.PuestosHelper();

            eh.Command = cmd;
            hh.Command = cmd;
            dh.Command = cmd;
            ph.Command = cmd;

            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idtrabajador = _idempleado;
            Historial.Core.Historial historial = new Historial.Core.Historial();
            historial.idtrabajador = _idempleado;
            Departamento.Core.Depto depto = new Departamento.Core.Depto();
            depto.idempresa = GLOBALES.IDEMPRESA;
            Puestos.Core.Puestos puesto = new Puestos.Core.Puestos();
            puesto.idempresa = GLOBALES.IDEMPRESA;

            try
            {
                cnx.Open();
                lstEmpleados = eh.obtenerEmpleado(empleado);
                lstHistorial = hh.obtenerHistoriales(historial);
                lstDepto = dh.obtenerDepartamentos(depto);
                lstPuesto = ph.obtenerPuestos(puesto);
                cnx.Close();
                cnx.Dispose();

                var lista = from emp in lstEmpleados join his in lstHistorial on emp.idtrabajador equals his.idtrabajador
                            join d in lstDepto on his.iddepartamento equals d.id
                            join p in lstPuesto on his.idpuesto equals p.idpuesto orderby his.fecha_imss ascending
                         select new
                         {
                             IdTrabajador = emp.idtrabajador,
                             NoEmpleado = emp.noempleado,
                             Nombre = emp.nombrecompleto,
                             Movimiento =
                                his.tipomovimiento == GLOBALES.mALTA ? "ALTA" :
                                his.tipomovimiento == GLOBALES.mMODIFICACIONSALARIO ? "MODIFICACION" :
                                his.tipomovimiento == GLOBALES.mREINGRESO ? "REINGRESO" :
                                his.tipomovimiento == GLOBALES.mBAJA ? "BAJA" :
                                his.tipomovimiento == GLOBALES.mCAMBIODEPARTAMENTO ? "CAMBIO DE DEPARTAMENTO" : "CAMBIO DE PUESTO",
                             SDI = his.valor,
                             FechaAplicacion = his.fecha_imss,
                             FechaSistema = his.fecha_sistema,
                             Depto = d.descripcion,
                             Puesto = p.nombre
                         };
                dgvHistorial.DataSource = lista.ToList();

                for (int i = 0; i < dgvHistorial.Columns.Count; i++)
                {
                    dgvHistorial.AutoResizeColumn(i);
                }
                dgvHistorial.Columns["IdTrabajador"].Visible = false;
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }
        }
        private void toolAplicar_Click(object sender, EventArgs e)
        {
            int i = 1;

            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            SqlBulkCopy bulk = new SqlBulkCopy(cnx);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            Historial.Core.HistorialHelper hh = new Historial.Core.HistorialHelper();
            hh.bulkCommand = bulk;
            hh.Command = cmd;

            DataTable dt = new DataTable();
            DataRow dtFila;
            dt.Columns.Add("id", typeof(Int32));
            dt.Columns.Add("idtrabajador", typeof(Int32));
            dt.Columns.Add("tipomovimiento", typeof(Int32));
            dt.Columns.Add("valor", typeof(Double));
            dt.Columns.Add("fecha_imss", typeof(DateTime));
            dt.Columns.Add("fecha_sistema", typeof(DateTime));
            dt.Columns.Add("idempresa", typeof(Int32));
            dt.Columns.Add("motivobaja", typeof(Int32));

            DataTable dtAntiguedad = new DataTable();
            DataRow dtFilaAntiguedad;
            dtAntiguedad.Columns.Add("id", typeof(Int32));
            dtAntiguedad.Columns.Add("idtrabajador", typeof(Int32));
            dtAntiguedad.Columns.Add("sdi", typeof(Double));
            dtAntiguedad.Columns.Add("antiguedad", typeof(Int32));
            dtAntiguedad.Columns.Add("antiguedadmod", typeof(Int32));

            foreach (DataGridViewRow fila in dgvEmpleados.Rows)
            {
                if ((int)fila.Cells["seleccion"].Value == 1)
                {
                    dtFila = dt.NewRow();
                    dtFila["id"] = i;
                    dtFila["idtrabajador"] = int.Parse(fila.Cells["idtrabajador"].Value.ToString());
                    dtFila["tipomovimiento"] = GLOBALES.mMODIFICACIONSALARIO;
                    dtFila["valor"] = double.Parse(fila.Cells["sdinuevo"].Value.ToString());
                    dtFila["fecha_imss"] = DateTime.Parse(fila.Cells["fechaimss"].Value.ToString());
                    dtFila["fecha_sistema"] = DateTime.Now;
                    dtFila["idempresa"] = GLOBALES.IDEMPRESA;
                    dtFila["motivobaja"] = 0;
                    dt.Rows.Add(dtFila);

                    dtFilaAntiguedad = dtAntiguedad.NewRow();
                    dtFilaAntiguedad["id"] = i;
                    dtFilaAntiguedad["idtrabajador"] = int.Parse(fila.Cells["idtrabajador"].Value.ToString());
                    dtFilaAntiguedad["sdi"] = double.Parse(fila.Cells["sdinuevo"].Value.ToString());
                    dtFilaAntiguedad["antiguedad"] = int.Parse(fila.Cells["antiguedad"].Value.ToString());
                    dtFilaAntiguedad["antiguedadmod"] = int.Parse(fila.Cells["antiguedadmod"].Value.ToString());
                    dtAntiguedad.Rows.Add(dtFilaAntiguedad);
                    i++;
                }
            }

            try
            {
                cnx.Open();
                hh.bulkMovimientos(dt, "tmpMovimientoTrabajador");
                hh.bulkMovimientos(dtAntiguedad, "tmpSalarioAntiguedad");
                hh.stpAntiguedadHistorial();
                cnx.Close();
                cnx.Dispose();

                MessageBox.Show("Incremento aplicado.", "Confirmación");
                ListaEmpleados();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
            }
        }
        private void toolGuardar_Click(object sender, EventArgs e)
        {
            cnx = new SqlConnection();
            cnx.ConnectionString = cdn;
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            eh = new Empleados.Core.EmpleadosHelper();
            hh = new Historial.Core.HistorialHelper();
            mh = new Modificaciones.Core.ModificacionesHelper();
            eh.Command = cmd;
            hh.Command = cmd;
            mh.Command = cmd;

            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idtrabajador = _idempleado;
            empleado.sdi = decimal.Parse(txtSDI.Text);
            empleado.sd = decimal.Parse(txtSD.Text);
            empleado.sueldo = decimal.Parse(txtSueldo.Text);

            Historial.Core.Historial historia = new Historial.Core.Historial();
            historia.idtrabajador = _idempleado;
            historia.idempresa = GLOBALES.IDEMPRESA;
            historia.tipomovimiento = GLOBALES.mMODIFICACIONSALARIO;
            historia.valor = decimal.Parse(txtSDI.Text);
            historia.fecha_imss = dtpFecha.Value;
            historia.fecha_sistema = DateTime.Now;
            historia.motivobaja = 0;

            if (departamento)
                historia.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
            else
                historia.iddepartamento = iddepto;

            if (puesto)
                historia.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
            else
                historia.idpuesto = idpuesto;

            Modificaciones.Core.Modificaciones mod = new Modificaciones.Core.Modificaciones();
            mod.idtrabajador = _idempleado;
            mod.idempresa = GLOBALES.IDEMPRESA;
            mod.registropatronal = rp;
            mod.nss = nss;
            mod.fecha = dtpFecha.Value;
            mod.sdi = decimal.Parse(txtSDI.Text);

            aplih = new Aplicaciones.Core.AplicacionesHelper();
            aplih.Command = cmd;
            Aplicaciones.Core.Aplicaciones aDepto = new Aplicaciones.Core.Aplicaciones();
            Aplicaciones.Core.Aplicaciones aPuesto = new Aplicaciones.Core.Aplicaciones();

            try {
                cnx.Open();
                eh.actualizaSueldo(empleado);
                hh.insertarHistorial(historia);
                mh.insertaModificacion(mod);

                if (departamento)
                {
                    Historial.Core.Historial historiaDepto = new Historial.Core.Historial();
                    historiaDepto.idtrabajador = _idempleado;
                    historiaDepto.idempresa = GLOBALES.IDEMPRESA;
                    historiaDepto.tipomovimiento = GLOBALES.mCAMBIODEPARTAMENTO;
                    historiaDepto.valor = decimal.Parse(txtSDI.Text);
                    historiaDepto.fecha_imss = dtpFecha.Value;
                    historiaDepto.fecha_sistema = DateTime.Now;
                    historiaDepto.motivobaja = 0;
                    historiaDepto.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    historiaDepto.idpuesto = idpuesto;
                    hh.insertarHistorial(historiaDepto);

                    aDepto = new Aplicaciones.Core.Aplicaciones();
                    aDepto.idtrabajador = _idempleado;
                    aDepto.idempresa = GLOBALES.IDEMPRESA;
                    aDepto.iddeptopuesto = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    aDepto.deptopuesto = "D";
                    aDepto.fecha = dtpFecha.Value.Date;
                    aDepto.registro = DateTime.Now.Date;
                    aDepto.idusuario = GLOBALES.IDUSUARIO;
                    aDepto.periodoinicio = inicioPeriodo;
                    aDepto.periodofin = finPeriodo;
                    aplih.insertaAplicacion(aDepto);
                }

                if (puesto)
                {
                    Historial.Core.Historial historiaPuesto = new Historial.Core.Historial();
                    historiaPuesto.idtrabajador = _idempleado;
                    historiaPuesto.idempresa = GLOBALES.IDEMPRESA;
                    historiaPuesto.tipomovimiento = GLOBALES.mCAMBIOPUESTO;
                    historiaPuesto.valor = decimal.Parse(txtSDI.Text);
                    historiaPuesto.fecha_imss = dtpFecha.Value;
                    historiaPuesto.fecha_sistema = DateTime.Now;
                    historiaPuesto.motivobaja = 0;
                    historiaPuesto.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    historiaPuesto.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
                    hh.insertarHistorial(historiaPuesto);

                    aPuesto = new Aplicaciones.Core.Aplicaciones();
                    aPuesto.idtrabajador = _idempleado;
                    aPuesto.idempresa = GLOBALES.IDEMPRESA;
                    aPuesto.iddeptopuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
                    aPuesto.deptopuesto = "P";
                    aPuesto.fecha = dtpFecha.Value.Date;
                    aPuesto.registro = DateTime.Now.Date;
                    aPuesto.idusuario = GLOBALES.IDUSUARIO;
                    aPuesto.periodoinicio = inicioPeriodo;
                    aPuesto.periodofin = finPeriodo;
                    aplih.insertaAplicacion(aPuesto);
                }

                cnx.Close();
                cnx.Dispose();

                MessageBox.Show("Incremento aplicado.", "Confirmación");

                if (OnIncrementoSalarial != null)
                    OnIncrementoSalarial();
            }
            catch (Exception error) {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }
            this.Dispose();
        }
예제 #6
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            int existeVacaciones = 0, existeIncapacidad = 0;
            int diasProporcionales = 0;
            int existeBaja = 0;
            DialogResult respuesta = MessageBox.Show("¿Desea dar de baja al empleado?","Confirmación",MessageBoxButtons.YesNo);
            if (respuesta == DialogResult.Yes)
            {
                //if (ausentismo)
                //{
                //    frmDiasAusentismo da = new frmDiasAusentismo();
                //    da.OnDiasAusentismo += da_OnDiasAusentismo;
                //    da.ShowDialog();
                //}

                //if (diasAusentismo == 0 && ausentismo)
                //{
                //    MessageBox.Show("El número de dias es 0 o se presionó el boton cancelar. Por favor revisar.", "Error");
                //    return;
                //}

                cnx = new SqlConnection(cdn);
                cmd = new SqlCommand();
                cmd.Connection = cnx;

                PeriodoFechaAplicacion();

                #region EXISTENCIA DE INCAPACIDAD
                Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
                ih.Command = cmd;

                Incidencias.Core.Incidencias incidencia = new Incidencias.Core.Incidencias();
                incidencia.idtrabajador = _idempleado;
                incidencia.fechainicio = periodoInicio.Date;
                incidencia.fechafin = periodoFin.Date;

                try
                {
                    cnx.Open();
                    existeIncapacidad = (int)ih.existeIncidenciaBaja(incidencia);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Al obtener existencia de Incapacidad.","Error");
                    cnx.Dispose();
                    return;
                }
                #endregion

                #region EXISTENCIA DE VACACIONES
                Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
                vh.Command = cmd;

                Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima();
                vp.idtrabajador = _idempleado;
                vp.periodoinicio = periodoInicio;
                vp.periodofin = periodoFin;
                vp.vacacionesprima = "V";

                try
                {
                    cnx.Open();
                    existeVacaciones = (int)vh.existeVacacionesPrima(vp);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Al obtener existencia de Vacaciones.", "Error");
                    cnx.Dispose();
                    return;
                }
                #endregion

                #region VALIDACION DE INCAPACIDAD
                if (existeIncapacidad != 0)
                {
                    DateTime fechaInicioIncidencia;
                    DateTime fechaFinIncidencia;
                    try
                    {
                        cnx.Open();
                        fechaInicioIncidencia = DateTime.Parse(ih.fechaInicio(incidencia).ToString());
                        fechaFinIncidencia = DateTime.Parse(ih.fechaFin(incidencia).ToString());
                        cnx.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error: Al obtener las fechas de incapacidad.", "Error");
                        cnx.Dispose();
                        return;
                    }

                    if (dtpFechaBaja.Value.Date >= fechaInicioIncidencia.Date && dtpFechaBaja.Value.Date <= fechaFinIncidencia.Date)
                    {
                        MessageBox.Show("No se puede dar de baja. La fecha de baja esta entre una incapacidad.", "Error");
                        return;
                    }
                    if (dtpFechaBaja.Value.Date <= fechaInicioIncidencia.Date)
                    {
                        MessageBox.Show("No se puede dar de baja. Existe una incapacidad.", "Error");
                        return;
                    }
                }
                #endregion

                #region VALIDACION DE VACACIONES
                if (existeVacaciones != 0)
                {
                    DateTime fechaInicioVac;
                    DateTime fechaFinVac;

                    try
                    {
                        cnx.Open();
                        fechaInicioVac = DateTime.Parse(vh.fechaInicio(vp).ToString());
                        fechaFinVac = DateTime.Parse(vh.fechaFin(vp).ToString());
                        cnx.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error: Al obtener las fechas de las vacaciones.", "Error");
                        cnx.Dispose();
                        return;
                    }

                    if (dtpFechaBaja.Value.Date >= fechaInicioVac.Date && dtpFechaBaja.Value.Date <= fechaFinVac.Date)
                    {
                        MessageBox.Show("No se puede dar de baja. La fecha de baja coninciden con vacaciones.", "Error");
                        return;
                    }
                    if (dtpFechaBaja.Value.Date <= fechaInicioVac.Date)
                    {
                        MessageBox.Show("No se puede dar de baja. El trabajador tiene vacaciones.", "Error");
                        return;
                    }
                }
                #endregion

                Empresas.Core.EmpresasHelper ep = new Empresas.Core.EmpresasHelper();
                ep.Command = cmd;

                Empresas.Core.Empresas empresa = new Empresas.Core.Empresas();
                empresa.idempresa = GLOBALES.IDEMPRESA;

                Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper();
                eh.Command = cmd;

                Empleados.Core.Empleados emp = new Empleados.Core.Empleados();
                emp.idtrabajador = _idempleado;

                Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus();
                ee.idtrabajador = _idempleado;
                ee.idempresa = GLOBALES.IDEMPRESA;
                ee.estatus = GLOBALES.INACTIVO;

                Historial.Core.HistorialHelper hp = new Historial.Core.HistorialHelper();
                hp.Command = cmd;

                Historial.Core.Historial h = new Historial.Core.Historial();
                h.idtrabajador = _idempleado;
                h.tipomovimiento = GLOBALES.mBAJA;
                h.fecha_imss = dtpFechaBaja.Value;
                h.fecha_sistema = DateTime.Now;
                h.idempresa = GLOBALES.IDEMPRESA;
                h.motivobaja = int.Parse(cmbMotivoBaja.SelectedValue.ToString());
                h.iddepartamento = 0;
                h.idpuesto = 0;

                //Ausentismo.Core.AusentismoHelper ah = new Ausentismo.Core.AusentismoHelper();
                //ah.Command = cmd;

                //Ausentismo.Core.Ausentismo a = new Ausentismo.Core.Ausentismo();
                //a.idtrabajador = _idempleado;
                //a.idempresa = GLOBALES.IDEMPRESA;
                //a.fecha_imss = dtpFechaBaja.Value;
                //a.dias = diasAusentismo;

                Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper();
                bh.Command = cmd;

                Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
                baja.idtrabajador = _idempleado;
                baja.idempresa = GLOBALES.IDEMPRESA;
                baja.motivo = int.Parse(cmbMotivoBaja.SelectedValue.ToString());
                baja.fecha = dtpFechaBaja.Value.Date;
                //baja.diasproporcionales = (int)(dtpFechaBaja.Value.Date - periodoInicio.Date).TotalDays + 1;
                baja.periodoinicio = periodoInicio.Date;
                baja.periodofin = periodoFin.Date;
                baja.observaciones = txtObservaciones.Text;
                baja.registro = DateTime.Now;

                diasProporcionales = (int)(dtpFechaBaja.Value.Date - periodoInicio.Date).TotalDays + 1;
                if (diasProporcionales == 16)
                    baja.diasproporcionales = diasProporcionales - 1;
                else
                    baja.diasproporcionales = (int)(dtpFechaBaja.Value.Date - periodoInicio.Date).TotalDays + 1;

                try
                {
                    cnx.Open();
                    existeBaja = (int)bh.existeBaja(baja);
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al verificar la existencia de la baja.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (existeBaja != 0)
                {
                    MessageBox.Show(
                        string.Format("El trabajador ya cuenta con una baja en el periodo del: \r\n \r\n {0} al {1}",
                        periodoInicio.Date.ToShortDateString(), periodoFin.Date.ToShortDateString()),
                        "Información");
                    return;
                }

                bool obraCivil = false;
                try
                {
                    cnx.Open();
                    obraCivil = bool.Parse(eh.esObraCivil(GLOBALES.IDEMPRESA, _idempleado).ToString());
                    cnx.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: Al obtener dato de obra civil. \r\n \r\n" + error.Message, "Error");
                    return;
                }

                if (obraCivil)
                {
                    nh = new CalculoNomina.Core.NominaHelper();
                    nh.Command = cmd;
                    List<CalculoNomina.Core.tmpPagoNomina> lstPreNominaGuardada = new List<CalculoNomina.Core.tmpPagoNomina>();
                    List<CalculoNomina.Core.tmpPagoNomina> lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>();
                    try
                    {
                        cnx.Open();
                        lstUltimaNomina = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, _idempleado, periodo);
                        lstPreNominaGuardada = nh.fechaPreNominaObraCivil(GLOBALES.IDEMPRESA, _idempleado, periodoInicio, periodoFin);
                        cnx.Close();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: Al obtener las fechas de pago. \r\n \r\n" + error.Message, "Error");
                        return;
                    }

                    if (lstUltimaNomina.Count != 0)
                    {
                        if (dtpFechaBaja.Value.Date >= lstUltimaNomina[0].fechainicio || dtpFechaBaja.Value.Date <= lstUltimaNomina[0].fechafin)
                        {
                            MessageBox.Show("La baja corresponde a un periodo cerrado.", "Información");
                            return;
                        }
                    }

                    if (lstPreNominaGuardada.Count != 0)
                    {
                        if (dtpFechaBaja.Value.Date <= lstPreNominaGuardada[0].fechafin)
                        {
                            try
                            {
                                Bajas.Core.Bajas bajaTrabajador = new Bajas.Core.Bajas();
                                bajaTrabajador.idtrabajador = _idempleado;
                                cnx.Open();
                                bh.bajaEmpleado(bajaTrabajador);
                                nh.eliminaPreNomina(_idempleado, periodo);
                                cnx.Close();
                            }
                            catch (Exception error)
                            {
                                MessageBox.Show("Error: Al dar baja del empleado. \r\n \r\n" + error.Message, "Error");
                                return;
                            }
                        }
                    }
                }
                else {
                    nh = new CalculoNomina.Core.NominaHelper();
                    nh.Command = cmd;
                    List<CalculoNomina.Core.tmpPagoNomina> lstNomina = new List<CalculoNomina.Core.tmpPagoNomina>();
                    try
                    {
                        cnx.Open();
                        lstNomina = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, _idempleado, periodo);
                        cnx.Close();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: Al obtener las fechas de pago. \r\n \r\n" + error.Message, "Error");
                        return;
                    }

                    if (lstNomina.Count != 0)
                    {
                        if (dtpFechaBaja.Value.Date <= lstNomina[0].fechainicio || dtpFechaBaja.Value.Date <= lstNomina[0].fechafin)
                        {
                            try
                            {
                                Bajas.Core.Bajas bajaTrabajador = new Bajas.Core.Bajas();
                                bajaTrabajador.idtrabajador = _idempleado;
                                cnx.Open();
                                bh.bajaEmpleado(bajaTrabajador);
                                nh.eliminaPreNomina(_idempleado, periodo);
                                cnx.Close();
                                baja.fecha = lstNomina[0].fechafin;
                                baja.diasproporcionales = 1;
                                MessageBox.Show("La baja corresponde a un periodo cerrado. \r\n\r\n Se dará con la fecha de termino del periodo cerrado: " +
                                    lstNomina[0].fechafin.ToShortDateString(), "Información");
                            }
                            catch (Exception error)
                            {
                                MessageBox.Show("Error: Al dar baja del empleado. \r\n \r\n" + error.Message, "Error");
                                return;
                            }
                        }
                    }
                }

                try
                {
                    cnx.Open();
                    h.valor = (decimal)eh.obtenerSalarioDiarioIntegrado(emp);
                    hp.insertarHistorial(h);
                    //ACTUALIZA TABLA trabajadoresestatus
                    eh.bajaEmpleado(ee);

                    baja.registropatronal = (string)ep.obtenerRegistroPatronal(empresa);
                    baja.nss = (string)eh.obtenerNss(emp);
                    bh.insertaBaja(baja);

                    //if (ausentismo)
                    //{
                    //    a.registropatronal = (string)ep.obtenerRegistroPatronal(empresa);
                    //    a.nss = (string)eh.obtenerNss(emp);
                    //    ah.insertaAusentismo(a);
                    //}

                    cnx.Close();
                    cnx.Dispose();

                    if(OnBajaEmpleado !=  null)
                        OnBajaEmpleado(GLOBALES.ACTIVO);
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                }

                MessageBox.Show("Baja exitosa.", "Información");
                btnAceptar.Enabled = false;
                this.Dispose();
            }
        }
예제 #7
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            obtenerPeriodoCalculo();

            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            Aplicaciones.Core.AplicacionesHelper ah = new Aplicaciones.Core.AplicacionesHelper();
            ah.Command = cmd;

            Aplicaciones.Core.Aplicaciones a = new Aplicaciones.Core.Aplicaciones();

            a.idtrabajador = _idempleado;
            a.idempresa = GLOBALES.IDEMPRESA;
            a.iddeptopuesto = int.Parse(cmbDeptoPuesto.SelectedValue.ToString());
            a.fecha = dtpFechaAplicacion.Value.Date;
            a.registro = DateTime.Now;
            a.idusuario = GLOBALES.IDUSUARIO;
            a.periodoinicio = inicioPeriodo;
            a.periodofin = finPeriodo;

            Historial.Core.HistorialHelper hh = new Historial.Core.HistorialHelper();
            hh.Command = cmd;

            Historial.Core.Historial historial = new Historial.Core.Historial();

            historial = new Historial.Core.Historial();
            historial.idtrabajador = _idempleado;
            historial.idempresa = GLOBALES.IDEMPRESA;
            historial.valor = sdi;
            historial.fecha_sistema = DateTime.Now;
            historial.motivobaja = 0;
            historial.fecha_imss = dtpFechaAplicacion.Value.Date;

            if (_deptopuesto == 0)
            {
                a.deptopuesto = "D";
                historial.tipomovimiento = GLOBALES.mCAMBIODEPARTAMENTO;
                historial.iddepartamento = int.Parse(cmbDeptoPuesto.SelectedValue.ToString());
                historial.idpuesto = idpuesto;
            }
            else
            {
                a.deptopuesto = "P";
                historial.tipomovimiento = GLOBALES.mCAMBIOPUESTO;
                historial.idpuesto = int.Parse(cmbDeptoPuesto.SelectedValue.ToString());
                historial.iddepartamento = iddepto;
            }

            try
            {
                cnx.Open();
                hh.insertarHistorial(historial);
                cnx.Close();

            }
            catch (Exception)
            {
                MessageBox.Show("Error: Al insertar el historico.", "Error");
                cnx.Dispose();
            }

            if (inicioPeriodo.Date == periodoInicioCalculo.Date && finPeriodo.Date == periodoFinCalculo.Date)
            {
                Empleados.Core.EmpleadosHelper eh = new Empleados.Core.EmpleadosHelper();
                eh.Command = cmd;
                try
                {
                    cnx.Open();
                    if (_deptopuesto == 0)
                        eh.actualizaDeptoPuesto(int.Parse(cmbDeptoPuesto.SelectedValue.ToString()), _idempleado, "D");
                    else
                        eh.actualizaDeptoPuesto(int.Parse(cmbDeptoPuesto.SelectedValue.ToString()), _idempleado, "P");
                    cnx.Close();
                    cnx.Dispose();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al actualizar el depto/puesto.", "Error");
                    cnx.Dispose();
                }
            }
            else
            {
                try
                {
                    cnx.Open();
                    ah.insertaAplicacion(a);
                    cnx.Close();
                    cnx.Dispose();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al ingresar la aplicacion del depto/puesto.", "Error");
                    cnx.Dispose();
                }
            }

            this.Dispose();
        }