Example #1
0
        private void gvHistorico_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            in_producto_x_tb_bodega_Costo_Historico_Info row = (in_producto_x_tb_bodega_Costo_Historico_Info)gvHistorico.GetRow(e.RowHandle);

            if (row == null)
            {
                return;
            }

            if (e.Column == colCostoPromedio)
            {
                if (row.Secuencia == 0)
                {
                    string mens = string.Empty;
                    if (row.fecha != DateTime.MinValue && row.costo > 0)
                    {
                        row.IdEmpresa        = param.IdEmpresa;
                        row.IdSucursal       = ucIn_Sucursal_Bodega1.get_IdSucursal();
                        row.IdBodega         = ucIn_Sucursal_Bodega1.get_IdBodega();
                        row.IdProducto       = Convert.ToDecimal(cmb_producto.EditValue);
                        row.IdFecha          = Convert.ToInt32(row.fecha.ToString("yyyyMMdd"));
                        row.fecha            = row.fecha;
                        row.Stock_a_la_fecha = 0;
                        row.Observacion      = param.IdUsuario + " " + DateTime.Now.ToString("dd/MM/yyyy");

                        bus_costo_historico.GuardarDB(row, ref mens);
                    }
                }
                else
                {
                    bus_costo_historico.ModificarDB(row);
                }
                gcHistorico.RefreshDataSource();
            }
        }
Example #2
0
        private List <in_Ing_Egr_Inven_det_Info> GetDetalle_Ing_Egr_Inven(List <in_transferencia_det_Info> listDetalle, int IdSucursal, int IdBodega, string Signo, DateTime fecha)
        {
            try
            {
                List <in_Ing_Egr_Inven_det_Info> list_IngEgrDet = new List <in_Ing_Egr_Inven_det_Info>();
                foreach (var item in listDetalle.Where(q => q.IdProducto != null).ToList())
                {
                    switch (Signo)
                    {
                    case "-":
                        info_costo = bus_costo.get_UltimoCosto_x_Producto_Bodega(item.IdEmpresa, IdSucursal, IdBodega, item.IdProducto ?? 0, fecha);
                        list_costo_historico.Add(info_costo);
                        break;

                    case "+":
                        info_costo = list_costo_historico.FirstOrDefault(q => q.IdEmpresa == item.IdEmpresa && q.IdProducto == item.IdProducto);
                        break;
                    }
                    in_Ing_Egr_Inven_det_Info info = new in_Ing_Egr_Inven_det_Info();
                    info.IdEmpresa      = item.IdEmpresa;
                    info.IdSucursal     = IdSucursal;
                    info.IdNumMovi      = 0;
                    info.Secuencia      = item.dt_secuencia;
                    info.IdBodega       = IdBodega;
                    info.IdProducto     = item.IdProducto ?? 0;
                    info.dm_cantidad    = item.dt_cantidad;
                    info.dm_observacion = item.tr_Observacion;

                    info.dm_precio = info_costo == null ? 0 : info_costo.costo;

                    info.mv_costo_sinConversion = info_costo == null ? 0 : info_costo.costo;
                    info.mv_costo = info_costo == null ? 0 : info_costo.costo;

                    info.dm_cantidad_sinConversion = item.dt_cantidad;
                    info.dm_cantidad = item.dt_cantidad;

                    info.IdUnidadMedida = item.IdUnidadMedida;
                    info.IdUnidadMedida_sinConversion = item.IdUnidadMedida;

                    info.IdCentroCosto = item.IdCentroCosto;
                    info.IdCentroCosto_sub_centro_costo = item.IdCentroCosto_sub_centro_costo;

                    info.pr_descripcion = item.pr_descripcion;

                    info.IdPunto_cargo       = item.IdPunto_cargo;
                    info.IdPunto_cargo_grupo = item.IdPunto_cargo_grupo;

                    list_IngEgrDet.Add(info);
                }
                return(list_IngEgrDet);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "GetDetalle_Ing_Egr_Inven", ex.Message), ex)
                      {
                          EntityType = typeof(in_transferencia_bus)
                      };
            }
        }
