Ejemplo n.º 1
0
        void loadGrid()
        {
            dgvEgresos.Rows.Clear();
            totalEgreso  = 0;
            totalIngreso = 0;
            var list = TransaccionController.listar(-1).Where(x => x.FechaTransaccion.Equals(dtFechaFiltro.Value.Date)).ToList();

            if (list == null)
            {
                throw new Exception("No se pudo cargar");
            }
            for (int i = 0; i < list.Count; i++)
            {
                decimal ingreso = list[i].Egreso.Where(x => x.TipoTransaccion == 1 && x.Activo).Sum(y => y.Cantidad);
                decimal egreso  = list[i].Egreso.Where(x => x.TipoTransaccion == 0 && x.Activo).Sum(y => y.Cantidad);
                string  cajero  = UsuariosController.leer(list[i].Id_usuario).Personas.ToString();
                dgvEgresos.Rows.Add(list[i].IdTransaccion, cajero, list[i].Vehiculo.Placa, list[i].FechaTransaccion.ToShortDateString(), ingreso, egreso);
                if (!list[i].Activo)
                {
                    dgvEgresos.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
                }
                else
                {
                    dgvEgresos.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
                }
                totalIngreso += ingreso;
                totalEgreso  += egreso;
            }
            setTotales();
        }
Ejemplo n.º 2
0
 private void btnAnular_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtFac.Text) && !String.IsNullOrWhiteSpace(txtFac.Text))
     {
         try
         {
             int num  = Convert.ToInt32(txtFac.Text.Trim());
             var item = TransaccionController.leer(num);
             if (item != null)
             {
                 var form = new DetalleTransaccion(item);
                 form.ShowDialog();
             }
             else
             {
                 MessageBox.Show("EL NUMERO DE FACTURA INGRESADO NO EXISTE", "NO EXISTE TRANSACCION", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             ActualizarNoFactura();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         MessageBox.Show("INGRESE EL NUMERO DE LA FACTURA A BUSCAR", "NUMERO DE FACTURA", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
0
        private void btnCancelar_Click(object sender, EventArgs e)
        {
            DialogResult result;
            var          admin = new Administracion("Confirme la eliminacion del registro numero: " + codigo.IdTransaccion);

            admin.ShowDialog();
            result = admin.resultado;
            if (DialogResult.Yes.Equals(result))
            {
                try
                {
                    var an = TransaccionController.anular(codigo.IdTransaccion);
                    if (an < 0)
                    {
                        throw new Exception("No se pudo eliminar la transaccion");
                    }
                    else
                    {
                        MessageBox.Show("Factura #" + codigo.IdTransaccion + "  ha sido anulada correctamente",
                                        "Factura Anulada", MessageBoxButtons.OK, MessageBoxIcon.Information
                                        );
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show(
                    @"Confirme la insercion del abono", "Agregar el abono?",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result.Equals(DialogResult.Yes))
                {
                    decimal monto = int.Parse(txtMonto.Text);
                    //Obteniendo el codigo de el detalle a abonar
                    int id = (int)dgvCreditos.SelectedRows[0].Cells["Detalle"].Value;
                    //Obteniendo el codigo del vehiculo
                    int id_vehiculo = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                    //Registramos la transaccion
                    int i = TransaccionController.agregar(MainContainer.sesion.Id_usuario, id_vehiculo, DateTime.Now.Date, true);
                    if (i > 0)
                    {
                        //si se guardo el encabezado de la factura
                        int j = _AbonoController.Agregar(TransaccionController.getUltima().IdTransaccion, id, monto);
                        if (j > 0)
                        {
                            MessageBox.Show("Abono Agregado Correctamente!", "Cambios Guardados");
                            //Mostramos factura
                            var tra   = TransaccionController.getUltima();
                            var abono = _AbonoController.getAllAbono().OrderByDescending(x => x.Id_transaccion).FirstOrDefault();

                            var form = new Factura_Abono(
                                tra.Vehiculo.Placa, tra.IdTransaccion, tra.FechaTransaccion,
                                MainContainer.sesion.Nickname, abono.Detalle.IdTransaccion,
                                abono.Detalle.Transaccion.FechaTransaccion, abono.Detalle.TipoEgreso.ToString(),
                                abono.Detalle.Cantidad, abono.Monto, (abono.Detalle.Saldo_detalle.Saldo)
                                );
                            form.ShowDialog();
                            //Recargamos los datos
                            AgregarAbono_Load(sender, e);
                        }
                        else
                        {
                            throw new Exception("No se ha logrado la insercion del Abono!!!");
                        }
                    }
                    else
                    {
                        throw new NullReferenceException("No se ha registrado la transaccion", new Exception("El codigo de la transaccion no se genero correctamente!"));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error durante la insercion de la factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
 private void vToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int codigo = (int)dgvEgresos.SelectedRows[0].Cells[0].Value;
         var form   = new DetalleTransaccion(TransaccionController.leer(codigo));
         form.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 6
0
        private void btnFiltrar_Click(object sender, EventArgs e)
        {
            try
            {
                totalEgreso  = 0;
                totalIngreso = 0;
                if (String.IsNullOrWhiteSpace(txtDescripcion.Text) || String.IsNullOrEmpty(txtDescripcion.Text))
                {
                    loadGrid();
                }
                else
                {
                    dgvEgresos.Rows.Clear();
                    var codigoVehiculo = VehiculosController.leer(txtDescripcion.Text);
                    if (codigoVehiculo == null)
                    {
                        throw new Exception("No existe un vehiculo con esa placa");
                    }

                    var list = TransaccionController.listar(codigoVehiculo.Id_Vehiculo).Where(x => x.FechaTransaccion.Equals(dtFechaFiltro.Value.Date)).ToList();

                    if (codigoVehiculo.Transaccion.Count == 0)
                    {
                        throw new Exception("No hay transacciones para ese vehiculo");
                    }
                    for (int i = 0; i < list.Count; i++)
                    {
                        decimal ingreso = list[i].Egreso.Where(y => y.TipoTransaccion == 1 && y.Activo).Sum(x => x.Cantidad);
                        decimal egreso  = list[i].Egreso.Where(y => y.TipoTransaccion == 0 && y.Activo).Sum(x => x.Cantidad);
                        string  cajero  = UsuariosController.leer(list[i].Id_usuario).Personas.ToString();
                        dgvEgresos.Rows.Add(list[i].IdTransaccion, cajero, list[i].Vehiculo.Placa, list[i].FechaTransaccion.ToShortDateString(), ingreso, egreso);
                        if (!list[i].Activo)
                        {
                            dgvEgresos.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
                        }
                        else
                        {
                            dgvEgresos.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
                        }
                        totalIngreso += ingreso;
                        totalEgreso  += egreso;
                    }
                    setTotales();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 7
0
 void ActualizarNoFactura()
 {
     try
     {
         var ultima = TransaccionController.getUltima();
         if (ultima != null)
         {
             lblFactura.Text = String.Format("{0}", ultima.IdTransaccion + 1);
         }
         else
         {
             lblFactura.Text = "1";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error al obtener el numero de facturacion actual", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 8
0
 void ActualizarNoFactura()
 {
     try
     {
         var ultima = TransaccionController.getUltima();
         if (ultima != null)
         {
             lblNoFactura.Text = String.Format("{0}", ultima.IdTransaccion + 1);
         }
         else
         {
             lblNoFactura.Text = "1";
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
 private void imprimirFacturaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int     codigo   = (int)dgvEgresos.SelectedRows[0].Cells[0].Value;
         var     transacc = TransaccionController.leer(codigo);
         var     det      = DetalleController.listar(codigo);
         string  cajero   = UsuariosController.leer(transacc.Id_usuario).ToString();
         decimal ingreso  = det.Where(x => x.TipoTransaccion == 1).Sum(y => y.Cantidad);
         decimal egreso   = det.Where(x => x.TipoTransaccion == 0).Sum(y => y.Cantidad);
         decimal total    = ingreso - egreso;
         Form    ticket   = new Reportes.ImprimirFactura(codigo, cajero, transacc.Vehiculo.Placa, dtFechaFiltro.Value);
         ticket.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 10
0
 private void dgDatos_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         int valor = (int)dgDatos.SelectedRows[0].Cells[0].Value;
         var item  = TransaccionController.leer(valor);
         if (item != null)
         {
             Transacciones.DetalleTransaccion form = new Transacciones.DetalleTransaccion(item);
             form.ShowDialog();
         }
         else
         {
             throw new Exception("Factura no encontrada");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 11
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (CombosValidos())
            {
                var confirmacion = MessageBox.Show("Guardar Factura?", "Los Cambios no se pueden deshacer!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (confirmacion.Equals(DialogResult.Yes))
                {
                    try
                    {
                        //Obtiendo el encabezado de la transaccion
                        int      id_cajero   = MainContainer.sesion.Personas.Id_persona;
                        int      id_vehiculo = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                        DateTime Fecha       = dtFecha.Value.Date;
                        //Insertando la transaccion
                        int i = TransaccionController.agregar(id_cajero, id_vehiculo, Fecha, true);
                        //Si la transaccion tuvo exito
                        if (i > 0)
                        {
                            int t = 0;
                            //Obtiendo el utimo id de la transaccion
                            int     idTransaccion = TransaccionController.getUltima().IdTransaccion;
                            decimal ing           = 0;
                            decimal eg            = 0;
                            for (int j = 0; j < dgvEgresos.Rows.Count; j++)
                            {
                                int    TipoDetalle   = (int)dgvEgresos.Rows[j].Cells[0].Value;
                                string Descripcion   = (string)dgvEgresos.Rows[j].Cells[2].Value;
                                string tipo          = dgvEgresos.Rows[j].Cells[3].Value.ToString();
                                int    tpTransaccion = 0; //Egreso
                                if (tipo.Equals("INGRESO"))
                                {
                                    tpTransaccion = 1;
                                }
                                else if (tipo.Equals("CREDITO"))
                                {
                                    tpTransaccion = 2;
                                }

                                decimal monto = (decimal)dgvEgresos.Rows[j].Cells[4].Value;

                                t = DetalleController.agregar(idTransaccion, TipoDetalle, Descripcion, monto, tpTransaccion, true);
                                float dec = Convert.ToSingle(monto);

                                if (tipo == "INGRESO")
                                {
                                    ing += monto;
                                }

                                else if (tipo.Equals("EGRESO"))
                                {
                                    eg += monto;
                                }
                                totalFactura = 0;
                            }
                            if (t == 0) //Si no se registraron transacciones
                            {
                                throw new Exception("No se registraron las transacciones de Entrada/Salida!");
                            }
                            else
                            {
                                decimal total = ing - eg;
                                MessageBox.Show("Se ha insertado la transacion", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ImprimirTicket(idTransaccion, MainContainer.sesion.ToString(), ((Vehiculo)cboVehiculo.SelectedItem).Placa, total, ing, eg);
                                LimpiarControles();
                            }
                        }
                        else
                        {
                            throw new Exception("No se pudo insertar la transaccion");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Todos los campos son requeridos!", "Faltan campos por completar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 12
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //Validar Selecciones
            bool txts, cbos;

            txts = TextosValidos();
            cbos = CombosValidos();
            //fechas = FechasValidas();
            if (txts && cbos)
            {
                try
                {
                    //Obtencion de la informacion para registrar una carrera
                    int      id_cajero    = MainContainer.sesion.Personas.Id_persona;
                    int      id_conductor = ((Conductor)cboConductor.SelectedItem).Id_conductor;
                    int      id_vehiculo  = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                    DateTime Fecha        = dtFecha.Value.Date;
                    TimeSpan salida       = dtSalida.Value.TimeOfDay;
                    TimeSpan llegada      = dtLlegada.Value.TimeOfDay;
                    bool     vuelta       = cbVueltaCompleta.Checked;
                    //Agregando Transaccion
                    int t = TransaccionController.agregar(id_cajero, id_vehiculo, Fecha, true);
                    //Comprobamos que se haya insertado la transaccion
                    if (t > 0)
                    {
                        //Obtenemos el id de la ultima transaccion
                        int idTransaccion = TransaccionController.getUltima().IdTransaccion;
                        t = CarreraController.Agregar(idTransaccion, id_vehiculo, id_conductor, salida, llegada, Fecha, vuelta);
                        //Si se inserto correctamente la carrera, procedemos a ingresar los gastos
                        if (t > 0)
                        {
                            t = 0;
                            decimal ingreso = Decimal.Parse(QuitarEspacios(txtIngreso.Text));
                            //Registrando Ingreso
                            t = DetalleController.agregar(idTransaccion, TipoDetalleController.leer("CICLO").IdTipoDetalle, "CICLO", ingreso, 0, true);
                            //Verificando y registrando los egresos
                            decimal totalEgreso = 0;
                            if (dgvEgresos.Rows.Count > 0) // Si hay egresos
                            {
                                for (int j = 0; j < dgvEgresos.RowCount; j++)
                                {
                                    int     id_egreso   = (int)dgvEgresos.Rows[j].Cells[0].Value;
                                    string  descripcion = dgvEgresos.Rows[j].Cells[2].Value.ToString();
                                    decimal monto       = (decimal)dgvEgresos.Rows[j].Cells[3].Value;
                                    totalEgreso += monto;
                                    t           += DetalleController.agregar(idTransaccion, id_egreso, descripcion, monto, 1, true);
                                }
                            }
                            if (t == 0) //Si no se registraron transacciones
                            {
                                throw new Exception("No se registraron las transacciones de Entrada/Salida!");
                            }
                            //Se imprime la factura
                            else
                            {
                                var result = MessageBox.Show("Imprimir factura?", "Confirme Impresion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (result.Equals(DialogResult.Yes))
                                {
                                    var ultima = CarreraController.getUltima();
                                    //var cond = ConductorController.leer(ultima.Id_conductor);
                                    //Creando instancia de reporte
                                    TicketFisicoForm ticket = new TicketFisicoForm(
                                        CapaControlador.TransaccionController.getUltima().IdTransaccion,
                                        ultima.FechaCarrera.ToShortDateString(),
                                        MainContainer.sesion.ToString(),
                                        ultima.Vehiculo.Placa,
                                        ultima.Vehiculo.Socio.ToString(),
                                        cboConductor.SelectedItem.ToString(),
                                        ingreso,
                                        totalEgreso,
                                        (ingreso - totalEgreso)
                                        );
                                    ticket.ShowDialog();
                                }
                                limpiarControles();
                                actualizarNoFactura();
                            }
                        }
                        else
                        {
                            throw new Exception("No se Completo el registro de la carrera");
                        }
                    }
                    else
                    {
                        throw new Exception("No se Ingreso la carrera");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Todos los campos son requeridos!", "Faltan campos por completar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }