Ejemplo n.º 1
0
        public void Delete(int Id)
        {
            Init();
            try
            {
                 using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION repositorio = new RepositorioFACTURACION(context);
                    FACTURACION _FACTURACION = repositorio.GetById(Id);

                    if(Equals(_FACTURACION ,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =",Id.ToString()));
                    }

                    _FACTURACION.ACTIVO = false;

                    context.SaveChanges();
                }
            }
            catch(Exception ex)
            {
                 ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                 throw ex;
            }
        }
Ejemplo n.º 2
0
        public int Add(int CLIENTEId, int FACTURACIONId, int TIPO_FACTURAId, int CORRELATIVO, string RUT_LABORATORIO, int NETO, int IVA, int TOTAL, string NOMBRE_CLIENTE = "", string RUT_CLIENTE = "", string DIRECCION = "", string NOMBRE_COMUNA = "", int? NUMERO_FACTURA = null, int? DESCUENTO = null, string FONO = "", string GIRO = "", string DETALLE = "", bool? PAGADA = null)
        {
            Init();
            try
            {
                 using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioCLIENTE _repositorioCLIENTE = new RepositorioCLIENTE(context);
                    CLIENTE _objCLIENTE = _repositorioCLIENTE.GetById(CLIENTEId);
                    if(Equals(_objCLIENTE,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CLIENTE con Id =",CLIENTEId.ToString()));
                    }

                    RepositorioFACTURACION _repositorioFACTURACION = new RepositorioFACTURACION(context);
                    FACTURACION _objFACTURACION = _repositorioFACTURACION.GetById(FACTURACIONId);
                    if(Equals(_objFACTURACION,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =",FACTURACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA _objTIPO_FACTURA = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if(Equals(_objTIPO_FACTURA,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =",TIPO_FACTURAId.ToString()));
                    }

                    FACTURA _FACTURA = new FACTURA();

                    //properties

                    _FACTURA.CORRELATIVO = CORRELATIVO;
                    _FACTURA.NOMBRE_CLIENTE = NOMBRE_CLIENTE;
                    _FACTURA.RUT_CLIENTE = RUT_CLIENTE;
                    _FACTURA.DIRECCION = DIRECCION;
                    _FACTURA.NOMBRE_COMUNA = NOMBRE_COMUNA;
                    _FACTURA.NUMERO_FACTURA = NUMERO_FACTURA;
                    _FACTURA.RUT_LABORATORIO = RUT_LABORATORIO;
                    _FACTURA.DESCUENTO = DESCUENTO;
                    _FACTURA.FONO = FONO;
                    _FACTURA.GIRO = GIRO;
                    _FACTURA.DETALLE = DETALLE;
                    _FACTURA.NETO = NETO;
                    _FACTURA.IVA = IVA;
                    _FACTURA.TOTAL = TOTAL;
                    _FACTURA.PAGADA = PAGADA;
                    _FACTURA.ACTIVO = true;

                    //parents

                    _FACTURA.CLIENTE = _objCLIENTE;
                    _FACTURA.FACTURACION = _objFACTURACION;
                    _FACTURA.TIPO_FACTURA = _objTIPO_FACTURA;

                    context.AddObject("FACTURA",_FACTURA);
                    context.SaveChanges();

                    return _FACTURA.ID;
                }
            }
            catch(Exception ex)
            {
                 ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public void Update(int Id, int CLIENTEId, int FACTURACIONId, int TIPO_FACTURAId, int CORRELATIVO, string RUT_LABORATORIO, int NETO, int IVA, int TOTAL, string NOMBRE_CLIENTE = "", string RUT_CLIENTE = "", string DIRECCION = "", string NOMBRE_COMUNA = "", int? NUMERO_FACTURA = null, int? DESCUENTO = null, string FONO = "", string GIRO = "", string DETALLE = "", bool? PAGADA = null)
        {
            Init();
            try
            {
                 using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURA repositorio = new RepositorioFACTURA(context);
                    FACTURA _FACTURA = repositorio.GetById(Id);
                    if(Equals(_FACTURA,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURA con Id =",Id.ToString()));
                    }

                    RepositorioCLIENTE _repositorioCLIENTE = new RepositorioCLIENTE(context);
                    CLIENTE _objCLIENTE = _repositorioCLIENTE.GetById(CLIENTEId);
                    if(Equals(_objCLIENTE,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CLIENTE con Id =",CLIENTEId.ToString()));
                    }

                    RepositorioFACTURACION _repositorioFACTURACION = new RepositorioFACTURACION(context);
                    FACTURACION _objFACTURACION = _repositorioFACTURACION.GetById(FACTURACIONId);
                    if(Equals(_objFACTURACION,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =",FACTURACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA _objTIPO_FACTURA = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if(Equals(_objTIPO_FACTURA,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =",TIPO_FACTURAId.ToString()));
                    }

                    //properties

                        _FACTURA.CORRELATIVO = CORRELATIVO;
                    if (!string.IsNullOrEmpty(NOMBRE_CLIENTE))
                    {
                        _FACTURA.NOMBRE_CLIENTE = NOMBRE_CLIENTE;
                    }
                    if (!string.IsNullOrEmpty(RUT_CLIENTE))
                    {
                        _FACTURA.RUT_CLIENTE = RUT_CLIENTE;
                    }
                    if (!string.IsNullOrEmpty(DIRECCION))
                    {
                        _FACTURA.DIRECCION = DIRECCION;
                    }
                    if (!string.IsNullOrEmpty(NOMBRE_COMUNA))
                    {
                        _FACTURA.NOMBRE_COMUNA = NOMBRE_COMUNA;
                    }
                    if (NUMERO_FACTURA.HasValue)
                    {
                        _FACTURA.NUMERO_FACTURA = NUMERO_FACTURA.Value;
                    }
                    if (!string.IsNullOrEmpty(RUT_LABORATORIO))
                    {
                        _FACTURA.RUT_LABORATORIO = RUT_LABORATORIO;
                    }
                    if (DESCUENTO.HasValue)
                    {
                        _FACTURA.DESCUENTO = DESCUENTO.Value;
                    }
                    if (!string.IsNullOrEmpty(FONO))
                    {
                        _FACTURA.FONO = FONO;
                    }
                    if (!string.IsNullOrEmpty(GIRO))
                    {
                        _FACTURA.GIRO = GIRO;
                    }
                    if (!string.IsNullOrEmpty(DETALLE))
                    {
                        _FACTURA.DETALLE = DETALLE;
                    }
                        _FACTURA.NETO = NETO;
                        _FACTURA.IVA = IVA;
                        _FACTURA.TOTAL = TOTAL;
                    if (PAGADA.HasValue)
                    {
                        _FACTURA.PAGADA = PAGADA.Value;
                    }

                    //parents

                    _FACTURA.CLIENTE = _objCLIENTE;
                    _FACTURA.FACTURACION = _objFACTURACION;
                    _FACTURA.TIPO_FACTURA = _objTIPO_FACTURA;

                    context.SaveChanges();
                }
            }
            catch(Exception ex)
            {
                 ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                 throw ex;
            }
        }
Ejemplo n.º 4
0
 public FACTURACION GetByIdWithReferences(int ID)
 {
     Init();
     try
     {
         using (LQCEEntities context = new LQCEEntities())
         {
             RepositorioFACTURACION repositorio = new RepositorioFACTURACION(context);
             return repositorio.GetByIdWithReferences(ID);
         }
     }
     catch (Exception ex)
     {
          ISException.RegisterExcepcion(ex);
         Error = ex.Message;
         throw ex;
     }
 }
Ejemplo n.º 5
0
        public void Update(int Id, System.DateTime FECHA_FACTURACION)
        {
            Init();
            try
            {
                 using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION repositorio = new RepositorioFACTURACION(context);
                    FACTURACION _FACTURACION = repositorio.GetById(Id);
                    if(Equals(_FACTURACION,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =",Id.ToString()));
                    }

                    //properties

                        _FACTURACION.FECHA_FACTURACION = FECHA_FACTURACION;

                    //parents

                    context.SaveChanges();
                }
            }
            catch(Exception ex)
            {
                 ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                 throw ex;
            }
        }
Ejemplo n.º 6
0
 public List<FACTURACION> GetAll()
 {
     Init();
     try
     {
         using (LQCEEntities context = new LQCEEntities())
         {
             RepositorioFACTURACION repositorio = new RepositorioFACTURACION(context);
                                 return repositorio.GetAll().OrderBy(i => i.ID).ToList();
                             }
     }
     catch (Exception ex)
        {
          ISException.RegisterExcepcion(ex);
         Error = ex.Message;
         throw ex;
     }
 }
Ejemplo n.º 7
0
 public List<FACTURACION> GetByFilterWithReferences(System.DateTime? FECHA_FACTURACION = null)
 {
     Init();
     try
     {
          using (LQCEEntities context = new LQCEEntities())
         {
             RepositorioFACTURACION repositorio = new RepositorioFACTURACION(context);
             return repositorio.GetByFilterWithReferences(FECHA_FACTURACION).OrderBy(i => i.ID).ToList();
         }
     }
     catch (Exception ex)
     {
          ISException.RegisterExcepcion(ex);
         Error = ex.Message;
         throw ex;
     }
 }
Ejemplo n.º 8
0
        public List<DTO_RESUMEN_PRESTACIONES_FACTURAR> GetClientesAFacturar(DateTime FechaDesde,
            DateTime FechaHasta, int? IdCliente)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

                    var q = from c in _RepositorioFACTURACION.GetPrestacionesPorFacturar(FechaDesde, FechaHasta, IdCliente)
                            group c by c.ID_CLIENTE into g
                            select new DTO_RESUMEN_PRESTACIONES_FACTURAR
                            {
                                ID_CLIENTE = g.Key,
                                RUT_CLIENTE = g.FirstOrDefault().RUT,
                                NOMBRE_CLIENTE = g.FirstOrDefault().NOMBRE,
                                CANTIDAD_PRESTACIONES = g.Count(),
                                TOTAL_PRESTACIONES = g.Sum(p => p.TOTAL),
                                DESCUENTO = g.FirstOrDefault().DESCUENTO,
                                TOTAL_FACTURA = g.Sum(p => (int)(p.TOTAL * (1 - (double)g.FirstOrDefault().DESCUENTO / 100.0)))
                            };
                    return q.ToList();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public DTO_DETALLE_FACTURA GetDetalleFacturaById(int ID_FACTURA)
        {
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioVISTA_REPORTE_FACTURA _RepositorioVISTA_REPORTE_FACTURA = new RepositorioVISTA_REPORTE_FACTURA(context);
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

                    var f = _RepositorioVISTA_REPORTE_FACTURA.GetById(ID_FACTURA);
                    if (f == null)
                        throw new Exception("No se encuentra información de la factura");
                    var pagos = _RepositorioFACTURACION.GetPagosByIdFacturaWithReferencesFull(ID_FACTURA);
                    var detalle_factura = _RepositorioFACTURACION.GetFacturaDetalleByIdFactura(ID_FACTURA);
                    var notas_cobro = _RepositorioFACTURACION.GetNotasCobrosByIdFacturaWithReferencesFull(ID_FACTURA);

                    DTO_DETALLE_FACTURA _DTO_FACTURA = new DTO_DETALLE_FACTURA();
                    _DTO_FACTURA.ID_FACTURA = f.ID;
                    _DTO_FACTURA.NUMERO_FACTURA = f.NUMERO_FACTURA;
                    _DTO_FACTURA.RUT_CLIENTE = f.RUT_CLIENTE;
                    _DTO_FACTURA.NOMBRE_CLIENTE = f.NOMBRE_CLIENTE;
                    _DTO_FACTURA.FECHA_EMISION = f.FECHA_FACTURACION;
                    _DTO_FACTURA.VALOR_TOTAL = f.TOTAL;
                    _DTO_FACTURA.VALOR_PAGADO = f.VALOR_PAGADO ?? 0;
                    _DTO_FACTURA.PAGOS_REGISTRADOS = f.PAGOS_REGISTRADOS ?? 0;
                    _DTO_FACTURA.SALDO_DEUDOR = f.SALDO_DEUDOR ?? 0;
                    _DTO_FACTURA.PAGADA = f.PAGADA;

                    _DTO_FACTURA.LISTA_PRESTACIONES = (from df in detalle_factura
                                                       where df.ACTIVO && df.PRESTACION.ACTIVO
                                                       select new DTO_DETALLE_FACTURA_PRESTACION
                                                       {
                                                           ID_CLIENTE = df.FACTURA.CLIENTE.ID,
                                                           ID_FACTURA_DETALLE = df.ID,
                                                           NUMERO_FICHA = df.PRESTACION.ID,
                                                           MONTO_TOTAL = df.MONTO_TOTAL,
                                                           MONTO_COBRADO = df.MONTO_COBRADO,
                                                           FECHA_RECEPCION = df.PRESTACION.FECHA_RECEPCION,
                                                           NOMBRE_PACIENTE = df.PRESTACION.PRESTACION_HUMANA != null ? df.PRESTACION.PRESTACION_HUMANA.NOMBRE : df.PRESTACION.PRESTACION_VETERINARIA.NOMBRE
                                                       }).ToList();

                    _DTO_FACTURA.LISTA_COBROS = (from c in notas_cobro
                                                 select new DTO_DETALLE_FACTURA_COBRO
                                                 {
                                                     ID_NOTA_COBRO = c.ID,
                                                     FECHA_COBRO = c.COBRO.FECHA_COBRO,
                                                     NOMBRE_TIPO_COBRO = c.COBRO.TIPO_COBRO.NOMBRE,
                                                     MONTO_PENDIENTE_TOTAL = c.NOTA_COBRO_DETALLE.Where(ncd => ncd.ACTIVO).Sum(ncd => ncd.MONTO_PENDIENTE),
                                                     MONTO_PENDIENTE_FACTURA = c.NOTA_COBRO_DETALLE.Where(ncd => ncd.ACTIVO && ncd.FACTURA.ID == ID_FACTURA).Sum(ncd => ncd.MONTO_PENDIENTE)
                                                 }).ToList();

                    _DTO_FACTURA.LISTA_PAGOS = (from p in pagos
                                                select new DTO_DETALLE_FACTURA_PAGO
                                                {
                                                    ID_PAGO = p.ID,
                                                    FECHA_PAGO = p.FECHA_PAGO,
                                                    MONTO_PAGO_TOTAL = p.MONTO_PAGO,
                                                    MONTO_PAGO_FACTURA = p.PAGO_DETALLE.Where(pd => pd.ACTIVO
                                                    && pd.FACTURA_DETALLE.ACTIVO
                                                    && pd.FACTURA_DETALLE.FACTURA.ID == ID_FACTURA).Sum(pd => pd.MONTO)
                                                }).ToList();

                    return _DTO_FACTURA;
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 10
0
        public void EmitirNotasCobros(DateTime FechaFacturacionDesde, DateTime FechaFacturacionHasta,
            int IdTipoCobro, int? IdCliente)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);
                    RepositorioTIPO_COBRO _RepositorioTIPO_COBRO = new RepositorioTIPO_COBRO(context);
                    RepositorioFACTURA _RepositorioFACTURA = new RepositorioFACTURA(context);
                    RepositorioCLIENTE _RepositorioCLIENTE = new RepositorioCLIENTE(context);
                    RepositorioVISTA_REPORTE_FACTURA _RepositorioVISTA_REPORTE_FACTURA = new RepositorioVISTA_REPORTE_FACTURA(context);

                    TIPO_COBRO _TIPO_COBRO = _RepositorioTIPO_COBRO.GetById(IdTipoCobro);
                    if (_TIPO_COBRO == null)
                        throw new Exception("No se encuentra información del tipo de cobro");

                    COBRO _COBRO = new COBRO();
                    _COBRO.FECHA_COBRO = DateTime.Now;
                    _COBRO.TIPO_COBRO = _TIPO_COBRO;
                    _COBRO.ACTIVO = true;
                    context.AddToCOBRO(_COBRO);

                    var cliente_facturas = (from f in _RepositorioFACTURACION.GetFacturasPorNotificar(FechaFacturacionDesde,
                        FechaFacturacionHasta, IdTipoCobro, IdCliente)
                                            group f by f.ID_CLIENTE into g
                                            select new
                                            {
                                                IdCliente = g.Key,
                                                Facturas = g
                                            }).ToList();

                    if (!cliente_facturas.Any())
                        throw new Exception("No hay facturas que notificar");

                    int correlativo = 1;
                    foreach (var cf in cliente_facturas)
                    {
                        CLIENTE _CLIENTE = _RepositorioCLIENTE.GetById(cf.IdCliente);
                        if (_CLIENTE == null)
                            throw new Exception("No se encuentra información del cliente");

                        NOTA_COBRO _NOTA_COBRO = new NOTA_COBRO();
                        _NOTA_COBRO.COBRO = _COBRO;
                        _NOTA_COBRO.CORRELATIVO = correlativo;
                        _NOTA_COBRO.CLIENTE = _CLIENTE;
                        _NOTA_COBRO.ACTIVO = true;
                        context.AddToNOTA_COBRO(_NOTA_COBRO);

                        foreach (var f in cf.Facturas)
                        {
                            FACTURA _FACTURA = _RepositorioFACTURA.GetById(f.ID);
                            if (_FACTURA == null)
                                throw new Exception("No se encuentra información de la factura ");

                            VISTA_REPORTE_FACTURA _VISTA_REPORTE_FACTURA = _RepositorioVISTA_REPORTE_FACTURA.GetById(f.ID);
                            if (_VISTA_REPORTE_FACTURA == null)
                                throw new Exception("No se encuentra información de la factura ");

                            NOTA_COBRO_DETALLE _NOTA_COBRO_DETALLE = new NOTA_COBRO_DETALLE();
                            _NOTA_COBRO_DETALLE.NOTA_COBRO = _NOTA_COBRO;
                            _NOTA_COBRO_DETALLE.FACTURA = _FACTURA;
                            if (_FACTURA.PAGADA.HasValue && _FACTURA.PAGADA.Value == true)
                            {
                                _NOTA_COBRO_DETALLE.MONTO_PENDIENTE = 0;
                            }
                            else
                            {
                                _NOTA_COBRO_DETALLE.MONTO_PENDIENTE = _VISTA_REPORTE_FACTURA.SALDO_DEUDOR ?? 0;
                            }
                            _NOTA_COBRO_DETALLE.ACTIVO = true;
                            context.AddToNOTA_COBRO_DETALLE(_NOTA_COBRO_DETALLE);
                        }

                        correlativo++;
                    }

                    context.SaveChanges();

                    try
                    {
                        ListaNotaCobro = GetReporteNotaCobroByID_COBRO(context, _COBRO.ID);

                        string deviceInfo =
                                      "<DeviceInfo>" +
                                      "  <OutputFormat>PDF</OutputFormat>" +
                                      "  <PageWidth>8.2in</PageWidth>" +
                                      "  <PageHeight>11.7in</PageHeight>" +
                                      "  <MarginTop>0in</MarginTop>" +
                                      "  <MarginLeft>0in</MarginLeft>" +
                                      "  <MarginRight>0in</MarginRight>" +
                                      "  <MarginBottom>0in</MarginBottom>" +
                                      "</DeviceInfo>";
                        Warning[] warnings;
                        m_streams_NotaCobro = new List<Stream>();

                        List<DTO_REPORTE_NOTA_COBRO> ListaNotaCobroEncabezado = (from nc in ListaNotaCobro
                                                                                 group nc by nc.CORRELATIVO into g
                                                                                 select new DTO_REPORTE_NOTA_COBRO
                                                                                 {
                                                                                     ID_COBRO = g.FirstOrDefault().ID_COBRO,
                                                                                     ID_CLIENTE = g.FirstOrDefault().ID_CLIENTE,
                                                                                     CORRELATIVO = g.Key,
                                                                                     NOMBRE_CLIENTE = g.FirstOrDefault().NOMBRE_CLIENTE,
                                                                                     RUT_CLIENTE = g.FirstOrDefault().RUT_CLIENTE,
                                                                                     NOMBRE_REPORTE = g.FirstOrDefault().NOMBRE_REPORTE,
                                                                                 }).ToList();

                        // Documento 1: Un archivo con todas las notas de cobro emitidas
                        Hashtable propiedades = new Hashtable();
                        propiedades.Add("Fecha de Documento", _COBRO.FECHA_COBRO);
                        propiedades.Add("Tipo de Documento", "Nota de Cobro " + ListaNotaCobroEncabezado.FirstOrDefault().NOMBRE_REPORTE);
                        propiedades.Add("Formato", "Consolidado");

                        ReportViewer _ReportViewer = new ReportViewer();
                        _ReportViewer.ProcessingMode = ProcessingMode.Local;
                        _ReportViewer.LocalReport.ShowDetailedSubreportMessages = true;
                        _ReportViewer.LocalReport.DataSources.Clear();
                        _ReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ListaNotaCobroEncabezado));
                        _ReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReporteNotaCobro_SubreportProcessingEventHandler);
                        _ReportViewer.LocalReport.ReportEmbeddedResource = "LQCE.Transaccion.Reporte." + ListaNotaCobroEncabezado.FirstOrDefault().NOMBRE_REPORTE;

                        _ReportViewer.LocalReport.Render("PDF", deviceInfo, CreateStreamNotaCobro, out warnings);
                        foreach (Stream stream in m_streams_NotaCobro)
                            stream.Position = 0;

                        using (SPWeb spWeb = new SPSite(Settings.Default.SP_WEB).OpenWeb())
                        {
                            SPList spList = spWeb.GetList(Settings.Default.SP_LIBRERIA_FACTURAS);
                            string strNombreFactura = DateTime.Now.ToString("yyyyMMddhhmmss") + "_NotaCobro_" + _COBRO.TIPO_COBRO.NOMBRE + ".pdf";
                            spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + strNombreFactura, m_streams_NotaCobro[0], propiedades, true);
                            spList.Update();
                        }

                        foreach (var item in ListaNotaCobroEncabezado)
                        {
                            m_streams_NotaCobroIndividual = new List<Stream>();
                            // Documento 2: Un archivo por cada detalles de facturas
                            List<DTO_REPORTE_NOTA_COBRO> LISTA_DTO_REPORTE_NOTA_COBRO2 = new List<DTO_REPORTE_NOTA_COBRO>();
                            LISTA_DTO_REPORTE_NOTA_COBRO2.Add(item);

                            Hashtable propiedadesDetalle = new Hashtable();
                            propiedadesDetalle.Add("Fecha de Documento", _COBRO.FECHA_COBRO);
                            propiedadesDetalle.Add("Tipo de Documento", "Nota de Cobro " + item.NOMBRE_REPORTE);
                            propiedadesDetalle.Add("Formato", "Individual");
                            propiedadesDetalle.Add("RUT Cliente", item.RUT_CLIENTE);
                            propiedadesDetalle.Add("Nombre Cliente", item.NOMBRE_CLIENTE);

                            ReportViewer _ReportViewerDetalle = new ReportViewer();
                            _ReportViewerDetalle.ProcessingMode = ProcessingMode.Local;
                            _ReportViewerDetalle.LocalReport.ShowDetailedSubreportMessages = true;
                            _ReportViewerDetalle.LocalReport.DataSources.Clear();
                            _ReportViewerDetalle.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", LISTA_DTO_REPORTE_NOTA_COBRO2));
                            _ReportViewerDetalle.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReporteNotaCobro_SubreportProcessingEventHandler);
                            _ReportViewerDetalle.LocalReport.ReportEmbeddedResource = "LQCE.Transaccion.Reporte." + item.NOMBRE_REPORTE;

                            _ReportViewerDetalle.LocalReport.Render("PDF", deviceInfo, CreateStreamNotaCobroIndividual, out warnings);
                            foreach (Stream stream in m_streams_NotaCobroIndividual)
                                stream.Position = 0;

                            using (SPWeb spWeb = new SPSite(Settings.Default.SP_WEB).OpenWeb())
                            {
                                SPList spList = spWeb.GetList(Settings.Default.SP_LIBRERIA_FACTURAS);
                                string strNombreFactura = DateTime.Now.ToString("yyyyMMddhhmmss") + "_NotaCobroIndividual_" + _COBRO.TIPO_COBRO.NOMBRE + "_" + item.NOMBRE_CLIENTE + ".pdf";
                                spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + strNombreFactura, m_streams_NotaCobroIndividual[0], propiedadesDetalle, true);
                                spList.Update();
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        RepositorioCOBRO _RepositorioCOBRO = new RepositorioCOBRO(context);
                        COBRO _NUEVO_COBRO = _RepositorioCOBRO.GetByIdWithReferences(_COBRO.ID);

                        _NUEVO_COBRO.ACTIVO = false;
                        foreach (var _NOTA_COBRO in _NUEVO_COBRO.NOTA_COBRO)
                        {
                            _NOTA_COBRO.ACTIVO = false;
                            foreach (var _NOTA_COBRO_DETALLE in _NOTA_COBRO.NOTA_COBRO_DETALLE)
                            {
                                _NOTA_COBRO_DETALLE.ACTIVO = false;
                                context.ApplyPropertyChanges("NOTA_COBRO_DETALLE", _NOTA_COBRO_DETALLE);
                            }
                            context.ApplyPropertyChanges("NOTA_COBRO", _NOTA_COBRO);
                        }
                        context.ApplyPropertyChanges("COBRO", _NUEVO_COBRO);
                        context.SaveChanges();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 11
