public bool ModificarDB(cp_orden_giro_Info InfoOrdenGiro_I, ref string msg)
        {
            Boolean res = true;

            try
            {
                cp_orden_giro_Info info = new cp_orden_giro_Info();
                info.IdEmpresa        = InfoOrdenGiro_I.IdEmpresa;
                info.IdTipoCbte_Ogiro = InfoOrdenGiro_I.IdTipoCbte_Ogiro;
                info.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro;

                cp_orden_giro_Data odata = new cp_orden_giro_Data();

                info = odata.Get_Info_orden_giro(info);

                if (info.co_serie == InfoOrdenGiro_I.co_serie && info.co_factura == InfoOrdenGiro_I.co_factura)
                {
                    // no valido
                }
                else
                {
                    //valido
                    if (data.ExisteFacturaPorProveedor(InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdProveedor, InfoOrdenGiro_I.co_serie, InfoOrdenGiro_I.co_factura))
                    {
                        msg = "La Factura#: " + InfoOrdenGiro_I.co_serie + "-" + InfoOrdenGiro_I.co_factura + ". Ya se encuentra ingresada";
                        res = false;
                        return(false);
                    }
                }


                //diario contable x OG
                if (CbteCble_B.ModificarDB(InfoOrdenGiro_I.Info_CbteCble_x_OG, ref msg))
                {
                    //OG
                    cp_orden_giro_Data OdataOG = new cp_orden_giro_Data();
                    if (OdataOG.ModificarDB(InfoOrdenGiro_I, ref msg))
                    {
                        #region reembolso formaspago y retenciones

                        InfoOrdenGiro_I.lst_formasPagoSRI.ForEach(p => { p.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro; p.IdTipoCbte_Ogiro = InfoOrdenGiro_I.IdTipoCbte_Ogiro; });
                        if (!pagoSRI_B.ModificarDB(InfoOrdenGiro_I.lst_formasPagoSRI, InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdCbteCble_Ogiro, InfoOrdenGiro_I.IdTipoCbte_Ogiro, ref msg))
                        {
                            msg = "No se pudo Modificar la(s) forma(s) de pago \n Comuníquese con sistemas por favor";
                            res = false;
                        }



                        if (InfoOrdenGiro_I.Info_Retencion != null && InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT != null)
                        {
                            if (InfoOrdenGiro_I.Info_Retencion.IdEmpresa != 0)
                            {
                                //  Verificar Retencion
                                cp_retencion_Bus bus_Reten = new cp_retencion_Bus();
                                if (bus_Reten.Existe_Retencion(InfoOrdenGiro_I.Info_Retencion.IdEmpresa, InfoOrdenGiro_I.Info_Retencion.IdRetencion))
                                {
                                    //Modifica
                                    if (!Bus_Retencion.ModificarDB(InfoOrdenGiro_I.Info_Retencion, InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT, ref msg))
                                    {
                                        msg = "No se pudo Actualizar las retenciones"; res = false;
                                    }
                                }
                                else
                                {
                                    InfoOrdenGiro_I.Info_Retencion.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro;



                                    if (Bus_Retencion.Graba_CbteCble_Ret_FactProveedor(InfoOrdenGiro_I.Info_Retencion, InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT, ref mensaje))
                                    {
                                        //actualizando el suencial de la retencion serie y #retencion
                                        Bus_Retencion.Modificar_Num_Retencion(InfoOrdenGiro_I.Info_Retencion, ref mensaje);
                                    }
                                    else
                                    {
                                        mensaje = "Hubo un inconveniente al ingresar la retención comuniquese con sistemas.." + mensaje; res = false;
                                    }
                                }
                            }
                        }


                        #endregion

                        if (InfoOrdenGiro_I.Info_cuotas_x_doc.lst_cuotas_det.Count != 0)
                        {
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdEmpresa_ct = InfoOrdenGiro_I.IdEmpresa;
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdTipoCbte   = InfoOrdenGiro_I.IdTipoCbte_Ogiro;
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdCbteCble   = InfoOrdenGiro_I.IdCbteCble_Ogiro;
                            bus_cuotas_x_doc.GuardarDB(InfoOrdenGiro_I.Info_cuotas_x_doc);
                        }


                        msg = "La Fact. Proveedor # " + InfoOrdenGiro_I.IdCbteCble_Ogiro + " se modificó Exitósamente";
                    }
                }
            }
            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("", "ModificarFacturaProveedor", ex.Message), ex)
                      {
                          EntityType = typeof(cp_orden_giro_Bus)
                      };
            }
            return(res);
        }
