public List<ReportePrepago> ReporteComprasxCliente(string tiporeporte, string fechadesde, string fechahasta, string modotrans, int idCliente = 0)
 {
     string fechasdesdemod = fechadesde.Substring(6, 4) + fechadesde.Substring(3, 2) + fechadesde.Substring(0, 2);
     string fechahastamod = fechahasta.Substring(6, 4) + fechahasta.Substring(3, 2) + fechahasta.Substring(0, 2);
     List<ReportePrepago> reporte = new List<ReportePrepago>();
     EncabezadoReporte encabezado = new EncabezadoReporte();
     #region Por Cliente específico
     if (tiporeporte == "uno")
     {
         List<BeneficiarioPrepagoIndex> beneficiarios = repCliente.FindBeneficiarios(idCliente, "", "", "", "", "").OrderBy(x => x.Afiliado.id).ToList();
         encabezado.nombreReporte = "Reporte de Compras";
         encabezado.tipoconsultaReporte = "Por Cliente";
         encabezado.parametrotipoconsultaReporte = beneficiarios.First().Cliente.rifCliente + " " + beneficiarios.First().Cliente.nameCliente;
         encabezado.fechainicioReporte = fechadesde;
         encabezado.fechafinReporte = fechahasta;
         encabezado.modotransaccionReporte = modotrans;
         foreach (BeneficiarioPrepagoIndex b in beneficiarios)
         {
             //string movimientosPrepagoJson = WSL.Cards.getReport(fechasdesdemod, fechahastamod, b.Afiliado.docnumber.Substring(2), "NULL", Globals.TRANSCODE_COMPRA_PREPAGO);
             //if (WSL.Cards.ExceptionServicioCards(movimientosPrepagoJson))
             //{
             //    return null;
             //}
             //List<Movimiento> movimientosPrepago = (List<Movimiento>)JsonConvert.DeserializeObject<List<Movimiento>>(movimientosPrepagoJson).OrderBy(x => x.fecha).ToList();
             List<Movimiento> movimientosPrepago = new List<Movimiento>();
             using (CardsEntities db = new CardsEntities())
             {
                 db.Database.Connection.ConnectionString = AppModule.ConnectionString("Cards");
                 foreach (PLZ_GETREPORT_Result fila in db.PLZ_GETREPORT(fechasdesdemod, fechahastamod, b.Afiliado.docnumber.Substring(2), "NULL", Globals.TRANSCODE_COMPRA_PREPAGO))
                 {
                     if (fila.TRANSCODE.Value.ToString() != Globals.TRANSCODE_CONSULTA_DE_SALDO)
                     {
                         Movimiento mov = new Movimiento()
                         {
                             fecha = fila.FECHA,
                             batchtime = fila.BATCHTIME,
                             saldo = fila.SALDO.Value,
                             isodescription = fila.ISODESCRIPTION,
                             transcode = fila.TRANSCODE.ToString(),
                             transname = fila.TRANSNAME,
                             pan = fila.PAN,
                             batchid = fila.BATCHID
                         };
                         movimientosPrepago.Add(mov);
                     }
                 }
             } foreach (Movimiento m in movimientosPrepago)
             {
                 ReportePrepago linea = new ReportePrepago()
                 {
                     Beneficiario = b,
                     fecha = DateTime.ParseExact(m.fecha.Substring(6, 2) + "/" + m.fecha.Substring(4, 2) + "/" + m.fecha.Substring(0, 4), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                     monto = Convert.ToDecimal(m.saldo),
                     detalle = m.isodescription,
                     tipo = m.transcode + "-" + m.transname,
                     numerotarjeta = Convert.ToDecimal(m.pan),
                     batchid = m.batchid.ToString(),
                     Encabezado = encabezado
                 };
                 if (modotrans == "En Linea")
                 {
                     if (!linea.detalle.Contains("offline"))
                     {
                         reporte.Add(linea);
                     }
                 }
                 else if (modotrans == "Offline")
                 {
                     if (linea.detalle.Contains("offline"))
                     {
                         reporte.Add(linea);
                     }
                 }
                 else
                 {
                     reporte.Add(linea);
                 }
             }
         }
     }
     #endregion
     #region Todos los Clientes
     else if (tiporeporte == "todos")
     {
         ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
         List<ClientePrepago> clientes = repCliente.Find("", "").OrderBy(x => x.idCliente).ToList();
         encabezado.nombreReporte = "Reporte de Compras";
         encabezado.tipoconsultaReporte = "Por Cliente";
         encabezado.parametrotipoconsultaReporte = "Todos";
         encabezado.fechainicioReporte = fechadesde;
         encabezado.fechafinReporte = fechahasta;
         encabezado.modotransaccionReporte = modotrans;
         foreach (ClientePrepago c in clientes)
         {
             List<BeneficiarioPrepagoIndex> beneficiarios = repCliente.FindBeneficiarios(c.idCliente, "", "", "", "", "").OrderBy(x => x.Afiliado.id).ToList();
             foreach (BeneficiarioPrepagoIndex b in beneficiarios)
             {
                 //string movimientosPrepagoJson = WSL.Cards.getReport(fechasdesdemod, fechahastamod, b.Afiliado.docnumber.Substring(2), "NULL", Globals.TRANSCODE_COMPRA_PREPAGO);
                 //if (WSL.Cards.ExceptionServicioCards(movimientosPrepagoJson))
                 //{
                 //    return null;
                 //}
                 //List<Movimiento> movimientosPrepago = (List<Movimiento>)JsonConvert.DeserializeObject<List<Movimiento>>(movimientosPrepagoJson).OrderBy(x => x.fecha).ToList();
                 List<Movimiento> movimientosPrepago = new List<Movimiento>();
                 using (CardsEntities db = new CardsEntities())
                 {
                     db.Database.Connection.ConnectionString = AppModule.ConnectionString("Cards");
                     foreach (PLZ_GETREPORT_Result fila in db.PLZ_GETREPORT(fechasdesdemod, fechahastamod, b.Afiliado.docnumber.Substring(2), "NULL", Globals.TRANSCODE_COMPRA_PREPAGO))
                     {
                         if (fila.TRANSCODE.Value.ToString() != Globals.TRANSCODE_CONSULTA_DE_SALDO)
                         {
                             Movimiento mov = new Movimiento()
                             {
                                 fecha = fila.FECHA,
                                 batchtime = fila.BATCHTIME,
                                 saldo = fila.SALDO.Value,
                                 isodescription = fila.ISODESCRIPTION,
                                 transcode = fila.TRANSCODE.ToString(),
                                 transname = fila.TRANSNAME,
                                 pan = fila.PAN,
                                 batchid = fila.BATCHID
                             };
                             movimientosPrepago.Add(mov);
                         }
                     }
                 }
                 foreach (Movimiento m in movimientosPrepago)
                 {
                     ReportePrepago linea = new ReportePrepago()
                     {
                         Beneficiario = b,
                         fecha = DateTime.ParseExact(m.fecha.Substring(6, 2) + "/" + m.fecha.Substring(4, 2) + "/" + m.fecha.Substring(0, 4), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                         monto = Convert.ToDecimal(m.saldo),
                         detalle = m.isodescription,
                         tipo = m.transcode + "-" + m.transname,
                         numerotarjeta = Convert.ToDecimal(m.pan),
                         batchid = m.batchid.ToString(),
                         Encabezado = encabezado
                     };
                     if (modotrans == "En Linea")
                     {
                         if (!linea.detalle.Contains("offline"))
                         {
                             reporte.Add(linea);
                         }
                     }
                     else if (modotrans == "Offline")
                     {
                         if (linea.detalle.Contains("offline"))
                         {
                             reporte.Add(linea);
                         }
                     }
                     else
                     {
                         reporte.Add(linea);
                     }
                 }
             }
         }
     }
     #endregion
     if (reporte.Count == 0)
     {
         ReportePrepago r = new ReportePrepago()
         {
             Encabezado = encabezado
         };
         reporte.Add(r);
     }
     return reporte.OrderBy(x => x.fecha).ToList();
 }
        public List<ReportePrepago> ReporteTarjetasxCliente(string tiporeporte, string fechadesde, string fechahasta, int idCliente = 0, string estadoTarjeta = "")
        {
            List<ReportePrepago> reporte = new List<ReportePrepago>();
            using (LealtadEntities db = new LealtadEntities())
            {
                db.Database.Connection.ConnectionString = AppModule.ConnectionString("SumaLealtad");
                #region Por Cliente específico
                if (tiporeporte == "uno")
                {
                    if (estadoTarjeta == "")
                    {
                        reporte = (from a in db.Affiliates
                                   join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                                   join s in db.SumaStatuses on a.sumastatusid equals s.id
                                   join t in db.Types on a.typeid equals t.id
                                   join b in db.PrepaidBeneficiaries on a.id equals b.affiliateid
                                   join p in db.PrepaidCustomers on b.prepaidcustomerid equals p.id
                                   join tar in db.TARJETAS on a.id equals tar.NRO_AFILIACION
                                   where p.id == idCliente
                                   select new ReportePrepago()
                                   {
                                       Beneficiario = new BeneficiarioPrepagoIndex()
                                       {
                                           Afiliado = new AfiliadoSumaIndex()
                                           {
                                               docnumber = a.docnumber,
                                               name = c.NOMBRE_CLIENTE1,
                                               lastname1 = c.APELLIDO_CLIENTE1
                                           },
                                           Cliente = new ClientePrepago()
                                           {
                                               idCliente = idCliente,
                                               nameCliente = p.name
                                           }
                                       },
                                       fecha = tar.FECHA_CREACION == null ? new DateTime() : tar.FECHA_CREACION.Value,
                                       numerotarjeta = tar.NRO_TARJETA,
                                       estatustarjeta = tar.ESTATUS_TARJETA,
                                       Encabezado = new EncabezadoReporte()
                                       {
                                           nombreReporte = "Reporte de Tarjetas",
                                           tipoconsultaReporte = "Por Cliente",
                                           parametrotipoconsultaReporte = p.rif + " " + p.name,
                                           fechainicioReporte = fechadesde,
                                           fechafinReporte = fechahasta,
                                           estatustarjetaReporte = "Todos"
                                       }
                                   }).ToList();
                    }
                    else
                    {
                        reporte = (from a in db.Affiliates
                                   join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                                   join s in db.SumaStatuses on a.sumastatusid equals s.id
                                   join t in db.Types on a.typeid equals t.id
                                   join b in db.PrepaidBeneficiaries on a.id equals b.affiliateid
                                   join p in db.PrepaidCustomers on b.prepaidcustomerid equals p.id
                                   join tar in db.TARJETAS on a.id equals tar.NRO_AFILIACION
                                   where p.id == idCliente && tar.ESTATUS_TARJETA == estadoTarjeta
                                   select new ReportePrepago()
                                   {
                                       Beneficiario = new BeneficiarioPrepagoIndex()
                                       {
                                           Afiliado = new AfiliadoSumaIndex()
                                           {
                                               docnumber = a.docnumber,
                                               name = c.NOMBRE_CLIENTE1,
                                               lastname1 = c.APELLIDO_CLIENTE1
                                           },
                                           Cliente = new ClientePrepago()
                                           {
                                               idCliente = idCliente,
                                               nameCliente = p.name
                                           }
                                       },
                                       fecha = tar.FECHA_CREACION == null ? new DateTime() : tar.FECHA_CREACION.Value,
                                       numerotarjeta = tar.NRO_TARJETA,
                                       estatustarjeta = tar.ESTATUS_TARJETA,
                                       Encabezado = new EncabezadoReporte()
                                       {
                                           nombreReporte = "Reporte de Tarjetas",
                                           tipoconsultaReporte = "Por Cliente",
                                           parametrotipoconsultaReporte = p.rif + " " + p.name,
                                           fechainicioReporte = fechadesde,
                                           fechafinReporte = fechahasta,
                                           estatustarjetaReporte = estadoTarjeta
                                       }
                                   }).ToList();
                    }
                    if (reporte.Count() == 0)
                    {
                        ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
                        ClientePrepago Cliente = repCliente.Find(idCliente);
                        ReportePrepago r = new ReportePrepago()
                        {
                            Encabezado = new EncabezadoReporte()
                            {
                                nombreReporte = "Reporte de Tarjetas",
                                tipoconsultaReporte = "Por Cliente",
                                parametrotipoconsultaReporte = Cliente.rifCliente + " " + Cliente.nameCliente,
                                fechainicioReporte = fechadesde,
                                fechafinReporte = fechahasta,
                                estatustarjetaReporte = estadoTarjeta
                            }
                        };
                        reporte.Add(r);
                    }
                }
                #endregion
                #region Todos los Clientes
                else if (tiporeporte == "todos")
                {
                    if (estadoTarjeta == "")
                    {
                        reporte = (from a in db.Affiliates
                                   join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                                   join s in db.SumaStatuses on a.sumastatusid equals s.id
                                   join t in db.Types on a.typeid equals t.id
                                   join b in db.PrepaidBeneficiaries on a.id equals b.affiliateid
                                   join p in db.PrepaidCustomers on b.prepaidcustomerid equals p.id
                                   join tar in db.TARJETAS on a.id equals tar.NRO_AFILIACION
                                   select new ReportePrepago()
                                   {
                                       Beneficiario = new BeneficiarioPrepagoIndex()
                                       {
                                           Afiliado = new AfiliadoSumaIndex()
                                           {
                                               docnumber = a.docnumber,
                                               name = c.NOMBRE_CLIENTE1,
                                               lastname1 = c.APELLIDO_CLIENTE1
                                           },
                                           Cliente = new ClientePrepago()
                                           {
                                               idCliente = idCliente,
                                               nameCliente = p.name
                                           }
                                       },
                                       fecha = tar.FECHA_CREACION == null ? new DateTime() : tar.FECHA_CREACION.Value,
                                       numerotarjeta = tar.NRO_TARJETA,
                                       estatustarjeta = tar.ESTATUS_TARJETA,
                                       Encabezado = new EncabezadoReporte()
                                       {
                                           nombreReporte = "Reporte de Tarjetas",
                                           tipoconsultaReporte = "Por Cliente",
                                           parametrotipoconsultaReporte = "Todos",
                                           fechainicioReporte = fechadesde,
                                           fechafinReporte = fechahasta,
                                           estatustarjetaReporte = "Todos"
                                       }
                                   }).ToList();
                    }
                    else
                    {
                        reporte = (from a in db.Affiliates
                                   join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                                   join s in db.SumaStatuses on a.sumastatusid equals s.id
                                   join t in db.Types on a.typeid equals t.id
                                   join b in db.PrepaidBeneficiaries on a.id equals b.affiliateid
                                   join p in db.PrepaidCustomers on b.prepaidcustomerid equals p.id
                                   join tar in db.TARJETAS on a.id equals tar.NRO_AFILIACION
                                   where tar.ESTATUS_TARJETA == estadoTarjeta
                                   select new ReportePrepago()
                                   {
                                       Beneficiario = new BeneficiarioPrepagoIndex()
                                       {
                                           Afiliado = new AfiliadoSumaIndex()
                                           {
                                               docnumber = a.docnumber,
                                               name = c.NOMBRE_CLIENTE1,
                                               lastname1 = c.APELLIDO_CLIENTE1
                                           },
                                           Cliente = new ClientePrepago()
                                           {
                                               idCliente = idCliente,
                                               nameCliente = p.name
                                           }
                                       },
                                       fecha = tar.FECHA_CREACION == null ? new DateTime() : tar.FECHA_CREACION.Value,
                                       numerotarjeta = tar.NRO_TARJETA,
                                       estatustarjeta = tar.ESTATUS_TARJETA,
                                       Encabezado = new EncabezadoReporte()
                                       {
                                           nombreReporte = "Reporte de Tarjetas",
                                           tipoconsultaReporte = "Por Cliente",
                                           parametrotipoconsultaReporte = "Todos",
                                           fechainicioReporte = fechadesde,
                                           fechafinReporte = fechahasta,
                                           estatustarjetaReporte = estadoTarjeta
                                       }
                                   }).ToList();

                    }
                    if (reporte.Count() == 0)
                    {
                        ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
                        ClientePrepago Cliente = repCliente.Find(idCliente);
                        ReportePrepago r = new ReportePrepago()
                        {
                            Encabezado = new EncabezadoReporte()
                            {
                                nombreReporte = "Reporte de Tarjetas",
                                tipoconsultaReporte = "Por Cliente",
                                parametrotipoconsultaReporte = "Todos",
                                fechainicioReporte = fechadesde,
                                fechafinReporte = fechahasta,
                                estatustarjetaReporte = estadoTarjeta
                            }
                        };
                        reporte.Add(r);
                    }
                }
                #endregion
            }
            DateTime desde = DateTime.ParseExact(fechadesde, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime hasta = DateTime.ParseExact(fechahasta, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            return reporte.Where(x => x.fecha.Date >= desde && x.fecha.Date <= hasta).OrderBy(x => x.fecha).ToList();
        }
 public BeneficiarioPrepago Find(int id)
 {
     AfiliadoSumaRepository repAfiliado = new AfiliadoSumaRepository();
     ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
     BeneficiarioPrepago beneficiario = new BeneficiarioPrepago()
     {
         Afiliado = repAfiliado.Find(id),
         Cliente = repCliente.FindXidAfiliado(id)
     };
     beneficiario.Afiliado.idClientePrepago = beneficiario.Cliente.idCliente;
     beneficiario.Afiliado.NombreClientePrepago = beneficiario.Cliente.nameCliente;
     return beneficiario;
 }
 public List<ReportePrepago> ReporteRecargasxCliente(string tiporeporte, string fechadesde, string fechahasta, int idCliente = 0, string referencia = "")
 {
     List<ReportePrepago> reporte = new List<ReportePrepago>();
     using (LealtadEntities db = new LealtadEntities())
     {
         db.Database.Connection.ConnectionString = AppModule.ConnectionString("SumaLealtad");
         #region Por Cliente específico
         if (tiporeporte == "uno")
         {
             if (referencia == "")
             {
                 reporte = (from o in db.Orders
                            join od in db.OrdersDetails on o.id equals od.orderid
                            join a in db.Affiliates on od.customerid equals a.id
                            join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                            join s in db.SumaStatuses on o.sumastatusid equals s.id
                            join p in db.PrepaidCustomers on o.prepaidcustomerid equals p.id
                            where o.prepaidcustomerid == idCliente && s.name == "Procesada" && od.comments == "Recarga efectiva"
                            select new ReportePrepago()
                            {
                                Beneficiario = new BeneficiarioPrepagoIndex()
                                {
                                    Afiliado = new AfiliadoSumaIndex()
                                    {
                                        docnumber = a.docnumber,
                                        name = c.NOMBRE_CLIENTE1,
                                        lastname1 = c.APELLIDO_CLIENTE1
                                    },
                                    Cliente = new ClientePrepago()
                                    {
                                        idCliente = idCliente,
                                        nameCliente = p.name
                                    }
                                },
                                fecha = o.processdate,
                                monto = od.amount,
                                detalle = od.comments,
                                tipo = "200-Recarga",
                                batchid = od.cardsresponse,
                                nroordenrecarga = o.id,
                                referenciarecarga = o.documento,
                                observacionesrecarga = o.observaciones,
                                Encabezado = new EncabezadoReporte()
                                {
                                    nombreReporte = "Reporte de Recargas",
                                    tipoconsultaReporte = "Por Cliente",
                                    parametrotipoconsultaReporte = p.rif + " " + p.name,
                                    fechainicioReporte = fechadesde,
                                    fechafinReporte = fechahasta,
                                    documentoreferenciaReporte = referencia
                                }
                            }).ToList();
             }
             else
             {
                 reporte = (from o in db.Orders
                            join od in db.OrdersDetails on o.id equals od.orderid
                            join a in db.Affiliates on od.customerid equals a.id
                            join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                            join s in db.SumaStatuses on o.sumastatusid equals s.id
                            join p in db.PrepaidCustomers on o.prepaidcustomerid equals p.id
                            where o.prepaidcustomerid == idCliente && s.name == "Procesada" && o.documento == referencia && od.comments == "Recarga efectiva"
                            select new ReportePrepago()
                            {
                                Beneficiario = new BeneficiarioPrepagoIndex()
                                {
                                    Afiliado = new AfiliadoSumaIndex()
                                    {
                                        docnumber = a.docnumber,
                                        name = c.NOMBRE_CLIENTE1,
                                        lastname1 = c.APELLIDO_CLIENTE1
                                    },
                                    Cliente = new ClientePrepago()
                                    {
                                        idCliente = idCliente,
                                        nameCliente = p.name
                                    }
                                },
                                fecha = o.processdate,
                                monto = od.amount,
                                detalle = od.comments,
                                tipo = "200-Recarga",
                                batchid = od.cardsresponse,
                                nroordenrecarga = o.id,
                                referenciarecarga = o.documento,
                                observacionesrecarga = o.observaciones,
                                Encabezado = new EncabezadoReporte()
                                {
                                    nombreReporte = "Reporte de Recargas",
                                    tipoconsultaReporte = "Por Cliente",
                                    parametrotipoconsultaReporte = p.rif + " " + p.name,
                                    fechainicioReporte = fechadesde,
                                    fechafinReporte = fechahasta,
                                    documentoreferenciaReporte = referencia
                                }
                            }).ToList();
             }
             if (reporte.Count() == 0)
             {
                 ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
                 ClientePrepago Cliente = repCliente.Find(idCliente);
                 ReportePrepago r = new ReportePrepago()
                 {
                     Encabezado = new EncabezadoReporte()
                     {
                         nombreReporte = "Reporte de Recargas",
                         tipoconsultaReporte = "Por Cliente",
                         parametrotipoconsultaReporte = Cliente.rifCliente + " " + Cliente.nameCliente,
                         fechainicioReporte = fechadesde,
                         fechafinReporte = fechahasta,
                         documentoreferenciaReporte = referencia
                     }
                 };
                 reporte.Add(r);
             }
         }
         #endregion
         #region Todos los Clientes
         else if (tiporeporte == "todos")
         {
             if (referencia == "")
             {
                 reporte = (from o in db.Orders
                            join od in db.OrdersDetails on o.id equals od.orderid
                            join a in db.Affiliates on od.customerid equals a.id
                            join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                            join s in db.SumaStatuses on o.sumastatusid equals s.id
                            join p in db.PrepaidCustomers on o.prepaidcustomerid equals p.id
                            where s.name == "Procesada" && od.comments == "Recarga efectiva"
                            select new ReportePrepago()
                            {
                                Beneficiario = new BeneficiarioPrepagoIndex()
                                {
                                    Afiliado = new AfiliadoSumaIndex()
                                    {
                                        docnumber = a.docnumber,
                                        name = c.NOMBRE_CLIENTE1,
                                        lastname1 = c.APELLIDO_CLIENTE1
                                    },
                                    Cliente = new ClientePrepago()
                                    {
                                        idCliente = idCliente,
                                        nameCliente = p.name
                                    }
                                },
                                fecha = o.processdate,
                                monto = od.amount,
                                detalle = od.comments,
                                tipo = "200-Recarga",
                                batchid = od.cardsresponse,
                                nroordenrecarga = o.id,
                                referenciarecarga = o.documento,
                                observacionesrecarga = o.observaciones,
                                Encabezado = new EncabezadoReporte()
                                {
                                    nombreReporte = "Reporte de Recargas",
                                    tipoconsultaReporte = "Por Cliente",
                                    parametrotipoconsultaReporte = "Todos",
                                    fechainicioReporte = fechadesde,
                                    fechafinReporte = fechahasta,
                                    documentoreferenciaReporte = referencia
                                }
                            }).ToList();
             }
             else
             {
                 reporte = (from o in db.Orders
                            join od in db.OrdersDetails on o.id equals od.orderid
                            join a in db.Affiliates on od.customerid equals a.id
                            join c in db.CLIENTES on a.docnumber equals c.TIPO_DOCUMENTO + "-" + c.NRO_DOCUMENTO
                            join s in db.SumaStatuses on o.sumastatusid equals s.id
                            join p in db.PrepaidCustomers on o.prepaidcustomerid equals p.id
                            where s.name == "Procesada" && o.documento == referencia && od.comments == "Recarga efectiva"
                            select new ReportePrepago()
                            {
                                Beneficiario = new BeneficiarioPrepagoIndex()
                                {
                                    Afiliado = new AfiliadoSumaIndex()
                                    {
                                        docnumber = a.docnumber,
                                        name = c.NOMBRE_CLIENTE1,
                                        lastname1 = c.APELLIDO_CLIENTE1
                                    },
                                    Cliente = new ClientePrepago()
                                    {
                                        idCliente = idCliente,
                                        nameCliente = p.name
                                    }
                                },
                                fecha = o.processdate,
                                monto = od.amount,
                                detalle = od.comments,
                                tipo = "200-Recarga",
                                batchid = od.cardsresponse,
                                nroordenrecarga = o.id,
                                referenciarecarga = o.documento,
                                observacionesrecarga = o.observaciones,
                                Encabezado = new EncabezadoReporte()
                                {
                                    nombreReporte = "Reporte de Recargas",
                                    tipoconsultaReporte = "Por Cliente",
                                    parametrotipoconsultaReporte = "Todos",
                                    fechainicioReporte = fechadesde,
                                    fechafinReporte = fechahasta,
                                    documentoreferenciaReporte = referencia
                                }
                            }).ToList();
             }
             if (reporte.Count() == 0)
             {
                 ClientePrepagoRepository repCliente = new ClientePrepagoRepository();
                 ClientePrepago Cliente = repCliente.Find(idCliente);
                 ReportePrepago r = new ReportePrepago()
                 {
                     Encabezado = new EncabezadoReporte()
                     {
                         nombreReporte = "Reporte de Recargas",
                         tipoconsultaReporte = "Por Cliente",
                         parametrotipoconsultaReporte = "Todos",
                         fechainicioReporte = fechadesde,
                         fechafinReporte = fechahasta,
                         documentoreferenciaReporte = referencia
                     }
                 };
                 reporte.Add(r);
             }
         }
         #endregion
     }
     DateTime desde = DateTime.ParseExact(fechadesde, "dd/MM/yyyy", CultureInfo.InvariantCulture);
     DateTime hasta = DateTime.ParseExact(fechahasta, "dd/MM/yyyy", CultureInfo.InvariantCulture);
     return reporte.Where(x => x.fecha.Date >= desde && x.fecha.Date <= hasta).OrderBy(x => x.fecha).ToList();
 }