0
        public List<DTO_PAGO_PRESTACIONES> FacturaForPagos(int IdDetalleFactura)
        {
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);
                    RepositorioPRESTACION_EXAMEN _RepositorioPRESTACION_EXAMEN = new RepositorioPRESTACION_EXAMEN(context);
                    var detalle_factura = _RepositorioFACTURACION.GetFacturaDetalleByIdDetalleFactura(IdDetalleFactura);
                    List<DTO_PAGO_PRESTACIONES> lista = new List<DTO_PAGO_PRESTACIONES>();
                    foreach (var lis in detalle_factura)
                    {
                        DTO_PAGO_PRESTACIONES _DTO_PAGO_PRESTACIONES = new DTO_PAGO_PRESTACIONES();
                        _DTO_PAGO_PRESTACIONES.ID_FACTURA = lis.FACTURA.ID;
                        _DTO_PAGO_PRESTACIONES.NUMERO_FACTURA = lis.FACTURA.NUMERO_FACTURA;
                        _DTO_PAGO_PRESTACIONES.NOMBRE_PACIENTE = lis.PRESTACION.PRESTACION_HUMANA != null ? lis.PRESTACION.PRESTACION_HUMANA.NOMBRE : lis.PRESTACION.PRESTACION_VETERINARIA.NOMBRE;// lis.FACTURA.NOMBRE_CLIENTE;
                        _DTO_PAGO_PRESTACIONES.PRESTACION = lis.PRESTACION.TIPO_PRESTACION.NOMBRE;
                        //_DTO_PAGO_PRESTACIONES.EXAMEN = ;
                        //_DTO_PAGO_PRESTACIONES.VALOR_EXAMEN = lis.PRESTACION;
                        _DTO_PAGO_PRESTACIONES.FECHA_RECEPCION = lis.PRESTACION.FECHA_RECEPCION;
                        _DTO_PAGO_PRESTACIONES.ID_FACTURA_DETALLE = lis.ID;

                        var prestacion = _RepositorioPRESTACION_EXAMEN.GetByFilterWithReferences(null, lis.PRESTACION.ID, null);
                        foreach (var pre in prestacion)
                        {
                            _DTO_PAGO_PRESTACIONES.EXAMEN = pre.EXAMEN.NOMBRE;
                            _DTO_PAGO_PRESTACIONES.VALOR_EXAMEN = int.Parse(pre.VALOR.ToString());
                        }

                        lista.Add(_DTO_PAGO_PRESTACIONES);
                    }
                    return lista;
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 12
0
        public void EmitirFacturas(List<DTO_EMISION_FACTURA> ListaClientesFacturar, DateTime FechaDesde,
            DateTime FechaHasta)
        {
            Init();
            ListaDetalleFactura = new List<DTO_REPORTE_DETALLEFACTURA_PRESTACION>();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);
                    RepositorioCLIENTE _RepositorioCLIENTE = new RepositorioCLIENTE(context);
                    RepositorioPRESTACION _RepositorioPRESTACION = new RepositorioPRESTACION(context);

                    FACTURACION _FACTURACION = new FACTURACION();
                    _FACTURACION.FECHA_FACTURACION = DateTime.Now;
                    _FACTURACION.ACTIVO = true;
                    context.AddToFACTURACION(_FACTURACION);

                    int correlativo = 1;
                    foreach (var item in ListaClientesFacturar)
                    {
                        CLIENTE _CLIENTE = _RepositorioCLIENTE.GetByIdWithReferences(item.ID_CLIENTE);
                        if (_CLIENTE == null)
                            throw new Exception("No se encuentra información del cliente");

                        var prestaciones = _RepositorioFACTURACION.GetPrestacionesPorFacturar(FechaDesde, FechaHasta, item.ID_CLIENTE).ToList();

                        FACTURA _FACTURA = new FACTURA();
                        _FACTURA.FACTURACION = _FACTURACION;
                        _FACTURA.CORRELATIVO = correlativo;
                        _FACTURA.CLIENTE = _CLIENTE;
                        _FACTURA.NUMERO_FACTURA = null;
                        _FACTURA.RUT_LABORATORIO = _CLIENTE.TIPO_FACTURA.RUT_FACTURA;
                        _FACTURA.ACTIVO = true;
                        _FACTURA.DESCUENTO = item.DESCUENTO;
                        _FACTURA.NOMBRE_CLIENTE = _CLIENTE.NOMBRE;
                        _FACTURA.RUT_CLIENTE = _CLIENTE.RUT;
                        _FACTURA.DIRECCION = _CLIENTE.DIRECCION;
                        if (_CLIENTE.COMUNA != null)
                        {
                            _FACTURA.NOMBRE_COMUNA = _CLIENTE.COMUNA.NOMBRE;
                        }
                        _FACTURA.FONO = _CLIENTE.FONO;
                        _FACTURA.GIRO = _CLIENTE.GIRO;
                        _FACTURA.DETALLE = "Exámenes realizados del " + FechaDesde.ToString("dd MMMM yyyy") + " al " + FechaHasta.ToString("dd MMMM yyyy");
                        _FACTURA.TIPO_FACTURA = _CLIENTE.TIPO_FACTURA;

                        context.AddToFACTURA(_FACTURA);

                        int suma_total = 0;
                        foreach (var prestacion in prestaciones)
                        {
                            PRESTACION _PRESTACION = _RepositorioPRESTACION.GetById(prestacion.ID);
                            if (_PRESTACION == null)
                                throw new Exception("No se encuentra información de la prestación");

                            int total = (int)(prestacion.TOTAL * (1 - (double)item.DESCUENTO / 100.0));
                            suma_total += total;

                            FACTURA_DETALLE _FACTURA_DETALLE = new FACTURA_DETALLE();
                            _FACTURA_DETALLE.FACTURA = _FACTURA;
                            _FACTURA_DETALLE.PRESTACION = _PRESTACION;
                            _FACTURA_DETALLE.MONTO_TOTAL = total;
                            _FACTURA_DETALLE.MONTO_COBRADO = 0;
                            _FACTURA_DETALLE.ACTIVO = true;
                            context.AddToFACTURA_DETALLE(_FACTURA_DETALLE);
                        }

                        if (_CLIENTE.TIPO_FACTURA.AFECTO_IVA)
                        {
                            if (_CLIENTE.TIPO_PRESTACION.ID == (int)Enum.ENUM_TIPO_PRESTACION.Humanas)
                            {
                                _FACTURA.NETO = suma_total;
                                _FACTURA.IVA = (int)(suma_total * 0.19);
                                _FACTURA.TOTAL = (int)(suma_total * 1.19);
                            }
                            else
                            {
                                _FACTURA.NETO = (int)(suma_total / 1.19);
                                _FACTURA.IVA = suma_total - (int)(suma_total / 1.19);
                                _FACTURA.TOTAL = suma_total;
                            }
                        }
                        else
                        {
                            _FACTURA.NETO = suma_total;
                            _FACTURA.IVA = 0;
                            _FACTURA.TOTAL = suma_total;
                        }
                        //context.ApplyPropertyChanges("FACTURA", _FACTURA);
                        correlativo++;
                    }
                    context.SaveChanges();

                    try
                    {
                        var LISTA_DTO_REPORTE_FACTURA = GetReporteFacturaByID_FACTURACION(_FACTURACION.ID);

                        ListaDetalleFactura = GetReporteDetalleFacturaByID_FACTURACION(_FACTURACION.ID);

                        string deviceInfo =
                                      "<DeviceInfo>" +
                                      "  <OutputFormat>PDF</OutputFormat>" +
                                      "  <PageWidth>21cm</PageWidth>" +
                                      "  <PageHeight>29.7cm</PageHeight>" +
                                      "  <MarginTop>1cm</MarginTop>" +
                                      "  <MarginLeft>0.5cm</MarginLeft>" +
                                      "  <MarginRight>0.5cm</MarginRight>" +
                                      "  <MarginBottom>1cm</MarginBottom>" +
                                      "</DeviceInfo>";
                        Warning[] warnings;
                        m_streams_matriz = new List<Stream>();
                        m_streams_DetalleFactura = new List<Stream>();

                        string deviceInfoDireccion =
                                     "<DeviceInfo>" +
                                     "  <OutputFormat>PDF</OutputFormat>" +
                                     "  <PageWidth>11in</PageWidth>" +
                                     "  <PageHeight>1.3in</PageHeight>" +
                                     "  <MarginTop>0.5in</MarginTop>" +
                                     "  <MarginLeft>1in</MarginLeft>" +
                                     "  <MarginRight>1in</MarginRight>" +
                                     "  <MarginBottom>0.5in</MarginBottom>" +
                                     "</DeviceInfo>";
                        Warning[] warningsDireccion;
                        m_streams_Direccion = new List<Stream>();

                        // Documento 1: Un archivo con todas las facturas sin fondo para imprimir en matriz de punto
                        var tf = from f in LISTA_DTO_REPORTE_FACTURA
                                 group f by f.NOMBRE_REPORTE_FACTURA into g
                                 select g;

                        foreach (var facturas in tf)
                        {
                            Hashtable propiedades = new Hashtable();
                            propiedades.Add("Fecha de Documento", _FACTURACION.FECHA_FACTURACION);
                            propiedades.Add("Tipo de Documento", "Factura " + facturas.FirstOrDefault().NOMBRE_TIPO_FACTURA);
                            propiedades.Add("Formato", "Consolidado");

                            Hashtable propiedadesDireccion = new Hashtable();
                            propiedadesDireccion.Add("Fecha de Documento", _FACTURACION.FECHA_FACTURACION);
                            propiedadesDireccion.Add("Tipo de Documento", "Direcciones " + facturas.FirstOrDefault().NOMBRE_TIPO_FACTURA);
                            propiedadesDireccion.Add("Formato", "Consolidado");

                            ReportViewer _ReportViewer = new ReportViewer();
                            _ReportViewer.ProcessingMode = ProcessingMode.Local;
                            _ReportViewer.LocalReport.ShowDetailedSubreportMessages = true;
                            _ReportViewer.LocalReport.DataSources.Clear();
                            _ReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", facturas));
                            _ReportViewer.LocalReport.ReportEmbeddedResource = "LQCE.Transaccion.Reporte." + facturas.Key;
                            _ReportViewer.LocalReport.Render("PDF", deviceInfo, CreateStream, out warnings);
                            foreach (Stream stream in m_streams_matriz)
                                stream.Position = 0;

                            ReportViewer _ReportViewerDireccion = new ReportViewer();
                            _ReportViewerDireccion.ProcessingMode = ProcessingMode.Local;
                            _ReportViewerDireccion.LocalReport.DataSources.Clear();
                            _ReportViewerDireccion.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", facturas));
                            _ReportViewerDireccion.LocalReport.ReportEmbeddedResource = "LQCE.Transaccion.Reporte.DireccionFactura.rdlc";
                            _ReportViewerDireccion.LocalReport.Render("PDF", deviceInfoDireccion, CreateStreamDireccion, out warningsDireccion);
                            foreach (Stream stream in m_streams_Direccion)
                                stream.Position = 0;

                            using (SPWeb spWeb = new SPSite(Settings.Default.SP_WEB).OpenWeb())
                            {
                                SPList spList = spWeb.GetList(Settings.Default.SP_LIBRERIA_FACTURAS);

                                string strNombreFactura = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + facturas.Key + ".pdf";
                                spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + strNombreFactura, m_streams_matriz[0], propiedades, true);
                                spList.Update();

                                string strNombreDirecciones = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + facturas.Key + " - Direcciones.pdf";
                                spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + strNombreDirecciones, m_streams_Direccion[0], propiedadesDireccion, true);
                                spList.Update();
                            }
                        }

                        // Documento 2: Un archivo con todos los detalles de facturas
                        List<DTO_REPORTE_DETALLEFACTURA_FACTURA> LISTA_DTO_REPORTE_DETALLEFACTURA_FACTURA =
                            (from df in ListaDetalleFactura
                             group df by df.ID_FACTURA into g
                             select new DTO_REPORTE_DETALLEFACTURA_FACTURA
                             {
                                 ID_FACTURA = g.Key,
                                 ID_CLIENTE = g.FirstOrDefault().ID_CLIENTE,
                                 NOMBRE_CLIENTE = g.FirstOrDefault().NOMBRE_CLIENTE,
                                 RUT_CLIENTE = g.FirstOrDefault().RUT_CLIENTE,
                                 DETALLE = g.FirstOrDefault().DETALLE,
                                 SUMA_PENDIENTE = g.Where(p => p.ESTADO_PENDIENTE == "INPAGO" || p.ESTADO_PREVISION == "INPAGO").Sum(p => p.MONTO_TOTAL)
                             }).ToList();

                        Hashtable propiedadesDetalle = new Hashtable();
                        propiedadesDetalle.Add("Fecha de Documento", _FACTURACION.FECHA_FACTURACION);
                        propiedadesDetalle.Add("Tipo de Documento", "Detalle de Factura");
                        propiedadesDetalle.Add("Formato", "Consolidado");

                        ReportViewer _ReportViewerDetalle = new ReportViewer();
                        _ReportViewerDetalle.ProcessingMode = ProcessingMode.Local;
                        _ReportViewerDetalle.LocalReport.ShowDetailedSubreportMessages = true;
                        _ReportViewerDetalle.LocalReport.DataSources.Clear();
                        _ReportViewerDetalle.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", LISTA_DTO_REPORTE_DETALLEFACTURA_FACTURA));
                        _ReportViewerDetalle.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReporteDetalleFactura_SubreportProcessingEventHandler);
                        _ReportViewerDetalle.LocalReport.ReportEmbeddedResource = "LQCE.Transaccion.Reporte.DetalleFactura.rdlc";

                        _ReportViewerDetalle.LocalReport.Render("PDF", deviceInfo, CreateStreamDetalleFactura, out warnings);
                        foreach (Stream stream in m_streams_DetalleFactura)
                            stream.Position = 0;

                        using (SPWeb spWeb = new SPSite(Settings.Default.SP_WEB).OpenWeb())
                        {
                            SPList spList = spWeb.GetList(Settings.Default.SP_LIBRERIA_FACTURAS);
                            string strNombreFactura = DateTime.Now.ToString("yyyyMMddhhmmss") + "_DetalleFactura.pdf";
                            spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + strNombreFactura, m_streams_DetalleFactura[0], propiedadesDetalle, true);
                            spList.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        // En caso de error, al generar los PDF se eliminan los registros de las facturas
                        _FACTURACION.ACTIVO = false;
                        foreach (var _FACTURA in _FACTURACION.FACTURA)
                        {
                            _FACTURA.ACTIVO = false;
                            foreach (var _FACTURA_DETALLE in _FACTURA.FACTURA_DETALLE)
                            {
                                _FACTURA_DETALLE.ACTIVO = false;
                                context.ApplyPropertyChanges("FACTURA_DETALLE", _FACTURA_DETALLE);
                            }
                            context.ApplyPropertyChanges("FACTURA", _FACTURA);
                        }
                        context.ApplyPropertyChanges("FACTURACION", _FACTURACION);
                        context.SaveChanges();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 13
