public bool AprobarDB(com_CotizacionPedido_Info info, string Cargo) { try { try { decimal IdOrdenPedido = 0; List <CotizacionesParaActualizar> Lista = new List <CotizacionesParaActualizar>(); using (EntitiesCompras db = new EntitiesCompras()) { var Entity = db.com_CotizacionPedido.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdCotizacion == info.IdCotizacion).FirstOrDefault(); if (Entity == null) { return(false); } #region Update estado JC o GA if (Cargo == "JC") { Entity.EstadoJC = info.EstadoJC; Entity.IdUsuarioJC = info.IdUsuario; Entity.FechaJC = DateTime.Now; Entity.cp_Observacion = info.cp_Observacion; } else { Entity.EstadoGA = info.EstadoGA; } #endregion #region Update de estado de proceso en el detalle de la cotizacion y pedido foreach (var item in info.ListaDetalle) { var det = db.com_CotizacionPedidoDet.Where(q => q.IdEmpresa == item.IdEmpresa && q.IdCotizacion == item.IdCotizacion && q.Secuencia == item.Secuencia).FirstOrDefault(); if (det != null) { if (Cargo == "JC") { det.EstadoJC = item.A; } else { det.EstadoGA = item.A; } } var detped = db.com_OrdenPedidoDet.Where(q => q.IdEmpresa == item.IdEmpresa && q.IdOrdenPedido == item.opd_IdOrdenPedido && q.Secuencia == item.opd_Secuencia).FirstOrDefault(); if (detped != null) { if (Cargo == "JC") { detped.opd_EstadoProceso = item.A == true ? "AJC" : "A"; } else { detped.opd_EstadoProceso = item.A == true ? "C" : "RGA"; } } } #endregion #region Update cabecera de orden de pedido con la auditoria del aprobador GA if (Cargo == "GA") { var lstPedido = info.ListaDetalle.GroupBy(q => q.opd_IdOrdenPedido).ToList(); foreach (var item in lstPedido) { var Pedido = db.com_OrdenPedido.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdOrdenPedido == item.Key).FirstOrDefault(); if (Pedido != null) { Pedido.IdUsuarioAprobacion = info.IdUsuario; Pedido.FechaAprobacion = DateTime.Now; Pedido.ObservacionGA = info.ObservacionAprobador; IdOrdenPedido = Pedido.IdOrdenPedidoReg ?? 0; } } } #endregion if (Cargo == "GA" && info.ListaDetalle.Where(q => q.EstadoGA).Count() > 0) { #region Cabecera OC com_ordencompra_local_Data odataCom = new com_ordencompra_local_Data(); int workDays = info.cp_PlazoEntrega; DateTime tmpDate = DateTime.Now.Date; while (workDays > 0) { tmpDate = tmpDate.AddDays(1); if (tmpDate.DayOfWeek < DayOfWeek.Saturday && tmpDate.DayOfWeek > DayOfWeek.Sunday) { workDays--; } } db.com_ordencompra_local.Add(new com_ordencompra_local { IdEmpresa = info.IdEmpresa, IdSucursal = info.IdSucursal, IdOrdenCompra = info.oc_IdOrdenCompra = odataCom.GetId(info.IdEmpresa, info.IdSucursal), IdProveedor = info.IdProveedor, oc_NumDocumento = "COT" + info.IdCotizacion.ToString("0000000000"), Tipo = "", IdTerminoPago = info.IdTerminoPago, oc_plazo = info.cp_Plazo, oc_fecha = DateTime.Now.Date, oc_flete = 0, oc_observacion = info.cp_Observacion, Estado = "A", IdEstadoAprobacion_cat = "APRO", Fecha_Transac = DateTime.Now, IdEstadoRecepcion_cat = "PEN", AfectaCosto = "S", IdDepartamento = info.IdDepartamento, IdMotivo = null, oc_fechaVencimiento = tmpDate, IdEstado_cierre = "ABI", IdComprador = info.IdComprador, IdUsuario = info.IdUsuario, co_fecha_aprobacion = DateTime.Now, IdUsuario_Aprueba = info.IdUsuario }); #endregion #region Detalle OC int Secuencia = 1; var lstGeneracion = info.ListaDetalle.Where(q => q.A && q.cd_Cantidad > 0).ToList(); foreach (var item in lstGeneracion) { var impuesto = odataImp.Get_Info_impuesto(item.IdCod_Impuesto); if (impuesto != null) { item.Por_Iva = impuesto.porcentaje; item.cd_iva = item.cd_subtotal * (impuesto.porcentaje / 100); item.cd_total = item.cd_subtotal + item.cd_iva; } Lista.Add(new CotizacionesParaActualizar { SecuenciaPedido = item.opd_Secuencia, IdSucursal = info.IdSucursal, IdOrdenCompra = info.oc_IdOrdenCompra, SecuenciaOC = item.Secuencia, CostouniFinal = item.cd_precioFinal }); db.com_ordencompra_local_det.Add(new com_ordencompra_local_det { IdEmpresa = info.IdEmpresa, IdSucursal = info.IdSucursal, IdOrdenCompra = info.oc_IdOrdenCompra, Secuencia = item.Secuencia, IdProducto = item.IdProducto ?? 0, do_Cantidad = item.cd_Cantidad, do_precioCompra = item.cd_precioCompra, do_porc_des = item.cd_porc_des, do_descuento = item.cd_descuento, do_precioFinal = item.cd_precioFinal, do_subtotal = item.cd_subtotal, do_iva = item.cd_iva, do_total = item.cd_total, do_ManejaIva = true, do_Costeado = "N", do_peso = 0, IdCentroCosto = null, IdCentroCosto_sub_centro_costo = null, IdPunto_cargo = item.IdPunto_cargo, IdPunto_cargo_grupo = null, IdUnidadMedida = item.IdUnidadMedida, Por_Iva = item.Por_Iva, IdCod_Impuesto = item.IdCod_Impuesto, do_observacion = (string.IsNullOrEmpty(item.cd_DetallePorItem) ? "" : item.cd_DetallePorItem + " ") + (string.IsNullOrEmpty(item.opd_Detalle) ? "" : item.opd_Detalle), IdSucursalDestino = item.IdSucursalDestino }); } #endregion Entity.oc_IdOrdenCompra = Convert.ToInt32(info.oc_IdOrdenCompra); } db.SaveChanges(); if (Cargo == "JC") { com_OrdenPedido_Data odataPedido = new com_OrdenPedido_Data(); odataPedido.SaltarPaso5(info.IdEmpresa, info.IdOrdenPedido ?? 0, info.IdUsuario); } else { if (IdOrdenPedido > 0) { foreach (var item in Lista) { ReemplazarCotizacionesIngresadas(info.IdEmpresa, IdOrdenPedido, item.SecuenciaPedido, item.IdSucursal, item.IdOrdenCompra, item.SecuenciaOC, item.CostouniFinal); } } } } return(true); } catch (DbEntityValidationException ex) { throw; } } catch (Exception ex) { throw; } }
public bool GuardarDB(com_CotizacionPedido_Info info) { try { EntitiesInventario dbi = new EntitiesInventario(); EntitiesGeneral dbg = new EntitiesGeneral(); int Contadot = 0; using (EntitiesCompras db = new EntitiesCompras()) { db.com_CotizacionPedido.Add(new com_CotizacionPedido { IdEmpresa = info.IdEmpresa, IdCotizacion = info.IdCotizacion = GetID(info.IdEmpresa), IdSucursal = info.IdSucursal, IdProveedor = info.IdProveedor, IdTerminoPago = info.IdTerminoPago, cp_Fecha = info.cp_Fecha, cp_Plazo = info.cp_Plazo, IdOrdenPedido = info.IdOrdenPedido, cp_Observacion = info.cp_Observacion, IdComprador = info.IdComprador, IdDepartamento = info.IdDepartamento, IdSolicitante = Convert.ToInt32(info.IdSolicitante), EstadoGA = "P", EstadoJC = "P", cp_PlazoEntrega = info.cp_PlazoEntrega, cp_ObservacionAdicional = info.cp_ObservacionAdicional }); int Secuencia = 1; foreach (var item in info.ListaDetalle) { var Cont = db.com_CotizacionPedidoDet.Where(q => q.opd_IdEmpresa == item.opd_IdEmpresa && q.opd_IdOrdenPedido == item.opd_IdOrdenPedido && q.opd_Secuencia == item.opd_Secuencia && (q.com_CotizacionPedido.EstadoJC == "P" || q.EstadoJC == true)).Count(); if (Cont == 0) { Contadot++; db.com_CotizacionPedidoDet.Add(new com_CotizacionPedidoDet { IdEmpresa = info.IdEmpresa, IdCotizacion = info.IdCotizacion, Secuencia = Secuencia++, opd_IdEmpresa = item.opd_IdEmpresa, opd_IdOrdenPedido = item.opd_IdOrdenPedido, opd_Secuencia = item.opd_Secuencia, cd_Cantidad = item.cd_Cantidad, cd_precioCompra = item.cd_precioCompra, cd_porc_des = item.cd_porc_des, cd_descuento = item.cd_descuento, cd_precioFinal = item.cd_precioFinal, cd_subtotal = item.cd_subtotal, IdCod_Impuesto = item.IdCod_Impuesto, Por_Iva = item.Por_Iva, cd_iva = item.cd_iva, cd_total = item.cd_total, IdProducto = item.IdProducto ?? 0, IdPunto_cargo = item.IdPunto_cargo, IdUnidadMedida = item.IdUnidadMedida, cd_DetallePorItem = item.cd_DetallePorItem, AdjuntoC = item.AdjuntoC, NombreArchivoC = !string.IsNullOrEmpty(item.NombreArchivoC) ? Path.GetFileName(item.NombreArchivoC) : item.NombreArchivoC }); var det_op = db.com_OrdenPedidoDet.Where(q => q.IdEmpresa == item.opd_IdEmpresa && q.IdOrdenPedido == item.opd_IdOrdenPedido && q.Secuencia == item.opd_Secuencia && q.opd_EstadoProceso == "A").FirstOrDefault(); if (det_op != null) { det_op.opd_EstadoProceso = "AC"; if (det_op.IdProducto == null) { det_op.pr_descripcion = dbi.in_Producto.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdProducto == item.IdProducto).FirstOrDefault().pr_descripcion; det_op.IdUnidadMedida = item.IdUnidadMedida; det_op.IdProducto = item.IdProducto; } det_op.FechaCotizacion = DateTime.Now; det_op.IdUsuarioCotizacion = info.IdUsuario; } } } var persona = dbg.tb_persona.Where(q => q.IdPersona == info.IdPersona).FirstOrDefault(); if (persona != null) { persona.pe_correo_secundario1 = info.pe_correo; } if (Contadot > 0) { db.SaveChanges(); dbg.SaveChanges(); } } com_OrdenPedido_Data data_ped = new com_OrdenPedido_Data(); if (Contadot > 0) { if (data_ped.SaltarPaso4(info.IdEmpresa, info.IdOrdenPedido ?? 0, info.IdUsuario)) { } if (data_ped.ValidarProceso(info.IdEmpresa, info.IdOrdenPedido ?? 0)) { } try { #region Adjuntos var lst_adjuntos = info.ListaDetalle.Where(q => q.AdjuntoC == true).ToList(); var param = paramData.Get_Info_parametro(info.IdEmpresa); if (param != null && !string.IsNullOrEmpty(param.UbicacionArchivosCotizacion)) { string Comando = "/c Net Use " + param.FileDominio + " /USER:"******" " + param.FileContrasenia; Fx.ExecuteCommand(@"" + Comando); Directory.CreateDirectory(param.UbicacionArchivosCotizacion + @"\" + info.IdCotizacion.ToString()); foreach (var item in lst_adjuntos) { var ext = Path.GetFileName(item.NombreArchivoC); System.IO.File.Copy(item.NombreArchivoC, param.UbicacionArchivosCotizacion + @"\" + info.IdCotizacion.ToString() + @"\" + ext, true); } Comando = "/c Net Use /DELETE " + param.FileDominio + " /USER:"******" " + param.FileContrasenia; Fx.ExecuteCommand(@"" + Comando); } #endregion } catch (Exception) { using (SqlConnection connection = new SqlConnection(ConexionERP.GetConnectionString())) { connection.Open(); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "update com_CotizacionPedidoDet set AdjuntoC = 0, NombreArchivoC = NULL where IdEmpresa = " + info.IdEmpresa.ToString() + " and IdCotizacion = " + info.IdCotizacion.ToString(); command.ExecuteNonQuery(); } } } return(true); } catch (Exception ex) { string mensaje = string.Empty; 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.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message , "", arreglo, "", "", "", "", "", DateTime.Now); oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje); mensaje = ex.ToString(); throw new Exception(ex.ToString()); } }
public bool GuardarDB(com_CotizacionPedido_Info info) { try { EntitiesInventario dbi = new EntitiesInventario(); EntitiesGeneral dbg = new EntitiesGeneral(); using (EntitiesCompras db = new EntitiesCompras()) { db.com_CotizacionPedido.Add(new com_CotizacionPedido { IdEmpresa = info.IdEmpresa, IdCotizacion = info.IdCotizacion = GetID(info.IdEmpresa), IdSucursal = info.IdSucursal, IdProveedor = info.IdProveedor, IdTerminoPago = info.IdTerminoPago, cp_Fecha = info.cp_Fecha, cp_Plazo = info.cp_Plazo, IdOrdenPedido = info.IdOrdenPedido, cp_Observacion = info.cp_Observacion, IdComprador = info.IdComprador, IdDepartamento = info.IdDepartamento, IdSolicitante = Convert.ToInt32(info.IdSolicitante), EstadoGA = "P", EstadoJC = "P", cp_PlazoEntrega = info.cp_PlazoEntrega, cp_ObservacionAdicional = info.cp_ObservacionAdicional }); int Secuencia = 1; foreach (var item in info.ListaDetalle) { db.com_CotizacionPedidoDet.Add(new com_CotizacionPedidoDet { IdEmpresa = info.IdEmpresa, IdCotizacion = info.IdCotizacion, Secuencia = Secuencia++, opd_IdEmpresa = item.opd_IdEmpresa, opd_IdOrdenPedido = item.opd_IdOrdenPedido, opd_Secuencia = item.opd_Secuencia, cd_Cantidad = item.cd_Cantidad, cd_precioCompra = item.cd_precioCompra, cd_porc_des = item.cd_porc_des, cd_descuento = item.cd_descuento, cd_precioFinal = item.cd_precioFinal, cd_subtotal = item.cd_subtotal, IdCod_Impuesto = item.IdCod_Impuesto, Por_Iva = item.Por_Iva, cd_iva = item.cd_iva, cd_total = item.cd_total, IdProducto = item.IdProducto ?? 0, IdPunto_cargo = item.IdPunto_cargo, IdUnidadMedida = item.IdUnidadMedida, cd_DetallePorItem = item.cd_DetallePorItem }); var det_op = db.com_OrdenPedidoDet.Where(q => q.IdEmpresa == item.opd_IdEmpresa && q.IdOrdenPedido == item.opd_IdOrdenPedido && q.Secuencia == item.opd_Secuencia && q.opd_EstadoProceso == "A").FirstOrDefault(); if (det_op != null) { det_op.opd_EstadoProceso = "AC"; if (det_op.IdProducto == null) { det_op.pr_descripcion = dbi.in_Producto.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdProducto == item.IdProducto).FirstOrDefault().pr_descripcion; det_op.IdUnidadMedida = item.IdUnidadMedida; det_op.IdProducto = item.IdProducto; } det_op.FechaCotizacion = DateTime.Now; det_op.IdUsuarioCotizacion = info.IdUsuario; } } var persona = dbg.tb_persona.Where(q => q.IdPersona == info.IdPersona).FirstOrDefault(); if (persona != null) { persona.pe_correo_secundario1 = info.pe_correo; } db.SaveChanges(); dbg.SaveChanges(); } com_OrdenPedido_Data data_ped = new com_OrdenPedido_Data(); if (data_ped.SaltarPaso4(info.IdEmpresa, info.IdOrdenPedido ?? 0, info.IdUsuario)) { } if (data_ped.ValidarProceso(info.IdEmpresa, info.IdOrdenPedido ?? 0)) { } return(true); } catch (Exception) { throw; } }