Пример #1
0
        private void AgregarProducto()
        {
            DataRow MyFila;
            double  cantidad = 1;
            double  subTotal = 0, total = 0;

            try
            {
                cantidad = double.Parse(txtCantidad.Text);

                if ((drProducto != null) && (nivelPrecio != ""))
                {
                    subTotal = cantidad * precioSinItbis;
                    itbis    = cantidad * itbis;
                    total    = cantidad * precioLista;

                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]      = drProducto["Producto_Id"];
                    MyFila["Descripcion"]      = drProducto["Nombre_Corto"];
                    MyFila["Categoria_Id"]     = drProducto["Categoria_Id"];
                    MyFila["UMedida_Id"]       = drProducto["UMedida_Id"];
                    MyFila["Cantidad"]         = cantidad;
                    MyFila["Precio_Sin_Itbis"] = Math.Round(precioSinItbis, 2);
                    MyFila["Precio"]           = Math.Round(precioLista, 2);
                    MyFila["Sub_Total"]        = Math.Round(subTotal, 2);
                    MyFila["Descuento"]        = 0;
                    MyFila["Tasa_Itbis"]       = Math.Round(tasaItbis, 2);
                    MyFila["Itbis"]            = Math.Round(itbis, 2);
                    MyFila["Monto"]            = Math.Round(total, 2);
                    MyFila["EsOferta"]         = esOferta;
                    MyFila["Nivel_Precio"]     = nivelPrecio;

                    AgregarLineaDetalle(MyFila);
                    txtCantidad.Text = "1";
                }

                precioLista    = 0;
                precioSinItbis = 0;
                itbis          = 0;
                nivelPrecio    = "";

                txtProductoId.Text      = "0000";
                txtProductoId.drFilaSel = null;
                drProducto = null;
                cboNivelPrecio.SelectedValue = "";
                txtProductoId.SelectAll();

                txtProductoId.Focus();
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
        }
Пример #2
0
        private void AddItem()
        {
            DataRow MyFila;
            double  cantidad = 1;

            try
            {
                cantidad = objUtil.ConvertirANumero(txtCantidad.Text);

                if (drProducto != null)
                {
                    if (cantidad <= 0)
                    {
                        objUtil.MostrarMensajeAdvertencia("LA CANTIDAD DEBE SER MAYOR A CERO(0)");
                        txtCantidad.Focus();
                        return;
                    }


                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]    = drProducto["Producto_Id"];
                    MyFila["Descripcion"]    = drProducto["Nombre_Corto"];
                    MyFila["Categoria_Id"]   = drProducto["Categoria_Id"];
                    MyFila["UMedida_Id"]     = drProducto["UMedida_Id"];
                    MyFila["Cantidad"]       = cantidad;
                    MyFila["Precio"]         = 0;
                    MyFila["Sub_Total"]      = 0;
                    MyFila["Descuento"]      = 0;
                    MyFila["Tasa_Itbis"]     = 0;
                    MyFila["Itbis"]          = 0;
                    MyFila["Total"]          = 0;
                    MyFila["EsExcentoItbis"] = false;
                    MyFila["PrecioConItbis"] = false;

                    AgregarLineaDetalle(MyFila, "Identificador_Id");

                    txtCodigoProducto.Text       = "";
                    txtCantidad.Text             = "1";
                    drProducto                   = null;
                    btnAgregarItem.Enabled       = false;
                    lblProdDescripcion.BackColor = SystemColors.Control;
                    lblProdDescripcion.Text      = @"NOMBRE/DESCRIPCION ITEM VENTA";

                    txtCodigoProducto.Focus();
                }
            }
            catch (Exception ex)
            {
                lblProdDescripcion.Text      = "ERROR: " + ex.Message;
                lblProdDescripcion.BackColor = Color.Red;
            }
        }
