static List <gsOV_BuscarDetalleResult> OrdenVenta_ObtenerDetalle(gsOV_BuscarCabeceraResult objOrdenVentaCab_R, gsOV_BuscarDetalleResult[] objOrdenVentaDet, int idEmpresa, int codigoUsuario) { ImpuestoWCFClient objImpuestoWCF = new ImpuestoWCFClient(); gsOV_BuscarImpuestoResult[] lstImpuestos = null; List <gsOV_BuscarDetalleResult> lstPedidoDet; List <gsItem_BuscarResult> lstProductos = new List <gsItem_BuscarResult>(); // = (List<gsItem_BuscarResult>)Session["lstProductos"]; //List<gsItem_BuscarResult> lstProductosR = new List<gsItem_BuscarResult>(); gsOV_BuscarDetalleResult objProducto; List <gsImpuesto_ListarPorItemResult> lstImpuestoItem = new List <gsImpuesto_ListarPorItemResult>(); DateTime fecha; try { foreach (gsOV_BuscarDetalleResult objDetalle in objOrdenVentaDet) { gsItem_BuscarResult objItem = new gsItem_BuscarResult(); objItem.Codigo = objDetalle.ID_Item; objItem.Cantidad = Convert.ToInt32(objDetalle.Cantidad); objItem.DctoMax = objDetalle.DctoMax; objItem.Descuento = objDetalle.Dcto; objItem.ID_Moneda = objDetalle.ID_Moneda; objItem.ID_UnidadControl = objDetalle.ID_UnidadDoc; objItem.ID_UnidadInv = objDetalle.ID_UnidadInv; objItem.Importe = objDetalle.Importe; objItem.Item = objDetalle.Item; objItem.Item_ID = objDetalle.Item_ID; objItem.NombreMoneda = objDetalle.NombreMoneda; objItem.Observacion = objDetalle.Observaciones; objItem.Precio = objDetalle.Precio; objItem.PrecioInicial = objDetalle.PrecioMinimo; objItem.Signo = objDetalle.Signo; if (objOrdenVentaCab_R.Aprobacion1) { objItem.Stock = objDetalle.Stock + objDetalle.Cantidad; } else { objItem.Stock = objDetalle.Stock; } objItem.FactorUnidadInv = objDetalle.FactorUnidadInv; objItem.UnidadPresentacion = objDetalle.UnidadPresentacion; objItem.ID_Amarre = objDetalle.ID_Amarre; objItem.Estado = 1; objItem.CostoUnitario = objDetalle.CostoUnitario; lstImpuestoItem.AddRange(objImpuestoWCF.Impuesto_ListarPorItem(idEmpresa, codigoUsuario, objDetalle.ID_Item, DateTime.Now)); //ViewState["fecha"] = objOrdenVentaCab.FechaOrden; fecha = objOrdenVentaCab_R.FechaOrden; lstProductos.Add(objItem); } //Session["lstProductos"] = lstProductos; //Session["lstImpuestos"] = lstImpuestoItem; lstPedidoDet = new List <gsOV_BuscarDetalleResult>(); foreach (gsItem_BuscarResult producto in lstProductos) { objProducto = new gsOV_BuscarDetalleResult(); objProducto.ID_Amarre = producto.ID_Amarre; objProducto.TablaOrigen = "OV"; objProducto.ID_Item = producto.Codigo; objProducto.ID_ItemPedido = null; objProducto.Item_ID = producto.Item_ID; objProducto.Cantidad = producto.Cantidad; objProducto.Precio = producto.Precio; objProducto.Dcto = producto.Descuento; //objProducto.DctoValor = Math.Round(producto.Descuento * producto.Precio / 100, 2); objProducto.DctoValor = Math.Round(((producto.Descuento / 100)) * producto.Precio, 4); objProducto.Importe = producto.Importe; objProducto.ID_ItemAnexo = null; objProducto.ID_CCosto = null; objProducto.ID_UnidadGestion = null; objProducto.ID_UnidadProyecto = null; objProducto.ID_UnidadInv = producto.ID_UnidadInv; objProducto.FactorUnidadInv = producto.FactorUnidadInv; objProducto.CantidadUnidadInv = producto.Cantidad; // Consultar como se calcula realmente objProducto.ID_UnidadDoc = producto.ID_UnidadControl; objProducto.CantidadUnidadDoc = producto.Cantidad; // Consultar como se calcula realmente objProducto.Observaciones = producto.Observacion; objProducto.Estado = (int)producto.Estado; objProducto.Stock = producto.Stock; lstPedidoDet.Add(objProducto); } return(lstPedidoDet); } catch (Exception ex) { throw ex; } }
static void Pedido_Cargar(string idOrdenVenta, int idEmpresa, int codigoUsuario) { OrdenVentaWCFClient objOrdenVentaWCF = new OrdenVentaWCFClient();; gsOV_BuscarCabeceraResult objOrdenVentaCab; List <GlosaBE> lstGlosa = new List <GlosaBE>(); ImpuestoWCFClient objImpuestoWCF = new ImpuestoWCFClient(); gsOV_BuscarImpuestoResult[] lstImpuestos = null; List <gsImpuesto_ListarPorItemResult> lstImpuestoItem = new List <gsImpuesto_ListarPorItemResult>(); gsOV_BuscarDetalleResult[] objOrdenVentaDet = null; List <gsItem_BuscarResult> lstProductos = new List <gsItem_BuscarResult>(); bool? bloqueado = false; string mensajeBloqueo = null; AgendaWCFClient objAgendaWCFClient; AgendaWCF.VBG01134Result objAgendaCliente; decimal? lineaCredito = null; DateTime?fechaVecimiento = null; string strLETRAS = ""; decimal? TC = 0; try { objAgendaWCFClient = new AgendaWCFClient(); objAgendaCliente = new AgendaWCF.VBG01134Result(); objOrdenVentaCab = objOrdenVentaWCF.OrdenVenta_Buscar(idEmpresa, codigoUsuario, int.Parse(idOrdenVenta), ref objOrdenVentaDet, ref lstImpuestos, ref bloqueado, ref mensajeBloqueo); objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(idEmpresa, codigoUsuario, objOrdenVentaCab.ID_Agenda, ref lineaCredito, ref fechaVecimiento, ref TC); List <GlosaBE> Impuesto_Obtener_R = new List <GlosaBE>(); gsPedidos_FechasLetrasSelectResult[] lstFechas = objOrdenVentaWCF.PedidoLetras_Detalle(idEmpresa, codigoUsuario, 0, int.Parse(idOrdenVenta)); strLETRAS = PedidosFechas_Letras(lstFechas.ToList(), (DateTime)objOrdenVentaCab.FechaEmision); //----------------------------------------------------------- gsOV_BuscarCabeceraResult cabecera = OrdenVenta_ObtenerCabecera(objOrdenVentaCab, idOrdenVenta, lstImpuestos, ref Impuesto_Obtener_R); gsOV_BuscarDetalleResult[] detalle = OrdenVenta_ObtenerDetalle(objOrdenVentaCab, objOrdenVentaDet, idEmpresa, codigoUsuario).ToArray(); int KardexFlete = 0; List <gsOV_BuscarDetalleResult> kardex = new List <gsOV_BuscarDetalleResult>(); gsOV_BuscarDetalleResult objetoFlete = new gsOV_BuscarDetalleResult(); kardex = detalle.ToList().FindAll(x => x.Item.Contains("Flete") && x.Estado == 1).ToList(); if (kardex.Count > 0) { KardexFlete = Convert.ToInt32(kardex[0].Item_ID); //----------------------------------------------------------- if (KardexFlete > 0) { objetoFlete = detalle.ToList().Find(x => x.Item_ID == KardexFlete && x.Estado == 1); } } // ---------------------------------------------------------- objOrdenVentaWCF.OrdenVenta_Registrar(idEmpresa, 1, cabecera, detalle, Impuesto_Obtener_R.ToArray(), decimal.Parse(idOrdenVenta), (decimal)lineaCredito, (DateTime)fechaVecimiento, lstFechas, strLETRAS, KardexFlete, objetoFlete); //objOrdenVentaWCF.OrdenVenta_Registrar(codEmpresa, codUsuario, cabecera, detalle, impuesto, idPedido, LineaCredito, // dtFechaVencimiento, fechas, PlanLetras, KardexFlete, objetoFlete); //string pedido = "Realizado."; } catch (Exception ex) { throw new ArgumentException(ex.Message, ex.TargetSite.Name + "No se pudo registrar el pedido en la base de datos."); } }
//public static void ReadFileFromFTP(int idEmpresa, List<string> files, string RutaOrigen, string RutaSubmit, string RutaFail, string user, string pass) public static void ReadFileFromFTP(int idEmpresa, List <Cargar_Pedidos_ConfirmacionResult> ListaPedido) { List <gsInterfacePedidos_LeerResult> lstPedidos; //string Nombre; int codigoUsuario = 1; int idOrdenVenta; //foreach (Cargar_Pedidos_ConfirmacionResult file in ListaPedido) //{ try { lstPedidos = new List <gsInterfacePedidos_LeerResult>(); foreach (Cargar_Pedidos_ConfirmacionResult file in ListaPedido) { gsInterfacePedidos_LeerResult Pedido = new gsInterfacePedidos_LeerResult(); //Pedido.NroPedido = "30313"; // file.NumeroDeDocumento; // Campos[0]; //Op OV //Pedido.ID_Item = "10210109003514"; //( file.CodigoDeArticulo; // Campos[1]; //Item //Pedido.Lote = "170831-0171-2050"; // file.CodigoDeLote; // Campos[2]; //Lote //Pedido.CantidadPedido = 6; // (decimal)file.UnidadesPedido; // decimal.Parse(Campos[3]); //Cantidad //Pedido.CantidadEntrega = 6; // (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]); //Cantidad entregada //Pedido.CantidadPendiente = 0; // (decimal)(file.Diferencia); // decimal.Parse(Campos[5]); //Diferencia //Pedido.EstadoPedido = "D"; // file.Anticipado; // Campos[7]; // Estado //Pedido.Id_Amarre = 76851; // decimal.Parse(file.IDDeLinea); // decimal.Parse(Campos[8]); // Id_Amarre //Pedido.TransferidoTabla = "SILPT"; // file.Empresa; //Pedido.Servicio = file.NumeroDeAlbaran; /////////////------------------------------------------------- Pedido.NroPedido = file.NumeroDeDocumento; // Campos[0]; //Op OV Pedido.ID_Item = file.CodigoDeArticulo; // Campos[1]; //Item Pedido.Lote = file.CodigoDeLote; // Campos[2]; //Lote Pedido.CantidadPedido = (decimal)file.UnidadesPedido; // decimal.Parse(Campos[3]); //Cantidad Pedido.CantidadEntrega = (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]); //Cantidad entregada Pedido.CantidadPendiente = (decimal)(file.Diferencia); // decimal.Parse(Campos[5]); //Diferencia Pedido.EstadoPedido = file.Anticipado; // Campos[7]; // Estado Pedido.Id_Amarre = decimal.Parse(file.IDDeLinea); // decimal.Parse(Campos[8]); // Id_Amarre Pedido.TransferidoTabla = file.Empresa; Pedido.Servicio = file.NumeroDeAlbaran; lstPedidos.Add(Pedido); } lstPedidos = lstPedidos.OrderBy(x => x.Op).ToList(); foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos) { try { WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient(); objWmsInsert.WmsPedidosPendientes_Insertar(idEmpresa, 1, pedido.NroPedido, pedido.ID_Item, pedido.Lote, decimal.Parse(pedido.CantidadPedido.ToString()), decimal.Parse(pedido.CantidadEntrega.ToString()), decimal.Parse(pedido.CantidadPendiente.ToString()), pedido.EstadoPedido, int.Parse(pedido.Id_Amarre.ToString())); //1=SILVESTRE; 2=NEOAGRUM; 6=INATEC //objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio); Console.Write("Se registro Op" + pedido.NroPedido + " - " + pedido.Id_Amarre); } catch (Exception ex) { Console.Write("Error: Registrar TXT: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString()); } } Console.Write("Se registro los pedidos consumidos."); //---------------------------Pedido-------------------------------- //var lstOpOV = lstPedidos.Select(x => x.NroPedido).Distinct(); foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos) { try { GuiaWCFClient objGuiaVentaWCF = new GuiaWCFClient(); OrdenVentaWCFClient objOrdenVentaWCF = new OrdenVentaWCFClient(); gsOV_BuscarCabeceraResult objOrdenVentaCab; gsOV_BuscarDetalleResult[] objOrdenVentaDet = null; gsGuia_BuscarCabeceraResult objGuiaVentaCab = new gsGuia_BuscarCabeceraResult(); gsGuia_BuscarDetalleResult[] objGuiaVentaDet = null; gsGuia_BuscarDetalleResult objGuiaVentaDetUpdate = null; gsOV_BuscarDetalleResult objOrdenVenta_Linea = null; List <DM.gsItem_BuscarResult> lstProductos = new List <DM.gsItem_BuscarResult>(); gsOV_BuscarImpuestoResult[] lstImpuestos = null; GuiaVenta_LotesItemsResult[] lstLotes = null; bool? bloqueado = false; string mensajeBloqueo = null; AgendaWCFClient objAgendaWCFClient; VBG01134Result objAgendaCliente; decimal?lineaCredito = null; decimal?Id_Amarre = 0; decimal?TC = 0; DateTime?fechaVecimiento = null; Console.Write("OP:" + pedido.NroPedido); objAgendaWCFClient = new AgendaWCFClient(); objAgendaCliente = new VBG01134Result(); idOrdenVenta = int.Parse(pedido.NroPedido.ToString()); objOrdenVentaCab = objOrdenVentaWCF.OrdenVenta_Buscar_Guia(idEmpresa, codigoUsuario, idOrdenVenta, ref objOrdenVentaDet, ref lstImpuestos, ref bloqueado, ref mensajeBloqueo); objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(idEmpresa, codigoUsuario, objOrdenVentaCab.ID_Agenda, ref lineaCredito, ref fechaVecimiento, ref TC); Id_Amarre = pedido.Id_Amarre; objOrdenVenta_Linea = objOrdenVentaDet.ToList().FindAll(x => x.ID_Amarre == Id_Amarre).Single(); int idGuiaOp = 0; int idGuiaOpLinea = 0; int item_id = 0; idGuiaOp = int.Parse(objOrdenVentaCab.OpGuia.ToString()); idGuiaOpLinea = int.Parse(objOrdenVenta_Linea.OpGuia.ToString()); item_id = int.Parse(objOrdenVenta_Linea.Item_ID.ToString()); if (objOrdenVenta_Linea == null) { } else { if (idGuiaOpLinea > 0) { objGuiaVentaCab = objGuiaVentaWCF.GuiaVenta_Buscar(idEmpresa, codigoUsuario, idGuiaOp, ref objGuiaVentaDet, ref bloqueado, ref mensajeBloqueo); } else { objGuiaVentaCab = GuiaVenta_ObtenerCabecera(objOrdenVentaCab, idGuiaOp); objGuiaVentaDet = GuiaVenta_ObtenerDetalle(objOrdenVentaCab, objOrdenVentaDet, idEmpresa, codigoUsuario).ToArray(); } if (idGuiaOp > 0) { lstLotes = objGuiaVentaWCF.GuiaVenta_LotesItemBuscar(idEmpresa, codigoUsuario, int.Parse(idGuiaOp.ToString()), int.Parse(objOrdenVenta_Linea.Item_ID.ToString())); } List <GuiaVenta_LotesItemsResult> LotesUp = new List <GuiaVenta_LotesItemsResult>(); if (lstLotes == null) { LotesUp = new List <GuiaVenta_LotesItemsResult>(); } else { LotesUp = ((GuiaVenta_LotesItemsResult[])lstLotes).ToList(); } objGuiaVentaDetUpdate = GuiaVenta_ObtenerDetalle_Update(objGuiaVentaDet, lstPedidos, Id_Amarre, ref LotesUp, item_id); lstLotes = (GuiaVenta_LotesItemsResult[])LotesUp.ToArray(); try { int Error = 0; int cont = 0; WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient(); List <VBG00971Result> Lista_LoteVar = objGuiaVentaWCF.GuiaVenta_BuscarLotesxItem(idEmpresa, 1, int.Parse(pedido.NroPedido), (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, (int)pedido.Id_Amarre).ToList(); foreach (VBG00971Result Lote in Lista_LoteVar) { if (Lote.Lote == pedido.Lote) { cont++; break; } } if (cont == 0) { objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "No se encuentra Lote para el Item"); } else { try { objGuiaVentaWCF.GuiaVenta_Registrar(idEmpresa, 1, objGuiaVentaCab, objGuiaVentaDetUpdate, decimal.Parse(idGuiaOp.ToString()), lstLotes); objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio); objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "S", "Se registro correctamente."); } catch (Exception ex) { objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "Error, al registrar la Guia."); Console.Write("Error al registrar guias: " + ex.Message.ToString()); } } } catch (Exception ex) { } } } catch (Exception ex) { Console.Write("Error: Registrar Guia: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString()); } } ////------------------Mover archivos--------- // //MoverArchivos(RutaOrigen, RutaSubmit, file, user, pass); ////} } catch (Exception ex) { Console.Write("Error: Registrar Guia, " + ex.Message.ToString()); //MoverArchivos(RutaOrigen, RutaFail, file, user, pass); } //} }
//public static void ReadFileFromFTP(int idEmpresa, List<string> files, string RutaOrigen, string RutaSubmit, string RutaFail, string user, string pass) public static void ReadFileFromFTP(int idEmpresa, DataTable ListaPedido, string esquema, string EmpresaPT) { //string Nombre; int codigoUsuario = 1; int idOrdenVenta; try { List <gsInterfacePedidos_LeerResult> lstPedidos = new List <gsInterfacePedidos_LeerResult>(); foreach (DataRow file in ListaPedido.Rows) { gsInterfacePedidos_LeerResult Pedido = new gsInterfacePedidos_LeerResult(); //Pedido.NroPedido = "30313"; // file.NumeroDeDocumento; // Campos[0]; //Op OV //Pedido.ID_Item = "10210109003514"; //( file.CodigoDeArticulo; // Campos[1]; //Item //Pedido.Lote = "170831-0171-2050"; // file.CodigoDeLote; // Campos[2]; //Lote //Pedido.CantidadPedido = 6; // (decimal)file.UnidadesPedido; // decimal.Parse(Campos[3]); //Cantidad //Pedido.CantidadEntrega = 6; // (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]); //Cantidad entregada //Pedido.CantidadPendiente = 0; // (decimal)(file.Diferencia); // decimal.Parse(Campos[5]); //Diferencia //Pedido.EstadoPedido = "D"; // file.Anticipado; // Campos[7]; // Estado //Pedido.Id_Amarre = 76851; // decimal.Parse(file.IDDeLinea); // decimal.Parse(Campos[8]); // Id_Amarre //Pedido.TransferidoTabla = "SILPT"; // file.Empresa; //Pedido.Servicio = file.NumeroDeAlbaran; //------------------------------------------------- Pedido.NroPedido = file["NumeroDeDocumento"]; // Campos[0]; //Op OV Pedido.ID_Item = file["CodigoDeArticulo"]; // Campos[1]; //Item Pedido.Lote = file["CodigoDeLote"]; // Campos[2]; //Lote Pedido.CantidadPedido = decimal.Parse(file["UnidadesPedido"].ToString()); // decimal.Parse(Campos[3]); //Cantidad Pedido.CantidadEntrega = decimal.Parse(file["UnidadesEntregadas"].ToString()); // int.Parse(Campos[4]); //Cantidad entregada Pedido.CantidadPendiente = decimal.Parse(file["Diferencia"].ToString()); // decimal.Parse(Campos[5]); //Diferencia Pedido.EstadoPedido = file["Anticipado"]; // Campos[7]; // Estado Pedido.Id_Amarre = decimal.Parse(file["IDDeLinea"].ToString()); // decimal.Parse(Campos[8]); // Id_Amarre Pedido.TransferidoTabla = file["CIF"]; Pedido.Servicio = file["NumeroDeAlbaran"]; lstPedidos.Add(Pedido); } lstPedidos = lstPedidos.OrderBy(x => x.NroPedido).ToList(); foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos) { try { WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient(); objWmsInsert.WmsPedidosPendientes_Insertar(idEmpresa, 1, pedido.NroPedido.ToString(), pedido.ID_Item.ToString(), pedido.Lote.ToString(), decimal.Parse(pedido.CantidadPedido.ToString()), decimal.Parse(pedido.CantidadEntrega.ToString()), decimal.Parse(pedido.CantidadPendiente.ToString()), pedido.EstadoPedido.ToString(), int.Parse(pedido.Id_Amarre.ToString())); //1=SILVESTRE; 2=NEOAGRUM; 6=INATEC //objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio); Console.Write("Se registro Op" + pedido.NroPedido + " - " + pedido.Id_Amarre); } catch (Exception ex) { Console.Write("Error: Registrar TXT: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString()); } } Console.Write("Se registro los pedidos consumidos."); Console.Write("..:Procesando Guias:.."); //---------------------------Pedido-------------------------------- //var lstOpOV = lstPedidos.Select(x => x.NroPedido).Distinct(); foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos) { try { GuiaWCFClient objGuiaVentaWCF = new GuiaWCFClient(); OrdenVentaWCFClient objOrdenVentaWCF = new OrdenVentaWCFClient(); gsOV_BuscarCabeceraResult objOrdenVentaCab; gsOV_BuscarDetalleResult[] objOrdenVentaDet = null; gsGuia_BuscarCabeceraResult objGuiaVentaCab = new gsGuia_BuscarCabeceraResult(); gsGuia_BuscarDetalleResult[] objGuiaVentaDet = null; gsGuia_BuscarDetalleResult objGuiaVentaDetUpdate = null; gsOV_BuscarDetalleResult objOrdenVenta_Linea = null; List <gsItem_BuscarResult> lstProductos = new List <gsItem_BuscarResult>(); gsOV_BuscarImpuestoResult[] lstImpuestos = null; GuiaVenta_LotesItemsResult[] lstLotes = null; bool? bloqueado = false; string mensajeBloqueo = null; AgendaWCFClient objAgendaWCFClient; VBG01134Result objAgendaCliente; decimal?lineaCredito = null; decimal?Id_Amarre = 0; decimal?TC = 0; int variable = Convert.ToInt32(pedido.NroPedido); if (variable == 23876) { TC = TC; } DateTime?fechaVecimiento = null; Console.Write("OP:" + pedido.NroPedido); Console.Write(" "); objAgendaWCFClient = new AgendaWCFClient(); objAgendaCliente = new VBG01134Result(); idOrdenVenta = int.Parse(pedido.NroPedido.ToString()); Console.WriteLine("Inicio: objOrdenVentaWCF.OrdenVenta_Buscar_Guia"); objOrdenVentaCab = objOrdenVentaWCF.OrdenVenta_Buscar_Guia(idEmpresa, codigoUsuario, idOrdenVenta, ref objOrdenVentaDet, ref lstImpuestos, ref bloqueado, ref mensajeBloqueo); Console.WriteLine("Inicio: objAgendaWCFClient.Agenda_BuscarCliente"); objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(idEmpresa, codigoUsuario, objOrdenVentaCab.ID_Agenda, ref lineaCredito, ref fechaVecimiento, ref TC); Id_Amarre = (decimal)pedido.Id_Amarre; objOrdenVenta_Linea = objOrdenVentaDet.ToList().FindAll(x => x.ID_Amarre == Id_Amarre).Single(); int idGuiaOp = 0; int idGuiaOpLinea = 0; int item_id = 0; idGuiaOp = int.Parse(objOrdenVentaCab.OpGuia.ToString()); idGuiaOpLinea = int.Parse(objOrdenVenta_Linea.OpGuia.ToString()); item_id = int.Parse(objOrdenVenta_Linea.Item_ID.ToString()); if (objOrdenVenta_Linea == null) { } else { if (idGuiaOpLinea > 0) { Console.WriteLine("Inicio: objGuiaVentaWCF.GuiaVenta_Buscar"); objGuiaVentaCab = objGuiaVentaWCF.GuiaVenta_Buscar(idEmpresa, codigoUsuario, idGuiaOp, ref objGuiaVentaDet, ref bloqueado, ref mensajeBloqueo); } else { Console.WriteLine("Inicio: GuiaVenta_ObtenerCabecera"); objGuiaVentaCab = GuiaVenta_ObtenerCabecera(objOrdenVentaCab, idGuiaOp); Console.WriteLine("Inicio: GuiaVenta_ObtenerDetalle"); objGuiaVentaDet = GuiaVenta_ObtenerDetalle(objOrdenVentaCab, objOrdenVentaDet, idEmpresa, codigoUsuario).ToArray(); } if (idGuiaOp > 0) { Console.WriteLine("Inicio: objGuiaVentaWCF.GuiaVenta_LotesItemBuscar"); lstLotes = objGuiaVentaWCF.GuiaVenta_LotesItemBuscar(idEmpresa, codigoUsuario, int.Parse(idGuiaOp.ToString()), int.Parse(objOrdenVenta_Linea.Item_ID.ToString())); } List <GuiaVenta_LotesItemsResult> LotesUp = new List <GuiaVenta_LotesItemsResult>(); if (lstLotes == null) { LotesUp = new List <GuiaVenta_LotesItemsResult>(); } else { LotesUp = ((GuiaVenta_LotesItemsResult[])lstLotes).ToList(); } Console.WriteLine("Inicio: GuiaVenta_ObtenerDetalle_Update"); objGuiaVentaDetUpdate = GuiaVenta_ObtenerDetalle_Update(objGuiaVentaDet, lstPedidos, Id_Amarre, ref LotesUp, item_id); lstLotes = (GuiaVenta_LotesItemsResult[])LotesUp.ToArray(); try { int Error = 0; int cont = 0; WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient(); //List<VBG00971Result> Lista_LoteVar = objGuiaVentaWCF.GuiaVenta_BuscarLotesxItem(idEmpresa, 1, int.Parse(pedido.NroPedido), (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, (int)pedido.Id_Amarre).ToList(); //List<VBG00971Result> Lista_LoteVar = dcg.VBG00971(item_id, ID_AlmacenAnexo, "GuiaVenta", 0, "OV", id_amarre).ToList(); DataTable dtTabla = new DataTable(); blTareo bl = new blTareo(); Console.WriteLine("Inicio de VBG00971_WMS"); //Lista Producción por recibir DataSet ds1 = bl.ListarDataSet( string.Format( //"set dateformat DMY\n" + "set dateformat " + getFormatDate() + "\n" + "exec " + esquema + "..VBG00971_WMS {0},{1},'GuiaVenta', 0, 'OV',{2},'{3}'", (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, pedido.Id_Amarre.ToString(), pedido.Lote.ToString() ) ); //Busca registro de interfaz dtTabla = ds1.Tables[0]; dtTabla.Columns.Add("Consumo", typeof(int)); Console.WriteLine("Fin de VBG00971_WMS"); int Pendiente = 0; Pendiente = Convert.ToInt32(pedido.CantidadEntrega); foreach (DataRow Lote in dtTabla.Rows)//traer solo lotes iguales al lote del kardex { string strLote = Lote["Lote"].ToString(); if (strLote == pedido.Lote.ToString()) { int Consumo = 0; int CantLote = Convert.ToInt32(Lote[10]); if (CantLote >= Pendiente) { Consumo = Pendiente; Pendiente = 0; } else { Consumo = CantLote; Pendiente = Pendiente - CantLote; } Lote["Consumo"] = Consumo; cont++; if (Pendiente <= 0) { break; } } } if (cont == 0) { //objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "No se encuentra Lote para el Item"); DataSet ds11 = bl.ListarDataSet( string.Format( "set dateformat DMY\n" + "exec " + esquema + "..gsInterfacePedidos_Update '{0}',{1},{2},'{3}'", pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "'F'", "No se encuentra Lote para el Item" )); //dcg.gsInterfacePedidos_Update(Lote, Id_Amarre, transferido, observacion); } else { try { Console.WriteLine("Registrando Guia y moviendo el Inv."); objGuiaVentaWCF.GuiaVenta_Registrar_wms(idEmpresa, 1, objGuiaVentaCab, objGuiaVentaDetUpdate, decimal.Parse(idGuiaOp.ToString()), lstLotes, EmpresaPT, pedido.Servicio.ToString(), pedido.Lote.ToString(), pedido.Id_Amarre.ToString()); Console.WriteLine("Finalizado"); //DataSet ds13 = bl.ListarDataSet( // string.Format( // "set dateformat DMY\n" + // "exec " + esquema + "..Cargar_Pedidos_UpdateEstilos '{0}','{1}'", // EmpresaPT, pedido.Servicio.ToString() // )); //DataSet ds14 = bl.ListarDataSet( // string.Format( // "set dateformat DMY\n" + // "exec " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'", // pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "S", "Se registro correctamente." // )); } catch (Exception ex) { //objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "Error, al registrar la Guia."); //DataSet ds12 = bl.ListarDataSet( //string.Format( //"set dateformat DMY\n" + //"exec " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'", //pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía" //)); Console.Write("Error al registrar guias: " + ex.Message.ToString()); } } } catch (Exception ex) { blTareo bl = new blTareo(); DataSet ds15 = bl.ListarDataSet( string.Format( "set dateformat DMY\n" + "exec " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'", pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía" )); Console.Write("Error al registrar guias: " + ex.Message.ToString()); } } } catch (Exception ex) { blTareo bl = new blTareo(); DataSet ds16 = bl.ListarDataSet( string.Format( "set dateformat DMY\n" + "exec " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'", pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía" )); Console.Write("Error: Registrar Guia: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString()); } } ////------------------Mover archivos--------- // //MoverArchivos(RutaOrigen, RutaSubmit, file, user, pass); ////} } catch (Exception ex) { Console.Write("Error: Registrar Guia, " + ex.Message.ToString()); //MoverArchivos(RutaOrigen, RutaFail, file, user, pass); } //} }