protected override bool CumplePoliticas(AuthReturnOrder result) { Order orden = result.Order; if (this.esWebUserExcluyente(orden.WebUserID)) { Console.WriteLine($"El webUserID { orden.WebUserID} se excluye por la lista que paso Mario "); return(false); } return(true); }
protected bool esFacturable(AuthReturnOrder result) { if (result.Order.TotalPrice > 0 && (result.Order.BillingMethodName.Contains("Convenio CIE") || result.Order.BillingMethodID == 5845 || result.Order.BillingMethodID == 5708)) { return(true); } else { Console.WriteLine($"{result.Order.OrderID} No se registra porque NO cuenta con el método de pago Convenio CIE"); return(false); } }
public AuthReturnOrder TraerInfo(int idOrden) { this._parametroOrden = new AuthHeaderOrder() { CompanyID = this._conexion.CompanyID, MasterKey = this._conexion.MasterKey, OrderID = idOrden, ProducerID = this._conexion.ProducerID, Username = this._conexion.Username }; //this._parametroOrden.OrderID = idOrden; AuthReturnOrder result = this.client.GetOrder(this._parametroOrden); //result.Jobs.ToList().ForEach(job => //{ // var j=this.client.GetJob(new AuthHeaderJob() // { // CompanyID= this._conexion.CompanyID, // JobID= job.JobID, // MasterKey= this._conexion.MasterKey, // ProducerID= this._conexion.ProducerID, // Username= this._conexion.Username // }); // if (j.JobExtras.Length > 0) // { // Console.WriteLine("Tiene configuracion extra"); // } // else // { // Console.WriteLine("No tiene configuracion extra"); // } //}); return(result); //Order orden = result.Order; //Job[] jobs = result.Jobs; //Console.WriteLine($"Limite de credito:{result.UserProfile.CreditLimit}"); //Console.WriteLine($"Own Credit:{result.UserProfile.OwnCredit}"); //Console.WriteLine($"Billing Method {result.Order.BillingMethodName}"); //jobs.ToList().ForEach(x => { // Console.WriteLine(x.Quantity +" " +x.SKU +" "+x.JobName); // }); }
protected void registrarEnBitacoraFacturacion(AuthReturnOrder result) { Order orden = result.Order; XElement detalleOrdenXML = result.ToXElement <AuthReturnOrder>(); OrdenFacturacionDAO ordenFacturacionDAO = new OrdenFacturacionDAO(); if (!ordenFacturacionDAO.Existe(orden.OrderID)) { ordenFacturacionDAO.Registrar(new OrdenFacturacion() { numero_orden = orden.OrderID, fecha_registro = DateTime.Now, Importe = Decimal.Parse((orden.TotalPrice + orden.ShippingPrice).ToString()), tienda = this._nombreTienda, detalle = detalleOrdenXML }); } }
public void RegistrarOrdenesEnEstadoCuentaSAAM(int id_tienda) { this._conexion.StartDate = new DateTime(2019, 05, 14, 15, 0, 0); var ordenes = this.GetListaOrdenes(OrderStatuses.All); ordenes.ToList().ForEach(numero_orden => { AuthReturnOrder result = this.TraerInfo(numero_orden); Order orden = result.Order; OrdenEstadoCuenta ordenSAAM = new OrdenEstadoCuenta(); ordenSAAM.numero_orden = orden.OrderID; ordenSAAM.id_tienda = id_tienda; ordenSAAM.total = (decimal)orden.TotalPrice; ordenSAAM.esCampana = orden.BillingMethodName.ToLowerInvariant().Contains("campaña"); ordenSAAM.BillingMethod = orden.BillingMethodName; ordenSAAM.estatus = orden.OrderStatus; ordenSAAM.OrderDate = orden.OrderDate; ordenSAAM.BillingDate = orden.BillingDate; ordenSAAM.ReleaseDate = orden.ReleaseDate; ordenSAAM.webUserID = result.UserProfile.WebUserID; ordenSAAM.fecha_registro = DateTime.Now; DAO.EstadodeCuentaSAAM.OrdenDAO ordenDAO = new DAO.EstadodeCuentaSAAM.OrdenDAO(); var _orden = ordenDAO.obtenerOrden(orden.OrderID); if (_orden != null && (_orden.estatus != ordenSAAM.estatus)) { Console.WriteLine($"Se actualiza la orden {_orden.numero_orden} "); ordenDAO.ActualizarEstatus(_orden.numero_orden, ordenSAAM.estatus); } if (_orden == null) { Console.WriteLine($"Registrando la orden {ordenSAAM.numero_orden}"); ordenDAO.Agregar(ordenSAAM); } }); }
public void LlenarInfoGoePower() { this._conexion.StartDate = DateTime.Today.AddDays(-320); //this._conexion.StartDate = new DateTime(2018, 1, 1); this._conexion.EndDate = DateTime.Now; int[] ordenes = this.GetListaOrdenes(OrderStatuses.All); if (ordenes == null) { Console.WriteLine($"No hay ordenes por procesar en la tienda {this._nombreTienda}"); return; } Console.WriteLine($"Total de ordenes {ordenes.Length} en la tienda {this._nombreTienda}"); foreach (int orden in ordenes) { OrdenDAO ordenDao = new OrdenDAO(); ItemDAO itemDao = new ItemDAO(); ClienteDAO clienteDAO = new ClienteDAO(); string __ordenID = $"{this._nombreTienda}_{orden}"; this._parametroOrden = new AuthHeaderOrder() { CompanyID = this._conexion.CompanyID, MasterKey = this._conexion.MasterKey, OrderID = orden, ProducerID = this._conexion.ProducerID, Username = this._conexion.Username }; AuthReturnOrder result = this.client.GetOrder(this._parametroOrden); Order order = result.Order; Job[] jobs = result.Jobs; var cte = clienteDAO.BuscarClienteCampoExtra(order.WebUserID.ToString()); XElement detalleOrdenXML; // Convertir La respuesta en XML para Guardarlo en la Base de Datos try { detalleOrdenXML = result.ToXElement <AuthReturnOrder>(); } catch (Exception e) { detalleOrdenXML = null; } Orden ordendDto = new Orden() { tienda = this._nombreTienda, ordenID = __ordenID, status = order.OrderStatus, webUserID = order.WebUserID, completeDate = order.CompletedDate, orderDate = order.OrderDate, releaseDate = order.ReleaseDate, shippingDate = order.ShippingDate, Total = (float)order.TotalPrice, clienteIntelisis = cte != null ? cte.Clave : "16776", detalle = detalleOrdenXML }; var o = ordenDao.existe(__ordenID); if (o != null) { if (o.status != order.OrderStatus) { Console.WriteLine("Es diferente"); Console.WriteLine($"La orden {orden} cambio de {o.status} a {order.OrderStatus}"); ordenDao.Actualiza(ordendDto); } continue; } Console.WriteLine($"Insertando la orden {orden} de la tienda {this._nombreTienda}"); ordenDao.Agregar(ordendDto); foreach (Job job in jobs) { Console.WriteLine($"Insertando el job {job.JobID}"); int cantidad = job.Quantity; int _cantidad = cantidad; if (job.Records > 1) { _cantidad = job.Records; } Item itemDto = new Item() { cantidad = job.Quantity, descripcion = job.JobName, ordenID = __ordenID, precio = (job.Price / _cantidad), records = job.Records, sku = job.SKU, setSize = job.SetSize }; itemDao.Agregar(itemDto); } if (order.ShippingPrice > 0) { Console.WriteLine($"Insertando el envio"); Item envio = new Item() { sku = "EN", descripcion = "Gastos de Envio", cantidad = 1, precio = order.ShippingPrice, ordenID = __ordenID, setSize = 1, records = 1 }; itemDao.Agregar(envio); } } }
protected void ProcesarOrden(int idOrden) { this._parametroOrden = new AuthHeaderOrder() { CompanyID = this._conexion.CompanyID, MasterKey = this._conexion.MasterKey, OrderID = idOrden, ProducerID = this._conexion.ProducerID, Username = this._conexion.Username }; AuthReturnOrder result = this.client.GetOrder(this._parametroOrden); Order orden = result.Order; Job[] jobs = result.Jobs; VentaDAO venta_dao = new VentaDAO(); if (this.esFacturacionPedido && !orden.BillingMethodName.Contains("Facturación por pedido")) { Console.WriteLine($"La orden {orden.OrderID} no es Facturacion por pedido"); return; } //bool existeVenta = venta_dao.Buscar(orden.OrderID.ToString()); bool existeVenta = this.Existe(orden.OrderID.ToString()); if (existeVenta) { Console.WriteLine("La orden {0} ya existe", orden.OrderID.ToString()); return; } ClienteDAO clienteDAO = new ClienteDAO(); CtoCampoExtra cte = clienteDAO.BuscarClienteCampoExtra(orden.WebUserID.ToString()); string nombreContacto = string.Empty; string clave = String.Empty; switch (this._nombreTienda) { case "kfc": cte = new CtoCampoExtra(); cte.Clave = "18933"; clave = cte.Clave; CteCto contacto = clienteDAO.BuscarContacto(orden.WebUserID); if (contacto != null) { nombreContacto = contacto.Nombre; } this.Cliente = new Cte() { Concepto = "SAAM KFC", Agente = "C.R.C", Condicion = "60 DIAS", DiasVencimiento = 60, }; break; case "lsm": clave = cte != null ? cte.Clave : "23565"; this.CargarDetalleCliente(clave); break; default: clave = cte != null ? cte.Clave : "16776"; this.CargarDetalleCliente(clave); break; } DateTime time = DateTime.Now; DateTime timeVencimiento = time.AddDays(this.Cliente.DiasVencimiento); #region RegistrarEnBitacoraFacturacion this.registrarEnBitacoraFacturacion(result); #endregion #region Llenado de Venta Venta venta = new Venta() { Empresa = "LITO", Contacto = orden.WebUserID, ContactoNombre = nombreContacto.Length > 0 ? nombreContacto : null, Mov = "Factura Electronica", FechaEmision = new DateTime(time.Year, time.Month, time.Day), //Concepto = $"SAAM {this._nombreTienda.ToUpper()}", Concepto = this.Cliente.Concepto, Moneda = "Pesos", TipoCambio = 1.0, Usuario = "MTOVAR", Referencia = orden.OrderID.ToString(), OrdenCompra = "", Estatus = "SINAFECTAR", Cliente = clave, Almacen = "AL PT", Observaciones = this.Cliente.Concepto, Condicion = this.esTransferencia ? "Contado Transferencia" : this.Cliente.Condicion, Vencimiento = new DateTime(timeVencimiento.Year, timeVencimiento.Month, timeVencimiento.Day), AgenteComision = agenteComision.HasValue ? agenteComision : null, Agente = this.Cliente.Agente, //Agente = this.agente, //"A.L.P.", //Importe = Decimal.Parse((orden.TotalPrice + orden.ShippingPrice).ToString()), //Impuestos = Decimal.Parse(orden.Tax1.ToString()), Sucursal = 0, SucursalOrigen = 0, Atencion = "", AtencionTelefono = "", Clase = "", Directo = true, OrdenID = orden.OrderID.ToString() }; #endregion if (this.Existe(orden.OrderID.ToString())) { Console.WriteLine("La orden {0} ya existe", orden.OrderID.ToString()); return; } int id_venta = venta_dao.Insertar(venta); int x = 1; #region Llenado de VentaD foreach (Job job in jobs) { int _cantidad = job.Quantity; if (job.Records > 1) { _cantidad = job.Records; } VentaD ventad = new VentaD() { ID = id_venta, Renglon = x * 2048, RenglonID = x, SubCuenta = $"P{x++}", Cantidad = _cantidad, Almacen = "AL PT", Articulo = job.SKU, Unidad = "pza", Precio = (job.TotalPrice / _cantidad), Impuesto1 = 16, DescripcionExtra = job.JobName, RenglonTipo = 'N' }; venta_dao.InsertarDetalle(ventad); } #endregion #region Costo por pedido cuando aplique //if (orden.OrderFee > 0) //{ // VentaD detalleEnvio = new VentaD() // { // ID = id_venta, // DescripcionExtra = "Costo por pedido", // RenglonID = x, // RenglonTipo = 'N', // Renglon = x * 2048, // SubCuenta = $"P{x++}", // Articulo = "CostoPedido", // Precio = Math.Round(orden.OrderFee, 2), // Cantidad = 1, // Impuesto1 = 16, // Unidad = "Servicio", // Almacen = "AL PT" // }; // venta_dao.InsertarDetalle(detalleEnvio); //} #endregion #region Envio if (orden.ShippingPrice > 0) { VentaD detalleEnvio = new VentaD() { ID = id_venta, DescripcionExtra = "Gastos de Envio", RenglonID = x, RenglonTipo = 'N', Renglon = x * 2048, SubCuenta = $"P{x}", Articulo = "EN", Precio = Math.Round(orden.ShippingPrice, 2), Cantidad = 1, Impuesto1 = 16, Unidad = "Servicio", Almacen = "AL PT" }; venta_dao.InsertarDetalle(detalleEnvio); } #endregion DAO.EstadodeCuentaSAAM.BitacoraDAO bitacoraDAO = new DAO.EstadodeCuentaSAAM.BitacoraDAO(); bitacoraDAO.Insertar(new BitacoraIntelisis() { fecha_registro = DateTime.Now, numero_orden = orden.OrderID, total = Decimal.Parse((orden.TotalPrice + orden.ShippingPrice).ToString()) }); //this.CambioStatusOrden(orden.OrderID.ToString()); }
protected virtual bool CumplePoliticas(AuthReturnOrder result) { return(true); }
protected new void ProcesarOrden(int idOrden) { this._parametroOrden = new AuthHeaderOrder() { CompanyID = this._conexion.CompanyID, MasterKey = this._conexion.MasterKey, OrderID = idOrden, ProducerID = this._conexion.ProducerID, Username = this._conexion.Username }; //this._parametroOrden.OrderID = idOrden; AuthReturnOrder result = this.client.GetOrder(this._parametroOrden); if (!this.esFacturable(result)) { return; } //if (!this.CumplePoliticas(result)) //{ // return; //} Order orden = result.Order; Job[] jobs = result.Jobs; VentaDAO venta_dao = new VentaDAO(); bool existeVenta = venta_dao.Buscar(orden.OrderID.ToString()); if (existeVenta) { Console.WriteLine("La orden {0} ya existe", orden.OrderID.ToString()); return; } DAO.Lito.ClienteDAO cliente_dao = new DAO.Lito.ClienteDAO(); //CteHonda cte = cliente_dao.BuscarCliente(orden.WebUserID.ToString()); CtoCampoExtra cte = cliente_dao.BuscarClienteCampoExtra(orden.WebUserID.ToString()); this.CargarDetalleCliente(cte != null?cte.Clave: "16776"); DateTime time = DateTime.Now; DateTime timeVencimiento = time.AddDays(this.Cliente.DiasVencimiento); #region RegistrarEnBitacoraFacturacion this.registrarEnBitacoraFacturacion(result); #endregion #region Llenado de Venta Venta venta = new Venta() { Empresa = "LITO", Mov = "Factura Electronica", FechaEmision = new DateTime(time.Year, time.Month, time.Day), //Concepto = $"SAAM {this._nombreTienda.ToUpper()}", Concepto = this.Cliente.Concepto, Moneda = "Pesos", TipoCambio = 1.0, Usuario = "MTOVAR", Referencia = orden.OrderID.ToString(), OrdenCompra = "", Estatus = "SINAFECTAR", Cliente = cte != null ? cte.Clave : "16776", Almacen = "AL PT", //Observaciones = $"SAAM {this._nombreTienda.ToUpper()}", Observaciones = this.Cliente.Concepto, //Condicion = this.condiciones, Condicion = this.Cliente.Condicion, Vencimiento = new DateTime(timeVencimiento.Year, timeVencimiento.Month, timeVencimiento.Day), AgenteComision = agenteComision.HasValue ? agenteComision : null, Agente = this.Cliente.Agente, //Agente = this.agente, //"A.L.P.", //Importe = Decimal.Parse((orden.TotalPrice + orden.ShippingPrice).ToString()), //Impuestos = Decimal.Parse(orden.Tax1.ToString()), Sucursal = 0, SucursalOrigen = 0, Atencion = "", AtencionTelefono = "", Clase = "", Directo = true, OrdenID = orden.OrderID.ToString() }; #endregion int id_venta = venta_dao.Insertar(venta); int x = 1; #region Llenado de VentaD foreach (Job job in jobs) { int _cantidad = job.Quantity; if (job.Records > 1) { _cantidad = job.Records; } VentaD ventad = new VentaD() { ID = id_venta, Renglon = x * 2048, RenglonID = x, SubCuenta = $"P{x++}", Cantidad = _cantidad, Almacen = "AL PT", Articulo = job.SKU, Unidad = "pza", Precio = (job.TotalPrice / _cantidad), Impuesto1 = 16, DescripcionExtra = job.JobName, RenglonTipo = 'N' }; venta_dao.InsertarDetalle(ventad); } #endregion #region Costo por pedido cuando aplique //if (orden.OrderFee > 0) //{ // VentaD detalleEnvio = new VentaD() // { // ID = id_venta, // DescripcionExtra = "Costo por pedido", // RenglonID = x, // RenglonTipo = 'N', // Renglon = x * 2048, // SubCuenta = $"P{x++}", // Articulo = "CostoPedido", // Precio = Math.Round(orden.OrderFee, 2), // Cantidad = 1, // Impuesto1 = 16, // Unidad = "Servicio", // Almacen = "AL PT" // }; // venta_dao.InsertarDetalle(detalleEnvio); //} #endregion #region Envio if (orden.ShippingPrice > 0) { VentaD detalleEnvio = new VentaD() { ID = id_venta, DescripcionExtra = "Gastos de Envio", RenglonID = x, RenglonTipo = 'N', Renglon = x * 2048, SubCuenta = $"P{x}", Articulo = "EN", Precio = Math.Round(orden.ShippingPrice, 2), Cantidad = 1, Impuesto1 = 16, Unidad = "Servicio", Almacen = "AL PT" }; venta_dao.InsertarDetalle(detalleEnvio); } #endregion }