Пример #3
0
        private void addItem()
        {
            DataRow MyFila;
            double  precioLista = 0, precioSinItbis = 0, tasaItbis = 0, itbis = 0, cantidad = 1;
            double  subTotal = 0, total = 0;
            bool    esPrecioConItbis = true, esExcentoItbis = false, esOferta = false;
            string  nivelPrecio = "R";

            try
            {
                nivelPrecio = "R";
                if (drCliente != null)
                {
                    nivelPrecio = nivelPrecio = objUtil.GetAsString("Nivel_Precio", drCliente).ToUpper();
                }
                ;
                cantidad = objUtil.ConvertirANumero(txtCantidad.Text);

                if (drProducto != null)
                {
                    tasaItbis = objUtil.GetAsDouble("Tasa_Itbis", drProducto);

                    if (nivelPrecio == "A")
                    {
                        precioLista = objUtil.GetAsDouble("PrecioA", drProducto);
                    }
                    else if (nivelPrecio == "B")
                    {
                        precioLista = objUtil.GetAsDouble("PrecioB", drProducto);
                    }
                    else if (nivelPrecio == "C")
                    {
                        precioLista = objUtil.GetAsDouble("PrecioC", drProducto);
                    }

                    if (nivelPrecio == "R" || precioLista <= 0)
                    {
                        precioLista = objUtil.GetAsDouble("PrecioR", drProducto);
                    }

                    esExcentoItbis = objUtil.GetAsBoolean("EsExcentoItbis", drProducto);
                    esOferta       = objUtil.GetAsBoolean("EsOferta", drProducto);
                    if (esOferta)
                    {
                        precioLista = objUtil.GetAsDouble("PrecioO", drProducto);
                        nivelPrecio = "O";
                    }

                    precioSinItbis = precioLista;

                    if (cantidad <= 0)
                    {
                        objUtil.MostrarMensajeAdvertencia("LA CANTIDAD DEBE SER MAYOR A CERO(0)");
                        txtCantidad.Focus();
                        return;
                    }

                    if (tipoNCF <= 0 || esExcentoItbis)
                    {
                        tasaItbis = 0;
                    }

                    //CALCULAMOS PRECIO SIN EL ITEBIS
                    if (tasaItbis > 0)
                    {
                        precioSinItbis = Math.Round(precioLista / (1 + tasaItbis / 100.0), 2);
                        itbis          = precioLista - precioSinItbis;
                    }


                    subTotal = cantidad * precioSinItbis;
                    itbis    = cantidad * itbis;
                    total    = cantidad * precioLista;

                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]      = drProducto["Producto_Id"];
                    MyFila["Descripcion"]      = drProducto["Nombre_Corto"];
                    MyFila["Categoria_Id"]     = drProducto["Categoria_Id"];
                    MyFila["UMedida_Id"]       = drProducto["UMedida_Id"];
                    MyFila["Cantidad"]         = cantidad;
                    MyFila["Precio_Sin_Itbis"] = Math.Round(precioSinItbis, 2);
                    MyFila["Precio"]           = Math.Round(precioLista, 2);
                    MyFila["Sub_Total"]        = Math.Round(subTotal, 2);
                    MyFila["Descuento"]        = 0;
                    MyFila["Tasa_Itbis"]       = Math.Round(tasaItbis, 2);
                    MyFila["Itbis"]            = Math.Round(itbis, 2);
                    MyFila["Monto"]            = Math.Round(total, 2);
                    MyFila["EsOferta"]         = esOferta;
                    MyFila["Nivel_Precio"]     = nivelPrecio;
                    MyFila["EsExcentoItbis"]   = esExcentoItbis;
                    MyFila["PrecioConItbis"]   = esPrecioConItbis;

                    AgregarLineaDetalle(MyFila);

                    txtBusquedaProducto.Text = "";
                    txtCantidad.Text         = "1";

                    drProducto = null;

                    txtBusquedaProducto.Focus();
                }
            }
            catch (Exception ex)
            {
                lblMensajeError.Visible = true;
                lblMensajeError.Text    = "ERROR: " + ex.Message;
                toolTip1.SetToolTip(lblMensajeError, lblMensajeError.Text);
            }
            finally
            {
                txtBusquedaProducto.Focus();
            }
        }