Example #3
0
        public List <in_producto_x_tb_bodega_Costo_Historico_Info> Proceso_recosteo_y_correccion_contable_inv(int IdEmpresa, int IdSucursal, int IdBodega, DateTime Fecha_ini, int Decimales)
        {
            try
            {
                List <in_producto_x_tb_bodega_Costo_Historico_Info> Lista = new List <in_producto_x_tb_bodega_Costo_Historico_Info>();
                Fecha_ini = Fecha_ini.Date;
                using (EntitiesInventario Context = new EntitiesInventario())
                {
                    Context.SetCommandTimeOut(10000);

                    Context.spSys_Inv_Recosteo_Inventario(IdEmpresa, IdSucursal, IdBodega, Fecha_ini, Decimales);
                    var lst = from q in Context.vwin_producto_x_tb_bodega_Costo_Historico
                              where q.IdEmpresa == IdEmpresa &&
                              q.IdSucursal == IdSucursal &&
                              q.IdBodega == IdBodega &&
                              q.fecha >= Fecha_ini
                              select q;

                    foreach (var item in lst)
                    {
                        in_producto_x_tb_bodega_Costo_Historico_Info info = new in_producto_x_tb_bodega_Costo_Historico_Info();
                        info.IdEmpresa        = item.IdEmpresa;
                        info.IdSucursal       = item.IdSucursal;
                        info.IdBodega         = item.IdBodega;
                        info.IdProducto       = item.IdProducto;
                        info.IdFecha          = item.IdFecha;
                        info.Secuencia        = item.Secuencia;
                        info.fecha            = item.fecha;
                        info.costo            = item.costo;
                        info.Stock_a_la_fecha = item.Stock_a_la_fecha;
                        info.Observacion      = item.Observacion;
                        info.fecha_trans      = item.fecha_trans;

                        info.cod_sucursal = item.cod_sucursal;
                        info.nom_sucursal = "[" + item.cod_sucursal + "] " + item.nom_sucursal;
                        info.cod_bodega   = item.cod_bodega;
                        info.nom_bodega   = "[" + item.cod_bodega + "]" + item.nom_bodega;
                        info.cod_producto = item.cod_producto;
                        info.nom_producto = "[" + item.cod_producto + "]" + item.nom_producto;

                        Lista.Add(info);
                    }
                }
                return(Lista);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString() + " " + ex.Message;
                throw new Exception(ex.ToString());
            }
        }
Example #4
0
        public bool ModificarDB(in_producto_x_tb_bodega_Costo_Historico_Info info)
        {
            using (SqlConnection connection = new SqlConnection(ConexionERP.GetConnectionString()))
            {
                connection.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "update in_producto_x_tb_bodega_Costo_Historico set costo = " + info.costo.ToString() + " where IdEmpresa = " + info.IdEmpresa.ToString() + " and IdSucursal = " + info.IdSucursal.ToString() + " and IdBodega = " + info.IdBodega.ToString() + " and IdProducto = " + info.IdProducto.ToString() + " and IdFecha = " + info.IdFecha.ToString() + " and Secuencia = " + info.Secuencia;
                command.ExecuteNonQuery();
            }
            return(true);
        }
Example #5
0
 public Boolean GuardarDB(in_producto_x_tb_bodega_Costo_Historico_Info Info, ref string msjError)
 {
     try
     {
         return(dataProd.GuardarDB(Info, ref msjError));
     }
     catch (Exception ex)
     {
         Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
         throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "GuardarDB", ex.Message), ex)
               {
                   EntityType = typeof(in_producto_x_tb_bodega_Costo_Historico_Bus)
               };
     }
 }
