public Boolean GenerarDiario(int IdEmpresa, int IdSucursal, decimal IdRegistroGasto, ref string msg, ref decimal idCbteCble, ref string CodTipod)
        {
            try{
                #region Declaracion
                ct_Periodo_Info  Per_I      = new ct_Periodo_Info();
                ct_Cbtecble_Info CbteCble_I = new ct_Cbtecble_Info();
                List <imp_ordencompra_ext_x_imp_gastosxImport_Det_Info> ListaDetalle  = new List <imp_ordencompra_ext_x_imp_gastosxImport_Det_Info>();
                imp_gastosximport_x_empresa_Data                    BusGastosXEmpresa = new imp_gastosximport_x_empresa_Data();
                List <imp_gastosximport_x_empresa_Info>             lstGastosXEmpresa = new List <imp_gastosximport_x_empresa_Info>();
                List <imp_ordencompra_ext_x_imp_gastosxImport_Info> Lst   = new List <imp_ordencompra_ext_x_imp_gastosxImport_Info>();
                imp_ordencompra_ext_x_imp_gastosxImport_Info        _Info = new imp_ordencompra_ext_x_imp_gastosxImport_Info();
                int                         IdTipoCbte   = 0;
                ba_Cbte_Ban_Bus             BusCbteBanco = new ba_Cbte_Ban_Bus();
                ct_Periodo_Data             Per_B        = new ct_Periodo_Data();
                List <ct_Cbtecble_det_Info> LstCbteCble  = new List <ct_Cbtecble_det_Info>();
                cl_parametrosGenerales_Bus  param        = cl_parametrosGenerales_Bus.Instance;
                ba_Cbte_Ban_Info            CbteBan_I    = new ba_Cbte_Ban_Info();
                string                      MensajeError = "";
                #endregion
                #region ObtenerGastoImportacion
                Lst = Get_List_ordencompra_ext_x_imp_gastosxImport_Para_Contabilizar(IdEmpresa, IdSucursal, IdRegistroGasto);
                foreach (var item in Lst)
                {
                    _Info.IdOrdenCompraExt  = item.IdOrdenCompraExt;
                    _Info.IdProveedor       = item.IdProveedor;
                    _Info.IdEmpresa         = item.IdEmpresa;
                    _Info.IdSucusal         = item.IdSucusal;
                    _Info.IdRegistroGasto   = item.IdRegistroGasto;
                    _Info.Observacion       = item.Observacion;
                    _Info.IdCtaCble_Banco   = item.IdCtaCble_Banco;
                    _Info.IdBanco           = item.IdBanco;
                    _Info.CodOrdenCompraExt = item.CodOrdenCompraExt;
                    IdTipoCbte  = item.IdTipoCbte;
                    _Info.Fecha = item.Fecha;
                    _Info.IdCtaCble_Importacion = item.IdCtaCble_Importacion;

                    imp_ordencompra_ext_x_imp_gastosxImport_Det_Info Det = new imp_ordencompra_ext_x_imp_gastosxImport_Det_Info();
                    Det.IdGastoImp = item.IdGastoImp;
                    Det.Valor      = item.Valor;
                    _Info.ListaGastos.Add(Det);
                }
                #endregion
                Per_I             = Per_B.Get_Info_Periodo(_Info.IdEmpresa, _Info.Fecha, ref MensajeError);
                lstGastosXEmpresa = BusGastosXEmpresa.Get_List_gastosximport_x_empresa(IdEmpresa);
                var DatosDiario = from p in _Info.ListaGastos
                                  join w in lstGastosXEmpresa
                                  on new { p.IdGastoImp } equals new { w.IdGastoImp }
                select new { p.IdGastoImp, w.IdCtaCble, p.Valor, w.debCre_Provicion, w.debcre_DebBanco };

                if (DatosDiario.ToList().Count != _Info.ListaGastos.Count)
                {
                    msg = "No existen parametros contables verifique que los parametros Contables Esten Llenados correctametne /n Comunicarce Cons sistemas";
                    return(false);
                }
                #region CbteCble_Detalle
                foreach (var item in DatosDiario)
                {
                    ct_Cbtecble_det_Info obj = new ct_Cbtecble_det_Info();
                    obj.dc_Observacion = "Cont. X gastos De Imp " + _Info.CodOrdenCompraExt + " / " + _Info.IdOrdenCompraExt + " / " + _Info.Observacion + " / " + Get_Descripcion(item.IdGastoImp);
                    obj.IdCtaCble      = item.IdCtaCble;
                    obj.IdTipoCbte     = IdTipoCbte;
                    obj.IdEmpresa      = _Info.IdEmpresa;
                    if (CodTipod == "DEBBAN")
                    {
                        if (item.debcre_DebBanco == "C")
                        {
                            obj.dc_Valor = item.Valor * -1;
                        }
                        else
                        {
                            obj.dc_Valor = item.Valor;
                        }
                    }
                    if (CodTipod == "PROVI")
                    {
                        if (item.debcre_DebBanco == "D")
                        {
                            obj.dc_Valor = item.Valor * -1;
                        }
                        else
                        {
                            obj.dc_Valor = item.Valor;
                        }
                    }
                    LstCbteCble.Add(obj);
                }
                ct_Cbtecble_det_Info obj2 = new ct_Cbtecble_det_Info();
                double Valor = 0;
                foreach (var item in _Info.ListaGastos)
                {
                    Valor = Valor + item.Valor;
                }
                obj2.dc_Observacion = "Cont. X gastos De Imp " + _Info.CodOrdenCompraExt + " / " + _Info.IdOrdenCompraExt + " / " + _Info.Observacion + " / Importacion";
                obj2.IdCtaCble      = _Info.IdCtaCble_Banco;
                obj2.IdTipoCbte     = IdTipoCbte;
                obj2.IdEmpresa      = _Info.IdEmpresa;
                ba_Banco_Cuenta_Bus B_banco = new ba_Banco_Cuenta_Bus();
                var Banco = B_banco.Get_Info_Banco_Cuenta(param.IdEmpresa, _Info.IdBanco);
                if (CodTipod == "DEBBAN")
                {
                    obj2.IdCtaCble = Banco.IdCtaCble;
                    obj2.dc_Valor  = Valor * -1;
                }
                if (CodTipod == "PROVI")
                {
                    obj2.IdCtaCble = _Info.IdCtaCble_Importacion;
                    obj2.dc_Valor  = Valor;
                }
                LstCbteCble.Add(obj2);
                #endregion
                #region CbteCble
                CbteCble_I.IdEmpresa  = _Info.IdEmpresa;
                CbteCble_I.IdTipoCbte = IdTipoCbte;
                CbteCble_I.IdPeriodo  = Per_I.IdPeriodo;
                CbteCble_I.cb_Fecha   = Convert.ToDateTime(_Info.Fecha.ToShortDateString());
                CbteCble_I.cb_Valor   = Valor;
                if (CodTipod == "DEBBAN")
                {
                    CbteCble_I.CodCbteCble = "DEBBAN";
                }
                if (CodTipod == "PROVI")
                {
                    CbteCble_I.CodCbteCble = "PROVI";
                }
                CbteCble_I.cb_Observacion           = "Cont. X Imp. " + _Info.CodOrdenCompraExt + " / " + _Info.IdOrdenCompraExt + "Gastos de Importacion. / " + _Info.Observacion;
                CbteCble_I.Secuencia                = 0;
                CbteCble_I.Estado                   = "A";
                CbteCble_I.Anio                     = _Info.Fecha.Year;
                CbteCble_I.Mes                      = _Info.Fecha.Month;
                CbteCble_I.IdUsuario                = param.IdUsuario;
                CbteCble_I.IdUsuarioUltModi         = param.IdUsuario;
                CbteCble_I.cb_FechaTransac          = param.GetDateServer();
                CbteCble_I.cb_FechaUltModi          = param.GetDateServer();
                CbteCble_I.Mayorizado               = "N";
                CbteCble_I._cbteCble_det_lista_info = LstCbteCble;
                // decimal idCbteCble = 0;
                string          cod_CbteCble = "";
                ct_Cbtecble_Bus CbteCble_B   = new ct_Cbtecble_Bus();
                if (CbteCble_B.GrabarDB(CbteCble_I, ref idCbteCble, ref msg) == false)
                {
                    return(false);
                }
                oData.ModificarDB(_Info, idCbteCble);
                #endregion
                if (CodTipod == "DEBBAN")
                {
                    #region CbteBan_I
                    CbteBan_I.IdEmpresa       = param.IdEmpresa;
                    CbteBan_I.IdTipocbte      = IdTipoCbte;
                    CbteBan_I.IdCbteCble      = idCbteCble;
                    CbteBan_I.Cod_Cbtecble    = cod_CbteCble;
                    CbteBan_I.IdPeriodo       = Per_I.IdPeriodo;
                    CbteBan_I.IdBanco         = _Info.IdBanco;
                    CbteBan_I.cb_Fecha        = Convert.ToDateTime(_Info.Fecha.ToShortDateString());
                    CbteBan_I.cb_Observacion  = _Info.Observacion.Trim();
                    CbteBan_I.cb_Valor        = Valor;
                    CbteBan_I.Estado          = "A";
                    CbteBan_I.IdUsuario       = param.IdUsuario;
                    CbteBan_I.IdUsuario_Anu   = param.IdUsuario;
                    CbteBan_I.FechaAnulacion  = param.Fecha_Transac;
                    CbteBan_I.Fecha_Transac   = param.Fecha_Transac;
                    CbteBan_I.Fecha_UltMod    = param.Fecha_Transac;
                    CbteBan_I.IdUsuarioUltMod = param.IdUsuario;
                    CbteBan_I.ip     = param.ip;
                    CbteBan_I.nom_pc = param.nom_pc;
                    if (BusCbteBanco.GrabarDB(CbteBan_I, ref MensajeError) == false)
                    {
                        return(false);
                    }
                    #endregion
                }
                imp_ordencompra_ext_x_ct_cbtecble_Data DataOrdxCbt         = new imp_ordencompra_ext_x_ct_cbtecble_Data();
                imp_ordencompra_ext_x_ct_cbtecble_Info ordCompraxCbte_info = new imp_ordencompra_ext_x_ct_cbtecble_Info();
                ordCompraxCbte_info.ct_IdEmpresa         = ordCompraxCbte_info.imp_IdEmpresa = _Info.IdEmpresa;
                ordCompraxCbte_info.imp_IdOrdenCompraExt = _Info.IdOrdenCompraExt;
                ordCompraxCbte_info.imp_IdSucusal        = _Info.IdSucusal;
                ordCompraxCbte_info.ct_IdTipoCbte        = IdTipoCbte;
                ordCompraxCbte_info.ct_IdCbteCble        = idCbteCble;
                ordCompraxCbte_info.TipoReg = "Gast";
                DataOrdxCbt.GuardarDB(ordCompraxCbte_info, ref mensaje);


                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("", "GenerarDiario", ex.Message), ex)
                      {
                          EntityType = typeof(imp_ordencompra_ext_x_imp_gastosxImport_Bus)
                      };
            }
        }