Пример #4
0
        private void btnCargarArchivoCliente_Click(object sender, EventArgs e)
        {
            StreamReader streamDatos;
            string       linea = null;
            string       codigoCliente = "";
            string       nombreCliente = "";
            string       municipio = "";
            string       tipo = "", factura = "", sFecha, recibo, sValor, origen, concepto = "";
            int          anio, mes, dia;

            string[]       AFecha;
            DateTime       fecha;
            DataRow        dr;
            OpenFileDialog ofdArchivoCliente = new OpenFileDialog();
            string         nombreArchivo     = "";
            int            index             = 0;

            int conteo = 0;
            int carACopiar = 0, longitudActual = 0, posActual = 0;

            try
            {
                string directorioActual = "";

                directorioActual = System.Environment.CurrentDirectory;

                if (Directory.Exists(directorioActual))
                {
                    ofdArchivoCliente.InitialDirectory = directorioActual;
                }


                LimpiarDetalleTemporal();

                this.Cursor = Cursors.WaitCursor;
                ofdArchivoCliente.Filter = "txt files (*.txt)|*.txt";


                if (ofdArchivoCliente.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Verificamos si el archivo existe en el directori actual
                    nombreArchivo = ofdArchivoCliente.SafeFileName;
                    nombreArchivo = directorioActual + @"\" + nombreArchivo;

                    if (nombreArchivo.ToUpper() != ofdArchivoCliente.FileName.ToUpper())
                    {
                        if (File.Exists(nombreArchivo))
                        {
                            File.Delete(nombreArchivo);
                        }

                        File.Copy(ofdArchivoCliente.FileName, nombreArchivo);
                    }

                    ofdArchivoCliente.FileName = nombreArchivo;
                    streamDatos = new StreamReader(nombreArchivo);

                    while ((linea = streamDatos.ReadLine()) != null)
                    {
                        conteo++;
                        linea    = linea.Trim();
                        tipo     = "";
                        factura  = "";
                        sFecha   = "";
                        recibo   = "";
                        sValor   = "0.00";
                        origen   = "DR";
                        concepto = "";
                        fecha    = DateTime.Now.Date;

                        if (linea == "")
                        {
                            continue;
                        }

                        if (conteo == 6)
                        {
                            codigoCliente   = linea.Substring(0, 7);
                            nombreCliente   = linea.Substring(7, linea.Length - 7);
                            txtCodigo.Text  = codigoCliente;
                            txtNombres.Text = nombreCliente;
                            continue;
                        }

                        //Buscamos el Municipio
                        if (conteo == 8)
                        {
                            municipio         = linea;
                            txtMunicipio.Text = municipio;
                            continue;
                        }

                        if (conteo == 7)
                        {
                            municipio = linea;
                            continue;
                        }

                        if (linea.Contains("-----"))
                        {
                            continue;
                        }
                        if (linea.Contains("TIPO  FACTURA"))
                        {
                            continue;
                        }

                        tipo = linea.Substring(0, 2).ToUpper();

                        if ((tipo == "FT") || (tipo == "ND") || (tipo == "NC") || (tipo == "RC"))
                        {
                            factura = linea.Substring(2, 12).Trim();
                            recibo  = linea.Substring(14, 8).Trim();
                            sFecha  = linea.Substring(22, 11).Trim();
                            sValor  = linea.Substring(33, 13).Trim();

                            longitudActual = 47;
                            posActual      = 46;
                            if (linea.Length > longitudActual)
                            {
                                origen = linea.Substring(posActual, 2).Trim();
                                if (origen.Trim() != "")
                                {
                                    longitudActual = 49;
                                    posActual      = 48;
                                }
                            }

                            if (origen.Trim() == "")
                            {
                                origen = "DR";
                            }

                            //Buscamos el Concepto
                            carACopiar = linea.Length - longitudActual;
                            if (carACopiar > 0)
                            {
                                concepto = linea.Substring(posActual, carACopiar + 1).Trim();
                            }


                            //Vamos a Buscar la Fecha
                            if (sFecha.Trim() != "")
                            {
                                AFecha = sFecha.Split('/');
                                dia    = int.Parse(AFecha[0]);
                                mes    = int.Parse(AFecha[1]);
                                anio   = int.Parse(AFecha[2]);

                                fecha = new DateTime(anio, mes, dia);
                            }


                            dr              = DTDetalle.NewRow();
                            dr["tipo"]      = tipo;
                            dr["Factura"]   = factura;
                            dr["Recibo_No"] = recibo;
                            dr["Fecha"]     = fecha;
                            dr["valor"]     = objUtil.ConvertirANumero(sValor);
                            dr["Origen"]    = origen;
                            dr["Concepto"]  = concepto;

                            AgregarLineaDetalle(dr);
                        }
                    }


                    //ELIMINAMOS EL ARCHIVO

                    try
                    {
                        streamDatos.Dispose();
                        if (File.Exists(nombreArchivo))
                        {
                            File.Delete(nombreArchivo);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
                ofdArchivoCliente.Dispose();
            }
        }
        private void AddItem()
        {
            DataRow MyFila;
            double  precioLista, precioSinItbis, tasaItbis, itbis = 0, cantidad = 1;
            double  subTotal = 0, total = 0;
            bool    esPrecioConItbis = true, esExcentoItbis = false;

            try
            {
                cantidad       = objUtil.ConvertirANumero(txtCantidad.Text);
                precioLista    = objUtil.ConvertirANumero(txtPrecio.Text);
                precioSinItbis = precioLista;
                itbis          = 0;


                if (drProducto != null)
                {
                    tasaItbis      = objUtil.GetAsDouble("Tasa_Itbis", drProducto);
                    esExcentoItbis = objUtil.GetAsBoolean("EsExcentoItbis", drProducto);
                    if (esExcentoItbis)
                    {
                        tasaItbis = 0;
                    }

                    if (cantidad <= 0)
                    {
                        objUtil.MostrarMensajeAdvertencia("LA CANTIDAD DEBE SER MAYOR A CERO(0)");
                        txtCantidad.Focus();
                        return;
                    }

                    //CALCULAMOS PRECIO SIN EL ITEBIS
                    if (tasaItbis > 0)
                    {
                        precioSinItbis = Math.Round(precioSinItbis / (1 + tasaItbis / 100.0), 2);
                        itbis          = precioLista - precioSinItbis;
                    }


                    subTotal = cantidad * precioSinItbis;
                    itbis    = cantidad * itbis;
                    total    = cantidad * precioLista;

                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]    = drProducto["Producto_Id"];
                    MyFila["Descripcion"]    = drProducto["Nombre_Corto"];
                    MyFila["Categoria_Id"]   = drProducto["Categoria_Id"];
                    MyFila["UMedida_Id"]     = drProducto["UMedida_Id"];
                    MyFila["Cantidad"]       = cantidad;
                    MyFila["Precio"]         = Math.Round(precioLista, 2);
                    MyFila["Sub_Total"]      = Math.Round(subTotal, 2);
                    MyFila["Descuento"]      = 0;
                    MyFila["Tasa_Itbis"]     = Math.Round(tasaItbis, 2);
                    MyFila["Itbis"]          = Math.Round(itbis, 2);
                    MyFila["Total"]          = Math.Round(total, 2);
                    MyFila["EsExcentoItbis"] = esExcentoItbis;
                    MyFila["PrecioConItbis"] = esPrecioConItbis;

                    AgregarLineaDetalle(MyFila, "Identificador_Id");

                    txtCodigoProducto.Text       = "";
                    txtCantidad.Text             = "1";
                    txtPrecio.Text               = "0.00";
                    drProducto                   = null;
                    btnAgregarItem.Enabled       = false;
                    lblProdDescripcion.BackColor = SystemColors.Control;
                    lblProdDescripcion.Text      = @"NOMBRE/DESCRIPCION ITEM VENTA";

                    txtCodigoProducto.Focus();
                }
            }
            catch (Exception ex)
            {
                lblProdDescripcion.Text      = "ERROR: " + ex.Message;
                lblProdDescripcion.BackColor = Color.Red;
            }
        }
Пример #6
0
        void aplicarNotaCredito()
        {
            FormFacturaAplicarDevolucion frm = new FormFacturaAplicarDevolucion();
            double  monto = 0, itbis = 0, subtotal = 0;
            int     codigo = 0;
            string  concepto = "";
            DataRow MyFila;

            try
            {
                frm.esPorEntidad = NOTA_CREDITO_POR_ENTIDAD;
                frm.entidadId    = 0;

                frm.ShowDialog();

                if (frm.lOK)
                {
                    monto    = Math.Abs(frm.monto) * -1;
                    itbis    = Math.Abs(frm.itbis) * -1;
                    subtotal = (Math.Abs(frm.monto) - Math.Abs(frm.itbis)) * -1;
                    codigo   = frm.Id;
                    concepto = frm.concepto.Trim();
                    if (concepto == "")
                    {
                        concepto = "DEVOLUCION DE PRODUCTOS Y/O SERVICIOS";
                    }

                    concepto = "NC " + frm.concepto.Trim();

                    //Validamos no exista ya dicha nota de credito
                    if (DTDetalle.Select("Producto_Id = " + codigo.ToString() + " AND Tipo = 'NC' ").Count() > 0)
                    {
                        objUtil.MostrarMensajeError("ESTA NOTA DE CREDITO YA FUE AGREGADA");
                        return;
                    }

                    //Agregamos al Detalle si no existe la Nota de Credito Ya Aplicada
                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]      = codigo;
                    MyFila["Descripcion"]      = concepto;
                    MyFila["Categoria_Id"]     = 0;
                    MyFila["UMedida_Id"]       = 0;
                    MyFila["Cantidad"]         = 1;
                    MyFila["Precio_Sin_Itbis"] = 0;
                    MyFila["Precio"]           = monto;
                    MyFila["Sub_Total"]        = subtotal;
                    MyFila["Descuento"]        = 0;
                    MyFila["Tasa_Itbis"]       = 0;
                    MyFila["Itbis"]            = itbis;
                    MyFila["Monto"]            = monto;
                    MyFila["EsOferta"]         = 0;
                    MyFila["Nivel_Precio"]     = "R";
                    MyFila["EsExcentoItbis"]   = false;
                    MyFila["PrecioConItbis"]   = false;
                    MyFila["Tipo"]             = "NC";

                    AgregarLineaDetalle(MyFila);
                    TotalizarDetalle();
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                frm.Dispose();
            }
        }
Пример #7
0
        private void AgregarProducto()
        {
            DataRow MyFila;
            double  precioLista, precioSinItbis, tasaItbis, itbis = 0, cantidad = 1, gramos = 0;
            double  subTotal = 0, total = 0, precioMinimo = 0;
            bool    esPrecioConItbis = true, esExcentoItbis = false, esOferta = false, continuar = true;
            string  nivelPrecio = "R";

            try
            {
                nivelPrecio    = "R";
                cantidad       = objUtil.ConvertirANumero(txtCantidad.Text);
                continuar      = true;
                precioLista    = objUtil.ConvertirANumero(txtPrecio.Text);
                precioSinItbis = precioLista;
                itbis          = 0;

                if (cboTipoNCF.SelectedValue == null)
                {
                    tipoNCF = 0;
                }
                else
                {
                    tipoNCF = int.Parse(cboTipoNCF.SelectedValue.ToString());
                }


                if (drProducto != null)
                {
                    tasaItbis      = objUtil.GetAsDouble("Tasa_Itbis", drProducto);
                    precioMinimo   = objUtil.GetAsDouble("PrecioM", drProducto);
                    esExcentoItbis = objUtil.GetAsBoolean("EsExcentoItbis", drProducto);
                    esOferta       = objUtil.GetAsBoolean("EsOferta", drProducto);
                    if (esOferta)
                    {
                        precioMinimo = objUtil.GetAsDouble("PrecioO", drProducto);
                        nivelPrecio  = "O";
                    }

                    //VALIDAMOS EL PRECIO NO SEA MENOR O IGUAL A CERO NI MENOR AL PRECIO MINIMO
                    if (precioLista <= 0 || precioLista < precioMinimo)
                    {
                        objUtil.MostrarMensajeAdvertencia("EL PRECIO NO PUEDE SER MENOR AL PRECIO MINIMO: " + precioMinimo.ToString("N2"));
                        txtPrecio.Focus();
                        return;
                    }

                    if (cantidad <= 0)
                    {
                        objUtil.MostrarMensajeAdvertencia("LA CANTIDAD DEBE SER MAYOR A CERO(0)");
                        txtCantidad.Focus();
                        return;
                    }

                    if (tipoNCF <= 0 || esExcentoItbis)
                    {
                        tasaItbis = 0;
                    }

                    //CALCULAMOS PRECIO SIN EL ITEBIS
                    if (tasaItbis > 0)
                    {
                        precioSinItbis = Math.Round(precioSinItbis / (1 + tasaItbis / 100.0), 2);
                        itbis          = precioLista - precioSinItbis;
                    }



                    subTotal = cantidad * precioSinItbis;
                    itbis    = cantidad * itbis;
                    total    = cantidad * precioLista;

                    MyFila = DTDetalle.NewRow();
                    MyFila["Producto_Id"]      = drProducto["Producto_Id"];
                    MyFila["Descripcion"]      = drProducto["Nombre_Corto"];
                    MyFila["Categoria_Id"]     = drProducto["Categoria_Id"];
                    MyFila["UMedida_Id"]       = drProducto["UMedida_Id"];
                    MyFila["Cantidad"]         = cantidad;
                    MyFila["Precio_Sin_Itbis"] = Math.Round(precioSinItbis, 2);
                    MyFila["Precio"]           = Math.Round(precioLista, 2);
                    MyFila["Sub_Total"]        = Math.Round(subTotal, 2);
                    MyFila["Descuento"]        = 0;
                    MyFila["Tasa_Itbis"]       = Math.Round(tasaItbis, 2);
                    MyFila["Itbis"]            = Math.Round(itbis, 2);
                    MyFila["Monto"]            = Math.Round(total, 2);
                    MyFila["EsOferta"]         = esOferta;
                    MyFila["Nivel_Precio"]     = nivelPrecio;
                    MyFila["EsExcentoItbis"]   = esExcentoItbis;
                    MyFila["PrecioConItbis"]   = esPrecioConItbis;

                    AgregarLineaDetalle(MyFila);

                    txtCodigo.Text               = "";
                    txtCantidad.Text             = "1";
                    txtPrecio.Text               = "0.00";
                    drProducto                   = null;
                    btnAgregarItem.Enabled       = false;
                    lblProdDescripcion.BackColor = SystemColors.Control;
                    lblProdDescripcion.Text      = @"NOMBRE/DESCRIPCION ITEM VENTA";

                    txtCodigo.Focus();
                }
            }
            catch (Exception ex)
            {
                lblProdDescripcion.Text      = "ERROR: " + ex.Message;
                lblProdDescripcion.BackColor = Color.Red;
            }
        }
Пример #8
0
        void Generar()
        {
            double   monto      = 0;
            double   montoCuota = 0;
            double   tasaAnual  = 0;
            int      plazo      = 0;
            string   tipoSaldo;
            string   formaPago = "M";
            string   concepto  = "";
            DataRow  MyFila;
            DateTime fecha;
            double   saldoInicial = 0;
            double   saldoFinal   = 0;
            double   interes      = 0;
            double   capital      = 0;
            double   tasa         = 0;
            double   total        = 0.00;
            double   totalCapital = 0;
            double   diferencia   = 0;
            double   montoInicial = 0;
            int      metodo       = 0;
            double   dias         = 0;

            try
            {
                btnGrabar.Enabled = false;
                usaCliente0       = true;

                //VALIDAMOS QUE LA FECHA DE PRIMER PAGO SEA MAYOR A FECHA ACTUAL
                fecha     = dtpFechaPrimerPago.Value.Date;
                metodo    = cboMetodo.SelectedIndex;
                monto     = objUtil.ConvertirANumero(txtMonto.Text);
                plazo     = int.Parse(txtPlazo.Text);
                tasaAnual = double.Parse(txtTasa.Text);
                tipoSaldo = cboTipoSaldo.SelectedValue.ToString();
                formaPago = cboFrecuenciaPago.SelectedValue.ToString();

                if (monto <= 0)
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar El Monto del Prestamo");
                }
                else if (txtTasa.Text.Trim() == "")
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar la Tasa de Interes");
                }
                else if (txtPlazo.Text.Trim() == "")
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar el Plazo o Cantidad de Cuota");
                }
                else if (cboTipoSaldo.Text.Trim() == "")
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar el tipo de Saldo");
                }
                else if (cboFrecuenciaPago.Text.Trim() == "")
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar La Frecuencia o Forma de Pago");
                }
                else if (tasaMinima > 0 && tasaAnual < tasaMinima)
                {
                    objUtil.MostrarMensajeError("La Tasa de Interes No Puede Ser Menor A: " + tasaMinima.ToString("N2"));
                }
                else
                {
                    SetValorEncabezado("Monto_Aprobado", monto);
                    SetValorEncabezado("Monto_Inicial", montoInicial);

                    saldoInicial = monto;

                    if (formaPago == "M")
                    {
                        dias = 30;
                    }
                    else if (formaPago == "T")
                    {
                        dias = 360;
                    }
                    else if (formaPago == "Q")
                    {
                        dias = 15;
                    }
                    else if (formaPago == "S")
                    {
                        dias = 7;
                    }
                    else if (formaPago == "D")
                    {
                        dias = 1;
                    }

                    if ((tasaAnual < 0) || (plazo <= 0))
                    {
                        throw new Exception("Error La Tasa No Puede Ser Menor a Cero, Plazo o Cuota debe Ser Mayor a Cero");
                    }


                    if (metodo > 0)
                    {
                        montoCuota = objPrestamo.GetCuota(monto, plazo, tasaAnual, "I");

                        tasa = (tasaAnual / 12.0) / 100.0;
                        if (montoCuota == 0)
                        {
                            montoCuota = monto / plazo;
                        }
                    }
                    else
                    {
                        interes    = monto * (tasaAnual / 100.0) * (dias / 360);
                        montoCuota = (monto / plazo) + interes;
                    }

                    //LIMPIAMOS EL DETALLE TEMPORAL
                    LimpiarDetalleTemporal();

                    totalCapital = 0;
                    diferencia   = 0;

                    for (int i = 1; i <= plazo; i++)
                    {
                        concepto = "CUOTA " + i.ToString() + " DE " + plazo.ToString();
                        MyFila   = null;

                        MyFila = DTDetalle.NewRow();
                        MyFila["ItemNumero"] = i;
                        MyFila["Cuota_No"]   = i;
                        MyFila["Concepto"]   = concepto;


                        if (i > 1)
                        {
                            if (formaPago == "M")
                            {
                                fecha = fecha.AddMonths(1);
                            }
                            else if (formaPago == "T")
                            {
                                fecha = fecha.AddMonths(1);
                            }
                            else if (formaPago == "Q")
                            {
                                fecha = fecha.AddDays(15);
                            }
                            else if (formaPago == "S")
                            {
                                fecha = fecha.AddDays(7);
                            }
                            else if (formaPago == "D")
                            {
                                fecha = fecha.AddDays(1);
                            }
                            else
                            {
                                throw new Exception("Forma de Pago No Existe");
                            }
                        }

                        MyFila["Fecha"] = fecha;


                        if (montoInicial > 0 && metodo > 0)
                        {
                            if (i == 1)
                            {
                                interes = (saldoInicial * (tasaAnual / 12.0)) / 100;
                                capital = montoCuota - interes;
                            }
                        }
                        else if (metodo > 0)
                        {
                            interes = saldoInicial * tasa;

                            if (saldoInicial > montoCuota)
                            {
                                capital = montoCuota - interes;
                            }
                            else if (saldoInicial < montoCuota)
                            {
                                capital = saldoInicial;
                            }
                            else
                            {
                                capital = saldoInicial - interes;
                            }
                        }
                        else
                        {
                            capital = monto / plazo;
                        }

                        totalCapital += capital;

                        //VALIDAMOS QUE EL TOTAL DE CAPITAL = MONTO DEL PRESTAMO
                        if ((i == plazo) && (montoInicial <= 0))
                        {
                            diferencia = monto - totalCapital;
                            if (diferencia > 0)
                            {
                                capital += diferencia;
                                interes -= diferencia;
                            }
                            else
                            {
                                capital -= diferencia;
                                interes += diferencia;
                            }
                        }

                        MyFila["Saldo_Inicial"] = saldoInicial;
                        MyFila["Capital"]       = capital;
                        MyFila["Interes"]       = interes;
                        MyFila["Monto"]         = (capital + interes);

                        if (saldoInicial > montoCuota)
                        {
                            saldoFinal = saldoInicial - capital;
                        }
                        else
                        {
                            saldoFinal = saldoInicial - (capital + interes);
                        }

                        if (saldoFinal < 0)
                        {
                            saldoFinal = 0;
                        }

                        MyFila["Saldo_Final"] = saldoFinal;

                        saldoInicial = saldoFinal;

                        AgregarLineaDetalle(MyFila);
                    }

                    capital = GetSumDetalle("Capital");
                    interes = GetSumDetalle("Interes");

                    total = capital + interes;

                    lblTotalCapital.Text = capital.ToString("N2");
                    lblTotalInteres.Text = interes.ToString("N2");
                    lblTotal.Text        = total.ToString("N2");
                    lblMontoCuota.Text   = montoCuota.ToString("N2");

                    //GUARDAMOS DATOS DEL ENCABEZADO
                    SetValorEncabezado("Tipo_Saldo", tipoSaldo);
                    SetValorEncabezado("Tasa_Interes", tasaAnual);
                    SetValorEncabezado("Frecuencia_Pago", formaPago);
                    SetValorEncabezado("Plazo", plazo);
                    SetValorEncabezado("Monto_Cuota", montoCuota);
                    SetValorEncabezado("Monto_Prestamo", monto);
                    SetValorEncabezado("Fecha_Termino", fecha);
                    SetValorEncabezado("Fecha_Primer_Pago", dtpFechaPrimerPago.Value);



                    PostEncabezadoTemp();


                    btnGrabar.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
        }
