Exemple #1
0
        private async void LoadAgendamientos(string tipo_busqueda, string texto_busqueda)
        {
            try
            {
                var(rpta, dtAgendamiento) = await NAgendamiento_cobros.BuscarAgendamientos(tipo_busqueda, texto_busqueda);

                this.Agendamientos = new List <Agendamiento_cobros>();
                if (dtAgendamiento != null)
                {
                    int pagos   = 0;
                    int nopagos = 0;

                    List <UserControl> controls = new List <UserControl>();
                    this.UltimoAgendamiento = new Agendamiento_cobros(dtAgendamiento.Rows[0]);
                    foreach (DataRow row in dtAgendamiento.Rows)
                    {
                        Agendamiento_cobros ag = new Agendamiento_cobros(row);
                        this.Agendamientos.Add(ag);
                        if (ag.Estado_cobro.Equals("TERMINADO"))
                        {
                            pagos += 1;
                        }
                        else
                        {
                            nopagos += 1;
                        }

                        AgendamientoSmall agendamientoSmall = new AgendamientoSmall
                        {
                            Agendamiento = ag,
                        };
                        agendamientoSmall.OnRefresh += AgendamientoSmall_OnRefresh;
                        controls.Add(agendamientoSmall);
                    }
                    this.panelPagos.AddArrayControl(controls);

                    this.rdNoPagos.Text    = "No pagos (" + nopagos + ")";
                    this.rdTerminados.Text = "Terminados (" + pagos + ")";
                }
            }
            catch (Exception ex)
            {
                Mensajes.MensajeErrorCompleto(this.Name, "LoadAgendamientos",
                                              "Hubo un error al buscar los agendamientos", ex.Message);
            }
        }
        private async void AsignarDatos(Ventas venta)
        {
            this.IsEditar = true;

            //Obtener el último agendamiento
            var(rptaAg, dt) =
                await NAgendamiento_cobros.BuscarAgendamientos("ID VENTA", venta.Id_venta.ToString());

            if (dt != null)
            {
                Agendamiento_cobros agendamiento = new Agendamiento_cobros(dt.Rows[0]);

                this.txtValorAbono.Text   = agendamiento.Valor_pagado.ToString("C");
                this.txtValorAbono.Tag    = agendamiento.Valor_pagado;
                this.dateUltimoPago.Value = agendamiento.Fecha_cobro;
            }

            this.gbValorAbono.Visible = true;
            this.rdActual.Visible     = false;
            this.rdAnterior.Visible   = false;
            this.gbUltimoPago.Visible = true;

            this.dateFechaVenta.Value    = venta.Fecha_venta;
            this.txtNombres.Text         = venta.Cliente.Nombres;
            this.txtApellidos.Text       = venta.Cliente.Apellidos;
            this.txtIdentificacion.Text  = venta.Cliente.Identificacion;
            this.txtValorTotalVenta.Tag  = venta.Total_venta;
            this.txtValorTotalVenta.Text = venta.Total_venta.ToString("C");

            this.txtDireccionResidencia.Text = venta.Direccion.Direccion;
            this.txtTelCliente.Text          = venta.Cliente.Celular;

            this.numericPlazo.Value = venta.Numero_cuotas;

            this.dateFechaVenta.Value = venta.Fecha_venta;

            this.LoadListaFrecuencia();
            this.listaFrecuencia.Text = venta.Frecuencia_cobro;

            this.LoadCiudades("ID PAIS", "2020");
            this.listaCiudades.SelectedValue = venta.Direccion.Zona.Id_ciudad.ToString();

            this.LoadBarrios("ID CIUDAD", venta.Direccion.Zona.Id_ciudad.ToString());
            this.listaBarrios.SelectedValue = venta.Direccion.Zona.Id_zona;
        }
        private async void AbonoSmall_OnBtnSaveClick(object sender, EventArgs e)
        {
            object[] objs                = (object[])sender;
            decimal  valor_abono         = (decimal)objs[0];
            DateTime fecha_proximo_abono = (DateTime)objs[1];
            DateTime fecha_abono         = (DateTime)objs[2];

            if (valor_abono != 0)
            {
                MainController main = MainController.GetInstance();
                this.Agendamiento.Fecha_cobro     = fecha_abono;
                this.Agendamiento.Valor_pagado    = valor_abono;
                this.Agendamiento.Saldo_restante -= valor_abono;
                this.Agendamiento.Id_turno        = main.Turno.Id_turno;
                this.Agendamiento.Turno           = main.Turno;
                this.Agendamiento.Estado_cobro    = "TERMINADO";

                string rpta =
                    await NAgendamiento_cobros.EditarAgendamiento(this.Agendamiento.Id_agendamiento, this.Agendamiento);

                if (rpta.Equals("OK"))
                {
                    this.Agendamiento.Valor_pagado = 0;
                    this.Agendamiento.Fecha_cobro  = fecha_proximo_abono;
                    this.Agendamiento.Estado_cobro = "PENDIENTE";
                    rpta = NAgendamiento_cobros.InsertarAgendamiento(out int id_agendamiento, this.Agendamiento);
                    if (rpta.Equals("OK"))
                    {
                        Mensajes.MensajeInformacion("Abono realizado y proximo cobro agendado con éxito para la fecha " +
                                                    fecha_proximo_abono.ToLongDateString(), "Entendido");
                    }
                    else
                    {
                        Mensajes.MensajeInformacion("Abono realizado correctamente pero no se realizó el agendamiento para el proximo cobro", "Entendido");
                    }
                    this.OnRefresh?.Invoke(sender, e);
                }
                else
                {
                    Mensajes.MensajeInformacion("No se pudo realizar el abono", "Entendido");
                }
            }
        }
        private async Task LoadAgendamientos(string tipo_busqueda, string texto_busqueda)
        {
            try
            {
                MensajeEspera.ShowWait("Cargando...");
                var(rpta, dtAgendamiento) = await NAgendamiento_cobros.BuscarAgendamientos(tipo_busqueda, texto_busqueda);

                this.panelClientes.clearDataSource();
                this.positionChanged = 1;
                this.DtAgendamientos = dtAgendamiento;

                if (dtAgendamiento != null)
                {
                    List <UserControl> userControls = new List <UserControl>();

                    foreach (DataRow row in dtAgendamiento.Rows)
                    {
                        Agendamiento_cobros ag           = new Agendamiento_cobros(row);
                        ClienteSmall        clienteSmall = new ClienteSmall
                        {
                            Agendamiento = ag,
                        };
                        clienteSmall.OnRefresh += ClienteSmall_OnRefresh;
                        userControls.Add(clienteSmall);
                    }

                    this.panelClientes.PageSize             = 20;
                    this.panelClientes.OnBsPositionChanged += PaneClientes_OnBsPositionChanged;
                    this.panelClientes.SetPagedDataSource(userControls, this.bindingNavigator2);
                }

                MensajeEspera.CloseForm();
                this.Show();
            }
            catch (Exception ex)
            {
                MensajeEspera.CloseForm();
                Mensajes.MensajeErrorCompleto(this.Name, "LoadClientes",
                                              "Hubo un error al cargar los agendamientos", ex.Message);
            }
        }
        private async void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var(result, usuario, direccion, venta, agendamiento) = await this.Comprobaciones();

                if (result)
                {
                    MensajeEspera.ShowWait("Guardando...");
                    List <string> errores = new List <string>();
                    string        rpta    = "";

                    if (this.IsEditar)
                    {
                        rpta = NUsuarios.EditarUsuario(usuario.Id_usuario, usuario);
                    }
                    else
                    {
                        rpta = NUsuarios.InsertarUsuario(out int id_usuario, usuario);
                        direccion.Id_usuario = id_usuario;
                        venta.Id_cliente     = id_usuario;
                        usuario.Id_usuario   = id_usuario;
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.IsEditar)
                        {
                            rpta = NDireccion_clientes.EditarDireccion(direccion.Id_direccion, direccion);
                        }
                        else
                        {
                            rpta = NDireccion_clientes.InsertarDireccion(out int id_direccion, direccion);
                            venta.Id_direccion = id_direccion;
                        }

                        if (rpta.Equals("OK"))
                        {
                            if (this.IsEditar)
                            {
                                rpta = NVentas.EditarVenta(venta.Id_venta, venta);
                            }
                            else
                            {
                                rpta           = NVentas.InsertarVenta(out int id_venta, venta);
                                venta.Id_venta = id_venta;
                            }

                            if (rpta.Equals("OK"))
                            {
                                if (this.rdActual.Checked && !this.IsEditar && this.chkDescontar.Checked)
                                {
                                    foreach (Articulos art in this.ArticulosSelected)
                                    {
                                        Detalle_articulos_venta detalle = new Detalle_articulos_venta
                                        {
                                            Articulo          = art,
                                            Id_articulo       = art.Id_articulo,
                                            Venta             = venta,
                                            Id_venta          = venta.Id_venta,
                                            Cantidad_articulo = (int)art.Cantidad_articulo,
                                            Valor_articulo    = art.Valor_articulo,
                                            Estado_detalle    = "ACTIVO",
                                        };

                                        var(rptaDetalle, id_detalle) =
                                            await NDetalle_articulos_venta.InsertarDetalle(detalle);

                                        if (!rptaDetalle.Equals("OK"))
                                        {
                                            errores.Add(rptaDetalle);
                                        }
                                    }
                                }

                                MainController main = MainController.GetInstance();

                                if (!this.IsEditar)
                                {
                                    rpta = NUsuariosVentas.InsertarUsuarioVenta(new Usuarios_ventas
                                    {
                                        Id_usuario = main.Usuario.Id_usuario,
                                        Id_venta   = venta.Id_venta,
                                    });

                                    if (rpta.Equals("OK"))
                                    {
                                        agendamiento.Id_venta = venta.Id_venta;
                                        rpta = NAgendamiento_cobros.InsertarAgendamiento(out int id_agendamiento, agendamiento);
                                        if (rpta.Equals("OK"))
                                        {
                                            MensajeEspera.CloseForm();
                                            Mensajes.MensajeInformacion("Se guardó correctamente el cliente, " +
                                                                        "número cliente: " + usuario.Id_usuario + " Número venta: " + venta.Id_venta, "Entendido");
                                            this.Close();
                                        }
                                        else
                                        {
                                            throw new Exception(rpta);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception(rpta);
                                    }
                                }
                                else
                                {
                                    //Obtener el último agendamiento
                                    var(rptaAg, dt) =
                                        await NAgendamiento_cobros.BuscarAgendamientos("ID VENTA", venta.Id_venta.ToString());

                                    if (dt != null)
                                    {
                                        agendamiento             = new Agendamiento_cobros(dt.Rows[0]);
                                        agendamiento.Valor_cobro = venta.Valor_cuota;
                                        agendamiento.Fecha_cobro = this.dateUltimoPago.Value;
                                        rptaAg = await NAgendamiento_cobros.EditarAgendamiento(agendamiento.Id_agendamiento, agendamiento);

                                        if (rptaAg != "OK")
                                        {
                                            Mensajes.MensajeInformacion("Se actualizó el cliente pero no su último pago," +
                                                                        "número cliente: " + usuario.Id_usuario + " Número venta: " + venta.Id_venta, "Entendido");
                                            this.OnRefresh?.Invoke(sender, e);
                                            this.Close();
                                        }
                                        else
                                        {
                                            Mensajes.MensajeInformacion("Se actualizó correctamente el cliente, " +
                                                                        "número cliente: " + usuario.Id_usuario + " Número venta: " + venta.Id_venta, "Entendido");
                                            this.OnRefresh?.Invoke(sender, e);
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        Mensajes.MensajeInformacion("Se actualizó correctamente el cliente pero no se encontraron sus agendamientos, número asignado: " + usuario.Id_usuario, "Entendido");
                                        this.OnRefresh?.Invoke(sender, e);
                                        this.Close();
                                    }
                                }
                            }
                        }
                        else
                        {
                            throw new Exception(rpta);
                        }
                    }
                    else
                    {
                        throw new Exception(rpta);
                    }
                }
                MensajeEspera.CloseForm();
            }
            catch (Exception ex)
            {
                MensajeEspera.CloseForm();
                Mensajes.MensajeErrorCompleto(this.Name, "BtnSave_Click",
                                              "Hubo un error al guardar el cliente", ex.Message);
            }
        }
        private async void BtnReporteClientes_Click(object sender, EventArgs e)
        {
            MensajeEspera.ShowWait("Cargando reporte...");
            DataTable dtClientes = new DataTable("Clientes");

            dtClientes.Columns.Add("Id_cliente", typeof(int));
            dtClientes.Columns.Add("Nombre_cliente", typeof(string));
            dtClientes.Columns.Add("Celular_cliente", typeof(string));
            dtClientes.Columns.Add("Referencia_articulo", typeof(string));
            dtClientes.Columns.Add("Saldo_restante", typeof(string));
            dtClientes.Columns.Add("Venta_total", typeof(string));
            dtClientes.Columns.Add("Fecha_venta", typeof(string));
            dtClientes.Columns.Add("Fecha_ultimo_pago", typeof(string));
            dtClientes.Columns.Add("Dias_mora", typeof(int));

            int            id_cliente          = 0;
            string         nombre_cliente      = string.Empty;
            string         celular_cliente     = string.Empty;
            string         referencia_articulo = string.Empty;
            decimal        saldo_restante      = 0;
            decimal        total_venta         = 0;
            DateTime       fecha_venta         = DateTime.Now;
            decimal        suma_ventas         = 0;
            decimal        suma_saldos         = 0;
            DateTime       fecha_ultimo_pago   = DateTime.Now;
            MainController main = MainController.GetInstance();

            var(rpta, dtVentas) =
                await NVentas.BuscarVentas("ID COBRO ACTIVO", main.Id_cobro.ToString());

            if (dtVentas != null)
            {
                foreach (DataRow row in dtVentas.Rows)
                {
                    Ventas venta = new Ventas(row);
                    id_cliente      = venta.Id_cliente;
                    nombre_cliente  = venta.Cliente.NombreCompleto;
                    celular_cliente = venta.Cliente.Celular;
                    total_venta     = venta.Total_venta;
                    fecha_venta     = venta.Fecha_venta;
                    suma_ventas    += venta.Total_venta;

                    //Buscar los agendamientos de cada venta para ver su saldo restante
                    var(rpta1, dtAgendamientos) = await NAgendamiento_cobros.BuscarAgendamientos("ID VENTA", venta.Id_venta.ToString());

                    if (dtAgendamientos != null)
                    {
                        Agendamiento_cobros ag = new Agendamiento_cobros(dtAgendamientos.Rows[0]);
                        saldo_restante    = ag.Saldo_restante;
                        suma_saldos      += ag.Saldo_restante;
                        fecha_ultimo_pago = ag.Fecha_cobro;
                    }

                    TimeSpan timeSpan  = DateTime.Now - fecha_ultimo_pago;
                    double   dias_mora = timeSpan.TotalDays;

                    DataRow newRow = dtClientes.NewRow();
                    newRow["Id_cliente"]          = id_cliente;
                    newRow["Nombre_cliente"]      = nombre_cliente;
                    newRow["Celular_cliente"]     = celular_cliente;
                    newRow["Referencia_articulo"] = referencia_articulo;
                    newRow["Saldo_restante"]      = saldo_restante.ToString("C");
                    newRow["Venta_total"]         = total_venta.ToString("C");
                    newRow["Fecha_venta"]         = fecha_venta.ToString("dd-MM-yyyy");
                    newRow["Fecha_ultimo_pago"]   = fecha_ultimo_pago.ToString("dd-MM-yyyy");
                    newRow["Dias_mora"]           = dias_mora;
                    dtClientes.Rows.Add(newRow);
                }

                if (dtClientes.Rows.Count > 0)
                {
                    MensajeEspera.CloseForm();
                    //Enviar informe
                    FrmReporteClientes frmReporteClientes = new FrmReporteClientes
                    {
                        WindowState  = FormWindowState.Maximized,
                        dtClientes   = dtClientes,
                        Total_saldos = suma_saldos.ToString("C"),
                        Total_ventas = suma_ventas.ToString("C"),
                    };
                    frmReporteClientes.Show();
                }
                else
                {
                    MensajeEspera.CloseForm();
                    Mensajes.MensajeInformacion("No se encontraron clientes", "Entendido");
                }
            }
            else
            {
                MensajeEspera.CloseForm();
                Mensajes.MensajeInformacion("No se encontraron clientes", "Entendido");
            }

            MensajeEspera.CloseForm();
        }