Esempio n. 2
0
        public Boolean GenerarDiarioFOB(int IdEmpresa, int IdSucursal, decimal IdImportacion, ref string msg, ref decimal idCbteCble, string idCbteCble_Proveedor)
        {
            try
            {
                imp_ordencompra_ext_x_ct_cbtecble_Info ordCompraxCbte_info = new imp_ordencompra_ext_x_ct_cbtecble_Info();
                ct_Periodo_Info  Per_I      = new ct_Periodo_Info();
                ct_Cbtecble_Info CbteCble_I = new ct_Cbtecble_Info();
                List <imp_ordencompra_ext_x_imp_gastosxImport_Det_Info> ListaDetalle  = new List <imp_ordencompra_ext_x_imp_gastosxImport_Det_Info>();
                imp_gastosximport_x_empresa_Data                    BusGastosXEmpresa = new imp_gastosximport_x_empresa_Data();
                List <imp_gastosximport_x_empresa_Info>             lstGastosXEmpresa = new List <imp_gastosximport_x_empresa_Info>();
                List <imp_ordencompra_ext_x_imp_gastosxImport_Info> Lst = new List <imp_ordencompra_ext_x_imp_gastosxImport_Info>();
                ba_Cbte_Ban_Bus             BusCbteBanco    = new ba_Cbte_Ban_Bus();
                ct_Periodo_Data             Per_B           = new ct_Periodo_Data();
                List <ct_Cbtecble_det_Info> LstCbteCble     = new List <ct_Cbtecble_det_Info>();
                cl_parametrosGenerales_Bus  param           = cl_parametrosGenerales_Bus.Instance;
                ba_Cbte_Ban_Info            CbteBan_I       = new ba_Cbte_Ban_Info();
                imp_Parametros_Data         Data_parametros = new imp_Parametros_Data();
                var tip = Data_parametros.Get_Info_Parametros(IdEmpresa);
                imp_ordencompra_ext_x_ct_cbtecble_Data DataOrdxCbt = new imp_ordencompra_ext_x_ct_cbtecble_Data();
                cp_proveedor_Data        _Prove_D = new cp_proveedor_Data();
                imp_ordencompra_ext_Info _Info    = oData.Get_Info_ordencompra_ext(IdEmpresa, IdSucursal, IdImportacion);
                string MensajeError = "";
                var    proveedor    = _Prove_D.Get_Info_Proveedor(param.IdEmpresa, _Info.IdProveedor);
                Per_I = Per_B.Get_Info_Periodo(_Info.IdEmpresa, _Info.ci_fecha, ref MensajeError);
                ct_Cbtecble_det_Info _CbteCble_I   = new ct_Cbtecble_det_Info();
                in_categorias_data   producto_data = new in_categorias_data();
                //var producto = producto_data.ObtenerObjeto(param.IdEmpresa, _Info.IdCategoria).ca_Categoria;
                var    producto    = producto_data.Get_List_categorias(0);
                string Observacion = _CbteCble_I.dc_Observacion = proveedor.pr_nombre + ".: " + _Info.CodOrdenCompraExt + ": //" + IdImportacion + "//" + "Cont. de la  Importacion #" + IdImportacion +
                                                                  @"'\'" + _Info.CodOrdenCompraExt + " Diario FOB" + _Info.ci_Observacion + " : " + producto + ". " + _Info.ci_tonelaje + " T";
                _CbteCble_I.IdCtaCble  = _Info.IdCtaCble_import;
                _CbteCble_I.IdEmpresa  = IdEmpresa;
                _CbteCble_I.IdTipoCbte = tip.IdTipoCbte_DiarioFob;
                _CbteCble_I.dc_Valor   = _Info.FOB;
                LstCbteCble.Add(_CbteCble_I);
                ct_Cbtecble_det_Info obj2 = new ct_Cbtecble_det_Info();
                obj2.IdCtaCble      = _Info.IdCtaCble_import;
                obj2.dc_Observacion = Observacion;// "Cont. de la  Importacion #" + IdImportacion + @"'\'" + _Info.CodOrdenCompraExt + " Diario FOB" + _Info.ci_Observacion;
                obj2.IdCtaCble      = idCbteCble_Proveedor;
                obj2.IdTipoCbte     = tip.IdTipoCbte_DiarioFob;
                obj2.IdEmpresa      = _Info.IdEmpresa;
                obj2.dc_Valor       = _Info.FOB * -1;
                LstCbteCble.Add(obj2);

                CbteCble_I.IdEmpresa   = _Info.IdEmpresa;
                CbteCble_I.IdTipoCbte  = tip.IdTipoCbte_DiarioFob;
                CbteCble_I.CodCbteCble = "IM";
                CbteCble_I.IdPeriodo   = Per_I.IdPeriodo;
                CbteCble_I.cb_Fecha    = Convert.ToDateTime(_Info.ci_fecha.ToShortDateString());
                CbteCble_I.cb_Valor    = _Info.FOB;
                if (_Info.CodOrdenCompraExt == null || _Info.CodOrdenCompraExt == "")
                {
                    _Info.CodOrdenCompraExt = "IMP" + IdImportacion;
                }
                CbteCble_I.cb_Observacion           = Observacion;
                CbteCble_I.Secuencia                = 0;
                CbteCble_I.Estado                   = "A";
                CbteCble_I.Anio                     = _Info.ci_fecha.Year;
                CbteCble_I.Mes                      = _Info.ci_fecha.Month;
                CbteCble_I.IdUsuario                = param.IdUsuario;
                CbteCble_I.IdUsuarioUltModi         = param.IdUsuario;
                CbteCble_I.cb_FechaTransac          = param.GetDateServer();
                CbteCble_I.cb_FechaUltModi          = param.GetDateServer();
                CbteCble_I.Mayorizado               = "N";
                CbteCble_I._cbteCble_det_lista_info = LstCbteCble;
                ct_Cbtecble_Bus CbteCble_B   = new ct_Cbtecble_Bus();
                string          cod_CbteCble = "";

                if (CbteCble_B.GrabarDB(CbteCble_I, ref idCbteCble, ref msg) == false)
                {
                    return(false);
                }
                ordCompraxCbte_info.ct_IdEmpresa         = ordCompraxCbte_info.imp_IdEmpresa = _Info.IdEmpresa;
                ordCompraxCbte_info.imp_IdOrdenCompraExt = _Info.IdOrdenCompraExt;
                ordCompraxCbte_info.imp_IdSucusal        = _Info.IdSucusal;
                ordCompraxCbte_info.ct_IdTipoCbte        = tip.IdTipoCbte_DiarioFob;
                ordCompraxCbte_info.ct_IdCbteCble        = idCbteCble;
                ordCompraxCbte_info.TipoReg = "FOB";
                DataOrdxCbt.GuardarDB(ordCompraxCbte_info, ref mensaje);

                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("", "consultaDiariosxImportacion", ex.Message), ex)
                      {
                          EntityType = typeof(imp_ordencompra_ext_Bus)
                      };
            }
        }