Пример #9
0
        void Generar()
        {
            double    monto = 0;
            double    montoCuota = 0;
            double    tasaAnual = 0;
            int       plazo = 0, diaAPagar = 0, conteo = 0;
            string    formaPago = "M", tipoSaldo = "I", SSQL = "";
            double    totalCapital = 0, totalInteres = 0;
            DataTable DTData     = null;
            DataRow   MyFila     = null;
            DateTime  fechaIni   = DateTime.Now;
            DateTime  fechaFinal = DateTime.Now;

            try
            {
                btnGrabar.Enabled = false;
                usaCliente0       = true;

                if (cboTipoSaldo.SelectedValue != null)
                {
                    tipoSaldo = cboTipoSaldo.SelectedValue.ToString();
                }

                int.TryParse(txtPlazo.Text, out plazo);
                tasaAnual = double.Parse(txtTasa.Text);
                monto     = double.Parse(lblMontoPrestamo.Text);
                diaAPagar = (int)nudDiaAPagar.Value;
                if (cboFrecuenciaPago.SelectedValue != null)
                {
                    formaPago = cboFrecuenciaPago.SelectedValue.ToString();
                }

                if (monto <= 0)
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar El Monto del Prestamo");
                }
                else if (tasaAnual <= 0)
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar la Tasa de Interes");
                }
                else if (plazo <= 0)
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar el Plazo o Cantidad de Cuota");
                }
                else if (cboFrecuenciaPago.Text.Trim() == "")
                {
                    objUtil.MostrarMensajeAdvertencia("Debe Indicar La Frecuencia o Forma de Pago");
                }
                else
                {
                    SetValorEncabezado("Monto_Prestamo", monto);
                    SetValorEncabezado("Dia_APagar", diaAPagar);

                    //GENERAMOS LA TABLA DE AMORTIZACION
                    SSQL   = "select * from dbo.FN_TABLA_AMORTIZACION(";
                    SSQL  += monto.ToString() + ", ";
                    SSQL  += tasaAnual.ToString() + ", ";
                    SSQL  += plazo.ToString() + ", ";
                    SSQL  += "'" + formaPago.Trim() + "', ";
                    SSQL  += "NULL, ";
                    SSQL  += diaAPagar.ToString();
                    SSQL  += ")";
                    DTData = objDB.GetSQL(SSQL);

                    //LIMPIAMOS EL DETALLE TEMPORAL
                    LimpiarDetalleTemporal();
                    foreach (DataRow item in DTData.Rows)
                    {
                        if (conteo <= 0)
                        {
                            montoCuota = objDB.GetAsDouble("Cuota", item);
                            fechaIni   = objDB.GetAsDate("Fecha", item);
                        }

                        fechaFinal = objDB.GetAsDate("Fecha", item);

                        MyFila = null;
                        MyFila = DTDetalle.NewRow();
                        MyFila["ItemNumero"]    = conteo + 1;
                        MyFila["Cuota_No"]      = objDB.GetAsInt("Id", item);
                        MyFila["Concepto"]      = objDB.GetAsString("Concepto", item);
                        MyFila["Fecha"]         = objDB.GetAsDate("Fecha", item);
                        MyFila["Saldo_Inicial"] = objDB.GetAsDouble("CapitalIni", item);
                        MyFila["Capital"]       = objDB.GetAsDouble("Capital", item);
                        MyFila["Interes"]       = objDB.GetAsDouble("Interes", item);
                        MyFila["Monto"]         = (objDB.GetAsDouble("Capital", item) + objDB.GetAsDouble("Interes", item));
                        MyFila["Saldo_Final"]   = objDB.GetAsDouble("Saldo", item);

                        totalCapital += objDB.GetAsDouble("Capital", item);
                        totalInteres += objDB.GetAsDouble("Interes", item);

                        AgregarLineaDetalle(MyFila);
                        conteo++;
                    }

                    lblTotalDetalle.Text  = "Capital: " + totalCapital.ToString("N2") + "             ";
                    lblTotalDetalle.Text += "Interes: " + totalInteres.ToString("N2");
                    lblTotalDetalle.Text += "             Cuota de: " + montoCuota.ToString("N2");
                    lblMontoCuota.Text    = montoCuota.ToString("N2");

                    //GUARDAMOS DATOS DEL ENCABEZADO
                    SetValorEncabezado("Tipo_Saldo", tipoSaldo);
                    SetValorEncabezado("Tasa_Interes", tasaAnual);
                    SetValorEncabezado("Frecuencia_Pago", formaPago);
                    SetValorEncabezado("Plazo", plazo);
                    SetValorEncabezado("Monto_Cuota", montoCuota);
                    SetValorEncabezado("Monto_Prestamo", monto);
                    SetValorEncabezado("Fecha_Termino", fechaFinal);
                    SetValorEncabezado("Fecha_Primer_Pago", fechaIni);

                    PostEncabezadoTemp();

                    //btnGenerar.Focus();
                    btnGrabar.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
        }