public IHttpActionResult SaldoInicial(string fecha, int idCliente) { try { ServiciosVentas servicio = new ServiciosVentas(); decimal resp = servicio.DocumentoVentaObtenerSaldoInicial(idCliente, fecha); return(Ok(resp)); } catch (Exception ex) { LoggerHelper.LogError(MethodBase.GetCurrentMethod(), ex); return(BadRequest(ex.GetExceptionOriginal().Message)); } }
public HttpResponseMessage ExportarCtaCteCsv(string fechaDesde, string fechaHasta, int idCliente) { HttpResponseMessage result = null; try { ServiciosVentas servicio = new ServiciosVentas(); decimal saldoInicial = servicio.DocumentoVentaObtenerSaldoInicial(idCliente, fechaDesde); List <ItemListado> listado = servicio.ObtenerCtaCteCliente(fechaDesde, fechaHasta, idCliente, saldoInicial); StringBuilder registros = new StringBuilder(); registros.AppendLine("Fecha,Comprobante,Pedido Facturado,Debito,Credito,Saldo"); listado.ForEach(delegate(ItemListado item) { registros.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}", item.Campo1, item.Campo2, item.Campo3, item.Campo4, item.Campo5, item.Campo6)); }); byte[] byteArray = Encoding.UTF8.GetBytes(registros.ToString()); MemoryStream reportStream = new MemoryStream(byteArray); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(reportStream); //excel //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); //csv result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = string.Format("CtaCte_{0}_{1}.csv", idCliente.ToString(), DateTime.Now.ToString("yyyyMMdd")) }; return(result); } catch (Exception ex) { LoggerHelper.LogError(MethodBase.GetCurrentMethod(), ex); return(Request.CreateResponse(HttpStatusCode.Gone)); } }