private void Iniciza() { cierreInventarioController = new CierreInventarioController(); cierreInventariopController = new CierreInventariopController(); informeController = new InformeController(); cierreInventario = null; cierreInventariop = null; CargaMalla(); }
public bool InsertOne(CierreInventario o) { try { using (var db = new DymContext()) { db.Add(o); return(db.SaveChanges() > 0 ? true : false); } } catch (Exception ex) { Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString()); } return(false); }
public bool Update(CierreInventario o) { try { using (var db = new DymContext()) { db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified; return(db.SaveChanges() > 0 ? true : false); } } catch (Exception ex) { Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString()); } return(false); }
public bool DeletePartidas(CierreInventario o) { try { using (var db = new DymContext()) { var partidas = db.CierreInventariop.Where(x => x.CierreInventarioId == o.CierreInventarioId).ToList(); if (partidas != null) { db.RemoveRange(partidas); db.SaveChanges(); return(true); } } } catch (Exception ex) { Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString()); } return(false); }
private void Agregar() { if (Ambiente.Pregunta("REALMENTE NO ES NECESARIO CREAR CIERRES MANUALES. \n El sistema generá automaticamente los cambios y arranques de periodos automaticamente. \n CREAR DE TODAS FORMAS")) { if (Ambiente.Pregunta("Aseguresé que conoce las implicaciones de generar periodos manualmente. CONTINUAR")) { cierreInventario = new CierreInventario(); cierreInventario.FechaInicial = DpFinicial.Value; cierreInventario.FechaFinal = DpFinicial.Value; cierreInventario.FechaProgramacion = DpFechaEjecucion.Value; cierreInventario.Etapa1Generada = false; cierreInventario.Etapa2Generada = false; cierreInventario.CreatedAt = DateTime.Now; cierreInventario.CreatedBy = Ambiente.LoggedUser.UsuarioId; if (cierreInventarioController.InsertOne(cierreInventario)) { Ambiente.Mensaje("Proceso completado"); } } } }
private void GenerarAnioCompleto() { var mactual = DateTime.Now.ToString("MMMM").ToUpper(); var mfinal = (DateTime.Now.AddMonths(12 - DateTime.Now.Month)).ToString("MMMM").ToUpper(); if (Ambiente.Pregunta("Se generarán los cierres de inventarios de " + mactual + " hasta " + mfinal)) { for (int i = DateTime.Now.Month; i <= DateTime.Now.AddMonths(12 - DateTime.Now.Month).Month; i++) { cierreInventario = new CierreInventario(); cierreInventario.FechaInicial = new DateTime(DateTime.Now.Year, i, 1); cierreInventario.FechaFinal = cierreInventario.FechaInicial.AddMonths(1).AddDays(-1); cierreInventario.FechaProgramacion = cierreInventario.FechaFinal.AddDays(1); cierreInventario.Etapa1Generada = false; cierreInventario.Etapa2Generada = false; cierreInventario.CreatedAt = DateTime.Now; cierreInventario.CreatedBy = Ambiente.LoggedUser.UsuarioId; cierreInventario.EstacionId = Ambiente.Estacion.EstacionId; cierreInventarioController.InsertOne(cierreInventario); } CargaMalla(); Ambiente.Mensaje("Proceso concluido"); } }
private void Initialize() { //Controllers productoSustanciaController = new ProductoSustanciaController(); cierreInventariopController = new CierreInventariopController(); productoImpuestoController = new ProductoImpuestoController(); cierreInventarioController = new CierreInventarioController(); migrationTableController = new MigrationTableController(); migrationFieldController = new MigrationFieldController(); presentacionController = new PresentacionController(); laboratorioController = new LaboratorioController(); categoriaController = new CategoriaController(); sustanciaController = new SustanciaController(); productoController = new ProductoController(); loteController = new LoteController(); movInvController = new MovInvController(); //Objetos productoSustancia = null; productoImpuesto = null; cierreInventario = null; cierreInventariop = null; migrationTable = null; migrationField = null; presentacion = null; laboratorio = null; categoria = null; sustancia = null; producto = null; lote = null; //Listas productoSustancias = new List <ProductoSustancia>(); productoImpuestos = new List <ProductoImpuesto>(); migrationTables = new List <MigrationTable>(); migrationFields = new List <MigrationField>(); presentaciones = new List <Presentacion>(); laboratorios = new List <Laboratorio>(); categorias = new List <Categoria>(); sustancias = new List <Sustancia>(); productos = new List <Producto>(); lotes = new List <Lote>(); try { //Conexion vfpro Sql = ""; dataTable = new DataTable(); connectionstring = "Provider=VFPOLEDB.1;Data Source=" + Ambiente.Empresa.MicroPvdb + ";"; oleDbConnection = new OleDbConnection(connectionstring); oleDbConnection.Open(); //Llena combo tablas migrationTables = migrationTableController.SelectAll(); CboTabla.DataSource = migrationTables; CboTabla.DisplayMember = "Tabla"; CboTabla.ValueMember = "MigrationTableId"; CboTabla.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Sincronizaprodsalma() { try { migrationTable = migrationTableController.SelectOne(11); migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId); Sql = "SELECT "; foreach (var f in migrationFields) { if (migrationFields.Last() == f) { Sql += f.Expresion + " FROM " + migrationTable.Tabla; } else { Sql += f.Expresion + " , "; } } Sql += " " + migrationTable.Condicion; GetDataTable(Sql); productos = productoController.SelectAll(); decimal i = 0; int I = 0; Ambiente.S20 = "AJUSTADO X SINCRONIZACION \n"; cierreInventario = new CierreInventario(); cierreInventario.FechaInicial = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); cierreInventario.FechaFinal = cierreInventario.FechaInicial.AddMonths(1).AddDays(-1); cierreInventario.FechaProgramacion = cierreInventario.FechaFinal.AddDays(1); cierreInventario.Etapa1Generada = true; cierreInventario.Etapa2Generada = false; cierreInventario.CreatedAt = DateTime.Now; cierreInventario.CreatedBy = Ambiente.LoggedUser.UsuarioId; cierreInventario.EstacionId = Ambiente.Estacion.EstacionId; cierreInventarioController.InsertOne(cierreInventario); foreach (DataRow row in dataTable.Rows) { Ambiente.S1 = row["producto"].ToString().Trim().ToUpper(); Ambiente.Decimal1 = decimal.TryParse(row["existenc"].ToString().Trim(), out i) == true ? i : 0; Ambiente.Int1 = int.TryParse(row["min"].ToString().Trim(), out I) == true ? I : 0; Ambiente.Int2 = int.TryParse(row["max"].ToString().Trim(), out I) == true ? I : 0; producto = productos.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1)); if (producto != null) { producto.Stock = Ambiente.Decimal1; producto.Min = Ambiente.Int1; producto.Max = Ambiente.Int2; producto.ValorStock = producto.Costopp * producto.Stock; //**********Cierre inventariop****************// cierreInventariop = new CierreInventariop(); cierreInventariop.CierreInventarioId = cierreInventario.CierreInventarioId; cierreInventariop.ProductoId = producto.ProductoId; cierreInventariop.Descripcion = producto.Descripcion; cierreInventariop.InvInicial = producto.Stock; cierreInventariop.Entradas = 0; cierreInventariop.Salidas = 0; cierreInventariop.UltimoCosto = producto.UltimoCosto; cierreInventariop.PrevioVta = producto.Precio1; cierreInventariop.ValorCosto = 0; cierreInventariop.ValorVenta = 0; cierreInventariopController.InsertOne(cierreInventariop); if (producto.TieneLote) { var lotes = loteController.SelecByProducConRestanteCeros(producto); Ambiente.Decimal6 = 0; if (lotes != null) { if (lotes.Count > 0) { Ambiente.Decimal6 = Ambiente.Decimal1 / lotes.Count; foreach (var l in lotes) { l.StockInicial = Ambiente.Decimal6; l.StockRestante = Ambiente.Decimal6; loteController.Update(l); } } else { var l = new Lote(); l.CompraId = 0; l.NoLote = "L0001"; l.ProductoId = producto.ProductoId; l.StockInicial = producto.Stock; l.StockRestante = producto.Stock; l.Caducidad = DateTime.Now.AddDays(365); l.CreatedBy = Ambiente.LoggedUser.UsuarioId; l.CreatedAt = DateTime.Now; l.ReferenciaInt = 0; l.ReferenciaString = "AJUSTADO X SINCRONIZACION"; loteController.InsertOne(l); Ambiente.S20 += " PRODUCTOID: " + producto.ProductoId + " STOCK: " + producto.Stock + " CONTROL_LOTE: TRUE LOTES ENCONTRADOS: " + lotes.Count + "\n"; } } } //**************MOVIMIENTO DE INVENTARIO****************// var movInv = new MovInv(); movInv.FechaOperacion = DateTime.Now; movInv.ConceptoMovsInvId = "IIN"; movInv.ProductoId = producto.ProductoId; movInv.CreatedBy = Ambiente.LoggedUser.UsuarioId; movInv.ProveedorId = ""; movInv.ClienteId = ""; movInv.EstacionId = Ambiente.Estacion.EstacionId; movInv.ReferenciaId = 0; movInv.ReferenciapId = 0; movInv.Es = "E"; movInv.Cantidad = producto.Stock; movInv.UltimoCosto = producto.UltimoCosto; movInv.Costopp = producto.Costopp; movInv.Valor = producto.Stock * producto.UltimoCosto; movInv.StockAlMomento = 0; movInv.PrecioVta = producto.Precio1; movInv.Afectacion = movInv.Es.Equals("E") ? 1 : -1; movInv.IsDeleted = false; movInv.TieneLote = false; movInv.NoLote = ""; movInv.Caducidad = DateTime.Now; movInv.CreatedAt = DateTime.Now; movInvController.InsertOne(movInv); productoController.Update(producto); } else { Ambiente.S2 += " NO EXISTE " + Ambiente.S1 + " \n"; } } Ambiente.Mensaje("Proceso concluido"); if (Ambiente.S20.Length > 30) { Ambiente.Mensaje(Ambiente.S20); } } catch (Exception ex) { Ambiente.Mensaje(ex.ToString()); } }
public static void ActualizaCierresInventario() { try { using (var db = new DymContext()) { var cpendientes1 = db.CierreInventario.Where(x => x.Etapa1Generada == false).ToList(); foreach (var c in cpendientes1) { if (c.FechaInicial.Month == DateTime.Now.Month) { if (!c.Etapa1Generada) { foreach (var p in db.Producto.ToList()) { var cierreInventariop = new CierreInventariop(); cierreInventariop.CierreInventarioId = c.CierreInventarioId; cierreInventariop.ProductoId = p.ProductoId; cierreInventariop.Descripcion = p.Descripcion; cierreInventariop.InvInicial = p.Stock; cierreInventariop.Entradas = 0; cierreInventariop.Salidas = 0; cierreInventariop.UltimoCosto = p.UltimoCosto; cierreInventariop.PrevioVta = p.Precio1; cierreInventariop.ValorCosto = 0; cierreInventariop.ValorVenta = 0; db.Add(cierreInventariop); } c.Etapa1Generada = true; MessageBox.Show("INVENTARIO DE CIERRE GENERADO"); db.SaveChanges(); } } } var cpendientes2 = db.CierreInventario.Where(x => x.Etapa1Generada == true && x.Etapa2Generada == false).ToList(); foreach (var c in cpendientes2) { if (c.FechaProgramacion.Date <= DateTime.Now.Date) { if (!c.Etapa2Generada) { MessageBox.Show("EL SISTEMA INICÍO EL MANTENIMIENTO MENSUAL \n" + " LE SUPLICAMOS NO CIERRE EL SISTEMA, " + " INCLUSO SI USTEN NO VE ACTIVIDAD SIMPLEMENTE ESPERE\n" + " ESTO TOMARÁ UN PAR DE MINUTOS" , "NO CERRAR EL SISTEMA", MessageBoxButtons.OK); //****************Nuevo cierre inventario********************** var ncierreInventario = new CierreInventario(); //var ini = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); ncierreInventario.FechaInicial = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); ncierreInventario.FechaFinal = ncierreInventario.FechaInicial.AddMonths(1).AddDays(-1); ncierreInventario.FechaProgramacion = ncierreInventario.FechaFinal.AddDays(1); ncierreInventario.Etapa1Generada = true; ncierreInventario.Etapa2Generada = false; ncierreInventario.CreatedAt = DateTime.Now; ncierreInventario.CreatedBy = "SYS"; ncierreInventario.EstacionId = "SYS"; db.Add(ncierreInventario); // db.SaveChanges(); var productos = db.Producto.ToList(); foreach (var pr in productos) { var cierreInventariop = new CierreInventariop(); cierreInventariop.CierreInventarioId = ncierreInventario.CierreInventarioId; cierreInventariop.ProductoId = pr.ProductoId; cierreInventariop.Descripcion = pr.Descripcion; cierreInventariop.InvInicial = pr.Stock; cierreInventariop.Entradas = 0; cierreInventariop.Salidas = 0; cierreInventariop.UltimoCosto = pr.UltimoCosto; cierreInventariop.PrevioVta = pr.Precio1; cierreInventariop.ValorCosto = 0; cierreInventariop.ValorVenta = 0; db.Add(cierreInventariop); // db.SaveChanges(); } //////////////////////////////////////////////////////////////// Producto p; var cierreinvp = db.CierreInventariop.Where(x => x.CierreInventarioId == c.CierreInventarioId).ToList(); var mosvInv = db.MovInv.Where(x => x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).ToList(); foreach (var cp in cierreinvp) { p = productos.FirstOrDefault(x => x.ProductoId.Equals(cp.ProductoId)); if (p != null) { cp.Entradas = mosvInv.Where(x => x.Es.Equals("E") && !x.ConceptoMovsInvId.Equals("IIN") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad); cp.Salidas = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad); cp.InvFinal = cp.InvInicial + cp.Entradas - cp.Salidas; cp.UltimoCosto = p.UltimoCosto; cp.PrevioVta = p.Precio1; //ultimo precio venta cp.Stock = p.Stock; cp.ValorCosto = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Valor); cp.ValorVenta = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad * x.PrecioVta); db.Update(cp); } } c.Etapa2Generada = true; db.Update(c); db.SaveChanges(); MessageBox.Show("INVENTARIO DE CIERRE GENERADO"); } } } } } catch (Exception ex) { MessageBox.Show("Error ActualizaCierresInventario : " + ex.ToString()); } }