0
        private List<DTO_REPORTE_NOTA_COBRO_DETALLE> GetReporteNotaCobroByID_COBRO(LQCEEntities context, int IdCobro)
        {
            RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

            var q = _RepositorioFACTURACION.GetNotaCobroDetalleByIdCobro(IdCobro);

            return (from nd in q
                    select new DTO_REPORTE_NOTA_COBRO_DETALLE
                    {
                        FECHA_FACTURACION = nd.FACTURA.FACTURACION.FECHA_FACTURACION,
                        ID_COBRO = nd.NOTA_COBRO.COBRO.ID,
                        ID_CLIENTE = nd.NOTA_COBRO.CLIENTE.ID,
                        CORRELATIVO = nd.NOTA_COBRO.CORRELATIVO,
                        NOMBRE_CLIENTE = nd.NOTA_COBRO.CLIENTE.NOMBRE,
                        RUT_CLIENTE = nd.NOTA_COBRO.CLIENTE.RUT,
                        NOMBRE_REPORTE = nd.NOTA_COBRO.COBRO.TIPO_COBRO.REPORTE,
                        ID_NOTA_COBRO_DETALLE = nd.ID,
                        NUMERO_FACTURA = nd.FACTURA.NUMERO_FACTURA.HasValue ? nd.FACTURA.NUMERO_FACTURA.Value : 0,
                        MONTO_TOTAL = nd.FACTURA.TOTAL,
                        MONTO_PENDIENTE = nd.MONTO_PENDIENTE
                    }).ToList();
        }
