Exemplo n.º 1
0
        private void FormSALIDAS_Load(object sender, EventArgs e)
        {
            idproyectos = 0;
            if (OSAGralSeleccionada == null)
            {
                OENGRALnextId();
            }
            //comboBoxClientes.DataSource = clientes.GetExistentes();
            comboVendedor.DataSource       = usuario.GetExistentes();
            comboBoxClientes.SelectedIndex = -1;
            comboVendedor.SelectedIndex    = -1;
            EmpleadoSeleccionado           = (usuario)comboVendedor.SelectedItem;
            DataColumn workCol = PartidasOSA.Columns.Add("Catálogo", typeof(string));

            workCol.AllowDBNull = false;
            workCol.Unique      = false;
            DataColumn Descripcion = PartidasOSA.Columns.Add("Descripción", typeof(string));

            Descripcion.AllowDBNull = false;
            Descripcion.Unique      = false;
            PartidaNextId();
            if (idosa > 0)
            {
                polizaseleccionada         = new polizasdb(OSAGralSeleccionada.idpoliza);
                ClienteSeleccionado        = new clientes(OSAGralSeleccionada.ID_CLIENTE);
                comboBoxClientes.Text      = ClienteSeleccionado.RAZON_SOCIAL;
                proyectoSeleccionado       = new proyectos(OSAGralSeleccionada.PROYECTO_ID);
                comboBoxProyecto.Text      = proyectoSeleccionado.NOMBRE;
                textBoxOENid.Text          = OSAGralSeleccionada.Id.ToString();
                FACTURA.Text               = OSAGralSeleccionada.FACTURA;
                REMISION.Text              = OSAGralSeleccionada.REMISION;
                textBoxTipoCambio.Text     = OSAGralSeleccionada.TC.ToString();
                COTIZACION.Text            = OSAGralSeleccionada.COTIZACION.ToString();
                buttonCancelar.Visible     = false;
                buttonIngresarHoja.Visible = false;
                buttonIngresar.Visible     = false;
                buttonNewProject.Visible   = false;
                label2.Visible             = false;
                textBoxCantidad.Visible    = false;
                label1.Visible             = false;
                textBoxProducto.Visible    = false;
                button1.Visible            = true;
            }
        }
