private void InsertaPartida()
        {
            if (producto == null && TxtProductoId.Text.Trim().Length == 0)
            {
                Ambiente.Mensaje("Producto no encontrado");
                return;
            }

            producto = productoController.SelectOne(TxtProductoId.Text.Trim());
            if (producto == null)
            {
                return;
            }

            try
            {
                if ((bool)producto.Ocupado)
                {
                    Ambiente.Mensaje("Operación abortada, el articulo está bloqueado por otro proceso [INVENTARIOS, AJUSTES, AUTORIZACIONES, ETC]");
                    return;
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }


            if (traspaso != null)
            {
                if (traspaso.TraspasoId == 0)
                {
                    Ambiente.Mensaje("El traspaso no existe");
                    return;
                }
            }

            var partida = new Traspasop();

            partida.TraspasoId  = traspaso.TraspasoId;
            partida.ProductoId  = producto.ProductoId;
            partida.Descripcion = producto.Descripcion;
            partida.Cantidad    = NCantidad.Value;
            partida.Stock       = producto.Stock;
            partida.Precio      = producto.Precio1;
            partida.ImpuestoId1 = producto.Impuesto1Id;
            partida.ImpuestoId2 = producto.Impuesto2Id;
            partida.Impuesto1   = Ambiente.GetTasaImpuesto(partida.ImpuestoId1);
            partida.Impuesto2   = Ambiente.GetTasaImpuesto(partida.ImpuestoId2);
            //Totales de la partida
            partida.Subtotal         = partida.Cantidad * partida.Precio;
            partida.ImporteImpuesto1 = partida.Subtotal * partida.Impuesto1;
            partida.ImporteImpuesto2 = partida.Subtotal * partida.Impuesto2;
            partida.Total            = partida.Subtotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;


            if (lote != null)
            {
                if (lote.StockRestante >= partida.Cantidad)
                {
                    partida.LoteId    = lote.LoteId;
                    partida.NoLote    = lote.NoLote;
                    partida.Caducidad = lote.Caducidad;
                }
                else
                {
                    Ambiente.Mensaje("Proceso abortado, el lote seleccionado no tiene suficiente stock.");
                    return;
                }
            }
            else
            {
                partida.LoteId    = null;
                partida.NoLote    = null;
                partida.Caducidad = null;
            }



            //partida al grid
            Malla.Rows[SigPartida].Cells[0].Value = partida.Descripcion;
            Malla.Rows[SigPartida].Cells[1].Value = partida.Stock;
            Malla.Rows[SigPartida].Cells[2].Value = partida.Cantidad;
            Malla.Rows[SigPartida].Cells[3].Value = partida.Precio;
            Malla.Rows[SigPartida].Cells[4].Value = partida.Impuesto1;
            Malla.Rows[SigPartida].Cells[5].Value = partida.Impuesto2;
            Malla.Rows[SigPartida].Cells[6].Value = partida.Subtotal;
            Malla.Rows[SigPartida].Cells[7].Value = partida.Subtotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
            Malla.Rows[SigPartida].Cells[8].Value = partida.NoLote;
            Malla.Rows[SigPartida].Cells[9].Value = partida.Caducidad;
            partidas.Add(partida);
            ResetPartida();
            CalculaTotales();
        }
Beispiel #2
0
        private void InsertaPartida()
        {
            if (producto == null && TxtProducto.Text.Trim().Length == 0)
            {
                Ambiente.Mensaje("Producto no encontrado");
                return;
            }

            producto = productoController.SelectOne(TxtProducto.Text.Trim());


            if (producto == null)
            {
                return;
            }
            try
            {
                if ((bool)producto.Ocupado)
                {
                    Ambiente.Mensaje("Operación abortada, el articulo está bloqueado por otro proceso [INVENTARIOS, AJUSTES, AUTORIZACIONES, ETC]");
                    return;
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }

            if (conceptoMovInv == null)
            {
                return;
            }



            var partida = new Devolucionp();


            if (producto.TieneLote && conceptoMovInv.Es.Equals("E"))
            {
                using (var form = new FrmLoteCaducidad(0, NCantidad.Value, producto.ProductoId, devolucion.DevolucionId, conceptoMovInv.ConceptoMovInvId))
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        partida.LoteId    = form.lotes[0].LoteId;
                        partida.NoLote    = form.lotes[0].NoLote;
                        partida.Caducidad = form.lotes[0].Caducidad;
                    }
                    else
                    {
                        partida.LoteId    = null;
                        partida.NoLote    = null;
                        partida.Caducidad = null;
                    }
                }
                BtnAceptar.Focus();
            }

            if (producto.TieneLote && conceptoMovInv.Es.Equals("S"))
            {
                producto.Lote = new List <Lote>();
                if (lote == null)
                {
                    Ambiente.Mensaje("Seleccione el lote del articulo");
                    return;
                }
                else
                {
                    producto.Lote.Add(lote);
                    partida.LoteId    = lote.LoteId;
                    partida.NoLote    = lote.NoLote;
                    partida.Caducidad = lote.Caducidad;
                }
            }

            //control lotes



            partida.DevolucionId = devolucion.DevolucionId;
            partida.ProductoId   = producto.ProductoId;
            partida.Descripcion  = producto.Descripcion;
            partida.Cantidad     = (int)NCantidad.Value;
            partida.Stock        = (int)producto.Stock;
            partida.PrecioCompra = producto.PrecioCompra;
            partida.ImpuestoId1  = producto.Impuesto1Id;
            partida.ImpuestoId2  = producto.Impuesto2Id;
            partida.Impuesto1    = Ambiente.GetTasaImpuesto(partida.ImpuestoId1);
            partida.Impuesto2    = Ambiente.GetTasaImpuesto(partida.ImpuestoId2);
            //Totales de la partida
            partida.Subtotal         = partida.Cantidad * partida.PrecioCompra;
            partida.ImporteImpuesto1 = partida.Subtotal * partida.Impuesto1;
            partida.ImporteImpuesto2 = partida.Subtotal * partida.Impuesto2;
            partida.Total            = partida.Subtotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;



            //partida al grid
            Malla.Rows.Add();
            Malla.Rows[Malla.RowCount - 1].Cells[0].Value = partida.Descripcion;
            Malla.Rows[Malla.RowCount - 1].Cells[1].Value = partida.Stock;
            Malla.Rows[Malla.RowCount - 1].Cells[2].Value = partida.Cantidad;
            Malla.Rows[Malla.RowCount - 1].Cells[3].Value = partida.PrecioCompra;
            Malla.Rows[Malla.RowCount - 1].Cells[4].Value = partida.Impuesto1;
            Malla.Rows[Malla.RowCount - 1].Cells[5].Value = partida.Impuesto2;
            Malla.Rows[Malla.RowCount - 1].Cells[6].Value = partida.Subtotal;
            Malla.Rows[Malla.RowCount - 1].Cells[7].Value = partida.Subtotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
            Malla.Rows[Malla.RowCount - 1].Cells[8].Value = partida.NoLote;
            Malla.Rows[Malla.RowCount - 1].Cells[9].Value = partida.Caducidad;
            partidas.Add(partida);
            ResetPartida();
            CalculaTotales();
        }
        private void InsertaPartida()
        {
            if (producto == null && TxtProductoId.Text.Trim().Length == 0)
            {
                Ambiente.Mensaje("Producto no encontrado");
                return;
            }

            producto = productoController.SelectOne(TxtProductoId.Text.Trim());
            if (producto == null)
            {
                return;
            }

            if (venta.VentaId <= 0)
            {
                Ambiente.Mensaje("La venta no existe");
                return;
            }

            try
            {
                if ((bool)producto.Ocupado)
                {
                    Ambiente.Mensaje("Operación abortada, el articulo está bloqueado por otro proceso [INVENTARIOS, AJUSTES, AUTORIZACIONES, ETC]");
                    return;
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }

            //partida a la lista
            var partida = new Ventap();

            partida.VentaId     = venta.VentaId;
            partida.ProductoId  = producto.ProductoId;
            partida.Descripcion = producto.Descripcion;
            partida.Descuento   = 0;

            if (Ambiente.Estacion.VenderSinStock)
            {
                partida.Cantidad = 1;
            }
            else
            {
                if (HayStockSuficiente(producto, 1))
                {
                    partida.Cantidad = 1;
                }
                else
                {
                    Ambiente.Mensaje("Stock insuficiente");
                    return;
                }
            }


            partida.Precio = SeleccionaPrecio(producto, cliente);
            if (partida.Precio == 0)
            {
                Ambiente.Mensaje("Proceso abortado, el precio del artículo no puede ser cero.  \n ARTÍCULO: " + producto.ProductoId + " Verifique los precios del artículo y el precio asignado al cliente");
                return;
            }
            partida.Impuesto1 = Ambiente.GetTasaImpuesto(producto.Impuesto1Id);
            partida.Impuesto2 = Ambiente.GetTasaImpuesto(producto.Impuesto2Id);

            if (producto.TieneLote)
            {
                lote = loteController.GetLoteDisponibilidad(producto.ProductoId, 1);
                if (lote != null)
                {
                    partida.LoteId    = lote.LoteId;
                    partida.NoLote    = lote.NoLote;
                    partida.Caducidad = lote.Caducidad;
                }
                else
                {
                    Ambiente.Mensaje("Este artículo tiene control de lote, pero no hay lotes registrados. No se imprimirá el lote del artículo");
                }
            }
            else
            {
                partida.LoteId    = null;
                partida.NoLote    = null;
                partida.Caducidad = null;
            }
            partida.Costo            = producto.PrecioCompra;
            partida.PrecioCaja       = producto.PrecioCaja;
            partida.ClaveProdServ    = producto.ClaveProdServId.Trim().Length == 0 ? "01010101" : producto.ClaveProdServId.Trim();
            partida.ClaveUnidad      = producto.ClaveUnidadId.Trim().Length == 0 ? "H87" : producto.ClaveUnidadId.Trim();
            partida.Unidad           = producto.UnidadMedidaId.Trim().Length == 0 ? "SYS" : producto.UnidadMedidaId.Trim();
            partida.ClaveImpuesto1   = SeleccionaClaveImpuesto(producto, 1);
            partida.ClaveImpuesto2   = SeleccionaClaveImpuesto(producto, 2);
            partida.TasaOcuota1      = "Tasa";
            partida.TasaOcuota2      = "Tasa";
            partida.SubTotal         = partida.Cantidad * partida.Precio;
            partida.ImporteImpuesto1 = partida.SubTotal * partida.Impuesto1;
            partida.ImporteImpuesto2 = partida.SubTotal * partida.Impuesto2;
            partida.Total            = partida.SubTotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
            partidas.Add(partida);

            //Calcular totales de partidas y venta();
            CalculaTotales();

            // partida al grid
            Malla.Rows[SigPartida].Cells[0].Value = partida.Descripcion;
            Malla.Rows[SigPartida].Cells[1].Value = producto.Stock;
            Malla.Rows[SigPartida].Cells[2].Value = partida.Cantidad;
            Malla.Rows[SigPartida].Cells[3].Value = Math.Round(partida.Precio, 2);
            Malla.Rows[SigPartida].Cells[4].Value = partida.SubTotal;
            Malla.Rows[SigPartida].Cells[5].Value = partida.Impuesto1;
            Malla.Rows[SigPartida].Cells[6].Value = partida.Impuesto2;
            Malla.Rows[SigPartida].Cells[7].Value = partida.Total;
            Malla.Rows[SigPartida].Cells[8].Value = partida.NoLote;
            Malla.Rows[SigPartida].Cells[9].Value = partida.ProductoId;
            //Scroll to the last row.
            if (SigPartida > 10)
            {
                Malla.FirstDisplayedScrollingRowIndex = SigPartida - 10;
                Malla.Rows[SigPartida].Selected       = true;
            }



            ResetPartida();
        }
Beispiel #4
0
        internal static void VentasAcosto(DateTime inicial, DateTime final, bool todasLasFechas)
        {
            report = new StiReport();


            List <Producto> productos;
            List <Ventap>   partidas;

            using (var db = new DymContext())
            {
                if (todasLasFechas)
                {
                    var q = from v in db.Venta
                            join vp in db.Ventap on v.VentaId equals vp.VentaId
                            where (v.Anulada == false && !v.EstadoDocId.Equals("PEN"))
                            select vp;
                    partidas  = q.ToList();
                    productos = db.Producto.ToList();
                }
                else
                {
                    var q = from v in db.Venta
                            join vp in db.Ventap on v.VentaId equals vp.VentaId
                            where (v.Anulada == false && !v.EstadoDocId.Equals("PEN") && v.CreatedAt.Date >= inicial.Date && v.CreatedAt.Date <= final.Date)
                            select vp;
                    partidas  = q.ToList();
                    productos = db.Producto.ToList();
                }
            }
            decimal subtotalvp = 0, impuestovp = 0, totalvp = 0;
            decimal subtotalcp = 0, impuestocp = 0, totalcp = 0;

            decimal subtotalvt = 0, impuestovt = 0, totalvt = 0;
            decimal subtotalct = 0, impuestoct = 0, totalct = 0;

            foreach (var p in partidas)
            {
                var prod = productoController.SelectOne(p.ProductoId.Trim());

                //Importe parcial venta
                subtotalvp = p.SubTotal;
                impuestovp = p.ImporteImpuesto1 + p.ImporteImpuesto2;
                totalvp    = subtotalvp + impuestovp;

                //Importe pacial costo
                impuestocp  = 0;
                subtotalcp  = p.Cantidad * prod.PrecioCompra;
                impuestocp  = subtotalcp * Ambiente.GetTasaImpuesto(prod.Impuesto1Id);
                impuestocp += subtotalcp * Ambiente.GetTasaImpuesto(prod.Impuesto2Id);
                totalcp     = subtotalcp + impuestocp;

                //Sumar totales

                subtotalvt += subtotalvp;
                impuestovt += impuestovp;
                totalvt    += totalvp;

                subtotalct += subtotalcp;
                impuestoct += impuestocp;
                totalct    += totalcp;
            }

            report.Load(@"C:\Dympos\Formatos\VentasAcosto.mrt");
            report.Compile();
            report["creador"]  = Ambiente.LoggedUser.UsuarioId;
            report["subv"]     = subtotalvt;
            report["impv"]     = impuestovt;
            report["totv"]     = totalvt;
            report["subc"]     = subtotalct;
            report["impc"]     = impuestoct;
            report["totc"]     = totalct;
            report["utilidad"] = totalvt - totalct;
            if (todasLasFechas)
            {
                report["inicial"] = null;
                //report["final"] = null;
            }
            else
            {
                report["inicial"] = inicial.ToString("dd-MM-yyyy");
                report["final"]   = final.ToString("dd-MM-yyyy");
            }

            report.Show();
        }
        private void CalculaTotales()
        {
            venta.Unidades = 0;
            venta.SubTotal = 0;
            venta.Impuesto = 0;
            venta.Total    = 0;
            int index = 0;

            if (partidas.Count == 0)
            {
                //Reflear totales en el PDV
                TxtSubtotal.Text = Ambiente.FDinero(0.ToString());
                TxtTotal.Text    = Ambiente.FDinero(0.ToString());
                return;
            }
            foreach (var partida in partidas)
            {
                //partida.Cantidad = 1; actualizado desde el grid o incrementos rapidos
                //Calcular el total por partida
                producto = productoController.SelectOne(partida.ProductoId);

                partida.Precio    = SeleccionaPrecio(producto, cliente);
                partida.Impuesto1 = Ambiente.GetTasaImpuesto(producto.Impuesto1Id);
                partida.Impuesto2 = Ambiente.GetTasaImpuesto(producto.Impuesto2Id);
                //if (producto.TieneLote)
                //{
                //    //partida.LoteId = loteController.TraeDatosLote(producto, partida.Cantidad).Item1;
                //    //partida.Caducidad = loteController.TraeDatosLote(producto, partida.Cantidad).Item2;
                //}
                partida.SubTotal         = partida.Cantidad * partida.Precio;
                partida.ImporteImpuesto1 = partida.SubTotal * partida.Impuesto1;
                partida.ImporteImpuesto2 = partida.SubTotal * partida.Impuesto2;
                partida.Total            = partida.SubTotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;

                //sumar unidades

                venta.Unidades += partida.Cantidad;
                if (Ambiente.Estacion.SumarUnidadesPdv)
                {
                    LblUnidades.Visible = true;
                    LblUnidades.Text    = venta.Unidades + " Unidades";
                }
                else
                {
                    LblUnidades.Visible = false;
                }

                //sumar el total por partida a los totales de la venta
                venta.SubTotal += partida.SubTotal;
                venta.Impuesto += partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
                venta.Total     = venta.SubTotal + venta.Impuesto;

                //Refleajar el cambio  de precio y columnas calculadas en la malla
                Malla.Rows[index].Cells[0].Value = partida.Descripcion;
                Malla.Rows[index].Cells[1].Value = producto.Stock;
                Malla.Rows[index].Cells[2].Value = partida.Cantidad;
                Malla.Rows[index].Cells[3].Value = Math.Round(partida.Precio, 2);
                Malla.Rows[index].Cells[4].Value = partida.SubTotal;
                Malla.Rows[index].Cells[5].Value = partida.Impuesto1;
                Malla.Rows[index].Cells[6].Value = partida.Impuesto2;
                Malla.Rows[index].Cells[7].Value = partida.Total;
                Malla.Rows[index].Cells[8].Value = partida.NoLote;
                Malla.Rows[index].Cells[9].Value = partida.ProductoId;


                //Reflear totales en el PDV
                TxtSubtotal.Text = Ambiente.FDinero(venta.SubTotal.ToString());
                TxtTotal.Text    = Ambiente.FDinero(venta.Total.ToString());

                index++;
            }
        }