Ejemplo n.º 14
0
        protected List<DTO_REPORTE_FACTURA> GetReporteFacturaByID_FACTURACION(int IdFacturacion)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

                    FACTURACION _FACTURACION = _RepositorioFACTURACION.GetByIdWithReferencesFull(IdFacturacion);
                    if (_FACTURACION == null)
                        throw new Exception("No se encuentra información de la facturación");

                    return (from f in _FACTURACION.FACTURA
                            where f.ACTIVO
                            select new DTO_REPORTE_FACTURA
                            {
                                NOMBRE_REPORTE_DETALLE_FACTURA = f.CLIENTE.TIPO_PRESTACION.NOMBRE_REPORTE_DETALLE_FACTURA,
                                NOMBRE_REPORTE_FACTURA = f.TIPO_FACTURA.NOMBRE_REPORTE_FACTURA,
                                NOMBRE_REPORTE_FACTURA_INDIVIDUAL = f.TIPO_FACTURA.NOMBRE_REPORTE_FACTURA_INDIVIDUAL,
                                DIA = f.FACTURACION.FECHA_FACTURACION.Day,
                                MES = f.FACTURACION.FECHA_FACTURACION.ToString("MMMM"),
                                AÑO = f.FACTURACION.FECHA_FACTURACION.Year,
                                NOMBRE_CLIENTE = f.NOMBRE_CLIENTE,
                                RUT_CLIENTE = f.RUT_CLIENTE,
                                DIRECCION = f.DIRECCION,
                                COMUNA = f.NOMBRE_COMUNA,
                                FONO = f.FONO,
                                GIRO = f.GIRO,
                                DETALLE = f.DETALLE,
                                NETO = f.NETO,
                                IVA = f.IVA,
                                TOTAL = f.TOTAL,
                                NUMERO_FACTURA = f.NUMERO_FACTURA,
                                NOMBRE_TIPO_FACTURA = f.TIPO_FACTURA.NOMBRE_FACTURA
                            }).ToList();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 15