Exemple #2
0
        public bool ModificarDB(cp_orden_giro_Info InfoOrdenGiro_I, ref string msg)
        {
            Boolean res = true;

            try
            {
                cp_orden_giro_Info info = new cp_orden_giro_Info();
                info.IdEmpresa        = InfoOrdenGiro_I.IdEmpresa;
                info.IdTipoCbte_Ogiro = InfoOrdenGiro_I.IdTipoCbte_Ogiro;
                info.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro;

                cp_orden_giro_Data odata = new cp_orden_giro_Data();

                info = odata.Get_Info_orden_giro(info);

                if (info.co_serie == InfoOrdenGiro_I.co_serie && info.co_factura == InfoOrdenGiro_I.co_factura)
                {
                    // no valido
                }
                else
                {
                    //valido
                    if (data.ExisteFacturaPorProveedor(InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdProveedor, InfoOrdenGiro_I.co_serie, InfoOrdenGiro_I.co_factura))
                    {
                        msg = "La Factura#: " + InfoOrdenGiro_I.co_serie + "-" + InfoOrdenGiro_I.co_factura + ". Ya se encuentra ingresada";
                        res = false;
                        return(false);
                    }
                }


                //diario contable x OG
                if (CbteCble_B.ModificarDB(InfoOrdenGiro_I.Info_CbteCble_x_OG, ref msg))
                {
                    //OG
                    cp_orden_giro_Data OdataOG = new cp_orden_giro_Data();
                    if (OdataOG.ModificarDB(InfoOrdenGiro_I, ref msg))
                    {
                        #region reembolso formaspago y retenciones
                        InfoOrdenGiro_I.lst_reembolso.ForEach(p => { p.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro; p.IdTipoCbte_Ogiro = InfoOrdenGiro_I.IdTipoCbte_Ogiro; });

                        if (!Reem_B.ModificarLst(InfoOrdenGiro_I.lst_reembolso, InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdCbteCble_Ogiro, InfoOrdenGiro_I.IdTipoCbte_Ogiro))
                        {
                            msg = "No se pudo Modificar lo(s) reembolso(s) \n Comuníquese con sistemas por favor";

                            res = false;
                        }
                        InfoOrdenGiro_I.lst_formasPagoSRI.ForEach(p => { p.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro; p.IdTipoCbte_Ogiro = InfoOrdenGiro_I.IdTipoCbte_Ogiro; });
                        if (!pagoSRI_B.ModificarDB(InfoOrdenGiro_I.lst_formasPagoSRI, InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdCbteCble_Ogiro, InfoOrdenGiro_I.IdTipoCbte_Ogiro, ref msg))
                        {
                            msg = "No se pudo Modificar la(s) forma(s) de pago \n Comuníquese con sistemas por favor";
                            res = false;
                        }



                        if (InfoOrdenGiro_I.Info_Retencion != null && InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT != null)
                        {
                            if (InfoOrdenGiro_I.Info_Retencion.IdEmpresa != 0)
                            {
                                //  Verificar Retencion
                                cp_retencion_Bus bus_Reten = new cp_retencion_Bus();
                                if (bus_Reten.Existe_Retencion(InfoOrdenGiro_I.Info_Retencion.IdEmpresa, InfoOrdenGiro_I.Info_Retencion.IdRetencion))
                                {
                                    //Modifica
                                    if (!Bus_Retencion.ModificarDB(InfoOrdenGiro_I.Info_Retencion, InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT, ref msg))
                                    {
                                        msg = "No se pudo Actualizar las retenciones"; res = false;
                                    }
                                }
                                else
                                {
                                    InfoOrdenGiro_I.Info_Retencion.IdCbteCble_Ogiro = InfoOrdenGiro_I.IdCbteCble_Ogiro;



                                    if (Bus_Retencion.Graba_CbteCble_Ret_FactProveedor(InfoOrdenGiro_I.Info_Retencion, InfoOrdenGiro_I.Info_Retencion.Info_CbteCble_x_RT, ref mensaje))
                                    {
                                        //actualizando el suencial de la retencion serie y #retencion
                                        Bus_Retencion.Modificar_Num_Retencion(InfoOrdenGiro_I.Info_Retencion, ref mensaje);
                                    }
                                    else
                                    {
                                        mensaje = "Hubo un inconveniente al ingresar la retención comuniquese con sistemas.." + mensaje; res = false;
                                    }
                                }
                            }
                        }


                        #endregion

                        if (InfoOrdenGiro_I.Info_cuotas_x_doc.lst_cuotas_det.Count != 0)
                        {
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdEmpresa_ct = InfoOrdenGiro_I.IdEmpresa;
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdTipoCbte   = InfoOrdenGiro_I.IdTipoCbte_Ogiro;
                            InfoOrdenGiro_I.Info_cuotas_x_doc.IdCbteCble   = InfoOrdenGiro_I.IdCbteCble_Ogiro;
                            bus_cuotas_x_doc.GuardarDB(InfoOrdenGiro_I.Info_cuotas_x_doc);
                        }

                        List <imp_ordencompra_ext_x_ct_cbtecble_Info> Tab_Int = ocXcbt_B.Get_List_ordencompra_ext_x_ct_cbtecble(InfoOrdenGiro_I.IdEmpresa, InfoOrdenGiro_I.IdTipoCbte_Ogiro,
                                                                                                                                InfoOrdenGiro_I.IdCbteCble_Ogiro, ref msg);
                        if (Tab_Int == null || Tab_Int.Count < 1)
                        {
                            #region
                            if (InfoOrdenGiro_I.LstImportacionGrid.Count() > 0)
                            {
                                InfoOrdenGiro_I.LstImportacionGrid.ForEach(p => p.IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);

                                if (ocXgastosxImp_B.GuardarDB(InfoOrdenGiro_I.LstImportacionGrid, ref mensaje))
                                {
                                    InfoOrdenGiro_I.LstocXcbt_I.ForEach(p => p.ct_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);
                                    if (ocXcbt_B.GuardarDB(InfoOrdenGiro_I.LstocXcbt_I, ref mensaje))
                                    {
                                        InfoOrdenGiro_I.LisImportacion.ForEach(p => p.og_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);
                                        if (Importacion_B.GrabarDB(InfoOrdenGiro_I.LisImportacion, ref mensaje))
                                        {
                                            InfoOrdenGiro_I.LstImportacionOC.ForEach(p => p.og_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);

                                            if (!OC_B.GrabarDB(InfoOrdenGiro_I.LstImportacionOC, ref mensaje))
                                            {
                                                mensaje = "Hubo un inconveniente al ingresar la importación comuniquese con sistemas.." + mensaje; res = false;
                                            }
                                        }
                                        else
                                        {
                                            mensaje = "Hubo un inconveniente al ingresar la importación comuniquese con sistemas.." + mensaje; res = false;
                                        }
                                    }
                                    else
                                    {
                                        mensaje = "Hubo un inconveniente al ingresar la importación comuniquese con sistemas.." + mensaje; res = false;
                                    }
                                }
                                else
                                {
                                    mensaje = "Hubo un inconveniente al ingresar la importación comuniquese con sistemas.." + mensaje; res = false;
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            List <imp_ordencompra_ext_x_imp_gastosxImport_Info> a = ocXgastosxImp_B.Get_List_ordencompra_ext_x_imp_gastosxImport(Tab_Int[0].imp_IdEmpresa,
                                                                                                                                                 Tab_Int[0].imp_IdSucusal, Tab_Int[0].imp_IdOrdenCompraExt);
                            List <imp_ordencompra_ext_x_imp_gastosxImport_Info> b = new List <imp_ordencompra_ext_x_imp_gastosxImport_Info>();
                            if (a != null)
                            {
                                b = a.FindAll(q => Convert.ToInt32(q.IdTipoCbte) == InfoOrdenGiro_I.IdTipoCbte_Ogiro &&
                                              Convert.ToDecimal(q.IdCbteCble) == InfoOrdenGiro_I.IdCbteCble_Ogiro);
                            }
                            //eliminar tabla intermedia
                            ocXcbt_B.EliminarDB(Tab_Int[0].ct_IdEmpresa, Tab_Int[0].ct_IdCbteCble, Tab_Int[0].ct_IdTipoCbte);
                            imp_ordencompra_ext_x_imp_gastosxImport_Det_Bus detBus = new imp_ordencompra_ext_x_imp_gastosxImport_Det_Bus();

                            foreach (imp_ordencompra_ext_x_imp_gastosxImport_Info item in b)
                            {
                                if (!detBus.EliminarDB(item, ref msg))
                                {
                                    return(false);
                                }

                                if (!ocXgastosxImp_B.EliminarDB(item.IdEmpresa, item.IdSucusal, item.IdOrdenCompraExt, item.IdRegistroGasto, ref msg))
                                {
                                    return(false);
                                }
                            }
                            if (InfoOrdenGiro_I.LstImportacionGrid.Count() > 0)
                            {
                                InfoOrdenGiro_I.LstImportacionGrid.ForEach(p => p.IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);

                                if (!ocXgastosxImp_B.GuardarDB(InfoOrdenGiro_I.LstImportacionGrid, ref mensaje))
                                {
                                    return(false);
                                }

                                InfoOrdenGiro_I.LstocXcbt_I.ForEach(p => p.ct_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);

                                if (!ocXcbt_B.GuardarDB(InfoOrdenGiro_I.LstocXcbt_I, ref mensaje))
                                {
                                    return(false);
                                }

                                var d = Importacion_B.Get_List_orden_giro_x_imp_ordencompra_ext(Tab_Int[0].ct_IdEmpresa, Tab_Int[0].ct_IdCbteCble, Tab_Int[0].ct_IdTipoCbte);
                                if (d != null)
                                {
                                    Importacion_B.EliminarDB(d);
                                    InfoOrdenGiro_I.LisImportacion.ForEach(p => p.og_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);
                                    if (!Importacion_B.GrabarDB(InfoOrdenGiro_I.LisImportacion, ref mensaje))
                                    {
                                        return(false);
                                    }
                                    var e = OC_B.Get_List_orden_giro_x_com_ordencompra_local(Tab_Int[0].ct_IdEmpresa, Tab_Int[0].ct_IdCbteCble, Tab_Int[0].ct_IdTipoCbte);
                                    if (e != null)
                                    {
                                        OC_B.EliminarLista(e);
                                        InfoOrdenGiro_I.LstImportacionOC.ForEach(p => p.og_IdCbteCble = InfoOrdenGiro_I.IdCbteCble_Ogiro);
                                        if (!OC_B.GrabarDB(InfoOrdenGiro_I.LstImportacionOC, ref mensaje))
                                        {
                                            mensaje = "Hubo un inconveniente al ingresar la importación comuniquese con sistemas.." + mensaje; res = false;
                                        }
                                    }
                                }
                                //}
                            }
                        }


                        msg = "La Fact. Proveedor # " + InfoOrdenGiro_I.IdCbteCble_Ogiro + " se modificó Exitósamente";
                    }
                }
            }
            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("", "ModificarFacturaProveedor", ex.Message), ex)
                      {
                          EntityType = typeof(cp_orden_giro_Bus)
                      };
            }
            return(res);
        }