Exemple #1
0
        public bool GuardarDB(ct_Distribucion_Info info)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConexionERP.GetConnectionString()))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.Connection = connection;
                    #region Diario
                    info.IdCbteCble     = odatact.Get_IdCbteCble(info.IdEmpresa, info.IdTipoCbte, ref MensajeError);
                    command.CommandText = "INSERT INTO [dbo].[ct_cbtecble]([IdEmpresa],[IdTipoCbte],[IdCbteCble],[CodCbteCble],[IdPeriodo],[cb_Fecha],[cb_Valor],[cb_Observacion],[cb_Secuencia],[cb_Estado],[cb_Anio],[cb_mes]"
                                          + " ,[IdUsuario],[IdUsuarioAnu],[cb_MotivoAnu],[IdUsuarioUltModi],[cb_FechaAnu],[cb_FechaTransac],[cb_FechaUltModi],[cb_Mayorizado],[cb_para_conciliar],[IdSucursal])"
                                          + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + ",''," + info.Fecha.ToString("yyyyMM").ToString() + ",DATEFROMPARTS(" + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString() + "," + info.Fecha.Day.ToString() + ")," + info.ListaDiario.Where(q => q.dc_Valor > 0).Sum(q => q.dc_Valor).ToString() + ",'" + info.Observacion + "',0,'A'," + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString()
                                          + " ,'" + info.IdUsuario + "',NULL,NULL,NULL,NULL,GETDATE(),NULL,0,0,1);";
                    command.ExecuteNonQuery();
                    int Secuencia = 1;
                    command.CommandText = string.Empty;
                    foreach (var item in info.ListaDiario)
                    {
                        command.CommandText += "INSERT INTO [dbo].[ct_cbtecble_det]"
                                               + " ([IdEmpresa],[IdTipoCbte],[IdCbteCble],[secuencia],[IdCtaCble],[IdCentroCosto],[IdCentroCosto_sub_centro_costo],[dc_Valor],[dc_Observacion],[dc_Numconciliacion],[dc_EstaConciliado],[IdPunto_cargo],[IdPunto_cargo_grupo],[dc_para_conciliar])"
                                               + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + "," + Secuencia.ToString() + ",'" + item.IdCtaCble + "'," + (string.IsNullOrEmpty(item.IdCentroCosto) ? "NULL" : "'" + item.IdCentroCosto + "'") + "," + (string.IsNullOrEmpty(item.IdCentroCosto_sub_centro_costo) ? "NULL" : "'" + item.IdCentroCosto_sub_centro_costo + "'") + "," + item.dc_Valor.ToString() + ",'" + item.dc_Observacion + "',NULL,NULL," + (item.IdPunto_cargo == null ? "NULL" : item.IdPunto_cargo.ToString()) + "," + (item.IdPunto_cargo_grupo == null ? "NULL" : item.IdPunto_cargo_grupo.ToString()) + ",NULL);";
                        Secuencia++;
                    }
                    command.ExecuteNonQuery();
                    #endregion
                    command.CommandText = string.Empty;
                    #region Distribucion
                    info.IdDistribucion  = GetID(info.IdEmpresa);
                    command.CommandText += "Insert into ct_Distribucion ([IdEmpresa],[IdDistribucion],[Fecha], FechaDesde, FechaHasta,[Observacion],[Estado],[IdTipoCbte],[IdCbteCble],[IdUsuarioCreacion],[FechaCreacion], [IdCtaCble])"
                                           + " values  (" + info.IdEmpresa.ToString() + "," + info.IdDistribucion.ToString() + ",DATEFROMPARTS(" + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString() + "," + info.Fecha.Day.ToString() + "),DATEFROMPARTS(" + info.FechaDesde.Year.ToString() + "," + info.FechaDesde.Month.ToString() + "," + info.FechaDesde.Day.ToString() + "), DATEFROMPARTS(" + info.FechaHasta.Year.ToString() + "," + info.FechaHasta.Month.ToString() + "," + info.FechaHasta.Day.ToString() + "),'" + info.Observacion + "',1," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + ",'" + info.IdUsuario + "',GETDATE()," + (string.IsNullOrEmpty(info.IdCtaCble) ? "NULL" : "'" + info.IdCtaCble + "'") + ");";
                    Secuencia = 1;
                    foreach (var item in info.ListaDistribuido)
                    {
                        command.CommandText += "INSERT INTO [dbo].[ct_DistribucionDetDistribuido]([IdEmpresa],[IdDistribucion],[Secuencia],[IdCtaCble],[IdCentroCosto],[IdCentroCosto_sub_centro_costo],[F1],[F2], [Observacion])"
                                               + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdDistribucion.ToString() + "," + Secuencia.ToString() + ",'" + item.IdCtaCble + "'," + (string.IsNullOrEmpty(item.IdCentroCosto) ? "NULL" : "'" + item.IdCentroCosto + "'") + "," + (string.IsNullOrEmpty(item.IdCentroCosto_sub_centro_costo) ? "NULL" : "'" + item.IdCentroCosto_sub_centro_costo + "'") + "," + item.F1.ToString() + "," + item.F2.ToString() + ",'" + item.Observacion + "');";
                        Secuencia++;
                    }
                    Secuencia = 1;
                    foreach (var item in info.ListaPorDistribuir)
                    {
                        command.CommandText += "INSERT INTO [dbo].[ct_DistribucionDetPorDistribuir]([IdEmpresa],[IdDistribucion],[Secuencia],[IdCtaCble],[IdCentroCosto],[IdCentroCosto_sub_centro_costo],[Valor])"
                                               + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdDistribucion.ToString() + "," + Secuencia.ToString() + ",'" + item.IdCtaCble + "'," + (string.IsNullOrEmpty(item.IdCentroCosto) ? "NULL" : "'" + item.IdCentroCosto + "'") + "," + (string.IsNullOrEmpty(item.IdCentroCosto_sub_centro_costo) ? "NULL" : "'" + item.IdCentroCosto_sub_centro_costo + "'") + "," + item.Valor.ToString() + ");";
                        Secuencia++;
                    }
                    #endregion

                    command.ExecuteNonQuery();
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #2
0
        public bool GuardarDB(in_ProvisionIngresosPorOC_Info info)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConexionERP.GetConnectionString()))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand();
                    command.Connection = connection;

                    #region Diario
                    info.IdCbteCble     = odatact.Get_IdCbteCble(info.IdEmpresa, info.IdTipoCbte, ref MensajeError);
                    command.CommandText = "INSERT INTO [dbo].[ct_cbtecble]([IdEmpresa],[IdTipoCbte],[IdCbteCble],[CodCbteCble],[IdPeriodo],[cb_Fecha],[cb_Valor],[cb_Observacion],[cb_Secuencia],[cb_Estado],[cb_Anio],[cb_mes]"
                                          + " ,[IdUsuario],[IdUsuarioAnu],[cb_MotivoAnu],[IdUsuarioUltModi],[cb_FechaAnu],[cb_FechaTransac],[cb_FechaUltModi],[cb_Mayorizado],[cb_para_conciliar],[IdSucursal])"
                                          + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + ",''," + info.Fecha.ToString("yyyyMM").ToString() + ",DATEFROMPARTS(" + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString() + "," + info.Fecha.Day.ToString() + ")," + info.ListaDiario.Where(q => q.dc_Valor > 0).Sum(q => q.dc_Valor).ToString() + ",'" + info.Observacion + "',0,'A'," + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString()
                                          + " ,'" + info.IdUsuario + "',NULL,NULL,NULL,NULL,GETDATE(),NULL,0,0,1);";
                    command.ExecuteNonQuery();
                    int Secuencia = 1;
                    command.CommandText = string.Empty;
                    foreach (var item in info.ListaDiario)
                    {
                        command.CommandText += "INSERT INTO [dbo].[ct_cbtecble_det]"
                                               + " ([IdEmpresa],[IdTipoCbte],[IdCbteCble],[secuencia],[IdCtaCble],[IdCentroCosto],[IdCentroCosto_sub_centro_costo],[dc_Valor],[dc_Observacion],[dc_Numconciliacion],[dc_EstaConciliado],[IdPunto_cargo],[IdPunto_cargo_grupo],[dc_para_conciliar])"
                                               + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + "," + Secuencia.ToString() + ",'" + item.IdCtaCble + "'," + (string.IsNullOrEmpty(item.IdCentroCosto) ? "NULL" : "'" + item.IdCentroCosto + "'") + "," + (string.IsNullOrEmpty(item.IdCentroCosto_sub_centro_costo) ? "NULL" : "'" + item.IdCentroCosto_sub_centro_costo + "'") + "," + item.dc_Valor.ToString() + ",'" + item.dc_Observacion + "',NULL,NULL," + (item.IdPunto_cargo == null ? "NULL" : item.IdPunto_cargo.ToString()) + "," + (item.IdPunto_cargo_grupo == null ? "NULL" : item.IdPunto_cargo_grupo.ToString()) + ",NULL);";
                        Secuencia++;
                    }
                    command.ExecuteNonQuery();
                    #endregion

                    #region Provision
                    info.IdProvision    = GetID(info.IdEmpresa);
                    command.CommandText = "INSERT INTO [dbo].[in_ProvisionIngresosPorOC]([IdEmpresa],[IdProvision],[IdCtaCble],[Fecha],[Observacion],[IdTipoCbte],[IdCbteCble],[FechaIni],[FechaFin],[Estado],[IdUsuarioCreacion],[FechaCreacion])"
                                          + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdProvision.ToString() + ",'" + info.IdCtaCble + "',DATEFROMPARTS(" + info.Fecha.Year.ToString() + "," + info.Fecha.Month.ToString() + "," + info.Fecha.Day.ToString() + "),'" + info.Observacion + "'," + info.IdTipoCbte.ToString() + "," + info.IdCbteCble.ToString() + ",DATEFROMPARTS(" + info.FechaIni.Year.ToString() + "," + info.FechaIni.Month.ToString() + "," + info.FechaIni.Day.ToString() + "),DATEFROMPARTS(" + info.FechaFin.Year.ToString() + "," + info.FechaFin.Month.ToString() + "," + info.FechaFin.Day.ToString() + "),1,'" + info.IdUsuario + "',GETDATE())";
                    command.ExecuteNonQuery();
                    Secuencia           = 1;
                    command.CommandText = string.Empty;
                    foreach (var item in info.ListaDetalle)
                    {
                        command.CommandText += "INSERT INTO [dbo].[in_ProvisionIngresosPorOCDet]([IdEmpresa],[IdProvision],[Secuencia],[IdSucursal],[IdMovi_inven_tipo],[IdNumMovi],[Secuencia_inv],[Costo])"
                                               + " VALUES(" + info.IdEmpresa.ToString() + "," + info.IdProvision.ToString() + "," + (Secuencia++).ToString() + "," + item.IdSucursal.ToString() + "," + item.IdMovi_inven_tipo.ToString() + "," + item.IdNumMovi.ToString() + "," + item.Secuencia_inv.ToString() + "," + item.Costo.ToString() + ");";
                    }
                    command.ExecuteNonQuery();
                    #endregion
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public decimal Get_IdCbteCble(int IdEmpresa, int idTipoCbte, ref string MensajeError)
        {
            decimal IdcbteCble;

            try
            {
                IdcbteCble = data.Get_IdCbteCble(IdEmpresa, idTipoCbte, ref MensajeError);
                return(IdcbteCble);
            }
            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("", "Get_IdCbteCble", ex.Message), ex)
                      {
                          EntityType = typeof(ct_Cbtecble_Bus)
                      };
            }
        }