Exemple #7
0
        private async void AbonoSmall_OnBtnSaveClick(object sender, EventArgs e)
        {
            object[] objs                = (object[])sender;
            decimal  valor_abono         = (decimal)objs[0];
            DateTime fecha_proximo_abono = (DateTime)objs[1];
            DateTime fecha_abono         = (DateTime)objs[2];

            if (valor_abono != 0)
            {
                MainController main = MainController.GetInstance();
                string         rpta = "OK";

                if (this.UltimoAgendamiento != null)
                {
                    if (this.UltimoAgendamiento.Estado_cobro.Equals("PENDIENTE"))
                    {
                        this.UltimoAgendamiento.Fecha_cobro     = fecha_abono;
                        this.UltimoAgendamiento.Valor_pagado    = valor_abono;
                        this.UltimoAgendamiento.Saldo_restante -= valor_abono;
                        this.UltimoAgendamiento.Id_turno        = main.Turno.Id_turno;
                        this.UltimoAgendamiento.Turno           = main.Turno;
                        this.UltimoAgendamiento.Estado_cobro    = "TERMINADO";

                        rpta =
                            await NAgendamiento_cobros.EditarAgendamiento(this.UltimoAgendamiento.Id_agendamiento, this.UltimoAgendamiento);
                    }
                    else
                    {
                        this.UltimoAgendamiento.Fecha_cobro     = fecha_abono;
                        this.UltimoAgendamiento.Valor_pagado    = valor_abono;
                        this.UltimoAgendamiento.Saldo_restante -= valor_abono;
                        this.UltimoAgendamiento.Id_turno        = main.Turno.Id_turno;
                        this.UltimoAgendamiento.Turno           = main.Turno;
                        this.UltimoAgendamiento.Estado_cobro    = "TERMINADO";

                        rpta =
                            NAgendamiento_cobros.InsertarAgendamiento(out int id, this.UltimoAgendamiento);
                    }
                }
                else
                {
                    this.UltimoAgendamiento                     = new Agendamiento_cobros();
                    this.UltimoAgendamiento.Orden_cobro         = 0;
                    this.UltimoAgendamiento.Id_venta            = this.Venta.Id_venta;
                    this.UltimoAgendamiento.Venta               = this.Venta;
                    this.UltimoAgendamiento.Fecha_cobro         = fecha_abono;
                    this.UltimoAgendamiento.Valor_cobro         = this.Venta.Valor_cuota;
                    this.UltimoAgendamiento.Valor_pagado        = valor_abono;
                    this.UltimoAgendamiento.Saldo_restante      = this.Venta.Total_venta - valor_abono;
                    this.UltimoAgendamiento.Id_turno            = main.Turno.Id_turno;
                    this.UltimoAgendamiento.Turno               = main.Turno;
                    this.UltimoAgendamiento.Estado_cobro        = "TERMINADO";
                    this.UltimoAgendamiento.Tipo_cobro          = this.Venta.Frecuencia_cobro;
                    this.UltimoAgendamiento.Observaciones_cobro = string.Empty;
                }

                if (rpta.Equals("OK"))
                {
                    this.abonoSmall.Clear();

                    this.UltimoAgendamiento.Valor_pagado = 0;
                    this.UltimoAgendamiento.Fecha_cobro  = fecha_proximo_abono;
                    this.UltimoAgendamiento.Estado_cobro = "PENDIENTE";
                    rpta = NAgendamiento_cobros.InsertarAgendamiento(out int id_agendamiento, this.UltimoAgendamiento);
                    if (rpta.Equals("OK"))
                    {
                        Mensajes.MensajeInformacion("Abono realizado y proximo cobro agendado con éxito para la fecha " +
                                                    fecha_proximo_abono.ToLongDateString(), "Entendido");
                    }
                    else
                    {
                        Mensajes.MensajeInformacion("Abono realizado correctamente pero no se realizó el agendamiento para el proximo cobro", "Entendido");
                    }

                    this.LoadAgendamientos("ID VENTA", this.Venta.Id_venta.ToString());
                }
                else
                {
                    Mensajes.MensajeInformacion("No se pudo realizar el abono", "Entendido");
                }
            }
        }