Example #6
0
        public in_producto_x_tb_bodega_Costo_Historico_Info Get_UltimoCosto_x_Producto_Bodega(int IdEmpresa, int IdSucursal, int IdBodega, decimal IdProducto, DateTime Fecha)
        {
            try
            {
                in_producto_x_tb_bodega_Costo_Historico_Info Info = new in_producto_x_tb_bodega_Costo_Historico_Info();
                int IdFechaMax             = 0;
                int SecuenciaMax           = 0;
                EntitiesInventario entInve = new EntitiesInventario();

                Fecha = Fecha.Date;

                var select = (from q in entInve.in_producto_x_tb_bodega_Costo_Historico
                              where q.IdEmpresa == IdEmpresa &&
                              q.IdSucursal == IdSucursal &&
                              q.IdBodega == IdBodega &&
                              q.IdProducto == IdProducto &&
                              q.fecha <= Fecha
                              select q);



                if (select.Count() == 0)
                {
                    Info = new in_producto_x_tb_bodega_Costo_Historico_Info();
                }
                else
                {
                    IdFechaMax = select.Max(q => q.IdFecha);

                    SecuenciaMax = select.Where(q => q.IdEmpresa == IdEmpresa &&
                                                q.IdSucursal == IdSucursal &&
                                                q.IdBodega == IdBodega && q.IdProducto == IdProducto &&
                                                q.IdFecha == IdFechaMax).Max(q => q.Secuencia);

                    Info = Get_Producto_Bodega_Historico(IdEmpresa, IdSucursal, IdBodega, IdProducto, IdFechaMax, SecuenciaMax);
                }
                return(Info);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString() + " " + ex.Message;
                throw new Exception(ex.ToString());
            }
        }
Example #7
0
        public in_producto_x_tb_bodega_Costo_Historico_Info Get_Producto_Bodega_Historico(int IdEmpresa, int IdSucursal, int IdBodega, decimal IdProducto, int IdFecha, int Secuencia)
        {
            try
            {
                in_producto_x_tb_bodega_Costo_Historico_Info Info = new in_producto_x_tb_bodega_Costo_Historico_Info();

                using (EntitiesInventario entInve = new EntitiesInventario())
                {
                    var select = (from q in entInve.in_producto_x_tb_bodega_Costo_Historico
                                  where q.IdEmpresa == IdEmpresa &&
                                  q.IdSucursal == IdSucursal &&
                                  q.IdBodega == IdBodega && q.IdProducto == IdProducto &&
                                  q.IdFecha == IdFecha && q.Secuencia == Secuencia
                                  select q);

                    foreach (var item in select)
                    {
                        Info.IdEmpresa        = item.IdEmpresa;
                        Info.IdSucursal       = item.IdSucursal;
                        Info.IdBodega         = item.IdBodega;
                        Info.IdProducto       = item.IdProducto;
                        Info.IdFecha          = item.IdFecha;
                        Info.Secuencia        = item.Secuencia;
                        Info.fecha            = item.fecha;
                        Info.costo            = item.costo;
                        Info.Stock_a_la_fecha = item.Stock_a_la_fecha;
                        Info.Observacion      = item.Observacion;
                    }
                }


                return(Info);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString() + " " + ex.Message;
                throw new Exception(ex.InnerException.ToString());
            }
        }
