Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (cbOficinas.Text == "")
            {
                MessageBox.Show("Seleccione una sucursal", "Sucursal", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cbOficinas.Focus();
            }
            else
            {
                if (recuperado == false)
                {
                    Models.Transfers transferencia = new Models.Transfers();
                    using (transferencia)
                    {
                        transferencia.Folio        = Convert.ToInt16(txtFolios.Text);
                        transferencia.Tipo_trapaso = "E";
                        transferencia.Sucursal     = cbOficinas.SelectedValue.ToString();
                        transferencia.Subtotal     = Convert.ToDouble(txtSubtotal.Text);
                        transferencia.Iva          = 0;
                        transferencia.Total        = 0;
                        transferencia.Facturado    = Convert.ToInt16(false);
                        transferencia.CreateTransfer();
                        List <Models.Transfers> ultimo = transferencia.getTransferbyfolio(Convert.ToInt16(txtFolios.Text), "E");

                        Models.Det_transfers detalles = new Models.Det_transfers();
                        using (detalles)
                        {
                            detalles.Folio = Convert.ToInt16(txtFolios.Text);
                            detalles.Tipo  = "E";

                            Models.Product poductos = new Models.Product();
                            foreach (DataGridViewRow row in dtProductos.Rows)
                            {
                                detalles.Cantidad    = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                                detalles.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString());
                                detalles.Precio      = Convert.ToDouble(row.Cells["p_u"].Value.ToString());
                                detalles.CreateDet();
                                using (poductos)
                                {
                                    List <Models.Product> producto = poductos.getProductById(Convert.ToInt16(row.Cells["id"].Value.ToString()));
                                    Models.Kardex         kardex   = new Models.Kardex();
                                    using (kardex)
                                    {
                                        kardex.Id_producto  = Convert.ToInt16(row.Cells["id"].Value.ToString());
                                        kardex.Tipo         = "T";
                                        kardex.Id_documento = ultimo[0].Id;
                                        kardex.Cantidad     = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                                        kardex.Antes        = producto[0].Existencia;
                                        kardex.CreateKardex();

                                        List <Models.Kardex> ultimo_kardez = kardex.getidKardex(Convert.ToInt16(row.Cells["id"].Value.ToString()), ultimo[0].Id, "T");
                                        Models.Afecta_inv    afecta        = new Models.Afecta_inv();
                                        using (afecta)
                                        {
                                            afecta.Disminuye(ultimo_kardez[0].Id);
                                        }
                                    }
                                }
                            }
                        }
                    }


                    Models.Folios folio = new Models.Folios();
                    using (folio)
                    {
                        folio.Transferencia = (Convert.ToInt16(txtFolios.Text) + 1);
                        folio.savenewTransfer();
                    }
                }
                else
                {
                    Models.Transfers transferencia = new Models.Transfers();
                    using (transferencia)
                    {
                        transferencia.Folio        = Convert.ToInt32(txtFolios.Text);
                        transferencia.Tipo_trapaso = "E";
                        transferencia.Sucursal     = cbOficinas.SelectedValue.ToString();
                        transferencia.Subtotal     = Convert.ToDouble(txtSubtotal.Text);
                        transferencia.Iva          = 0;
                        transferencia.Total        = 0;
                        transferencia.Facturado    = Convert.ToInt16(false);
                        transferencia.updateTrasfer();
                    }
                    Models.Det_transfers detalles = new Models.Det_transfers();
                    using (detalles)
                    {
                        detalles.Folio = Convert.ToInt32(txtFolios.Text);
                        detalles.delete_det();

                        detalles.Folio = Convert.ToInt16(txtFolios.Text);
                        detalles.Tipo  = "E";

                        Models.Product poductos = new Models.Product();
                        foreach (DataGridViewRow row in dtProductos.Rows)
                        {
                            detalles.Cantidad    = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                            detalles.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString());
                            detalles.Precio      = Convert.ToDouble(row.Cells["p_u"].Value.ToString());
                            detalles.CreateDet();
                            using (poductos)
                            {
                                List <Models.Product> producto = poductos.getProductById(Convert.ToInt16(row.Cells["id"].Value.ToString()));
                                Models.Kardex         kardex   = new Models.Kardex();
                                using (kardex)
                                {
                                    kardex.Id_producto  = Convert.ToInt16(row.Cells["id"].Value.ToString());
                                    kardex.Tipo         = "T";
                                    kardex.Id_documento = id_transfer;
                                    kardex.Cantidad     = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                                    kardex.Antes        = producto[0].Existencia;
                                    kardex.CreateKardex();

                                    List <Models.Kardex> ultimo_kardez = kardex.getidKardex(Convert.ToInt16(row.Cells["id"].Value.ToString()), id_transfer, "T");
                                    Models.Afecta_inv    afecta        = new Models.Afecta_inv();
                                    using (afecta)
                                    {
                                        afecta.Disminuye(ultimo_kardez[0].Id);
                                    }
                                }
                            }
                        }
                    }
                }


                Models.Configuration configuracion = new Models.Configuration();
                int cuantos   = dtProductos.RowCount;
                int faltantes = 0;
                int valor;


                using (configuracion)
                {
                    faltantes = cuantos - 1;

                    valor = 110 * faltantes;

                    valor = valor + 1150;
                    PaperSize ps = new PaperSize("Custom", 300, valor);
                    List <Models.Configuration> config = configuracion.getConfiguration();

                    printDocument1.DefaultPageSettings.PaperSize = ps;
                    printDocument1.PrinterSettings.PrinterName   = config[0].Impresora;
                    printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);

                    printDocument1.Print();
                }


                this.Close();
            }
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Models.Inv_out salida = new Models.Inv_out(
                Convert.ToInt16(folio),
                dtFecha.Text + " 00:00:00",
                "",
                Convert.ToDouble(txtTotal.Text),
                "A"
                );

            Models.Det_salidas det      = new Models.Det_salidas();
            Models.Kardex      kardex   = new Models.Kardex();
            Models.Product     producto = new Models.Product();
            Models.Afecta_inv  afecta   = new Models.Afecta_inv();
            int nuevo = 0;

            det.Id = 0;

            if (folio == "0")
            {
                using (salida)
                {
                    salida.createInv_out();
                    List <Models.Inv_out> result = salida.getListabyAll(dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text));
                    folio = result[0].Id.ToString();

                    det.Id_salida = Convert.ToInt16(folio);
                    foreach (DataGridViewRow row in dtProductos.Rows)
                    {
                        det.Cantidad    = Convert.ToInt16(row.Cells["cantidad"].Value.ToString());
                        det.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString());
                        det.P_u         = Convert.ToDouble(row.Cells["p_u"].Value.ToString());
                        det.Total       = Convert.ToDouble(row.Cells["total"].Value.ToString());
                        using (det)
                        {
                            det.craeteDet_salida();
                            using (producto)
                            {
                                List <Models.Product> prod = producto.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString()));
                                nuevo = Convert.ToInt16(row.Cells["cantidad"].Value.ToString());
                                while (prod[0].Parent != "0")
                                {
                                    nuevo = nuevo * Convert.ToInt16(prod[0].C_unidad);
                                    prod  = producto.getProductById(Convert.ToInt16(prod[0].Parent));
                                }
                                kardex.Fecha        = Convert.ToDateTime(dtFecha.Text).ToString();
                                kardex.Id_producto  = prod[0].Id;
                                kardex.Tipo         = "S";
                                kardex.Cantidad     = nuevo;
                                kardex.Antes        = prod[0].Existencia;
                                kardex.Id           = 0;
                                kardex.Id_documento = Convert.ToInt16(folio);
                                using (kardex)
                                {
                                    kardex.CreateKardex();
                                    List <Models.Kardex> numeracion = kardex.getidKardex(prod[0].Id, Convert.ToInt16(folio), "S");
                                    using (afecta)
                                    {
                                        afecta.Disminuye(numeracion[0].Id);
                                    }
                                }
                            }
                        }
                    }
                }
            }


            this.Close();
        }