Exemplo n.º 2
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[1].Value == DBNull.Value)
            {
                return;
            }
            int rowIndex = e.RowIndex;

            int    item     = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[0].Value);
            string catalogo = dataGridView1.Rows[rowIndex].Cells[1].Value.ToString();

            osa_indiv        i       = new osa_indiv(item, osaSeleccionada.Id);
            productos        p       = new productos(i.ID_PRODUCTO2);
            inventariocostos invCost = new inventariocostos(i.ID_PRODUCTO2, true);

            FormDevolucion d = new FormDevolucion();

            d.labelProducto.Text     = "OSA no. " + osaSeleccionada.Id + ",  ITEM: " + item + ",  CATALOGO: " + catalogo;
            d.textBoxExistencia.Text = i.QTY2.ToString();
            d.existencia             = i.QTY2;
            d.stock = p.STOCK;
            d.ShowDialog();

            if (d.DialogResult == DialogResult.OK)
            {
                if (d.existencia < i.QTY2)
                {
                    #region WHILE DEVOLVER A iNVENTARIOCOSTOS
                    if (invCost.Id > 0)
                    {
                        int diferenciaOen = invCost.cantidad_oen - invCost.cantidad_actual;
                        int restaOsa      = i.QTY2 - d.existencia;

                        if (restaOsa <= diferenciaOen)
                        {
                            invCost.cantidad_actual += restaOsa;
                            invCost.Update("Id");
                        }
                        else
                        {
                            int qty = restaOsa;

                            invCost.cantidad_actual += diferenciaOen;
                            invCost.Update("Id");
                            qty -= diferenciaOen;

                            while (qty > 0)
                            {
                                inventariocostos invCost2 = new inventariocostos(i.ID_PRODUCTO2, true);
                                if (invCost2.Id > 0)
                                {
                                    int restaOen = invCost2.cantidad_oen - invCost2.cantidad_actual;
                                    if (qty <= restaOen)
                                    {
                                        invCost2.cantidad_actual += qty;
                                        invCost2.Update("Id");
                                        qty = 0;
                                    }
                                    else
                                    {
                                        invCost2.cantidad_actual += restaOen;
                                        invCost2.Update("Id");
                                        qty -= restaOen;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("No hay ordenes de entrada para este producto");
                                    qty = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No hay ordenes de entrada para estos productos");
                    }

                    #endregion WHILE DEVOLVER A INVENTARIOcOSTOS

                    i.QTY2  = d.existencia;
                    p.STOCK = d.stock;
                    i.Update("Id");
                    p.Update("Id");

                    MessageBox.Show("Devolucion aplicada");
                    VerDGV(osaSeleccionada.Id);
                    foreach (DataGridViewRow fila in dataGridView1.Rows)
                    {
                        string cantidad = fila.Cells[2].ToString();
                        string cat      = fila.Cells[1].ToString();
                    }
                }
            }
            if (osaSeleccionada.idpoliza > 0)
            {
                double tot = 0;
                foreach (DataGridViewRow fila in dataGridView1.Rows)
                {
                    if (fila.Cells[3].Value != null)
                    {
                        string cantidad = fila.Cells[3].Value.ToString();
                        catalogo = fila.Cells[1].Value.ToString();
                        item     = Convert.ToInt32(dataGridView1.Rows[fila.Index].Cells[0].Value);
                        i        = new osa_indiv(item, osaSeleccionada.Id);
                        p        = new productos(i.ID_PRODUCTO2);
                        tot     += Convert.ToInt32(cantidad) * p.PrecioAlmacen;
                    }
                }
                polizasdb pol = new polizasdb(osaSeleccionada.idpoliza);
                pol.subtotal = tot;
                pol.egreso   = tot;
                pol.Update("folio");
            }
        }
Exemplo n.º 3
0
        private void buttonIngresarHoja_Click_1(object sender, EventArgs e)
        {
            #region validaciones
            if (FACTURA.Text != "")
            {
                try
                {
                    Convert.ToInt32(FACTURA.Text);
                }
                catch
                {
                    MessageBox.Show("Solo numeros en la factura");
                    return;
                }
            }
            if (checkBoxPorProyecto.Checked == true)
            {
                if (proyectoSeleccionado == null)
                {
                    MessageBox.Show("Falta elegir el proyecto");
                    return;
                }
            }
            else
            {
                if (FACTURA.Text == "" && txtpo.Text == "" && COTIZACION.Text == "" && REMISION.Text == "")
                {
                    MessageBox.Show("Es necesario capturar un comprobante de salida");
                    return;
                }
            }
            if (FACTURA.Text != "" && txtpo.Text == "")
            {
                MessageBox.Show("Falta capturar la PO de la factura");
                return;
            }
            if (comboBoxClientes.SelectedIndex == -1 || comboVendedor.SelectedIndex == -1)
            {
                MessageBox.Show("Seleccione Cliente y Vendedor");
                return;
            }
            #endregion validaciones
            List <productos>        listaproductos   = new List <productos>();
            List <inventariocostos> listainventarios = new List <inventariocostos>();
            OSAGralSeleccionada.PARTIDAS2.Clear();
            if (AccesoInternet())
            {
                DataTable sal;
                sumatoria = 0;
                if (dataGridView2.RowCount > 0)
                {
                    for (int jj = 0; jj < dataGridView2.RowCount - 1; jj++)
                    {
                        string a = dataGridView2.Rows[jj].Cells[8].Value.ToString();
                        sal = productos.sumas(dataGridView2.Rows[jj].Cells[8].Value.ToString());
                        string w = dataGridView2.Rows[jj].Cells[4].Value.ToString();
                        sumatoria += Convert.ToDouble(sal.Rows[0][0]) * Convert.ToInt32(dataGridView2.Rows[jj].Cells[4].Value);
                    }
                }
                try
                {
                    /*
                     * OSA_GRAL OrdenSalida = new OSA_GRAL();
                     * OrdenSalida.Id = OrdenSalida.NextID();
                     * OrdenSalida.ID_CLIENTE = ClienteSeleccionado.ID;
                     * OrdenSalida.ID_VENDEDOR = EmpleadoSeleccionado.ID;
                     * OrdenSalida.FACTURA = FACTURA.Text;
                     * OrdenSalida.CODIGODEBARRAS = OrdenSalida.Id.ToString();
                     * OrdenSalida.FECHA = DateTime.Now.Date;
                     */
                    #region datos de salida general
                    if (checkBoxPorProyecto.Checked == true)
                    {
                        OSAGralSeleccionada.PROYECTO_ID = proyectoSeleccionado.ID;
                    }
                    OSAGralSeleccionada.ID_CLIENTE     = ClienteSeleccionado.ID;
                    OSAGralSeleccionada.ID_VENDEDOR    = EmpleadoSeleccionado.ID;
                    OSAGralSeleccionada.FACTURA        = FACTURA.Text;
                    OSAGralSeleccionada.TC             = Convert.ToDouble(textBoxTipoCambio.Text);
                    OSAGralSeleccionada.CODIGODEBARRAS = OSAGralSeleccionada.Id.ToString();
                    OSAGralSeleccionada.FECHA          = DateTime.Now.Date;
                    OSAGralSeleccionada.REMISION       = REMISION.Text;
                    OSAGralSeleccionada.COTIZACION     = COTIZACION.Text;
                    #endregion salida
                    if (PartidasOSA.Rows.Count > 0)
                    {
                        int item = 1;
                        #region validacion de productos
                        foreach (DataRow dr in PartidasOSA.Rows)
                        {
                            int       idproducto = Convert.ToInt32(dr["ID_PRODUCTO2"]);
                            productos stock      = new productos(idproducto);
                            if (stock.PrecioAlmacen == 0)
                            {
                                MessageBox.Show("El producto " + idproducto + " " + stock.DESCRIPCION + " No tiene PRECIO ACTUAL, favor de ingresarlo");
                                return;
                            }
                            osa_indiv PartidaIndividual = new osa_indiv();
                            PartidaIndividual.Id           = partidaId;
                            PartidaIndividual.ID_OSAGRAL   = OSAGralSeleccionada.Id;
                            PartidaIndividual.ITEM2        = item;
                            PartidaIndividual.ID_PRODUCTO2 = idproducto;
                            PartidaIndividual.QTY2         = Convert.ToInt32(dr["QTY2"]);
                            PartidaIndividual.VENTA        = Convert.ToInt32(dr["VENTA"]);
                            if (stock.PrecioAlmacen > 0)
                            {
                                PartidaIndividual.precioAlmacen = stock.PrecioAlmacen;
                                PartidaIndividual.totalItem     = stock.PrecioAlmacen * PartidaIndividual.QTY2;
                            }
                            stock.STOCK -= PartidaIndividual.QTY2;
                            if (stock.STOCK < 0)
                            {
                                MessageBox.Show("No hay suficientes " + dr["Catálogo"].ToString() + " en Stock");
                                return;
                            }
                        }
                        #endregion validacion
                        foreach (DataRow dr in PartidasOSA.Rows)
                        {
                            int       idproducto = Convert.ToInt32(dr["ID_PRODUCTO2"]);
                            productos stock      = new productos(idproducto);

                            /* if (stock.PrecioAlmacen == 0)
                             * {
                             *   MessageBox.Show("El producto " + idproducto + " " + stock.DESCRIPCION + " No tiene PRECIO ACTUAL, favor de ingresarlo");
                             *   return;
                             * }*/
                            #region guardar individual
                            osa_indiv PartidaIndividual = new osa_indiv();
                            PartidaIndividual.Id           = partidaId;
                            PartidaIndividual.ID_OSAGRAL   = OSAGralSeleccionada.Id;
                            PartidaIndividual.ITEM2        = item;
                            PartidaIndividual.ID_PRODUCTO2 = idproducto;
                            PartidaIndividual.QTY2         = Convert.ToInt32(dr["QTY2"]);
                            PartidaIndividual.VENTA        = Convert.ToInt32(dr["VENTA"]);
                            if (stock.PrecioAlmacen > 0)
                            {
                                PartidaIndividual.precioAlmacen = stock.PrecioAlmacen;
                                PartidaIndividual.totalItem     = stock.PrecioAlmacen * PartidaIndividual.QTY2;
                            }
                            #endregion individual
                            stock.STOCK -= PartidaIndividual.QTY2;//resta al stock

                            /*if (stock.STOCK < 0)
                             * {
                             *  MessageBox.Show("No hay suficientes " + dr["Catálogo"].ToString() + " en Stock");
                             *  return;
                             * }*/
                            listaproductos.Add(stock);
                            //stock.Update("Id");//actualiza datos del producto
                            MessageBox.Show(stock.CATALOGO + " nuevo stock " + stock.STOCK);
                            #region LOOP SALIDAS INVETNARIOCOSTOS
                            inventariocostos invCost = new inventariocostos(PartidaIndividual.ID_PRODUCTO2, "Salida");
                            if (invCost.Id > 0)
                            {
                                if (PartidaIndividual.QTY2 <= invCost.cantidad_actual) //si la cantidad de salida es menor o igual a la cantidad de inventario costos
                                {
                                    invCost.cantidad_actual -= PartidaIndividual.QTY2; //le resta la cantidad de salida a la de inventario costos
                                    listainventarios.Add(invCost);
                                    //invCost.Update("Id");//actualiza
                                }
                                else//si la cantidad de salida es mayor
                                {
                                    int Qty = PartidaIndividual.QTY2;
                                    Qty -= invCost.cantidad_actual;//a la cantidad de salida le resta la de inventarios
                                    invCost.cantidad_actual = 0;
                                    listainventarios.Add(invCost);
                                    //invCost.Update("Id");//actaliza
                                    while (Qty > 0)
                                    {
                                        inventariocostos invCost2 = new inventariocostos(PartidaIndividual.ID_PRODUCTO2, "Salida2");
                                        if (invCost2.Id > 0)
                                        {
                                            if (Qty <= invCost2.cantidad_actual) //si la cantidad de salida es menor o igual a la cantidad de inventario costos
                                            {
                                                invCost2.cantidad_actual -= Qty; //le resta la cantidad de salida a la de inventario costos
                                                listainventarios.Add(invCost2);
                                                //invCost2.Update("Id");
                                                Qty = 0;
                                            }
                                            else// si la cantidad de salida es mayor
                                            {
                                                Qty -= invCost2.cantidad_actual;
                                                invCost2.cantidad_actual = 0;
                                                listainventarios.Add(invCost2);
                                                //invCost2.Update("Id");
                                            }
                                        }
                                        else
                                        {
                                            // MessageBox.Show("No hay entradas registradas para esta salida");
                                            Qty = 0;
                                        }
                                    }
                                }
                            }

                            /* else
                             * {
                             *   // MessageBox.Show("Este producto no tiene Facturas de compra, Favor de ingresarlas antes de Sacar el Producto");
                             * }*/
                            #endregion LOOP SALIDAS INVETNARIOCOSTOS
                            OSAGralSeleccionada.PARTIDAS2.Add(PartidaIndividual);//agrga la individual
                            partidaId++;
                            item++;
                        }
                        SaveFileDialog save = new SaveFileDialog();
                        save.DefaultExt = "pdf";
                        save.Filter     = "PDF files|*.pdf";
                        if (save.ShowDialog() == DialogResult.OK)
                        {
                            string ruta = save.FileName;

                            CreatePDF(ruta);
                            System.Diagnostics.Process.Start(ruta);
                        }
                        DialogResult result = MessageBox.Show("DESEA GENERAR LA SALIDA CON LOS DATOS CAPTURADOS?", "REVISAR PDF ANTES DE GUARDAR", MessageBoxButtons.YesNo);
                        if (result == DialogResult.No)
                        {
                            return;
                        }
                        else if (result == DialogResult.Yes)
                        {
                            OSAGralSeleccionada.InsertarHoja();
                            string titulo = "OSA:" + textBoxOENid.Text + "\n\n";
                            foreach (productos prod in listaproductos)
                            {
                                titulo += prod.CATALOGO + "=" + prod.DESCRIPCION + ".\n\n";
                                prod.Update("Id");
                            }
                            foreach (inventariocostos inve in listainventarios)
                            {
                                inve.Update("Id");
                            }
                            if (!(Directory.Exists(Application.StartupPath + @"/OSA_RESPALDO/")))
                            {
                                Directory.CreateDirectory(Application.StartupPath + @"/OSA_RESPALDO/");
                            }
                            string ruta = Application.StartupPath + @"/OSA_RESPALDO/OSA_" + textBoxOENid.Text + ".pdf";
                            CreatePDF(ruta);
                            polizasdb crearpoliza = new polizasdb();
                            crearpoliza.Insertarpoliza(this, titulo);//////////////////////////////////////poliza

                            MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();

                            sb.Server   = "secure199.inmotionhosting.com";
                            sb.UserID   = "abdsto5_felipe";
                            sb.Password = "******";
                            sb.Database = "abdsto5_cotizaciones";


                            //PRUEBAS EN LOCALHOST

                            /*
                             * sb.Server = "localhost";
                             * sb.UserID = "felipe";
                             * sb.Password = "******";
                             * sb.Database = "ejemplo";
                             */
                            bdMysql = new DataBase();
                            bdMysql.DataBaseProvider = TypeOfDataBase.MySqlServer;
                            bdMysql.ConnectionString = sb.ToString();
                            //   bdMysql.ConnectionString = "Server = localhost; Database = descobi; Uid = felipe; Pwd = 1945Inadescobi";
                            bdMysql.CreateConnection();
                            DbObject.DefaultDataBaseObject = bdMysql;

                            resetOSA();//reset
                        }
                    }
                    else
                    {
                        MessageBox.Show("No hay partidas para guardar");
                    }
                }
                catch
                {
                    MessageBox.Show("Ingrese los datos correctos");
                }
            }
            else
            {
                MessageBox.Show("NO HAY INTERNET INTENTELO EN UN MOMENTO");//10000
            }
        }