0
        protected List<DTO_REPORTE_DETALLEFACTURA_PRESTACION> GetReporteDetalleFacturaByID_FACTURACION(int IdFacturacion)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

                    int IdTipoPrestacionVeterinaria = (int)Enum.ENUM_TIPO_PRESTACION.Veterinarias;
                    int IdTipoPrestacionHumana = (int)Enum.ENUM_TIPO_PRESTACION.Humanas;

                    var q = _RepositorioFACTURACION.GetFacturaDetalleByIdFacturacion(IdFacturacion);

                    var lista = (from fd in q
                            select new DTO_REPORTE_DETALLEFACTURA_PRESTACION
                            {
                                ID_FACTURA = fd.FACTURA.ID,
                                ID_CLIENTE = fd.FACTURA.CLIENTE.ID,
                                NOMBRE_CLIENTE = fd.FACTURA.NOMBRE_CLIENTE,
                                RUT_CLIENTE = fd.FACTURA.RUT_CLIENTE,
                                DETALLE = fd.FACTURA.DETALLE,
                                ID_FACTURA_DETALLE = fd.ID,
                                NUMERO_FICHA = fd.PRESTACION.ID,
                                MONTO_TOTAL = fd.MONTO_TOTAL,
                                FECHA_RECEPCION = fd.PRESTACION.FECHA_RECEPCION,
                                NOMBRE = fd.PRESTACION.PRESTACION_HUMANA != null ? fd.PRESTACION.PRESTACION_HUMANA.NOMBRE : fd.PRESTACION.PRESTACION_VETERINARIA.NOMBRE,
                                MEDICO = fd.PRESTACION.MEDICO,
                                EXAMENES = "",
                                //ESTADO = fd.PRESTACION.GARANTIA != null ? fd.PRESTACION.GARANTIA.NOMBRE : ""
                                ESTADO_PENDIENTE = fd.PRESTACION.TIPO_PRESTACION.ID == IdTipoPrestacionVeterinaria ?
                                    ((fd.PRESTACION.PENDIENTE == "CANCELADO" || fd.PRESTACION.PENDIENTE == "PAGADO") ? "PAGADO" : "INPAGO") : "",
                                ESTADO_PREVISION = fd.PRESTACION.TIPO_PRESTACION.ID == IdTipoPrestacionHumana ?
                                    ((fd.PRESTACION.PREVISION.NOMBRE == "CANCELADO" || fd.PRESTACION.PREVISION.NOMBRE == "PAGADO") ? "PAGADO" : "INPAGO") : "",
                            }).ToList();

                    foreach (var i in lista)
                    {
                        string examenes = "";
                        FACTURA_DETALLE _FACTURA_DETALLE = _RepositorioFACTURACION.GetFacturaDetalleByIdDetalleFactura(i.ID_FACTURA_DETALLE).FirstOrDefault();
                        if (_FACTURA_DETALLE != null)
                        {
                            if(_FACTURA_DETALLE.PRESTACION != null)
                            {
                                foreach (var e in _FACTURA_DETALLE.PRESTACION.PRESTACION_EXAMEN.Where(pe => pe.ACTIVO))
                                {
                                    if (e.EXAMEN != null)
                                    {
                                        if (!string.IsNullOrEmpty(examenes))
                                            examenes += ", ";
                                        examenes += e.EXAMEN.NOMBRE;
                                    }
                                }
                            }
                        }
                        i.EXAMENES = examenes;
                    }
                    return lista;
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 16
0
        protected List<DTO_REPORTE_DETALLEFACTURA_PRESTACION> GetReporteDetalleFacturaByID_FACTURA(int IdFactura)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURACION _RepositorioFACTURACION = new RepositorioFACTURACION(context);

                    var q = _RepositorioFACTURACION.GetFacturaDetalleByIdFactura(IdFactura);

                    var lista = (from fd in q
                            select new DTO_REPORTE_DETALLEFACTURA_PRESTACION
                            {
                                ID_FACTURA = fd.FACTURA.ID,
                                ID_CLIENTE = fd.FACTURA.CLIENTE.ID,
                                NOMBRE_CLIENTE = fd.FACTURA.NOMBRE_CLIENTE,
                                RUT_CLIENTE = fd.FACTURA.RUT_CLIENTE,
                                DETALLE = fd.FACTURA.DETALLE,
                                ID_FACTURA_DETALLE = fd.ID,
                                NUMERO_FICHA = fd.PRESTACION.ID,
                                MONTO_TOTAL = fd.MONTO_TOTAL,
                                FECHA_RECEPCION = fd.PRESTACION.FECHA_RECEPCION,
                                NOMBRE = fd.PRESTACION.PRESTACION_HUMANA != null ? fd.PRESTACION.PRESTACION_HUMANA.NOMBRE : fd.PRESTACION.PRESTACION_VETERINARIA.NOMBRE,
                                MEDICO = fd.PRESTACION.MEDICO,
                                EXAMENES = ""
                            }).ToList();

                    foreach (var i in lista)
                    {
                        string examenes = "";
                        FACTURA_DETALLE _FACTURA_DETALLE = _RepositorioFACTURACION.GetFacturaDetalleByIdDetalleFactura(i.ID_FACTURA_DETALLE).FirstOrDefault();
                        if (_FACTURA_DETALLE != null)
                        {
                            if(_FACTURA_DETALLE.PRESTACION != null)
                            {
                                foreach (var e in _FACTURA_DETALLE.PRESTACION.PRESTACION_EXAMEN.Where(pe => pe.ACTIVO))
                                {
                                    if(e.EXAMEN != null)
                                    {
                                    if (!string.IsNullOrEmpty(examenes))
                                        examenes += ", ";
                                    examenes += e.EXAMEN.NOMBRE;
                                    }
                                }
                            }
                        }
                        i.EXAMENES = examenes;
                    }
                    return lista;
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }