public Boolean AnularDB(in_Ing_Egr_Inven_Info info, ref string msgs)
        {
            try
            {
                in_Ing_Egr_Inven_det_Bus BusDeta_Ing_Egr_Inven = new in_Ing_Egr_Inven_det_Bus();
                Boolean Respuesta_anulacion            = false;
                Boolean Respuesta_anulacion_Inventario = false;

                in_movi_inven_tipo_Info info_movi_inven_tipo = new in_movi_inven_tipo_Info();
                in_movi_inven_tipo_Bus  bus_movi_inven_tipo  = new in_movi_inven_tipo_Bus();
                info_movi_inven_tipo = bus_movi_inven_tipo.Get_Info_movi_inven_tipo(info.IdEmpresa, info.IdMovi_inven_tipo);

                in_Motivo_Inven_Info info_motivo_inven = new in_Motivo_Inven_Info();
                in_Motivo_Inven_Bus  bus_motivo_inven  = new in_Motivo_Inven_Bus();
                info_motivo_inven = bus_motivo_inven.Get_Info_Motivo_Inven(info.IdEmpresa, info.IdMotivo_Inv == null ? 0 : Convert.ToInt32(info.IdMotivo_Inv));

                string genero_movi = info_movi_inven_tipo.Genera_Movi_Inven == true && info_motivo_inven.Genera_Movi_Inven == "S" ? "S" : "N";

                if (info.listIng_Egr.Count() > 0)
                {
                    info.IdEstadoAproba = info.listIng_Egr.Max(q => q.IdEstadoAproba);
                }

                if (info.IdEstadoAproba == "APRO")
                {
                    odata.Reversar_Aprobacion(info.IdEmpresa, info.IdSucursal, info.IdMovi_inven_tipo, info.IdNumMovi, genero_movi);
                }
                info.IdusuarioUltAnu = param.IdUsuario;
                Respuesta_anulacion  = odata.AnularDB(info, ref msgs);

                if (Respuesta_anulacion)
                {
                    Respuesta_anulacion_Inventario = true;
                }

                //Agrupo lista de ordenes de compra
                var lst_oc = (from q in info.listIng_Egr
                              where q.IdOrdenCompra != null
                              group q by new { q.IdEmpresa_oc, q.IdSucursal_oc, q.IdOrdenCompra }
                              into grouping
                              select new { grouping.Key.IdEmpresa_oc, grouping.Key.IdSucursal_oc, grouping.Key.IdOrdenCompra }
                              ).ToList();

                BusDeta_Ing_Egr_Inven.Modificar_Enserar_Campos_OC(info.listIng_Egr);

                foreach (var item in lst_oc)
                {
                    bus_oc.Modificar_Estado_Cierre(Convert.ToInt32(item.IdEmpresa_oc), Convert.ToInt32(item.IdSucursal_oc), Convert.ToInt32(item.IdOrdenCompra), "ABI");
                }

                return(Respuesta_anulacion && Respuesta_anulacion_Inventario);
            }
            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("", "AnularDB", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }
        Boolean Genera_Inventario_x_IngEgr_Inven(in_Ing_Egr_Inven_Info info, ref string msg)
        {
            try
            {
                //graba inventario
                in_movi_inve_Info info_MoviInve = new in_movi_inve_Info();

                info_MoviInve.IdEmpresa         = info.IdEmpresa;
                info_MoviInve.IdSucursal        = info.IdSucursal;
                info_MoviInve.IdBodega          = (info.IdBodega == null && info.listIng_Egr.Count != 0) ? Convert.ToInt32(info.listIng_Egr.FirstOrDefault().IdBodega) : Convert.ToInt32(info.IdBodega);
                info_MoviInve.IdMovi_inven_tipo = info.IdMovi_inven_tipo;



                in_movi_inven_tipo_Info Info_moviInvTipo = new in_movi_inven_tipo_Info();
                in_movi_inven_tipo_Bus  bus_moviInvTipo  = new in_movi_inven_tipo_Bus();

                Info_moviInvTipo = bus_moviInvTipo.Get_Info_movi_inven_tipo(info.IdEmpresa, info.IdMovi_inven_tipo);
                if (Info_moviInvTipo.Genera_Movi_Inven == true)
                {
                    if (Info_moviInvTipo == null)
                    {
                        msg = "No existen Tipos de Movimientos de Inventario";
                        return(false);
                    }

                    info_MoviInve.IdMovi_inven_tipo = Info_moviInvTipo.IdMovi_inven_tipo;
                    info_MoviInve.CodMoviInven      = Info_moviInvTipo.Codigo;
                    info_MoviInve.cm_tipo           = Info_moviInvTipo.cm_tipo_movi;

                    info_MoviInve.cm_observacion = info.cm_observacion;
                    info_MoviInve.cm_fecha       = info.cm_fecha;

                    info_MoviInve.IdEmpresa_Ing_Egr         = info.IdEmpresa;
                    info_MoviInve.IdSucursal_Ing_Egr        = info.IdSucursal;
                    info_MoviInve.IdBodega_Ing_Egr          = info.IdBodega;
                    info_MoviInve.IdMovi_inven_tipo_Ing_Egr = info.IdMovi_inven_tipo;
                    info_MoviInve.IdNumMovi_Ing_Egr         = info.IdNumMovi;
                    info_MoviInve.IdMotivo_inv = info.IdMotivo_Inv;


                    //detalle
                    List <in_movi_inve_detalle_Info> list_inveDet = new List <in_movi_inve_detalle_Info>();

                    foreach (var item in info.listIng_Egr)
                    {
                        in_movi_inve_detalle_Info infoMovDet = new in_movi_inve_detalle_Info();

                        infoMovDet.IdProducto     = item.IdProducto;
                        infoMovDet.dm_cantidad    = item.dm_cantidad;
                        infoMovDet.dm_observacion = (item.dm_observacion == null) ? "" : item.dm_observacion;
                        infoMovDet.mv_costo       = item.mv_costo;
                        infoMovDet.IdCentroCosto  = item.IdCentroCosto;
                        infoMovDet.IdCentroCosto_sub_centro_costo = item.IdCentroCosto_sub_centro_costo;

                        infoMovDet.IdUnidadMedida               = item.IdUnidadMedida;
                        infoMovDet.mv_costo_sinConversion       = item.mv_costo_sinConversion;
                        infoMovDet.dm_cantidad_sinConversion    = item.dm_cantidad_sinConversion;
                        infoMovDet.IdUnidadMedida_sinConversion = item.IdUnidadMedida_sinConversion;
                        infoMovDet.IdPunto_Cargo       = item.IdPunto_cargo;
                        infoMovDet.IdPunto_cargo_grupo = item.IdPunto_cargo_grupo;
                        infoMovDet.IdMotivo_Inv        = item.IdMotivo_Inv;

                        //Campos para saber cual movimiento esta devolviendo este
                        infoMovDet.IdEmpresa_dev         = item.IdEmpresa_dev;
                        infoMovDet.IdSucursal_dev        = item.IdSucursal_dev;
                        infoMovDet.IdBodega_dev          = item.IdBodega_dev;
                        infoMovDet.IdMovi_inven_tipo_dev = item.IdMovi_inven_tipo_dev;
                        infoMovDet.IdNumMovi_dev         = item.IdNumMovi_dev;
                        infoMovDet.Secuencia_dev         = item.Secuencia_dev;

                        infoMovDet.IdOrdenCompra = (item.IdOrdenCompra == null) ? 0 : Convert.ToDecimal(item.IdOrdenCompra);

                        list_inveDet.Add(infoMovDet);
                    }

                    info_MoviInve.listmovi_inve_detalle_Info = list_inveDet;

                    //detalle

                    in_movi_inve_Bus bus_MovInve = new in_movi_inve_Bus();
                    decimal          idMoviInven;
                    idMoviInven = 0;
                    string mensaje_cbte_cble = "";

                    if (bus_MovInve.GrabarDB(info_MoviInve, ref idMoviInven, ref mensaje, ref mensaje_cbte_cble))
                    {
                        // actualizar item Movimientos en in_Ing_Egr_Inven_det
                        foreach (var item in info_MoviInve.listmovi_inve_detalle_Info)
                        {
                            int conta = 0;
                            foreach (var item2 in info.listIng_Egr)
                            {
                                if (item2.IdEmpresa_inv == null && item2.IdSucursal_inv == null &&
                                    item2.IdBodega_inv == null && item2.IdMovi_inven_tipo_inv == null &&
                                    item2.IdNumMovi_inv == null && item2.secuencia_inv == null)
                                {
                                    item2.IdEmpresa_inv         = item.IdEmpresa;
                                    item2.IdSucursal_inv        = item.IdSucursal;
                                    item2.IdBodega_inv          = item.IdBodega;
                                    item2.IdMovi_inven_tipo_inv = item.IdMovi_inven_tipo;
                                    item2.IdNumMovi_inv         = idMoviInven;
                                    item2.secuencia_inv         = item.Secuencia;

                                    conta = conta + 1;
                                    break;
                                }
                                if (conta > 0)
                                {
                                    item2.IdEmpresa_inv         = null;
                                    item2.IdSucursal_inv        = null;
                                    item2.IdBodega_inv          = null;
                                    item2.IdMovi_inven_tipo_inv = null;
                                    item2.IdNumMovi_inv         = null;
                                    item2.secuencia_inv         = null;
                                    break;
                                }
                            }
                        }
                        string msgs = "";
                        // odata.ModificarCabecera_IdMovi_Inven_x_IngEgr(info, ref msgs);
                        in_Ing_Egr_Inven_det_Data odataDet = new in_Ing_Egr_Inven_det_Data();
                        odataDet.ModificarDetalle_IdMovi_Inven_x_IngEgr(info.listIng_Egr, ref msgs);
                    }
                    else
                    {
                        msg = mensaje + "-" + mensaje_cbte_cble;
                        return(false);
                    }
                }

                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("", "Genera_Inventario_x_IngEgr_Inven", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }
        public Boolean GuardarDB(in_devolucion_inven_Info info, ref decimal IdDev_Inven, ref string mensaje)
        {
            Boolean Respuesta = false;

            try
            {
                int c = 0;
                Respuesta = oDat.GuardarDB(info, ref IdDev_Inven, ref mensaje);
                if (Respuesta)
                {
                    c = 0;
                    foreach (var item in info.lista_detalle)
                    {
                        item.IdDev_Inven = IdDev_Inven;
                        c++;
                        item.secuencia = c;
                    }
                    in_devolucion_inven_det_Bus BusDev_inv_det = new in_devolucion_inven_det_Bus();
                    Respuesta = BusDev_inv_det.GuardarDB(info.lista_detalle, ref mensaje);


                    in_Parametro_Bus  BusParametro  = new in_Parametro_Bus();
                    in_Parametro_Info InfoParametro = new in_Parametro_Info();
                    InfoParametro = BusParametro.Get_Info_Parametro(info.IdEmpresa);
                    in_movi_inven_tipo_Info InfoMovi_tipo = new in_movi_inven_tipo_Info();
                    in_movi_inven_tipo_Bus  BusMovi_tipo  = new in_movi_inven_tipo_Bus();


                    InfoMovi_tipo = BusMovi_tipo.Get_Info_movi_inven_tipo(info.IdEmpresa, info.IdMovi_inven_tipo);

                    //                    in_movi_inve_Bus BusMovi_Inven = new in_movi_inve_Bus();
                    //                    in_movi_inve_Info InfoMovi_Inven = new in_movi_inve_Info();

                    //InfoMovi_Inven  = BusMovi_Inven.Get_Info_Movi_inven(info.IdEmpresa, info.IdSucursal_movi_inven, info.IdBodega_movi_inven, info.IdMovi_inven_tipo, info.IdNumMovi);

                    in_Ing_Egr_Inven_Bus  Bus_Ing_Egre = new in_Ing_Egr_Inven_Bus();
                    in_Ing_Egr_Inven_Info Info_Ing_Egr = new in_Ing_Egr_Inven_Info();

                    Info_Ing_Egr = Bus_Ing_Egre.Get_Info_Ing_Egr_Inven(info.IdEmpresa, info.IdSucursal_movi_inven, info.IdMovi_inven_tipo, info.IdNumMovi);

                    Info_Ing_Egr.IdNumMovi    = 0;
                    Info_Ing_Egr.IdMotivo_Inv = 1;
                    if (InfoMovi_tipo.cm_tipo_movi == "-")// si es positivo hacer un egreso
                    {
                        Info_Ing_Egr.IdMovi_inven_tipo = Convert.ToInt32(InfoParametro.IdMovi_Inven_tipo_x_Dev_Inv_x_Erg);
                        Info_Ing_Egr.signo             = "+";
                    }
                    else
                    {
                        Info_Ing_Egr.IdMovi_inven_tipo = Convert.ToInt32(InfoParametro.IdMovi_Inven_tipo_x_Dev_Inv_x_Ing);
                        Info_Ing_Egr.signo             = "-";
                    }

                    Info_Ing_Egr.CodMoviInven   = "";
                    Info_Ing_Egr.cm_observacion = "Ing x Dev/Inv. " + info.observacion;
                    Info_Ing_Egr.cm_fecha       = info.Fecha.Date;//La fecha de devolución
                    Info_Ing_Egr.IdUsuario      = param.IdUsuario;
                    Info_Ing_Egr.Estado         = "A";

                    c = 0;


                    foreach (var item in info.lista_detalle)
                    {
                        c = c + 1;
                        in_movi_inve_detalle_Info info_det_movi = new in_movi_inve_detalle_Info();
                        in_movi_inve_detalle_Bus  bus_det_movi  = new in_movi_inve_detalle_Bus();
                        info_det_movi = bus_det_movi.Get_info_Movi_inven_det(item.IdEmpresa_movi_inv, item.IdSucursal_movi_inv, item.IdBodega_movi_inv, item.IdMovi_inven_tipo_movi_inv, item.IdNumMovi_movi_inv, item.Secuencia_movi_inv);

                        in_Ing_Egr_Inven_det_Info InfoDet_Ing_Egr = new in_Ing_Egr_Inven_det_Info();

                        InfoDet_Ing_Egr.IdEmpresa  = item.IdEmpresa;
                        InfoDet_Ing_Egr.IdSucursal = item.IdSucursal_movi_inv;
                        InfoDet_Ing_Egr.IdNumMovi  = 0;
                        InfoDet_Ing_Egr.Secuencia  = c;
                        InfoDet_Ing_Egr.IdBodega   = item.IdBodega_movi_inv;
                        InfoDet_Ing_Egr.IdProducto = info_det_movi.IdProducto;
                        if (Info_Ing_Egr.signo == "+")// si es positivo hacer un egreso
                        {
                            InfoDet_Ing_Egr.dm_cantidad_sinConversion = Math.Abs(item.cantidad_a_devolver);
                            InfoDet_Ing_Egr.dm_cantidad    = Math.Abs(item.cantidad_a_devolver);
                            InfoDet_Ing_Egr.IdEstadoAproba = "APRO";//Debe ir directamente aprobado para poder vincularlo al ing/egr que se va a devolver por cuestiones del recosteo
                        }
                        else
                        {
                            InfoDet_Ing_Egr.dm_cantidad_sinConversion = Math.Abs(item.cantidad_a_devolver);
                            InfoDet_Ing_Egr.dm_cantidad    = Math.Abs(item.cantidad_a_devolver) * -1;
                            InfoDet_Ing_Egr.IdEstadoAproba = "APRO";//Debe ir directamente aprobado para poder vincularlo al ing/egr que se va a devolver por cuestiones del recosteo
                        }

                        //Se pasa directamente el costo y unidad de medida convertido
                        InfoDet_Ing_Egr.mv_costo_sinConversion = (info_det_movi.mv_costo == null) ? 0 : Convert.ToDouble(info_det_movi.mv_costo);
                        InfoDet_Ing_Egr.mv_costo                     = (info_det_movi.mv_costo == null) ? 0 : Convert.ToDouble(info_det_movi.mv_costo);
                        InfoDet_Ing_Egr.IdUnidadMedida               = info_det_movi.IdUnidadMedida;
                        InfoDet_Ing_Egr.IdUnidadMedida_Consumo       = info_det_movi.IdUnidadMedida;
                        InfoDet_Ing_Egr.IdUnidadMedida_sinConversion = info_det_movi.IdUnidadMedida;

                        //Ingreso los id del detalle que esta devolviendo
                        InfoDet_Ing_Egr.IdEmpresa_dev         = item.IdEmpresa_movi_inv;
                        InfoDet_Ing_Egr.IdSucursal_dev        = item.IdSucursal_movi_inv;
                        InfoDet_Ing_Egr.IdBodega_dev          = item.IdBodega_movi_inv;
                        InfoDet_Ing_Egr.IdMovi_inven_tipo_dev = item.IdMovi_inven_tipo_movi_inv;
                        InfoDet_Ing_Egr.IdNumMovi_dev         = item.IdNumMovi_movi_inv;
                        InfoDet_Ing_Egr.Secuencia_dev         = item.Secuencia_movi_inv;

                        //Campos de egresos
                        InfoDet_Ing_Egr.IdPunto_cargo                  = info_det_movi.IdPunto_Cargo;
                        InfoDet_Ing_Egr.IdPunto_cargo_grupo            = info_det_movi.IdPunto_cargo_grupo;
                        InfoDet_Ing_Egr.IdCentroCosto                  = info_det_movi.IdCentroCosto;
                        InfoDet_Ing_Egr.IdCentroCosto_sub_centro_costo = info_det_movi.IdCentroCosto_sub_centro_costo;

                        Info_Ing_Egr.listIng_Egr.Add(InfoDet_Ing_Egr);
                    }

                    decimal IdNumMovi = 0;

                    Respuesta = Bus_Ing_Egre.GuardarDB(Info_Ing_Egr, ref IdNumMovi, ref mensaje);
                }


                return(Respuesta);
            }
            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_devolucion_inven_Bus)
                      };
            }
        }
        Boolean Genera_Inventario(in_Ingreso_x_OrdenCompra_Info info, decimal IdIngreso_oc, ref string msg)
        {
            try
            {
                //graba inventario
                in_movi_inve_Info info_MoviInve = new in_movi_inve_Info();

                info_MoviInve.IdEmpresa  = info.IdEmpresa;
                info_MoviInve.IdSucursal = info.IdSucursal;
                info_MoviInve.IdBodega   = info.IdBodega;

                int Idtipo = 0;
                com_parametro_Data odataParam     = new com_parametro_Data();
                com_parametro_Info list_parametro = new com_parametro_Info();

                list_parametro = odataParam.Get_Info_parametro(info.IdEmpresa);
                Idtipo         = list_parametro.IdMovi_inven_tipo_OC;

                if (list_parametro == null)
                {
                    msg = "No existen parámetros de compras";
                    return(false);
                }

                in_movi_inven_tipo_Info Info_moviInvTipo = new in_movi_inven_tipo_Info();
                in_movi_inven_tipo_Bus  bus_moviInvTipo  = new in_movi_inven_tipo_Bus();

                Info_moviInvTipo = bus_moviInvTipo.Get_Info_movi_inven_tipo(info.IdEmpresa, Idtipo);

                if (Info_moviInvTipo == null)
                {
                    msg = "No existen Tipos de Movimientos de Inventario";
                    return(false);
                }

                info_MoviInve.IdMovi_inven_tipo = Info_moviInvTipo.IdMovi_inven_tipo;
                info_MoviInve.CodMoviInven      = Info_moviInvTipo.Codigo;
                info_MoviInve.cm_tipo           = Info_moviInvTipo.cm_tipo_movi;

                info_MoviInve.cm_observacion = info.Observacion;
                info_MoviInve.cm_fecha       = info.Fecha_ing_bod;
                info_MoviInve.cm_anio        = info.Fecha_ing_bod.Year;
                info_MoviInve.cm_mes         = info.Fecha_ing_bod.Month;
                //info_MoviInve.IdCentroCosto = Convert.ToString(cmb_Centro_Costo.EditValue);
                //info_MoviInve.IdCentroCosto_sub_centro_costo = Convert.ToString(cmb_Sub_Centro_Costo.EditValue);
                info_MoviInve.IdProvedor = info.IdProveedor;

                //detalle
                List <in_movi_inve_detalle_Info> list_inveDet = new List <in_movi_inve_detalle_Info>();

                foreach (var item1 in info.listIngxOrdComDet)
                {
                    in_movi_inve_detalle_Info infoMovDet = new in_movi_inve_detalle_Info();

                    // infoMovDet.Checked = item.Checked;
                    infoMovDet.oc_IdEmpresa     = item1.IdEmpresa_oc;
                    infoMovDet.oc_IdSucursal    = item1.IdSucursal_oc;
                    infoMovDet.oc_IdOrdenCompra = item1.IdOrdenCompra;
                    // infoMovDet.oc_Secuencial = item1.secuencia_oc_det;
                    infoMovDet.oc_Secuencial  = item1.Secuencia_oc;
                    infoMovDet.IdProducto     = item1.IdProducto;
                    infoMovDet.dm_cantidad    = item1.Cant_a_recibir;
                    infoMovDet.dm_stock_ante  = item1.pr_stock;
                    infoMovDet.dm_stock_actu  = item1.pr_stock + item1.Cant_a_recibir;
                    infoMovDet.oc_observacion = info_MoviInve.cm_observacion;
                    infoMovDet.dm_precio      = item1.oc_precio;
                    infoMovDet.mv_costo       = item1.oc_precio;// se coloca el costo de la OC de la columna precio de compra
                    infoMovDet.peso           = item1.pr_peso;
                    infoMovDet.IdCentroCosto  = item1.IdCentroCosto;
                    infoMovDet.IdCentroCosto_sub_centro_costo = item1.IdCentroCosto_sub_centro_costo;
                    infoMovDet.nom_producto = item1.nom_producto;

                    list_inveDet.Add(infoMovDet);
                }

                info_MoviInve.listmovi_inve_detalle_Info = list_inveDet;

                //detalle

                in_movi_inve_Bus bus_MovInve = new in_movi_inve_Bus();
                decimal          idMoviInven;
                idMoviInven = 0;
                string mensaje_cbte_cble = "";

                if (bus_MovInve.GrabarDB(info_MoviInve, ref idMoviInven, ref mensaje, ref mensaje_cbte_cble))
                {
                    //grabando tabla intermedia  in_movi_inve_detalle_x_com_ordencompra_local_det

                    #region grabando tabla intermedia  in_movi_inve_detalle_x_com_ordencompra_local_det

                    List <in_movi_inve_detalle_Info> listMovInvDet = new List <in_movi_inve_detalle_Info>();
                    in_movi_inve_detalle_Bus         bus_MovInvDet = new in_movi_inve_detalle_Bus();
                    listMovInvDet = bus_MovInvDet.Get_list_Movi_inven_det(info_MoviInve.IdEmpresa, info_MoviInve.IdSucursal, info_MoviInve.IdBodega, info_MoviInve.IdMovi_inven_tipo, idMoviInven);

                    List <in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info> listIngComp = new List <in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info>();
                    List <in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info> listOrdComp = new List <in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info>();

                    in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info info1;

                    foreach (var item2 in listMovInvDet)
                    {
                        info1 = new in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info();

                        info1.mi_IdEmpresa         = item2.IdEmpresa;
                        info1.mi_IdSucursal        = item2.IdSucursal;
                        info1.mi_IdBodega          = item2.IdBodega;
                        info1.mi_IdMovi_inven_tipo = item2.IdMovi_inven_tipo;
                        info1.mi_IdNumMovi         = item2.IdNumMovi;
                        info1.mi_Secuencia         = item2.Secuencia;

                        listIngComp.Add(info1);
                    }

                    //  foreach (var item in ListaBind)
                    foreach (var item3 in info_MoviInve.listmovi_inve_detalle_Info)
                    {
                        info1 = new in_movi_inve_detalle_x_com_ordencompra_local_detalle_Info();

                        //if (item3.Checked == true)
                        //{
                        info1.ocd_IdEmpresa  = item3.IdEmpresa;
                        info1.ocd_IdSucursal = item3.IdSucursal;
                        //  info1.ocd_IdOrdenCompra = item3.IdOrdenCompra;
                        info1.ocd_IdOrdenCompra = item3.oc_IdOrdenCompra;
                        info1.ocd_Secuencia     = item3.oc_Secuencial;

                        listOrdComp.Add(info1);

                        //}
                    }

                    int     ocd_IdEmpresa     = 0;
                    int     ocd_IdSucursal    = 0;
                    decimal ocd_IdOrdenCompra = 0;
                    int     ocd_Secuencia     = 0;

                    foreach (var item4 in listIngComp)
                    {
                        var items = listOrdComp.First(v => v.mi_IdEmpresa == 0 && v.mi_IdSucursal == 0 && v.mi_IdBodega == 0 && v.mi_IdMovi_inven_tipo == 0 && v.mi_IdNumMovi == 0 && v.mi_Secuencia == 0);
                        ocd_IdEmpresa     = items.ocd_IdEmpresa;
                        ocd_IdSucursal    = items.ocd_IdSucursal;
                        ocd_IdOrdenCompra = items.ocd_IdOrdenCompra;
                        ocd_Secuencia     = items.ocd_Secuencia;

                        listOrdComp.Remove(items);

                        item4.ocd_IdEmpresa     = ocd_IdEmpresa;
                        item4.ocd_IdSucursal    = ocd_IdSucursal;
                        item4.ocd_IdOrdenCompra = ocd_IdOrdenCompra;
                        item4.ocd_Secuencia     = ocd_Secuencia;
                    }

                    in_movi_inve_detalle_x_com_ordencompra_local_detalle_Bus bus_Inter = new in_movi_inve_detalle_x_com_ordencompra_local_detalle_Bus();

                    if (bus_Inter.GrabarDB(listIngComp, ref mensaje))
                    {
                    }

                    // consulta grid contable

                    //info_InMovxCble = new in_movi_inve_x_ct_cbteCble_Info();
                    //info_InMovxCble = bus_InMovxCble.Obtener_x_Movi_Inven(Info_MoviInve.IdEmpresa, Info_MoviInve.IdSucursal, Info_MoviInve.IdBodega, Info_MoviInve.IdMovi_inven_tipo, idMoviInven);

                    //this.ucCon_GridDiarioContable1.setInfo(info_InMovxCble.IdEmpresa, info_InMovxCble.IdTipoCbte, info_InMovxCble.IdCbteCble);

                    #endregion

                    // actualizando los item de movimiento en tabla in_Ingreso_x_OrdenCompra

                    // consulta in_Ingreso_x_OrdenCompra
                    in_Ingreso_x_OrdenCompra_Info infoIngxComp = new in_Ingreso_x_OrdenCompra_Info();
                    infoIngxComp = odata.Get_Info_Ingreso_x_OrdenCompra(info.IdEmpresa, IdIngreso_oc);

                    // consulta in_movi_inve
                    in_movi_inve_Bus  bus_MovInv = new in_movi_inve_Bus();
                    in_movi_inve_Info infoMovInv = new in_movi_inve_Info();
                    infoMovInv = bus_MovInv.Get_Info_Movi_inven(info_MoviInve.IdEmpresa, info_MoviInve.IdSucursal, info_MoviInve.IdBodega, info_MoviInve.IdMovi_inven_tipo, idMoviInven);

                    // actualizar item Movimientos en in_Ingreso_x_OrdenCompra

                    infoIngxComp.IdEmpresa_mIinv        = infoMovInv.IdEmpresa;
                    infoIngxComp.IdSucursal_mInv        = infoMovInv.IdSucursal;
                    infoIngxComp.IdBodega_mInv          = infoMovInv.IdBodega;
                    infoIngxComp.IdMovi_inven_tipo_mInv = infoMovInv.IdMovi_inven_tipo;
                    infoIngxComp.IdNumMovi_mInv         = infoMovInv.IdNumMovi;

                    string msgs = "";
                    // odata.ModificarCabecera(infoIngxComp, ref msgs);
                }

                else
                {
                    msg = mensaje + "-" + mensaje_cbte_cble;
                    return(false);
                }

                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("", "Genera_Inventario", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ingreso_x_OrdenCompra_Bus)
                      };
            }
        }
示例#5
0
        public Boolean AnularDB(in_Ing_Egr_Inven_Info info, ref string msgs)
        {
            try
            {
                in_Ing_Egr_Inven_det_Bus         BusDeta_Ing_Egr_Inven     = new in_Ing_Egr_Inven_det_Bus();
                List <in_Ing_Egr_Inven_det_Info> ListDet_Ing_Egr_Inven_det = new List <in_Ing_Egr_Inven_det_Info>();
                Boolean Respuesta_anulacion            = false;
                Boolean Respuesta_anulacion_Inventario = false;

                in_movi_inven_tipo_Info info_movi_inven_tipo = new in_movi_inven_tipo_Info();
                in_movi_inven_tipo_Bus  bus_movi_inven_tipo  = new in_movi_inven_tipo_Bus();
                info_movi_inven_tipo = bus_movi_inven_tipo.Get_Info_movi_inven_tipo(info.IdEmpresa, info.IdMovi_inven_tipo);

                in_Motivo_Inven_Info info_motivo_inven = new in_Motivo_Inven_Info();
                in_Motivo_Inven_Bus  bus_motivo_inven  = new in_Motivo_Inven_Bus();
                info_motivo_inven = bus_motivo_inven.Get_Info_Motivo_Inven(info.IdEmpresa, info.IdMotivo_Inv == null ? 0 : Convert.ToInt32(info.IdMotivo_Inv));

                string genero_movi = info_movi_inven_tipo.Genera_Movi_Inven == true && info_motivo_inven.Genera_Movi_Inven == "S" ? "S" : "N";

                odata.Reversar_Aprobacion(info.IdEmpresa, info.IdSucursal, info.IdMovi_inven_tipo, info.IdNumMovi, genero_movi);

                Respuesta_anulacion = odata.AnularDB(info, ref msgs);

                if (Respuesta_anulacion)
                {
                    ListDet_Ing_Egr_Inven_det = BusDeta_Ing_Egr_Inven.Get_List_Ing_Egr_Inven_det_x_Num_Movimiento(info.IdEmpresa, info.IdSucursal, info.IdMovi_inven_tipo, info.IdNumMovi);

                    in_movi_inve_Bus  BusMovi_Inven           = new in_movi_inve_Bus();
                    in_movi_inve_Info Info_movi_inve_a_Anular = new in_movi_inve_Info();

                    foreach (var item in ListDet_Ing_Egr_Inven_det)
                    {
                        if (item.IdNumMovi_inv != null)
                        {
                            Info_movi_inve_a_Anular = new in_movi_inve_Info();

                            Info_movi_inve_a_Anular = BusMovi_Inven.Get_Info_Movi_inven(Convert.ToInt32(item.IdEmpresa_inv), Convert.ToInt32(item.IdSucursal_inv), Convert.ToInt32(item.IdBodega_inv), Convert.ToInt32(item.IdMovi_inven_tipo_inv), Convert.ToDecimal(item.IdNumMovi_inv));
                            if (Info_movi_inve_a_Anular != null)
                            {
                                if (Info_movi_inve_a_Anular.IdEmpresa != 0)
                                {
                                    Respuesta_anulacion_Inventario = BusMovi_Inven.AnularDB(Info_movi_inve_a_Anular, DateTime.Now, ref msgs);
                                }
                                else
                                {
                                    Respuesta_anulacion_Inventario = true;//por que puede q no haya movi invent
                                }
                            }
                        }
                        else
                        {
                            Respuesta_anulacion_Inventario = true;
                        }
                    }
                }

                //Agrupo lista de ordenes de compra
                var lst_oc = (from q in ListDet_Ing_Egr_Inven_det
                              where q.IdOrdenCompra != null
                              group q by new { q.IdEmpresa_oc, q.IdSucursal_oc, q.IdOrdenCompra }
                              into grouping
                              select new { grouping.Key.IdEmpresa_oc, grouping.Key.IdSucursal_oc, grouping.Key.IdOrdenCompra }
                              ).ToList();

                BusDeta_Ing_Egr_Inven.Modificar_Enserar_Campos_OC(ListDet_Ing_Egr_Inven_det);

                foreach (var item in lst_oc)
                {
                    bus_oc.Modificar_Estado_Cierre(Convert.ToInt32(item.IdEmpresa_oc), Convert.ToInt32(item.IdSucursal_oc), Convert.ToInt32(item.IdOrdenCompra), "ABI");
                }

                return(Respuesta_anulacion && Respuesta_anulacion_Inventario);
            }
            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("", "AnularDB", ex.Message), ex)
                      {
                          EntityType = typeof(in_Ing_Egr_Inven_Bus)
                      };
            }
        }