Example #8
0
        public Boolean GuardarDB(in_producto_x_tb_bodega_Costo_Historico_Info Info, ref string msjError)
        {
            try
            {
                using (EntitiesInventario Context = new EntitiesInventario())
                {
                    var Address = new in_producto_x_tb_bodega_Costo_Historico();

                    Address.IdEmpresa        = Info.IdEmpresa;
                    Address.IdSucursal       = Info.IdSucursal;
                    Address.IdBodega         = Convert.ToInt32(Info.IdBodega);
                    Address.IdProducto       = Info.IdProducto;
                    Address.IdFecha          = Info.IdFecha;
                    Address.Secuencia        = Info.Secuencia = GetSecuencia(Info);
                    Address.fecha            = Convert.ToDateTime(Info.fecha.ToShortDateString());
                    Address.costo            = Info.costo;
                    Address.Stock_a_la_fecha = Info.Stock_a_la_fecha;
                    if (Info.Observacion == null || Info.Observacion == "")
                    {
                        Address.Observacion = ".";
                    }
                    else
                    {
                        Address.Observacion = Info.Observacion;//.Substring(1, 25);
                    }
                    Address.fecha_trans = DateTime.Now;
                    Context.in_producto_x_tb_bodega_Costo_Historico.Add(Address);
                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje  = ex.ToString() + " " + ex.Message;
                msjError = mensaje;
                throw new Exception(ex.ToString());
            }
        }
Example #9
0
        public int GetSecuencia(in_producto_x_tb_bodega_Costo_Historico_Info Info)
        {
            try
            {
                int Id;
                EntitiesInventario entInve = new EntitiesInventario();
                var select = (from q in entInve.in_producto_x_tb_bodega_Costo_Historico
                              where q.IdEmpresa == Info.IdEmpresa &&
                              q.IdSucursal == Info.IdSucursal &&
                              q.IdBodega == Info.IdBodega &&
                              q.IdProducto == Info.IdProducto &&
                              q.IdFecha == Info.IdFecha
                              select q.Secuencia).Count();

                if (select == 0)
                {
                    Id = 1;
                }
                else
                {
                    var select_IdCXC = (from q in entInve.in_producto_x_tb_bodega_Costo_Historico
                                        where q.IdEmpresa == Info.IdEmpresa &&
                                        q.IdSucursal == Info.IdSucursal &&
                                        q.IdBodega == Info.IdBodega &&
                                        q.IdProducto == Info.IdProducto &&
                                        q.IdFecha == Info.IdFecha
                                        select q.Secuencia).Max();
                    Id = Convert.ToInt32(select_IdCXC.ToString()) + 1;
                }
                return(Id);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString() + " " + ex.Message;
                throw new Exception(ex.ToString());
            }
        }
        private void ProcesoRecosteoInventario(in_Ing_Egr_Inven_Info info)
        {
            try
            {
                foreach (var item in info.listIng_Egr)
                {
                    in_producto_Bus  BusProducto = new in_producto_Bus();
                    in_Producto_Info InfoProdu   = BusProducto.Get_info_Product(info.IdEmpresa, item.IdProducto);
                    item.signo = info.signo;

                    if (item.mv_costo_sinConversion == 0 || item.signo == "-")
                    {
                        in_producto_x_tb_bodega_Costo_Historico_Bus  BusProd_x_Costo     = new in_producto_x_tb_bodega_Costo_Historico_Bus();
                        in_producto_x_tb_bodega_Costo_Historico_Info Info_Produc_x_Costo = new in_producto_x_tb_bodega_Costo_Historico_Info();
                        Info_Produc_x_Costo         = BusProd_x_Costo.get_UltimoCosto_x_Producto_Bodega(item.IdEmpresa, item.IdSucursal, Convert.ToInt32(item.IdBodega), item.IdProducto, info.cm_fecha);
                        item.mv_costo               = Info_Produc_x_Costo.costo;
                        item.mv_costo_sinConversion = Info_Produc_x_Costo.costo;
                    }
                    #region Convierte costo y cantidad en la unidad de consumo
                    ValorEquiv          = 0;
                    InfoUni_Equiv       = busUni_Equiv.Get_Info_in_UnidadMedida_Equiv_conversion(item.IdUnidadMedida_sinConversion, InfoProdu.IdUnidadMedida_Consumo);
                    ValorEquiv          = InfoUni_Equiv.valor_equiv == 0 ? 1 : InfoUni_Equiv.valor_equiv;
                    item.dm_cantidad    = item.dm_cantidad_sinConversion * ValorEquiv;
                    item.mv_costo       = item.signo == "-" ? item.mv_costo_sinConversion : (item.mv_costo_sinConversion * item.dm_cantidad_sinConversion) / item.dm_cantidad;
                    item.IdUnidadMedida = InfoProdu.IdUnidadMedida_Consumo;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "ProcesoRecosteoInventario", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }
        public Boolean ModificarDB(in_Ing_Egr_Inven_Info info, ref string msgs)
        {
            try
            {
                in_Ing_Egr_Inven_det_Data dataDet   = new in_Ing_Egr_Inven_det_Data();
                in_Parametro_Bus          busParam  = new in_Parametro_Bus();
                in_Parametro_Info         infoParam = new in_Parametro_Info();
                string IdEstadoAproba_Param         = "";
                infoParam = busParam.Get_Info_Parametro(info.IdEmpresa);
                if (InfoParam.IdEmpresa == 0)
                {
                    return(false);
                }
                if (info.signo == "+")
                {
                    IdEstadoAproba_Param = infoParam.IdEstadoAproba_x_Ing;
                }
                else
                {
                    IdEstadoAproba_Param = infoParam.IdEstadoAproba_x_Egr;
                }

                Boolean res = false;

                if (Validar_objeto_IngEgr(info, ref mensaje))
                {
                    //arreglando los id del detalle en caso q no venga sin id
                    foreach (var item in info.listIng_Egr)
                    {
                        item.IdEmpresa         = info.IdEmpresa;
                        item.IdSucursal        = info.IdSucursal;
                        item.IdNumMovi         = info.IdNumMovi;
                        item.IdMovi_inven_tipo = info.IdMovi_inven_tipo;
                        item.signo             = info.signo;

                        in_producto_Bus  BusProducto = new in_producto_Bus();
                        in_Producto_Info InfoProdu   = BusProducto.Get_info_Product(info.IdEmpresa, item.IdProducto);

                        if (item.IdEstadoAproba == null || item.IdEstadoAproba == "")
                        {
                            if (info.signo == "+")
                            {
                                IdEstadoAproba_Param = infoParam.IdEstadoAproba_x_Ing;
                            }
                            else
                            {
                                IdEstadoAproba_Param = infoParam.IdEstadoAproba_x_Egr;
                            }
                            item.IdEstadoAproba = Get_EstadoApro(Convert.ToInt32(info.IdEmpresa), Convert.ToInt32(info.IdSucursal), Convert.ToInt32(info.IdBodega), IdEstadoAproba_Param);
                        }
                        if (item.IdUnidadMedida_sinConversion == null || item.IdUnidadMedida_sinConversion == "" || item.IdUnidadMedida == null || item.IdUnidadMedida == "")
                        {
                            item.IdUnidadMedida               = InfoProdu.IdUnidadMedida;
                            item.IdUnidadMedida_Consumo       = InfoProdu.IdUnidadMedida_Consumo;
                            item.IdUnidadMedida_sinConversion = InfoProdu.IdUnidadMedida;
                        }
                        if (item.mv_costo_sinConversion == 0 || item.signo == "-")
                        {
                            in_producto_x_tb_bodega_Costo_Historico_Bus  BusProd_x_Costo     = new in_producto_x_tb_bodega_Costo_Historico_Bus();
                            in_producto_x_tb_bodega_Costo_Historico_Info Info_Produc_x_Costo = new in_producto_x_tb_bodega_Costo_Historico_Info();
                            Info_Produc_x_Costo         = BusProd_x_Costo.get_UltimoCosto_x_Producto_Bodega(item.IdEmpresa, item.IdSucursal, Convert.ToInt32(item.IdBodega), item.IdProducto, info.cm_fecha);
                            item.mv_costo               = Info_Produc_x_Costo.costo;
                            item.mv_costo_sinConversion = Info_Produc_x_Costo.costo;
                        }
                        #region Convierte costo y cantidad en la unidad de consumo
                        ValorEquiv          = 0;
                        InfoUni_Equiv       = busUni_Equiv.Get_Info_in_UnidadMedida_Equiv_conversion(item.IdUnidadMedida_sinConversion, InfoProdu.IdUnidadMedida_Consumo);
                        ValorEquiv          = InfoUni_Equiv.valor_equiv == 0 ? 1 : InfoUni_Equiv.valor_equiv;
                        item.dm_cantidad    = item.dm_cantidad_sinConversion * ValorEquiv;
                        item.mv_costo       = item.mv_costo_sinConversion / ValorEquiv;
                        item.IdUnidadMedida = InfoProdu.IdUnidadMedida_Consumo;
                        #endregion
                    }

                    if (dataDet.EliminarDB(info.IdEmpresa, info.IdSucursal, info.IdMovi_inven_tipo, info.IdNumMovi, ref msgs))
                    {
                        info.IdUsuarioUltModi = param.IdUsuario;

                        if (odata.ModificarDB(info, ref msgs))
                        {
                            foreach (var item in info.listIng_Egr)
                            {
                                item.Secuencia      = 0;
                                item.IdEstadoAproba = Get_EstadoApro(Convert.ToInt32(info.IdEmpresa), Convert.ToInt32(info.IdSucursal), Convert.ToInt32(info.IdBodega), IdEstadoAproba_Param);

                                if (item.IdEmpresa == null || item.IdEmpresa == 0)
                                {
                                    item.IdEmpresa = Convert.ToInt32(info.IdEmpresa);
                                }

                                if (item.IdSucursal == null || item.IdSucursal == 0)
                                {
                                    item.IdSucursal = Convert.ToInt32(info.IdSucursal);
                                }

                                if (item.IdBodega == null || item.IdBodega == 0)
                                {
                                    item.IdBodega = Convert.ToInt32(info.IdBodega);
                                }

                                if (item.IdMovi_inven_tipo == null || item.IdMovi_inven_tipo == 0)
                                {
                                    item.IdMovi_inven_tipo = Convert.ToInt32(info.IdMovi_inven_tipo);
                                }

                                if (item.IdNumMovi == null || item.IdNumMovi == 0)
                                {
                                    item.IdNumMovi = Convert.ToInt32(info.IdNumMovi);
                                }
                            }

                            if (dataDet.GuardarDB(info.listIng_Egr))
                            {
                                res = true;
                                res = procesoGenerarMoviInve(info, info.IdNumMovi, ref mensaje);
                            }
                        }
                    }
                }

                return(res);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "ModificarDB", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }
        public Boolean GuardarDB(in_Ing_Egr_Inven_Info info, ref decimal IdNumMovi, ref string mensaje)
        {
            try
            {
                Boolean res = true;

                InfoParam = busParam.Get_Info_Parametro(info.IdEmpresa);

                if (Validar_objeto_IngEgr(info, ref mensaje))
                {
                    foreach (var item in info.listIng_Egr)
                    {
                        in_producto_Bus  BusProducto = new in_producto_Bus();
                        in_Producto_Info InfoProdu   = BusProducto.Get_info_Product(info.IdEmpresa, item.IdProducto);
                        item.signo = info.signo;

                        if (item.IdEstadoAproba == null || item.IdEstadoAproba == "")
                        {
                            if (info.signo == "+")
                            {
                                IdEstadoAproba_Param = InfoParam.IdEstadoAproba_x_Ing;
                            }
                            else
                            {
                                IdEstadoAproba_Param = InfoParam.IdEstadoAproba_x_Egr;
                            }
                            item.IdEstadoAproba = Get_EstadoApro(Convert.ToInt32(info.IdEmpresa), Convert.ToInt32(info.IdSucursal), Convert.ToInt32(info.IdBodega), IdEstadoAproba_Param);
                        }
                        if (item.IdUnidadMedida_sinConversion == null || item.IdUnidadMedida_sinConversion == "")
                        {
                            item.IdUnidadMedida               = InfoProdu.IdUnidadMedida;
                            item.IdUnidadMedida_Consumo       = InfoProdu.IdUnidadMedida_Consumo;
                            item.IdUnidadMedida_sinConversion = InfoProdu.IdUnidadMedida;
                        }
                        if (/*item.mv_costo_sinConversion == 0 ||*/ item.signo == "-")
                        {
                            in_producto_x_tb_bodega_Costo_Historico_Bus  BusProd_x_Costo     = new in_producto_x_tb_bodega_Costo_Historico_Bus();
                            in_producto_x_tb_bodega_Costo_Historico_Info Info_Produc_x_Costo = new in_producto_x_tb_bodega_Costo_Historico_Info();
                            Info_Produc_x_Costo         = BusProd_x_Costo.get_UltimoCosto_x_Producto_Bodega(item.IdEmpresa, item.IdSucursal, Convert.ToInt32(item.IdBodega), item.IdProducto, info.cm_fecha);
                            item.mv_costo               = Info_Produc_x_Costo.costo;
                            item.mv_costo_sinConversion = Info_Produc_x_Costo.costo;
                        }

                        #region Convierte costo y cantidad en la unidad de consumo
                        ValorEquiv          = 0;
                        InfoUni_Equiv       = busUni_Equiv.Get_Info_in_UnidadMedida_Equiv_conversion(item.IdUnidadMedida_sinConversion, InfoProdu.IdUnidadMedida_Consumo);
                        ValorEquiv          = InfoUni_Equiv.valor_equiv == 0 ? 1 : InfoUni_Equiv.valor_equiv;
                        item.dm_cantidad    = item.dm_cantidad_sinConversion * ValorEquiv;
                        item.mv_costo       = item.signo == "-" ? item.mv_costo_sinConversion : (item.mv_costo_sinConversion * item.dm_cantidad_sinConversion) / item.dm_cantidad;
                        item.IdUnidadMedida = InfoProdu.IdUnidadMedida_Consumo;
                        #endregion
                    }
                    if (res = odata.GuardarDB(info, ref IdNumMovi, ref mensaje))
                    {
                        res = procesoGenerarMoviInve(info, IdNumMovi, ref mensaje);
                    }
                }
                else
                {
                    res = false;
                }

                return(res);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "GuardarDB", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }
Example #13
0
        private bool Generar_info_ing_egr(in_ajusteFisico_Info info_ajuste, ref decimal IdNumMovi_ing, ref decimal IdNumMovi_egr)
        {
            try
            {
                in_Ing_Egr_Inven_Info info_ing_egr = new in_Ing_Egr_Inven_Info();

                bool HayIngresos = false;
                bool HayEgresos  = false;

                var TIngreso = (from q in info_ajuste.list_det_AjusteFisico
                                where q.CantidadAjustada > 0
                                select q).Count();


                var TEgresos = (from q in info_ajuste.list_det_AjusteFisico
                                where q.CantidadAjustada < 0
                                select q).Count();


                HayIngresos = (Convert.ToDouble(TIngreso) > 0) ? true : false;

                #region HayIngreso

                if (HayIngresos == true)
                {
                    info_ing_egr = new in_Ing_Egr_Inven_Info();

                    info_ing_egr.IdEmpresa         = info_ajuste.IdEmpresa;
                    info_ing_egr.IdSucursal        = info_ajuste.IdSucursal;
                    info_ing_egr.IdBodega          = info_ajuste.IdBodega;
                    info_ing_egr.IdMovi_inven_tipo = info_ajuste.IdMovi_inven_tipo_Ing;
                    info_ing_egr.signo             = "+";
                    info_ing_egr.cm_observacion    = info_ajuste.Observacion;
                    info_ing_egr.IdUsuario         = info_ajuste.IdUsuario;
                    info_ing_egr.nom_pc            = info_ajuste.nom_pc;
                    info_ing_egr.ip           = info_ajuste.ip;
                    info_ing_egr.Estado       = "A";
                    info_ing_egr.cm_fecha     = info_ajuste.Fecha;
                    info_ing_egr.CodMoviInven = "AJU";
                    info_ing_egr.IdMotivo_Inv = 1;

                    /// obteniendo el detalle del movimiento de invetario
                    var SelectDetMoviIng = from q in info_ajuste.list_det_AjusteFisico
                                           where q.CantidadAjustada > 0
                                           select q;
                    int c = 1;
                    foreach (var item in SelectDetMoviIng)
                    {
                        info_costo_historico = bus_costo_historico.get_UltimoCosto_x_Producto_Bodega(info_ajuste.IdEmpresa, info_ajuste.IdSucursal, info_ajuste.IdBodega, item.IdProducto, info_ing_egr.cm_fecha);


                        in_Ing_Egr_Inven_det_Info detMovInfo = new in_Ing_Egr_Inven_det_Info();
                        //detMovInfo.dm_peso = item.p;
                        detMovInfo.dm_cantidad = Convert.ToDouble(item.CantidadAjustada);
                        detMovInfo.dm_cantidad_sinConversion = Convert.ToDouble(item.CantidadAjustada);
                        detMovInfo.IdProducto        = item.IdProducto;
                        detMovInfo.Secuencia         = c;
                        detMovInfo.IdEmpresa         = info_ajuste.IdEmpresa;
                        detMovInfo.IdBodega          = info_ing_egr.IdBodega;
                        detMovInfo.IdSucursal        = info_ing_egr.IdSucursal;
                        detMovInfo.IdMovi_inven_tipo = info_ing_egr.IdMovi_inven_tipo;
                        detMovInfo.IdNumMovi         = 0;//Nuevo
                        detMovInfo.signo             = info_ing_egr.signo;
                        detMovInfo.dm_observacion    = info_ajuste.Observacion;
                        //Costo historico
                        detMovInfo.mv_costo = info_costo_historico.costo;
                        detMovInfo.mv_costo_sinConversion = info_costo_historico.costo;
                        detMovInfo.IdCentroCosto          = item.IdCentroCosto;
                        info_ing_egr.listIng_Egr.Add(detMovInfo);
                        c++;
                    }
                    bus_ing_egr.GuardarDB(info_ing_egr, ref IdNumMovi_ing, ref mensaje);
                }


                #endregion
                #region HayEgreso
                HayEgresos = (Convert.ToDouble(TEgresos) > 0) ? true : false;

                if (HayEgresos == true)
                {
                    info_ing_egr = new in_Ing_Egr_Inven_Info();

                    info_ing_egr.IdEmpresa         = info_ajuste.IdEmpresa;
                    info_ing_egr.IdSucursal        = info_ajuste.IdSucursal;
                    info_ing_egr.IdBodega          = info_ajuste.IdBodega;
                    info_ing_egr.IdMovi_inven_tipo = info_ajuste.IdMovi_inven_tipo_Egr;
                    info_ing_egr.signo             = "-";
                    info_ing_egr.cm_observacion    = info_ajuste.Observacion;
                    info_ing_egr.IdUsuario         = info_ajuste.IdUsuario;
                    info_ing_egr.nom_pc            = info_ajuste.nom_pc;
                    info_ing_egr.ip           = info_ajuste.ip;
                    info_ing_egr.Estado       = "A";
                    info_ing_egr.cm_fecha     = info_ajuste.Fecha;
                    info_ing_egr.CodMoviInven = "AJU";
                    info_ing_egr.IdMotivo_Inv = 1;
                    /// encontrando el detalle de inventario
                    ///
                    var SelectDetMoviEgre = from q in info_ajuste.list_det_AjusteFisico
                                            where q.CantidadAjustada < 0
                                            select q;

                    int c = 1;

                    foreach (var item in SelectDetMoviEgre)
                    {
                        info_costo_historico = bus_costo_historico.get_UltimoCosto_x_Producto_Bodega(info_ajuste.IdEmpresa, info_ajuste.IdSucursal, info_ajuste.IdBodega, item.IdProducto, info_ing_egr.cm_fecha);

                        in_Ing_Egr_Inven_det_Info detMovInfo = new in_Ing_Egr_Inven_det_Info();
                        detMovInfo.IdEmpresa         = info_ing_egr.IdEmpresa;
                        detMovInfo.IdBodega          = info_ing_egr.IdBodega;
                        detMovInfo.IdSucursal        = info_ing_egr.IdSucursal;
                        detMovInfo.IdMovi_inven_tipo = info_ing_egr.IdMovi_inven_tipo;
                        detMovInfo.IdNumMovi         = 0;//Nuevo
                        //detMovInfo.peso = item.pr_peso;
                        detMovInfo.Secuencia = c;
                        c++;
                        detMovInfo.signo       = info_ing_egr.signo;
                        detMovInfo.IdProducto  = item.IdProducto;
                        detMovInfo.dm_cantidad = Convert.ToDouble(item.CantidadAjustada) * -1;
                        detMovInfo.dm_cantidad_sinConversion = Convert.ToDouble(item.CantidadAjustada) * -1;
                        detMovInfo.dm_observacion            = info_ing_egr.cm_observacion;
                        //Costo historico
                        detMovInfo.mv_costo = info_costo_historico.costo;
                        detMovInfo.mv_costo_sinConversion = info_costo_historico.costo;
                        detMovInfo.IdCentroCosto          = item.IdCentroCosto;

                        info_ing_egr.listIng_Egr.Add(detMovInfo);
                    }
                    bus_ing_egr.GuardarDB(info_ing_egr, ref IdNumMovi_egr, ref mensaje);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Armar_info_ing_egr", ex.Message), ex)
                      {
                          EntityType = typeof(in_AjusteFisico_Bus)
                      };
            }
        }
Example #14
0
 public bool ModificarDB(in_producto_x_tb_bodega_Costo_Historico_Info info)
 {
     return(dataProd.ModificarDB(info));
 }