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 }
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()); }
public void InsertarDetalle(VentaD venta) { this.ctx.VentaD.InsertOnSubmit(venta); this.ctx.SubmitChanges(); }